HelperService = require('../services/helper');
const ToolsService = require('../services/tools.service');
const models = require('../models');
const db = require('../../config/database');
const F = db.files;
const {File} = models;
class FileController extends BaseController {
constructor() {
super({
sql: {
model: [File]
},
});
/* async getArrayFromObject(obj) {
let array = [];
try {
if ((typeof obj) === "string" && obj.indexOf('{') === -1 && obj.indexOf('[') === -1) {
let result = obj.replace(/(\')|(\")/gi, '');
return result.split(',');
}
obj = (typeof obj) === "string" ? JSON.parse(obj) : obj;
} catch (e) {
array.push(obj);
return array;
}
array = !Array.isArray(obj) ? [] : obj;
if (array.length === 0) {
if (obj && typeof obj.mv === 'function') {
array.push(obj);
} else {
for (let objKey in obj) {
array.push(obj[objKey]);
}
}
}
return array;
};*/
exports.uploadFile = async (req, res) => {
//console.log(req.files.file.data);
F.create({
id: req.body.id,
name: req.file.originalname,
description: req.body.description,
type: req.file.mimetype,
url: req.body.url,
file: req.file.buffer
}).then(() => {
res.json({
id: req.body.id,
name: req.file.originalname,
description: req.body.description,
type: req.file.mimetype,
url: req.body.url,
file: req.file.buffer
});
}).catch(err => {
console.log(err);
res.json({msg: 'Error', detail: err});
});
};
/* exports.listAllFiles = async(req, res) => {
F.findAll({attributes: ['id', 'name']}).then(files => {
res.json(files);
}).catch(err => {
console.log(err);
res.json({msg: 'Error', detail: err});
});
};
}*/
}
}
module.exports = FileController;
module.exports = new FileController ();
Обсуждают сегодня