diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-04 16:58:22 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-04 16:58:22 +0200 |
commit | 8faa84d56730bd1fc35b10d3d29db424691e3af5 (patch) | |
tree | f5e1e4d6ae6e5fd639f6ddc511fd9cf866789e72 /info.js | |
parent | 8a0a187b31a3e0e9b9faed1369441576a2b1d103 (diff) | |
download | local-nhentai-master.tar.xz |
Diffstat (limited to 'info.js')
-rw-r--r-- | info.js | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -1,30 +1,34 @@ const fs = require("fs").promises +const criteriaKeys = ["tag", "group", "artist", "character", "parody"] module.exports.doujins = shortNames => fs.readdir(".", {encoding: "utf8", withFileTypes: true}) .then(doujins => doujins .map(dirent => fs.readFile(`${dirent.name}/metadata.json`) .then(data => JSON.parse(data.toString())) + .then(data => {data.title = dirent.name; return data}) .then(data => [dirent.name, data]) .catch(_ => []))) .then(promises => Promise.all(promises)) .then(doujins => doujins - .filter(([title, data]) => title && data) - .filter(([title, data]) => (title == data.title) == !shortNames)) + .filter(([title, data]) => title && data)) + //.filter(([title, data]) => (title == data.title) == !shortNames)) .then(doujins => Object.fromEntries(doujins)) -module.exports.tags = _ => { - const tags = {"*": []} +module.exports.criteria = _ => { + const criteria = Object.fromEntries(criteriaKeys.map(key => [key, {["*"]: []}])) return module.exports.doujins() .then(doujins => Object.values(doujins)) .then(doujins => doujins - .forEach(doujin => { - tags["*"].push(doujin.title) + .forEach(doujin => + criteriaKeys.forEach(crit => { + criteria[crit]["*"].push(doujin.title) - doujin.tag && doujin.tag.forEach(tag => { - tags[tag] = tags[tag] || [] - tags[tag].push(doujin.title) + doujin[crit] && doujin[crit].forEach(val => { + criteria[crit][val] = criteria[crit][val] || [] + criteria[crit][val].push(doujin.title) + }) }) - })) - .then(_ => tags) + )) + .then(_ => criteria) } |