Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found

Cible

Sélectionner le projet cible
  • bakaclub/amadeus
1 résultat
Afficher les modifications
Validations sur la source (4)
const logger = require.main.require('./common/logger.js'); const logger = require.main.require('./common/logger.js');
const config = require.main.require('./common/config.js'); const config = require.main.require('./common/config.js');
const MiniSearch = require("minisearch")
var sqlite3 = require.main.require('sqlite3').verbose(); var sqlite3 = require.main.require('sqlite3').verbose();
/* The kara table is defined as follows: /* The kara table is defined as follows:
...@@ -48,6 +49,26 @@ class KaraDatabase { ...@@ -48,6 +49,26 @@ class KaraDatabase {
this.m_karaPath = config.content.database.path; this.m_karaPath = config.content.database.path;
this.m_db = new sqlite3.Database(this.m_karaPath); this.m_db = new sqlite3.Database(this.m_karaPath);
this.m_db.configure('busyTimeout', 50000); this.m_db.configure('busyTimeout', 50000);
this.m_search_engine = new MiniSearch({
fields: [
"id",
"cat",
"type",
"language",
"author",
"title",
"source"
], // fields to index for full-text search
storeFields: [
"id",
"cat",
"type",
"language",
"author",
"title",
"source"
] // fields to return with search results
})
logger.info('db', 'Create database from file ' + config.content.database.path); logger.info('db', 'Create database from file ' + config.content.database.path);
} }
...@@ -57,55 +78,28 @@ class KaraDatabase { ...@@ -57,55 +78,28 @@ class KaraDatabase {
logger.info('db', `Close database ${this.m_karaPath}`); logger.info('db', `Close database ${this.m_karaPath}`);
} }
/* Search from the kara table, a string. Can be anything (query, name, /* Search for karas with the search engine
* language, source, etc).
* - queryString: String * - queryString: String
* - limit: Int | null -> maximal number of results * => A list of search results [(id: Int, string, cat, type, language, author, title, source)] */
* - offset: Int | null -> offset in the search search(queryString) {
* => a promize, callback with [(id: Int, string, cat, type, language, author, title, source)] */ let searchResult = this.m_search_engine.search(queryString, {
search(queryString, offset = null, limit = null) { prefix: term => term.length,
var __ret = []; fuzzy: term => term.length > 3 ? 0.2 : null,
var __sqlQuery = `SELECT id, string, combineWith: 'AND'
category AS cat, })
(song_type || song_number) AS type, return searchResult;
language, author_name AS author,
song_name AS title, source_name AS source, available
FROM kara
WHERE string LIKE ? OR author_name COLLATE nocase = ?`;
if (offset != null && limit != null) __sqlQuery += ` LIMIT ${offset}, ${limit}`;
function __getRecords(db) {
return new Promise(resolv => {
db.all(__sqlQuery, [`%${queryString}%`, queryString], (err, rows) => {
if (err) {
logger.error('db', err);
throw err;
}
rows.forEach(row => {
__ret.push(row);
});
resolv(__ret);
});
});
}
return __getRecords(this.m_db);
} }
/* List all the kara in the db. /* Initiate the search engine with the db
* - limit: Int | null -> maximal number of results * => a promize */
* - offset: Int | null -> offset in the search setup_search_engine() {
* => a promize, callback with [(id: Int, string, cat, type, language, author, title, source)] */
all(offset = null, limit = null) {
var __ret = []; var __ret = [];
var __sqlQuery = `SELECT id, string, var __sqlQuery = `SELECT id,
category AS cat, category AS cat,
(song_type || song_number) AS type, (song_type || song_number) AS type,
language, author_name AS author, language, author_name AS author,
song_name AS title, source_name AS source, available song_name AS title, source_name AS source
FROM kara`; FROM kara`;
if (offset != null && limit != null) __sqlQuery += ` LIMIT ${offset}, ${limit}`;
function __getRecords(db) { function __getRecords(db) {
return new Promise(resolv => { return new Promise(resolv => {
db.all(__sqlQuery, [], (err, rows) => { db.all(__sqlQuery, [], (err, rows) => {
...@@ -121,7 +115,14 @@ class KaraDatabase { ...@@ -121,7 +115,14 @@ class KaraDatabase {
}); });
} }
return __getRecords(this.m_db); function __SetupSE(karas, search_engine = db.m_search_engine){
search_engine.removeAll()
logger.info("db", karas.length)
search_engine.addAll(karas)
logger.info("db", search_engine.documentCount)
}
return __getRecords(this.m_db).then(__SetupSE);
} }
/* List all the next karas in the queue. /* List all the next karas in the queue.
......
...@@ -96,9 +96,6 @@ window.onload = () => { ...@@ -96,9 +96,6 @@ window.onload = () => {
addIpcToButton('commandStop', ['cmd-stop']); addIpcToButton('commandStop', ['cmd-stop']);
addIpcToButton('commandClear', ['cmd-clear']); addIpcToButton('commandClear', ['cmd-clear']);
addIpcToButton('selectAdvence', ['select-advence']);
addIpcToButton('selectDatabase', ['select-database', 'reload-db-request']);
addIpcToButton('selectPlaylist', ['select-playlist']);
addIpcToButton('updateDB', ['update-database']); addIpcToButton('updateDB', ['update-database']);
addIpcToButton('dryUpdate', ['dry-update-database']); addIpcToButton('dryUpdate', ['dry-update-database']);
...@@ -119,15 +116,13 @@ window.onload = () => { ...@@ -119,15 +116,13 @@ window.onload = () => {
ipcRenderer.send('verify-lektord'); ipcRenderer.send('verify-lektord');
logger.debug('instance', 'Window loaded'); logger.debug('instance', 'Window loaded');
document.getElementById('filterInput').addEventListener('input', e => {
$('#filterInput').on('keypress', e => {
/* On 'Return'. */ /* On 'Return'. */
if (e.which != 13) return;
logger.debug('instance', `Send filter for: ${$('#filterInput').val()}`); logger.debug('instance', `Send filter for: ${$('#filterInput').val()}`);
ipcRenderer.send('reload-db-request', { ipcRenderer.send('reload-db-request', {
search: `${$('#filterInput').val()}`, search: `${$('#filterInput').val()}`,
}); });
}); })
document.addEventListener( document.addEventListener(
'keydown', 'keydown',
......
...@@ -7,9 +7,6 @@ ...@@ -7,9 +7,6 @@
{id: 'commandClear', tooltip: 'Clear the queue', name: 'eraser'}, {id: 'commandClear', tooltip: 'Clear the queue', name: 'eraser'},
]}); %></div> ]}); %></div>
<div class="btn-group" role="group"><%- include('menubar/buttons.ejs', {type: 'secondary', buttons: [ <div class="btn-group" role="group"><%- include('menubar/buttons.ejs', {type: 'secondary', buttons: [
{id: 'selectAdvence', tooltip: 'Advence search', name: 'search'},
{id: 'selectDatabase', tooltip: 'Database search', name: 'database'},
{id: 'selectPlaylist', tooltip: 'Playlist search', name: 'tag'},
{id: 'dryUpdate', tooltip: "Update kara Database", name: 'sync'}, {id: 'dryUpdate', tooltip: "Update kara Database", name: 'sync'},
{id: 'updateDB', tooltip: "Update and download kara Database", name: 'arrow-circle-down'}, {id: 'updateDB', tooltip: "Update and download kara Database", name: 'arrow-circle-down'},
{id: 'addResearchToQueue', tooltip: "Add research result to queue", name: 'upload'}, {id: 'addResearchToQueue', tooltip: "Add research result to queue", name: 'upload'},
......
...@@ -165,6 +165,10 @@ function createKurisuWindow() { ...@@ -165,6 +165,10 @@ function createKurisuWindow() {
kurisu.once('ready-to-show', () => kurisu.show()); kurisu.once('ready-to-show', () => kurisu.show());
} }
function setupKaraDB(){
db.setup_search_engine()
}
/****************************** /******************************
* The end of the application * * The end of the application *
******************************/ ******************************/
...@@ -239,18 +243,19 @@ ipcMain.on('dry-update-database', () => lkt.commandDryUpdateDatabase()); ...@@ -239,18 +243,19 @@ ipcMain.on('dry-update-database', () => lkt.commandDryUpdateDatabase());
/* Fill the pannel with the content of the DB. /* Fill the pannel with the content of the DB.
* The `arg` is the HTML object of the pannel */ * The `arg` is the HTML object of the pannel */
ipcMain.on('reload-db-request', (event, arg) => { ipcMain.on('reload-db-request', (event, arg) => {
logger.info('main', 'Reloading the DB content');
const callback = karas => event.reply('reload-db-responce', karas); const callback = karas => event.reply('reload-db-responce', karas);
if (arg && arg.search && arg.search !== '') { if (arg && arg.search && arg.search !== '') {
__lastFilter = arg.search; __lastFilter = arg.search;
logger.debug('main', `Reload DB with search '${arg}'`); logger.debug('main', `Reload DB with search '${arg}'`);
db.search(__lastFilter, 0, 100).then(callback); karas = db.search(__lastFilter);
callback(karas);
} else if ((arg && arg.search === '') || __lastFilter === '') { } else if ((arg && arg.search === '') || __lastFilter === '') {
__lastFilter = ''; __lastFilter = '';
callback([]); callback([]);
} else { } else {
logger.debug('main', `Reload DB with last filter '${__lastFilter}'`); logger.debug('main', `Reload DB with last filter '${__lastFilter}'`);
db.search(__lastFilter, 0, 100).then(callback); karas = db.search(__lastFilter);
callback(karas);
} }
}); });
...@@ -344,6 +349,7 @@ ipcMain.on('verify-lektord', (event, arg) => { ...@@ -344,6 +349,7 @@ ipcMain.on('verify-lektord', (event, arg) => {
}); });
lkt.reloadState(); lkt.reloadState();
setupKaraDB();
loopTimeouts.concat([ loopTimeouts.concat([
setTimeout(() => lkt.idleActualisation(), 1000), setTimeout(() => lkt.idleActualisation(), 1000),
...@@ -430,11 +436,13 @@ ipcMain.on('verify-lektord', (event, arg) => { ...@@ -430,11 +436,13 @@ ipcMain.on('verify-lektord', (event, arg) => {
}); });
} }
} }
}, 50);
setInterval(() => {
if (lkt.isDBUpdated()) { if (lkt.isDBUpdated()) {
lkt.setDBUpdated(false); lkt.setDBUpdated(false);
win.webContents.send('check-db-updated'); setupKaraDB();
} }
}, 50); }, 5000)
setInterval(() => { setInterval(() => {
if (currentPlaylist != '' && lkt.isPlaylistsUpdated()) { if (currentPlaylist != '' && lkt.isPlaylistsUpdated()) {
......
...@@ -12,22 +12,22 @@ ...@@ -12,22 +12,22 @@
], ],
"license": "ISC", "license": "ISC",
"scripts": { "scripts": {
"start": "electron -- --trace-uncaught . --trace-uncaught" "start": "electron --no-sandbox -- --trace-uncaught . --trace-uncaught"
}, },
"dependencies": { "dependencies": {
"ejs": "^3.1.5", "ejs": "^3.1.5",
"electron": "^10.1.1", "electron": "^26.1.1",
"electron-ejs": "^1.2.1", "electron-ejs": "^1.2.1",
"electron-prompt": "^1.6.2",
"express": "^4.17.1", "express": "^4.17.1",
"ini": "^2.0.0", "ini": "^2.0.0",
"node": "<14.0.0 ", "minisearch": "^6.1.0",
"node": ">14.0.0 ",
"sqlite3": "5.0.0", "sqlite3": "5.0.0",
"tail": "^2.0.4", "tail": "^2.0.4",
"winston": "^3.3.3", "winston": "^3.3.3"
"electron-prompt": "^1.6.2"
}, },
"config": { "config": {
"port": "8080",
"kurisu": "https://kurisu.iiens.net/" "kurisu": "https://kurisu.iiens.net/"
}, },
"devDependencies": { "devDependencies": {
......