feat: add optional Laya engine mode for grouping and language detection (#12)
Add a languageDetectionMode setting (algo | laya | laya+algo) exposed in Settings with three engine choices. When Laya is enabled, a laya service (Dockerfile.laya, optional compose profile, models stored outside the repo under ./data/models/laya) can be started, with model download and deletion from the UI via /laya routes to manage disk space. Add a channelLanguageFusion service combining Laya results with the existing algorithm, and wire detection mode through grouping, channel list and player. Cover engine selection, fusion and laya service behavior with tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -135,6 +135,18 @@ function initSchema() {
|
||||
CREATE INDEX IF NOT EXISTS idx_history_user_item ON watch_history(user_id, item_id);
|
||||
`);
|
||||
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS laya_language_cache (
|
||||
cache_key TEXT PRIMARY KEY,
|
||||
mode TEXT NOT NULL,
|
||||
model TEXT NOT NULL,
|
||||
response TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_laya_cache_mode_model
|
||||
ON laya_language_cache(mode, model);
|
||||
`);
|
||||
|
||||
// Migration: Add source_id column if missing (for existing databases)
|
||||
try {
|
||||
db.exec(`ALTER TABLE watch_history ADD COLUMN source_id INTEGER`);
|
||||
@ -209,8 +221,32 @@ const favorites = {
|
||||
}
|
||||
};
|
||||
|
||||
const layaLanguageCache = {
|
||||
get(cacheKey) {
|
||||
const row = getDb().prepare(
|
||||
'SELECT response FROM laya_language_cache WHERE cache_key = ?'
|
||||
).get(cacheKey);
|
||||
return row ? JSON.parse(row.response) : null;
|
||||
},
|
||||
|
||||
set(cacheKey, mode, model, response) {
|
||||
getDb().prepare(`
|
||||
INSERT INTO laya_language_cache (cache_key, mode, model, response, created_at)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
ON CONFLICT(cache_key) DO UPDATE SET
|
||||
response = excluded.response,
|
||||
created_at = excluded.created_at
|
||||
`).run(cacheKey, mode, model, JSON.stringify(response), Date.now());
|
||||
},
|
||||
|
||||
clear() {
|
||||
getDb().prepare('DELETE FROM laya_language_cache').run();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getDb,
|
||||
initSchema,
|
||||
favorites
|
||||
favorites,
|
||||
layaLanguageCache
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user