|
|
@ -1,6 +1,10 @@ |
|
|
|
const express = require('express'); |
|
|
|
const express = require('express'); |
|
|
|
|
|
|
|
|
|
|
|
const accessDB = require('../lib/accessDB'); |
|
|
|
const { |
|
|
|
|
|
|
|
dbJobAnvilSyncShared, |
|
|
|
|
|
|
|
dbQuery, |
|
|
|
|
|
|
|
dbSubRefreshTimestamp, |
|
|
|
|
|
|
|
} = 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'); |
|
|
|
const uploadSharedFiles = require('../middlewares/uploadSharedFiles'); |
|
|
|
const uploadSharedFiles = require('../middlewares/uploadSharedFiles'); |
|
|
@ -28,30 +32,98 @@ router |
|
|
|
|
|
|
|
|
|
|
|
const { fileUUID } = request.params; |
|
|
|
const { fileUUID } = request.params; |
|
|
|
const { fileName, fileLocations, fileType } = request.body; |
|
|
|
const { fileName, fileLocations, fileType } = request.body; |
|
|
|
|
|
|
|
const anvilSyncSharedFunctions = []; |
|
|
|
|
|
|
|
|
|
|
|
let query = ''; |
|
|
|
let query = ''; |
|
|
|
|
|
|
|
|
|
|
|
if (fileName || fileType) { |
|
|
|
if (fileName) { |
|
|
|
|
|
|
|
const [[oldFileName]] = dbQuery( |
|
|
|
|
|
|
|
`SELECT file_name FROM files WHERE file_uuid = '${fileUUID}';`, |
|
|
|
|
|
|
|
).stdout; |
|
|
|
|
|
|
|
console.log(`oldFileName=[${oldFileName}],newFileName=[${fileName}]`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fileName !== oldFileName) { |
|
|
|
|
|
|
|
query += ` |
|
|
|
|
|
|
|
UPDATE files |
|
|
|
|
|
|
|
SET |
|
|
|
|
|
|
|
file_name = '${fileName}', |
|
|
|
|
|
|
|
modified_date = '${dbSubRefreshTimestamp()}' |
|
|
|
|
|
|
|
WHERE file_uuid = '${fileUUID}';`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
anvilSyncSharedFunctions.push(() => |
|
|
|
|
|
|
|
dbJobAnvilSyncShared( |
|
|
|
|
|
|
|
'rename', |
|
|
|
|
|
|
|
`file_uuid=${fileUUID}\nold_name=${oldFileName}\nnew_name=${fileName}`, |
|
|
|
|
|
|
|
'0138', |
|
|
|
|
|
|
|
'0139', |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fileType) { |
|
|
|
query += ` |
|
|
|
query += ` |
|
|
|
UPDATE files |
|
|
|
UPDATE files |
|
|
|
SET |
|
|
|
SET |
|
|
|
${fileName ? `file_name = '${fileName}',` : ''} |
|
|
|
file_type = '${fileType}', |
|
|
|
${fileType ? `file_type = '${fileType}',` : ''} |
|
|
|
modified_date = '${dbSubRefreshTimestamp()}' |
|
|
|
modified_date = '${accessDB.sub('refresh_timestamp').stdout}' |
|
|
|
WHERE file_uuid = '${fileUUID}';`;
|
|
|
|
WHERE |
|
|
|
|
|
|
|
file_uuid = '${fileUUID}';`;
|
|
|
|
anvilSyncSharedFunctions.push(() => |
|
|
|
|
|
|
|
dbJobAnvilSyncShared( |
|
|
|
|
|
|
|
'check_mode', |
|
|
|
|
|
|
|
`file_uuid=${fileUUID}`, |
|
|
|
|
|
|
|
'0143', |
|
|
|
|
|
|
|
'0144', |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (fileLocations) { |
|
|
|
if (fileLocations) { |
|
|
|
fileLocations.forEach(({ fileLocationUUID, isFileLocationActive }) => { |
|
|
|
fileLocations.forEach(({ fileLocationUUID, isFileLocationActive }) => { |
|
|
|
const fileLocationActive = isFileLocationActive ? 1 : 0; |
|
|
|
let fileLocationActive = 0; |
|
|
|
|
|
|
|
let jobName = 'purge'; |
|
|
|
|
|
|
|
let jobTitle = '0136'; |
|
|
|
|
|
|
|
let jobDescription = '0137'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isFileLocationActive) { |
|
|
|
|
|
|
|
fileLocationActive = 1; |
|
|
|
|
|
|
|
jobName = 'pull_file'; |
|
|
|
|
|
|
|
jobTitle = '0132'; |
|
|
|
|
|
|
|
jobDescription = '0133'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
query += ` |
|
|
|
query += ` |
|
|
|
UPDATE file_locations |
|
|
|
UPDATE file_locations |
|
|
|
SET |
|
|
|
SET |
|
|
|
file_location_active = '${fileLocationActive}', |
|
|
|
file_location_active = '${fileLocationActive}', |
|
|
|
modified_date = '${accessDB.sub('refresh_timestamp').stdout}' |
|
|
|
modified_date = '${dbSubRefreshTimestamp()}' |
|
|
|
WHERE file_location_uuid = '${fileLocationUUID}';`;
|
|
|
|
WHERE file_location_uuid = '${fileLocationUUID}';`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const targetHosts = dbQuery( |
|
|
|
|
|
|
|
`SELECT
|
|
|
|
|
|
|
|
anv.anvil_node1_host_uuid, |
|
|
|
|
|
|
|
anv.anvil_node2_host_uuid, |
|
|
|
|
|
|
|
anv.anvil_dr1_host_uuid |
|
|
|
|
|
|
|
FROM anvils AS anv |
|
|
|
|
|
|
|
JOIN file_locations AS fil_loc |
|
|
|
|
|
|
|
ON anv.anvil_uuid = fil_loc.file_location_anvil_uuid |
|
|
|
|
|
|
|
WHERE fil_loc.file_location_uuid = '${fileLocationUUID}';`,
|
|
|
|
|
|
|
|
).stdout; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
targetHosts.flat().forEach((hostUUID) => { |
|
|
|
|
|
|
|
if (hostUUID) { |
|
|
|
|
|
|
|
anvilSyncSharedFunctions.push(() => |
|
|
|
|
|
|
|
dbJobAnvilSyncShared( |
|
|
|
|
|
|
|
jobName, |
|
|
|
|
|
|
|
`file_uuid=${fileUUID}`, |
|
|
|
|
|
|
|
jobTitle, |
|
|
|
|
|
|
|
jobDescription, |
|
|
|
|
|
|
|
{ jobHostUUID: hostUUID }, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -60,7 +132,7 @@ router |
|
|
|
let queryStdout; |
|
|
|
let queryStdout; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
({ stdout: queryStdout } = accessDB.query(query, 'write')); |
|
|
|
({ stdout: queryStdout } = dbQuery(query, 'write')); |
|
|
|
} catch (queryError) { |
|
|
|
} catch (queryError) { |
|
|
|
console.log(`Query error: ${queryError}`); |
|
|
|
console.log(`Query error: ${queryError}`); |
|
|
|
|
|
|
|
|
|
|
@ -74,6 +146,15 @@ router |
|
|
|
2, |
|
|
|
2, |
|
|
|
)}`,
|
|
|
|
)}`,
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
anvilSyncSharedFunctions.forEach((fn, index) => { |
|
|
|
|
|
|
|
console.log( |
|
|
|
|
|
|
|
`Anvil sync shared [${index}] output: [${JSON.stringify( |
|
|
|
|
|
|
|
fn(), |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
2, |
|
|
|
|
|
|
|
)}]`,
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
response.status(200).send(queryStdout); |
|
|
|
response.status(200).send(queryStdout); |
|
|
|
}); |
|
|
|
}); |
|
|
|