From 5964a10571be560c4393e62dabb99f717af635a2 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Tue, 19 Sep 2023 17:11:37 -0700 Subject: [PATCH] cld -> tinyld --- packages/backend/package.json | 2 +- packages/backend/src/@types/cld.d.ts | 16 ---------------- .../backend/src/models/repositories/note.ts | 4 ++-- pnpm-lock.yaml | 18 +++++++++++++++++- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index 4747519652..7bae448609 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -54,7 +54,6 @@ "chalk": "5.3.0", "chalk-template": "0.4.0", "chokidar": "^3.5.3", - "cld": "^2.9.0", "cli-highlight": "2.1.11", "color-convert": "2.0.1", "content-disposition": "0.5.4", @@ -133,6 +132,7 @@ "tar-stream": "^3.1.6", "tesseract.js": "^4.1.1", "tinycolor2": "1.6.0", + "tinyld": "^1.3.4", "tmp": "0.2.1", "twemoji-parser": "14.0.0", "typeorm": "0.3.17", diff --git a/packages/backend/src/@types/cld.d.ts b/packages/backend/src/@types/cld.d.ts index ea4ec09706..b79677dee4 100644 --- a/packages/backend/src/@types/cld.d.ts +++ b/packages/backend/src/@types/cld.d.ts @@ -23,19 +23,3 @@ interface DetectLanguage { readonly languages: Language[]; readonly chunks: Chunk[]; } -export declare module "cld" { - declare function detect( - text: string, - options: Options, - callback: (err: string, result: DetectLanguage) => void, - ): void; - declare function detect( - text: string, - callback: (err: string, result: DetectLanguage) => void, - ): void; - declare function detect( - text: string, - options: Options, - ): Promise; - declare function detect(text: string): Promise; -} diff --git a/packages/backend/src/models/repositories/note.ts b/packages/backend/src/models/repositories/note.ts index b9e37c52f0..6e5ef2f718 100644 --- a/packages/backend/src/models/repositories/note.ts +++ b/packages/backend/src/models/repositories/note.ts @@ -27,7 +27,7 @@ import { } from "@/misc/populate-emojis.js"; import { db } from "@/db/postgre.js"; import { IdentifiableError } from "@/misc/identifiable-error.js"; -import cld from "cld"; +import { detect as detectLanguage_ } from "tinyld"; import { detect } from "langdetect"; export async function populatePoll(note: Note, meId: User["id"] | null) { @@ -206,7 +206,7 @@ export const NoteRepository = db.getRepository(Note).extend({ let lang; try { - lang = (await cld.detect((note.text || "") + (note.cw || ""))) + lang = (detectLanguage_((note.text || "") + (note.cw || ""))) .languages[0].code; } catch (e) { lang = diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f92ddb1a27..51ece395e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -279,6 +279,9 @@ importers: koa-views: specifier: 7.0.2 version: 7.0.2(@types/koa@2.13.8)(ejs@3.1.9)(pug@3.0.2) + langdetect: + specifier: 0.2.1 + version: 0.2.1 megalodon: specifier: workspace:* version: link:../megalodon @@ -411,6 +414,9 @@ importers: tinycolor2: specifier: 1.6.0 version: 1.6.0 + tinyld: + specifier: ^1.3.4 + version: 1.3.4 tmp: specifier: 0.2.1 version: 0.2.1 @@ -12965,6 +12971,12 @@ packages: engines: {node: '>=14.16'} dev: false + /langdetect@0.2.1: + resolution: {integrity: sha512-vWK2xz8Urp6J0RFwnrR8+d0DQ2yIGjCOqAxBoXNMVFv4ZDmFsbCcNEtwuVnaQ5+ltwZ4Z5rTtuTwHSaEWFdw+A==} + dependencies: + unicode-9.0.0: 0.7.0 + dev: false + /last-run@1.1.1: resolution: {integrity: sha512-U/VxvpX4N/rFvPzr3qG5EtLKEnNI0emvIQB3/ecEwv+8GHaUKbIB8vxv1Oai5FAF0d0r7LXHhLLe5K/yChm5GQ==} engines: {node: '>= 0.10'} @@ -17384,7 +17396,6 @@ packages: resolution: {integrity: sha512-u26CNoaInA4XpDU+8s/6Cq8xHc2T5M4fXB3ICfXPokUQoLzmPgSZU02TAkFwFMJCWTjk53gtkS8pETTreZwCqw==} engines: {node: '>= 12.10.0', npm: '>= 6.12.0', yarn: '>= 1.20.0'} hasBin: true - dev: true /titleize@3.0.0: resolution: {integrity: sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==} @@ -18032,6 +18043,11 @@ packages: busboy: 1.6.0 dev: false + /unicode-9.0.0@0.7.0: + resolution: {integrity: sha512-aqL0GQ3LB2nC3ZEKBZ93hfn7QY80sVGk+OT9Sc6lTxl4wRiwzUBRlAjJB9Fe4+5XydXOV+tb8udp5oRBoED5Tw==} + deprecated: Use @unicode/unicode-9.0.0 instead. + dev: false + /unicode-emoji-json@0.4.0: resolution: {integrity: sha512-lVNOwh2AnmbwqtSrEVjAWKQoVzWgyWmXVqPuPkPfKb0tnA0+uYN/4ILCTdy9IRj/+3drAVhmjwjNJQr2dhCwnA==} dev: true