mirror of
https://github.com/alexankitty/Myrient-Search-Engine.git
synced 2026-01-15 16:33:15 -03:00
reorganize project, fix a couple of miscellaneous issues.
This commit is contained in:
66
server.js
66
server.js
@@ -1,38 +1,38 @@
|
||||
import getAllFiles from "./lib/dircrawl.js";
|
||||
import { optimizeDatabaseKws } from "./lib/dboptimize.js";
|
||||
import FileHandler from "./lib/filehandler.js";
|
||||
import Searcher from "./lib/search.js";
|
||||
import getAllFiles from "./lib/crawler/dircrawl.js";
|
||||
import { optimizeDatabaseKws } from "./lib/database/dboptimize.js";
|
||||
import FileHandler from "./lib/crawler/filehandler.js";
|
||||
import Searcher from "./lib/search/search.js";
|
||||
import cron from "node-cron";
|
||||
import "dotenv/config";
|
||||
import express from "express";
|
||||
import http from "http";
|
||||
import sanitize from "sanitize";
|
||||
import debugPrint from "./lib/debugprint.js";
|
||||
import debugPrint from "./lib/utility/printutils.js";
|
||||
import compression from "compression";
|
||||
import cookieParser from "cookie-parser";
|
||||
import { generateAsciiArt } from "./lib/asciiart.js";
|
||||
import { generateAsciiArt } from "./lib/utility/asciiart.js";
|
||||
import {
|
||||
getEmulatorConfig,
|
||||
isEmulatorCompatible,
|
||||
isNonGameContent,
|
||||
} from "./lib/emulatorConfig.js";
|
||||
} from "./lib/emulator/emulatorConfig.js";
|
||||
import fetch from "node-fetch";
|
||||
import { initDB, File, QueryCount, Metadata } from "./lib/database.js";
|
||||
import { initDB, File, QueryCount, Metadata } from "./lib/database/database.js";
|
||||
import { initElasticsearch } from "./lib/services/elasticsearch.js";
|
||||
import i18n, { locales } from "./config/i18n.js";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import MetadataSearch from "./lib/metadatasearch.js";
|
||||
import Flag from "./lib/flag.js";
|
||||
import ConsoleIcons from "./lib/consoleicons.js";
|
||||
import Flag from "./lib/images/flag.js";
|
||||
import ConsoleIcons from "./lib/images/consoleicons.js";
|
||||
import MetadataManager from "./lib/crawler/metadatamanager.js";
|
||||
|
||||
let categoryListPath = "./lib/categories.json";
|
||||
let nonGameTermsPath = "./lib/nonGameTerms.json";
|
||||
let emulatorsPath = "./lib/emulators.json";
|
||||
let localeNamePath = "./lib/json/maps/name_localization.json"
|
||||
let categoryListPath = "./lib/json/terms/categories.json";
|
||||
let nonGameTermsPath = "./lib/json/terms/nonGameTerms.json";
|
||||
let emulatorsPath = "./lib/json/dynamic_content/emulators.json";
|
||||
let localeNamePath = "./lib/json/maps/name_localization.json";
|
||||
let categoryList = await FileHandler.parseJsonFile(categoryListPath);
|
||||
let nonGameTerms = await FileHandler.parseJsonFile(nonGameTermsPath);
|
||||
let emulatorsData = await FileHandler.parseJsonFile(emulatorsPath);
|
||||
let localeNames = await FileHandler.parseJsonFile(localeNamePath)
|
||||
let localeNames = await FileHandler.parseJsonFile(localeNamePath);
|
||||
let crawlTime = 0;
|
||||
let queryCount = 0;
|
||||
let fileCount = 0;
|
||||
@@ -40,7 +40,6 @@ let indexPage = "pages/index";
|
||||
let flags = new Flag();
|
||||
let consoleIcons = new ConsoleIcons(emulatorsData);
|
||||
|
||||
|
||||
// Initialize databases
|
||||
await initDB();
|
||||
await initElasticsearch();
|
||||
@@ -73,11 +72,11 @@ for (let field in searchFields) {
|
||||
}
|
||||
|
||||
let search = new Searcher(searchFields);
|
||||
let metadataSearch = new MetadataSearch();
|
||||
let metadataManager = new MetadataManager();
|
||||
|
||||
async function getFilesJob() {
|
||||
console.log("Updating the file list.");
|
||||
let oldFileCount = fileCount || 0
|
||||
let oldFileCount = fileCount || 0;
|
||||
fileCount = await getAllFiles(categoryList);
|
||||
if (!fileCount) {
|
||||
console.log("File update failed");
|
||||
@@ -85,16 +84,16 @@ async function getFilesJob() {
|
||||
}
|
||||
crawlTime = Date.now();
|
||||
console.log(`Finished updating file list. ${fileCount} found.`);
|
||||
if(await Metadata.count() < await metadataSearch.getIGDBGamesCount()){
|
||||
await metadataSearch.syncAllMetadata();
|
||||
if ((await Metadata.count()) < (await metadataManager.getIGDBGamesCount())) {
|
||||
await metadataManager.syncAllMetadata();
|
||||
}
|
||||
if(fileCount > oldFileCount){
|
||||
await metadataSearch.matchAllMetadata()
|
||||
if (fileCount > oldFileCount) {
|
||||
await metadataManager.matchAllMetadata();
|
||||
}
|
||||
await optimizeDatabaseKws();
|
||||
//this is less important and needs to run last.
|
||||
if(fileCount > oldFileCount){
|
||||
metadataSearch.matchAllMetadata(true)
|
||||
if (fileCount > oldFileCount) {
|
||||
metadataManager.matchAllMetadata(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +219,7 @@ app.get("/search", async function (req, res) {
|
||||
delete settings.combineWith;
|
||||
}
|
||||
let loadOldResults =
|
||||
req.query.old === "true" || !await Metadata.count() ? true : false;
|
||||
req.query.old === "true" || !(await Metadata.count()) ? true : false;
|
||||
settings.pageSize = loadOldResults ? 100 : 10;
|
||||
settings.page = pageNum - 1;
|
||||
settings.sort = req.query.o || "";
|
||||
@@ -243,7 +242,7 @@ app.get("/search", async function (req, res) {
|
||||
settings: settings,
|
||||
flags: flags,
|
||||
consoleIcons: consoleIcons,
|
||||
localeNames: localeNames
|
||||
localeNames: localeNames,
|
||||
};
|
||||
let page = loadOldResults ? "resultsold" : "results";
|
||||
options = buildOptions(page, options);
|
||||
@@ -278,7 +277,7 @@ app.get("/lucky", async function (req, res) {
|
||||
app.get("/settings", async function (req, res) {
|
||||
let options = { defaultSettings: defaultSettings };
|
||||
let page = "settings";
|
||||
options.oldSettingsAvailable = await Metadata.count() ? true : false;
|
||||
options.oldSettingsAvailable = (await Metadata.count()) ? true : false;
|
||||
options = buildOptions(page, options);
|
||||
res.render(indexPage, options);
|
||||
});
|
||||
@@ -333,10 +332,6 @@ app.get("/play/:id", async function (req, res) {
|
||||
app.get("/info/:id", async function (req, res) {
|
||||
//set header to allow video embed
|
||||
res.setHeader("Cross-Origin-Embedder-Policy", "unsafe-non");
|
||||
if (!metadataSearch.authorized) {
|
||||
res.redirect("/");
|
||||
return;
|
||||
}
|
||||
let romId = parseInt(req.params.id);
|
||||
let romFile = await search.findIndex(romId);
|
||||
if (!romFile) {
|
||||
@@ -345,14 +340,14 @@ app.get("/info/:id", async function (req, res) {
|
||||
}
|
||||
let options = {
|
||||
file: {
|
||||
...romFile.dataValues
|
||||
...romFile.dataValues,
|
||||
},
|
||||
metadata: {
|
||||
...romFile?.details?.dataValues
|
||||
...romFile?.details?.dataValues,
|
||||
},
|
||||
flags: flags,
|
||||
consoleIcons: consoleIcons,
|
||||
localeNames: localeNames
|
||||
localeNames: localeNames,
|
||||
};
|
||||
let page = "info";
|
||||
options = buildOptions(page, options);
|
||||
@@ -579,4 +574,3 @@ if (
|
||||
}
|
||||
|
||||
cron.schedule("0 30 2 * * *", getFilesJob);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user