]> git.lizzy.rs Git - local-nhentai.git/blobdiff - info.js
Generic stats and select
[local-nhentai.git] / info.js
diff --git a/info.js b/info.js
index 95813b61af40d9a97b562590c674bc07e870e86a..2d8382e0b0c8022eb8a7ee2a6903b39d0fd889ef 100644 (file)
--- a/info.js
+++ b/info.js
@@ -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)
 }