Properly wire 'async' through the uploader
This commit is contained in:
parent
89b9cb4b47
commit
cbf5c5a748
4 changed files with 19 additions and 18 deletions
|
@ -17,7 +17,7 @@ export class Imgur extends ImageProvider {
|
|||
|
||||
static uploadMultiple(
|
||||
title: string, description: string, blobs: FileList,
|
||||
handleSuccessfullUpload: ((imageURL: string) => void),
|
||||
handleSuccessfullUpload: ((imageURL: string) => Promise<void>),
|
||||
allDone: (() => void),
|
||||
onFail: ((reason: string) => void),
|
||||
offset: number = 0) {
|
||||
|
@ -29,8 +29,8 @@ export class Imgur extends ImageProvider {
|
|||
const blob = blobs.item(offset);
|
||||
const self = this;
|
||||
this.uploadImage(title, description, blob,
|
||||
(imageUrl) => {
|
||||
handleSuccessfullUpload(imageUrl);
|
||||
async (imageUrl) => {
|
||||
await handleSuccessfullUpload(imageUrl);
|
||||
self.uploadMultiple(
|
||||
title, description, blobs,
|
||||
handleSuccessfullUpload,
|
||||
|
@ -45,7 +45,7 @@ export class Imgur extends ImageProvider {
|
|||
}
|
||||
|
||||
static uploadImage(title: string, description: string, blob: File,
|
||||
handleSuccessfullUpload: ((imageURL: string) => void),
|
||||
handleSuccessfullUpload: ((imageURL: string) => Promise<void>),
|
||||
onFail: (reason: string) => void) {
|
||||
|
||||
const apiUrl = 'https://api.imgur.com/3/image';
|
||||
|
@ -74,9 +74,9 @@ export class Imgur extends ImageProvider {
|
|||
// Response contains stringified JSON
|
||||
// Image URL available at response.data.link
|
||||
// @ts-ignore
|
||||
$.ajax(settings).done(function (response) {
|
||||
$.ajax(settings).done(async function (response) {
|
||||
response = JSON.parse(response);
|
||||
handleSuccessfullUpload(response.data.link);
|
||||
await handleSuccessfullUpload(response.data.link);
|
||||
}).fail((reason) => {
|
||||
console.log("Uploading to IMGUR failed", reason);
|
||||
// @ts-ignore
|
||||
|
|
|
@ -7,9 +7,9 @@ export default class ImgurUploader {
|
|||
public readonly failed: UIEventSource<string[]> = new UIEventSource<string[]>([]);
|
||||
public readonly success: UIEventSource<string[]> = new UIEventSource<string[]>([]);
|
||||
public maxFileSizeInMegabytes = 10;
|
||||
private readonly _handleSuccessUrl: (string) => void;
|
||||
private readonly _handleSuccessUrl: (string) => Promise<void>;
|
||||
|
||||
constructor(handleSuccessUrl: (string) => void) {
|
||||
constructor(handleSuccessUrl: (string) => Promise<void>) {
|
||||
this._handleSuccessUrl = handleSuccessUrl;
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,11 @@ export default class ImgurUploader {
|
|||
Imgur.uploadMultiple(title,
|
||||
description,
|
||||
files,
|
||||
function (url) {
|
||||
async function (url) {
|
||||
console.log("File saved at", url);
|
||||
self.success.data.push(url)
|
||||
self.success.ping();
|
||||
self._handleSuccessUrl(url);
|
||||
await self._handleSuccessUrl(url);
|
||||
},
|
||||
function () {
|
||||
console.log("All uploads completed");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue