feat: add travel album OTG import flow

This commit is contained in:
2026-07-08 09:24:51 +08:00
parent 00bda390e8
commit 92fcad7ac9
42 changed files with 6826 additions and 89 deletions

View File

@ -0,0 +1,78 @@
//
// TravelAlbumOTGUploader.swift
// suixinkan
//
import Foundation
/// OTG
@MainActor
protocol TravelAlbumOTGUploading {
///
func upload(
record: TravelAlbumOTGPhotoRecord,
scenicId: Int,
progress: @escaping (Int) -> Void
) async throws -> TravelAlbumMaterial
}
/// OTG OSS `upload-material`
@MainActor
final class TravelAlbumOTGUploader: TravelAlbumOTGUploading {
private let uploader: OSSUploadService
private let api: any TravelAlbumServing
/// OTG
init(
uploader: OSSUploadService? = nil,
api: (any TravelAlbumServing)? = nil
) {
self.uploader = uploader ?? NetworkServices.shared.ossUploadService
self.api = api ?? NetworkServices.shared.travelAlbumAPI
}
///
func upload(
record: TravelAlbumOTGPhotoRecord,
scenicId: Int,
progress: @escaping (Int) -> Void
) async throws -> TravelAlbumMaterial {
guard record.albumId > 0 else {
throw TravelAlbumOTGUploadError.invalidAlbum
}
guard !record.localPath.isEmpty,
FileManager.default.fileExists(atPath: record.localPath) else {
throw TravelAlbumOTGUploadError.localFileMissing
}
let data = try Data(contentsOf: URL(fileURLWithPath: record.localPath))
let remoteURL = try await uploader.uploadTravelAlbumMaterial(
data: data,
fileName: record.fileName,
scenicId: scenicId,
onProgress: progress
)
return try await api.uploadMaterial(
TravelAlbumUploadMaterialRequest(
userEquityTravelId: record.albumId,
fileName: record.fileName,
fileUrl: remoteURL
)
)
}
}
/// OTG
enum TravelAlbumOTGUploadError: LocalizedError, Equatable {
case invalidAlbum
case localFileMissing
var errorDescription: String? {
switch self {
case .invalidAlbum:
return "请先选择有效的相册"
case .localFileMissing:
return "本地文件不存在,无法上传"
}
}
}