Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
74 lines
3.8 KiB
Swift
74 lines
3.8 KiB
Swift
import SwiftUI
|
||
import LichtkastenCore
|
||
|
||
/// ⌘U – PM "Upload Photos" dialog for the selected images.
|
||
struct UploadWindow: View {
|
||
@EnvironmentObject var state: AppState
|
||
@Environment(\.dismissWindow) private var dismissWindow
|
||
@AppStorage("lastUploadTarget") private var target = ""
|
||
|
||
private var destination: FTPDestination? { state.settings.ftpDestinations.first { $0.id.uuidString == target } }
|
||
|
||
private var variant: UploadVariant {
|
||
target == "immich" ? state.settings.immich.variant : destination?.variant ?? .jpeg
|
||
}
|
||
|
||
private var files: [URL] { state.selectedItems.flatMap { state.uploadFiles(for: $0, variant: variant) } }
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 14) {
|
||
Text("Bilder hochladen").font(.title3.bold())
|
||
Form {
|
||
Picker("Ziel", selection: $target) {
|
||
Text("– bitte wählen –").tag("")
|
||
ForEach(state.settings.ftpDestinations) { d in Text(d.name).tag(d.id.uuidString) }
|
||
if state.settings.immich.enabled { Text("Immich").tag("immich") }
|
||
}
|
||
if let d = destination {
|
||
LabeledContent("Server", value: "\(d.proto.rawValue) · \(d.host):\(d.port)")
|
||
if let i = state.settings.ftpDestinations.firstIndex(where: { $0.id == d.id }) {
|
||
TextField("Zielordner", text: $state.settings.ftpDestinations[i].remoteDirectory)
|
||
TextField("Umbenennen (leer = Originalname)", text: $state.settings.ftpDestinations[i].renamePattern)
|
||
Picker("Dateien", selection: $state.settings.ftpDestinations[i].variant) {
|
||
ForEach(UploadVariant.allCases, id: \.self) { Text($0.rawValue).tag($0) }
|
||
}
|
||
}
|
||
if d.username.isEmpty || Keychain.get(d.keychainAccount) == nil {
|
||
Label("Benutzer/Passwort fehlen – Einstellungen → FTP", systemImage: "exclamationmark.triangle.fill")
|
||
.foregroundStyle(.orange)
|
||
}
|
||
} else if target == "immich" {
|
||
LabeledContent("Server", value: state.settings.immich.serverURL)
|
||
let albums = Set(state.selectedItems.map { state.immichAlbum(for: $0) }.filter { !$0.isEmpty })
|
||
LabeledContent("Album", value: albums.isEmpty ? "– kein Album –" : albums.sorted().joined(separator: ", "))
|
||
TextField("Album-Muster", text: $state.settings.immich.albumName, prompt: Text("{event}"))
|
||
}
|
||
LabeledContent("Auswahl", value: "\(state.selectedItems.count) Bild(er) → \(files.count) Datei(en)")
|
||
if files.count < state.selectedItems.count {
|
||
Text("Einige Bilder haben kein JPEG – zuerst in Lightroom exportieren (⌘⌥L).")
|
||
.font(.caption).foregroundStyle(.orange)
|
||
}
|
||
}
|
||
.lkForm()
|
||
HStack {
|
||
SettingsLink { Text("Server verwalten …") }
|
||
Spacer()
|
||
Button("Abbrechen") { dismissWindow(id: "upload") }.keyboardShortcut(.cancelAction)
|
||
Button("Hochladen") {
|
||
state.upload(to: target)
|
||
state.openWindow("tasks")
|
||
dismissWindow(id: "upload")
|
||
}
|
||
.keyboardShortcut(.defaultAction)
|
||
.buttonStyle(.borderedProminent)
|
||
.disabled(target.isEmpty || files.isEmpty)
|
||
}
|
||
}
|
||
.padding(18)
|
||
.frame(width: 560)
|
||
.onAppear {
|
||
if target.isEmpty, let first = state.settings.ftpDestinations.first { target = first.id.uuidString }
|
||
}
|
||
}
|
||
}
|