Skip to content

Commit f30ad6f

Browse files
authored
Merge pull request #36 from abhinavr4/feat/upload-options
Adding new upload options
2 parents 33bf005 + c4bf3ee commit f30ad6f

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

libs/interfaces/UploadOptions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,12 @@ export interface UploadOptions {
7676
/*
7777
* Final status of pending extensions will be sent to this URL.
7878
*/
79-
webhookUrl?: string
79+
webhookUrl?: string;
80+
overwriteFile?: boolean;
81+
overwriteAITags?: boolean;
82+
overwriteTags?: boolean;
83+
overwriteCustomMetadata?: boolean;
84+
customMetadata?: {
85+
[key: string]: string | number | boolean | Array<string | number | boolean>;
86+
}
8087
}

libs/upload/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ type FormDataOptions = Modify<
1414
isPrivateFile: string;
1515
extensions?: string;
1616
webhookUrl?: string;
17+
overwriteFile?: string;
18+
overwriteAITags?: string;
19+
overwriteTags?: string;
20+
overwriteCustomMetadata?: string;
21+
customMetadata?: string;
1722
}
1823
>;
1924

@@ -55,6 +60,9 @@ export default function (
5560
}
5661
else if(key == "extensions" && Array.isArray(uploadOptions.extensions)){
5762
formData.extensions = JSON.stringify(uploadOptions.extensions);
63+
} else if (key === "customMetadata" && typeof uploadOptions.customMetadata === "object" &&
64+
!Array.isArray(uploadOptions.customMetadata) && uploadOptions.customMetadata !== null) {
65+
formData.customMetadata = JSON.stringify(uploadOptions.customMetadata)
5866
}
5967
else {
6068
formData[key] = String(uploadOptions[key]);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit",
3-
"version": "3.2.4",
3+
"version": "3.2.5",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

tests/upload.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,20 @@ describe("File upload", function () {
107107
maxTags: 10
108108
}
109109
],
110-
webhookUrl: "https://your-domain/?appId=some-id"
110+
webhookUrl: "https://your-domain/?appId=some-id",
111+
overwriteFile: true,
112+
overwriteAITags: false,
113+
overwriteTags: true,
114+
overwriteCustomMetadata: false,
115+
customMetadata: {
116+
brand: "Nike",
117+
color: "red"
118+
},
111119
};
112120

113121
var callback = sinon.spy();
114122
var jsonStringifiedExtensions = JSON.stringify(fileOptions.extensions);
123+
const customMetadata = JSON.stringify(fileOptions.customMetadata);
115124

116125
const scope = nock('https://upload.imagekit.io/api')
117126
.post('/v1/files/upload')
@@ -127,6 +136,11 @@ describe("File upload", function () {
127136
checkFormData({requestBody,boundary,fieldName:"responseFields",fieldValue:"tags,metadata"});
128137
checkFormData({requestBody,boundary,fieldName:"extensions",fieldValue:jsonStringifiedExtensions});
129138
checkFormData({requestBody,boundary,fieldName:"webhookUrl",fieldValue:"https://your-domain/?appId=some-id"});
139+
checkFormData({requestBody,boundary,fieldName:"overwriteFile",fieldValue:"true"});
140+
checkFormData({requestBody,boundary,fieldName:"overwriteAITags",fieldValue:"false"});
141+
checkFormData({requestBody,boundary,fieldName:"overwriteTags",fieldValue:"true"});
142+
checkFormData({requestBody,boundary,fieldName:"overwriteCustomMetadata",fieldValue:"false"});
143+
checkFormData({requestBody,boundary,fieldName:"customMetadata",fieldValue:customMetadata});
130144
done()
131145
})
132146

0 commit comments

Comments
 (0)