Files
suixinkan_uikit/suixinkan/Features/CloudDrive/Services/CloudTransferModels.swift

98 lines
2.4 KiB
Swift

//
// CloudTransferModels.swift
// suixinkan
//
import Foundation
///
enum CloudTransferKind: String, Codable, Sendable {
case upload
case download
}
///
enum CloudTransferStatus: String, Codable, Sendable {
case pending
case uploading
case downloading
case paused
case failed
case completed
///
var title: String {
switch self {
case .pending:
"等待中"
case .uploading:
"上传中"
case .downloading:
"下载中"
case .paused:
"已暂停"
case .failed:
"失败"
case .completed:
"已完成"
}
}
}
///
struct CloudTransferTask: Codable, Sendable, Equatable, Hashable, Identifiable {
let id: String
let kind: CloudTransferKind
let fileName: String
let fileType: Int
let fileSize: Int64
let parentFolderId: Int
let localPath: String
let remoteURL: String
var status: CloudTransferStatus
var progress: Int
var errorMessage: String
var createdAt: TimeInterval
var updatedAt: TimeInterval
///
init(
id: String = UUID().uuidString.replacingOccurrences(of: "-", with: ""),
kind: CloudTransferKind,
fileName: String,
fileType: Int,
fileSize: Int64,
parentFolderId: Int = 0,
localPath: String = "",
remoteURL: String = "",
status: CloudTransferStatus = .pending,
progress: Int = 0,
errorMessage: String = "",
createdAt: TimeInterval = Date().timeIntervalSince1970,
updatedAt: TimeInterval = Date().timeIntervalSince1970
) {
self.id = id
self.kind = kind
self.fileName = fileName
self.fileType = fileType
self.fileSize = fileSize
self.parentFolderId = parentFolderId
self.localPath = localPath
self.remoteURL = remoteURL
self.status = status
self.progress = progress
self.errorMessage = errorMessage
self.createdAt = createdAt
self.updatedAt = updatedAt
}
}
///
protocol CloudTransferTaskStoring: AnyObject {
///
func loadTasks() -> [CloudTransferTask]
///
func saveTasks(_ tasks: [CloudTransferTask])
}