|
|
@ -4,6 +4,7 @@ const { |
|
|
|
dbJobAnvilSyncShared, |
|
|
|
dbJobAnvilSyncShared, |
|
|
|
dbQuery, |
|
|
|
dbQuery, |
|
|
|
dbSubRefreshTimestamp, |
|
|
|
dbSubRefreshTimestamp, |
|
|
|
|
|
|
|
dbWrite, |
|
|
|
} = require('../lib/accessDB'); |
|
|
|
} = require('../lib/accessDB'); |
|
|
|
const getFilesOverview = require('../lib/request_handlers/files/getFilesOverview'); |
|
|
|
const getFilesOverview = require('../lib/request_handlers/files/getFilesOverview'); |
|
|
|
const getFileDetail = require('../lib/request_handlers/files/getFileDetail'); |
|
|
|
const getFileDetail = require('../lib/request_handlers/files/getFileDetail'); |
|
|
@ -12,6 +13,28 @@ const uploadSharedFiles = require('../middlewares/uploadSharedFiles'); |
|
|
|
const router = express.Router(); |
|
|
|
const router = express.Router(); |
|
|
|
|
|
|
|
|
|
|
|
router |
|
|
|
router |
|
|
|
|
|
|
|
.delete('/:fileUUID', (request, response) => { |
|
|
|
|
|
|
|
const { fileUUID } = request.params; |
|
|
|
|
|
|
|
const FILE_TYPE_DELETED = 'DELETED'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [[oldFileType]] = dbQuery( |
|
|
|
|
|
|
|
`SELECT file_type FROM files WHERE file_uuid = '${fileUUID}';`, |
|
|
|
|
|
|
|
).stdout; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (oldFileType !== FILE_TYPE_DELETED) { |
|
|
|
|
|
|
|
dbWrite( |
|
|
|
|
|
|
|
`UPDATE files
|
|
|
|
|
|
|
|
SET |
|
|
|
|
|
|
|
file_type = '${FILE_TYPE_DELETED}', |
|
|
|
|
|
|
|
modified_date = '${dbSubRefreshTimestamp()}' |
|
|
|
|
|
|
|
WHERE file_uuid = '${fileUUID}';`,
|
|
|
|
|
|
|
|
).stdout; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dbJobAnvilSyncShared('purge', `file_uuid=${fileUUID}`, '0136', '0137'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response.status(204).send(); |
|
|
|
|
|
|
|
}) |
|
|
|
.get('/', getFilesOverview) |
|
|
|
.get('/', getFilesOverview) |
|
|
|
.get('/:fileUUID', getFileDetail) |
|
|
|
.get('/:fileUUID', getFileDetail) |
|
|
|
.post('/', uploadSharedFiles.single('file'), ({ file, body }, response) => { |
|
|
|
.post('/', uploadSharedFiles.single('file'), ({ file, body }, response) => { |
|
|
@ -44,11 +67,11 @@ router |
|
|
|
|
|
|
|
|
|
|
|
if (fileName !== oldFileName) { |
|
|
|
if (fileName !== oldFileName) { |
|
|
|
query += ` |
|
|
|
query += ` |
|
|
|
UPDATE files |
|
|
|
UPDATE files |
|
|
|
SET |
|
|
|
SET |
|
|
|
file_name = '${fileName}', |
|
|
|
file_name = '${fileName}', |
|
|
|
modified_date = '${dbSubRefreshTimestamp()}' |
|
|
|
modified_date = '${dbSubRefreshTimestamp()}' |
|
|
|
WHERE file_uuid = '${fileUUID}';`;
|
|
|
|
WHERE file_uuid = '${fileUUID}';`;
|
|
|
|
|
|
|
|
|
|
|
|
anvilSyncSharedFunctions.push(() => |
|
|
|
anvilSyncSharedFunctions.push(() => |
|
|
|
dbJobAnvilSyncShared( |
|
|
|
dbJobAnvilSyncShared( |
|
|
@ -132,7 +155,7 @@ router |
|
|
|
let queryStdout; |
|
|
|
let queryStdout; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
({ stdout: queryStdout } = dbQuery(query, 'write')); |
|
|
|
({ stdout: queryStdout } = dbWrite(query)); |
|
|
|
} catch (queryError) { |
|
|
|
} catch (queryError) { |
|
|
|
console.log(`Query error: ${queryError}`); |
|
|
|
console.log(`Query error: ${queryError}`); |
|
|
|
|
|
|
|
|
|
|
|