From 63efb75390e01793b1b3ea8f9ae2d38636d515eb Mon Sep 17 00:00:00 2001 From: nd0ut Date: Wed, 31 Aug 2022 14:20:12 +0300 Subject: [PATCH 1/4] chore: move video/document conversion methods to the `conversion` folder --- .../api/{addons => conversion}/convertDocument.test.ts | 0 .../src/api/{addons => conversion}/convertDocument.ts | 0 .../src/api/{addons => conversion}/convertVideo.test.ts | 0 .../src/api/{addons => conversion}/convertVideo.ts | 0 .../documentConversionJobStatus.test.ts | 0 .../{addons => conversion}/documentConversionJobStatus.ts | 0 .../videoConversionJobStatus.test.ts | 0 .../{addons => conversion}/videoConversionJobStatus.ts | 0 packages/rest-client/src/index.ts | 8 ++++---- 9 files changed, 4 insertions(+), 4 deletions(-) rename packages/rest-client/src/api/{addons => conversion}/convertDocument.test.ts (100%) rename packages/rest-client/src/api/{addons => conversion}/convertDocument.ts (100%) rename packages/rest-client/src/api/{addons => conversion}/convertVideo.test.ts (100%) rename packages/rest-client/src/api/{addons => conversion}/convertVideo.ts (100%) rename packages/rest-client/src/api/{addons => conversion}/documentConversionJobStatus.test.ts (100%) rename packages/rest-client/src/api/{addons => conversion}/documentConversionJobStatus.ts (100%) rename packages/rest-client/src/api/{addons => conversion}/videoConversionJobStatus.test.ts (100%) rename packages/rest-client/src/api/{addons => conversion}/videoConversionJobStatus.ts (100%) diff --git a/packages/rest-client/src/api/addons/convertDocument.test.ts b/packages/rest-client/src/api/conversion/convertDocument.test.ts similarity index 100% rename from packages/rest-client/src/api/addons/convertDocument.test.ts rename to packages/rest-client/src/api/conversion/convertDocument.test.ts diff --git a/packages/rest-client/src/api/addons/convertDocument.ts b/packages/rest-client/src/api/conversion/convertDocument.ts similarity index 100% rename from packages/rest-client/src/api/addons/convertDocument.ts rename to packages/rest-client/src/api/conversion/convertDocument.ts diff --git a/packages/rest-client/src/api/addons/convertVideo.test.ts b/packages/rest-client/src/api/conversion/convertVideo.test.ts similarity index 100% rename from packages/rest-client/src/api/addons/convertVideo.test.ts rename to packages/rest-client/src/api/conversion/convertVideo.test.ts diff --git a/packages/rest-client/src/api/addons/convertVideo.ts b/packages/rest-client/src/api/conversion/convertVideo.ts similarity index 100% rename from packages/rest-client/src/api/addons/convertVideo.ts rename to packages/rest-client/src/api/conversion/convertVideo.ts diff --git a/packages/rest-client/src/api/addons/documentConversionJobStatus.test.ts b/packages/rest-client/src/api/conversion/documentConversionJobStatus.test.ts similarity index 100% rename from packages/rest-client/src/api/addons/documentConversionJobStatus.test.ts rename to packages/rest-client/src/api/conversion/documentConversionJobStatus.test.ts diff --git a/packages/rest-client/src/api/addons/documentConversionJobStatus.ts b/packages/rest-client/src/api/conversion/documentConversionJobStatus.ts similarity index 100% rename from packages/rest-client/src/api/addons/documentConversionJobStatus.ts rename to packages/rest-client/src/api/conversion/documentConversionJobStatus.ts diff --git a/packages/rest-client/src/api/addons/videoConversionJobStatus.test.ts b/packages/rest-client/src/api/conversion/videoConversionJobStatus.test.ts similarity index 100% rename from packages/rest-client/src/api/addons/videoConversionJobStatus.test.ts rename to packages/rest-client/src/api/conversion/videoConversionJobStatus.test.ts diff --git a/packages/rest-client/src/api/addons/videoConversionJobStatus.ts b/packages/rest-client/src/api/conversion/videoConversionJobStatus.ts similarity index 100% rename from packages/rest-client/src/api/addons/videoConversionJobStatus.ts rename to packages/rest-client/src/api/conversion/videoConversionJobStatus.ts diff --git a/packages/rest-client/src/index.ts b/packages/rest-client/src/index.ts index 81f56075a..8b4413ec3 100644 --- a/packages/rest-client/src/index.ts +++ b/packages/rest-client/src/index.ts @@ -178,19 +178,19 @@ export { convertVideo, ConvertVideoResponse, ConvertVideoOptions -} from './api/addons/convertVideo' +} from './api/conversion/convertVideo' export { convertDocument, ConvertDocumentResponse, ConvertDocumentOptions -} from './api/addons/convertDocument' +} from './api/conversion/convertDocument' export { documentConversionJobStatus, DocumentConversionJobStatusResponse, DocumentConversionJobStatusOptions -} from './api/addons/documentConversionJobStatus' +} from './api/conversion/documentConversionJobStatus' export { videoConversionJobStatus, VideoConversionJobStatusResponse, VideoConversionJobStatusOptions -} from './api/addons/videoConversionJobStatus' +} from './api/conversion/videoConversionJobStatus' From 5b7123f2997a05e0b1a3b8fee81bfeea9457ae6a Mon Sep 17 00:00:00 2001 From: nd0ut Date: Wed, 31 Aug 2022 16:54:03 +0300 Subject: [PATCH 2/4] feat: add `executeAddon` and `addonExecutionStatus` --- .../api/addons/addonExecutionStatus.test.ts | 22 +++++++++++++--- .../src/api/addons/executeAddon.test.ts | 16 +++++++++--- .../src/api/addons/executeAddon.ts | 17 ++++++++---- packages/rest-client/src/index.ts | 20 ++++++++++++++ packages/rest-client/src/types/AddonName.ts | 3 ++- packages/rest-client/src/types/AddonParams.ts | 26 +++++++++++++++++++ packages/rest-client/test/fixtures.ts | 1 + 7 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 packages/rest-client/src/types/AddonParams.ts diff --git a/packages/rest-client/src/api/addons/addonExecutionStatus.test.ts b/packages/rest-client/src/api/addons/addonExecutionStatus.test.ts index e7d7e8e86..220943f88 100644 --- a/packages/rest-client/src/api/addons/addonExecutionStatus.test.ts +++ b/packages/rest-client/src/api/addons/addonExecutionStatus.test.ts @@ -3,13 +3,29 @@ import { addonExecutionStatus } from './addonExecutionStatus' import { testSettings } from '../../../test/helpers' import { AddonName } from '../../types/AddonName' +import { executeAddon } from './executeAddon' +import { ADDONS_UUID } from '../../../test/fixtures' +import { copyFileToLocalStorage } from '../file/copyFileToLocalStorage' -describe.skip('addonExecutionStatus', () => { +describe('addonExecutionStatus', () => { it('should work', async () => { + const copy = await copyFileToLocalStorage( + { source: ADDONS_UUID, store: false }, + testSettings + ) + + const { requestId } = await executeAddon( + { + addonName: AddonName.AWS_REKOGNITION_DETECT_LABELS, + target: copy.result.uuid + }, + testSettings + ) + const response = await addonExecutionStatus( { - addonName: AddonName.UC_CLAMAV_VIRUS_SCAN, - requestId: 'requestId' + addonName: AddonName.AWS_REKOGNITION_DETECT_LABELS, + requestId: requestId }, testSettings ) diff --git a/packages/rest-client/src/api/addons/executeAddon.test.ts b/packages/rest-client/src/api/addons/executeAddon.test.ts index 323689dbe..f2de4daba 100644 --- a/packages/rest-client/src/api/addons/executeAddon.test.ts +++ b/packages/rest-client/src/api/addons/executeAddon.test.ts @@ -3,12 +3,21 @@ import { executeAddon } from './executeAddon' import { testSettings } from '../../../test/helpers' import { AddonName } from '../../types/AddonName' +import { ADDONS_UUID } from '../../../test/fixtures' +import { copyFileToLocalStorage } from '../file/copyFileToLocalStorage' -describe.skip('executeAddon', () => { +describe('executeAddon', () => { it('should work', async () => { + const copy = await copyFileToLocalStorage( + { source: ADDONS_UUID, store: false }, + testSettings + ) + const response = await executeAddon( { - addonName: AddonName.UC_CLAMAV_VIRUS_SCAN + addonName: AddonName.AWS_REKOGNITION_DETECT_LABELS, + target: copy.result.uuid, + params: undefined }, testSettings ) @@ -19,7 +28,8 @@ describe.skip('executeAddon', () => { await expect( executeAddon( { - addonName: 'invalid' as AddonName + addonName: 'invalid' as AddonName, + target: ADDONS_UUID }, testSettings ) diff --git a/packages/rest-client/src/api/addons/executeAddon.ts b/packages/rest-client/src/api/addons/executeAddon.ts index 74a8e7732..0a39f9348 100644 --- a/packages/rest-client/src/api/addons/executeAddon.ts +++ b/packages/rest-client/src/api/addons/executeAddon.ts @@ -1,23 +1,30 @@ import { makeApiRequest, ApiRequestSettings } from '../../makeApiRequest' import { AddonName } from '../../types/AddonName' +import { AddonParams } from '../../types/AddonParams' import { handleApiRequest } from '../handleApiRequest' -export type ExecuteAddonOptions = { - addonName: AddonName +export type ExecuteAddonOptions = { + addonName: T + target: string + params?: AddonParams[T] } export type ExecuteAddonResponse = { requestId: string } -export async function executeAddon( - options: ExecuteAddonOptions, +export async function executeAddon( + options: ExecuteAddonOptions, userSettings: ApiRequestSettings ): Promise { const apiRequest = await makeApiRequest( { method: 'POST', - path: `/addons/${options.addonName}/execute/` + path: `/addons/${options.addonName}/execute/`, + body: { + target: options.target, + params: options.params + } }, userSettings ) diff --git a/packages/rest-client/src/index.ts b/packages/rest-client/src/index.ts index 8b4413ec3..19f7ad8d7 100644 --- a/packages/rest-client/src/index.ts +++ b/packages/rest-client/src/index.ts @@ -5,6 +5,12 @@ export { ApiRequestSettings } from './makeApiRequest' export { UserSettings } from './settings' export { AddonExecutionStatus } from './types/AddonExecutionStatus' export { AddonName } from './types/AddonName' +export { + AddonParams, + AddonUcClamavVirusScanParams, + AddonAwsRekognitionDetectLabelsParams, + AddonRemoveBgParams +} from './types/AddonParams' export { AppData, ClamavVirusScan, @@ -194,3 +200,17 @@ export { VideoConversionJobStatusResponse, VideoConversionJobStatusOptions } from './api/conversion/videoConversionJobStatus' + +/** + * Low-level Addons API + */ +export { + executeAddon, + ExecuteAddonResponse, + ExecuteAddonOptions +} from './api/addons/executeAddon' +export { + addonExecutionStatus, + AddonExecutionStatusResponse, + AddonExecutionStatusOptions +} from './api/addons/addonExecutionStatus' diff --git a/packages/rest-client/src/types/AddonName.ts b/packages/rest-client/src/types/AddonName.ts index c935e23dc..59bbf6aea 100644 --- a/packages/rest-client/src/types/AddonName.ts +++ b/packages/rest-client/src/types/AddonName.ts @@ -1,4 +1,5 @@ export enum AddonName { UC_CLAMAV_VIRUS_SCAN = 'uc_clamav_virus_scan', - AWS_REKOGNITION_DETECT_LABELS = 'aws_rekognition_detect_labels' + AWS_REKOGNITION_DETECT_LABELS = 'aws_rekognition_detect_labels', + REMOVE_BG = 'remove_bg' } diff --git a/packages/rest-client/src/types/AddonParams.ts b/packages/rest-client/src/types/AddonParams.ts new file mode 100644 index 000000000..e970a96da --- /dev/null +++ b/packages/rest-client/src/types/AddonParams.ts @@ -0,0 +1,26 @@ +import { AddonName } from './AddonName' + +export type AddonUcClamavVirusScanParams = { + purgeInfected: boolean +} + +export type AddonAwsRekognitionDetectLabelsParams = undefined + +export type AddonRemoveBgParams = { + crop?: boolean + cropMargin?: string + scale?: string + addShadow?: boolean + typeLevel?: 'none' | '1' | '2' | 'latest' + type?: 'auto' | 'person' | 'product' | 'car' + semitransparency?: boolean + channels?: 'rgba' | 'alpha' + roi?: string + position?: string +} + +export type AddonParams = { + [AddonName.UC_CLAMAV_VIRUS_SCAN]: AddonUcClamavVirusScanParams + [AddonName.AWS_REKOGNITION_DETECT_LABELS]: AddonAwsRekognitionDetectLabelsParams + [AddonName.REMOVE_BG]: AddonRemoveBgParams +} diff --git a/packages/rest-client/test/fixtures.ts b/packages/rest-client/test/fixtures.ts index e27cd90ed..a764d088e 100644 --- a/packages/rest-client/test/fixtures.ts +++ b/packages/rest-client/test/fixtures.ts @@ -7,3 +7,4 @@ export const GROUP_FILE_UUID = '749aee13-a313-48bf-a252-a7eeaadc1b55' export const INVALID_UUID = 'invalid-uuid-4f20-966f-caed5f978e15' export const DOCUMENT_UUID = 'bf96bce4-0c49-491a-887d-9855b319c549' export const VIDEO_UUID = '6992a455-5eb6-49a0-972a-36de53f51b5b' +export const ADDONS_UUID = 'd666789a-0067-4662-addf-c8452f6153bf' From c907c73c3dd067aefc20dc87e42057761dcca343 Mon Sep 17 00:00:00 2001 From: nd0ut Date: Wed, 31 Aug 2022 16:57:55 +0300 Subject: [PATCH 3/4] chore: export `GetUserAgentOptions` type --- packages/rest-client/src/index.ts | 3 ++- packages/upload-client/src/index.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/rest-client/src/index.ts b/packages/rest-client/src/index.ts index 19f7ad8d7..4d2dd9988 100644 --- a/packages/rest-client/src/index.ts +++ b/packages/rest-client/src/index.ts @@ -40,7 +40,8 @@ export { AudioInfo, CustomUserAgent, CustomUserAgentFn, - CustomUserAgentOptions + CustomUserAgentOptions, + GetUserAgentOptions } from '@uploadcare/api-client-utils' /** diff --git a/packages/upload-client/src/index.ts b/packages/upload-client/src/index.ts index 0b5c6cdfc..395bc54b1 100644 --- a/packages/upload-client/src/index.ts +++ b/packages/upload-client/src/index.ts @@ -21,7 +21,7 @@ export { default as uploadFileGroup } from './uploadFileGroup' /* Helpers */ export { default as UploadClient } from './UploadClient' -export { getUserAgent } from '@uploadcare/api-client-utils' +export { getUserAgent, GetUserAgentOptions } from '@uploadcare/api-client-utils' /* Types */ export { UploadcareFile } from './tools/UploadcareFile' From 6a11d9996c9c741371082210ac9745a8d7f9cf3d Mon Sep 17 00:00:00 2001 From: nd0ut Date: Tue, 13 Sep 2022 18:11:26 +0300 Subject: [PATCH 4/4] chore: use snake case to pass addon params --- packages/rest-client/src/api/addons/executeAddon.test.ts | 6 ++++-- packages/rest-client/src/types/AddonParams.ts | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/rest-client/src/api/addons/executeAddon.test.ts b/packages/rest-client/src/api/addons/executeAddon.test.ts index f2de4daba..ce02e4bbb 100644 --- a/packages/rest-client/src/api/addons/executeAddon.test.ts +++ b/packages/rest-client/src/api/addons/executeAddon.test.ts @@ -15,9 +15,11 @@ describe('executeAddon', () => { const response = await executeAddon( { - addonName: AddonName.AWS_REKOGNITION_DETECT_LABELS, + addonName: AddonName.UC_CLAMAV_VIRUS_SCAN, target: copy.result.uuid, - params: undefined + params: { + purge_infected: false + } }, testSettings ) diff --git a/packages/rest-client/src/types/AddonParams.ts b/packages/rest-client/src/types/AddonParams.ts index e970a96da..6604a6e34 100644 --- a/packages/rest-client/src/types/AddonParams.ts +++ b/packages/rest-client/src/types/AddonParams.ts @@ -1,17 +1,17 @@ import { AddonName } from './AddonName' export type AddonUcClamavVirusScanParams = { - purgeInfected: boolean + purge_infected: boolean } export type AddonAwsRekognitionDetectLabelsParams = undefined export type AddonRemoveBgParams = { crop?: boolean - cropMargin?: string + crop_margin?: string scale?: string - addShadow?: boolean - typeLevel?: 'none' | '1' | '2' | 'latest' + add_shadow?: boolean + type_level?: 'none' | '1' | '2' | 'latest' type?: 'auto' | 'person' | 'product' | 'car' semitransparency?: boolean channels?: 'rgba' | 'alpha'