fix(striker-ui-api): allow GET multiple files' detail

main
Tsu-ba-me 3 years ago
parent 411fd01a20
commit b583035630
  1. 31
      striker-ui-api/src/lib/request_handlers/files/buildQueryFilesDetail.ts
  2. 23
      striker-ui-api/src/lib/request_handlers/files/getFileDetail.ts
  3. 24
      striker-ui-api/src/lib/request_handlers/files/getFiles.ts
  4. 13
      striker-ui-api/src/lib/request_handlers/files/getFilesOverview.ts
  5. 4
      striker-ui-api/src/routes/files.ts

@ -0,0 +1,31 @@
const buildQueryFilesDetail = ({ filesUUID }: { filesUUID?: string[] }) => {
let condFilesUUID = '';
if (filesUUID instanceof Array && filesUUID.length > 0) {
const catFilesUUID = `'${filesUUID.join("', '")}'`;
condFilesUUID = `AND fil.file_uuid IN (${catFilesUUID})`;
}
return `
SELECT
fil.file_uuid,
fil.file_name,
fil.file_size,
fil.file_type,
fil.file_md5sum,
fil_loc.file_location_uuid,
fil_loc.file_location_active,
anv.anvil_uuid,
anv.anvil_name,
anv.anvil_description
FROM files AS fil
JOIN file_locations AS fil_loc
ON fil.file_uuid = fil_loc.file_location_file_uuid
JOIN anvils AS anv
ON fil_loc.file_location_anvil_uuid = anv.anvil_uuid
WHERE fil.file_type != 'DELETED'
${condFilesUUID};`;
};
export default buildQueryFilesDetail;

@ -1,25 +1,8 @@
import buildGetFiles from './buildGetFiles';
import buildQueryFilesDetail from './buildQueryFilesDetail';
const getFileDetail = buildGetFiles(
(request) =>
`SELECT
fil.file_uuid,
fil.file_name,
fil.file_size,
fil.file_type,
fil.file_md5sum,
fil_loc.file_location_uuid,
fil_loc.file_location_active,
anv.anvil_uuid,
anv.anvil_name,
anv.anvil_description
FROM files AS fil
JOIN file_locations AS fil_loc
ON fil.file_uuid = fil_loc.file_location_file_uuid
JOIN anvils AS anv
ON fil_loc.file_location_anvil_uuid = anv.anvil_uuid
WHERE fil.file_uuid = '${request.params.fileUUID}'
AND fil.file_type != 'DELETED';`,
const getFileDetail = buildGetFiles((request) =>
buildQueryFilesDetail({ filesUUID: [request.params.fileUUID] }),
);
export default getFileDetail;

@ -0,0 +1,24 @@
import buildGetFiles from './buildGetFiles';
import buildQueryFilesDetail from './buildQueryFilesDetail';
const getFiles = buildGetFiles((request) => {
const { filesUUID } = request.body;
let query = `
SELECT
file_uuid,
file_name,
file_size,
file_type,
file_md5sum
FROM files
WHERE file_type != 'DELETED';`;
if (filesUUID) {
query = buildQueryFilesDetail({ filesUUID });
}
return query;
});
export default getFiles;

@ -1,13 +0,0 @@
import buildGetFiles from './buildGetFiles';
const getFilesOverview = buildGetFiles(`
SELECT
file_uuid,
file_name,
file_size,
file_type,
file_md5sum
FROM files
WHERE file_type != 'DELETED';`);
export default getFilesOverview;

@ -6,7 +6,7 @@ import {
dbSubRefreshTimestamp,
dbWrite,
} from '../lib/accessDB';
import getFilesOverview from '../lib/request_handlers/files/getFilesOverview';
import getFiles from '../lib/request_handlers/files/getFiles';
import getFileDetail from '../lib/request_handlers/files/getFileDetail';
import uploadSharedFiles from '../middlewares/uploadSharedFiles';
@ -37,7 +37,7 @@ router
response.status(204).send();
})
.get('/', getFilesOverview)
.get('/', getFiles)
.get('/:fileUUID', getFileDetail)
.post('/', uploadSharedFiles.single('file'), ({ file, body }, response) => {
console.log('Receiving shared file.');

Loading…
Cancel
Save