added easyOCR
This commit is contained in:
parent
37d6678577
commit
9f208b0606
27 changed files with 1780 additions and 112 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { logger } from '../util/logger.js';
|
||||
import type { LinkMode } from '../types.js';
|
||||
|
||||
export interface SavedLink {
|
||||
url: string;
|
||||
name: string;
|
||||
active: boolean;
|
||||
mode: LinkMode;
|
||||
addedAt: string;
|
||||
}
|
||||
|
||||
|
|
@ -55,10 +57,11 @@ export class ConfigStore {
|
|||
const parsed = JSON.parse(raw) as Partial<SavedSettings>;
|
||||
const merged = { ...DEFAULTS, ...parsed };
|
||||
// Migrate old links: add name/active fields, strip /live from URLs
|
||||
merged.links = merged.links.map((l) => ({
|
||||
merged.links = merged.links.map((l: any) => ({
|
||||
url: l.url.replace(/\/live\/?$/, ''),
|
||||
name: l.name || '',
|
||||
active: l.active !== undefined ? l.active : true,
|
||||
mode: l.mode || 'live',
|
||||
addedAt: l.addedAt || new Date().toISOString(),
|
||||
}));
|
||||
logger.info({ path: this.filePath, linkCount: merged.links.length }, 'Loaded config.json');
|
||||
|
|
@ -85,10 +88,10 @@ export class ConfigStore {
|
|||
return this.data.links;
|
||||
}
|
||||
|
||||
addLink(url: string, name: string = ''): void {
|
||||
addLink(url: string, name: string = '', mode: LinkMode = 'live'): void {
|
||||
url = url.replace(/\/live\/?$/, '');
|
||||
if (this.data.links.some((l) => l.url === url)) return;
|
||||
this.data.links.push({ url, name, active: true, addedAt: new Date().toISOString() });
|
||||
this.data.links.push({ url, name, active: true, mode, addedAt: new Date().toISOString() });
|
||||
this.save();
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +108,7 @@ export class ConfigStore {
|
|||
this.save();
|
||||
}
|
||||
|
||||
updateLinkById(id: string, updates: { name?: string; active?: boolean }): SavedLink | null {
|
||||
updateLinkById(id: string, updates: { name?: string; active?: boolean; mode?: LinkMode }): SavedLink | null {
|
||||
const link = this.data.links.find((l) => {
|
||||
const parts = l.url.split('/');
|
||||
return parts[parts.length - 1] === id;
|
||||
|
|
@ -113,6 +116,7 @@ export class ConfigStore {
|
|||
if (!link) return null;
|
||||
if (updates.name !== undefined) link.name = updates.name;
|
||||
if (updates.active !== undefined) link.active = updates.active;
|
||||
if (updates.mode !== undefined) link.mode = updates.mode;
|
||||
this.save();
|
||||
return link;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue