Skip to content

Commit 2570ab8

Browse files
committed
list API tags array input fix
1 parent 97cc1ff commit 2570ab8

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

libs/constants/errorMessages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default {
99
"FILE_ID_MISSING": { message: "Missing File ID parameter for this request", help: "" },
1010
"FILE_VERSION_ID_MISSING": { message: "Missing File version ID parameter for this request", help: "" },
1111
"FILE_ID_OR_URL_MISSING": { message: "Pass either File ID or remote URL of the image as first parameter", help: "" },
12+
"INVALID_LIST_OPTIONS": { message: "Pass a valid JSON list options e.g. {skip: 10, limit: 100}.", help: "" },
1213
"UPDATE_DATA_MISSING": { message: "Missing file update data for this request", help: "" },
1314
"UPDATE_DATA_TAGS_INVALID": { message: "Invalid tags parameter for this request", help: "tags should be passed as null or an array like ['tag1', 'tag2']" },
1415
"UPDATE_DATA_COORDS_INVALID": { message: "Invalid customCoordinates parameter for this request", help: "customCoordinates should be passed as null or a string like 'x,y,width,height'" },

libs/interfaces/ListFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ListFileOptions {
2222
/**
2323
* Comma-separated list of tags. Files matching any of the tags are included in result response. If no tag is matched, the file is not included in result set.
2424
*/
25-
tags?: string;
25+
tags?: string | string[];
2626
/**
2727
* Whether to include folders in search results or not. By default only files are searched.
2828
* Accepts true and false. If this is set to true then tags and fileType parameters are ignored.

libs/manage/file.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,14 @@ const listFiles = function (
225225
callback?: IKCallback<FileDetailsResponse[]>,
226226
) {
227227
if (listOptions && !_.isObject(listOptions)) {
228-
respond(true, errorMessages.UPDATE_DATA_MISSING, callback);
228+
respond(true, errorMessages.INVALID_LIST_OPTIONS, callback);
229229
return;
230230
}
231231

232+
if (listOptions && listOptions.tags && _.isArray(listOptions.tags) && listOptions.tags.length) {
233+
listOptions.tags = listOptions.tags.join(",");
234+
}
235+
232236
var requestOptions = {
233237
url: `https://api.imagekit.io/v1/files/`,
234238
method: "GET",

tests/mediaLibrary.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,18 @@ describe("Media library APIs", function () {
339339
it('List files', function (done) {
340340
var listOptions = {
341341
skip: 0,
342-
limit: 100
342+
limit: 100,
343+
tags: ["t-shirt", "summer"]
343344
}
344345

345346
const scope = nock('https://api.imagekit.io')
346347
.get(`/v1/files/`)
347348
.basicAuth({ user: initializationParams.privateKey, pass: '' })
348-
.query(listOptions)
349+
.query({
350+
skip: listOptions.skip,
351+
limit: listOptions.limit,
352+
tags: listOptions.tags.join(",")
353+
})
349354
.reply(function (uri, requestBody) {
350355
expect(requestBody).equal("")
351356
done()
@@ -377,7 +382,7 @@ describe("Media library APIs", function () {
377382
it('List files empty invalid options', function (done) {
378383
imagekit.listFiles("invalid", function (err, response) {
379384
expect(err).to.deep.equal({
380-
message: "Missing file update data for this request",
385+
message: "Pass a valid JSON list options e.g. {skip: 10, limit: 100}.",
381386
help: ""
382387
})
383388
done();

0 commit comments

Comments
 (0)