Skip to content

Commit

Permalink
feat(upload-client): accept auto as store value (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut authored Jan 20, 2023
1 parent f52f26f commit e140644
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/upload-client/src/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { FailedResponse } from '../request/types'
import { getContentType } from '../tools/getContentType'
import { getFileName } from '../tools/getFileName'
import { getStoreValue } from '../tools/getStoreValue'
import { SupportedFileInput } from '../types'
import { StoreValue, SupportedFileInput } from '../types'
import { ProgressCallback, Uuid } from './types'

export type BaseResponse = {
Expand All @@ -32,7 +32,7 @@ export type BaseOptions = {
baseURL?: string
secureSignature?: string
secureExpire?: string
store?: boolean
store?: StoreValue
contentType?: string

signal?: AbortSignal
Expand Down
3 changes: 2 additions & 1 deletion packages/upload-client/src/api/fromUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getUserAgent } from '../tools/getUserAgent'
import { UploadClientError } from '../tools/errors'
import { retryIfFailed } from '../tools/retryIfFailed'
import { getStoreValue } from '../tools/getStoreValue'
import { StoreValue } from '../types'

export enum TypeEnum {
Token = 'token',
Expand Down Expand Up @@ -57,7 +58,7 @@ export type FromUrlOptions = {
publicKey: string

baseURL?: string
store?: boolean
store?: StoreValue
fileName?: string
checkForUrlDuplicates?: boolean
saveUrlForRecurrentUploads?: boolean
Expand Down
3 changes: 2 additions & 1 deletion packages/upload-client/src/api/multipartStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getUserAgent } from '../tools/getUserAgent'
import { retryIfFailed } from '../tools/retryIfFailed'
import { UploadClientError } from '../tools/errors'
import { getStoreValue } from '../tools/getStoreValue'
import { StoreValue } from '../types'

export type MultipartStartOptions = {
publicKey: string
Expand All @@ -26,7 +27,7 @@ export type MultipartStartOptions = {
baseURL?: string
secureSignature?: string
secureExpire?: string
store?: boolean
store?: StoreValue
multipartChunkSize?: number
signal?: AbortSignal
source?: string
Expand Down
9 changes: 7 additions & 2 deletions packages/upload-client/src/tools/getStoreValue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export function getStoreValue(store?: 'auto' | boolean): 'auto' | '0' | '1' {
return typeof store === 'undefined' ? 'auto' : store ? '1' : '0'
import { StoreValue } from '../types'

export function getStoreValue(store?: StoreValue): 'auto' | '0' | '1' {
if (typeof store === 'undefined' || store === 'auto') {
return 'auto'
}
return store ? '1' : '0'
}
4 changes: 3 additions & 1 deletion packages/upload-client/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { CustomUserAgent } from '@uploadcare/api-client-utils'

export type StoreValue = 'auto' | boolean

export interface DefaultSettings {
baseCDN: string
baseURL: string
Expand All @@ -18,7 +20,7 @@ export interface Settings extends Partial<DefaultSettings> {
publicKey: string
fileName?: string
contentType?: string
store?: boolean
store?: StoreValue
secureSignature?: string
secureExpire?: string
integration?: string
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-client/src/uploadFile/uploadDirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UploadcareFile } from '../tools/UploadcareFile'

import { CustomUserAgent, Metadata } from '@uploadcare/api-client-utils'
import { ProgressCallback } from '../api/types'
import { SupportedFileInput } from '../types'
import { StoreValue, SupportedFileInput } from '../types'

export type DirectOptions = {
publicKey: string
Expand All @@ -13,7 +13,7 @@ export type DirectOptions = {
baseURL?: string
secureSignature?: string
secureExpire?: string
store?: boolean
store?: StoreValue
contentType?: string

signal?: AbortSignal
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-client/src/uploadFile/uploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getFileSize } from '../tools/getFileSize'
import { isFileData } from '../tools/isFileData'
import { isMultipart } from '../tools/isMultipart'
import { UploadcareFile } from '../tools/UploadcareFile'
import { SupportedFileInput } from '../types'
import { StoreValue, SupportedFileInput } from '../types'
import { isUrl, isUuid } from './types'
import { uploadMultipart } from './uploadMultipart'

Expand All @@ -21,7 +21,7 @@ export type FileFromOptions = {
baseURL?: string
secureSignature?: string
secureExpire?: string
store?: boolean
store?: StoreValue

signal?: AbortSignal
onProgress?: ProgressCallback
Expand Down
4 changes: 2 additions & 2 deletions packages/upload-client/src/uploadFile/uploadMultipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { getContentType } from '../tools/getContentType'
import { getFileName } from '../tools/getFileName'
import { getFileSize } from '../tools/getFileSize'
import { SupportedFileInput } from '../types'
import { StoreValue, SupportedFileInput } from '../types'

export type MultipartOptions = {
publicKey: string
Expand All @@ -30,7 +30,7 @@ export type MultipartOptions = {
baseURL?: string
secureSignature?: string
secureExpire?: string
store?: boolean
store?: StoreValue
signal?: AbortSignal
onProgress?: ProgressCallback<ComputableProgressInfo>
source?: string
Expand Down
4 changes: 4 additions & 0 deletions packages/upload-client/test/tools/getStoreValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ describe('getStoreValue', () => {
expect(getStoreValue()).toEqual('auto')
})

it('should return auto if store is auto', () => {
expect(getStoreValue('auto')).toEqual('auto')
})

it('should return `1` if store is true', () => {
expect(getStoreValue(true)).toEqual('1')
})
Expand Down

0 comments on commit e140644

Please sign in to comment.