Update OTG transfer workflow
This commit is contained in:
@ -89,7 +89,8 @@ protocol PhotoRepositoryProtocol {
|
||||
func fetchPhotos(albumID: Int) throws -> [TravelAlbumOTGPhotoRecord]
|
||||
|
||||
/// 添加一张已下载到本地的照片。
|
||||
func addPhoto(albumID: Int, localPath: String, createdAt: Date) throws
|
||||
@discardableResult
|
||||
func addPhoto(albumID: Int, localPath: String, createdAt: Date) throws -> TravelAlbumOTGPhotoRecord
|
||||
|
||||
/// 删除指定照片及本地文件。
|
||||
func deletePhoto(photoID: String, albumID: Int) throws
|
||||
@ -110,12 +111,15 @@ final class TravelAlbumOTGPhotoRepository: PhotoRepositoryProtocol {
|
||||
}
|
||||
|
||||
/// 添加一张已下载到本地的照片。
|
||||
func addPhoto(albumID: Int, localPath: String, createdAt: Date) throws {
|
||||
@discardableResult
|
||||
func addPhoto(albumID: Int, localPath: String, createdAt: Date) throws -> TravelAlbumOTGPhotoRecord {
|
||||
let fileURL = URL(fileURLWithPath: localPath)
|
||||
let attributes = try? FileManager.default.attributesOfItem(atPath: localPath)
|
||||
let size = (attributes?[.size] as? NSNumber)?.int64Value ?? 0
|
||||
let userId = storage.context.userId
|
||||
guard !userId.isEmpty else { return }
|
||||
guard !userId.isEmpty else {
|
||||
throw CameraError.connectionFailed("用户信息缺失,无法保存照片")
|
||||
}
|
||||
|
||||
let record = TravelAlbumOTGPhotoRecord(
|
||||
id: TravelAlbumOTGPhotoStore.photoId(for: fileURL.lastPathComponent, createdAt: createdAt),
|
||||
@ -128,6 +132,7 @@ final class TravelAlbumOTGPhotoRepository: PhotoRepositoryProtocol {
|
||||
userId: userId
|
||||
)
|
||||
storage.upsert(record, albumId: albumID)
|
||||
return record
|
||||
}
|
||||
|
||||
/// 删除指定照片及本地文件。
|
||||
|
||||
Reference in New Issue
Block a user