Files
suixinkan_ios_new/suixinkan/Features/TravelAlbum/Services/TravelAlbumMaterialUploader.swift
汉秋 d2fe5d71e4 Add TravelAlbum, ProfileSpace, and wired camera transfer modules.
Introduce travel album entry with Sony PTP tethering pipeline, profile space settings page, home routing updates, Launch Screen storyboard, and related tests/docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 09:41:05 +08:00

64 lines
1.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// TravelAlbumMaterialUploader.swift
// suixinkan
//
// Created by Codex on 2026/6/29.
//
import Foundation
/// OSS + upload-material
@MainActor
final class TravelAlbumMaterialUploader: CameraAssetUploadSink {
private let api: any TravelAlbumServing
private let ossService: any OSSUploadServing
private let albumID: Int
private let scenicID: Int
/// APIOSS
init(api: any TravelAlbumServing, ossService: any OSSUploadServing, albumID: Int, scenicID: Int) {
self.api = api
self.ossService = ossService
self.albumID = albumID
self.scenicID = scenicID
}
/// OSS
func upload(
localURL: URL,
fileName: String,
fileType: Int,
progress: @escaping @Sendable (Int) -> Void
) async throws -> String {
guard albumID > 0 else {
throw APIError.serverCode(0, "请先选择有效的相册")
}
guard FileManager.default.fileExists(atPath: localURL.path) else {
throw APIError.serverCode(0, "相机文件读取失败")
}
let data = try Data(contentsOf: localURL)
guard !data.isEmpty else {
throw APIError.serverCode(0, "相机文件读取失败")
}
let remoteURL = try await ossService.uploadAlbumFile(
data: data,
fileName: fileName,
fileType: fileType,
scenicId: scenicID,
onProgress: progress
)
_ = try await api.uploadMaterial(
TravelAlbumUploadMaterialRequest(
userEquityTravelId: albumID,
fileName: fileName,
fileURL: remoteURL
)
)
return remoteURL
}
}