blob: 95813b61af40d9a97b562590c674bc07e870e86a (
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
|
const fs = require("fs").promises
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 => [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.tags = _ => {
const tags = {"*": []}
return module.exports.doujins()
.then(doujins => Object.values(doujins))
.then(doujins => doujins
.forEach(doujin => {
tags["*"].push(doujin.title)
doujin.tag && doujin.tag.forEach(tag => {
tags[tag] = tags[tag] || []
tags[tag].push(doujin.title)
})
}))
.then(_ => tags)
}
|