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