Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the media proxy and authenticated (user & token) API as env #2998

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,16 @@ FETCH_REPLIES_MAX_SINGLE=500

# Max number of replies Collection pages to fetch - total
FETCH_REPLIES_MAX_PAGES=500

##
# Maximum API requests per minute (=period)
##

#MEDIA_PROXY_API_LIMIT=300
#MEDIA_PROXY_API_PERIOD=1

#AUTHENTICATED_USER_API_LIMIT=3000
#AUTHENTICATED_USER_API_PERIOD=1

#AUTHENTICATED_TOKEN_API_LIMIT=3000
#AUTHENTICATED_TOKEN_API_PERIOD=1
6 changes: 3 additions & 3 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def paging_request?
IpBlock.blocked?(req.remote_ip)
end

throttle('throttle_authenticated_api', limit: 1_500, period: 5.minutes) do |req|
throttle('throttle_authenticated_api', limit: (ENV['AUTHENTICATED_USER_API_LIMIT'] || 1_500).to_i, period: (ENV['AUTHENTICATED_USER_API_PERIOD'] || 5).to_i.minutes) do |req|
req.authenticated_user_id if req.api_request?
end

throttle('throttle_per_token_api', limit: 300, period: 5.minutes) do |req|
throttle('throttle_per_token_api', limit: (ENV['AUTHENTICATED_TOKEN_API_LIMIT'] || 300).to_i, period: (ENV['AUTHENTICATED_TOKEN_API_PERIOD'] || 5).to_i.minutes) do |req|
req.authenticated_token_id if req.api_request?
end

Expand All @@ -82,7 +82,7 @@ def paging_request?
req.authenticated_user_id if req.post? && req.path.match?(%r{\A/api/v\d+/media\z}i)
end

throttle('throttle_media_proxy', limit: 30, period: 10.minutes) do |req|
throttle('throttle_media_proxy', limit: (ENV['MEDIA_PROXY_API_LIMIT'] || 30).to_i, period: (ENV['MEDIA_PROXY_API_PERIOD'] || 10).to_i.minutes) do |req|
req.throttleable_remote_ip if req.path.start_with?('/media_proxy')
end

Expand Down