media: return the appropriate Attachment type

This commit is contained in:
Alex Gleason 2023-09-08 16:15:34 -05:00
parent 8ae89462b7
commit acc18adffb
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 15 additions and 1 deletions

View File

@ -27,7 +27,7 @@ const mediaController: AppController = async (c) => {
return c.json({ return c.json({
id: cid, id: cid,
type: file.type, type: getAttachmentType(file.type),
url, url,
preview_url: url, preview_url: url,
remote_url: null, 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 }; export { mediaController };