Skip to content

Commit

Permalink
Merge pull request #91 from imagekit-developer/IK-1482
Browse files Browse the repository at this point in the history
added checks parameter
  • Loading branch information
imagekitio authored Jul 19, 2024
2 parents 3917883 + 3baa4ae commit 727dae4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagekit-javascript",
"version": "3.0.1",
"version": "3.0.2",
"description": "Javascript SDK for using ImageKit.io in the browser",
"main": "dist/imagekit.cjs.js",
"module": "dist/imagekit.esm.js",
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/UploadOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ export interface UploadOptions {
* Optional XMLHttpRequest object that you can send for upload API request. You can listen to `progress` and other events on this object for any custom logic.
*/
xhr?: XMLHttpRequest

/**
* Optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
*/
checks?: string
}
2 changes: 2 additions & 0 deletions src/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export const upload = (
} else if(key === "transformation" && typeof uploadOptions.transformation === "object" &&
uploadOptions.transformation !== null) {
formData.append(key, JSON.stringify(uploadOptions.transformation));
} else if (key === 'checks' && uploadOptions.checks) {
formData.append("checks", uploadOptions.checks);
} else if(uploadOptions[key] !== undefined) {
formData.append(key, String(uploadOptions[key]));
}
Expand Down
30 changes: 30 additions & 0 deletions test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,4 +1309,34 @@ describe("File upload", function () {
expect(callback.calledOnce).to.be.true;
sinon.assert.calledWith(callback, errRes, null);
});

it("With checks option", async function () {
const fileOptions = {
...securityParameters,
fileName: "test_file_name",
file: "test_file",
responseFields: "tags, customCoordinates, isPrivateFile, metadata",
useUniqueFileName: false,
checks: "'request.folder' : '/'",
};
var callback = sinon.spy();

imagekit.upload(fileOptions, callback);

expect(server.requests.length).to.be.equal(1);
await sleep();
successUploadResponse();
await sleep();

var arg = server.requests[0].requestBody;
expect(arg.get("file")).to.be.equal("test_file");
expect(arg.get("fileName")).to.be.equal("test_file_name");
expect(arg.get("responseFields")).to.be.equal("tags, customCoordinates, isPrivateFile, metadata");
expect(arg.get("useUniqueFileName")).to.be.equal("false");
expect(arg.get("publicKey")).to.be.equal("test_public_key");
expect(arg.get('checks')).to.be.equal("'request.folder' : '/'");

expect(callback.calledOnce).to.be.true;
sinon.assert.calledWith(callback, null, uploadSuccessResponseObj);
});
});

0 comments on commit 727dae4

Please sign in to comment.