update-storage
This commit is contained in:
37
mixio.js
37
mixio.js
@@ -832,6 +832,33 @@ var mixioServer = async function() {
|
||||
|
||||
var topic = packet.topic.split('/')
|
||||
var payload = String(packet.payload)
|
||||
if (topic.length == 4) {
|
||||
if(topic[3][0] == '$') {
|
||||
// 判断是否是base64, 开头为data:image/***;base64, ***可以为png,bmp,jpg,jpeg,gif,svg,ico
|
||||
const allowFormats = ['png', 'bmp', 'jpg', 'jpeg', 'gif', 'svg', 'ico'];
|
||||
const base64Reg = /^data:image\/(\w+);base64,/;
|
||||
const match = payload.match(base64Reg);
|
||||
if (match && allowFormats.includes(match[1])) {
|
||||
// 是base64
|
||||
const format = match[1];
|
||||
const timeStamp = Date.now();
|
||||
const fileName = topic[3] + '_' + `${timeStamp}.${format}`;
|
||||
const filePath = path.join('store', topic[0], topic[1], topic[2], fileName);
|
||||
const base64Data = payload.replace(base64Reg, '');
|
||||
const buffer = Buffer.from(base64Data, 'base64');
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.writeFileSync(filePath, buffer);
|
||||
} else {
|
||||
// 全部明文存为txt
|
||||
const timeStamp = Date.now();
|
||||
const fileName = topic[3] + '_' + `${timeStamp}.txt`;
|
||||
const filePath = path.join('store', topic[0], topic[1], topic[2], fileName);
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true});
|
||||
fs.writeFileSync(filePath, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (topic.length == 3) {
|
||||
if(topic[2][0] == '$') {
|
||||
// 判断是否是base64, 开头为data:image/***;base64, ***可以为png,bmp,jpg,jpeg,gif,svg,ico
|
||||
@@ -1353,8 +1380,13 @@ var mixioServer = async function() {
|
||||
app.get('/getImgStore', function(req, res) {
|
||||
if (req.session.userName && req.query.projectName){
|
||||
var projectName = req.query.projectName
|
||||
var isMixly = req.query.isMixly
|
||||
// store/username/projectName
|
||||
var imgStorePath = path.join('store/' + req.session.userName + "/" + projectName)
|
||||
if (isMixly == "true")
|
||||
{
|
||||
imgStorePath = path.join('store/MixIO/' + req.session.userName.substr(1) + "/" + projectName)
|
||||
}
|
||||
// 文件名发送列表
|
||||
fs.readdir(imgStorePath, function(err, files) {
|
||||
res.send(files || [])
|
||||
@@ -1367,8 +1399,13 @@ var mixioServer = async function() {
|
||||
if (req.session.userName && req.query.projectName && req.query.filename){
|
||||
var projectName = req.query.projectName
|
||||
var filename = req.query.filename
|
||||
var isMixly = req.query.isMixly
|
||||
// store/username/projectName
|
||||
var imgStorePath = 'store/' + req.session.userName + "/" + projectName
|
||||
if (isMixly == "true")
|
||||
{
|
||||
imgStorePath = path.join('store/MixIO/' + req.session.userName.substr(1) + "/" + projectName)
|
||||
}
|
||||
// 删除文件
|
||||
fs.unlink(path.join(imgStorePath, filename), function(err) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user