按账号与相册隔离相机下载目录,并同步更新传输管道与测试。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -92,9 +92,7 @@ final class WiredTransferPhotoStore {
|
||||
}
|
||||
|
||||
let normalizedRecords = filteredRecords.map { $0.normalizeInterruptedTransfer() }
|
||||
let migratedRecords = normalizeStoredPaths(normalizedRecords, albumID: albumID)
|
||||
|
||||
return migratedRecords
|
||||
return normalizedRecords
|
||||
.filter(\.isDisplayable)
|
||||
.sorted { $0.capturedAt > $1.capturedAt }
|
||||
.also { items in
|
||||
@ -102,27 +100,6 @@ final class WiredTransferPhotoStore {
|
||||
}
|
||||
}
|
||||
|
||||
/// 将旧版绝对路径迁移为相对路径并回写持久化。
|
||||
private func normalizeStoredPaths(
|
||||
_ records: [WiredTransferPhotoRecord],
|
||||
albumID: Int
|
||||
) -> [WiredTransferPhotoRecord] {
|
||||
var migrated = records
|
||||
var needsPersist = false
|
||||
|
||||
for index in migrated.indices {
|
||||
guard let normalized = migrated[index].withNormalizedStoredPaths(),
|
||||
normalized != migrated[index] else { continue }
|
||||
migrated[index] = normalized
|
||||
needsPersist = true
|
||||
}
|
||||
|
||||
if needsPersist {
|
||||
save(albumID: albumID, records: migrated)
|
||||
}
|
||||
return migrated
|
||||
}
|
||||
|
||||
/// 保存相册传图记录。
|
||||
func save(albumID: Int, records: [WiredTransferPhotoRecord]) {
|
||||
guard albumID > 0 else { return }
|
||||
@ -173,12 +150,18 @@ final class WiredTransferPhotoStore {
|
||||
|
||||
guard let data = defaults.data(forKey: storageKey(albumID)),
|
||||
let records = try? JSONDecoder().decode([WiredTransferPhotoRecord].self, from: data)
|
||||
else { return [] }
|
||||
else {
|
||||
CameraDownloadStorage.removeScopeDirectory(for: downloadScope(albumID: albumID))
|
||||
defaults.removeObject(forKey: storageKey(albumID))
|
||||
defaults.removeObject(forKey: deletedKey(albumID))
|
||||
return []
|
||||
}
|
||||
|
||||
let userRecords = records.filter { $0.userId == userID }
|
||||
userRecords.forEach { deleteRecordFiles($0) }
|
||||
CameraDownloadStorage.removeScopeDirectory(for: downloadScope(albumID: albumID))
|
||||
|
||||
var bindings = loadBindings().filter { $0.albumID != albumID }
|
||||
let bindings = loadBindings().filter { $0.albumID != albumID }
|
||||
saveBindings(bindings)
|
||||
|
||||
defaults.removeObject(forKey: storageKey(albumID))
|
||||
@ -216,6 +199,10 @@ final class WiredTransferPhotoStore {
|
||||
"\(accountPrefixProvider())\(Self.transferModeKeySuffix)"
|
||||
}
|
||||
|
||||
private func downloadScope(albumID: Int) -> CameraDownloadStorage.Scope {
|
||||
CameraDownloadStorage.Scope(accountKey: accountPrefixProvider(), albumID: albumID)
|
||||
}
|
||||
|
||||
private struct PhotoAlbumBinding: Codable {
|
||||
let photoID: String
|
||||
let albumID: Int
|
||||
@ -249,33 +236,6 @@ private extension WiredTransferPhotoRecord {
|
||||
return false
|
||||
}
|
||||
|
||||
/// 将 localPath/thumbnailPath 中的旧版绝对路径迁移为相对路径。
|
||||
func withNormalizedStoredPaths() -> WiredTransferPhotoRecord? {
|
||||
let migratedLocalPath = localPath.isEmpty ? localPath : (CameraDownloadStorage.migrateStoredPath(localPath) ?? localPath)
|
||||
let migratedThumbnailPath = thumbnailPath.isEmpty
|
||||
? thumbnailPath
|
||||
: (CameraDownloadStorage.migrateStoredPath(thumbnailPath) ?? thumbnailPath)
|
||||
|
||||
guard migratedLocalPath != localPath || migratedThumbnailPath != thumbnailPath else { return nil }
|
||||
|
||||
return WiredTransferPhotoRecord(
|
||||
id: id,
|
||||
sourceId: sourceId,
|
||||
fileName: fileName,
|
||||
localPath: migratedLocalPath,
|
||||
thumbnailPath: migratedThumbnailPath,
|
||||
capturedAt: capturedAt,
|
||||
fileSizeBytes: fileSizeBytes,
|
||||
status: status,
|
||||
progress: progress,
|
||||
errorMessage: errorMessage,
|
||||
albumId: albumId,
|
||||
userId: userId,
|
||||
remoteURL: remoteURL,
|
||||
updatedAt: updatedAt
|
||||
)
|
||||
}
|
||||
|
||||
func normalizeInterruptedTransfer() -> WiredTransferPhotoRecord {
|
||||
guard status == WiredTransferUploadStatus.transferring.rawValue
|
||||
|| status == WiredTransferUploadStatus.uploading.rawValue
|
||||
|
||||
Reference in New Issue
Block a user