Skip to content

Commit 4a4b92c

Browse files
fix : add new functions to support optional file id and avoid errors to download and list zero files
1 parent 20dc2f6 commit 4a4b92c

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

Sources/InternxtSwiftCore/Services/HttpAPI/DriveAPI.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public struct DriveAPI {
5050
return try await apiClient.fetch(type: GetFolderFilesResponseNew.self, endpoint, debugResponse: debug)
5151
}
5252

53+
54+
public func getFolderFilesV2(folderUuid: String, offset: Int = 0, limit: Int = 50, order: String = "ASC", debug: Bool = false) async throws -> GetFolderFilesResponseV2 {
55+
56+
let query: String = "?limit=\(String(limit))&offset=\(String(offset))&order=\(order)"
57+
let endpoint = Endpoint(path: "\(self.baseUrl)/folders/content/\(folderUuid)/files\(query)")
58+
59+
return try await apiClient.fetch(type: GetFolderFilesResponseV2.self, endpoint, debugResponse: debug)
60+
}
61+
5362
/// Get paginated folders inside the given folder using uuid
5463
public func getFolderFolders(folderUuid: String, offset: Int = 0, limit: Int = 50, order: String = "ASC", debug: Bool = false) async throws -> GetFolderFoldersResponseNew {
5564

@@ -211,6 +220,16 @@ public struct DriveAPI {
211220
return try await apiClient.fetch(type: GetFileMetaByIdResponse.self, endpoint, debugResponse: debug)
212221
}
213222

223+
/// Get file with fileid optional
224+
public func getFileMetaByUuidV2(uuid: String, debug: Bool = false) async throws -> GetFileMetaByIdResponseV2 {
225+
let endpoint = Endpoint(
226+
path: "\(self.baseUrl)/files/\(uuid)/meta",
227+
method: .GET
228+
)
229+
230+
return try await apiClient.fetch(type: GetFileMetaByIdResponseV2.self, endpoint, debugResponse: debug)
231+
}
232+
214233
public func moveFile(fileId: String, bucketId: String, destinationFolder: Int, debug: Bool = false) async throws -> MoveFileResponse {
215234
let endpoint = Endpoint(
216235
path: "\(self.baseUrl)/storage/move/file",

Sources/InternxtSwiftCore/Types/DriveTypes.swift

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ public struct GetFolderFilesResult: Decodable {
3434
public let uuid: String
3535
}
3636

37+
public struct GetFolderFilesResultV2: Decodable {
38+
public let id: Int
39+
public let fileId: String?
40+
public let name: String
41+
public let type: String?
42+
// Size string in bytes
43+
public let size: String
44+
public let bucket: String
45+
public let folderId: Int
46+
public let encryptVersion: String?
47+
public let deleted: Bool?
48+
// ISO string
49+
public let deletedAt: String?
50+
public let userId: Int
51+
public let modificationTime: String
52+
// ISO string
53+
public let createdAt: String
54+
// ISO string
55+
public let updatedAt: String
56+
public let plainName: String?
57+
public let removed: Bool?
58+
// ISO string
59+
public let removedAt: String?
60+
public let status: String
61+
public let uuid: String
62+
}
63+
3764
public struct GetFolderFilesResponse: Decodable {
3865
public let result: Array<GetFolderFilesResult>
3966
}
@@ -42,6 +69,10 @@ public struct GetFolderFilesResponseNew: Decodable {
4269
public let files: Array<GetFolderFilesResult>
4370
}
4471

72+
public struct GetFolderFilesResponseV2: Decodable {
73+
public let files: Array<GetFolderFilesResultV2>
74+
}
75+
4576
public struct GetFolderFoldersResult: Decodable {
4677
public let type: String?
4778
public let id: Int
@@ -201,6 +232,28 @@ public struct GetFileMetaByIdResponse: Decodable {
201232
public let folderUuid: String?
202233
}
203234

235+
public struct GetFileMetaByIdResponseV2: Decodable {
236+
public let id: Int
237+
public let fileId: String?
238+
public let folderId: Int
239+
public let name: String
240+
public let type: String?
241+
public let size: String
242+
public let bucket: String
243+
public let deleted: Bool?
244+
public let deletedAt: String?
245+
public let userId: Int
246+
public let modificationTime: String
247+
public let createdAt: String
248+
public let updatedAt: String
249+
public let uuid: String
250+
public let plainName: String?
251+
public let removed: Bool?
252+
public let removedAt: String?
253+
public let status: String
254+
public let folderUuid: String?
255+
}
256+
204257

205258
public struct CreateFileData: Encodable {
206259
public let fileId: String
@@ -363,7 +416,7 @@ public struct CreateFileResponseNew: Decodable {
363416
public let type: String?
364417
public let size: String?
365418
public let folderId: Int
366-
public let fileId: String
419+
public let fileId: String?
367420
public let bucket: String
368421
public let encrypt_version: String
369422
public let userId: Int

0 commit comments

Comments
 (0)