Implement remote library metadata sync for iPhone

This commit is contained in:
diyaa
2026-05-29 08:54:09 +02:00
parent ebc187f4a1
commit 6e73c1878e
20 changed files with 1379 additions and 48 deletions
@@ -0,0 +1,33 @@
import Foundation
import VelodyDomain
import VelodyNetworking
import VelodyPersistence
public protocol RemoteLibraryRepository: Actor {
func loadCachedRemoteTracks() async throws -> [RemoteTrack]
func syncRemoteTracks(deviceId: String) async throws -> [RemoteTrack]
}
public actor DefaultRemoteLibraryRepository: RemoteLibraryRepository {
private let apiClient: any VelodyAPIClient
private let store: any RemoteLibraryStore
public init(
apiClient: any VelodyAPIClient,
store: any RemoteLibraryStore
) {
self.apiClient = apiClient
self.store = store
}
public func loadCachedRemoteTracks() async throws -> [RemoteTrack] {
try await store.loadRemoteTracks()
}
public func syncRemoteTracks(deviceId: String) async throws -> [RemoteTrack] {
let response = try await apiClient.fetchRemoteLibrary(deviceId: deviceId)
let tracks = response.tracks.map(\.remoteTrack)
try await store.replaceRemoteTracks(tracks)
return tracks
}
}
@@ -0,0 +1,18 @@
import Foundation
import VelodyDomain
public actor RemoteLibrarySyncService {
private let repository: any RemoteLibraryRepository
public init(repository: any RemoteLibraryRepository) {
self.repository = repository
}
public func loadCachedRemoteTracks() async throws -> [RemoteTrack] {
try await repository.loadCachedRemoteTracks()
}
public func syncRemoteLibrary(deviceId: String) async throws -> [RemoteTrack] {
try await repository.syncRemoteTracks(deviceId: deviceId)
}
}