Skip to content

Commit 2c1296c

Browse files
committed
fix: added folder object in ListFileResponse
1 parent 001fb41 commit 2c1296c

File tree

7 files changed

+67
-70
lines changed

7 files changed

+67
-70
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,15 @@ imagekit.listFiles({
408408
limit : 10
409409
}, function(error, result) {
410410
if(error) console.log(error);
411-
else console.log(result);
411+
else {
412+
result.forEach((item) => {
413+
if (item.type === "folder") {
414+
console.log(item) // item is of type FolderObject
415+
} else {
416+
console.log(item) // item is of type FileObject
417+
}
418+
})
419+
};
412420
});
413421

414422

@@ -418,7 +426,13 @@ imagekit.listFiles({
418426
skip : 10,
419427
limit : 10
420428
}).then(response => {
421-
console.log(response);
429+
response.forEach((item) => {
430+
if (item.type === "folder") {
431+
console.log(item) // item is of type FolderObject
432+
} else {
433+
console.log(item) // item is of type FileObject
434+
}
435+
})
422436
}).catch(error => {
423437
console.log(error);
424438
});

index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CopyFolderResponse,
1111
FileDetailsOptions,
1212
FileObject,
13+
FolderObject,
1314
FileMetadataResponse,
1415
ImageKitOptions,
1516
ListFileOptions,
@@ -135,13 +136,13 @@ class ImageKit {
135136
*
136137
* @param listFilesOptions
137138
*/
138-
listFiles(listOptions: ListFileOptions): Promise<IKResponse<FileObject[]>>;
139-
listFiles(listOptions: ListFileOptions, callback: IKCallback<IKResponse<FileObject[]>>): void;
139+
listFiles(listOptions: ListFileOptions): Promise<IKResponse<ListFileResponse>>;
140+
listFiles(listOptions: ListFileOptions, callback: IKCallback<IKResponse<ListFileResponse>>): void;
140141
listFiles(
141142
listOptions: ListFileOptions,
142-
callback?: IKCallback<IKResponse<FileObject[]>>,
143-
): void | Promise<IKResponse<FileObject[]>> {
144-
return promisify<IKResponse<FileObject[]>>(this, manage.listFiles)(listOptions, this.options, callback);
143+
callback?: IKCallback<IKResponse<ListFileResponse>>,
144+
): void | Promise<IKResponse<ListFileResponse>> {
145+
return promisify<IKResponse<ListFileResponse>>(this, manage.listFiles)(listOptions, this.options, callback);
145146
}
146147

147148
/**

libs/interfaces/FileDetails.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { FileType } from "./FileType";
2-
import { Item } from "./Item";
32

43
export interface EmbeddedMetadataValues {
54
[key: string]:
@@ -56,13 +55,13 @@ export interface FileDetailsOptions {
5655
* Example - 50,50,500,500
5756
*/
5857
customCoordinates?: string;
59-
/*
60-
* Object with array of extensions to be processed on the image.
61-
*/
58+
/*
59+
* Object with array of extensions to be processed on the image.
60+
*/
6261
extensions?: Extension;
6362
/*
64-
* Final status of pending extensions will be sent to this URL.
65-
*/
63+
* Final status of pending extensions will be sent to this URL.
64+
*/
6665
webhookUrl?: string
6766
/*
6867
* Array of AI tags to remove from the asset.
@@ -93,9 +92,9 @@ export interface FileObject {
9392
*/
9493
fileId: string;
9594
/**
96-
* Type of item. It can be either file or folder.
95+
* Type of item. It can be either file, file-version or folder.
9796
*/
98-
type: Item;
97+
type: "file" | "file-version";
9998
/**
10099
* Name of the file or folder.
101100
*/
@@ -180,6 +179,38 @@ export interface FileObject {
180179
versionInfo?: { name: string; id: string };
181180
}
182181

182+
/**
183+
*
184+
* Folder object.
185+
*
186+
* @see {@link https://docs.imagekit.io/api-reference/media-api#file-object-structure}
187+
*/
188+
export interface FolderObject {
189+
/**
190+
* The unique fileId of the folder.
191+
*/
192+
folderId: string;
193+
/**
194+
* Type of item. It can be either file, file-version or folder.
195+
*/
196+
type: "folder";
197+
/**
198+
* Name of the file or folder.
199+
*/
200+
name: string;
201+
/**
202+
* The relative path of the folder.
203+
*/
204+
folderPath: string;
205+
/*
206+
* The date and time when the folder was first created. The format is YYYY-MM-DDTHH:mm:ss.sssZ
207+
*/
208+
createdAt: string;
209+
/*
210+
* The date and time when the folder was last updated. The format is YYYY-MM-DDTHH:mm:ss.sssZ
211+
*/
212+
updatedAt: string;
213+
}
183214

184215
export interface FileVersionDetailsOptions {
185216
/**
@@ -190,4 +221,4 @@ export interface FileVersionDetailsOptions {
190221
* The unique versionId of the uploaded file's version. This is returned in list files API and upload API as id within the versionInfo parameter.
191222
*/
192223
versionId: string;
193-
}
224+
}

libs/interfaces/Item.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

libs/interfaces/ListFile.ts

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { FileObject, FolderObject } from "./FileDetails";
12
import { FileType } from "./FileType";
2-
import { Item } from "./Item";
33

44
/**
55
* List and search files options
@@ -76,50 +76,4 @@ export interface ListFileOptions {
7676
*
7777
* @see {@link https://docs.imagekit.io/api-reference/media-api/list-and-search-files#response-structure-and-status-code-application-json}
7878
*/
79-
export interface ListFileResponse {
80-
/**
81-
* The unique fileId of the uploaded file.
82-
*/
83-
fileId: string;
84-
/**
85-
* Type of item. It can be either file or folder.
86-
*/
87-
type: Item;
88-
/**
89-
* Name of the file or folder.
90-
*/
91-
name: string;
92-
/**
93-
* The date and time when the file was first uploaded. The format is `YYYY-MM-DDTHH:mm:ss.sssZ`.
94-
*/
95-
createdAt: string;
96-
/**
97-
* The relative path of the file. In the case of an image, you can use this
98-
* path to construct different transformations.
99-
*/
100-
filePath: string;
101-
/**
102-
* Array of tags associated with the image. If no tags are set, it will be null.
103-
*/
104-
tags: string[] | null;
105-
/**
106-
* Is the file marked as private. It can be either true or false.
107-
*/
108-
isPrivateFile: boolean;
109-
/**
110-
* Value of custom coordinates associated with the image in format x,y,width,height. If customCoordinates are not defined then it is null.
111-
*/
112-
customCoordinates: string | null;
113-
/**
114-
* A publicly accessible URL of the file.
115-
*/
116-
url: string;
117-
/**
118-
* In case of an image, a small thumbnail URL.
119-
*/
120-
thumbnail: string;
121-
/**
122-
* The type of file, it could be either image or non-image.
123-
*/
124-
fileType: FileType;
125-
}
79+
export type ListFileResponse = Array<FileObject | FolderObject>;

libs/interfaces/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ListFileOptions, ListFileResponse } from "./ListFile";
88
import { CopyFileOptions } from "./CopyFile";
99
import { MoveFileOptions } from "./MoveFile";
1010
import { CreateFolderOptions } from "./CreateFolder";
11-
import { FileDetailsOptions, FileVersionDetailsOptions, FileObject } from "./FileDetails";
11+
import { FileDetailsOptions, FileVersionDetailsOptions, FileObject, FolderObject } from "./FileDetails";
1212
import { FileMetadataResponse } from "./FileMetadata";
1313
import { PurgeCacheResponse, PurgeCacheStatusResponse } from "./PurgeCache";
1414
import { BulkDeleteFilesResponse, BulkDeleteFilesError } from "./BulkDeleteFiles";
@@ -44,6 +44,7 @@ export type {
4444
FileDetailsOptions,
4545
FileVersionDetailsOptions,
4646
FileObject,
47+
FolderObject,
4748
FileMetadataResponse,
4849
PurgeCacheResponse,
4950
PurgeCacheStatusResponse,

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": "5.2.0",
3+
"version": "5.3.0",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

0 commit comments

Comments
 (0)