webamp/experiments/skin-database/discord-bot/info.js
2019-11-30 13:42:41 -08:00

26 lines
564 B
JavaScript

const path = require("path");
const fs = require("fs");
let cache = null;
function getCache() {
if (cache == null) {
cache = JSON.parse(
fs.readFileSync(path.join(__dirname, "../info.json"), "utf8")
);
}
return cache;
}
// TODO: Make async and rewriting using DB
function getInfo(md5) {
return getCache()[md5];
}
// TODO: Make async and rewriting using DB
function getFilename(md5) {
const info = getInfo(md5);
return info.filePaths.map(filepath => path.basename(filepath))[0];
}
module.exports = { getInfo, getCache, getFilename };