明树Git Lab

Commit bbde3270 authored by zfp1's avatar zfp1

1

parent 4c0745b4
Pipeline #108285 passed with stage
in 10 seconds
...@@ -15,7 +15,8 @@ async function upload(req, res, next) { ...@@ -15,7 +15,8 @@ async function upload(req, res, next) {
filename: req.file.filename, filename: req.file.filename,
path: req.file.path, path: req.file.path,
// nginxpath, // nginxpath,
size: (req.file.size / (1048576)).toFixed(2), size: (req.file.size / (1048576)).toFixed(2),
realSize: req.file.size,
}); });
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
...@@ -34,8 +35,10 @@ async function batchUpload(req, res, next) { ...@@ -34,8 +35,10 @@ async function batchUpload(req, res, next) {
mimetype: element.mimetype, mimetype: element.mimetype,
filename: element.filename, filename: element.filename,
path: element.path, path: element.path,
size: element.size, // size: element.size,
// nginxpath, // nginxpath,
size: (element.size / (1048576)).toFixed(2),
realSize: element.size,
}) })
} }
let data = await DB.File.insertMany(ret); let data = await DB.File.insertMany(ret);
...@@ -51,7 +54,7 @@ async function batchUpload(req, res, next) { ...@@ -51,7 +54,7 @@ async function batchUpload(req, res, next) {
async function downloadFileById(req, res, next) { async function downloadFileById(req, res, next) {
try { try {
let fileId = req.params.fileId; let fileId = req.params.fileId;
let fileinfo = await DB.File.findOne({ where: {id: fileId}, raw: true }); let fileinfo = await DB.File.findOne({ where: { id: fileId }, raw: true });
if (!(fileinfo && fileinfo.id)) { if (!(fileinfo && fileinfo.id)) {
return res.sendError(errorMessage.resourceNotFound) return res.sendError(errorMessage.resourceNotFound)
} }
...@@ -66,7 +69,7 @@ async function downloadFileById(req, res, next) { ...@@ -66,7 +69,7 @@ async function downloadFileById(req, res, next) {
} = fileinfo; } = fileinfo;
//TODO:path处理 //TODO:path处理
const filePath = Path.join(__dirname, '../../../', path); const filePath = Path.join(__dirname, '../../../', path);
if (!fs.existsSync(filePath)) { if (!fs.existsSync(filePath)) {
return res.sendError(errorMessage.resourceNotFound) return res.sendError(errorMessage.resourceNotFound)
} }
...@@ -90,8 +93,8 @@ async function downloadFileById(req, res, next) { ...@@ -90,8 +93,8 @@ async function downloadFileById(req, res, next) {
async function showFileById(req, res, next) { async function showFileById(req, res, next) {
try { try {
// ---------- // ----------
let fileId = req.params.fileId; let fileId = req.params.fileId;
let fileinfo = await DB.File.findOne({ where: {id: fileId}, raw: true }); let fileinfo = await DB.File.findOne({ where: { id: fileId }, raw: true });
if (!(fileinfo && fileinfo.id)) { if (!(fileinfo && fileinfo.id)) {
return res.sendError(errorMessage.resourceNotFound) return res.sendError(errorMessage.resourceNotFound)
} }
...@@ -106,7 +109,7 @@ async function showFileById(req, res, next) { ...@@ -106,7 +109,7 @@ async function showFileById(req, res, next) {
} = fileinfo; } = fileinfo;
//TODO:path处理 //TODO:path处理
const filePath = Path.join(__dirname, '../../../', path); const filePath = Path.join(__dirname, '../../../', path);
if (!fs.existsSync(filePath)) { if (!fs.existsSync(filePath)) {
return res.sendError(errorMessage.resourceNotFound) return res.sendError(errorMessage.resourceNotFound)
} }
......
...@@ -17,6 +17,9 @@ const File = sequelize.define('File', { ...@@ -17,6 +17,9 @@ const File = sequelize.define('File', {
type: DataTypes.STRING, type: DataTypes.STRING,
comment: "存储的文件名" comment: "存储的文件名"
}, },
size: {
type: DataTypes.STRING,
},
size: { size: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
}, },
...@@ -62,7 +65,7 @@ const File = sequelize.define('File', { ...@@ -62,7 +65,7 @@ const File = sequelize.define('File', {
File.sync({ File.sync({
// force: false, // force: false,
// force: true ,//会删除已存在表并重新创建 // force: true ,//会删除已存在表并重新创建
// alter: true alter: true
}) })
.then(() => { .then(() => {
console.log('File 表同步成功'); console.log('File 表同步成功');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment