From 447c44216c1f9f49ac903acb3436e4acdfb6d429 Mon Sep 17 00:00:00 2001 From: echicken <echicken@bbs.electronicchicken.com> Date: Wed, 27 Jan 2021 14:46:16 -0500 Subject: [PATCH] Optional content-disposition change. If file type is known to ctrl/mime_types.ini, and if files_inline is true in modopts.ini->[web], and if it's not application/octet-stream, set content-disposition to inline. --- webv4/root/api/files.ssjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/webv4/root/api/files.ssjs b/webv4/root/api/files.ssjs index 06855704fd..b2f8b17956 100644 --- a/webv4/root/api/files.ssjs +++ b/webv4/root/api/files.ssjs @@ -3,6 +3,7 @@ var settings = load('modopts.js', 'web') || { web_directory: '../webv4' }; load(settings.web_directory + '/lib/init.js'); load(settings.web_lib + 'auth.js'); +load(settings.web_lib + 'files.js'); require('filebase.js', 'FileBase'); var CHUNK_SIZE = 1024; @@ -41,8 +42,13 @@ if ((http_request.method === 'GET' || http_request.method === 'POST') && reply.error = 'Not enough credits to download this file'; break; } - http_reply.header['Content-Type'] = 'application/octet-stream'; - http_reply.header['Content-Disposition'] = 'attachment; filename="' + file.base + '.' + file.ext + '"'; + var mt = settings.files_inline ? getMimeType(file) : 'application/octet-stream'; + http_reply.header['Content-Type'] = mt; + if (mt === 'application/octet-stream') { + http_reply.header['Content-Disposition'] = 'attachment; filename="' + file.base + '.' + file.ext + '"'; + } else { + http_reply.header['Content-Disposition'] = 'inline'; + } http_reply.header['Content-Encoding'] = 'binary'; http_reply.header['Content-Length'] = file_size(file.path); var f = new File(file.path); -- GitLab