You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.6 KiB

const path = require('path');
const express = require('express');
const app = express();
app.use(express.json())
const port = 5000
const fontDb = require('../db/fontDb');
const { append } = require('express/lib/response');
const { listen } = require('express/lib/application');
const { listeners } = require('process');
const { where } = require('sequelize');
const svgtofont = require('svgtofont');
const fs = require('fs');
const { resolve } = require('path/posix');
app.use(express.json())
const font = fontDb.font
const iconFont = fontDb.iconfont
function createIcon (){
iconFont.belongsTo(font , {foreignKey: { name: 'iconfontID'} });
font.hasMany(iconFont , {foreignKey: { name: 'iconfontID'}});
app.listen(port , ()=>{
console.log('listening on port ')
})
app.post('/addIcon', async (req, res) => {
let fontId = await font.findOne({
where : {
name : req.body.fontName,
}
})
// iconFont.destroy({
// where:{
// iconfontID:null,
// }}
// )
const svgsFolder = "svgs/iconsax2"
fs.readdirSync(svgsFolder).forEach(file => {
const iconCreate = iconFont.create(
{
name : req.body.fontName,
iconfontID : fontId.id,
char : String.fromCharCode(file.substring(0,4)) ,
svgFile : svgsFolder + '/' + file,
varient : req.body.varient,
description : file,
}
)
res.send(iconFont.char)
} )
});
}
function createfont (){
app.listen(port , ()=>{
console.log('listening on port ')
})
app.post('/createfont', async (req, res) => {
const fontCreaet = font.create(
{
name : req.body.fontName,
})
res.send(font.id);
});
}
function createIconFont (){
iconFont.belongsTo(font , {foreignKey: { name: 'iconfontID'} });
font.hasMany(iconFont , {foreignKey: { name: 'iconfontID'}});
app.listen(port , ()=>{
console.log('listening on port ')
})
app.post('/createIconFont', async (req, res) => {
svgFiles = []
let fontId = await font.findOne( {
where : {
name : req.body.fontName,
}
})
let svgList = await font.findAll({
include : [{model: iconFont , where : {
varient : "Bulks",
iconfontID :fontId.dataValues.id,
}}, ],
})
svgList = svgList[0].dataValues.iconfonts
res.send(svgList)
for (let i = 0; i < svgList.length; i++){
if (!fs.existsSync("iconFont/svg/"+req.body.fontName)){
fs.mkdirSync("iconFont/svg/"+req.body.fontName);
}
fs.copyFile("svgs/"+req.body.fontName +"/"+svgList[i].name +".svg" , "iconFont/svg/"+req.body.fontName+"/"+svgList[i].name +".svg" ,function(err) {
if ( err ) console.log('ERROR: ' + err);
})
}
for (let i = 0; i < svgList.length; i++){
fs.rename( svgList[i].svgFile, "iconFont/svg/"+req.body.fontName+"/"+svgList[i].char+".svg" , function(err) {
if ( err ) console.log('ERROR: ' + err);
})
}
svgtofont({
src: path.resolve('iconFont/svg/'+req.body.fontName),
dist: path.resolve('iconFont/iconFontsOf'+req.body.fontName),
fontName: req.body.fontName,
css: true,
emptyDist: true,
useNameAsUnicode : true,
});
});
}
module.exports = {createIcon , createfont ,createIconFont}