Editor:
- Toggles (Tiptap Details). Open state is per reader, not saved.
- Embeds for YouTube, Vimeo, Loom, Figma, CodePen, Spotify, Google Docs
and Maps, in sandboxed frames. Other addresses become link cards.
- Link cards with title, description and picture read by docwell-server
(GET /link-preview). The fetcher refuses private, loopback, link-local
and CGNAT addresses after DNS resolution, redirects included.
- Block links: a margin button gives a block a short id and copies
/p/<id>#b-<block>. Opening one jumps to the block and flashes it.
- Markdown, HTML and PDF exports handle the new blocks; HTML import reads
<details> as a toggle.
Pages and spaces:
- History gets a Changes view: block and word diff against the previous
version or the page as it is now.
- Archive: archived pages leave the tree and become read-only but stay
readable; a space's Archive lists them with Unarchive. New migration
(pages.archived_at) and page.archived / page.unarchived webhook events.
- Full space export (GET /spaces/{id}/export): a zip of Markdown or HTML
files with subpages in folders, an index, and attachments under _files/.
Links between exported pages and to attachments become relative paths.
Desktop 1.0:
- Several servers, each with its own sign-in; old settings files carry over.
- Session tokens in the system keychain (go-keyring), moved out of
localStorage on first start.
- Native menu bar (File, Edit, View, Window, Help) with a Server submenu.
- docwell:// links may point at a block.
- Release workflow builds Windows NSIS, macOS DMG and Linux deb, rpm and
AppImage installers and attaches them to the release;
build/set-version.mjs stamps the version into their metadata.
Not yet run: the release workflow, the desktop menus by eye, and macOS or
Linux builds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"log/slog"
|
|
|
|
"github.com/zalando/go-keyring"
|
|
)
|
|
|
|
// keychainService names Docwell's entries in the system keychain (Windows
|
|
// Credential Manager, macOS Keychain, the Secret Service on Linux).
|
|
const keychainService = "Docwell"
|
|
|
|
// TokenService keeps each server's sign-in token in the system keychain,
|
|
// so it is not stored in a plain file or the web view's storage. It is
|
|
// bound to the frontend.
|
|
type TokenService struct {
|
|
store tokenStore
|
|
}
|
|
|
|
// tokenStore is the keychain; tests swap it for a map.
|
|
type tokenStore interface {
|
|
Get(service, user string) (string, error)
|
|
Set(service, user, password string) error
|
|
Delete(service, user string) error
|
|
}
|
|
|
|
type systemKeychain struct{}
|
|
|
|
func (systemKeychain) Get(service, user string) (string, error) { return keyring.Get(service, user) }
|
|
func (systemKeychain) Set(service, user, password string) error {
|
|
return keyring.Set(service, user, password)
|
|
}
|
|
func (systemKeychain) Delete(service, user string) error { return keyring.Delete(service, user) }
|
|
|
|
func NewTokenService() *TokenService { return &TokenService{store: systemKeychain{}} }
|
|
|
|
func tokenKey(serverID string) string { return "server:" + serverID }
|
|
|
|
// Get returns the token saved for a server, or "" when there is none. An
|
|
// error means the keychain can't be used (e.g. no Secret Service on a
|
|
// Linux desktop); the frontend then keeps the session in memory only.
|
|
func (t *TokenService) Get(serverID string) (string, error) {
|
|
tok, err := t.store.Get(keychainService, tokenKey(serverID))
|
|
if errors.Is(err, keyring.ErrNotFound) {
|
|
return "", nil
|
|
}
|
|
return tok, err
|
|
}
|
|
|
|
// Set saves a server's token; an empty token deletes it (signing out).
|
|
func (t *TokenService) Set(serverID, token string) error {
|
|
if token == "" {
|
|
return t.Delete(serverID)
|
|
}
|
|
return t.store.Set(keychainService, tokenKey(serverID), token)
|
|
}
|
|
|
|
// Delete removes a server's token. Deleting a missing token is not an error.
|
|
func (t *TokenService) Delete(serverID string) error {
|
|
err := t.store.Delete(keychainService, tokenKey(serverID))
|
|
if errors.Is(err, keyring.ErrNotFound) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
// forget deletes a removed server's token, logging rather than failing.
|
|
func (t *TokenService) forget(serverID string) {
|
|
if err := t.Delete(serverID); err != nil {
|
|
slog.Warn("could not delete token from keychain", "server", serverID, "err", err)
|
|
}
|
|
}
|