feat(microblog): add app token settings page and honest 5xx wording
The app token could only be entered in the publish sheet, and that field came back only after a 401/403, so a saved token had no standing way to be replaced or removed. The new Settings → Micro.blog page writes the same `MicropubTokenStore` slot the sheet reads, with a status row read back from the Keychain after every write so a locked keychain fails visibly instead of claiming "stored". The sheet now names the stored token a send carries when its field is hidden. Micro.blog's errors arrive as HTML pages, never Micropub JSON, so `decodeFailure` fell through to a bare `HTTP 503` that said nothing about whose side it was on. Any 5xx without a JSON description now reads "unavailable on their side — retry in a few minutes"; a described 5xx keeps its description and a 4xx keeps the bare status. One decode covers create, publish, q=config, and media uploads. Docs: AGENTS.md bullets, CHANGELOG [Unreleased] Added/Fixed, and the devlog for this task plus the 0.1.2 release log.
This commit is contained in:
1 parent
9aa0314564
commit
6938826101
11 files changed
+272
-14
No files matched your search
@@ -6,7 +6,9 @@
|
||||
// in-memory SettingsModel — one page per LLM surface (provider select,
|
||||
// registry combobox with first-class free text, per-provider effort menu)
|
||||
// and the Provider Keys page (endpoint, z.ai key-type toggle swapping the
|
||||
// endpoint family, masked key + reveal). Visual contract: #130 prototype
|
||||
// endpoint family, masked key + reveal). The Micro.blog page is the app
|
||||
// token's home (saved status, replace, remove over the publish sheet's own
|
||||
// Keychain slot). Visual contract: #130 prototype
|
||||
// variant C, with variant B's current-model headline folded in.
|
||||
//
|
||||
|
||||
@@ -340,6 +342,83 @@ private struct TestConnectionResult: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Micro.blog page: the app token's home — saved status, replace,
|
||||
/// remove. Writes the SAME Keychain slot the publish sheet reads
|
||||
/// (`MicropubTokenStore`), so a token saved here is the one a send
|
||||
/// carries; the sheet's own field stays the first-run path and its
|
||||
/// 401/403 re-entry. `saved` is read back from the Keychain after every
|
||||
/// write, never assumed — a locked keychain fails the save and the
|
||||
/// status line says so.
|
||||
struct MicroblogSettingsPage: View {
|
||||
@State private var tokenField = ""
|
||||
@State private var saved = MicropubTokenStore.read() != nil
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("Micro.blog")
|
||||
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
||||
Text("Where the Micro.blog app token lives.")
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
form
|
||||
.padding(.top, 12)
|
||||
.frame(maxWidth: DesignTokens.settingsFormWidth, alignment: .leading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.padding(.horizontal, 24)
|
||||
.padding(.top, 17)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||
}
|
||||
|
||||
private var trimmedToken: String {
|
||||
tokenField.trimmingCharacters(in: .whitespaces)
|
||||
}
|
||||
|
||||
private var form: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
SettingsFieldLabel("App Token")
|
||||
HStack(spacing: 8) {
|
||||
SecureField("App token", text: $tokenField)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.font(.system(size: 12, design: DesignTokens.mono))
|
||||
Button("Save") {
|
||||
let token = trimmedToken
|
||||
MicropubTokenStore.save(token)
|
||||
tokenField = ""
|
||||
saved = MicropubTokenStore.read() == token
|
||||
}
|
||||
.buttonStyle(BorderedSecondaryButtonStyle(minHeight: 28))
|
||||
.disabled(trimmedToken.isEmpty)
|
||||
if saved {
|
||||
Button("Remove") {
|
||||
MicropubTokenStore.delete()
|
||||
saved = MicropubTokenStore.read() != nil
|
||||
}
|
||||
.buttonStyle(BorderedSecondaryButtonStyle(minHeight: 28))
|
||||
}
|
||||
}
|
||||
// The standing state, in the Settings verdict idiom (Provider
|
||||
// Keys' "✓ works"). The intro line is a description — a state
|
||||
// swap there never read as a status.
|
||||
status
|
||||
Text("From micro.blog → Account → App Tokens. Stored in your Keychain — the publish sheet sends with this token.")
|
||||
.font(.system(size: 11.5))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
.padding(.top, 2)
|
||||
}
|
||||
}
|
||||
|
||||
/// Live: Save and Remove read the Keychain back, so this line is
|
||||
/// both the confirmation that a write landed and the standing
|
||||
/// answer to "is a token stored?".
|
||||
private var status: some View {
|
||||
Text(saved ? "✓ Token saved in your Keychain" : "No token saved — publishing will ask for one")
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(saved ? DesignTokens.accent : DesignTokens.muted)
|
||||
.padding(.top, 2)
|
||||
}
|
||||
}
|
||||
|
||||
/// The z.ai key-type toggle (prototype `.seg`): a two-segment capsule, the
|
||||
/// selected segment filled with the foreground ink. Toggling swaps the
|
||||
/// endpoint family (the model guards a custom endpoint).
|
||||
|
||||
Reference in new issue
Block a user