summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2023-11-20 17:31:21 +0100
committerSamantaz Fox <coding@samantaz.fr>2023-11-23 18:30:37 +0100
commit9310d09f9371072a2f5dba94e9dbbc6d49efa0a3 (patch)
tree7ee04cc6ebf36509e178494f1227aaaa91ca5331 /src
parentc5b87e3b5e5cc7f7f5c8baa7732bd6d81d8f910a (diff)
downloadinvidious-9310d09f9371072a2f5dba94e9dbbc6d49efa0a3.tar.gz
invidious-9310d09f9371072a2f5dba94e9dbbc6d49efa0a3.tar.bz2
invidious-9310d09f9371072a2f5dba94e9dbbc6d49efa0a3.zip
Kemal: remove APIHandler middleware
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr1
-rw-r--r--src/invidious/helpers/handlers.cr68
2 files changed, 0 insertions, 69 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index e0bd0101..c8cac80e 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -217,7 +217,6 @@ public_folder "assets"
Kemal.config.powered_by_header = false
add_handler FilteredCompressHandler.new
-add_handler APIHandler.new
add_handler AuthHandler.new
add_handler DenyFrame.new
add_context_storage_type(Array(String))
diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr
index d140a858..cece289b 100644
--- a/src/invidious/helpers/handlers.cr
+++ b/src/invidious/helpers/handlers.cr
@@ -134,74 +134,6 @@ class AuthHandler < Kemal::Handler
end
end
-class APIHandler < Kemal::Handler
- {% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
- only ["/api/v1/*"], {{method}}
- {% end %}
- exclude ["/api/v1/auth/notifications"], "GET"
- exclude ["/api/v1/auth/notifications"], "POST"
-
- def call(env)
- return call_next env unless only_match? env
-
- env.response.headers["Access-Control-Allow-Origin"] = "*"
-
- # Since /api/v1/notifications is an event-stream, we don't want
- # to wrap the response
- return call_next env if exclude_match? env
-
- # Here we swap out the socket IO so we can modify the response as needed
- output = env.response.output
- env.response.output = IO::Memory.new
-
- begin
- call_next env
-
- env.response.output.rewind
-
- if env.response.output.as(IO::Memory).size != 0 &&
- env.response.headers.includes_word?("Content-Type", "application/json")
- response = JSON.parse(env.response.output)
-
- if fields_text = env.params.query["fields"]?
- begin
- JSONFilter.filter(response, fields_text)
- rescue ex
- env.response.status_code = 400
- response = {"error" => ex.message}
- end
- end
-
- if env.params.query["pretty"]?.try &.== "1"
- response = response.to_pretty_json
- else
- response = response.to_json
- end
- else
- response = env.response.output.gets_to_end
- end
- rescue ex
- env.response.content_type = "application/json" if env.response.headers.includes_word?("Content-Type", "text/html")
- env.response.status_code = 500
-
- if env.response.headers.includes_word?("Content-Type", "application/json")
- response = {"error" => ex.message || "Unspecified error"}
-
- if env.params.query["pretty"]?.try &.== "1"
- response = response.to_pretty_json
- else
- response = response.to_json
- end
- end
- ensure
- env.response.output = output
- env.response.print response
-
- env.response.flush
- end
- end
-end
-
class DenyFrame < Kemal::Handler
exclude ["/embed/*"]