1
This commit is contained in:
149
api/controller_front/config.js
Normal file
149
api/controller_front/config.js
Normal file
@@ -0,0 +1,149 @@
|
||||
const dayjs = require("dayjs");
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { plu_api_linkjs, plu_ga, plu_func, plu_func_type, plu_version, querySql, op } = require("../../middleware/baseModel");
|
||||
|
||||
module.exports = {
|
||||
|
||||
"GET /config/v3_test": async (ctx, next) => {
|
||||
|
||||
let data = [
|
||||
{
|
||||
create_time: "2021-11-23 16:27:06",
|
||||
last_modify_time: "2021-11-23 16:27:06",
|
||||
id: 1,
|
||||
name: "数据银行",
|
||||
platformUrl: "databank.tmall.com",
|
||||
linkUrl: "https://yunzhuan.light120.com/platform/databank/index.js",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
create_time: "2021-11-23 16:26:38",
|
||||
last_modify_time: "2021-11-23 16:26:38",
|
||||
id: 2,
|
||||
name: "生意参谋",
|
||||
platformUrl: "sycm.taobao.com",
|
||||
linkUrl: "https://yunzhuan.light120.com/platform/businessStaff/index.js",
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
create_time: "2021-11-23 16:26:03",
|
||||
last_modify_time: "2021-11-23 16:26:03",
|
||||
id: 3,
|
||||
name: "策略中心",
|
||||
platformUrl: "strategy.tmall.com",
|
||||
linkUrl: "https://yunzhuan.light120.com/platform/strategy/index.js",
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
create_time: "2021-11-24 19:13:00",
|
||||
last_modify_time: "2021-11-24 19:13:00",
|
||||
id: 4,
|
||||
name: "淘宝直播",
|
||||
platformUrl: "market.m.taobao.com",
|
||||
linkUrl: "https://yunzhuan.light120.com/platform/tbLive/index.js",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
create_time: "2021-11-24 19:13:00",
|
||||
last_modify_time: "2021-11-24 19:13:00",
|
||||
id: 5,
|
||||
name: "达摩盘",
|
||||
platformUrl: "dmp.taobao.com",
|
||||
linkUrl: "https://yunzhuan.light120.com/platform/dmp/index.js",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
create_time: "2021-11-24 19:13:00",
|
||||
last_modify_time: "2021-11-24 19:13:00",
|
||||
id: 5,
|
||||
name: "淘宝光合",
|
||||
platformUrl: "creator.guanghe.taobao.com",
|
||||
linkUrl: "https://yunzhuan.light120.com/platform/guanghe/index.js",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
create_time: "2021-11-24 19:13:00",
|
||||
last_modify_time: "2021-11-24 19:13:00",
|
||||
id: 5,
|
||||
name: "抖音电商",
|
||||
platformUrl: "compass.jinritemai.com",
|
||||
linkUrl: "https://yunzhuan.light120.com/platform/tikTok/index.js",
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
create_time: "2021-11-24 19:13:00",
|
||||
last_modify_time: "2021-11-24 19:13:00",
|
||||
id: 6,
|
||||
name: "天猫详情",
|
||||
platformUrl: "detail.tmall.com",
|
||||
linkUrl: "https://yunzhuan.light120.com/platform/tmall/index.js",
|
||||
inline: true,
|
||||
},
|
||||
];
|
||||
return ctx.success(data);
|
||||
|
||||
},
|
||||
|
||||
"GET /config/v3": async (ctx, next) => {
|
||||
const res = await plu_api_linkjs.findAll({ where: {} });
|
||||
return ctx.success(res);
|
||||
|
||||
},
|
||||
|
||||
"GET /config/ga": async (ctx, next) => {
|
||||
let ip = ctx.getIp();
|
||||
let { title, brand, type, postion, parentSelector: parent_selector, className: class_name, icon, path, browser } = ctx.getQuery();
|
||||
let res = await plu_ga.create({ title, type, brand, postion, parent_selector, class_name, icon, path, ip, browser });
|
||||
return ctx.success(res);
|
||||
},
|
||||
|
||||
"GET /config/funType": async (ctx, next) => {
|
||||
|
||||
const res = await plu_func_type.findAll({ where: { is_enable: 1 } });
|
||||
let rows = res.map(p => {
|
||||
return { key: p.id, value: p.value }
|
||||
})
|
||||
|
||||
return ctx.success(rows);
|
||||
},
|
||||
|
||||
|
||||
"GET /config/funAll": async (ctx, next) => {
|
||||
let rows = await plu_func.findAll({ where: { is_enable: 1 }, order: [["sort", "asc"]] });
|
||||
return ctx.success(rows);
|
||||
},
|
||||
|
||||
|
||||
"GET /config/lastPlug": async (ctx, next) => {
|
||||
|
||||
const replaceUrl = (url) => {
|
||||
url = url.replace('https:', '')
|
||||
url = url.replace('http:', '')
|
||||
return url
|
||||
}
|
||||
|
||||
let defaultRow = {
|
||||
plugVersion: '2.7.5',
|
||||
plugUpdateDate: '2023-06-09',
|
||||
officialUrl: "//shopant.baozun.com/plug/#/",
|
||||
downUrl: '//bztic-shopant-files.oss-cn-shanghai.aliyuncs.com/front/plug/business-staff-extension_2.7.5.zip',
|
||||
helpUrl: '//bztic-shopant-files.oss-cn-shanghai.aliyuncs.com/front/plug/helpDoc.pdf'
|
||||
}
|
||||
|
||||
let row = await plu_version.findOne({ where: { is_enable: 1 }, order: [["id", "desc"]] })
|
||||
if (row) {
|
||||
|
||||
let { plugVersion, plugUpdateDate, downUrl, helpUrl } = row
|
||||
plugUpdateDate = dayjs(plugUpdateDate).format('YYYY-MM-DD')
|
||||
downUrl = replaceUrl(downUrl)
|
||||
helpUrl = replaceUrl(helpUrl)
|
||||
|
||||
defaultRow = Object.assign({}, defaultRow, { plugVersion, plugUpdateDate, downUrl, helpUrl })
|
||||
}
|
||||
|
||||
|
||||
return ctx.success(defaultRow);
|
||||
},
|
||||
|
||||
};
|
||||
159
api/controller_front/model.js
Normal file
159
api/controller_front/model.js
Normal file
@@ -0,0 +1,159 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { sys_model, sys_project, querySql, sys_model_field, op } = require("../../middleware/baseModel");
|
||||
const autoFile = require("../service/autoFile");
|
||||
const funTool = require("../../tool/funTool");
|
||||
const uuid = require("node-uuid");
|
||||
|
||||
module.exports = {
|
||||
"POST /model/all": async (ctx, next) => {
|
||||
let { projectKey } = ctx.getBody();
|
||||
|
||||
let projectRow = await sys_project.findOne({ where: { key: projectKey } });
|
||||
if (projectRow) {
|
||||
let project_id = projectRow.id;
|
||||
let resList = await sys_model.findAll({ where: { project_id } });
|
||||
|
||||
let resPromise = resList.map(async (row) => {
|
||||
let newRow = row.toJSON();
|
||||
|
||||
let isExistTableName = await querySql(`select TABLE_NAME from information_schema.TABLES where TABLE_NAME ="${newRow.key}"`);
|
||||
if (isExistTableName && isExistTableName.length > 0) {
|
||||
newRow.isTableExist = true;
|
||||
} else {
|
||||
newRow.isTableExist = false;
|
||||
}
|
||||
|
||||
let modelPath = await autoFile.outBuildPath(`api/model/${newRow.key}.js`, project_id);
|
||||
let isExistModel = await funTool.isExist(modelPath);
|
||||
newRow.isExistModel = isExistModel;
|
||||
|
||||
// 查询模型下所有字段
|
||||
let dbColKeys = [];
|
||||
let modelRow = await sys_model.findOne({ where: { id: newRow.id } });
|
||||
if (modelRow && newRow.isTableExist) {
|
||||
let colRows = await querySql(`show columns from ${modelRow.key}`);
|
||||
dbColKeys = colRows.map((p) => p.Field);
|
||||
}
|
||||
|
||||
let isDbFielExist = true;
|
||||
let model_fields = await sys_model_field.findAll({ where: { model_id: newRow.id } });
|
||||
model_fields.forEach((newFielRow) => {
|
||||
let = newFielRow.toJSON();
|
||||
if (dbColKeys.indexOf(newFielRow.key) === -1) {
|
||||
isDbFielExist = false;
|
||||
}
|
||||
});
|
||||
|
||||
newRow.isDbFielExist = isDbFielExist;
|
||||
|
||||
return newRow;
|
||||
});
|
||||
|
||||
let newResList = await Promise.all(resPromise);
|
||||
|
||||
return ctx.success(newResList);
|
||||
} else {
|
||||
return ctx.fail("未找到项目key");
|
||||
}
|
||||
},
|
||||
|
||||
"POST /model/detailPath": async (ctx, next) => {
|
||||
let { id } = ctx.getBody();
|
||||
let modelRow = await sys_model.findOne({ where: { id } });
|
||||
if (modelRow) {
|
||||
let { key, project_id } = modelRow;
|
||||
let projectRow = await sys_project.findOne({ where: { id: project_id } });
|
||||
if (projectRow) {
|
||||
let controllerPath = path.normalize(`/${projectRow.key}/api/controller_admin/${key}.js`);
|
||||
let modelPath = path.normalize(`/${projectRow.key}/api/model/${key}.js`);
|
||||
return ctx.success({ controllerPath, modelPath });
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.success({ controllerPath: "", modelPath: "" });
|
||||
},
|
||||
|
||||
|
||||
"POST /form/updateForm": async (ctx, next) => {
|
||||
let { id, name, model_id, api_path, component } = ctx.getBody();
|
||||
let formRow = await sys_form.findOne({ where: { id: id } });
|
||||
if (formRow) {
|
||||
let res = await sys_form.update({ name: `${name}_表单`, model_id, api_path, component }, { where: { id } });
|
||||
return ctx.success(res);
|
||||
} else {
|
||||
return ctx.fail("未找到指定项目");
|
||||
}
|
||||
},
|
||||
|
||||
"POST /form/createForm": async (ctx, next) => {
|
||||
let { name, project_key, model_id, api_path, component } = ctx.getBody();
|
||||
let projectRow = await sys_project.findOne({ where: { key: project_key } });
|
||||
if (projectRow) {
|
||||
let project_id = projectRow.id;
|
||||
let res = await sys_form.create({ name: `${name}_表单`, project_id, model_id, api_path, component });
|
||||
return ctx.success(res);
|
||||
} else {
|
||||
return ctx.fail("未找到指定项目");
|
||||
}
|
||||
},
|
||||
|
||||
"POST /form/generate": async (ctx, next) => {
|
||||
let form_id = ctx.get("id");
|
||||
if (form_id) {
|
||||
const sysFormRow = await sys_form.findOne({ where: { id: form_id } });
|
||||
if (sysFormRow) {
|
||||
await autoFile.createForm(sysFormRow);
|
||||
let frontApiUrl = await autoFile.autoFrontApi(sysFormRow);
|
||||
let frontVueUrl = await autoFile.autoFrontVue(sysFormRow);
|
||||
|
||||
frontApiUrl = path.normalize(frontApiUrl);
|
||||
frontVueUrl = path.normalize(frontVueUrl);
|
||||
|
||||
return ctx.success({ frontApiUrl, frontVueUrl });
|
||||
}
|
||||
}
|
||||
return ctx.fail("生成失败");
|
||||
},
|
||||
|
||||
// 生成model
|
||||
"POST /model/regenerate": async (ctx, next) => {
|
||||
let row = ctx.getBody();
|
||||
let { id } = row;
|
||||
if (id) {
|
||||
let sysModelFields = await sys_model_field.findAll({ where: { model_id: id } });
|
||||
if (sysModelFields && sysModelFields.length > 0) {
|
||||
let tempUUid = uuid.v4();
|
||||
// 创建model
|
||||
await autoFile.autoModel(id, tempUUid);
|
||||
|
||||
// 创建apiServer
|
||||
await autoFile.autoController(id);
|
||||
|
||||
|
||||
let modelRow = await sys_model.findOne({ where: { id } });
|
||||
if (modelRow) {
|
||||
let { key, project_id } = modelRow;
|
||||
let projectRow = await sys_project.findOne({ where: { id: project_id } });
|
||||
if (projectRow) {
|
||||
let controllerPath = path.normalize(`/${projectRow.key}/api/controller_admin/${key}.js`);
|
||||
let modelPath = path.normalize(`/${projectRow.key}/api/model/${key}.js`);
|
||||
return ctx.success({ controllerPath, modelPath });
|
||||
}
|
||||
else {
|
||||
return ctx.fail("未找到项目");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return ctx.fail("未找到模型文件");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
return ctx.fail("字段未添加,无效生成");
|
||||
}
|
||||
}
|
||||
return ctx.fail("参数错误 id");
|
||||
},
|
||||
};
|
||||
14
api/controller_front/project.js
Normal file
14
api/controller_front/project.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const dayjs = require("dayjs");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const autoFile = require("../service/autoFile");
|
||||
const { querySql, sys_project, op } = require("../../middleware/baseModel");
|
||||
|
||||
module.exports = {
|
||||
"POST /project/down": async (ctx, next) => {
|
||||
let { model_id } = ctx.getBody();
|
||||
},
|
||||
"POST /project/build": async (ctx, next) => {
|
||||
let { model_id } = ctx.getBody();
|
||||
},
|
||||
};
|
||||
15
api/controller_front/sofaware.js
Normal file
15
api/controller_front/sofaware.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const dayjs = require("dayjs");
|
||||
const { querySql, sof_sofawa_ga, op } = require("../../middleware/baseModel");
|
||||
module.exports = {
|
||||
"POST /sofaware/last": async (ctx, next) => {
|
||||
let row = { version: "1.5.0", officialUrl: "https://shopant.baozun.com/plug/#/", updateDate: "2024-05-10", downUrl: "https://bztic-shopant-files.oss-cn-shanghai.aliyuncs.com/prod/split_video/split_video_latest.zip" }
|
||||
return ctx.success(row)
|
||||
},
|
||||
|
||||
"POST /sofaware/ga": async (ctx, next) => {
|
||||
let row = ctx.getBody();
|
||||
const res = await sof_sofawa_ga.create(row);
|
||||
return ctx.success(res);
|
||||
},
|
||||
|
||||
};
|
||||
49
api/controller_front/sys_file.js
Normal file
49
api/controller_front/sys_file.js
Normal file
@@ -0,0 +1,49 @@
|
||||
var UUID = require("uuid");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
const ossTool = require("../service/ossTool");
|
||||
const funTool = require("../../tool/funTool");
|
||||
|
||||
module.exports = {
|
||||
"POST /sys_file/upload_img": async (ctx, next) => {
|
||||
const files = ctx.request.files; // 获取上传文件
|
||||
let fileArray = [];
|
||||
let rootPath = path.join(__dirname, "../../upload/imgs");
|
||||
for (var key in files) {
|
||||
fileArray.push(files[key]);
|
||||
}
|
||||
|
||||
//创建文件夹
|
||||
await funTool.mkdirsSync(rootPath);
|
||||
|
||||
let resArray = [];
|
||||
fileArray.forEach((file) => {
|
||||
// 创建可读流
|
||||
const reader = fs.createReadStream(file.path);
|
||||
|
||||
let filePath = `/${UUID.v1() + "_" + file.name}`;
|
||||
// 创建可写流
|
||||
const upStream = fs.createWriteStream(path.join(rootPath, filePath));
|
||||
// 可读流通过管道写入可写流
|
||||
|
||||
reader.pipe(upStream);
|
||||
|
||||
resArray.push({ name: file.name, path: path.join("/imgs", filePath) });
|
||||
});
|
||||
|
||||
ctx.success(resArray);
|
||||
},
|
||||
"POST /sys_file/upload_oos_img": async (ctx, next) => {
|
||||
let fileArray = [];
|
||||
const files = ctx.request.files; // 获取上传文件
|
||||
for (var key in files) {
|
||||
fileArray.push(files[key]);
|
||||
}
|
||||
let data = await ossTool.putImg(fileArray[0]);
|
||||
if (data.path) {
|
||||
return ctx.success(data);
|
||||
} else {
|
||||
return ctx.fail();
|
||||
}
|
||||
},
|
||||
};
|
||||
24
api/controller_front/upgrade.js
Normal file
24
api/controller_front/upgrade.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const { plu_upgrade, op } = require("../../middleware/baseModel");
|
||||
|
||||
module.exports = {
|
||||
"POST /upgrade/add": async (ctx, next) => {
|
||||
let row = ctx.getBody();
|
||||
let { fingerPrintKey, newVersion, oldVersion } = row;
|
||||
let upgradeRow = await plu_upgrade.findOne({ where: { fingerPrintKey, newVersion } });
|
||||
if (upgradeRow) {
|
||||
await plu_upgrade.update({ fingerPrintKey, newVersion, oldVersion, whetherTip: true }, { where: { id: upgradeRow.id }, individualHooks: true });
|
||||
return ctx.success();
|
||||
} else {
|
||||
const res = await plu_upgrade.create(row);
|
||||
return ctx.success(res);
|
||||
}
|
||||
},
|
||||
|
||||
"GET /upgrade/detail": async (ctx, next) => {
|
||||
let fingerPrintKey = ctx.get("fingerPrintKey");
|
||||
let newVersion = ctx.get("newVersion");
|
||||
|
||||
const res = await plu_upgrade.findOne({ where: { fingerPrintKey, newVersion } });
|
||||
return ctx.success(res);
|
||||
},
|
||||
};
|
||||
78
api/controller_front/video_effects.js
Normal file
78
api/controller_front/video_effects.js
Normal file
@@ -0,0 +1,78 @@
|
||||
const { plu_upgrade, op } = require("../../middleware/baseModel");
|
||||
const { encoder } = require("../service/ffmpeg/encoder");
|
||||
const fs = require('fs');
|
||||
const stream = require("stream");
|
||||
const path = require("path");
|
||||
|
||||
const getStreamContentTobase64Stream = async (file) => {
|
||||
|
||||
let p = new Promise((resolve, reject) => {
|
||||
const readStream = fs.createReadStream(file.path)
|
||||
const readStream2 = new stream.Readable();
|
||||
|
||||
|
||||
|
||||
let str = ''
|
||||
readStream.on('data', data => {
|
||||
str += data.toString()
|
||||
|
||||
})
|
||||
|
||||
readStream.on('end', () => {
|
||||
|
||||
let base64Array = str.split('data:image/png;base64,')
|
||||
console.log('count', base64Array.length)
|
||||
for (let i = 0; i < base64Array.length; i++) {
|
||||
let base64 = base64Array[i].replace(/^data:\w+\/\w+;base64,/, '')
|
||||
const buffer = Buffer.from(base64, "base64");
|
||||
readStream2.push(buffer);
|
||||
}
|
||||
|
||||
readStream2.push(null)
|
||||
|
||||
|
||||
resolve(readStream2)
|
||||
})
|
||||
|
||||
readStream.on('error', err => {
|
||||
reject(err)
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
return p
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
"POST /video_effects/build": async (ctx, next) => {
|
||||
const files = ctx.request.files; // 获取上传文件
|
||||
|
||||
let file = files.file
|
||||
|
||||
let frameStream = await getStreamContentTobase64Stream(file)
|
||||
|
||||
|
||||
const output = await encoder({
|
||||
silent: false,
|
||||
frameStream: frameStream,
|
||||
backgroundVideo: {
|
||||
videoPath: path.join(__dirname, "../../config/media/demo_out.mp4"),
|
||||
inSeconds: 1,
|
||||
outSeconds: 30,
|
||||
},
|
||||
output: "output/test.mp4",
|
||||
fps: {
|
||||
input: 30,
|
||||
output: 30,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
console.log("process done,", output.path);
|
||||
|
||||
return ctx.success({ path: output.path });
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user