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 };