35 lines
954 B
Swift
35 lines
954 B
Swift
|
|
import Foundation
|
||
|
|
|
||
|
|
struct BackupQueueItem: Identifiable, Codable, Sendable {
|
||
|
|
let id: String // = asset localIdentifier
|
||
|
|
var filename: String
|
||
|
|
var nasPath: String
|
||
|
|
var status: Status
|
||
|
|
var bytesUploaded: Int64
|
||
|
|
var totalBytes: Int64
|
||
|
|
var speedBytesPerSec: Double
|
||
|
|
var error: UploadError?
|
||
|
|
var retryCount: Int
|
||
|
|
var queuedAt: Date
|
||
|
|
var completedAt: Date?
|
||
|
|
|
||
|
|
enum Status: String, Codable, Sendable {
|
||
|
|
case queued, uploading, uploaded, skipped, failed
|
||
|
|
}
|
||
|
|
|
||
|
|
struct UploadError: Codable, Sendable {
|
||
|
|
var code: String
|
||
|
|
var message: String
|
||
|
|
var timestamp: Date
|
||
|
|
}
|
||
|
|
|
||
|
|
var progress: Double {
|
||
|
|
guard totalBytes > 0 else {
|
||
|
|
return (status == .uploaded || status == .skipped) ? 1.0 : 0.0
|
||
|
|
}
|
||
|
|
return min(1.0, Double(bytesUploaded) / Double(totalBytes))
|
||
|
|
}
|
||
|
|
|
||
|
|
var isFinished: Bool { status == .uploaded || status == .skipped || status == .failed }
|
||
|
|
}
|