Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multipart upload interface for handlers #766

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading