mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-28 11:37:17 +00:00
feat: add site logins integration to Add Downloads window
This commit is contained in:
@@ -21,6 +21,10 @@ struct AddDownloadsView: View {
|
|||||||
@State private var headerText = ""
|
@State private var headerText = ""
|
||||||
@State private var cookieText = ""
|
@State private var cookieText = ""
|
||||||
@State private var mirrorText = ""
|
@State private var mirrorText = ""
|
||||||
|
@State private var useAuthorization = false
|
||||||
|
@State private var authUsername = ""
|
||||||
|
@State private var authPassword = ""
|
||||||
|
@State private var saveLogin = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
@@ -139,6 +143,30 @@ struct AddDownloadsView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GridRow(alignment: .top) {
|
||||||
|
Label("Authorization", systemImage: "lock.shield")
|
||||||
|
.font(.headline)
|
||||||
|
.padding(.top, 4)
|
||||||
|
VStack(alignment: .leading, spacing: 10) {
|
||||||
|
Toggle("Use authorization", isOn: $useAuthorization)
|
||||||
|
.toggleStyle(.switch)
|
||||||
|
|
||||||
|
if useAuthorization {
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
TextField("Username", text: $authUsername)
|
||||||
|
.textFieldStyle(.roundedBorder)
|
||||||
|
.frame(width: 160)
|
||||||
|
SecureField("Password", text: $authPassword)
|
||||||
|
.textFieldStyle(.roundedBorder)
|
||||||
|
.frame(width: 160)
|
||||||
|
}
|
||||||
|
Toggle("Save login for this website", isOn: $saveLogin)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,6 +393,13 @@ struct AddDownloadsView: View {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let firstURL = urls.first, let creds = settings.credentials(for: firstURL) {
|
||||||
|
useAuthorization = true
|
||||||
|
authUsername = creds.username
|
||||||
|
authPassword = creds.password
|
||||||
|
saveLogin = false
|
||||||
|
}
|
||||||
|
|
||||||
metadataTask = Task {
|
metadataTask = Task {
|
||||||
var loaded: [PendingDownload] = []
|
var loaded: [PendingDownload] = []
|
||||||
for url in urls {
|
for url in urls {
|
||||||
@@ -400,12 +435,30 @@ struct AddDownloadsView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func addDownloads(start: Bool) {
|
private func addDownloads(start: Bool) {
|
||||||
|
var explicitCredentials: DownloadCredentials? = nil
|
||||||
|
if useAuthorization {
|
||||||
|
let cleanUsername = authUsername.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
if !cleanUsername.isEmpty {
|
||||||
|
explicitCredentials = DownloadCredentials(username: cleanUsername, password: authPassword)
|
||||||
|
if saveLogin {
|
||||||
|
var savedHosts = Set<String>()
|
||||||
|
for item in pendingDownloads {
|
||||||
|
if let host = item.url.host, !savedHosts.contains(host) {
|
||||||
|
settings.addSiteLogin(urlPattern: "*.\(host)", username: cleanUsername, password: authPassword)
|
||||||
|
savedHosts.insert(host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
controller.addPendingDownloads(
|
controller.addPendingDownloads(
|
||||||
pendingDownloads,
|
pendingDownloads,
|
||||||
connectionsPerServer: Int(connectionsPerServer),
|
connectionsPerServer: Int(connectionsPerServer),
|
||||||
overrideDirectory: overrideDirectory,
|
overrideDirectory: overrideDirectory,
|
||||||
startImmediately: start,
|
startImmediately: start,
|
||||||
queueID: targetQueueID,
|
queueID: targetQueueID,
|
||||||
|
credentials: explicitCredentials,
|
||||||
transferOptions: transferOptions,
|
transferOptions: transferOptions,
|
||||||
speedLimitKiBPerSecond: speedLimitEnabled ? speedLimitKiBPerSecond : nil
|
speedLimitKiBPerSecond: speedLimitEnabled ? speedLimitKiBPerSecond : nil
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ final class DownloadController: ObservableObject {
|
|||||||
overrideDirectory: URL?,
|
overrideDirectory: URL?,
|
||||||
startImmediately: Bool,
|
startImmediately: Bool,
|
||||||
queueID: UUID = DownloadQueue.mainQueueID,
|
queueID: UUID = DownloadQueue.mainQueueID,
|
||||||
|
credentials: DownloadCredentials? = nil,
|
||||||
transferOptions: DownloadTransferOptions = DownloadTransferOptions(),
|
transferOptions: DownloadTransferOptions = DownloadTransferOptions(),
|
||||||
speedLimitKiBPerSecond: Int? = nil
|
speedLimitKiBPerSecond: Int? = nil
|
||||||
) {
|
) {
|
||||||
@@ -130,7 +131,7 @@ final class DownloadController: ObservableObject {
|
|||||||
category: pending.category,
|
category: pending.category,
|
||||||
destinationDirectory: overrideDirectory ?? pending.defaultDirectory,
|
destinationDirectory: overrideDirectory ?? pending.defaultDirectory,
|
||||||
connectionsPerServer: clampedConnections,
|
connectionsPerServer: clampedConnections,
|
||||||
credentials: settings.credentials(for: pending.url),
|
credentials: credentials ?? settings.credentials(for: pending.url),
|
||||||
checksum: transferOptions.checksum,
|
checksum: transferOptions.checksum,
|
||||||
requestHeaders: transferOptions.requestHeaders,
|
requestHeaders: transferOptions.requestHeaders,
|
||||||
cookieHeader: transferOptions.cookieHeader,
|
cookieHeader: transferOptions.cookieHeader,
|
||||||
|
|||||||
Reference in New Issue
Block a user