You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.2 KiB
81 lines
2.2 KiB
const express = require('express'); |
|
|
|
const accessDB = require('../lib/accessDB'); |
|
const getFilesOverview = require('../lib/request_handlers/files/getFilesOverview'); |
|
const getFileDetail = require('../lib/request_handlers/files/getFileDetail'); |
|
const uploadSharedFiles = require('../middlewares/uploadSharedFiles'); |
|
|
|
const router = express.Router(); |
|
|
|
router |
|
.get('/', getFilesOverview) |
|
.get('/:fileUUID', getFileDetail) |
|
.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(); |
|
} |
|
}) |
|
.put('/:fileUUID', (request, response) => { |
|
console.log('Begin edit single file.'); |
|
|
|
const { fileUUID } = request.params; |
|
const { fileName, fileLocations, fileType } = request.body; |
|
|
|
let query = ''; |
|
|
|
if (fileName || fileType) { |
|
query += ` |
|
UPDATE files |
|
SET |
|
${fileName ? `file_name = '${fileName}',` : ''} |
|
${fileType ? `file_type = '${fileType}',` : ''} |
|
modified_date = '${accessDB.sub('refresh_timestamp').stdout}' |
|
WHERE |
|
file_uuid = '${fileUUID}';`; |
|
} |
|
|
|
if (fileLocations) { |
|
fileLocations.forEach(({ fileLocationUUID, isFileLocationActive }) => { |
|
const fileLocationActive = isFileLocationActive ? 1 : 0; |
|
|
|
query += ` |
|
UPDATE file_locations |
|
SET |
|
file_location_active = '${fileLocationActive}', |
|
modified_date = '${accessDB.sub('refresh_timestamp').stdout}' |
|
WHERE file_location_uuid = '${fileLocationUUID}';`; |
|
}); |
|
} |
|
|
|
console.log(`Query (type=[${typeof query}]): [${query}]`); |
|
|
|
let queryStdout; |
|
|
|
try { |
|
({ stdout: queryStdout } = accessDB.query(query, 'write')); |
|
} catch (queryError) { |
|
console.log(`Query error: ${queryError}`); |
|
|
|
response.status(500).send(); |
|
} |
|
|
|
console.log( |
|
`Query stdout (type=[${typeof queryStdout}]): ${JSON.stringify( |
|
queryStdout, |
|
null, |
|
2, |
|
)}`, |
|
); |
|
|
|
response.status(200).send(queryStdout); |
|
}); |
|
|
|
module.exports = router;
|
|
|