Implement offline library snapshot
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import Foundation
|
||||
|
||||
public struct OfflineLibraryTrack: Identifiable, Hashable, Sendable {
|
||||
public var id: String { remoteTrackId }
|
||||
|
||||
public var remoteTrackId: String
|
||||
public var assetId: String
|
||||
public var title: String
|
||||
public var artist: String
|
||||
public var durationSeconds: Int
|
||||
public var sha256: String
|
||||
public var localFilePath: String
|
||||
public var downloadedAt: Date?
|
||||
public var isFileAvailable: Bool
|
||||
|
||||
public init(
|
||||
remoteTrackId: String,
|
||||
assetId: String,
|
||||
title: String,
|
||||
artist: String,
|
||||
durationSeconds: Int,
|
||||
sha256: String,
|
||||
localFilePath: String,
|
||||
downloadedAt: Date?,
|
||||
isFileAvailable: Bool
|
||||
) {
|
||||
self.remoteTrackId = remoteTrackId
|
||||
self.assetId = assetId
|
||||
self.title = title
|
||||
self.artist = artist
|
||||
self.durationSeconds = durationSeconds
|
||||
self.sha256 = sha256
|
||||
self.localFilePath = localFilePath
|
||||
self.downloadedAt = downloadedAt
|
||||
self.isFileAvailable = isFileAvailable
|
||||
}
|
||||
}
|
||||
|
||||
public enum OfflineLibraryRemoteTrackStatus: String, Hashable, Sendable, CaseIterable {
|
||||
case notDownloaded
|
||||
case downloading
|
||||
case downloaded
|
||||
case missing
|
||||
case failed
|
||||
}
|
||||
|
||||
public struct OfflineLibraryRemoteTrack: Identifiable, Hashable, Sendable {
|
||||
public var id: String { remoteTrack.trackId }
|
||||
|
||||
public var remoteTrack: RemoteTrack
|
||||
public var localFilePath: String
|
||||
public var downloadedAt: Date?
|
||||
public var isFileAvailable: Bool
|
||||
public var status: OfflineLibraryRemoteTrackStatus
|
||||
public var lastDownloadError: String?
|
||||
|
||||
public init(
|
||||
remoteTrack: RemoteTrack,
|
||||
localFilePath: String,
|
||||
downloadedAt: Date?,
|
||||
isFileAvailable: Bool,
|
||||
status: OfflineLibraryRemoteTrackStatus,
|
||||
lastDownloadError: String?
|
||||
) {
|
||||
self.remoteTrack = remoteTrack
|
||||
self.localFilePath = localFilePath
|
||||
self.downloadedAt = downloadedAt
|
||||
self.isFileAvailable = isFileAvailable
|
||||
self.status = status
|
||||
self.lastDownloadError = lastDownloadError
|
||||
}
|
||||
}
|
||||
|
||||
public struct OfflineLibrarySnapshot: Hashable, Sendable {
|
||||
public var remoteTracks: [OfflineLibraryRemoteTrack]
|
||||
public var availableTracks: [OfflineLibraryTrack]
|
||||
|
||||
public init(
|
||||
remoteTracks: [OfflineLibraryRemoteTrack],
|
||||
availableTracks: [OfflineLibraryTrack]
|
||||
) {
|
||||
self.remoteTracks = remoteTracks
|
||||
self.availableTracks = availableTracks
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user