Update OTG transfer workflow
This commit is contained in:
@ -15,8 +15,8 @@ final class CanonRemoteCaptureService {
|
||||
|
||||
private var albumID: Int?
|
||||
private let photoRepository: PhotoRepositoryProtocol
|
||||
/// 下载成功时回调文件名,供 ConnectionManager 转发给 ViewModel。
|
||||
var onShotSaved: ((String) -> Void)?
|
||||
/// 下载成功时回调本地照片记录,供 ConnectionManager 转发给 ViewModel。
|
||||
var onShotSaved: ((TravelAlbumOTGPhotoRecord) -> Void)?
|
||||
|
||||
private var eventPollTimer: Timer?
|
||||
private var catalogPollTimer: Timer?
|
||||
@ -175,14 +175,14 @@ final class CanonRemoteCaptureService {
|
||||
|
||||
lastDownloadedSignature = objectID
|
||||
|
||||
guard await saveToAlbum(data: data, filename: filename, reason: reason) else {
|
||||
guard let record = await saveToAlbum(data: data, filename: filename, reason: reason) else {
|
||||
knownCatalogIDs.remove(objectID)
|
||||
return
|
||||
}
|
||||
|
||||
savedShotCount += 1
|
||||
OTGLog.info(.canon, "Live shot saved (#\(savedShotCount)): \(filename), bytes=\(data.count)")
|
||||
onShotSaved?(filename)
|
||||
onShotSaved?(record)
|
||||
} catch {
|
||||
knownCatalogIDs.remove(objectID)
|
||||
OTGLog.error(.canon, "\(reason): catalog download failed \(filename): \(error.localizedDescription)")
|
||||
@ -417,23 +417,23 @@ final class CanonRemoteCaptureService {
|
||||
lastDownloadedSignature = signature
|
||||
knownDownloadedHandles.insert(item.handle)
|
||||
|
||||
guard await saveToAlbum(data: result.data, filename: result.filename, reason: item.reason) else {
|
||||
guard let record = await saveToAlbum(data: result.data, filename: result.filename, reason: item.reason) else {
|
||||
return false
|
||||
}
|
||||
|
||||
savedShotCount += 1
|
||||
OTGLog.info(.canon, "Live shot saved (#\(savedShotCount)): \(result.filename), bytes=\(result.data.count)")
|
||||
onShotSaved?(result.filename)
|
||||
onShotSaved?(record)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private func saveToAlbum(data: Data, filename: String, reason: String) async -> Bool {
|
||||
private func saveToAlbum(data: Data, filename: String, reason: String) async -> TravelAlbumOTGPhotoRecord? {
|
||||
guard let albumID else {
|
||||
OTGLog.warning(.canon, "\(reason): live transfer album not configured, skip save")
|
||||
return false
|
||||
return nil
|
||||
}
|
||||
|
||||
do {
|
||||
@ -442,15 +442,14 @@ final class CanonRemoteCaptureService {
|
||||
filename: filename,
|
||||
albumID: albumID
|
||||
)
|
||||
try photoRepository.addPhoto(
|
||||
return try photoRepository.addPhoto(
|
||||
albumID: albumID,
|
||||
localPath: fileURL.path,
|
||||
createdAt: Date()
|
||||
)
|
||||
return true
|
||||
} catch {
|
||||
OTGLog.error(.canon, "\(reason): save failed: \(error.localizedDescription)")
|
||||
return false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,8 @@ final class NikonCatalogLiveCaptureService {
|
||||
|
||||
private var albumID: Int?
|
||||
private let photoRepository: PhotoRepositoryProtocol
|
||||
var onShotSaved: ((String) -> Void)?
|
||||
/// 下载成功时回调本地照片记录,供 ConnectionManager 转发给 ViewModel。
|
||||
var onShotSaved: ((TravelAlbumOTGPhotoRecord) -> Void)?
|
||||
|
||||
private var catalogPollTimer: Timer?
|
||||
private var isDownloading = false
|
||||
@ -140,14 +141,14 @@ final class NikonCatalogLiveCaptureService {
|
||||
|
||||
lastDownloadedSignature = objectID
|
||||
|
||||
guard await saveToAlbum(data: data, filename: filename, reason: reason) else {
|
||||
guard let record = await saveToAlbum(data: data, filename: filename, reason: reason) else {
|
||||
knownCatalogIDs.remove(objectID)
|
||||
return
|
||||
}
|
||||
|
||||
savedShotCount += 1
|
||||
OTGLog.info(.nikon, "Live shot saved (#\(savedShotCount)): \(filename), bytes=\(data.count)")
|
||||
onShotSaved?(filename)
|
||||
onShotSaved?(record)
|
||||
} catch {
|
||||
knownCatalogIDs.remove(objectID)
|
||||
OTGLog.error(.nikon, "\(reason): catalog download failed \(filename): \(error.localizedDescription)")
|
||||
@ -184,10 +185,10 @@ final class NikonCatalogLiveCaptureService {
|
||||
|
||||
// MARK: - Save
|
||||
|
||||
private func saveToAlbum(data: Data, filename: String, reason: String) async -> Bool {
|
||||
private func saveToAlbum(data: Data, filename: String, reason: String) async -> TravelAlbumOTGPhotoRecord? {
|
||||
guard let albumID else {
|
||||
OTGLog.warning(.nikon, "\(reason): live transfer album not configured, skip save")
|
||||
return false
|
||||
return nil
|
||||
}
|
||||
|
||||
do {
|
||||
@ -196,15 +197,14 @@ final class NikonCatalogLiveCaptureService {
|
||||
filename: filename,
|
||||
albumID: albumID
|
||||
)
|
||||
try photoRepository.addPhoto(
|
||||
return try photoRepository.addPhoto(
|
||||
albumID: albumID,
|
||||
localPath: fileURL.path,
|
||||
createdAt: Date()
|
||||
)
|
||||
return true
|
||||
} catch {
|
||||
OTGLog.error(.nikon, "\(reason): save failed: \(error.localizedDescription)")
|
||||
return false
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ final class SonyRemoteCaptureService {
|
||||
|
||||
private var albumID: Int?
|
||||
private let photoRepository: PhotoRepositoryProtocol
|
||||
/// 下载成功时回调文件名,供 ConnectionManager 转发给 ViewModel。
|
||||
var onShotSaved: ((String) -> Void)?
|
||||
/// 下载成功时回调本地照片记录,供 ConnectionManager 转发给 ViewModel。
|
||||
var onShotSaved: ((TravelAlbumOTGPhotoRecord) -> Void)?
|
||||
|
||||
private var pollTimer: Timer?
|
||||
private var propertyCheckTask: Task<Void, Never>?
|
||||
@ -298,7 +298,7 @@ final class SonyRemoteCaptureService {
|
||||
filename: downloaded.filename,
|
||||
albumID: albumID
|
||||
)
|
||||
try photoRepository.addPhoto(
|
||||
let record = try photoRepository.addPhoto(
|
||||
albumID: albumID,
|
||||
localPath: fileURL.path,
|
||||
createdAt: Date()
|
||||
@ -307,7 +307,7 @@ final class SonyRemoteCaptureService {
|
||||
.sony,
|
||||
"Live shot saved (#\(savedShotCount + 1)): \(downloaded.filename), bytes=\(downloaded.data.count), path=\(fileURL.lastPathComponent)"
|
||||
)
|
||||
onShotSaved?(downloaded.filename)
|
||||
onShotSaved?(record)
|
||||
return true
|
||||
} catch {
|
||||
OTGLog.error(.sony, "\(reason): save failed: \(error.localizedDescription)")
|
||||
|
||||
Reference in New Issue
Block a user