mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
media: return the appropriate Attachment type
This commit is contained in:
parent
8ae89462b7
commit
acc18adffb
1 changed files with 15 additions and 1 deletions
|
|
@ -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 };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue