Gesendet-Status, Agentur-Check, Rückgängig und Spieltag-Assistent

- Gesendet-Status pro Bild: Upload-Historie (FTP + Immich) mit Ziel und Zeit, grünes Abzeichen im Kontaktabzug,
  Anzeige in Lupe und IPTC-Fenster, Filter Gesendet/Nicht gesendet, bereits gesendete beim Upload überspringen,
  'Als nicht gesendet markieren'
- Agentur-Check vor dem FTP-Upload: Pflichtfelder, offene Variablen und Codes, Datum aus alter Vorlage,
  IIM-Längen, offene Trikot-Vorschläge, Mindestgröße; Prüffenster mit Bearbeiten/Erneut prüfen/
  Nur fehlerfreie senden; Einstellungsseite und Schalter pro Server
- Rückgängig/Wiederholen (⌘Z/⇧⌘Z) für Sterne, Farben, Tags, IPTC und Vorlagen, Schreibvorgänge serialisiert,
  in Textfeldern bleibt ⌘Z beim Text
- Spieltag-Assistent (⌘⇧N, auch im Ingest und in der Matchday-Ansicht): Teams, Wettbewerbe und Muster werden
  gespeichert; erzeugt Vorlage im Aufbau der Basis-Vorlage, Ingest-Ordner, Trikot-Teams und aktive Code-Teams;
  Trikotfarben aus der Erkennung fließen ins Team zurück; Matchday nimmt die Teams aus dem Ereignis des Bildes
- Tests für Spieltag-Generator, Agentur-Check und Gesendet-Log, README ergänzt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
This commit is contained in:
Lichtkasten DevandClaude Opus 5.5 committed 2026-11-05 00:23:03 +00:00
1 parent 22b2611228
commit 93ecdf03fc
22 files changed
+2119 -49

No files matched your search

@@ -39,15 +39,43 @@ public struct FTPDestination: Codable, Identifiable, Hashable, Sendable {
/// Path to an SSH private key for SFTP (optional; otherwise ssh-agent / password via curl).
public var sshKeyPath: String
public var allowInsecureTLS: Bool
/// Agentur-Check before uploading to this server
public var preflight: Bool
public init(id: UUID = UUID(), name: String = "Neuer Server", proto: FTPProtocol = .ftp, host: String = "",
port: Int = 21, username: String = "", remoteDirectory: String = "/", passive: Bool = true,
uploadWithTempName: Bool = true, renamePattern: String = "", variant: UploadVariant = .jpeg,
sshKeyPath: String = "", allowInsecureTLS: Bool = false) {
sshKeyPath: String = "", allowInsecureTLS: Bool = false, preflight: Bool = true) {
self.id = id; self.name = name; self.proto = proto; self.host = host; self.port = port
self.username = username; self.remoteDirectory = remoteDirectory; self.passive = passive
self.uploadWithTempName = uploadWithTempName; self.renamePattern = renamePattern; self.variant = variant
self.sshKeyPath = sshKeyPath; self.allowInsecureTLS = allowInsecureTLS
self.sshKeyPath = sshKeyPath; self.allowInsecureTLS = allowInsecureTLS; self.preflight = preflight
}
enum CodingKeys: String, CodingKey {
case id, name, proto, host, port, username, remoteDirectory, passive, uploadWithTempName, renamePattern,
variant, sshKeyPath, allowInsecureTLS, preflight
}
/// Tolerant decoding – new options must never wipe the saved server profiles.
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = FTPDestination()
func v<T: Decodable>(_ k: CodingKeys, _ def: T) -> T { (try? c.decode(T.self, forKey: k)) ?? def }
id = v(.id, UUID())
name = v(.name, d.name)
proto = v(.proto, d.proto)
host = v(.host, d.host)
port = v(.port, d.port)
username = v(.username, d.username)
remoteDirectory = v(.remoteDirectory, d.remoteDirectory)
passive = v(.passive, d.passive)
uploadWithTempName = v(.uploadWithTempName, d.uploadWithTempName)
renamePattern = v(.renamePattern, d.renamePattern)
variant = v(.variant, d.variant)
sshKeyPath = v(.sshKeyPath, d.sshKeyPath)
allowInsecureTLS = v(.allowInsecureTLS, d.allowInsecureTLS)
preflight = v(.preflight, d.preflight)
}
public var keychainAccount: String { "ftp-\(id.uuidString)" }
@@ -0,0 +1,175 @@
import Foundation
/// Agentur-Check: what is checked before photos go to an agency server.
public struct PreflightOptions: Codable, Hashable, Sendable {
/// Field ids that must not be empty (error)
public var requiredFields: [String] = ["caption", "headline", "creator", "copyright", "city", "country", "dateCreated"]
/// First caption line empty (the line for the people in the PM template) → warning
public var warnEmptyFirstLine = true
/// Dates like 02.11.2026 in headline/caption must match the capture date (old template reused?)
public var checkDates = true
/// IIM byte limits (agencies truncate)
public var checkLengths = true
/// Jersey suggestions not yet accepted/dismissed
public var checkOpenSuggestions = true
/// Minimum long edge in pixels (0 = off)
public var minLongEdge = 0
public init() {}
enum CodingKeys: String, CodingKey {
case requiredFields, warnEmptyFirstLine, checkDates, checkLengths, checkOpenSuggestions, minLongEdge
}
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
let d = PreflightOptions()
requiredFields = (try? c.decode([String].self, forKey: .requiredFields)) ?? d.requiredFields
warnEmptyFirstLine = (try? c.decode(Bool.self, forKey: .warnEmptyFirstLine)) ?? d.warnEmptyFirstLine
checkDates = (try? c.decode(Bool.self, forKey: .checkDates)) ?? d.checkDates
checkLengths = (try? c.decode(Bool.self, forKey: .checkLengths)) ?? d.checkLengths
checkOpenSuggestions = (try? c.decode(Bool.self, forKey: .checkOpenSuggestions)) ?? d.checkOpenSuggestions
minLongEdge = (try? c.decode(Int.self, forKey: .minLongEdge)) ?? d.minLongEdge
}
}
public enum PreflightSeverity: String, Codable, Sendable, Comparable {
case warning, error
public static func < (a: PreflightSeverity, b: PreflightSeverity) -> Bool { a == .warning && b == .error }
}
public struct PreflightIssue: Hashable, Identifiable, Sendable {
public var id: String { severity.rawValue + "|" + message }
public var severity: PreflightSeverity
public var message: String
/// field the issue belongs to (to jump to it), nil = whole image
public var fieldID: String?
public init(_ severity: PreflightSeverity, _ message: String, field: String? = nil) {
self.severity = severity; self.message = message; self.fieldID = field
}
}
public enum Preflight {
/// Checks one photo. `openSuggestions` = codes/names of jersey suggestions still open.
public static func check(iptc: IPTCValues, exif: [String: String], captureDate: Date?, codes: CodeReplacements,
options: PreflightOptions, openSuggestions: [String] = []) -> [PreflightIssue] {
var issues: [PreflightIssue] = []
// 1. required fields
for id in options.requiredFields {
guard let f = IPTCField.byID[id] else { continue }
let value = f.kind == .list ? iptc.list(f).joined() : (iptc.text[id] ?? "")
if value.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
issues.append(PreflightIssue(.error, "Pflichtfeld leer: \(f.label)", field: id))
}
}
let caption = iptc.text["caption"] ?? ""
// 2. first caption line (people line of the template) still empty
if options.warnEmptyFirstLine, !caption.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
let first = caption.components(separatedBy: .newlines).first ?? ""
if first.trimmingCharacters(in: .whitespaces).isEmpty {
issues.append(PreflightIssue(.warning, "Erste Zeile der Beschreibung ist leer – Person vergessen?", field: "caption"))
}
}
// 3. unresolved variables / codes in any text
var allTexts: [(IPTCField, String)] = []
for f in IPTCField.all {
if f.kind == .list { for v in iptc.list(f) { allTexts.append((f, v)) } }
else if let v = iptc.text[f.id], !v.isEmpty { allTexts.append((f, v)) }
}
var reported = Set<String>()
for (f, text) in allTexts {
for v in unresolvedVariables(in: text) where reported.insert("var" + v).inserted {
issues.append(PreflightIssue(.error, "Variable nicht ersetzt: \(v) (\(f.label))", field: f.id))
}
for c in unresolvedDelimiterCodes(in: text, delimiter: codes.delimiter) where reported.insert("code" + c).inserted {
issues.append(PreflightIssue(.error, "Code nicht ersetzt: \(c) (\(f.label))", field: f.id))
}
}
for (f, text) in allTexts where ["caption", "headline", "personInImage", "objectName"].contains(f.id) {
for token in bareCodes(in: text, codes: codes) where reported.insert("bare" + token).inserted {
issues.append(PreflightIssue(.warning, "„\(token)“ ist ein Code und steht noch im Text (\(f.label))", field: f.id))
}
}
// 4. dates in headline / caption vs. capture date
if options.checkDates, let captureDate {
let cal = Calendar(identifier: .gregorian)
for id in ["headline", "caption", "event"] {
guard let text = iptc.text[id] else { continue }
for d in dates(in: text) {
let days = abs(cal.dateComponents([.day], from: cal.startOfDay(for: d), to: cal.startOfDay(for: captureDate)).day ?? 0)
// ±1 day: late kick-off after midnight
if days > 1 {
let f = DateFormatter(); f.dateFormat = "dd.MM.yyyy"
let label = IPTCField.byID[id]?.label ?? id
issues.append(PreflightIssue(.warning, "Datum \(f.string(from: d)) in „\(label)“ passt nicht zur Aufnahme (\(f.string(from: captureDate))) – alte Vorlage?", field: id))
}
}
}
}
// 5. IIM lengths
if options.checkLengths {
for f in IPTCField.all {
guard let max = f.iimMaxBytes, f.iimTag != nil, f.id != "dateCreated" else { continue }
if f.kind == .list {
for v in iptc.list(f) where v.utf8.count > max {
issues.append(PreflightIssue(.warning, "\(f.label) „\(v.prefix(30))…“ länger als \(max) Bytes – wird gekürzt", field: f.id))
}
} else if let v = iptc.text[f.id], v.utf8.count > max {
issues.append(PreflightIssue(.warning, "\(f.label) zu lang (\(v.utf8.count)/\(max) Bytes) – wird gekürzt", field: f.id))
}
}
}
// 6. open jersey suggestions
if options.checkOpenSuggestions, !openSuggestions.isEmpty {
issues.append(PreflightIssue(.warning, "Spieler-Vorschlag noch offen: \(openSuggestions.joined(separator: ", "))"))
}
// 7. image size
if options.minLongEdge > 0,
let w = exif["ImageWidth"].flatMap({ Int($0) }), let h = exif["ImageHeight"].flatMap({ Int($0) }),
max(w, h) < options.minLongEdge {
issues.append(PreflightIssue(.error, "Bild zu klein: \(max(w, h)) px lange Kante (mindestens \(options.minLongEdge) px)"))
}
return issues.sorted { ($0.severity, $1.message) > ($1.severity, $0.message) }
}
/// "{city}", "{date}" … left in a text
static func unresolvedVariables(in text: String) -> [String] {
matches(#"\{[A-Za-z][A-Za-z0-9_]*\}"#, in: text)
}
/// ".w10." / "\h7\" – a code shape (letters + digits) between two delimiters
static func unresolvedDelimiterCodes(in text: String, delimiter: Character) -> [String] {
let d = NSRegularExpression.escapedPattern(for: String(delimiter))
return matches(d + #"[A-Za-z]{1,5}\d{1,3}(#\d+)?"# + d, in: text)
}
/// Words like "w10" that are codes of the enabled teams and were not expanded (typed without a space at the end).
static func bareCodes(in text: String, codes: CodeReplacements) -> [String] {
matches(#"(?<![A-Za-z0-9])[A-Za-z]{1,4}\d{1,3}(?![A-Za-z0-9])"#, in: text).filter { codes.lookup($0) != nil }
}
/// dd.MM.yyyy dates in a text
static func dates(in text: String) -> [Date] {
let f = DateFormatter()
f.locale = Locale(identifier: "de_DE")
f.dateFormat = "dd.MM.yyyy"
return matches(#"\b\d{2}\.\d{2}\.\d{4}\b"#, in: text).compactMap { f.date(from: $0) }
}
static func matches(_ pattern: String, in text: String) -> [String] {
guard let re = try? NSRegularExpression(pattern: pattern) else { return [] }
let ns = text as NSString
return re.matches(in: text, range: NSRange(location: 0, length: ns.length)).map { ns.substring(with: $0.range) }
}
}
@@ -0,0 +1,73 @@
import Foundation
/// One successful upload of a file.
public struct SentRecord: Codable, Hashable, Sendable {
/// FTP destination id (uuid string) or "immich"
public var destination: String
/// Destination name at the time of sending ("Beautiful Sports – Sport")
public var destinationName: String
/// File name on the server (after renaming)
public var remoteName: String
public var date: Date
public var size: Int64
public init(destination: String, destinationName: String, remoteName: String, date: Date = Date(), size: Int64 = 0) {
self.destination = destination; self.destinationName = destinationName
self.remoteName = remoteName; self.date = date; self.size = size
}
}
/// Upload history per file ("Gesendet"-Status). Keyed by the standardized file path; a photo counts as sent
/// when any of its files (RAW, JPEG companion) was sent.
public struct SentLog: Codable, Sendable {
public private(set) var records: [String: [SentRecord]] = [:]
public init() {}
public static func key(_ url: URL) -> String { url.standardizedFileURL.path }
public mutating func record(_ url: URL, _ r: SentRecord) {
records[SentLog.key(url), default: []].append(r)
}
/// Forget the history of these files ("Als nicht gesendet markieren").
public mutating func clear(_ urls: [URL]) {
for u in urls { records[SentLog.key(u)] = nil }
}
public func records(for urls: [URL]) -> [SentRecord] {
urls.flatMap { records[SentLog.key($0)] ?? [] }.sorted { $0.date < $1.date }
}
public func records(for item: PhotoItem) -> [SentRecord] {
records(for: [item.primary] + item.companions)
}
public func wasSent(_ item: PhotoItem, to destination: String? = nil) -> Bool {
let r = records(for: item)
guard let destination else { return !r.isEmpty }
return r.contains { $0.destination == destination }
}
/// Short summary for the thumbnail / panels, newest first.
public func summary(for item: PhotoItem) -> SentSummary? {
let r = records(for: item)
guard let last = r.last else { return nil }
let names = r.reduce(into: [String]()) { acc, rec in if !acc.contains(rec.destinationName) { acc.append(rec.destinationName) } }
return SentSummary(count: r.count, destinations: names, last: last.date, lastDestination: last.destinationName)
}
}
public struct SentSummary: Hashable, Sendable {
public var count: Int
public var destinations: [String]
public var last: Date
public var lastDestination: String
public var tooltip: String {
let f = DateFormatter()
f.dateFormat = "dd.MM.yyyy HH:mm"
let times = count == 1 ? "" : " (\(count)× gesendet)"
return "Gesendet an \(destinations.joined(separator: ", ")) – zuletzt \(f.string(from: last))\(times)"
}
}