2020-08-20 15:28:06 +02:00
|
|
|
class publiDB {
|
|
|
|
static async loadAsync() {
|
|
|
|
var db = new publiDB
|
|
|
|
const text = await getTextFromFileUrlAsync("/data/publis/index.yaml")
|
|
|
|
const myYaml = jsyaml.load(text);
|
|
|
|
db.sets = ((myYaml.sets === null) ? new Map() : new Map(Object.entries(myYaml.sets)));
|
|
|
|
db.others = ((myYaml.others === null) ? new Map() : new Map(Object.entries(myYaml.others)));
|
|
|
|
return db
|
|
|
|
}
|
|
|
|
static get UnknowSetName() {
|
|
|
|
return "Unknow set"
|
|
|
|
}
|
|
|
|
findNameFromSet(set, supportUnknow = false) {
|
|
|
|
if (supportUnknow && JSON.stringify(set) === JSON.stringify([""])) {
|
|
|
|
return publiDB.UnknowSetName
|
|
|
|
}
|
2020-09-09 14:39:46 +02:00
|
|
|
for (let [setname, articles] of this.sets.entries()) {
|
|
|
|
if (JSON.stringify(set.sort()) === JSON.stringify(articles.sort())) {
|
2020-08-20 15:28:06 +02:00
|
|
|
return setname
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
2020-09-09 14:39:46 +02:00
|
|
|
findSetNameFromArticle(article, supportUnknow = false) {
|
|
|
|
for (let [setname, articles] of this.sets.entries()) {
|
|
|
|
if (articles.includes(article))
|
2020-08-20 15:28:06 +02:00
|
|
|
return setname
|
|
|
|
}
|
2020-09-09 14:39:46 +02:00
|
|
|
if (supportUnknow && article === "") {
|
2020-08-26 15:04:30 +02:00
|
|
|
return publiDB.UnknowSetName
|
2020-08-20 15:28:06 +02:00
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|