- Untrack config.yaml (now gitignored) and add config.example.yaml with blank credentials; install.sh copies the example and sets mode 600 - Reserve room for the appended source link when asking Claude for a post, count length the way X does, and refuse over-length tweets before posting - Return https://x.com/i/status/<id> for posted tweets - Track which platforms each queued post reached so a partial failure can be retried without double-posting - Write config, state, posts and dismissed files atomically with 0600 - Keep refreshed Twitter tokens in memory if saving them fails, and log the failure instead of writing to the hidden stderr - Exit with a clear message on corrupt data files instead of panicking - Surface save errors in the UI; show status/error messages on home - Add tests for X length counting, the post store, and token updates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
830 B
Go
49 lines
830 B
Go
package store
|
|
|
|
import (
|
|
"coremarketing/internal/fileutil"
|
|
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
type DismissedStore struct {
|
|
IDs map[string]bool `json:"ids"`
|
|
path string
|
|
}
|
|
|
|
func LoadDismissed(path string) (*DismissedStore, error) {
|
|
s := &DismissedStore{
|
|
IDs: make(map[string]bool),
|
|
path: path,
|
|
}
|
|
data, err := os.ReadFile(path)
|
|
if os.IsNotExist(err) {
|
|
return s, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := json.Unmarshal(data, s); err != nil {
|
|
return nil, err
|
|
}
|
|
s.path = path
|
|
return s, nil
|
|
}
|
|
|
|
func (s *DismissedStore) Save() error {
|
|
data, err := json.MarshalIndent(s, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return fileutil.WriteFileAtomic(s.path, data, 0600)
|
|
}
|
|
|
|
func (s *DismissedStore) Dismiss(id string) {
|
|
s.IDs[id] = true
|
|
}
|
|
|
|
func (s *DismissedStore) IsDismissed(id string) bool {
|
|
return s.IDs[id]
|
|
}
|