Files
suixinkan_uikit/suixinkan/Features/CloudDrive/API/CloudDriveAPI.swift

145 lines
4.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// CloudDriveAPI.swift
// suixinkan
//
import Foundation
/// 便 ViewModel
@MainActor
protocol CloudDriveServing {
///
func cloudFileList(
parentFolderId: Int,
name: String,
type: Int,
orderBy: Int,
page: Int,
pageSize: Int
) async throws -> CloudFileListResponse
///
func createCloudFolder(parentFolderId: Int, name: String) async throws
/// OSS
func uploadCloudFile(parentFolderId: Int, fileUrl: String, fileName: String) async throws
///
func deleteCloudFiles(_ request: CloudFileDeleteRequest) async throws
///
func moveCloudFiles(_ request: CloudFileMoveRequest) async throws
///
func checkUploadPermission() async throws -> CloudUploadPermissionResponse
///
func modifyCloudFolderName(fileId: Int, name: String) async throws
///
func modifyCloudFileName(fileId: Int, fileName: String) async throws
}
@MainActor
/// API Android `NetworkApi` cloud-driver
final class CloudDriveAPI: CloudDriveServing {
private let client: APIClient
init(client: APIClient) {
self.client = client
}
func cloudFileList(
parentFolderId: Int,
name: String = "",
type: Int = 0,
orderBy: Int = 2,
page: Int = 1,
pageSize: Int = 20
) async throws -> CloudFileListResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/cloud-driver/list",
queryItems: [
URLQueryItem(name: "parent_folder_id", value: String(parentFolderId)),
URLQueryItem(name: "name", value: name),
URLQueryItem(name: "type", value: String(type)),
URLQueryItem(name: "order_by", value: String(orderBy)),
URLQueryItem(name: "page", value: String(page)),
URLQueryItem(name: "page_size", value: String(pageSize)),
]
)
)
}
func createCloudFolder(parentFolderId: Int, name: String) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/yf-handset-app/photog/cloud-driver/folder-create",
body: CloudFolderCreateRequest(parentFolderId: parentFolderId, name: name)
)
)
}
func uploadCloudFile(parentFolderId: Int, fileUrl: String, fileName: String) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/yf-handset-app/photog/cloud-driver/file-upload",
body: CloudFileUploadRequest(parentFolderId: parentFolderId, fileUrl: fileUrl, fileName: fileName)
)
)
}
func deleteCloudFiles(_ request: CloudFileDeleteRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/yf-handset-app/photog/cloud-driver/delete",
body: request
)
)
}
func moveCloudFiles(_ request: CloudFileMoveRequest) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/yf-handset-app/photog/cloud-driver/move",
body: request
)
)
}
func checkUploadPermission() async throws -> CloudUploadPermissionResponse {
try await client.send(
APIRequest(
method: .get,
path: "/api/yf-handset-app/photog/cloud-driver/check-upload-permission"
)
)
}
func modifyCloudFolderName(fileId: Int, name: String) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/yf-handset-app/photog/cloud-driver/folder-edit",
body: CloudFolderModifyRequest(fileId: fileId, name: name)
)
)
}
func modifyCloudFileName(fileId: Int, fileName: String) async throws {
let _: EmptyPayload = try await client.send(
APIRequest(
method: .post,
path: "/api/yf-handset-app/photog/cloud-driver/file-edit",
body: CloudFileModifyRequest(fileId: fileId, fileName: fileName)
)
)
}
}