Skip to content

Commit 8afc7ed

Browse files
committed
Merge branch 'dev'
2 parents ddab979 + 067768e commit 8afc7ed

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1111
[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)
1212

13-
Javascript SDK for [ImageKit](https://imagekit.io/) provides URL generation for image & video resizing and provides an interface for file upload. This SDK is lightweight and you can also use this as an ES module.
13+
Javascript SDK for [ImageKit](https://imagekit.io/) provides URL generation for image & video resizing and provides an interface for file upload. This SDK is lightweight and has no dependency. You can also use this as an ES module.
1414

1515
ImageKit is complete media storage, optimization, and transformation solution that comes with an [image and video CDN](https://imagekit.io/features/imagekit-infrastructure). It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
1616

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit-javascript",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "Javascript SDK for using ImageKit.io in the browser",
55
"main": "dist/imagekit.cjs.js",
66
"module": "dist/imagekit.esm.js",
@@ -29,6 +29,7 @@
2929
"formdata-node": "2.1.0",
3030
"mocha": "^7.0.1",
3131
"nyc": "^15.1.0",
32+
"regenerator-runtime": "^0.13.9",
3233
"rollup": "^2.22.0",
3334
"rollup-plugin-cleanup": "^3.2.1",
3435
"rollup-plugin-commonjs": "^10.1.0",
@@ -69,7 +70,5 @@
6970
"url": "https://github.com/imagekit-developer/imagekit-javascript/issues"
7071
},
7172
"homepage": "https://github.com/imagekit-developer/imagekit-javascript#readme",
72-
"dependencies": {
73-
"regenerator-runtime": "^0.13.9"
74-
}
73+
"dependencies": {}
7574
}

src/utils/request.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import respond from "../utils/respond";
22
import errorMessages from "../constants/errorMessages"
33
import { ImageKitOptions, UploadResponse } from "../interfaces";
44
import IKResponse from "../interfaces/IKResponse";
5-
import 'regenerator-runtime/runtime'
65

76
interface SignatureResponse {
87
signature: string
@@ -39,27 +38,25 @@ const addResponseHeadersAndBody = (body: any, xhr: XMLHttpRequest): IKResponse<U
3938
return response as IKResponse<UploadResponse>;
4039
}
4140

42-
export const request = async (
41+
export const request = (
4342
uploadFileXHR: XMLHttpRequest,
4443
formData: FormData,
4544
options: ImageKitOptions & { authenticationEndpoint: string },
4645
callback?: (err: Error | null, response: UploadResponse | null) => void) => {
47-
try {
48-
var signaturObj = await generateSignatureToken(options.authenticationEndpoint);
49-
} catch (ex) {
50-
return respond(true, ex, callback);
51-
}
5246

53-
formData.append("signature", signaturObj.signature);
54-
formData.append("expire", String(signaturObj.expire));
55-
formData.append("token", signaturObj.token);
47+
generateSignatureToken(options.authenticationEndpoint).then((signaturObj) => {
48+
formData.append("signature", signaturObj.signature);
49+
formData.append("expire", String(signaturObj.expire));
50+
formData.append("token", signaturObj.token);
5651

57-
try {
58-
var result = await uploadFile(uploadFileXHR, formData);
59-
return respond(false, result, callback);
60-
} catch (ex) {
52+
uploadFile(uploadFileXHR, formData).then((result) => {
53+
return respond(false, result, callback);
54+
}, (ex) => {
55+
return respond(true, ex, callback);
56+
});
57+
}, (ex) => {
6158
return respond(true, ex, callback);
62-
}
59+
});
6360
}
6461

6562
export const generateSignatureToken = (

test/upload.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const expect = chai.expect;
77
const initializationParams = require("./data").initializationParams
88
import ImageKit from "../src/index";
99
var requests, server;
10+
import 'regenerator-runtime/runtime'
1011

1112
const uploadSuccessResponseObj = {
1213
"fileId": "598821f949c0a938d57563bd",

0 commit comments

Comments
 (0)