Skip to content

Commit

Permalink
feat(rest-client/convert): add saveInGroup option to document conve…
Browse files Browse the repository at this point in the history
…rsion method (#499)

Co-authored-by: Egor Didenko <[email protected]>
  • Loading branch information
nd0ut and Egor Didenko authored Nov 14, 2023
1 parent ef940a0 commit 50720b7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/rest-client/src/api/conversion/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe('convert', () => {
{
type: ConversionType.DOCUMENT,
paths: [`${DOCUMENT_UUID}/document/-/format/pdf/`, 'invalid'],
store: false
store: false,
saveInGroup: false
},
testSettings
)
Expand Down
16 changes: 12 additions & 4 deletions packages/rest-client/src/api/conversion/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ export async function convert<T extends ValueOf<typeof ConversionType>>(
options: ConversionOptions<T>,
userSettings: ApiRequestSettings
): Promise<ConversionResponse<ConversionResult[T]>> {
const isDocument = options.type === ConversionType.DOCUMENT

const body = {
paths: options.paths,
store: storeValueToString(options.store)
}

if (isDocument) {
body['save_in_group'] = options?.saveInGroup?.toString()
}

const apiRequest = await makeApiRequest(
{
method: 'POST',
path: `/convert/${options.type}/`,
body: {
paths: options.paths,
store: storeValueToString(options.store)
}
body
},
userSettings
)
Expand Down
7 changes: 5 additions & 2 deletions packages/rest-client/src/tools/conversionJobPoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ export const conversionJobPoller = <T extends ValueOf<typeof ConversionType>>(
ConversionJobPollerOptions<T>,
settings: ApiRequestSettings
) => {
const { onRun, onStatus, ...pollerOptions } = options
const { onRun, onStatus, ...rest } = options

const pollerOptions = rest as ConversionOptions<T> &
CreateJobPollerPollOptions

const poller = createJobPoller({
runner: convert,
runner: convert<T>,
resolveJobs: (response, runnerOptions, runnerSettings) => {
onRun && onRun(response as ConversionResponse<ConversionResult[T]>)
return runnerOptions.paths.map((path) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-client/src/tools/createJobPoller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CancelError, poll } from '@uploadcare/api-client-utils'

export type CrateJobPollerRunner<Options, Settings, ReturnType> = (
export type CreateJobPollerRunner<Options, Settings, ReturnType> = (
options: Options,
settings: Settings
) => ReturnType
Expand Down Expand Up @@ -41,7 +41,7 @@ type CrateJobPollerOptions<
ResultType,
ErrorType
> = {
runner: CrateJobPollerRunner<RunnerOptions, RunnerSettings, RunnerReturnType>
runner: CreateJobPollerRunner<RunnerOptions, RunnerSettings, RunnerReturnType>
resolveJobs: CreateJobPollerJobResolver<
RunnerReturnType,
JobType,
Expand Down
7 changes: 6 additions & 1 deletion packages/rest-client/src/types/ConversionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { ConversionType } from './ConversionType'
import { StoreValue } from '@uploadcare/api-client-utils'
import { ValueOf } from './ValueOf'

export type ConversionOptions<T extends ValueOf<typeof ConversionType>> = {
type BaseConversionOption<T> = {
type: T
paths: string[]
store?: StoreValue
}

export type ConversionOptions<T extends ValueOf<typeof ConversionType>> =
T extends ConversionType.VIDEO
? BaseConversionOption<T>
: BaseConversionOption<T> & { saveInGroup?: boolean }

0 comments on commit 50720b7

Please sign in to comment.