Remove dependency on npm:mime, switch to @std/media-types

This commit is contained in:
Alex Gleason
2024-05-18 11:35:29 -05:00
parent 4c87e723c0
commit f97064afb4
3 changed files with 6 additions and 7 deletions

View File

@@ -1,8 +1,6 @@
import 'deno-safe-fetch';
// @deno-types="npm:@types/lodash@4.14.194"
export { default as lodash } from 'https://esm.sh/lodash@4.17.21';
// @deno-types="npm:@types/mime@3.0.0"
export { default as mime } from 'npm:mime@^3.0.0';
// @deno-types="npm:@types/sanitize-html@2.9.0"
export { default as sanitizeHtml } from 'npm:sanitize-html@^2.11.0';
export {

View File

@@ -1,10 +1,10 @@
import { typeByExtension } from '@std/media-types';
import 'linkify-plugin-hashtag';
import linkifyStr from 'linkify-string';
import linkify from 'linkifyjs';
import { nip19, nip21 } from 'nostr-tools';
import { Conf } from '@/config.ts';
import { mime } from '@/deps.ts';
import { type DittoAttachment } from '@/views/mastodon/attachments.ts';
linkify.registerCustomProtocol('nostr', true);
@@ -87,12 +87,13 @@ function isLinkURL(link: Link): boolean {
return link.type === 'url';
}
/** `npm:mime` treats `.com` as a file extension, so parse the full URL to get its path first. */
/** Get the extension from the URL, then get its type. */
function getUrlMimeType(url: string): string | undefined {
try {
const { pathname } = new URL(url);
return mime.getType(pathname) || undefined;
} catch (_e) {
const ext = pathname.split('.').pop() ?? '';
return typeByExtension(ext);
} catch {
return undefined;
}
}