Skip to content

Commit

Permalink
refactor(upload-client): rename some types
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Dec 29, 2022
1 parent 18ccb95 commit 533a1fc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
10 changes: 8 additions & 2 deletions packages/upload-client/src/UploadClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import { UploadcareGroup } from './tools/UploadcareGroup'
import { FileFromOptions, uploadFile } from './uploadFile'

import { FileInfo, GroupId, GroupInfo, Token, Url, Uuid } from './api/types'
import { SupportedFileInput, BrowserFile, NodeFile, Settings } from './types'
import {
SupportedFileInput,
BrowserFile,
NodeFile,
Settings,
Sliceable
} from './types'
import { uploadFileGroup, GroupFromOptions } from './uploadFileGroup'

/**
Expand Down Expand Up @@ -115,7 +121,7 @@ export default class UploadClient {
}

multipartUpload(
part: BrowserFile | NodeFile,
part: Sliceable,
url: MultipartPart,
options: Partial<MultipartUploadOptions> = {}
): Promise<MultipartUploadResponse> {
Expand Down
8 changes: 6 additions & 2 deletions packages/upload-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ export { Headers, ErrorRequestInfo } from './request/types'
export { UploadcareFile } from './tools/UploadcareFile'
export { UploadcareGroup } from './tools/UploadcareGroup'
export { UploadClientError, ErrorResponseInfo } from './tools/errors'
export { Settings, SupportedFileInput, ReactNativeFile } from './types'
export { NodeFile, BrowserFile, ReactNativeAsset } from './types'
export { Settings, SupportedFileInput as SupportedFileInput } from './types'
export {
NodeFile as NodeFile,
BrowserFile as BrowserFile,
ReactNativeAsset
} from './types'
export {
FileInfo,
GroupId,
Expand Down
5 changes: 2 additions & 3 deletions packages/upload-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export type ReactNativeAsset = {
uri: string
name?: string
}
export type ReactNativeFile = ReactNativeAsset | Blob

export type SupportedFileInput = BrowserFile | NodeFile | ReactNativeFile
export type AnySlicable = BrowserFile | NodeFile
export type SupportedFileInput = BrowserFile | NodeFile | ReactNativeAsset
export type Sliceable = BrowserFile | NodeFile
12 changes: 6 additions & 6 deletions packages/upload-client/src/uploadFile/sliceChunk.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AnySlicable } from '../types'
import { Sliceable } from '../types'

type Slicable<T> = T & { slice: (start: number, end: number) => Slicable<T> }
type Sliceable<T> = T & { slice: (start: number, end: number) => Sliceable<T> }

export const sliceChunk = <T extends AnySlicable>(
file: Slicable<T>,
export const sliceChunk = <T extends Sliceable>(
file: Sliceable<T>,
index: number,
fileSize: number,
chunkSize: number
): Slicable<T> => {
): Sliceable<T> => {
const start = chunkSize * index
const end = Math.min(start + chunkSize, fileSize)

return file.slice(start, end) as Slicable<T>
return file.slice(start, end) as Sliceable<T>
}
4 changes: 2 additions & 2 deletions packages/upload-client/src/uploadFile/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Url, Uuid } from '..'
import { SupportedFileInput, AnySlicable } from '../types'
import { SupportedFileInput, Sliceable } from '../types'
import { isFileData } from '../tools/isFileData'

/**
Expand Down Expand Up @@ -30,4 +30,4 @@ export type PrepareChunks = (
file: SupportedFileInput,
fileSize: number,
chunkSize: number
) => Promise<(index: number) => AnySlicable>
) => Promise<(index: number) => Sliceable>

0 comments on commit 533a1fc

Please sign in to comment.