blob: 2d8382e0b0c8022eb8a7ee2a6903b39d0fd889ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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))
.then(doujins => Object.fromEntries(doujins))
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 =>
criteriaKeys.forEach(crit => {
criteria[crit]["*"].push(doujin.title)
doujin[crit] && doujin[crit].forEach(val => {
criteria[crit][val] = criteria[crit][val] || []
criteria[crit][val].push(doujin.title)
})
})
))
.then(_ => criteria)
}
|