Proper upload interface

This commit is contained in:
WolverinDEV 2019-09-01 21:35:59 +02:00
parent 469e5d25d2
commit 824ae8c4ff

View file

@ -49,6 +49,12 @@ namespace transfer {
request_file() : Promise<Response>; request_file() : Promise<Response>;
} }
export interface UploadTransfer {
put_data(data: BlobPart | File) : Promise<void>;
get_key(): transfer.UploadKey;
}
export type DownloadKey = TransferKey; export type DownloadKey = TransferKey;
export type UploadKey = TransferKey; export type UploadKey = TransferKey;
@ -56,7 +62,7 @@ namespace transfer {
export function spawn_download_transfer(key: DownloadKey) : DownloadTransfer { export function spawn_download_transfer(key: DownloadKey) : DownloadTransfer {
return new RequestFileDownload(key); return new RequestFileDownload(key);
} }
export function spawn_upload_transfer(key: UploadKey) : RequestFileUpload { export function spawn_upload_transfer(key: UploadKey) : UploadTransfer {
return new RequestFileUpload(key); return new RequestFileUpload(key);
} }
} }
@ -96,12 +102,16 @@ class RequestFileDownload implements transfer.DownloadTransfer {
} }
} }
class RequestFileUpload { class RequestFileUpload implements transfer.UploadTransfer {
readonly transfer_key: transfer.UploadKey; readonly transfer_key: transfer.UploadKey;
constructor(key: transfer.DownloadKey) { constructor(key: transfer.DownloadKey) {
this.transfer_key = key; this.transfer_key = key;
} }
get_key(): transfer.UploadKey {
return this.transfer_key;
}
async put_data(data: BlobPart | File) : Promise<void> { async put_data(data: BlobPart | File) : Promise<void> {
const form_data = new FormData(); const form_data = new FormData();