Invidious is an alternative front-end to YouTube
Kemal: remove APIHandler middleware
Samantaz Fox9310d09f9371
diff --git a/src/invidious.cr b/src/invidious.crindex e0bd0101..c8cac80e 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -217,7 +217,6 @@ public_folder "assets"Kemal.config.powered_by_header = falseadd_handler FilteredCompressHandler.new-add_handler APIHandler.newadd_handler AuthHandler.newadd_handler DenyFrame.newadd_context_storage_type(Array(String))diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.crindex d140a858..cece289b 100644--- a/src/invidious/helpers/handlers.cr+++ b/src/invidious/helpers/handlers.cr@@ -134,74 +134,6 @@ class AuthHandler < Kemal::Handlerendend-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::Handlerexclude ["/embed/*"]