fix(striker-ui-api): handle POST to upload files

main
Tsu-ba-me 3 years ago
parent f64074f34a
commit eee01ce3d3
  1. 28
      striker-ui-api/lib/consts/SERVER_PATHS.js
  2. 16
      striker-ui-api/middlewares/uploadSharedFiles.js
  3. 15
      striker-ui-api/routes/files.js

@ -0,0 +1,28 @@
const path = require('path');
const SERVER_PATHS = {
mnt: {
shared: {
incoming: {},
},
},
};
const generatePaths = (
currentObject,
parents = path.parse(process.cwd()).root,
) => {
Object.keys(currentObject).forEach((pathKey) => {
const currentPath = path.join(parents, pathKey);
currentObject[pathKey].self = currentPath;
if (pathKey !== 'self') {
generatePaths(currentObject[pathKey], currentPath);
}
});
};
generatePaths(SERVER_PATHS);
module.exports = SERVER_PATHS;

@ -0,0 +1,16 @@
const multer = require('multer');
const SERVER_PATHS = require('../lib/consts/SERVER_PATHS');
const storage = multer.diskStorage({
destination: (request, file, callback) => {
callback(null, SERVER_PATHS.mnt.shared.incoming.self);
},
filename: (request, file, callback) => {
callback(null, file.originalname);
},
});
const uploadSharedFiles = multer({ storage });
module.exports = uploadSharedFiles;

@ -1,6 +1,8 @@
const express = require('express');
const { spawnSync } = require('child_process');
const uploadSharedFiles = require('../middlewares/uploadSharedFiles');
const router = express.Router();
router
@ -75,6 +77,19 @@ router
}
response.status(200).send(stdoutJSON);
})
.post('/', uploadSharedFiles.single('file'), ({ file, body }, response) => {
console.log('Receiving shared file.');
if (file) {
console.log(`file:`);
console.dir(file);
console.log('body:');
console.dir(body);
response.status(200).send();
}
});
module.exports = router;

Loading…
Cancel
Save