ref: format

This commit is contained in:
alikia2x (寒寒) 2024-10-07 01:41:21 +08:00
parent 76c4472de1
commit ea8b503653
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
11 changed files with 4326 additions and 371 deletions

View File

@ -12,7 +12,7 @@ import { settingsAtom } from "lib/state/settings";
import PlainText from "./plainText"; import PlainText from "./plainText";
import { sendError } from "lib/telemetering/sendError"; import { sendError } from "lib/telemetering/sendError";
import { handleNLUResult } from "./handleNLUResult"; import { handleNLUResult } from "./handleNLUResult";
import * as ort from 'onnxruntime-web'; import * as ort from "onnxruntime-web";
import { useAtom, useAtomValue } from "jotai"; import { useAtom, useAtomValue } from "jotai";
import i18next from "i18next"; import i18next from "i18next";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -100,16 +100,15 @@ export default function OneSearch() {
const embeddingDict = getEmbeddingLayer(arrBuf); const embeddingDict = getEmbeddingLayer(arrBuf);
setEmbeddingLayer(embeddingDict); setEmbeddingLayer(embeddingDict);
await loadModel("/models/NLU.onnx"); await loadModel("/models/NLU.onnx");
// if (!modelLoaded) { // if (!modelLoaded) {
// console.error("NLU model was not correctly loaded.") // console.error("NLU model was not correctly loaded.")
// } // }
})(); })();
}, []); }, []);
async function loadModel(modelPath: string) { async function loadModel(modelPath: string) {
ort.env.wasm.wasmPaths = "/onnx/" ort.env.wasm.wasmPaths = "/onnx/";
const session = await ort.InferenceSession.create(modelPath); const session = await ort.InferenceSession.create(modelPath);
setNLUsession(session); setNLUsession(session);
} }

View File

@ -1,10 +1,10 @@
{ {
"search": { "search": {
"placeholder": "ابحث أو اكتب عنوان URL" "placeholder": "ابحث أو اكتب عنوان URL"
}, },
"about": { "about": {
"license": { "license": {
"view": "← عرض" "view": "← عرض"
} }
} }
} }

View File

@ -1,39 +1,39 @@
{ {
"404": { "404": {
"title": "Page not found" "title": "Page not found"
}, },
"search": { "search": {
"placeholder": "Search or type a URL", "placeholder": "Search or type a URL",
"engine-aria": "Switch search engine", "engine-aria": "Switch search engine",
"engine": { "engine": {
"google": "Google", "google": "Google",
"baidu": "Baidu", "baidu": "Baidu",
"bing": "Bing", "bing": "Bing",
"duckduckgo": "DuckDuckGo", "duckduckgo": "DuckDuckGo",
"yandex": "Yandex", "yandex": "Yandex",
"yahoo": "Yahoo", "yahoo": "Yahoo",
"ecosia": "Ecosia" "ecosia": "Ecosia"
}, },
"search-help-text": "Search {engine}" "search-help-text": "Search {engine}"
}, },
"notfound": { "notfound": {
"title": "page not found", "title": "page not found",
"desc": "Please check if there is a typo in the URL. <br/>If SparkHome brought you to this page,<br/> please <a style=\"text-decoration:underline;\" href=\"mailto:contact@alikia2x.com\">contact us.</a>" "desc": "Please check if there is a typo in the URL. <br/>If SparkHome brought you to this page,<br/> please <a style=\"text-decoration:underline;\" href=\"mailto:contact@alikia2x.com\">contact us.</a>"
}, },
"tools": { "tools": {
"base64": { "base64": {
"title": "Base64 tools - LuminaraUtils", "title": "Base64 tools - LuminaraUtils",
"decode": "Decode", "decode": "Decode",
"encode": "Encode", "encode": "Encode",
"result": "Result: ", "result": "Result: ",
"copy": "Copy", "copy": "Copy",
"copied": "Copied" "copied": "Copied"
} }
}, },
"about": { "about": {
"title": "About sparkast", "title": "About sparkast",
"license": { "license": {
"view": "→ view" "view": "→ view"
} }
} }
} }

View File

@ -1,14 +1,14 @@
{ {
"search": { "search": {
"engine-aria": "検索エンジンを切り替える", "engine-aria": "検索エンジンを切り替える",
"engine": { "engine": {
"google": "Google" "google": "Google"
}, },
"placeholder": "検索またはURLを入力" "placeholder": "検索またはURLを入力"
}, },
"about": { "about": {
"license": { "license": {
"view": "→ 見る" "view": "→ 見る"
} }
} }
} }

View File

@ -1,39 +1,39 @@
{ {
"404": { "404": {
"title": "页面未找到" "title": "页面未找到"
}, },
"search": { "search": {
"placeholder": "搜索或输入网址", "placeholder": "搜索或输入网址",
"engine-aria": "切换搜索引擎", "engine-aria": "切换搜索引擎",
"engine": { "engine": {
"google": "谷歌", "google": "谷歌",
"baidu": "百度", "baidu": "百度",
"bing": "必应", "bing": "必应",
"duckduckgo": "DuckDuckGo", "duckduckgo": "DuckDuckGo",
"yandex": "Yandex", "yandex": "Yandex",
"yahoo": "雅虎", "yahoo": "雅虎",
"ecosia": "Ecosia" "ecosia": "Ecosia"
}, },
"search-help-text": "用 {engine} 搜索" "search-help-text": "用 {engine} 搜索"
}, },
"tools": { "tools": {
"base64": { "base64": {
"title": "Base64 工具", "title": "Base64 工具",
"decode": "解码", "decode": "解码",
"encode": "编码", "encode": "编码",
"result": "结果: ", "result": "结果: ",
"copy": "复制", "copy": "复制",
"copied": "已复制" "copied": "已复制"
} }
}, },
"notfound": { "notfound": {
"desc": "请检查网址是否出错。 <br/>如果你从星火主页跳转到这里,<br/> 请 <a style=\"text-decoration:underline;\" href=\"mailto:contact@alikia2x.com\">联系我们</a>", "desc": "请检查网址是否出错。 <br/>如果你从星火主页跳转到这里,<br/> 请 <a style=\"text-decoration:underline;\" href=\"mailto:contact@alikia2x.com\">联系我们</a>",
"title": "网页不存在" "title": "网页不存在"
}, },
"about": { "about": {
"title": "关于 sparkast", "title": "关于 sparkast",
"license": { "license": {
"view": "→ 查看" "view": "→ 查看"
} }
} }
} }

View File

@ -1,64 +1,64 @@
{ {
"name": "sparkhome", "name": "sparkhome",
"private": false, "private": false,
"version": "5.8.1", "version": "5.8.1",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "bun server.ts", "dev": "bun server.ts",
"build": "bun license-gen && tsc -b && vite build", "build": "bun license-gen && tsc -b && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "NODE_ENV=production bun server.ts", "preview": "NODE_ENV=production bun server.ts",
"license-gen": "bunx generate-license-file --input package.json --output lib/license.txt --overwrite", "license-gen": "bunx generate-license-file --input package.json --output lib/license.txt --overwrite",
"format": "prettier --write ." "format": "prettier --write ."
}, },
"dependencies": { "dependencies": {
"@iconify/react": "^5.0.1", "@iconify/react": "^5.0.1",
"@nextui-org/react": "^2.4.2", "@nextui-org/react": "^2.4.2",
"@types/bun": "^1.1.6", "@types/bun": "^1.1.6",
"@types/express": "^4.17.21", "@types/express": "^4.17.21",
"@types/tr46": "^5.0.0", "@types/tr46": "^5.0.0",
"@xenova/transformers": "^2.17.2", "@xenova/transformers": "^2.17.2",
"cac": "^6.7.14", "cac": "^6.7.14",
"chalk": "^5.3.0", "chalk": "^5.3.0",
"express": "^4.19.2", "express": "^4.19.2",
"fflate": "^0.8.2", "fflate": "^0.8.2",
"framer-motion": "^11.2.12", "framer-motion": "^11.2.12",
"generate-license-file": "^3.5.1", "generate-license-file": "^3.5.1",
"i18next": "^23.11.5", "i18next": "^23.11.5",
"i18next-browser-languagedetector": "^8.0.0", "i18next-browser-languagedetector": "^8.0.0",
"i18next-icu": "^2.3.0", "i18next-icu": "^2.3.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"jotai": "^2.8.3", "jotai": "^2.8.3",
"node-nlp": "^4.27.0", "node-nlp": "^4.27.0",
"onnxruntime-web": "^1.20.0-dev.20240925-a47254eaef", "onnxruntime-web": "^1.20.0-dev.20240925-a47254eaef",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
"react-i18next": "^14.1.2", "react-i18next": "^14.1.2",
"react-router": "^6.23.1", "react-router": "^6.23.1",
"react-router-dom": "^6.23.1", "react-router-dom": "^6.23.1",
"tr46": "^5.0.0", "tr46": "^5.0.0",
"valid-url": "^1.0.9", "valid-url": "^1.0.9",
"validate-color": "^2.2.4", "validate-color": "^2.2.4",
"vite-express": "^0.17.0" "vite-express": "^0.17.0"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18.3.3", "@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"@types/valid-url": "^1.0.7", "@types/valid-url": "^1.0.7",
"@typescript-eslint/eslint-plugin": "^7.13.1", "@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1", "@typescript-eslint/parser": "^7.13.1",
"@vitejs/plugin-react-swc": "^3.5.0", "@vitejs/plugin-react-swc": "^3.5.0",
"autoprefixer": "^10.4.19", "autoprefixer": "^10.4.19",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.2", "eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7", "eslint-plugin-react-refresh": "^0.4.7",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"tailwindcss": "^3.4.4", "tailwindcss": "^3.4.4",
"typescript": "^5.2.2", "typescript": "^5.2.2",
"vite": "^5.3.1", "vite": "^5.3.1",
"vite-plugin-chunk-split": "^0.5.0", "vite-plugin-chunk-split": "^0.5.0",
"vite-plugin-pages": "^0.32.2", "vite-plugin-pages": "^0.32.2",
"vite-tsconfig-paths": "^4.3.2" "vite-tsconfig-paths": "^4.3.2"
} }
} }

View File

@ -15,7 +15,10 @@ export default function AboutPage() {
<span className="leading-7 md:leading-9 text-3xl font-bold">sparkast</span> <span className="leading-7 md:leading-9 text-3xl font-bold">sparkast</span>
<p className="mt-2 leading-5 text-base md:text-xl"> <p className="mt-2 leading-5 text-base md:text-xl">
Made with <span className="text-red-500"></span> by Made with <span className="text-red-500"></span> by
<a className="underline decoration-dotted text-red-500 mx-1" href="https://alikia2x.com"> <a
className="underline decoration-dotted text-red-500 mx-1"
href="https://alikia2x.com"
>
alikia2x alikia2x
</a> </a>
from Luminara Studio from Luminara Studio
@ -40,7 +43,7 @@ export default function AboutPage() {
className="relative px-2 py-1 text-sm font-bold rounded-md text-nowrap underline className="relative px-2 py-1 text-sm font-bold rounded-md text-nowrap underline
bg-green-600 text-white" bg-green-600 text-white"
> >
<a href="/about/license">{t('about.license.view')}</a> <a href="/about/license">{t("about.license.view")}</a>
</span> </span>
</p> </p>

View File

@ -1 +1,13 @@
{"idx_to_class": {"0": "weather", "1": "base64", "2": "url-encode", "3": "html-encode", "4": "ai.command", "5": "knowledge", "6": "ai.question", "7": "datetime"}, "threshold": 1.7} {
"idx_to_class": {
"0": "weather",
"1": "base64",
"2": "url-encode",
"3": "html-encode",
"4": "ai.command",
"5": "knowledge",
"6": "ai.question",
"7": "datetime"
},
"threshold": 1.7
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,59 +1,59 @@
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import { isValidIPv4, } from "../lib/url/validLink"; import { isValidIPv4 } from "../lib/url/validLink";
describe("Check if a string is a valid IPv4", () => { describe("Check if a string is a valid IPv4", () => {
test("Invalid IPv4 addresses - Missing part", () => { test("Invalid IPv4 addresses - Missing part", () => {
expect(isValidIPv4("192.168.1")).toBe(false); expect(isValidIPv4("192.168.1")).toBe(false);
expect(isValidIPv4("1")).toBe(false); expect(isValidIPv4("1")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains non-digit characters", () => { test("Invalid IPv4 addresses - Contains non-digit characters", () => {
expect(isValidIPv4("192.168.1.a")).toBe(false); expect(isValidIPv4("192.168.1.a")).toBe(false);
expect(isValidIPv4("192.168.1.1a")).toBe(false); expect(isValidIPv4("192.168.1.1a")).toBe(false);
expect(isValidIPv4("192.168.1.1.1")).toBe(false); expect(isValidIPv4("192.168.1.1.1")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains empty parts", () => { test("Invalid IPv4 addresses - Contains empty parts", () => {
expect(isValidIPv4("192.168.1.")).toBe(false); expect(isValidIPv4("192.168.1.")).toBe(false);
expect(isValidIPv4("192..168.1")).toBe(false); expect(isValidIPv4("192..168.1")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains negative numbers", () => { test("Invalid IPv4 addresses - Contains negative numbers", () => {
expect(isValidIPv4("192.168.-1.1")).toBe(false); expect(isValidIPv4("192.168.-1.1")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains out-of-range numbers", () => { test("Invalid IPv4 addresses - Contains out-of-range numbers", () => {
expect(isValidIPv4("192.168.256.1")).toBe(false); expect(isValidIPv4("192.168.256.1")).toBe(false);
expect(isValidIPv4("192.168.1.256")).toBe(false); expect(isValidIPv4("192.168.1.256")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains multiple dots", () => { test("Invalid IPv4 addresses - Contains multiple dots", () => {
expect(isValidIPv4("192.168..1.1")).toBe(false); expect(isValidIPv4("192.168..1.1")).toBe(false);
expect(isValidIPv4("192.168.1..1")).toBe(false); expect(isValidIPv4("192.168.1..1")).toBe(false);
}); });
test("Invalid IPv4 addresses - Empty string", () => { test("Invalid IPv4 addresses - Empty string", () => {
expect(isValidIPv4("")).toBe(false); expect(isValidIPv4("")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains special characters", () => { test("Invalid IPv4 addresses - Contains special characters", () => {
expect(isValidIPv4("192.168.1.1!")).toBe(false); expect(isValidIPv4("192.168.1.1!")).toBe(false);
expect(isValidIPv4("192.168.1.1 ")).toBe(false); expect(isValidIPv4("192.168.1.1 ")).toBe(false);
expect(isValidIPv4("192.168.1.1\t")).toBe(false); expect(isValidIPv4("192.168.1.1\t")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains non-ASCII characters", () => { test("Invalid IPv4 addresses - Contains non-ASCII characters", () => {
expect(isValidIPv4("192.168.1.1©")).toBe(false); expect(isValidIPv4("192.168.1.1©")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains newline character", () => { test("Invalid IPv4 addresses - Contains newline character", () => {
expect(isValidIPv4("192.168.1.1\n")).toBe(false); expect(isValidIPv4("192.168.1.1\n")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains multiple IP addresses", () => { test("Invalid IPv4 addresses - Contains multiple IP addresses", () => {
expect(isValidIPv4("192.168.1.1 192.168.1.2")).toBe(false); expect(isValidIPv4("192.168.1.1 192.168.1.2")).toBe(false);
}); });
test("Invalid IPv4 addresses - Contains IPv6 address", () => { test("Invalid IPv4 addresses - Contains IPv6 address", () => {
expect(isValidIPv4("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toBe(false); expect(isValidIPv4("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toBe(false);
}); });
@ -61,19 +61,19 @@ describe("Check if a string is a valid IPv4", () => {
test("Valid IPv4 addresses - Standard IP", () => { test("Valid IPv4 addresses - Standard IP", () => {
expect(isValidIPv4("192.168.1.1")).toBe(true); expect(isValidIPv4("192.168.1.1")).toBe(true);
}); });
test("Valid IPv4 addresses - All zeros", () => { test("Valid IPv4 addresses - All zeros", () => {
expect(isValidIPv4("0.0.0.0")).toBe(true); expect(isValidIPv4("0.0.0.0")).toBe(true);
}); });
test("Valid IPv4 addresses - Maximum value", () => { test("Valid IPv4 addresses - Maximum value", () => {
expect(isValidIPv4("255.255.255.255")).toBe(true); expect(isValidIPv4("255.255.255.255")).toBe(true);
}); });
test("Valid IPv4 addresses - Leading zero but valid", () => { test("Valid IPv4 addresses - Leading zero but valid", () => {
expect(isValidIPv4("192.000.001.001")).toBe(true); expect(isValidIPv4("192.000.001.001")).toBe(true);
}); });
test("Valid IPv4 addresses - Single digit parts", () => { test("Valid IPv4 addresses - Single digit parts", () => {
expect(isValidIPv4("1.2.3.4")).toBe(true); expect(isValidIPv4("1.2.3.4")).toBe(true);
}); });