1
0
mirror of https://github.com/journey-ad/Moe-Counter.git synced 2024-11-24 07:40:11 +01:00
Moe-Counter/utils/themify.js

34 lines
828 B
JavaScript
Raw Normal View History

2020-08-05 07:37:12 +02:00
'use strict'
const fs = require('fs')
const path = require('path')
const mimeType = require('mime-types')
const themePath = path.resolve(__dirname, '../assets/theme')
const themeList = {}
fs.readdirSync(themePath).forEach(theme => {
if(!(theme in themeList)) themeList[theme] = {}
const imgList = fs.readdirSync(path.resolve(themePath, theme))
imgList.forEach(img => {
const name = path.parse(img).name
themeList[theme][name] = convertToDatauri(path.resolve(themePath, theme, img))
})
})
function convertToDatauri(path){
const mime = mimeType.lookup(path)
const base64 = fs.readFileSync(path).toString('base64')
return `data:${mime};base64,${base64}`
}
function wrap(num, theme='konachan'){
if(!(theme in themeList)) theme = 'konachan'
return themeList[theme][num]
}
module.exports = {
wrap
}