Proper upload interface

canary
WolverinDEV 2019-09-01 21:35:59 +02:00
parent 469e5d25d2
commit 824ae8c4ff
1 changed files with 12 additions and 2 deletions

View File

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