Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
manu4543 committed Jul 2, 2022
2 parents ddab979 + 067768e commit 8afc7ed
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)

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.
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.

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.

Expand Down
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagekit-javascript",
"version": "1.5.0",
"version": "1.5.1",
"description": "Javascript SDK for using ImageKit.io in the browser",
"main": "dist/imagekit.cjs.js",
"module": "dist/imagekit.esm.js",
Expand Down Expand Up @@ -29,6 +29,7 @@
"formdata-node": "2.1.0",
"mocha": "^7.0.1",
"nyc": "^15.1.0",
"regenerator-runtime": "^0.13.9",
"rollup": "^2.22.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-commonjs": "^10.1.0",
Expand Down Expand Up @@ -69,7 +70,5 @@
"url": "https://github.com/imagekit-developer/imagekit-javascript/issues"
},
"homepage": "https://github.com/imagekit-developer/imagekit-javascript#readme",
"dependencies": {
"regenerator-runtime": "^0.13.9"
}
"dependencies": {}
}
27 changes: 12 additions & 15 deletions src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import respond from "../utils/respond";
import errorMessages from "../constants/errorMessages"
import { ImageKitOptions, UploadResponse } from "../interfaces";
import IKResponse from "../interfaces/IKResponse";
import 'regenerator-runtime/runtime'

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

export const request = async (
export const request = (
uploadFileXHR: XMLHttpRequest,
formData: FormData,
options: ImageKitOptions & { authenticationEndpoint: string },
callback?: (err: Error | null, response: UploadResponse | null) => void) => {
try {
var signaturObj = await generateSignatureToken(options.authenticationEndpoint);
} catch (ex) {
return respond(true, ex, callback);
}

formData.append("signature", signaturObj.signature);
formData.append("expire", String(signaturObj.expire));
formData.append("token", signaturObj.token);
generateSignatureToken(options.authenticationEndpoint).then((signaturObj) => {
formData.append("signature", signaturObj.signature);
formData.append("expire", String(signaturObj.expire));
formData.append("token", signaturObj.token);

try {
var result = await uploadFile(uploadFileXHR, formData);
return respond(false, result, callback);
} catch (ex) {
uploadFile(uploadFileXHR, formData).then((result) => {
return respond(false, result, callback);
}, (ex) => {
return respond(true, ex, callback);
});
}, (ex) => {
return respond(true, ex, callback);
}
});
}

export const generateSignatureToken = (
Expand Down
1 change: 1 addition & 0 deletions test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const expect = chai.expect;
const initializationParams = require("./data").initializationParams
import ImageKit from "../src/index";
var requests, server;
import 'regenerator-runtime/runtime'

const uploadSuccessResponseObj = {
"fileId": "598821f949c0a938d57563bd",
Expand Down

0 comments on commit 8afc7ed

Please sign in to comment.