diff --git a/README.md b/README.md index 81e116d..12f8e35 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,13 @@ Sample usage imagekit.upload({ file : , //required fileName : "my_file_name.jpg", //required + extensions: [ + { + name: "google-auto-tagging", + maxTags: 5, + minConfidence: 95 + } + ] }, function(error, result) { if(error) console.log(error); else console.log(result); @@ -258,6 +265,13 @@ imagekit.upload({ imagekit.upload({ file : , //required fileName : "my_file_name.jpg", //required + extensions: [ + { + name: "google-auto-tagging", + maxTags: 5, + minConfidence: 95 + } + ] }).then(response => { console.log(response); }).catch(error => { @@ -374,7 +388,14 @@ Update parameters associated with the file as per the [API documentation here](h imagekit.updateFileDetails("file_id", { tags : ['image_tag'], - customCoordinates : "10,10,100,100" + customCoordinates : "10,10,100,100", + extensions: [ + { + name: "google-auto-tagging", + maxTags: 5, + minConfidence: 95 + } + ] }, function(error, result) { if(error) console.log(error); else console.log(result); @@ -385,7 +406,14 @@ imagekit.updateFileDetails("file_id", { imagekit.updateFileDetails("file_id", { tags : ['image_tag'], - customCoordinates : "10,10,100,100" + customCoordinates : "10,10,100,100", + extensions: [ + { + name: "google-auto-tagging", + maxTags: 5, + minConfidence: 95 + } + ] }).then(response => { console.log(response); }).catch(error => { diff --git a/libs/interfaces/FileDetails.ts b/libs/interfaces/FileDetails.ts index dda6a5d..73e3e78 100644 --- a/libs/interfaces/FileDetails.ts +++ b/libs/interfaces/FileDetails.ts @@ -16,6 +16,14 @@ export interface FileDetailsOptions { * Example - 50,50,500,500 */ customCoordinates?: string; + /* + * Object with array of extensions to be processed on the image. + */ + extensions?: object[]; + /* + * Final status of pending extensions will be sent to this URL. + */ + webhookUrl?: string } /** @@ -68,4 +76,12 @@ export interface FileDetailsResponse { * The type of file, it could be either image or non-image. */ fileType: FileType; + /* + * AITags field is populated only because the google-auto-tagging extension was executed synchronously and it received a successresponse. + */ + AITags?: object[]; + /* + * Field object which will contain the status of each extension at the time of completion of the update/upload request. + */ + extensionStatus?: { [key: string]: string } } diff --git a/libs/interfaces/UploadOptions.ts b/libs/interfaces/UploadOptions.ts index bd27d7c..4dfe8f8 100644 --- a/libs/interfaces/UploadOptions.ts +++ b/libs/interfaces/UploadOptions.ts @@ -69,4 +69,12 @@ export interface UploadOptions { * For example, set the value of this field to tags,customCoordinates,isPrivateFile,metadata to get value of tags, customCoordinates, isPrivateFile , and metadata in the response. */ responseFields?: string; + /* + * Object with array of extensions to be processed on the image. + */ + extensions?: object[]; + /* + * Final status of pending extensions will be sent to this URL. + */ + webhookUrl?: string } diff --git a/libs/interfaces/UploadResponse.ts b/libs/interfaces/UploadResponse.ts index 6162a3d..04ab396 100644 --- a/libs/interfaces/UploadResponse.ts +++ b/libs/interfaces/UploadResponse.ts @@ -58,4 +58,12 @@ export interface UploadResponse { * The metadata of the upload file. Use responseFields property in request to get the metadata returned in response of upload API. */ metadata?: string; + /* + * AITags field is populated only because the google-auto-tagging extension was executed synchronously and it received a successresponse. + */ + AITags?: object[]; + /* + * Field object which will contain the status of each extension at the time of completion of the update/upload request. + */ + extensionStatus?: { [key: string]: string } } diff --git a/libs/manage/file.ts b/libs/manage/file.ts index 8cf625f..99f6af8 100644 --- a/libs/manage/file.ts +++ b/libs/manage/file.ts @@ -118,6 +118,8 @@ const updateDetails = function ( var data = { tags: updateData.tags, customCoordinates: updateData.customCoordinates, + extensions: updateData.extensions, + webhookUrl: updateData.webhookUrl }; var requestOptions = { diff --git a/libs/upload/index.ts b/libs/upload/index.ts index bcb6ed1..0f351d3 100644 --- a/libs/upload/index.ts +++ b/libs/upload/index.ts @@ -12,6 +12,8 @@ type FormDataOptions = Modify< file: string | Buffer | object; useUniqueFileName: string; isPrivateFile: string; + extensions?: string; + webhookUrl?: string; } >; @@ -50,7 +52,11 @@ export default function ( }; } else if (key == "tags" && Array.isArray(uploadOptions.tags)) { formData.tags = uploadOptions.tags.join(","); - } else { + } + else if(key == "extensions" && Array.isArray(uploadOptions.extensions)){ + formData.extensions = JSON.stringify(uploadOptions.extensions); + } + else { formData[key] = String(uploadOptions[key]); } } diff --git a/package.json b/package.json index e2ee6b0..23fe68e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "imagekit", - "version": "3.2.2", + "version": "3.2.3", "description": "Offical NodeJS SDK for ImageKit.io integration", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/sample/index.js b/sample/index.js index a2afbb8..032f2d9 100644 --- a/sample/index.js +++ b/sample/index.js @@ -80,6 +80,14 @@ const sampleApp = async () => { filesList[0].fileId, ["buildings", "day"], "10,10,100,100", + //Uncomment to send extensions parameter + // [ + // { + // name: "google-auto-tagging", + // maxTags: 5, + // minConfidence: 95 + // } + // ] ); console.log("File Update Response: ", JSON.stringify(fileUpdateResponse, undefined, 2), "\n"); @@ -168,7 +176,15 @@ const uploadFileBuffer = async (imagekitInstance, filePath, fileName) => { const uploadFileBase64 = async (imagekitInstance, filePath, fileName) => { const file_base64 = fs.readFileSync(filePath, "base64"); - const response = await imagekitInstance.upload({ file: file_base64, fileName }); + //Uncomment to send extensions parameter + // var extensions = [ + // { + // name: "google-auto-tagging", + // maxTags: 5, + // minConfidence: 95 + // } + // ]; + const response = await imagekitInstance.upload({ file: file_base64, fileName/*, extensions*/}); return response; }; @@ -195,12 +211,15 @@ const getFileMetadata = async (imagekitInstance, fileId) => { return response; }; -const updateFileDetails = async (imagekitInstance, fileId, tags = [], customCoordinates = "") => { +const updateFileDetails = async (imagekitInstance, fileId, tags = [], customCoordinates = "", extensions = [], webhookUrl = "") => { let options = {}; if (Array.isArray(tags) && tags.length > 0) Object.assign(options, { tags }); if (typeof customCoordinates === "string" && customCoordinates.length > 0) Object.assign(options, { customCoordinates }); - + if (Array.isArray(extensions) && extensions.length > 0) + Object.assign(options,{ extensions }); + if (typeof webhookUrl === "string" && webhookUrl.length > 0) + Object.assign(options,{ webhookUrl }) const response = await imagekitInstance.updateFileDetails(fileId, options); return response; }; diff --git a/tests/mediaLibrary.js b/tests/mediaLibrary.js index 732180f..9fb439d 100644 --- a/tests/mediaLibrary.js +++ b/tests/mediaLibrary.js @@ -263,7 +263,15 @@ describe("Media library APIs", function () { var updateData = { tags: ["tag1", "tag2"], - customCoordinates: "10,10,100,100" + customCoordinates: "10,10,100,100", + extensions: [ + { + name: "google-auto-tagging", + maxTags: 5, + minConfidence: 95 + } + ], + webhookUrl: "https://some-domain/some-api-id" } const scope = nock('https://api.imagekit.io') diff --git a/tests/upload.js b/tests/upload.js index 7aafd7c..f9747e9 100644 --- a/tests/upload.js +++ b/tests/upload.js @@ -23,7 +23,9 @@ const uploadSuccessResponseObj = { "tags": ["t-shirt", "round-neck", "sale2019"], "isPrivateFile": false, "customCoordinates": null, - "fileType": "image" + "fileType": "image", + "AITags":[{"name":"Face","confidence":99.95,"source":"aws-auto-tagging"}], + "extensionStatus":{"aws-auto-tagging":"success"} }; describe("File upload custom endpoint", function () { @@ -97,10 +99,19 @@ describe("File upload", function () { tags: ["tag1","tag2"], // array handling isPrivateFile: true, // Boolean handling useUniqueFileName: "false", // As string - responseFields : ["tags,metadata"] + responseFields : ["tags,metadata"], + extensions: [ + { + name: "aws-auto-tagging", + minConfidence: 80, + maxTags: 10 + } + ], + webhookUrl: "https://your-domain/?appId=some-id" }; var callback = sinon.spy(); + var jsonStringifiedExtensions = JSON.stringify(fileOptions.extensions); const scope = nock('https://upload.imagekit.io/api') .post('/v1/files/upload') @@ -114,6 +125,8 @@ describe("File upload", function () { checkFormData({requestBody,boundary,fieldName:"isPrivateFile",fieldValue:"true"}); checkFormData({requestBody,boundary,fieldName:"useUniqueFileName",fieldValue:"false"}); checkFormData({requestBody,boundary,fieldName:"responseFields",fieldValue:"tags,metadata"}); + checkFormData({requestBody,boundary,fieldName:"extensions",fieldValue:jsonStringifiedExtensions}); + checkFormData({requestBody,boundary,fieldName:"webhookUrl",fieldValue:"https://your-domain/?appId=some-id"}); done() })