39 lines
912 B
TypeScript
Raw Normal View History

2021-12-14 16:06:03 +04:00
import * as fs from 'fs';
import logger from '../../logger';
class Icons {
private static FILE_NAME = '/elements/asset_registry_db/icons.json';
2021-12-14 16:06:03 +04:00
private iconIds: string[] = [];
private icons: { [assetId: string]: string; } = {};
2021-12-21 02:00:50 +04:00
constructor() {}
public loadIcons() {
2021-12-14 16:06:03 +04:00
if (!fs.existsSync(Icons.FILE_NAME)) {
logger.warn(`${Icons.FILE_NAME} does not exist. No Liquid icons loaded.`);
return;
}
const cacheData = fs.readFileSync(Icons.FILE_NAME, 'utf8');
this.icons = JSON.parse(cacheData);
for (const i in this.icons) {
this.iconIds.push(i);
}
logger.debug(`Liquid icons has been loaded.`);
}
public getIconByAssetId(assetId: string): Buffer | undefined {
const icon = this.icons[assetId];
if (icon) {
return Buffer.from(icon, 'base64');
}
}
public getAllIconIds() {
return this.iconIds;
}
}
export default new Icons();