Fix OTG album local path storage
This commit is contained in:
@ -18,7 +18,7 @@ enum TravelAlbumCameraImportState: Equatable {
|
||||
case loading
|
||||
case loaded(sections: [TravelAlbumCameraImportSection])
|
||||
case importing(current: Int, total: Int)
|
||||
case finished(importedCount: Int)
|
||||
case finished(importedCount: Int, failedCount: Int)
|
||||
case failed(message: String)
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ final class TravelAlbumCameraImportViewModel {
|
||||
id: object.id,
|
||||
sourceId: object.id,
|
||||
fileName: downloadedURL.lastPathComponent,
|
||||
localPath: downloadedURL.path,
|
||||
localPath: storage.relativePath(for: downloadedURL, albumId: albumId),
|
||||
thumbnailPath: "",
|
||||
capturedAt: TravelAlbumOTGPhotoStore.transferTimeText(object.capturedAt),
|
||||
fileSizeBytes: object.fileSize,
|
||||
@ -212,7 +212,7 @@ final class TravelAlbumCameraImportViewModel {
|
||||
}
|
||||
|
||||
selectedPhotoIds.subtract(existingPhotoIds)
|
||||
state = .finished(importedCount: importedCount)
|
||||
state = .finished(importedCount: importedCount, failedCount: failedPhotoIds.count)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,6 @@ final class WiredCameraTransferViewModel {
|
||||
|
||||
private var currentDriver: CameraDriver?
|
||||
private var persistedRecordsById: [String: TravelAlbumOTGPhotoRecord] = [:]
|
||||
private var deletedPhotoIds: Set<String> = []
|
||||
private var isUploading = false
|
||||
|
||||
@MainActor
|
||||
@ -235,6 +234,11 @@ final class WiredCameraTransferViewModel {
|
||||
return nil
|
||||
}
|
||||
|
||||
/// 历史导入期间暂停边拍边传轮询,避免 PTP 轮询与 ImageCaptureCore 下载互相抢占。
|
||||
func pauseLiveTransferForHistoricalImport() {
|
||||
connectionManager.suspendLiveTransfer()
|
||||
}
|
||||
|
||||
/// 选择或取消选择照片。
|
||||
func toggleTransferPhotoSelection(photoId: String) {
|
||||
guard selectUploadMode,
|
||||
@ -268,7 +272,6 @@ final class WiredCameraTransferViewModel {
|
||||
/// 删除单张本地照片。
|
||||
func deletePhoto(photoId: String) {
|
||||
storage.remove(albumId: albumId, photoId: photoId)
|
||||
deletedPhotoIds.insert(photoId)
|
||||
persistedRecordsById.removeValue(forKey: photoId)
|
||||
selectedPhotoIds.remove(photoId)
|
||||
applyMergedPhotos()
|
||||
@ -289,7 +292,6 @@ final class WiredCameraTransferViewModel {
|
||||
}
|
||||
|
||||
private func loadPersistedPhotos() {
|
||||
deletedPhotoIds = storage.loadDeletedIds(albumId: albumId)
|
||||
let records = storage.load(albumId: albumId)
|
||||
persistedRecordsById = Dictionary(uniqueKeysWithValues: records.map { ($0.id, $0) })
|
||||
applyMergedPhotos()
|
||||
@ -297,8 +299,7 @@ final class WiredCameraTransferViewModel {
|
||||
|
||||
private func applyMergedPhotos() {
|
||||
let persistedItems = persistedRecordsById.values
|
||||
.filter { !deletedPhotoIds.contains($0.id) }
|
||||
.map { $0.toPhotoItem() }
|
||||
.map { $0.toPhotoItem(storage: storage, albumId: albumId) }
|
||||
photos = persistedItems.sorted { $0.capturedAt > $1.capturedAt }
|
||||
}
|
||||
|
||||
@ -347,8 +348,8 @@ final class WiredCameraTransferViewModel {
|
||||
private func localRecordForUpload(id: String) async throws -> TravelAlbumOTGPhotoRecord {
|
||||
if let record = persistedRecordsById[id],
|
||||
!record.localPath.isEmpty,
|
||||
FileManager.default.fileExists(atPath: record.localPath) {
|
||||
return record
|
||||
storage.fileExists(relativePath: record.localPath, albumId: albumId) {
|
||||
return storage.recordWithResolvedFilePaths(record, albumId: albumId)
|
||||
}
|
||||
throw TravelAlbumOTGUploadError.localFileMissing
|
||||
}
|
||||
@ -367,7 +368,9 @@ final class WiredCameraTransferViewModel {
|
||||
sourceId: item.sourceId,
|
||||
fileName: item.fileName,
|
||||
localPath: item.localPath,
|
||||
thumbnailPath: item.thumbnailURL?.isFileURL == true ? item.thumbnailURL?.path ?? "" : "",
|
||||
thumbnailPath: item.thumbnailURL?.isFileURL == true
|
||||
? storage.relativePath(for: item.thumbnailURL ?? URL(fileURLWithPath: ""), albumId: albumId)
|
||||
: "",
|
||||
capturedAt: item.capturedAt,
|
||||
fileSizeBytes: item.fileSizeBytes,
|
||||
status: status,
|
||||
|
||||
Reference in New Issue
Block a user