From fa4480a51885ed6b8a2ed85032a20778825c897f Mon Sep 17 00:00:00 2001 From: Alexandra Date: Tue, 22 Oct 2024 03:21:37 -0600 Subject: [PATCH] disable debug --- .env | 2 +- lib/search.js | 2 +- server.js | 56 +++++++++++++++++++++++++-------------------------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/.env b/.env index 81302fd..2b85128 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ PORT=8062 BIND_ADDRESS=0.0.0.0 FORCE_FILE_REBUILD=0 -DEBUG=1 \ No newline at end of file +DEBUG=0 \ No newline at end of file diff --git a/lib/search.js b/lib/search.js index 433996d..1be54c6 100644 --- a/lib/search.js +++ b/lib/search.js @@ -8,7 +8,7 @@ export default class Searcher{ this.indexing = false fields.push('id') this.fields = fields - this.createIndex(fileArr, fields) + this.createIndex(fileArr) } async findAllMatches(query, options){ diff --git a/server.js b/server.js index 7156d25..ce87aee 100644 --- a/server.js +++ b/server.js @@ -53,11 +53,11 @@ async function getFilesJob() { await FileHandler.saveJsonFile(fileListPath, fileList); fileCount = fileList.length; if (typeof search == "undefined") { - await search.createIndex(fileList) - }else{ - await search.updateIndex(fileList) + await search.createIndex(fileList); + } else { + await search.updateIndex(fileList); } - fileList = [] + fileList = []; crawlTime = await FileHandler.fileTime(fileListPath); console.log(`Finished updating file list. ${fileCount} found.`); } @@ -76,14 +76,13 @@ if ( fileList = await FileHandler.parseJsonFile(fileListPath); fileCount = fileList.length; search = new Searcher(fileList, searchFields); - fileList = [] + fileList = []; } - let defaultOptions = { crawlTime: crawlTime, queryCount: queryCount, - fileCount: fileCount + fileCount: fileCount, }; let app = express(); @@ -98,32 +97,31 @@ app.get("/", function (req, res) { app.get("/search", async function (req, res) { let query = req.query.q ? req.query.q : ""; - let settings = {} - try{ + let settings = {}; + try { settings = req.query.s ? JSON.parse(atob(req.query.s)) : defaultSettings; + } catch { + debugPrint("Search settings corrupt, forcing default."); + settings = defaultSettings; } - catch{ - debugPrint('Search settings corrupt, forcing default.') - settings = defaultSettings - } - for(let key in defaultSettings){ - let failed = false - if(typeof settings[key] != 'undefined'){ - if(typeof settings[key] != typeof defaultSettings[key]){ - debugPrint('Search settings corrupt, forcing default.') - failed = true - break + for (let key in defaultSettings) { + let failed = false; + if (typeof settings[key] != "undefined") { + if (typeof settings[key] != typeof defaultSettings[key]) { + debugPrint("Search settings corrupt, forcing default."); + failed = true; + break; } } - if(failed){ - settings = defaultSettings + if (failed) { + settings = defaultSettings; } } - if (settings.combineWith != 'AND') { + if (settings.combineWith != "AND") { delete settings.combineWith; //remove if unset to avoid crashing } let results = await search.findAllMatches(query, settings); - debugPrint(results) + debugPrint(results); let options = { query: query, results: results, @@ -137,18 +135,18 @@ app.get("/search", async function (req, res) { }); app.get("/lucky", async function (req, res) { - let results = [] - if(req.query.q){ + let results = []; + if (req.query.q) { let settings = req.query.s ? JSON.parse(req.query.s) : defaultSettings; results = await search.findAllMatches(req.query.q, settings); - debugPrint(results) + debugPrint(results); } if (results.length) { res.redirect(results.items[0].path); } else { const magicNum = Math.floor(Math.random() * search.getIndexSize()); - const luckyPath = search.findIndex(magicNum).path - debugPrint(`${magicNum}: ${luckyPath}`) + const luckyPath = search.findIndex(magicNum).path; + debugPrint(`${magicNum}: ${luckyPath}`); res.redirect(luckyPath); } });