Skip to content

Commit

Permalink
Replace File with FileLike
Browse files Browse the repository at this point in the history
  • Loading branch information
a179346 committed Mar 8, 2024
1 parent 9eb2662 commit 8b77050
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs-chunk-upload-action",
"version": "7.1.0",
"version": "8.0.0",
"description": "Uploading large files with chunking using server action in Next.js",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -52,4 +52,4 @@
"typescript",
"ts"
]
}
}
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
* [API Reference]: https://github.com/a179346/nextjs-chunk-upload-action/blob/main/docs/api-reference.md
*/

export interface FileLike {
readonly size: number;
slice(start?: number, end?: number, contentType?: string): Blob;
}

export type Primitive = string | boolean | number | undefined | null;

export type Metadata = Record<string, Primitive>;
Expand All @@ -27,7 +32,7 @@ export type ChunkUploadHandler<TMetadata extends Metadata = Metadata> = (
) => Promise<void>;

export interface ChunkUploaderOptions<TMetadata extends Metadata> {
file: File;
file: FileLike;
/**
* The function that defines how the chunk is uploaded to the server.
*/
Expand Down Expand Up @@ -200,7 +205,7 @@ export class ChunkUploader<TMetadata extends Metadata> {
protected _position: number;
protected _error?: unknown;

protected readonly _file: File;
protected readonly _file: FileLike;
protected readonly _onChunkUpload: ChunkUploadHandler<TMetadata>;
protected readonly _chunkBytes: number;
protected readonly _metadata: Readonly<TMetadata>;
Expand Down Expand Up @@ -271,7 +276,6 @@ export class ChunkUploader<TMetadata extends Metadata> {

protected _validateOptions(options: ChunkUploaderOptions<TMetadata>) {
if (!options.file) throw new Error('File is required');
if (!(options.file instanceof File)) throw new Error('File must be an instance of File');

if (typeof options.onChunkUpload !== 'function')
throw new Error('onChunkUpload must be a function');
Expand Down

0 comments on commit 8b77050

Please sign in to comment.