Merge pull request #269 from h3poteto/add/detect-file-type

Detect file type from misskey files
This commit is contained in:
AkiraFukushima 2020-03-18 23:20:35 +09:00 committed by GitHub
commit 9fc6d9b95e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -126,10 +126,23 @@ namespace MisskeyAPI {
}
}
export const fileType = (s: string): 'unknown' | 'image' | 'gifv' | 'video' => {
if (s === 'image/gif') {
return 'gifv'
}
if (s.includes('image')) {
return 'image'
}
if (s.includes('video')) {
return 'video'
}
return 'unknown'
}
export const file = (f: Entity.File): MegalodonEntity.Attachment => {
return {
id: f.id,
type: 'image',
type: fileType(f.type),
url: f.url,
remote_url: f.url,
preview_url: f.thumbnailUrl,