misskey-awawa/src/misc/detect-url-mime.ts

16 lines
362 B
TypeScript
Raw Normal View History

import { createTemp } from './create-temp';
2020-04-11 10:49:25 +00:00
import { downloadUrl } from './download-url';
import { detectType } from './get-file-info';
export async function detectUrlMime(url: string) {
const [path, cleanup] = await createTemp();
try {
await downloadUrl(url, path);
const { mime } = await detectType(path);
return mime;
} finally {
cleanup();
}
}