mirror of
https://github.com/iv-org/invidious.git
synced 2026-02-18 01:58:30 -06:00
Merge 582d4973a0eb263d0dbae5b29c63a4e40d1e6058 into e7f8b15b215f86f10ee788bc716b559527d4b801
This commit is contained in:
commit
3b13f1bbd6
@ -436,6 +436,19 @@ full_refresh: false
|
|||||||
##
|
##
|
||||||
feed_threads: 1
|
feed_threads: 1
|
||||||
|
|
||||||
|
##
|
||||||
|
## Setting to disable easy to abuse API endpoints that can
|
||||||
|
## be spammed and therefore blocking your Invidious instance.
|
||||||
|
##
|
||||||
|
## Notes: The following API endpoints will be disabled:
|
||||||
|
## - /api/v1/videos
|
||||||
|
## - /api/v1/clips
|
||||||
|
## - /api/v1/transcripts
|
||||||
|
##
|
||||||
|
## Accepted values: true, false
|
||||||
|
## Default: false
|
||||||
|
##
|
||||||
|
disable_api: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
|
|||||||
@ -217,6 +217,7 @@ end
|
|||||||
Kemal.config.powered_by_header = false
|
Kemal.config.powered_by_header = false
|
||||||
add_handler FilteredCompressHandler.new
|
add_handler FilteredCompressHandler.new
|
||||||
add_handler APIHandler.new
|
add_handler APIHandler.new
|
||||||
|
add_handler DisableAbusableAPIHandler.new
|
||||||
add_handler AuthHandler.new
|
add_handler AuthHandler.new
|
||||||
add_handler DenyFrame.new
|
add_handler DenyFrame.new
|
||||||
|
|
||||||
|
|||||||
@ -180,6 +180,9 @@ class Config
|
|||||||
# Playlist length limit
|
# Playlist length limit
|
||||||
property playlist_length_limit : Int32 = 500
|
property playlist_length_limit : Int32 = 500
|
||||||
|
|
||||||
|
# Disable easy to abuse API endpoints
|
||||||
|
property disable_api : Bool = false
|
||||||
|
|
||||||
def disabled?(option)
|
def disabled?(option)
|
||||||
case disabled = CONFIG.disable_proxy
|
case disabled = CONFIG.disable_proxy
|
||||||
when Bool
|
when Bool
|
||||||
|
|||||||
@ -133,6 +133,26 @@ class APIHandler < Kemal::Handler
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class DisableAbusableAPIHandler < Kemal::Handler
|
||||||
|
{% for method in %w(GET HEAD) %}
|
||||||
|
# This endpoints make a video request to Invidious companion.
|
||||||
|
{% for endpoint in %w(videos clips transcripts) %}
|
||||||
|
only ["/api/v1/{{ endpoint.id }}/:id"], {{ method }}
|
||||||
|
{% end %}
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
return call_next env unless only_match?(env) && CONFIG.disable_api
|
||||||
|
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
env.response.status_code = 403
|
||||||
|
message = {"error" => "This API endpoint has been disabled by the administrator."}.to_json
|
||||||
|
env.response.print message
|
||||||
|
env.response.close
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class DenyFrame < Kemal::Handler
|
class DenyFrame < Kemal::Handler
|
||||||
exclude ["/embed/*"]
|
exclude ["/embed/*"]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user