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:
1 parent
22b2611228
commit
93ecdf03fc
22 files changed
+2119
-49
No files matched your search
@@ -0,0 +1,325 @@
|
||||
import Foundation
|
||||
|
||||
/// Stadium / place of a match.
|
||||
public struct Venue: Codable, Hashable, Sendable {
|
||||
public var name: String = "" // "AOK Stadion"
|
||||
public var city: String = "" // "Wolfsburg"
|
||||
public var state: String = "" // "Niedersachsen"
|
||||
public var country: String = "Deutschland"
|
||||
public var countryCode: String = "DEU"
|
||||
|
||||
public init(name: String = "", city: String = "", state: String = "", country: String = "Deutschland", countryCode: String = "DEU") {
|
||||
self.name = name; self.city = city; self.state = state; self.country = country; self.countryCode = countryCode
|
||||
}
|
||||
|
||||
public var isEmpty: Bool { name.isEmpty && city.isEmpty }
|
||||
}
|
||||
|
||||
/// Kit colors of a team (home / away).
|
||||
public struct Kit: Codable, Hashable, Sendable {
|
||||
public var shirt: KitColor
|
||||
public var shorts: KitColor?
|
||||
public init(shirt: KitColor, shorts: KitColor? = nil) { self.shirt = shirt; self.shorts = shorts }
|
||||
}
|
||||
|
||||
/// A club/team as it appears in captions, keywords, folder names, jersey recognition.
|
||||
public struct TeamProfile: Codable, Hashable, Identifiable, Sendable {
|
||||
public var id = UUID()
|
||||
public var name: String // "VfL Wolfsburg"
|
||||
public var shortName: String // "Wolfsburg (F)" – folder names
|
||||
public var abbreviation: String // "VFL" – match code VFLTSG
|
||||
/// comma separated, e.g. "VfL Wolfsburg, VfL, Wölfe, Wölfinnen, Grün Weiß"
|
||||
public var keywords: String
|
||||
public var venue: Venue // home stadium
|
||||
public var codeSetID: UUID? // players in the code library
|
||||
public var codePrefix: String // "w" → w10
|
||||
public var homeKit: Kit?
|
||||
public var awayKit: Kit?
|
||||
|
||||
public init(name: String, shortName: String = "", abbreviation: String = "", keywords: String = "",
|
||||
venue: Venue = Venue(), codeSetID: UUID? = nil, codePrefix: String = "") {
|
||||
self.name = name; self.shortName = shortName; self.abbreviation = abbreviation; self.keywords = keywords
|
||||
self.venue = venue; self.codeSetID = codeSetID; self.codePrefix = codePrefix
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, name, shortName, abbreviation, keywords, venue, codeSetID, codePrefix, homeKit, awayKit
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = (try? c.decode(UUID.self, forKey: .id)) ?? UUID()
|
||||
name = (try? c.decode(String.self, forKey: .name)) ?? ""
|
||||
shortName = (try? c.decode(String.self, forKey: .shortName)) ?? ""
|
||||
abbreviation = (try? c.decode(String.self, forKey: .abbreviation)) ?? ""
|
||||
keywords = (try? c.decode(String.self, forKey: .keywords)) ?? ""
|
||||
venue = (try? c.decode(Venue.self, forKey: .venue)) ?? Venue()
|
||||
codeSetID = try? c.decode(UUID.self, forKey: .codeSetID)
|
||||
codePrefix = (try? c.decode(String.self, forKey: .codePrefix)) ?? ""
|
||||
homeKit = try? c.decode(Kit.self, forKey: .homeKit)
|
||||
awayKit = try? c.decode(Kit.self, forKey: .awayKit)
|
||||
}
|
||||
|
||||
/// "VfL Wolfsburg" → "VFL" when no abbreviation is set
|
||||
public var effectiveAbbreviation: String {
|
||||
if !abbreviation.isEmpty { return abbreviation.uppercased() }
|
||||
let words = name.split(separator: " ").map(String.init)
|
||||
let main = words.first { $0.count > 3 && $0.first?.isLetter == true } ?? words.first ?? name
|
||||
return String(main.prefix(3)).uppercased()
|
||||
}
|
||||
|
||||
public var effectiveShortName: String { shortName.isEmpty ? name : shortName }
|
||||
}
|
||||
|
||||
/// Competition: "DFB-Pokal Frauen", "Frauen-Bundesliga", "FIBA Women's World Cup" …
|
||||
public struct Competition: Codable, Hashable, Identifiable, Sendable {
|
||||
public var id = UUID()
|
||||
public var name: String // headline / event: "DFB-Pokal Frauen"
|
||||
public var longName: String // caption: "DFB-Pokal der Frauen"
|
||||
public var sport: String // "Fußball"
|
||||
public var keywords: String // comma separated
|
||||
/// rights notice appended to the caption ("DFB REGULATIONS PROHIBIT …")
|
||||
public var notice: String
|
||||
|
||||
public init(name: String, longName: String = "", sport: String = "Fußball", keywords: String = "", notice: String = "") {
|
||||
self.name = name; self.longName = longName; self.sport = sport; self.keywords = keywords; self.notice = notice
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey { case id, name, longName, sport, keywords, notice }
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = (try? c.decode(UUID.self, forKey: .id)) ?? UUID()
|
||||
name = (try? c.decode(String.self, forKey: .name)) ?? ""
|
||||
longName = (try? c.decode(String.self, forKey: .longName)) ?? ""
|
||||
sport = (try? c.decode(String.self, forKey: .sport)) ?? "Fußball"
|
||||
keywords = (try? c.decode(String.self, forKey: .keywords)) ?? ""
|
||||
notice = (try? c.decode(String.self, forKey: .notice)) ?? ""
|
||||
}
|
||||
}
|
||||
|
||||
/// How the IPTC of every match is built – defaults follow Leon's Photo Mechanic template.
|
||||
public struct SpieltagPatterns: Codable, Hashable, Sendable {
|
||||
public var headline = "{competition}: {home} vs. {away}, {matchdate}"
|
||||
public var event = "{competition}: {home} - {away}"
|
||||
public var caption = "\n\n\n; {sport}, {competitionLong}, {round}: {home} vs. {away} am {matchdate} im {venue}, {city}{noticeBlock}"
|
||||
public var folder = "{matchdate} - {homeShort} - {awayShort}"
|
||||
public var matchCode = "{homeAbbr}{awayAbbr}"
|
||||
public var seasonKeyword = "Saison {season}"
|
||||
/// keywords for every match, comma separated ("Fußball, Fußballspiel, BLD")
|
||||
public var generalKeywords = ""
|
||||
|
||||
public init() {}
|
||||
|
||||
enum CodingKeys: String, CodingKey { case headline, event, caption, folder, matchCode, seasonKeyword, generalKeywords }
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let d = SpieltagPatterns()
|
||||
headline = (try? c.decode(String.self, forKey: .headline)) ?? d.headline
|
||||
event = (try? c.decode(String.self, forKey: .event)) ?? d.event
|
||||
caption = (try? c.decode(String.self, forKey: .caption)) ?? d.caption
|
||||
folder = (try? c.decode(String.self, forKey: .folder)) ?? d.folder
|
||||
matchCode = (try? c.decode(String.self, forKey: .matchCode)) ?? d.matchCode
|
||||
seasonKeyword = (try? c.decode(String.self, forKey: .seasonKeyword)) ?? d.seasonKeyword
|
||||
generalKeywords = (try? c.decode(String.self, forKey: .generalKeywords)) ?? d.generalKeywords
|
||||
}
|
||||
|
||||
/// Variables available in all patterns (shown in the assistant).
|
||||
public static let variables: [(String, String)] = [
|
||||
("{home}", "Heimteam"), ("{away}", "Gastteam"), ("{homeShort}", "Heim kurz (Ordner)"), ("{awayShort}", "Gast kurz"),
|
||||
("{homeAbbr}", "Heim-Kürzel"), ("{awayAbbr}", "Gast-Kürzel"), ("{competition}", "Wettbewerb"),
|
||||
("{competitionLong}", "Wettbewerb lang"), ("{round}", "Runde / Spieltag"), ("{sport}", "Sportart"),
|
||||
("{venue}", "Stadion"), ("{city}", "Stadt"), ("{state}", "Bundesland"), ("{country}", "Land"),
|
||||
("{matchdate}", "Datum 02.11.2026"), ("{isomatchdate}", "Datum 2026-11-02"), ("{season}", "Saison 26/27"),
|
||||
("{matchcode}", "Matchcode"), ("{notice}", "Rechtehinweis"), ("{noticeBlock}", "Leerzeile + Rechtehinweis"),
|
||||
]
|
||||
}
|
||||
|
||||
/// One planned/created match.
|
||||
public struct MatchPlan: Codable, Hashable, Identifiable, Sendable {
|
||||
public var id = UUID()
|
||||
public var homeID: UUID
|
||||
public var awayID: UUID
|
||||
public var competitionID: UUID?
|
||||
public var round: String
|
||||
public var date: Date
|
||||
public var venue: Venue
|
||||
/// comma separated, only for this match
|
||||
public var extraKeywords: String
|
||||
public var baseTemplateID: UUID?
|
||||
public var templateID: UUID?
|
||||
/// event text written into the photos – finds the match of a photo later (e.g. in SENT)
|
||||
public var event: String
|
||||
public var folderName: String
|
||||
public var created: Date
|
||||
|
||||
public init(homeID: UUID, awayID: UUID, competitionID: UUID?, round: String, date: Date, venue: Venue,
|
||||
extraKeywords: String = "", baseTemplateID: UUID? = nil) {
|
||||
self.homeID = homeID; self.awayID = awayID; self.competitionID = competitionID; self.round = round
|
||||
self.date = date; self.venue = venue; self.extraKeywords = extraKeywords; self.baseTemplateID = baseTemplateID
|
||||
self.event = ""; self.folderName = ""; self.created = Date()
|
||||
}
|
||||
}
|
||||
|
||||
/// Everything the Spieltag assistant remembers.
|
||||
public struct SpieltagLibrary: Codable, Sendable {
|
||||
public var teams: [TeamProfile] = []
|
||||
public var competitions: [Competition] = []
|
||||
public var patterns = SpieltagPatterns()
|
||||
public var matches: [MatchPlan] = []
|
||||
public var lastBaseTemplateID: UUID?
|
||||
public var lastCompetitionID: UUID?
|
||||
|
||||
public init() {}
|
||||
|
||||
enum CodingKeys: String, CodingKey { case teams, competitions, patterns, matches, lastBaseTemplateID, lastCompetitionID }
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||
teams = (try? c.decode([TeamProfile].self, forKey: .teams)) ?? []
|
||||
competitions = (try? c.decode([Competition].self, forKey: .competitions)) ?? []
|
||||
patterns = (try? c.decode(SpieltagPatterns.self, forKey: .patterns)) ?? SpieltagPatterns()
|
||||
matches = (try? c.decode([MatchPlan].self, forKey: .matches)) ?? []
|
||||
lastBaseTemplateID = try? c.decode(UUID.self, forKey: .lastBaseTemplateID)
|
||||
lastCompetitionID = try? c.decode(UUID.self, forKey: .lastCompetitionID)
|
||||
}
|
||||
|
||||
public func team(_ id: UUID?) -> TeamProfile? { id.flatMap { i in teams.first { $0.id == i } } }
|
||||
public func competition(_ id: UUID?) -> Competition? { id.flatMap { i in competitions.first { $0.id == i } } }
|
||||
|
||||
/// Newest match whose event text is exactly this (IPTC "Event" of a photo).
|
||||
public func match(forEvent event: String) -> MatchPlan? {
|
||||
guard !event.isEmpty else { return nil }
|
||||
return matches.last { $0.event == event }
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds headline, event, caption, keywords, folder name and the IPTC template of a match.
|
||||
public enum SpieltagGenerator {
|
||||
/// Season of a date: July–June, "26/27" for November 2026.
|
||||
public static func season(for date: Date) -> String {
|
||||
let c = Calendar(identifier: .gregorian).dateComponents([.year, .month], from: date)
|
||||
let y = (c.year ?? 2000) % 100, m = c.month ?? 1
|
||||
let start = m >= 7 ? y : (y + 99) % 100
|
||||
return String(format: "%02d/%02d", start, (start + 1) % 100)
|
||||
}
|
||||
|
||||
public static func context(match: MatchPlan, home: TeamProfile, away: TeamProfile, competition: Competition?,
|
||||
patterns: SpieltagPatterns) -> [String: String] {
|
||||
let f = DateFormatter()
|
||||
f.locale = Locale(identifier: "de_DE")
|
||||
f.dateFormat = "dd.MM.yyyy"
|
||||
let iso = DateFormatter()
|
||||
iso.locale = Locale(identifier: "en_US_POSIX")
|
||||
iso.dateFormat = "yyyy-MM-dd"
|
||||
var ctx: [String: String] = [
|
||||
"home": home.name, "away": away.name,
|
||||
"homeshort": home.effectiveShortName, "awayshort": away.effectiveShortName,
|
||||
"homeabbr": home.effectiveAbbreviation, "awayabbr": away.effectiveAbbreviation,
|
||||
"competition": competition?.name ?? "",
|
||||
"competitionlong": (competition?.longName.isEmpty == false ? competition?.longName : competition?.name) ?? "",
|
||||
"round": match.round, "sport": competition?.sport ?? "",
|
||||
"venue": match.venue.name, "city": match.venue.city, "state": match.venue.state,
|
||||
"country": match.venue.country, "countrycode": match.venue.countryCode,
|
||||
"matchdate": f.string(from: match.date), "isomatchdate": iso.string(from: match.date),
|
||||
"season": season(for: match.date),
|
||||
"notice": competition?.notice ?? "",
|
||||
"noticeblock": (competition?.notice ?? "").isEmpty ? "" : "\n\n" + (competition?.notice ?? ""),
|
||||
]
|
||||
ctx["matchcode"] = fill(patterns.matchCode, ctx).replacingOccurrences(of: " ", with: "")
|
||||
return ctx
|
||||
}
|
||||
|
||||
/// Replaces {variables} (case-insensitive) and tidies separators left by empty values
|
||||
/// (", :" → ":", ", ," → ","). Line breaks are kept exactly.
|
||||
public static func fill(_ pattern: String, _ ctx: [String: String]) -> String {
|
||||
var out = ""
|
||||
var rest = pattern[...]
|
||||
while let open = rest.firstIndex(of: "{") {
|
||||
out += rest[..<open]
|
||||
guard let close = rest[open...].firstIndex(of: "}") else { break }
|
||||
let key = rest[rest.index(after: open)..<close].lowercased()
|
||||
if let v = ctx[key] { out += v } else { out += rest[open...close] }
|
||||
rest = rest[rest.index(after: close)...]
|
||||
}
|
||||
out += rest
|
||||
return out.components(separatedBy: "\n").map(tidy).joined(separator: "\n")
|
||||
}
|
||||
|
||||
static func tidy(_ line: String) -> String {
|
||||
var s = line
|
||||
let rules: [(String, String)] = [(#",\s*:"#, ":"), (#",\s*,"#, ","), (#"\s+,"#, ","), (#"\(\s*\)"#, ""), (#" {2,}"#, " ")]
|
||||
for (p, r) in rules {
|
||||
s = s.replacingOccurrences(of: p, with: r, options: .regularExpression)
|
||||
}
|
||||
// trailing separators from empty values at the end ("…, 02.11.2026, " → "…, 02.11.2026")
|
||||
s = s.replacingOccurrences(of: #"[\s,;:–-]+$"#, with: "", options: .regularExpression)
|
||||
return s
|
||||
}
|
||||
|
||||
public static func splitKeywords(_ s: String) -> [String] { IPTCValues.splitList(s) }
|
||||
|
||||
public static func keywords(match: MatchPlan, home: TeamProfile, away: TeamProfile, competition: Competition?,
|
||||
patterns: SpieltagPatterns, ctx: [String: String]) -> [String] {
|
||||
var all: [String] = []
|
||||
all += splitKeywords(patterns.generalKeywords)
|
||||
all += splitKeywords(competition?.keywords ?? "")
|
||||
if !match.round.isEmpty { all.append(match.round) }
|
||||
all += splitKeywords(home.keywords)
|
||||
all += splitKeywords(away.keywords)
|
||||
if !match.venue.name.isEmpty { all.append(match.venue.name) }
|
||||
if let code = ctx["matchcode"], !code.isEmpty { all.append(code) }
|
||||
let season = fill(patterns.seasonKeyword, ctx)
|
||||
if !season.isEmpty { all.append(season) }
|
||||
all += splitKeywords(match.extraKeywords)
|
||||
var seen = Set<String>()
|
||||
return all.filter { seen.insert($0.lowercased()).inserted }
|
||||
}
|
||||
|
||||
/// Folder name for the ingest (no path separators).
|
||||
public static func folderName(patterns: SpieltagPatterns, ctx: [String: String]) -> String {
|
||||
fill(patterns.folder, ctx).replacingOccurrences(of: "/", with: "-").replacingOccurrences(of: ":", with: "-")
|
||||
}
|
||||
|
||||
public static let generatedFields = ["headline", "event", "caption", "city", "sublocation", "state", "country",
|
||||
"countryCode", "keywords", "dateCreated"]
|
||||
|
||||
/// The IPTC template of the match: base template (creator, copyright, …) + everything generated.
|
||||
public static func makeTemplate(match: MatchPlan, home: TeamProfile, away: TeamProfile, competition: Competition?,
|
||||
patterns: SpieltagPatterns, base: IPTCTemplate?) -> IPTCTemplate {
|
||||
let ctx = context(match: match, home: home, away: away, competition: competition, patterns: patterns)
|
||||
var t = base ?? IPTCTemplate(name: "", listMergeMode: .replace)
|
||||
t.id = match.templateID ?? UUID()
|
||||
t.name = "Spieltag \(ctx["matchdate"] ?? "") · \(home.name) – \(away.name)"
|
||||
var v = t.values
|
||||
v.text["headline"] = fill(patterns.headline, ctx)
|
||||
v.text["event"] = fill(patterns.event, ctx)
|
||||
v.text["caption"] = fill(patterns.caption, ctx)
|
||||
v.text["city"] = match.venue.city.isEmpty ? nil : match.venue.city
|
||||
v.text["sublocation"] = match.venue.name.isEmpty ? nil : match.venue.name
|
||||
v.text["state"] = match.venue.state.isEmpty ? nil : match.venue.state
|
||||
v.text["country"] = match.venue.country.isEmpty ? nil : match.venue.country
|
||||
v.text["countryCode"] = match.venue.countryCode.isEmpty ? nil : match.venue.countryCode
|
||||
v.lists["keywords"] = keywords(match: match, home: home, away: away, competition: competition, patterns: patterns, ctx: ctx)
|
||||
v.text["dateCreated"] = "{capturetime}"
|
||||
// "Location created" only if the base template uses it – then it must not keep the old stadium
|
||||
if t.values.text["lcCity"] != nil || t.values.text["lcSublocation"] != nil {
|
||||
v.text["lcCity"] = match.venue.city
|
||||
v.text["lcSublocation"] = match.venue.name
|
||||
v.text["lcState"] = match.venue.state
|
||||
v.text["lcCountry"] = match.venue.country
|
||||
v.text["lcCountryCode"] = match.venue.countryCode
|
||||
}
|
||||
t.values = v
|
||||
t.dateFromCapture = true
|
||||
if var applied = t.appliedFields {
|
||||
applied.formUnion(generatedFields)
|
||||
t.appliedFields = applied
|
||||
}
|
||||
if base == nil { t.listMergeMode = .replace }
|
||||
t.unmappedPMCodes = []
|
||||
t.modified = Date()
|
||||
return t
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,13 @@ public struct JerseyTeam: Codable, Hashable, Identifiable, Sendable {
|
||||
public var prefix: String
|
||||
public var shirtColor: KitColor
|
||||
public var shortsColor: KitColor?
|
||||
/// team profile of the Spieltag assistant this team comes from (kit colors are written back to it)
|
||||
public var profileID: UUID?
|
||||
/// home or away kit of that profile
|
||||
public var isHome: Bool?
|
||||
|
||||
public init(name: String, codeSetID: UUID? = nil, prefix: String, shirtColor: KitColor, shortsColor: KitColor? = nil) {
|
||||
self.name = name; self.codeSetID = codeSetID; self.prefix = prefix
|
||||
public init(id: UUID = UUID(), name: String, codeSetID: UUID? = nil, prefix: String, shirtColor: KitColor, shortsColor: KitColor? = nil) {
|
||||
self.id = id; self.name = name; self.codeSetID = codeSetID; self.prefix = prefix
|
||||
self.shirtColor = shirtColor; self.shortsColor = shortsColor
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user