diff --git a/package.json b/package.json index 8a7115abde..ca8f3742e9 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@crowdin/cli": "^3.7.10", "@hrgui/libass-wasm-ts": "^1.0.3", "@types/crypto-js": "^4.2.2", + "@types/ini": "^4.1.1", "@types/mark.js": "^8.11.8", "@types/node": "^20.0.0", "@types/qrcode": "^1.5.5", @@ -76,6 +77,7 @@ "flv.js": "^1.6.2", "hash-wasm": "^4.12.0", "hls.js": "^1.2.1", + "ini": "^5.0.0", "just-once": "^2.2.0", "libass-wasm": "^4.1.0", "lightgallery": "^2.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eaef3bb0b9..3d2c0e8d5e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,6 +74,9 @@ importers: hls.js: specifier: ^1.2.1 version: 1.2.1 + ini: + specifier: ^5.0.0 + version: 5.0.0 just-once: specifier: ^2.2.0 version: 2.2.0 @@ -141,6 +144,9 @@ importers: '@types/crypto-js': specifier: ^4.2.2 version: 4.2.2 + '@types/ini': + specifier: ^4.1.1 + version: 4.1.1 '@types/mark.js': specifier: ^8.11.8 version: 8.11.8 @@ -507,6 +513,9 @@ packages: '@types/hast@2.3.4': resolution: {integrity: sha512-wLEm0QvaoawEDoTRwzTXp4b4jpwiJDvR5KMnFnVodm3scufTlBOWRD6N1OBf9TZMhjlNsSfcO5V+7AF4+Vy+9g==} + '@types/ini@4.1.1': + resolution: {integrity: sha512-MIyNUZipBTbyUNnhvuXJTY7B6qNI78meck9Jbv3wk0OgNwRyOOVEKDutAkOs1snB/tx0FafyR6/SN4Ps0hZPeg==} + '@types/jquery@3.5.16': resolution: {integrity: sha512-bsI7y4ZgeMkmpG9OM710RRzDFp+w4P1RGiIt30C1mSBT+ExCleeh4HObwgArnDFELmRrOpXgSYN9VF1hj+f1lw==} @@ -1175,6 +1184,10 @@ packages: inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + ini@5.0.0: + resolution: {integrity: sha512-+N0ngpO3e7cRUWOJAS7qw0IZIVc6XPrW4MlFBdD066F2L4k1L6ker3hLqSq7iXxU5tgS4WGkIUElWn5vogAEnw==} + engines: {node: ^18.17.0 || >=20.5.0} + inline-style-parser@0.1.1: resolution: {integrity: sha512-7NXolsK4CAS5+xvdj5OMMbI962hU/wvwoxk+LWR9Ek9bVtyuuYScDN6eS0rUm6TxApFpw7CX1o4uJzcd4AyD3Q==} @@ -2450,6 +2463,8 @@ snapshots: dependencies: '@types/unist': 2.0.6 + '@types/ini@4.1.1': {} + '@types/jquery@3.5.16': dependencies: '@types/sizzle': 2.3.3 @@ -3085,6 +3100,8 @@ snapshots: inherits@2.0.4: {} + ini@5.0.0: {} + inline-style-parser@0.1.1: {} interpret@1.4.0: {} diff --git a/src/pages/home/previews/url.tsx b/src/pages/home/previews/url.tsx index a8a696a376..6a225ccfe6 100644 --- a/src/pages/home/previews/url.tsx +++ b/src/pages/home/previews/url.tsx @@ -1,15 +1,25 @@ import { MaybeLoading } from "~/components" +import { recordKeysToLowerCase } from "~/utils" import { FileInfo } from "./info" import { useFetchText, useParseText, useT } from "~/hooks" import { createEffect } from "solid-js" import { Button } from "@hope-ui/solid" +import { parse } from "ini" export default function () { const [content] = useFetchText() function openInNewWindow() { - const url = content()?.content - const { text } = useParseText(url) - url && window.open(text(), "_blank") + const ini = content()?.content + const { text } = useParseText(ini) + const config = recordKeysToLowerCase(parse(text())) + const url = config.internetshortcut?.url + if (url) { + const a = document.createElement("a") + a.href = url + a.rel = "noopener noreferrer" + a.target = "_blank" + a.click() + } } createEffect(() => { openInNewWindow() diff --git a/src/utils/convert.ts b/src/utils/convert.ts index 9352e7d136..d837c54128 100644 --- a/src/utils/convert.ts +++ b/src/utils/convert.ts @@ -12,3 +12,14 @@ export const recordToArray = (record: Record) => { } return res } + +export const recordKeysToLowerCase = >( + obj: T, +): Record => { + return Object.fromEntries( + Object.entries(obj).map(([k, v]) => [ + k.toLowerCase(), + v !== null && typeof v === "object" ? recordKeysToLowerCase(v) : v, + ]), + ) +}