More refactoring, still very broken

This commit is contained in:
Pieter Vander Vennet 2021-06-11 22:51:45 +02:00
parent d5d90afc74
commit 62f471df1e
23 changed files with 428 additions and 356 deletions

View file

@ -10,11 +10,8 @@ export class Imgur {
handleSuccessfullUpload: ((imageURL: string) => void),
allDone: (() => void),
onFail: ((reason: string) => void),
offset:number) {
offset:number = 0) {
if(offset === undefined){
throw "Offset undefined - not uploading to prevent to much uploads!"
}
if (blobs.length == offset) {
allDone();
return;
@ -36,6 +33,7 @@ export class Imgur {
}
static getDescriptionOfImage(url: string,
handleDescription: ((license: LicenseInfo) => void)) {

View file

@ -0,0 +1,41 @@
import {UIEventSource} from "../UIEventSource";
import {Imgur} from "./Imgur";
export default class ImgurUploader {
public queue: UIEventSource<string[]>;
public failed: UIEventSource<string[]>;
public success: UIEventSource<string[]>
private readonly _handleSuccessUrl: (string) => void;
constructor(handleSuccessUrl: (string) => void) {
this._handleSuccessUrl = handleSuccessUrl;
}
public uploadMany(title: string, description: string, files: FileList) {
for (let i = 0; i < files.length; i++) {
this.queue.data.push(files.item(i).name)
}
this.queue.ping()
const self = this;
this.queue.setData([...self.queue.data])
Imgur.uploadMultiple(title,
description,
files,
function (url) {
console.log("File saved at", url);
self.success.setData([...self.success.data, url]);
this. handleSuccessUrl(url);
},
function () {
console.log("All uploads completed");
},
function (failReason) {
console.log("Upload failed due to ", failReason)
self.failed.setData([...self.failed.data, failReason])
}
);
}
}