Skip to content

Commit

Permalink
Add multipart upload interface for handlers
Browse files Browse the repository at this point in the history
Change-type: minor
  • Loading branch information
otaviojacobi committed Jun 19, 2024
1 parent e43632a commit 79c46b8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/webresource-handler/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as Express from 'express';
import busboy from 'busboy';
import type * as stream from 'node:stream';
import type { AnyObject } from '../sbvr-api/common-types';
import * as uriParser from '../sbvr-api/uri-parser';
import * as sbvrUtils from '../sbvr-api/sbvr-utils';
import type { HookArgs } from '../sbvr-api/hooks';
Expand Down Expand Up @@ -30,10 +31,43 @@ export interface UploadResponse {
filename: string;
}

export interface BeginMultipartUploadPayload {
filename: string;
content_type: string;
size: number;
chunk_size: number;
}

export interface UploadPart {
url: string;
chunkSize: number;
partNumber: number;
}

export interface BeginMultipartUploadHandlerResponse {
uploadParts: UploadPart[];
fileKey: string;
uploadId: string;
}

export interface CommitMultipartUploadPayload {
fileKey: string;
uploadId: string;
filename: string;
providerCommitData?: AnyObject;
}

export interface WebResourceHandler {
handleFile: (resource: IncomingFile) => Promise<UploadResponse>;
removeFile: (fileReference: string) => Promise<void>;
onPreRespond: (webResource: WebResource) => Promise<WebResource>;
beginMultipartUpload?: (
fieldName: string,
payload: BeginMultipartUploadPayload,
) => Promise<BeginMultipartUploadHandlerResponse>;
commitMultipartUpload?: (
commitInfo: CommitMultipartUploadPayload,
) => Promise<WebResource>;
}

export class WebResourceError extends TypedError {}
Expand Down

0 comments on commit 79c46b8

Please sign in to comment.