From 60100c51feb2870fa434c6a062969ca2b9ea7721 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Mon, 1 Jun 2020 13:21:10 +0000 Subject: [PATCH] Add `send_attachment` function for direct download --- src/util.cr | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util.cr b/src/util.cr index 36a7791..e6008fb 100644 --- a/src/util.cr +++ b/src/util.cr @@ -35,6 +35,12 @@ def send_json(env, json) env.response.print json end +def send_attachment(env, path) + MIME.register ".cbz", "application/vnd.comicbook+zip" + MIME.register ".cbr", "application/vnd.comicbook-rar" + send_file env, path, filename: File.basename(path), disposition: "attachment" +end + def hash_to_query(hash) hash.map { |k, v| "#{k}=#{v}" }.join("&") end