fix(striker-ui-api): allow using all or * as condition file/anvil UUIDs

main
Tsu-ba-me 3 years ago
parent 2c4a025cf8
commit 011615e68f
  1. 11
      striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts
  2. 11
      striker-ui-api/src/lib/request_handlers/file/buildQueryFileDetail.ts
  3. 4
      striker-ui-api/src/lib/sanitizeQS.ts
  4. 2
      striker-ui-api/src/lib/sanitizeSQLParam.ts

@ -4,17 +4,22 @@ import NODE_AND_DR_RESERVED_MEMORY_SIZE from '../../consts/NODE_AND_DR_RESERVED_
import SERVER_PATHS from '../../consts/SERVER_PATHS'; import SERVER_PATHS from '../../consts/SERVER_PATHS';
import join from '../../join'; import join from '../../join';
import { sanitizeSQLParam } from '../../sanitizeSQLParam';
const buildQueryAnvilDetail = ({ const buildQueryAnvilDetail = ({
anvilUUIDs, anvilUUIDs = ['*'],
isForProvisionServer, isForProvisionServer,
}: { }: {
anvilUUIDs?: string[] | '*'; anvilUUIDs?: string[] | '*';
isForProvisionServer?: boolean; isForProvisionServer?: boolean;
}) => { }) => {
const condAnvilsUUID = join(anvilUUIDs, { const condAnvilsUUID = ['all', '*'].includes(anvilUUIDs[0])
? ''
: join(anvilUUIDs, {
beforeReturn: (toReturn) => beforeReturn: (toReturn) =>
toReturn ? `WHERE anv.anvil_uuid IN (${toReturn})` : '', toReturn
? `WHERE anv.anvil_uuid IN (${sanitizeSQLParam(toReturn)})`
: '',
elementWrapper: "'", elementWrapper: "'",
separator: ', ', separator: ', ',
}); });

@ -1,13 +1,18 @@
import join from '../../join'; import join from '../../join';
import { sanitizeSQLParam } from '../../sanitizeSQLParam';
const buildQueryFileDetail = ({ const buildQueryFileDetail = ({
fileUUIDs, fileUUIDs = ['*'],
}: { }: {
fileUUIDs?: string[] | '*'; fileUUIDs?: string[] | '*';
}) => { }) => {
const condFileUUIDs = join(fileUUIDs, { const condFileUUIDs = ['all', '*'].includes(fileUUIDs[0])
? ''
: join(fileUUIDs, {
beforeReturn: (toReturn) => beforeReturn: (toReturn) =>
toReturn ? `AND fil.file_uuid IN (${toReturn})` : '', toReturn
? `AND fil.file_uuid IN (${sanitizeSQLParam(toReturn)})`
: '',
elementWrapper: "'", elementWrapper: "'",
separator: ', ', separator: ', ',
}); });

@ -19,10 +19,8 @@ const MAP_TO_RETURN_FUNCTION: MapToReturnFunction = {
: String(qs).split(/[,;]/), : String(qs).split(/[,;]/),
}; };
const sanitizeQS = <ReturnTypeName extends keyof MapToReturnType>( export const sanitizeQS = <ReturnTypeName extends keyof MapToReturnType>(
qs: unknown, qs: unknown,
{ returnType = 'string' }: { returnType?: ReturnTypeName | 'string' } = {}, { returnType = 'string' }: { returnType?: ReturnTypeName | 'string' } = {},
): MapToReturnType[ReturnTypeName] => ): MapToReturnType[ReturnTypeName] =>
MAP_TO_RETURN_FUNCTION[returnType](qs) as MapToReturnType[ReturnTypeName]; MAP_TO_RETURN_FUNCTION[returnType](qs) as MapToReturnType[ReturnTypeName];
export { sanitizeQS };

@ -0,0 +1,2 @@
export const sanitizeSQLParam = (variable: string): string =>
variable.replaceAll(/[']/g, '');
Loading…
Cancel
Save