Files
suixinkan_ios_new/suixinkan/Features/TravelAlbum/Services/TravelAlbumOTGPhotoSink.swift
汉秋 be9c844bd3 将 otg_swift OTG 引擎迁入 Core/CameraOTG,并接入旅拍有线传图与历史导入。
恢复 USB 相机连接、边拍边传、三品牌驱动与 SwiftUI 历史导入页,通过适配层对接现有本地上传与 OSS 管道。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 11:22:07 +08:00

97 lines
2.9 KiB
Swift
Raw Permalink 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.

import Foundation
/// OTG scoped
@MainActor
final class TravelAlbumOTGPhotoSink: OTGPhotoSink {
private let albumId: Int
private let accountKey: String
private let pipeline: WiredCameraTransferPipeline
private let existingObjectIDsProvider: () async -> Set<String>
private let autoUploadProvider: () -> Bool
/// OTG
init(
albumId: Int,
accountKey: String,
pipeline: WiredCameraTransferPipeline,
existingObjectIDsProvider: @escaping () async -> Set<String>,
autoUploadProvider: @escaping () -> Bool
) {
self.albumId = albumId
self.accountKey = accountKey
self.pipeline = pipeline
self.existingObjectIDsProvider = existingObjectIDsProvider
self.autoUploadProvider = autoUploadProvider
}
///
func saveLiveShot(
data: Data,
filename: String,
capturedAt: Date,
cameraObjectID: String
) async throws -> SavedOTGPhoto {
let fileURL = try OTGPhotoFileWriter.writeImage(
data,
filename: filename,
accountKey: accountKey,
albumID: albumId
)
return ingestSavedFile(
fileURL: fileURL,
filename: filename,
capturedAt: capturedAt,
cameraObjectID: cameraObjectID
)
}
///
func saveDownloadedFile(
at url: URL,
filename: String,
capturedAt: Date,
cameraObjectID: String
) async throws -> SavedOTGPhoto {
let fileURL = try OTGPhotoFileWriter.moveDownloadedFile(
from: url,
filename: filename,
accountKey: accountKey,
albumID: albumId
)
return ingestSavedFile(
fileURL: fileURL,
filename: filename,
capturedAt: capturedAt,
cameraObjectID: cameraObjectID
)
}
/// ID
func existingCameraObjectIDs() async -> Set<String> {
await existingObjectIDsProvider()
}
private func ingestSavedFile(
fileURL: URL,
filename: String,
capturedAt: Date,
cameraObjectID: String
) -> SavedOTGPhoto {
let relativePath = OTGPhotoFileWriter.relativePath(for: fileURL)
let autoUpload = autoUploadProvider()
pipeline.ingestDownloadedAsset(
assetID: cameraObjectID,
filename: filename,
localPath: relativePath,
capturedAt: capturedAt,
autoUpload: autoUpload
)
return SavedOTGPhoto(
assetID: cameraObjectID,
relativeLocalPath: relativePath,
filename: filename,
capturedAt: capturedAt
)
}
}