This commit is contained in:
2025-03-20 10:52:32 -06:00
parent 3b593f564e
commit 48f5c0309d
3 changed files with 483 additions and 622 deletions

View File

@ -27,6 +27,9 @@ struct LoginView: View {
.autocapitalization(.none)
.disableAutocorrection(true)
.keyboardType(.URL)
.placeholder(when: serverURL.isEmpty) {
Text("example.com").foregroundColor(.gray.opacity(0.5))
}
SecureField("Admin Password", text: $password)
.textFieldStyle(RoundedBorderTextFieldStyle())
@ -114,9 +117,9 @@ struct LoginView: View {
.onAppear {
// Add some example connection info
debugLogs.append("Example URLs:")
debugLogs.append("https://bsky.social - Main Bluesky server")
debugLogs.append("https://bsky.atri.dad - Your local server")
debugLogs.append("http://localhost:3000 - Local development PDS")
debugLogs.append("bsky.social - Main Bluesky server")
debugLogs.append("bsky.atri.dad - Your local server")
debugLogs.append("localhost:3000 - Local development PDS")
}
}
@ -131,19 +134,8 @@ struct LoginView: View {
// Add debug info
debugLogs.append("Attempting login to: \(serverURL)")
// Sanitize the URL to ensure it has the correct format
var cleanURL = serverURL.trimmingCharacters(in: .whitespacesAndNewlines)
if !cleanURL.hasPrefix("http://") && !cleanURL.hasPrefix("https://") {
cleanURL = "http://\(cleanURL)"
debugLogs.append("Added http:// prefix: \(cleanURL)")
}
// Remove trailing slash if present
if cleanURL.hasSuffix("/") {
cleanURL.removeLast()
debugLogs.append("Removed trailing slash: \(cleanURL)")
}
// Normalize the URL to ensure it has the correct format
var cleanURL = normalizeServerURL(serverURL)
debugLogs.append("Using final URL: \(cleanURL)")
Task {
@ -157,4 +149,44 @@ struct LoginView: View {
}
}
}
private func normalizeServerURL(_ url: String) -> String {
// Remove any leading/trailing whitespace
var cleanURL = url.trimmingCharacters(in: .whitespacesAndNewlines)
// Strip any existing protocol prefix
if cleanURL.hasPrefix("http://") {
cleanURL = String(cleanURL.dropFirst(7))
debugLogs.append("Removed http:// prefix")
} else if cleanURL.hasPrefix("https://") {
cleanURL = String(cleanURL.dropFirst(8))
debugLogs.append("Removed https:// prefix")
}
// Remove trailing slash if present
if cleanURL.hasSuffix("/") {
cleanURL.removeLast()
debugLogs.append("Removed trailing slash")
}
// Add https:// prefix (always use HTTPS by default)
cleanURL = "https://\(cleanURL)"
debugLogs.append("Added https:// prefix")
return cleanURL
}
}
// Placeholder extension for TextField
extension View {
func placeholder<Content: View>(
when shouldShow: Bool,
alignment: Alignment = .leading,
@ViewBuilder placeholder: () -> Content
) -> some View {
ZStack(alignment: alignment) {
placeholder().opacity(shouldShow ? 1 : 0)
self
}
}
}