From 3553a5a513f503763e995fd0f8eb992d21ec7eb4 Mon Sep 17 00:00:00 2001 From: Joe Ma Date: Sun, 5 Jun 2022 19:24:30 +0800 Subject: [PATCH] Add option to display file as text Update API specification Signed-off-by: Joe Ma --- src/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 142d036..d450920 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,7 +62,9 @@ POST //settings Update paste setting, i.e., passcode and valid time [ ] # For paste with password protected, all API call related to the pastes requires additional x-pass header * uuid: [A-z0-9]{${UUID_LENGTH}} -* option: Render language +# Currently support two options +# "download": Download paste as attachment +# "raw": Display paste as plain text Features * Password protection [x] @@ -357,7 +359,13 @@ export default { } res.headers.set("cache-control", "public, max-age=18000"); - res.headers.set("content-type", descriptor.mime_type ?? "application/octet-stream"); + // Alter content type to text/plain + if (option === "raw") { + res.headers.set("content-type", "text/plain; charset=UTF-8;"); + } else { + res.headers.set("content-type", descriptor.mime_type ?? "application/octet-stream"); + } + res.headers.set("content-disposition", `inline; filename="${encodeURIComponent(descriptor.title ?? uuid)}"`);