diff --git a/deno.json b/deno.json index e40dd24..54ba468 100644 --- a/deno.json +++ b/deno.json @@ -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", diff --git a/src/deps.ts b/src/deps.ts index 46d8fec..12be07f 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -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 { diff --git a/src/note.ts b/src/note.ts index 1c5c70c..7dc39f5 100644 --- a/src/note.ts +++ b/src/note.ts @@ -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; } }