Fixes aus dem Bundesliga-Einsatz
- Upload: kein Absturz mehr bei abreißender Verbindung (Restzeit-Berechnung lief über), SIGPIPE ignoriert; bei Netzwechsel werden laufende Übertragungen abgebrochen und auf dem neuen Netz automatisch neu gestartet (Versuch zählt nicht), ohne Netz warten sie; tote Verbindungen enden nach 45 s - LR-Export: Bilder, die sich auf der Platte ändern, werden neu eingelesen (vorher blieb der erste, unvollständige Stand stehen); nie leeres IPTC über das JPEG schreiben; Zuordnung auch mit altem Plugin - I-Fenster: Cursor in der Beschreibung steht oben (wie PM), nicht am Ende - ⌘A wählt alle Bilder, ⌘⌫ legt die Auswahl (RAW + JPEG + XMP) nach Rückfrage in den Papierkorb - Gesendet-Status getrennt: grünes FTP- und blaues Immich-Abzeichen, Filter je Ziel, Info in Lupe/I-Fenster - nach dem Ingest sind die neu importierten Bilder ausgewählt (direkt weiter nach Lightroom) 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
fff701674a
commit
b2210757dd
10 files changed
+298
-33
No files matched your search
@@ -178,8 +178,10 @@ public struct FTPUploader: Sendable {
|
||||
let tempName = d.uploadWithTempName ? "lichtkasten-\(UUID().uuidString).part" : name
|
||||
let url = baseURL(d) + Self.encodePath(tempName)
|
||||
// No --silent: the progress meter on stderr gives the live upload rate.
|
||||
// --speed-limit/-time: a dead connection (Wi-Fi without internet) ends after 45 s instead of hanging
|
||||
var args = connectionOptions(d) + ["--show-error", "--fail", "--ftp-create-dirs", "-o", "/dev/null",
|
||||
"--connect-timeout", "20", "-K", "-", "-T", file.path, url]
|
||||
"--connect-timeout", "20", "--speed-limit", "512", "--speed-time", "45",
|
||||
"-K", "-", "-T", file.path, url]
|
||||
if d.uploadWithTempName { args.insert(contentsOf: ["--retry", "2"], at: 0) }
|
||||
if d.uploadWithTempName {
|
||||
if d.proto == .sftp {
|
||||
@@ -294,7 +296,15 @@ public struct FTPUploader: Sendable {
|
||||
/// Like `run`, but hands every stderr line (split at \r and \n) to `onLine` while the process runs.
|
||||
static func runStreaming(_ exe: String, _ args: [String], stdin: String?,
|
||||
onLine: @escaping @Sendable (String) -> Void) async throws -> ProcResult {
|
||||
try await withCheckedThrowingContinuation { cont in
|
||||
// Cancelling the task (network change, cancel button) ends curl instead of letting it hang.
|
||||
final class Running: @unchecked Sendable {
|
||||
let lock = NSLock(); var process: Process?; var cancelled = false
|
||||
func set(_ p: Process) -> Bool { lock.lock(); defer { lock.unlock() }; process = p; return !cancelled }
|
||||
func cancel() { lock.lock(); cancelled = true; let p = process; lock.unlock(); if p?.isRunning == true { p?.terminate() } }
|
||||
}
|
||||
let running = Running()
|
||||
let result: ProcResult = try await withTaskCancellationHandler {
|
||||
try await withCheckedThrowingContinuation { cont in
|
||||
DispatchQueue.global(qos: .utility).async {
|
||||
do {
|
||||
let p = Process()
|
||||
@@ -318,7 +328,10 @@ public struct FTPUploader: Sendable {
|
||||
for line in parts where !line.isEmpty { onLine(line) }
|
||||
}
|
||||
try p.run()
|
||||
if let stdin { inp.fileHandleForWriting.write(Data(stdin.utf8)) }
|
||||
let alive = running.set(p)
|
||||
if !alive { p.terminate() }
|
||||
// throwing write: a curl that already exited must not take the app down (EPIPE)
|
||||
if alive, let stdin { try? inp.fileHandleForWriting.write(contentsOf: Data(stdin.utf8)) }
|
||||
try? inp.fileHandleForWriting.close()
|
||||
_ = out.fileHandleForReading.readDataToEndOfFile()
|
||||
p.waitUntilExit()
|
||||
@@ -329,7 +342,12 @@ public struct FTPUploader: Sendable {
|
||||
stderr: String(decoding: all, as: UTF8.self)))
|
||||
} catch { cont.resume(throwing: error) }
|
||||
}
|
||||
}
|
||||
} onCancel: {
|
||||
running.cancel()
|
||||
}
|
||||
if Task.isCancelled { throw CancellationError() }
|
||||
return result
|
||||
}
|
||||
|
||||
struct ProcResult { var status: Int32; var stdout: String; var stderr: String }
|
||||
@@ -351,7 +369,7 @@ public struct FTPUploader: Sendable {
|
||||
p.standardError = err
|
||||
p.standardInput = inp
|
||||
try p.run()
|
||||
if let stdin { inp.fileHandleForWriting.write(Data(stdin.utf8)) }
|
||||
if let stdin { try? inp.fileHandleForWriting.write(contentsOf: Data(stdin.utf8)) }
|
||||
try? inp.fileHandleForWriting.close()
|
||||
// Read both pipes concurrently to avoid dead-locks on large output.
|
||||
final class Box: @unchecked Sendable { var data = Data() }
|
||||
|
||||
@@ -54,8 +54,19 @@ public struct SentLog: Codable, Sendable {
|
||||
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)
|
||||
var s = SentSummary(count: r.count, destinations: names, last: last.date, lastDestination: last.destinationName)
|
||||
let ftp = r.filter { $0.destination != SentLog.immich }, immich = r.filter { $0.destination == SentLog.immich }
|
||||
s.ftp = ftp.last.map { SentSummary.Part(count: ftp.count, last: $0.date,
|
||||
destinations: Array(Set(ftp.map(\.destinationName))).sorted()) }
|
||||
s.immich = immich.last.map { SentSummary.Part(count: immich.count, last: $0.date, destinations: ["Immich"]) }
|
||||
return s
|
||||
}
|
||||
|
||||
public static let immich = "immich"
|
||||
|
||||
/// Sent to an FTP server (any) / to Immich.
|
||||
public func wasSentByFTP(_ item: PhotoItem) -> Bool { records(for: item).contains { $0.destination != SentLog.immich } }
|
||||
public func wasSentToImmich(_ item: PhotoItem) -> Bool { records(for: item).contains { $0.destination == SentLog.immich } }
|
||||
}
|
||||
|
||||
public struct SentSummary: Hashable, Sendable {
|
||||
@@ -63,6 +74,26 @@ public struct SentSummary: Hashable, Sendable {
|
||||
public var destinations: [String]
|
||||
public var last: Date
|
||||
public var lastDestination: String
|
||||
/// FTP and Immich separately – two badges on the thumbnail
|
||||
public var ftp: Part?
|
||||
public var immich: Part?
|
||||
|
||||
public struct Part: Hashable, Sendable {
|
||||
public var count: Int
|
||||
public var last: Date
|
||||
public var destinations: [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)"
|
||||
}
|
||||
}
|
||||
|
||||
public init(count: Int, destinations: [String], last: Date, lastDestination: String) {
|
||||
self.count = count; self.destinations = destinations; self.last = last; self.lastDestination = lastDestination
|
||||
}
|
||||
|
||||
public var tooltip: String {
|
||||
let f = DateFormatter()
|
||||
|
||||
Reference in new issue
Block a user