media: return the appropriate Attachment type
This commit is contained in:
parent
8ae89462b7
commit
acc18adffb
|
@ -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 };
|
||||
|
|
Loading…
Reference in New Issue