Skip to content

Commit 727dae4

Browse files
authored
Merge pull request #91 from imagekit-developer/IK-1482
added checks parameter
2 parents 3917883 + 3baa4ae commit 727dae4

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit-javascript",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "Javascript SDK for using ImageKit.io in the browser",
55
"main": "dist/imagekit.cjs.js",
66
"module": "dist/imagekit.esm.js",

src/interfaces/UploadOptions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,9 @@ export interface UploadOptions {
141141
* 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.
142142
*/
143143
xhr?: XMLHttpRequest
144+
145+
/**
146+
* Optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
147+
*/
148+
checks?: string
144149
}

src/upload/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export const upload = (
9090
} else if(key === "transformation" && typeof uploadOptions.transformation === "object" &&
9191
uploadOptions.transformation !== null) {
9292
formData.append(key, JSON.stringify(uploadOptions.transformation));
93+
} else if (key === 'checks' && uploadOptions.checks) {
94+
formData.append("checks", uploadOptions.checks);
9395
} else if(uploadOptions[key] !== undefined) {
9496
formData.append(key, String(uploadOptions[key]));
9597
}

test/upload.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,4 +1309,34 @@ describe("File upload", function () {
13091309
expect(callback.calledOnce).to.be.true;
13101310
sinon.assert.calledWith(callback, errRes, null);
13111311
});
1312+
1313+
it("With checks option", async function () {
1314+
const fileOptions = {
1315+
...securityParameters,
1316+
fileName: "test_file_name",
1317+
file: "test_file",
1318+
responseFields: "tags, customCoordinates, isPrivateFile, metadata",
1319+
useUniqueFileName: false,
1320+
checks: "'request.folder' : '/'",
1321+
};
1322+
var callback = sinon.spy();
1323+
1324+
imagekit.upload(fileOptions, callback);
1325+
1326+
expect(server.requests.length).to.be.equal(1);
1327+
await sleep();
1328+
successUploadResponse();
1329+
await sleep();
1330+
1331+
var arg = server.requests[0].requestBody;
1332+
expect(arg.get("file")).to.be.equal("test_file");
1333+
expect(arg.get("fileName")).to.be.equal("test_file_name");
1334+
expect(arg.get("responseFields")).to.be.equal("tags, customCoordinates, isPrivateFile, metadata");
1335+
expect(arg.get("useUniqueFileName")).to.be.equal("false");
1336+
expect(arg.get("publicKey")).to.be.equal("test_public_key");
1337+
expect(arg.get('checks')).to.be.equal("'request.folder' : '/'");
1338+
1339+
expect(callback.calledOnce).to.be.true;
1340+
sinon.assert.calledWith(callback, null, uploadSuccessResponseObj);
1341+
});
13121342
});

0 commit comments

Comments
 (0)