Fix OTG album local path storage

This commit is contained in:
2026-07-08 10:25:35 +08:00
parent e9f593643f
commit 773fbd1180
8 changed files with 206 additions and 76 deletions

View File

@ -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,