mirror of
https://github.com/hkalexling/Mango.git
synced 2026-03-20 00:00:48 -04:00
Finish the API endpoint for cover upload
This commit is contained in:
28
src/handlers/upload_handler.cr
Normal file
28
src/handlers/upload_handler.cr
Normal file
@@ -0,0 +1,28 @@
|
||||
require "kemal"
|
||||
require "../util"
|
||||
|
||||
class UploadHandler < Kemal::Handler
|
||||
def initialize(@upload_dir : String)
|
||||
end
|
||||
|
||||
def call(env)
|
||||
unless request_path_startswith(env, [UPLOAD_URL_PREFIX]) &&
|
||||
env.request.method == "GET"
|
||||
return call_next env
|
||||
end
|
||||
|
||||
pp env.request.path
|
||||
|
||||
ary = env.request.path.split(File::SEPARATOR).select { |part| !part.empty? }
|
||||
ary[0] = @upload_dir
|
||||
path = File.join ary
|
||||
|
||||
pp path
|
||||
|
||||
if File.exists? path
|
||||
send_file env, path
|
||||
else
|
||||
env.response.status_code = 404
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user