Skip to content

Commit 804e41e

Browse files
committed
function signature
1 parent 83a4fd6 commit 804e41e

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

constants/errorMessages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ module.exports = {
1919
"MISSING_PHASH_VALUE": { message: "Missing pHash value", help: "Please pass two pHash values" },
2020
"UNEQUAL_STRING_LENGTH": { message: "Unequal pHash string length", help: "For distance calucation, the two pHash strings must have equal length" },
2121
//bulk delete errors
22-
"INVALID_FILEIDS_VALUE": {message: "Invalid value for fileIds", help: "fileIds should be an string array of fileId of the files to delete. The array should have atleast one fileId."}
22+
"INVALID_FILEIDS_VALUE": {message: "Invalid value for fileIds", help: "fileIds should be an string array of fileId of the files to delete. The array should have atleast one fileId.",},
23+
"BULK_ADD_TAGS_INVALID": {message: "Invalid value for tags", help: "tags should be a non empty array of string like ['tag1', 'tag2']."}
2324
};

index.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ var ImageKit = function(opts) {
100100
return manage.updateFileDetails(fileId, updateData, this.options, callback);
101101
});
102102

103+
// Add bulk tags
104+
this.bulkAddTags = promisify(function(fileIdArray, tags, callback) {
105+
return manage.bulkAddTags(fileIdArray, tags, this.options, callback);
106+
});
107+
108+
// Remove bulk tags
109+
this.bulkRemoveTags = promisify(function(fileIds, tags, callback) {
110+
return manage.bulkRemoveTags(fileIds, tags, this.options, callback);
111+
});
112+
103113
// Delete File API
104114
this.deleteFile = promisify(function(fileId, callback) {
105115
return manage.deleteFile(fileId, this.options, callback);
@@ -118,12 +128,47 @@ var ImageKit = function(opts) {
118128
this.bulkDeleteFiles = promisify(function(fileIdArray, callback) {
119129
return manage.bulkDeleteFiles(fileIdArray, this.options, callback);
120130
});
121-
131+
132+
// Copy files API
133+
this.copyFile = promisify(function(sourceFilePath, destinationPath, callback) {
134+
return manage.copyFile(sourceFilePath, destinationPath, this.options, callback);
135+
});
136+
137+
// Move files API
138+
this.moveFile = promisify(function(sourceFilePath, destinationPath, callback) {
139+
return manage.moveFile(sourceFilePath, destinationPath, this.options, callback);
140+
});
141+
142+
// Create folder API
143+
this.createFolder = promisify(function(folderName, parentFolderPath, callback) {
144+
return manage.createFolder(folderName, parentFolderPath, this.options, callback);
145+
});
146+
147+
// Delete folder API
148+
this.deleteFolder = promisify(function(folderPath, callback) {
149+
return manage.deleteFolder(folderPath, this.options, callback);
150+
});
151+
152+
// Copy folder API
153+
this.copyFolder = promisify(function(sourceFolderPath, destinationPath, callback) {
154+
return manage.copyFile(sourceFolderPath, destinationPath, this.options, callback);
155+
});
156+
157+
// Move folder API
158+
this.moveFolder = promisify(function(sourceFolderPath, destinationPath, callback) {
159+
return manage.moveFolder(sourceFolderPath, destinationPath, this.options, callback);
160+
});
161+
122162
// To generate Signature for upload request
123163
this.getAuthenticationParameters = function(token, timestamp) {
124164
return signature.getAuthenticationParameters(token, timestamp, this.options);
125165
};
126166

167+
// Get bulk job status API
168+
this.getBulkJobStatus = function(jobId) {
169+
return manage.getBulkJobStatus(jobId, this.options);
170+
};
171+
127172
// To calculate distance between two pHash strings
128173
this.pHashDistance = function(firstPHash, secondPHash) {
129174
return pHashUtils.pHashDistance(firstPHash, secondPHash);

libs/manage/file.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,38 @@ module.exports.bulkDeleteFiles = function(fileIdArray, defaultOptions, callback)
128128
json: data
129129
}
130130

131+
request(requestOptions, defaultOptions, callback);
132+
};
133+
134+
/*
135+
Add tags in bulk
136+
*/
137+
module.exports.bulkAddTags = function(fileIdArray, tags, defaultOptions, callback) {
138+
139+
if(!Array.isArray(fileIdArray)
140+
|| fileIdArray.length === 0
141+
|| fileIdArray.filter(fileId => typeof(fileId) !== 'string').length > 0) {
142+
respond(true, errorMessages.INVALID_FILEIDS_VALUE, callback);
143+
return;
144+
}
145+
146+
if(!Array.isArray(tags)
147+
|| tags.length === 0
148+
|| tags.filter(tag => typeof(tag) !== 'string').length > 0) {
149+
respond(true, errorMessages.BULK_ADD_TAGS_INVALID, callback);
150+
return;
151+
}
152+
153+
const data = {
154+
fileIds: fileIdArray,
155+
tags: tags
156+
}
157+
158+
const requestOptions = {
159+
url: "https://api.imagekit.io/v1/files/addTags",
160+
method: "POST",
161+
json: data
162+
}
163+
131164
request(requestOptions, defaultOptions, callback);
132165
};

0 commit comments

Comments
 (0)