diff --git a/lib/categories.json b/lib/categories.json index b1e31bf..36aea8c 100644 --- a/lib/categories.json +++ b/lib/categories.json @@ -362,33 +362,47 @@ ] }, "Types": [ - "BIOS", - "BigEndian", - "ByteSwapped", - "CBZ", - "DLC", - "Decrypted", - "Development Kit", - "Digital", - "Disc Keys", - "GameShark", - "Header", - "Headerless", - "LittleEndian", - "NKit", - "NoNpDrm", - "PDF", - "PS one Classics", - "PSN", - "PSX2PSP", - "RAW", - "Source Code", - "UMD Music", - "UMD Video", - "Updates and DLC", - "Updates", - "VPK", - "Visual Memory Unit", - "WUX" + "(BIOS)", + "(BigEndian)", + "(ByteSwapped)", + "(CBZ)", + "(DLC)", + "(Decrypted)", + "(Development Kit)", + "(Digital)", + "(Disc Keys)", + "(GameShark)", + "(Header)", + "(Headerless)", + "(LittleEndian)", + "(NKit)", + "(NoNpDrm)", + "(PDF)", + "(PS one Classics)", + "(PSN)", + "(PSX2PSP)", + "(RAW)", + "(Source Code)", + "(UMD Music)", + "(UMD Video)", + "(Updates and DLC)", + "(Updates)", + "(VPK)", + "(Visual Memory Unit)", + "(WUX)" + ], + "Regions": [ + "USA", + "Europe", + "Germany", + "Italy", + "Korea", + "Spain", + "France", + "Japan", + "Brazil", + "World", + "UK", + "Asia" ] } \ No newline at end of file diff --git a/lib/dircrawl.js b/lib/dircrawl.js index 0b7241b..ceed55a 100644 --- a/lib/dircrawl.js +++ b/lib/dircrawl.js @@ -59,6 +59,7 @@ async function getFilesAndFolders(url, catList, base = ""){ category: findCategory(base + name, catList), type: findType(base + name, catList), date: innertext(fileList[x].querySelector('.date').innerHTML).trim(), + region: findRegion(base + name, catList) }) } return fileArray @@ -98,12 +99,13 @@ function singleLineStatus(str){ } function findCategory(str, catList){ + let lowerStr = str.toLowerCase() let foundCat = '' let catLength = 0 let foundSubCat = '' let subCatLength = 0 for(let cat in catList.Categories){ - if(str.includes(cat)){ + if(lowerStr.includes(cat.toLowerCase())){ if(cat.length > catLength){ foundCat = cat catLength = cat.length @@ -112,10 +114,11 @@ function findCategory(str, catList){ } if(foundCat){ for(let subCat in catList.Categories[foundCat]){ - if(str.includes(subCat)){ - if(subCat.length > subCatLength){ - foundSubCat = catList.Categories[foundCat][subCat] - subCatLength = subCat.length + let subCatString = catList.Categories[foundCat][subCat] //I will go insane if this is inlined repeatedly + if(lowerStr.includes(subCatString.toLowerCase())){ + if(subCatString.length > subCatLength){ + foundSubCat = subCatString + subCatLength = subCatString.length } } } @@ -123,15 +126,37 @@ function findCategory(str, catList){ else{ return 'Other' } - return `${foundCat} ${foundSubCat}` + return `${foundCat} ${foundSubCat}`.trim() } function findType(str, catList){ + let lowerStr = str.toLowerCase() let foundTypes = '' for(let type in catList.Types){ - if(str.includes(type)){ - foundTypes += `(${catList.Types[type]}) ` + let typeString = catList.Types[type] //including here + if(lowerStr.includes(typeString.toLowerCase())){ + foundTypes += `${typeString} ` } } return foundTypes.trim() +} + +function findRegion(str, catList){ + let lowerStr = str.toLowerCase() + let foundRegions = '' + for(let region in catList.Regions){ + let regionString = catList.Regions[region] //including here + if(lowerStr.includes(regionString.toLowerCase())){ + if(foundRegions){ + foundRegions += `, ${regionString}` + } + else{ + foundRegions += `${regionString}` + } + } + } + if(!foundRegions){ + return "None" + } + return foundRegions.trim() } \ No newline at end of file diff --git a/lib/search.js b/lib/search.js index 32efb1a..4a5c762 100644 --- a/lib/search.js +++ b/lib/search.js @@ -24,7 +24,7 @@ export default class Searcher{ createIndex(fileArr){ this.miniSearch = new MiniSearch({ fields: ['name', 'category', 'type'], - storeFields: ['name', 'category', 'type', 'date', 'size'], + storeFields: ['filename', 'category', 'type', 'date', 'size', 'region'], searchOptions: { boost: { name: 2 }, fuzzy: this.distance, diff --git a/server.js b/server.js index dcb0965..e02ed1c 100644 --- a/server.js +++ b/server.js @@ -17,6 +17,9 @@ async function getFilesJob(){ console.log('Updating the file list.') fileList = await getAllFiles(categoryList) saveJsonFile(fileListPath, fileList) + if(search){ + search.createIndex(fileList) //recreate the search index + } console.log(`Finished updating file list. ${fileList.length} found.`) } diff --git a/views/pages/results.ejs b/views/pages/results.ejs index 84b2a6b..b3aac0a 100644 --- a/views/pages/results.ejs +++ b/views/pages/results.ejs @@ -22,7 +22,8 @@ _ / / / _ /_/ /_ / _ / / __/ / / / /_