import using drag & drop

This commit is contained in:
Jan Prochazka
2020-11-07 21:52:35 +01:00
parent c65806fd89
commit 6fb314c414
8 changed files with 228 additions and 58 deletions

View File

@@ -2,6 +2,21 @@ const path = require('path');
const { uploadsdir } = require('../utility/directories');
const uuidv1 = require('uuid/v1');
const extensions = [
{
ext: '.xlsx',
type: 'excel',
},
{
ext: '.jsonl',
type: 'jsonl',
},
{
ext: '.csv',
type: 'csv',
},
];
module.exports = {
upload_meta: {
method: 'post',
@@ -16,10 +31,21 @@ module.exports = {
const uploadName = uuidv1();
const filePath = path.join(uploadsdir(), uploadName);
console.log(`Uploading file ${data.name}, size=${data.size}`);
let storageType = null;
let shortName = data.name;
for (const { ext, type } of extensions) {
if (data.name.endsWith(ext)) {
storageType = type;
shortName = data.name.slice(0, -ext.length);
}
}
data.mv(filePath, () => {
res.json({
originalName: data.name,
shortName,
storageType,
uploadName,
filePath,
});
});
},