initial commit

This commit is contained in:
2026-01-18 21:40:51 +01:00
commit 197a01440c
14 changed files with 374 additions and 0 deletions

48
lib/fetcher.wikijs.go Normal file
View File

@@ -0,0 +1,48 @@
package lib
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type WikiFetcher struct {
Config Config
Cache *Cache
}
func (f WikiFetcher) Fetch() string {
q := `{"query":"{ pages { list(orderBy: UPDATED, orderByDirection: DESC, limit: 1){ updatedAt title }}}"}`
wikiURL := fmt.Sprintf("%s/graphql", f.Config.WikiBaseURL)
req, _ := http.NewRequest("POST", wikiURL, bytes.NewBuffer([]byte(q)))
req.Header.Set("Authorization", "Bearer "+f.Config.WikiToken)
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
return ""
}
defer res.Body.Close()
var r struct {
Data struct {
Pages struct {
List []struct {
UpdatedAt string
Title string
Path string
}
}
}
}
json.NewDecoder(res.Body).Decode(&r)
if len(r.Data.Pages.List) == 0 {
return ""
}
u := r.Data.Pages.List[0]
if f.Cache.TryUpdate("wiki", u.UpdatedAt) {
url := fmt.Sprintf("%s/%s", f.Config.WikiBaseURL, u.Path)
return fmt.Sprintf("Wiki: %s <%s>", u.Title, url)
}
return ""
}