Kartenimport, Metadaten und Versand absichern
This commit is contained in:
1 parent
be6bd49da5
commit
427b6fa7b0
18 files changed
+643
-193
No files matched your search
@@ -70,6 +70,8 @@ struct PendingUpload: Identifiable {
|
||||
let id = UUID()
|
||||
let target: String
|
||||
let targetName: String
|
||||
var variant: UploadVariant
|
||||
let skipAlreadySent: Bool
|
||||
var items: [PhotoItem]
|
||||
/// item id → issues
|
||||
var issues: [String: [PreflightIssue]]
|
||||
@@ -203,7 +205,8 @@ final class AppState: ObservableObject {
|
||||
@Published private(set) var sentLog = SentLog()
|
||||
private var sentLogSaveTask: Task<Void, Never>?
|
||||
/// Agentur-Check / double-send question waiting for the user (window "check")
|
||||
@Published var pendingUpload: PendingUpload?
|
||||
@Published private var pendingUploads: [PendingUpload] = []
|
||||
var pendingUpload: PendingUpload? { pendingUploads.first }
|
||||
/// Undo / redo of ratings, labels, tags and IPTC changes
|
||||
@Published private(set) var undoStack: [UndoEntry] = []
|
||||
@Published private(set) var redoStack: [UndoEntry] = []
|
||||
@@ -1081,35 +1084,47 @@ final class AppState: ObservableObject {
|
||||
}
|
||||
statusText = "Lightroom: \(result.imported) importiert, \(result.exported.count) JPEG(s) exportiert"
|
||||
guard let job, !result.exported.isEmpty else { continue }
|
||||
Task { await handleExported(result.exported, job: job, sources: jobSources) }
|
||||
Task { await handleExported(result, job: job, sources: jobSources) }
|
||||
}
|
||||
}
|
||||
|
||||
/// After LR export: re-apply the original IPTC (PM-identical structure) and upload.
|
||||
private func handleExported(_ files: [URL], job: LightroomJob, sources jobSources: [PhotoItem]) async {
|
||||
// Map exported JPEG → source item by base name (LR keeps the file name, may append "-2").
|
||||
// Current state if the photo is still open (IPTC edited meanwhile), else the copy from the job.
|
||||
let sources = jobSources.map { item($0.id) ?? $0 }
|
||||
if job.rewriteIPTCAfterExport, let w = writer {
|
||||
for file in files {
|
||||
let base = file.deletingPathExtension().lastPathComponent
|
||||
guard let src = sources.first(where: { base == $0.baseName || base.hasPrefix($0.baseName + "-") }) else { continue }
|
||||
let jpegItem = PhotoItem(primary: file)
|
||||
do { try await w.write(values: src.iptc, fields: IPTCField.all, to: jpegItem) } catch { report(error) }
|
||||
private func handleExported(_ result: LightroomJobResult, job: LightroomJob, sources jobSources: [PhotoItem]) async {
|
||||
let sources = Dictionary(jobSources.map { original in
|
||||
let path = (original.rawFile ?? original.primary).standardizedFileURL.path
|
||||
return (path, item(original.id) ?? original)
|
||||
}, uniquingKeysWith: { first, _ in first })
|
||||
let writer = job.rewriteIPTCAfterExport ? self.writer : nil
|
||||
var exportedItems: [PhotoItem] = []
|
||||
var missingSources = 0
|
||||
for file in result.exported {
|
||||
guard let path = result.exportSources[file]?.standardizedFileURL.path, let source = sources[path] else {
|
||||
missingSources += 1
|
||||
continue
|
||||
}
|
||||
var exported = PhotoItem(primary: file)
|
||||
if job.rewriteIPTCAfterExport {
|
||||
guard let writer else { continue }
|
||||
do {
|
||||
try await writer.write(values: source.iptc, fields: IPTCField.all, to: exported)
|
||||
} catch {
|
||||
report(error)
|
||||
continue
|
||||
}
|
||||
}
|
||||
exported.iptc = source.iptc
|
||||
exported.exif = source.exif
|
||||
exported.captureDate = source.captureDate
|
||||
exportedItems.append(exported)
|
||||
}
|
||||
// Exported JPEGs carry the IPTC of their RAW (needed for {event} album names, rename patterns …)
|
||||
let exportedItems: [PhotoItem] = files.compactMap { file in
|
||||
let base = file.deletingPathExtension().lastPathComponent
|
||||
guard let src = sources.first(where: { base == $0.baseName || base.hasPrefix($0.baseName + "-") }) else { return nil }
|
||||
var it = PhotoItem(primary: file)
|
||||
it.iptc = src.iptc; it.exif = src.exif; it.captureDate = src.captureDate
|
||||
return it
|
||||
if missingSources > 0 && (job.rewriteIPTCAfterExport || !job.uploadTargets.isEmpty) {
|
||||
alert = AppAlert(title: "Lightroom-Export ohne Originalzuordnung",
|
||||
message: "Für \(missingSources) JPEG(s) wurden IPTC-Nachbearbeitung und automatischer Versand ausgesetzt. Bitte die Lichtkasten Bridge aktualisieren und Lightroom neu starten.")
|
||||
}
|
||||
for target in job.uploadTargets {
|
||||
requestUpload(exportedItems, to: target, skipAlreadySent: true)
|
||||
}
|
||||
if !job.uploadTargets.isEmpty { openWindow("tasks") }
|
||||
if !job.uploadTargets.isEmpty && pendingUpload == nil { openWindow("tasks") }
|
||||
// SENT workflow: show the exported JPEGs for captioning.
|
||||
if settings.lightroom.openSentAfterExport, let dir = job.exportFolder {
|
||||
if folder != dir { lastRawFolder = folder; open(folder: dir) } else { refreshFolder() }
|
||||
@@ -1175,7 +1190,7 @@ final class AppState: ObservableObject {
|
||||
var issues: [String: [PreflightIssue]] = [:]
|
||||
if runCheck {
|
||||
for t in withFiles {
|
||||
let i = preflightIssues(for: t)
|
||||
let i = preflightIssues(for: t, variant: variant)
|
||||
if !i.isEmpty { issues[t.id] = i }
|
||||
}
|
||||
}
|
||||
@@ -1186,41 +1201,52 @@ final class AppState: ObservableObject {
|
||||
enqueueUpload(send, target: target, variant: variant)
|
||||
return
|
||||
}
|
||||
pendingUpload = PendingUpload(target: target, targetName: name, items: withFiles, issues: issues, alreadySent: sentBefore)
|
||||
pendingUploads.append(PendingUpload(target: target, targetName: name, variant: variant, skipAlreadySent: skipAlreadySent ?? true,
|
||||
items: withFiles, issues: issues, alreadySent: sentBefore))
|
||||
openWindow("check")
|
||||
}
|
||||
|
||||
/// Agentur-Check of one photo (current metadata).
|
||||
func preflightIssues(for item: PhotoItem) -> [PreflightIssue] {
|
||||
func preflightIssues(for item: PhotoItem, variant: UploadVariant) -> [PreflightIssue] {
|
||||
let cur = self.item(item.id) ?? item
|
||||
let open = openSuggestions(for: cur.id).map { s -> String in
|
||||
let name = s.replacement.map { JerseyLogic.personName(replacement: $0, columns: []) } ?? ""
|
||||
return [s.code ?? "#\(s.number)", name].filter { !$0.isEmpty }.joined(separator: " ")
|
||||
}
|
||||
return Preflight.check(iptc: cur.iptc, exif: cur.exif, captureDate: cur.captureDate, codes: codes,
|
||||
options: settings.preflight, openSuggestions: open)
|
||||
options: settings.preflight, openSuggestions: open,
|
||||
uploadFiles: uploadFiles(for: cur, variant: variant))
|
||||
}
|
||||
|
||||
/// Check window: run the check again (after fixing captions in the IPTC window).
|
||||
func recheckPendingUpload() {
|
||||
guard var p = pendingUpload else { return }
|
||||
guard var p = pendingUpload, let variant = uploadVariant(p.target) else { return }
|
||||
p.variant = variant
|
||||
p.items = p.items.map { item($0.id) ?? $0 }
|
||||
var issues: [String: [PreflightIssue]] = [:]
|
||||
let destination = settings.ftpDestinations.first { $0.id.uuidString == p.target }
|
||||
if p.target != "immich" && (destination?.preflight ?? true) {
|
||||
for t in p.items { let i = preflightIssues(for: t); if !i.isEmpty { issues[t.id] = i } }
|
||||
for t in p.items { let i = preflightIssues(for: t, variant: variant); if !i.isEmpty { issues[t.id] = i } }
|
||||
}
|
||||
p.issues = issues
|
||||
p.alreadySent = Set(p.items.filter { sentLog.wasSent($0, to: p.target) }.map(\.id))
|
||||
pendingUpload = p
|
||||
pendingUploads[0] = p
|
||||
}
|
||||
|
||||
/// Check window: send these photos.
|
||||
func confirmPendingUpload(_ send: [PhotoItem]) {
|
||||
guard let p = pendingUpload, let variant = uploadVariant(p.target) else { pendingUpload = nil; return }
|
||||
pendingUpload = nil
|
||||
guard let p = pendingUpload else { return }
|
||||
guard let variant = uploadVariant(p.target) else { discardPendingUpload(); return }
|
||||
guard p.variant == variant else { recheckPendingUpload(); return }
|
||||
discardPendingUpload()
|
||||
guard !send.isEmpty else { return }
|
||||
enqueueUpload(send.map { item($0.id) ?? $0 }, target: p.target, variant: variant)
|
||||
enqueueUpload(send, target: p.target, variant: variant)
|
||||
}
|
||||
|
||||
func discardPendingUpload() {
|
||||
guard !pendingUploads.isEmpty else { return }
|
||||
pendingUploads.removeFirst()
|
||||
recheckPendingUpload()
|
||||
}
|
||||
|
||||
private func enqueueUpload(_ items: [PhotoItem], target: String, variant: UploadVariant) {
|
||||
|
||||
Reference in new issue
Block a user