diff options
| author | Fuwn <[email protected]> | 2026-03-01 16:20:51 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-01 16:21:02 -0800 |
| commit | eae5d24d9e79e59a19d4721caaeaa0ca650ecb33 (patch) | |
| tree | 1b685bb248e051dfa26d2bfdebe6689402dd93c5 /src/lib/Utility/image.ts | |
| parent | chore(tooling): remove legacy eslint and prettier (diff) | |
| download | due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.tar.xz due.moe-eae5d24d9e79e59a19d4721caaeaa0ca650ecb33.zip | |
chore(biome): drop formatter style overrides
Diffstat (limited to 'src/lib/Utility/image.ts')
| -rw-r--r-- | src/lib/Utility/image.ts | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/src/lib/Utility/image.ts b/src/lib/Utility/image.ts index b8ed0663..2d08e62f 100644 --- a/src/lib/Utility/image.ts +++ b/src/lib/Utility/image.ts @@ -1,46 +1,50 @@ -import { env } from '$env/dynamic/public'; +import { env } from "$env/dynamic/public"; export const cdn = (urlString: string | undefined) => - !urlString || - !['http', 'https'].some((protocol) => urlString.startsWith(protocol)) || - env.PUBLIC_ANILIST_REDIRECT_URI?.includes('localhost') || - [ - 'api.telegram.org', - 'telegra.ph', - 't.me', - 'discord.com', - 'cdn.discordapp.com', - 'media.discordapp.net', - 'images-ext-1.discordapp.net', - 'images-ext-2.discordapp.net', - 'media.trace.moe', - 'files.catbox.moe' - ].includes(new URL(urlString).hostname) - ? urlString - : `https://cdn.due.moe?url=${encodeURIComponent(urlString)}`; + !urlString || + !["http", "https"].some((protocol) => urlString.startsWith(protocol)) || + env.PUBLIC_ANILIST_REDIRECT_URI?.includes("localhost") || + [ + "api.telegram.org", + "telegra.ph", + "t.me", + "discord.com", + "cdn.discordapp.com", + "media.discordapp.net", + "images-ext-1.discordapp.net", + "images-ext-2.discordapp.net", + "media.trace.moe", + "files.catbox.moe", + ].includes(new URL(urlString).hostname) + ? urlString + : `https://cdn.due.moe?url=${encodeURIComponent(urlString)}`; export const thumbnail = (url: string | undefined) => { - const width = 144; - const height = 200; + const width = 144; + const height = 200; - if (url && url.includes('catbox.moe') && !url.includes('gif')) - return url.replace('catbox.moe/', 'catbox.moe/thumbs/t_'); + if (url && url.includes("catbox.moe") && !url.includes("gif")) + return url.replace("catbox.moe/", "catbox.moe/thumbs/t_"); - if (url && url.includes('imgur') && !url.includes('gif')) - return (!url.includes('i.imgur.com') ? url.replace('imgur.com', 'i.imgur.com') : url).replace( - /(\.\w+)$/, - `_d.webp?maxwidth=${width}&shape=thumb&fidelity=high` - ); + if (url && url.includes("imgur") && !url.includes("gif")) + return ( + !url.includes("i.imgur.com") + ? url.replace("imgur.com", "i.imgur.com") + : url + ).replace( + /(\.\w+)$/, + `_d.webp?maxwidth=${width}&shape=thumb&fidelity=high`, + ); - if (url && url.includes('discordapp')) { - const match = url.match(/attachments\/(\d+)\/(\d+)\/(.+)/); + if (url && url.includes("discordapp")) { + const match = url.match(/attachments\/(\d+)\/(\d+)\/(.+)/); - if (match) { - const [, server, id, file] = match; + if (match) { + const [, server, id, file] = match; - return `https://media.discordapp.net/attachments/${server}/${id}/${file}?width=${width}&height=${height}`; - } - } + return `https://media.discordapp.net/attachments/${server}/${id}/${file}?width=${width}&height=${height}`; + } + } - return url; + return url; }; |