summaryrefslogtreecommitdiff
path: root/Sora/Views/Settings/Section/SettingsProviderView.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-06-16 09:37:27 -0700
committerFuwn <[email protected]>2025-06-16 09:37:27 -0700
commitd292e582910c990cae8481c966366b34dc7041b3 (patch)
treefe11aa49917d793e363094644d6c1662886ece88 /Sora/Views/Settings/Section/SettingsProviderView.swift
parentfeat: Development commit (diff)
downloadsora-testing-d292e582910c990cae8481c966366b34dc7041b3.tar.xz
sora-testing-d292e582910c990cae8481c966366b34dc7041b3.zip
feat: Development commit
Diffstat (limited to 'Sora/Views/Settings/Section/SettingsProviderView.swift')
-rw-r--r--Sora/Views/Settings/Section/SettingsProviderView.swift52
1 files changed, 52 insertions, 0 deletions
diff --git a/Sora/Views/Settings/Section/SettingsProviderView.swift b/Sora/Views/Settings/Section/SettingsProviderView.swift
index 606fe64..82834b9 100644
--- a/Sora/Views/Settings/Section/SettingsProviderView.swift
+++ b/Sora/Views/Settings/Section/SettingsProviderView.swift
@@ -20,6 +20,33 @@ struct SettingsProviderView: View {
}
}
+ SecureField(
+ "API Key",
+ text: Binding(
+ get: { settings.providerAPIKeys[settings.preferredBooru] ?? "" },
+ set: { updateCredentials(apiKey: $0) }
+ )
+ )
+ .autocorrectionDisabled(true)
+
+ TextField(
+ "User ID",
+ text: Binding(
+ get: {
+ String(settings.providerUserIDs[settings.preferredBooru] ?? 0)
+ },
+ set: { newValue in
+ let userID = Int(newValue) ?? 0
+
+ updateCredentials(userID: userID)
+ }
+ )
+ )
+ .autocorrectionDisabled(true)
+ #if os(iOS)
+ .keyboardType(.numberPad)
+ #endif
+
Button("Add Custom Provider") {
showingCustomBooruSheet = true
}
@@ -145,6 +172,31 @@ struct SettingsProviderView: View {
return true
}
+ private func updateCredentials(apiKey: String? = nil, userID: Int? = nil) {
+ var allCredentials = settings.providerCredentials
+
+ if let index = allCredentials.firstIndex(where: { $0.provider == settings.preferredBooru }) {
+ let credentials = allCredentials[index]
+
+ allCredentials[index] = BooruProviderCredentials(
+ provider: credentials.provider,
+ apiKey: apiKey ?? credentials.apiKey,
+ userID: userID ?? credentials.userID,
+ id: credentials.id
+ )
+ } else {
+ allCredentials.append(
+ BooruProviderCredentials(
+ provider: settings.preferredBooru,
+ apiKey: apiKey ?? "",
+ userID: userID ?? 0
+ )
+ )
+ }
+
+ settings.providerCredentials = allCredentials
+ }
+
private func removeCustomProviderButtonContent(_ provider: BooruProviderCustom) -> some View {
Button("Remove Custom Provider") {
settings.customProviders.removeAll { $0.id == provider.id }