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
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 6 additions and 7 deletions

View File

@ -32,7 +32,7 @@
"@std/dotenv": "jsr:@std/dotenv@^0.224.0",
"@std/encoding": "jsr:@std/encoding@^0.224.0",
"@std/json": "jsr:@std/json@^0.223.0",
"@std/media-types": "jsr:@std/media-types@^0.224.0",
"@std/media-types": "jsr:@std/media-types@^0.224.1",
"@std/streams": "jsr:@std/streams@^0.223.0",
"comlink": "npm:comlink@^4.4.1",
"deno-safe-fetch": "https://gitlab.com/soapbox-pub/deno-safe-fetch/-/raw/v1.0.0/load.ts",

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;
}
}