diff --git a/.env b/.env index d2ed41f..6c17a8f 100644 --- a/.env +++ b/.env @@ -3,9 +3,11 @@ BIND_ADDRESS=0.0.0.0 FORCE_FILE_REBUILD=0 DEBUG=0 NODE_ENV=production -# Memory Impacting Settings - Trades for threading efficiency. Much slower, but should be useful for limited memory environments like VPS +# Memory Impacting Settings - Trades for threading efficiency. Much slower, but should be useful for limited memory environments like VPS # May also decrease 504 failure rates # Changes the maximum number of jobs the crawler can queue. Setting it too high will cause a call stack overflow MAX_JOB_QUEUE=1000 # Changes the maximum number of pages that can be fetched for parsing. Has a massive impact on memory usage. Setting to 12 results in about 1.1GiB memory usage -MAX_FETCH_JOBS=1000 \ No newline at end of file +MAX_FETCH_JOBS=1000 +# Changes the name of your instance +INSTANCE_NAME=Myrient \ No newline at end of file diff --git a/lib/asciiart.js b/lib/asciiart.js new file mode 100644 index 0000000..af96600 --- /dev/null +++ b/lib/asciiart.js @@ -0,0 +1,9 @@ +import figlet from 'figlet'; + +export function generateAsciiArt(text) { + return figlet.textSync(text || process.env.INSTANCE_NAME || 'Myrient', { + font: 'Slant', + horizontalLayout: 'default', + verticalLayout: 'default' + }); +} diff --git a/lib/search.js b/lib/search.js index e94b63c..4a7c5a9 100644 --- a/lib/search.js +++ b/lib/search.js @@ -11,7 +11,7 @@ export default class Searcher{ } termProcessor(term){ - term = term.toLowerCase() + term = term.toLowerCase() let stringArray = [term] stringArray.push(...Searcher.stringBreakout(term)) for(let group in searchAlikes.StringAssoc){ @@ -25,7 +25,7 @@ export default class Searcher{ } } return [...new Set(stringArray)] - } + } static stringBreakout(string){ let symbolRegex = /-|_|\+|=|\)|\(|\[|{|}|]|;|:|"|'|<|>|\.|,|\/|\?|\||\\|!|@|#|\$|%|\^|&|\*/g @@ -62,7 +62,7 @@ export default class Searcher{ console.error(err) } } - + async createIndex(fileArr){ if(!this.miniSearch){ this.miniSearch = new MiniSearch({ @@ -157,7 +157,7 @@ export default class Searcher{ else { //bad result discard continue - } + } suggestions.push(`${query}${prediction}`) continue } @@ -178,10 +178,10 @@ export default class Searcher{ else { //bad result discard continue - } + } suggestions.push(`${query}${prediction}`) continue - } + } } let dedupe = [...new Set(suggestions)] let dedupeLimit = dedupe.length >= 10 ? 10 : dedupe.length @@ -190,7 +190,7 @@ export default class Searcher{ arr.push({ suggestion: dedupe[x] }) - } + } return arr } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d5b8f2f..98e09ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "dotenv": "^16.4.5", "ejs": "^3.1.10", "express": "^4.21.1", + "figlet": "^1.7.0", "file-older-than": "^1.0.0", "innertext": "^1.0.3", "jsdom": "^25.0.1", @@ -934,6 +935,18 @@ "node": "^12.20 || >= 14.13" } }, + "node_modules/figlet": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.8.0.tgz", + "integrity": "sha512-chzvGjd+Sp7KUvPHZv6EXV5Ir3Q7kYNpCr4aHrRW79qFtTefmQZNny+W1pW9kf5zeE6dikku2W50W/wAH2xWgw==", + "license": "MIT", + "bin": { + "figlet": "bin/index.js" + }, + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/file-older-than": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-older-than/-/file-older-than-1.0.0.tgz", diff --git a/package.json b/package.json index 7d1f490..3fa9957 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "node-fetch": "^3.3.2", "node-html-parser": "^6.1.13", "piscina": "^4.7.0", - "sanitize": "^2.1.2" + "sanitize": "^2.1.2", + "figlet": "^1.7.0" }, "type": "module" } diff --git a/server.js b/server.js index bfca882..1dce01a 100644 --- a/server.js +++ b/server.js @@ -8,7 +8,8 @@ import express from "express"; import http from "http"; import sanitize from "sanitize"; import debugPrint from "./lib/debugprint.js"; -import compression from "compression"; +import compression from "compression"; +import { generateAsciiArt } from './lib/asciiart.js'; let fileListPath = "./filelist.json"; let queryCountFile = "./queries.txt"; @@ -99,7 +100,8 @@ let defaultOptions = { crawlTime: crawlTime, queryCount: queryCount, fileCount: fileCount, - termCount: search.miniSearch.termCount + termCount: search.miniSearch.termCount, + generateAsciiArt: generateAsciiArt }; function updateDefaults(){ @@ -114,7 +116,7 @@ let server = http.createServer(app); app.use(sanitize.middleware); app.use(compression()) app.use(express.json()) -app.set("view engine", "ejs"); +app.set("view engine", "ejs"); app.get("/", function (req, res) { let page = "search"; @@ -209,6 +211,11 @@ app.post("/suggest", async function(req, res){ res.end(JSON.stringify({ suggestions })); }) +app.get("/about", function (req, res) { + let page = "about"; + res.render(indexPage, buildOptions(page)); +}); + server.listen(process.env.PORT, process.env.BIND_ADDRESS); server.on("listening", function () { console.log( diff --git a/views/pages/about.ejs b/views/pages/about.ejs new file mode 100644 index 0000000..9bcace0 --- /dev/null +++ b/views/pages/about.ejs @@ -0,0 +1,32 @@ +
+
+
+<%= generateAsciiArt() %>
+                                About
+    
+
+
+

About <%= process.env.INSTANCE_NAME || 'Myrient' %> Search

+

A search engine for Myrient - + a service by Erista dedicated to video game preservation.

+

Myrient offers organized and publicly available video game collections, keeping them from becoming + lost to time.

+

Not affiliated with Myrient/Erista!

+ +
+

If you like this project, please consider supporting Myrient:

+ Donate to Myrient +
+ +
+

Search engine created by Alexankitty

+

View project on GitHub

+ + Buy Me a Coffee at ko-fi.com + +
+
+
+
+
\ No newline at end of file diff --git a/views/pages/results.ejs b/views/pages/results.ejs index f2d527f..f79239a 100644 --- a/views/pages/results.ejs +++ b/views/pages/results.ejs @@ -1,4 +1,4 @@ -<% +<% let pageCount = Math.ceil(results.items.length / 100) pageCount = pageCount ? pageCount : 1 //always ensure 1 page if(pageNum > pageCount){ @@ -13,31 +13,26 @@ - +

Found <%= results.items.length %> result<%= results.items.length != 1 ? 's': '' %> in <%= results.elapsed %> seconds. <%= indexing ? "Indexing in progress, if the list is missing something please try reloading in a few minutes" : "" %>

- +

Displaying results <%= entryStart %> through <%= entryEnd %>.

@@ -80,7 +75,7 @@ _ / / / _ /_/ /_ / _ / / __/ / / / /_ <% } %>
- <% + <% if(pageCount > 1) { %>
@@ -88,7 +83,7 @@ _ / / / _ /_/ /_ / _ / / __/ / / / /_