feat: remove old site UI, replace with ktb

This commit is contained in:
nikomiko 2026-07-14 19:31:18 -04:00
parent 93b74d0179
commit d01128d54f
72 changed files with 772 additions and 31005 deletions

View file

@ -22,6 +22,7 @@
"@feathersjs/feathers": "^5.0.6",
"@google-cloud/local-auth": "^3.0.1",
"@repo/common": "workspace:*",
"cors": "^2.8.6",
"csv-parser": "^3.2.0",
"express": "^5.1.0",
"google-auth-library": "^9.15.1",
@ -34,6 +35,7 @@
},
"devDependencies": {
"@total-typescript/ts-reset": "^0.6.1",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.3",
"@types/node": "^22.5.1",
"tsx": "^4.19.4",

View file

@ -1,17 +1,16 @@
import "reflect-metadata";
import { SAMPLE } from "@repo/common/sample";
import express from "express";
import crypto from "crypto"
import fs from 'fs';
;import { appDataSource } from "./config/dbconfig.js";
import { Lemma, WordForm, Lect } from "./db/dbmodel.js";
import crypto from "crypto";
import fs from "fs";
import { appDataSource } from "./config/dbconfig.js";
import { Lemma, WordForm, Lect, Definition, Example } from "./db/dbmodel.js";
import "@total-typescript/ts-reset";
import {
Like, In
} from "typeorm";
import { Like, In } from "typeorm";
import cors from "cors";
const RELOAD_SHEET_ON_START = false;
const SOURCE_FILE = 'res/sample.tsv'
const SOURCE_FILE = "res/sample.tsv";
appDataSource
.initialize()
@ -32,6 +31,8 @@ function initExpress() {
const word_form_repository = appDataSource.getRepository(WordForm);
const lemma_repository = appDataSource.getRepository(Lemma);
app.use(cors(), express.json());
app.get("/sample", (_req, res) => {
res.status(200).send(SAMPLE);
});
@ -39,26 +40,28 @@ function initExpress() {
app.get("/search", async (req, res) => {
const search_term = req.query.search_term?.toString();
let word_forms: WordForm[];
let lemmas: Lemma[];
if (!search_term) {
return void res.sendStatus(400);
lemmas = await Lemma.find({
relations: { word_forms: { lect: true } }
});
} else {
word_forms = await WordForm.find({
where: { word_form: Like(`%${search_term}%`) },
relations: { lemma: true },
});
let lemma_ids = word_forms.map((w) => w.lemma.lemma_name);
lemmas = await Lemma.find({
where: { lemma_name: In(lemma_ids) },
relations: { word_forms: { lect: true } },
});
}
const word_forms: WordForm[] = await WordForm.find({
where:{word_form: Like(`%${search_term}%`)},
relations: { lemma: true }
});
let lemma_ids = word_forms.map(w=>w.lemma.lemma_name);
const lemmas: Lemma[] = await Lemma.find({
where: { lemma_name: In(lemma_ids)},
relations: { word_forms: { lect: true }}
})
res.status(200).send({
terms: lemmas.length,
results: lemmas
});
res.status(200).send({ terms: lemmas.length, results: lemmas });
});
app.get("/lect", async (req, res) => {
@ -78,9 +81,111 @@ function initExpress() {
app.get("/lects", async (_req, res) => {
const lects = await Lect.find();
res.status(200).send({
lects,
res.status(200).send({ lects });
});
app.get("/lemma-detail", async (_req, res) => {
const lemma_name = _req.query.lemma_name?.toString();
const lemma_detail = await Lemma.findOne({
where: {
lemma_name: lemma_name
},
relations: {
word_forms: {
lect: true
},
examples: true,
definitions: true,
media: true,
parts_of_speech: true
}
});
res.status(200).send({ lemma_detail });
});
app.put("/definition", async (_req, res) => {
const definition_text = _req.body.definition_text?.toString();
const lemma_name = _req.body.lemma_name?.toString();
if(definition_text == null || lemma_name == null){
console.error(`Error: ${JSON.stringify({definition_text:definition_text, lemma_name:lemma_name})}`);
return void res.status(400).send();
}
const lemma = await Lemma.findOne({where:{
lemma_name: lemma_name
}});
if(!lemma){
return void res.status(400).send();
}
var definition:Definition = new Definition();
definition.definition_text = definition_text;
definition.lemma = lemma;
Definition.save(definition)
var lemma_detail = await Lemma.findOne({
where: {
lemma_name: lemma_name
},
relations: {
word_forms: {
lect: true
},
examples: true,
definitions: true,
media: true,
parts_of_speech: true
}
});
res.status(200).send({lemma_detail});
});
app.put("/example", async (_req, res) => {
const example_text = _req.body.example_text?.toString();
const lemma_name = _req.body.lemma_name?.toString();
if(!example_text || !lemma_name){
return void res.status(400).send();
}
const lemma = await Lemma.findOne({where:{
lemma_name
}});
if(!lemma){
return void res.status(400).send();
}
var example:Example = new Example();
example.example_text = example_text;
example.lemma = lemma;
Example.save(example)
var lemma_detail = await Lemma.findOne({
where: {
lemma_name: lemma_name
},
relations: {
word_forms: {
lect: true
},
examples: true,
definitions: true,
media: true,
parts_of_speech: true
}
});
res.status(200).send({lemma_detail});
});
app.listen(PORT, () => {
@ -98,18 +203,17 @@ async function loadSheet() {
await lemma_repository.clear();
await lect_repository.clear();
const rawData: string = fs.readFileSync(SOURCE_FILE, 'utf8');
const rows: string[] = rawData.split('\n');
const rawData: string = fs.readFileSync(SOURCE_FILE, "utf8");
const rows: string[] = rawData.split("\n");
if (!rows || rows.length === 0) {
console.error("No data found.");
return;
}
const lect_names = rows.shift()?.split('\t');
const lect_names = rows.shift()?.split("\t");
const keys = rows.map(row=>row.split('\t')[0]?.split(';')[0]);
const keys = rows.map((row) => row.split("\t")[0]?.split(";")[0]);
console.log(keys);
if (keys.length != rows.length) {
@ -128,27 +232,27 @@ async function loadSheet() {
let l = new Lect();
l.name = lect;
l.save();
lects.push(l)
lects.push(l);
console.log(l);
}
const lemmas = Array<Lemma>();
for (let i = 0; i < rows.length; i++) {
const row = rows[i]?.split('\t');
const row = rows[i]?.split("\t");
const lect_name = lect_names[i];
if(!lect_name){
if (!lect_name) {
console.error("No lect name");
break;
}
if(!row){
if (!row) {
console.error("Row doesn't exist");
continue;
}
if(row.length !== lect_names.length){
if (row.length !== lect_names.length) {
console.error("Mismatched row size");
continue;
}
@ -175,10 +279,10 @@ async function loadSheet() {
const lect = lects[j];
if (
cell === null ||
cell === undefined ||
(typeof cell === "string" && cell.length === 0) ||
!lect
cell === null
|| cell === undefined
|| (typeof cell === "string" && cell.length === 0)
|| !lect
) {
continue;
}