mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-28 02:34:25 +01:00
media: return the appropriate Attachment type
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user