|
|
@ -44,16 +44,18 @@ |
|
|
|
if (settled) return |
|
|
|
settled = true |
|
|
|
|
|
|
|
if(file.thumbnail == null) return |
|
|
|
const thumb = typeof file.thumbnail === 'function' ? (await file.thumbnail()) : file.data; |
|
|
|
// media is to be either thumbnail or data |
|
|
|
// const thumb = file.thumbnail || file.data |
|
|
|
const media = typeof file.thumbnail === 'function' ? (await file.thumbnail()) : file.data; |
|
|
|
if(media == null) return |
|
|
|
|
|
|
|
let type: FileTypeResult | undefined |
|
|
|
if (thumb instanceof Buffer) { |
|
|
|
type = await fileTypeFromBuffer(thumb); |
|
|
|
url = URL.createObjectURL(new Blob([thumb], { type: type?.mime })) |
|
|
|
if (media instanceof ArrayBuffer || media instanceof Uint8Array) { |
|
|
|
type = await fileTypeFromBuffer(media); |
|
|
|
url = URL.createObjectURL(new Blob([media], { type: type?.mime })) |
|
|
|
// if (!type) return; // extracted out below for TypeScript |
|
|
|
} else if (typeof thumb === 'string'){ |
|
|
|
let head = headerStringToObject(await GM_head(thumb, undefined)) |
|
|
|
} else if (typeof media === 'string'){ |
|
|
|
let head = headerStringToObject(await GM_head(media, undefined)) |
|
|
|
// TODO write a proper getExt() and getMime() |
|
|
|
type = { ext: '' as any, mime: head['content-type'].split(';')[0].trim() } |
|
|
|
} |
|
|
|