From acc18adffbdab79f6cdcd8b9f5b3459698aa4cb2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 8 Sep 2023 16:15:34 -0500 Subject: [PATCH] media: return the appropriate Attachment type --- src/controllers/api/media.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/controllers/api/media.ts b/src/controllers/api/media.ts index 5b5128c..75b8bd8 100644 --- a/src/controllers/api/media.ts +++ b/src/controllers/api/media.ts @@ -27,7 +27,7 @@ const mediaController: AppController = async (c) => { return c.json({ id: cid, - type: file.type, + type: getAttachmentType(file.type), url, preview_url: url, remote_url: null, @@ -40,4 +40,18 @@ const mediaController: AppController = async (c) => { } }; +/** MIME to Mastodon API `Attachment` type. */ +function getAttachmentType(mime: string): string { + const [type] = mime.split('/'); + + switch (type) { + case 'image': + case 'video': + case 'audio': + return type; + default: + return 'unknown'; + } +} + export { mediaController };