feat(feeds): inherit FreshRSS folders in cached subscription tree
Build and publish container images / images (push) Successful in 10m33s
Build and publish container images / images (push) Successful in 10m33s
This commit is contained in:
1 parent
1057be6d2b
commit
bf9a9c2847
14 files changed
+408
-55
No files matched your search
+23
-8
@@ -72,7 +72,7 @@ API prefixは `/_/api/v1/extension/organizer.feeds/`。Domain内の本人専用
|
||||
| `POST sources/{uuid}/refresh` | 次回背景取得を予約。画面から外部通信しない |
|
||||
| `POST sources/{uuid}/delete` | versionを照合してsource・cache・内蔵read/starを削除 |
|
||||
| `GET items` | source/unread/starred/件名・配信元で絞り込み、100件単位のkeysetページング |
|
||||
| `GET catalog?source=…` | 本人のFreshRSS購読・カテゴリの取得済み一覧。外部通信なし |
|
||||
| `GET catalog?source=…` | 本人のFreshRSS購読・カテゴリの取得済み一覧。`subscriptions`と空フォルダも含む`folders`。外部通信なし |
|
||||
| `GET item?source=…&id=…` | 本人の記事本文 |
|
||||
| `POST state` | 内蔵read/starの条件付き変更。FreshRSSは拒否 |
|
||||
| `POST remote-state` | FreshRSSの一記事・一項目の変更を予約。request_id、source、id、field、desired、source_versionを指定 |
|
||||
@@ -92,7 +92,10 @@ v3で`feed_import_receipts`を追加し、購読の一括追加と再送記録
|
||||
v4でsourceに購読一覧、記事にremote feed ID・カテゴリIDを追加します。FreshRSSの旧workerを
|
||||
versionで無効化し、次の背景取得を予約します。内蔵sourceのversion・取得予約は変更しません。
|
||||
v5でsourceの`write_enabled`(既定OFF)と`feed_actions`を追加します。操作記録はsourceを削除しても保持し、
|
||||
送信済みの可能性があるものはunknown、未送信はcancelledにします。DB更新前にバックアップを取得し、
|
||||
送信済みの可能性があるものはunknown、未送信はcancelledにします。
|
||||
v6でsourceに`remote_folders`を追加します。既存の購読・記事・設定version・取得予約・worker claim・
|
||||
書戻しreceiptは変更しません。初回の背景取得までは既存の購読情報から分類を組み立て、
|
||||
空フォルダは次の取得成功時に追加します。DB更新前にバックアップを取得し、
|
||||
旧バイナリへの切戻しだけで追加schemaが巻き戻るとは扱いません。
|
||||
既存テーブルを破壊・再構成しません。SQLiteのforeign_keys設定に依存せず削除を完遂するtriggerを
|
||||
持ちます。内蔵read/starを本文cacheから分離し、記事を保持窓から落としても状態は黙って消しません。
|
||||
@@ -115,7 +118,7 @@ sourceのprovider・URL・資格情報の変更は別sourceを作る契約です
|
||||
| 内蔵記事cache | 1 source最大500件、text本文32 KiB・HTML本文128 KiB。HTML上限超過はtextへフォールバックし、text切詰めを明示 |
|
||||
| 内蔵read/star | 1 source最大10,000件。上限では新規状態保存を拒否し、既存状態を捨てない |
|
||||
| FreshRSS | reading-list最新200件の窓を取得。更新成功時はその窓で置換し、全履歴同期とはしない |
|
||||
| FreshRSS購読一覧 | 最大1,000購読、1購読64カテゴリ、保存JSON 1 MiB。記事と同じ取得予算で収集 |
|
||||
| FreshRSS購読・分類一覧 | 最大1,000購読・1,000フォルダ、1購読64カテゴリ、保存JSON合計1 MiB。記事と同じ取得予算で収集 |
|
||||
| 再試行 | 次の設定間隔まで待機。手動予約にも最終成功から60秒の制限、取得中の重複claim拒否 |
|
||||
|
||||
内蔵は条件付きGET、304ではcacheを保持します。どちらのproviderも通信・認証・構文失敗で
|
||||
@@ -125,14 +128,25 @@ extension無効化は画面・API・取得・完了保存に適用します。
|
||||
|
||||
### FreshRSSの購読とカテゴリ
|
||||
|
||||
背景取得ではlogin後にreading-listと`subscription/list`を読み、両方に成功した場合だけ
|
||||
記事・購読一覧を同じtransactionで置換します。一方の取得失敗、上限超過、不正なsnapshotでは
|
||||
前回の両cacheを保持します。記事が取得窓内にない購読も一覧には残します。
|
||||
背景取得ではlogin後にreading-list・`subscription/list`・`tag/list`を読み、すべてに成功した場合だけ
|
||||
記事・購読一覧・分類一覧を同じtransactionで置換します。一部の取得失敗、上限超過、不正なsnapshotでは
|
||||
前回のcache全体を保持します。記事が取得窓内にない購読も一覧には残します。
|
||||
`tag/list`は`type=folder`だけを分類として取り込み、記事タグとシステムの状態タグは除外します。
|
||||
購読一覧のカテゴリとIDで統合し、購読元のない空フォルダも保持します。
|
||||
|
||||
左ペインでFreshRSS sourceを選ぶと、接続先→分類フォルダ→購読元のツリーを表示します。
|
||||
フォルダ名は記事の絞り込み、隣の矢印は開閉と役割を分けます。開閉状態は接続先UUID単位で
|
||||
ブラウザのlocalStorageに保存し、利用できない場合もその画面内では保持します。
|
||||
閉じたフォルダは購読元のDOMを作らず、展開時は50件ずつ描画します。購読名・分類名で検索すると
|
||||
該当購読を重複なしで一覧化します。名前に含まれる`/`は文字として扱い、独自の階層には分割しません。
|
||||
|
||||
左ペインでFreshRSS sourceを選ぶとカテゴリ選択・購読名の検索・購読一覧を表示します。
|
||||
カテゴリは表示名でなくremote category ID、購読は`origin.streamId`とsubscription IDを対応させます。
|
||||
同名でも混同せず、複数カテゴリに属する購読も扱います。`GET items`の`feed`/`category`は
|
||||
同名でも混同せず、複数カテゴリに属する購読は各フォルダに表示します。記事の分類絞り込みは
|
||||
記事タグではなく同期した購読元の所属を使い、FreshRSSでの分類移動に追従します。
|
||||
分類のない購読は「未分類」に表示し、購読一覧にない記事を未分類へ混在させません。
|
||||
`GET items`の`feed`/`category`/`category_mode=uncategorized`は
|
||||
source指定と組み合わせ、既存の未読・star・検索・keysetページングと併用できます。
|
||||
`category`と`category_mode`の同時指定は拒否します。
|
||||
絞り込み対象は最新200記事のcache内に限られ、購読を選んでも履歴全件を外部取得しません。
|
||||
購読の追加・削除やカテゴリの編集はFreshRSS側で行います。
|
||||
|
||||
@@ -283,6 +297,7 @@ Wiki単独は親Path配下の `rss-{request UUID}` に新規作成します。
|
||||
- [ ] RSS-5:FreshRSS実環境の接続先・版・API資格情報を指定してread-only受入。
|
||||
- [ ] RSS-6:大規模利用時の公平性、host別並列上限、Retry-After/backoff、資格情報rotation UI。
|
||||
- [x] RSS-7:FreshRSSの購読一覧・カテゴリを使うnavigation。同名ID分離、複数カテゴリ、cache内絞り込み、背景での原子的更新、失敗時保持。
|
||||
- [x] RSS-7b:分類フォルダの継承、空フォルダ・未分類、開閉状態保存、50件ずつの購読描画、分類移動への追従。schema v6の再実行・失敗rollbackと1440px/390pxの合成試験。
|
||||
|
||||
隔離試験はRSS/Atom・FreshRSS login/read、欠落ID・巨大/不正feed、条件付きGET、失敗時cache保持、
|
||||
本人分離・失効・readonly、二重送信・版競合・旧worker拒否、migration再実行/失敗rollback、
|
||||
|
||||
@@ -51,12 +51,12 @@ func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
switch {
|
||||
case key == "catalog" && r.Method == "GET":
|
||||
catalog, e := s.store.FeedCatalog(r.Context(), domain, actor, r.URL.Query().Get("source"))
|
||||
catalog, e := s.store.FeedCatalogSnapshot(r.Context(), domain, actor, r.URL.Query().Get("source"))
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"subscriptions": catalog})
|
||||
writeEventJSON(w, 200, catalog)
|
||||
return
|
||||
case key == "note" && r.Method == "POST":
|
||||
var input struct {
|
||||
@@ -170,7 +170,7 @@ func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
items, e := s.store.FeedItems(r.Context(), domain, actor, q.Get("source"), q.Get("filter"), q.Get("q"), before, q.Get("key"), q.Get("feed"), q.Get("category"))
|
||||
items, e := s.store.FeedItems(r.Context(), domain, actor, q.Get("source"), q.Get("filter"), q.Get("q"), before, q.Get("key"), q.Get("feed"), q.Get("category"), q.Get("category_mode"))
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
|
||||
@@ -49,6 +49,7 @@ func TestFeedCatalogBackgroundSnapshotIsolation(t *testing.T) {
|
||||
}
|
||||
calls := 0
|
||||
failCatalog := false
|
||||
failFolders := false
|
||||
client := &http.Client{Transport: feedTransportFunc(func(r *http.Request) (*http.Response, error) {
|
||||
calls++
|
||||
body := ""
|
||||
@@ -63,7 +64,7 @@ func TestFeedCatalogBackgroundSnapshotIsolation(t *testing.T) {
|
||||
t.Error("article request")
|
||||
}
|
||||
body = `{"items":[{"id":"a","title":"First","origin":{"title":"Same title","streamId":"feed/1"},"categories":["user/alice/label/Tech"]},{"id":"b","title":"Second","origin":{"title":"Same title","streamId":"feed/2"},"categories":["user/alice/label/Other"]}]}`
|
||||
if failCatalog {
|
||||
if failCatalog || failFolders {
|
||||
body = `{"items":[]}`
|
||||
}
|
||||
case strings.HasSuffix(r.URL.Path, "/subscription/list"):
|
||||
@@ -74,6 +75,11 @@ func TestFeedCatalogBackgroundSnapshotIsolation(t *testing.T) {
|
||||
return nil, errors.New("synthetic timeout")
|
||||
}
|
||||
body = testFeedCatalog
|
||||
case strings.HasSuffix(r.URL.Path, "/tag/list"):
|
||||
if failFolders {
|
||||
return nil, errors.New("synthetic folder failure")
|
||||
}
|
||||
body = `{"tags":[{"id":"user/-/label/Empty/Folder","type":"folder"},{"id":"user/-/label/Not a folder","type":"tag"}]}`
|
||||
default:
|
||||
t.Fatalf("unexpected external request %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
@@ -89,7 +95,7 @@ func TestFeedCatalogBackgroundSnapshotIsolation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
run()
|
||||
if calls != 3 {
|
||||
if calls != 4 {
|
||||
t.Fatal("fetch count", calls)
|
||||
}
|
||||
w := feedRequestTest(s, token, "GET", "catalog?source="+v.UUID, nil)
|
||||
@@ -127,9 +133,16 @@ func TestFeedCatalogBackgroundSnapshotIsolation(t *testing.T) {
|
||||
if _, e := s.store.FeedCatalog(ctx, uuid.NewString(), actor, v.UUID); e == nil {
|
||||
t.Fatal("cross-domain catalog leak")
|
||||
}
|
||||
if calls != 3 {
|
||||
if calls != 4 {
|
||||
t.Fatal("foreground external request")
|
||||
}
|
||||
failFolders = true
|
||||
run()
|
||||
kept, e := s.store.FeedCatalogSnapshot(ctx, domain, actor, v.UUID)
|
||||
if e != nil || len(kept.Folders) != 3 || len(kept.Subscriptions) != 3 {
|
||||
t.Fatal("folder failure erased snapshot", kept, e)
|
||||
}
|
||||
failFolders = false
|
||||
failCatalog = true
|
||||
run()
|
||||
catalog, e := s.store.FeedCatalog(ctx, domain, actor, v.UUID)
|
||||
|
||||
@@ -345,7 +345,7 @@ func freshRSSLogin(ctx context.Context, client *http.Client, v store.FeedSource,
|
||||
}
|
||||
return auth, nil
|
||||
}
|
||||
func fetchFreshRSS(ctx context.Context, client *http.Client, v store.FeedSource, user, password string, catalogs ...*[]store.FeedRemoteSubscription) ([]store.FeedItem, error) {
|
||||
func fetchFreshRSS(ctx context.Context, client *http.Client, v store.FeedSource, user, password string, catalogs ...*store.FeedCatalogSnapshot) ([]store.FeedItem, error) {
|
||||
base := strings.TrimRight(v.URL, "/")
|
||||
auth, e := freshRSSLogin(ctx, client, v, user, password)
|
||||
if e != nil {
|
||||
@@ -368,7 +368,23 @@ func fetchFreshRSS(ctx context.Context, client *http.Client, v store.FeedSource,
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
*catalogs[0] = catalog
|
||||
raw, _, _, e = feedRequest(ctx, client, "GET", base+"/reader/api/0/tag/list?output=json", auth, nil, nil)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
folders, e := parseFreshRSSFolders(raw)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
folders, e = store.FeedFolders(catalog, folders)
|
||||
if e != nil {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
snapshot := store.FeedCatalogSnapshot{Subscriptions: catalog, Folders: folders}
|
||||
if _, _, e = snapshot.Encode(); e != nil {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
*catalogs[0] = snapshot
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -504,7 +520,7 @@ func (s *Server) syncFeedSourcesWithClient(ctx context.Context, job *store.Event
|
||||
}
|
||||
child, stop := context.WithTimeout(ctx, 8*time.Second)
|
||||
var items []store.FeedItem
|
||||
var catalog []store.FeedRemoteSubscription
|
||||
var catalog store.FeedCatalogSnapshot
|
||||
etag, modified := v.ETag, v.Modified
|
||||
unchanged := false
|
||||
if !validCalendarSourceURL(v.URL) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func parseFreshRSSFolders(raw []byte) ([]store.FeedCategory, error) {
|
||||
if len(raw) > 4<<20 || !utf8.Valid(raw) {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
var response struct {
|
||||
Tags []struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
} `json:"tags"`
|
||||
}
|
||||
if json.Unmarshal(raw, &response) != nil || response.Tags == nil || len(response.Tags) > 10000 {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
folders := []store.FeedCategory{}
|
||||
seen := map[string]bool{}
|
||||
for _, tag := range response.Tags {
|
||||
// Article tags and system state tags are not subscription folders.
|
||||
if tag.Type != "folder" {
|
||||
continue
|
||||
}
|
||||
prefix, label, ok := strings.Cut(tag.ID, "/label/")
|
||||
if !ok || !strings.HasPrefix(prefix, "user/") || len(prefix) <= 5 || label == "" || !store.ValidFeedRemoteID(tag.ID) || seen[tag.ID] {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
seen[tag.ID] = true
|
||||
folders = append(folders, store.FeedCategory{ID: tag.ID, Label: feedText(label, 512)})
|
||||
}
|
||||
if _, e := store.FeedFolders(nil, folders); e != nil {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
return folders, nil
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func TestFreshRSSFoldersParsing(t *testing.T) {
|
||||
folders, e := parseFreshRSSFolders([]byte(`{"tags":[{"id":"user/-/state/com.google/starred"},{"id":"user/-/label/ArticleTag","type":"tag"},{"id":"user/-/label/技術/Linux","type":"folder"}]}`))
|
||||
if e != nil || len(folders) != 1 || folders[0].Label != "技術/Linux" {
|
||||
t.Fatal(folders, e)
|
||||
}
|
||||
for _, raw := range []string{`{}`, `{"tags":null}`, `{"tags":[{"id":"invalid","type":"folder"}]}`, `{"tags":[{"id":"user/-/label/","type":"folder"}]}`, `{"tags":[{"id":"user/-/label/A","type":"folder"},{"id":"user/-/label/A","type":"folder"}]}`} {
|
||||
if _, e = parseFreshRSSFolders([]byte(raw)); e == nil {
|
||||
t.Fatal("invalid folder accepted", raw)
|
||||
}
|
||||
}
|
||||
tags := []map[string]string{}
|
||||
for i := 0; i < 1001; i++ {
|
||||
tags = append(tags, map[string]string{"id": fmt.Sprintf("user/-/label/%d", i), "type": "folder"})
|
||||
}
|
||||
raw, _ := json.Marshal(map[string]any{"tags": tags})
|
||||
if _, e = parseFreshRSSFolders(raw); e == nil {
|
||||
t.Fatal("unbounded folders")
|
||||
}
|
||||
if _, e = store.FeedFolders([]store.FeedRemoteSubscription{{ID: "feed/1", Categories: []store.FeedCategory{{ID: "cat", Label: "A"}}}}, []store.FeedCategory{{ID: "cat", Label: "B"}}); e == nil {
|
||||
t.Fatal("conflicting labels")
|
||||
}
|
||||
large := store.FeedCatalogSnapshot{}
|
||||
for i := 0; i < 1000; i++ {
|
||||
large.Subscriptions = append(large.Subscriptions, store.FeedRemoteSubscription{ID: fmt.Sprintf("feed/%d", i), Title: strings.Repeat("s", 512)})
|
||||
large.Folders = append(large.Folders, store.FeedCategory{ID: fmt.Sprintf("user/-/label/%d", i), Label: strings.Repeat("f", 512)})
|
||||
}
|
||||
if _, e := store.FeedCatalogJSON(large.Subscriptions); e != nil {
|
||||
t.Fatal("catalog alone should fit", e)
|
||||
}
|
||||
if _, _, e := large.Encode(); e != store.ErrTaskDAVLimit {
|
||||
t.Fatal("combined snapshot limit", e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedFolderMembershipAndUncategorized(t *testing.T) {
|
||||
s, token, domain, actor, source := feedActionFixture(t)
|
||||
ctx := context.Background()
|
||||
if _, e := s.store.DB.Exec(`UPDATE feed_sources SET next_ms=0 WHERE uuid=?`, source.UUID); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
sources, e := s.store.FeedSources(ctx, domain, actor)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, v := range sources {
|
||||
if v.UUID == source.UUID {
|
||||
source = v
|
||||
}
|
||||
}
|
||||
claim, e := s.store.ClaimFeed(ctx, source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
cat := store.FeedCategory{ID: "user/-/label/New/Folder", Label: "New/Folder"}
|
||||
snapshot := store.FeedCatalogSnapshot{Subscriptions: []store.FeedRemoteSubscription{{ID: "feed/1", Title: "Moved", Categories: []store.FeedCategory{cat}}, {ID: "feed/2", Title: "Unclassified", Categories: []store.FeedCategory{}}}, Folders: []store.FeedCategory{{ID: "user/-/label/Empty", Label: "Empty"}}}
|
||||
items := []store.FeedItem{{ID: "a", Title: "Moved", RemoteFeed: "feed/1", RemoteCategories: []string{"user/-/label/Old"}}, {ID: "b", Title: "Unclassified", RemoteFeed: "feed/2", RemoteCategories: []string{"user/-/label/ArticleTag"}}, {ID: "c", Title: "Unknown subscription", RemoteFeed: "feed/unknown"}}
|
||||
if e = s.store.CompleteFeed(ctx, claim, items, "", "", "", false, snapshot); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, test := range []struct {
|
||||
query string
|
||||
want string
|
||||
}{{"category=" + url.QueryEscape(cat.ID), "a"}, {"category_mode=uncategorized", "b"}, {"category=user%2F-%2Flabel%2FOld", ""}, {"category=user%2F-%2Flabel%2FEmpty", ""}} {
|
||||
w := feedRequestTest(s, token, "GET", "items?source="+source.UUID+"&"+test.query, nil)
|
||||
var data struct {
|
||||
Items []store.FeedItem `json:"items"`
|
||||
}
|
||||
json.Unmarshal(w.Body.Bytes(), &data)
|
||||
if w.Code != 200 || (test.want == "" && len(data.Items) != 0) || (test.want != "" && (len(data.Items) != 1 || data.Items[0].ID != test.want)) {
|
||||
t.Fatal(test.query, w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
for _, query := range []string{"category_mode=uncategorized", "source=" + source.UUID + "&category_mode=bad", "source=" + source.UUID + "&category_mode=uncategorized&category=" + url.QueryEscape(cat.ID)} {
|
||||
if w := feedRequestTest(s, token, "GET", "items?"+query, nil); w.Code != 422 {
|
||||
t.Fatal(query, w.Code)
|
||||
}
|
||||
}
|
||||
got, e := s.store.FeedCatalogSnapshot(ctx, domain, actor, source.UUID)
|
||||
if e != nil || len(got.Folders) != 2 {
|
||||
t.Fatal(got, e)
|
||||
}
|
||||
}
|
||||
@@ -569,7 +569,7 @@ func TestFeedsChromium(t *testing.T) {
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.store.CompleteFeed(context.Background(), claim, []store.FeedItem{{ID: "catalog-a", Title: "Catalog first", RemoteFeed: "feed/1", RemoteCategories: []string{"user/alice/label/Tech"}}, {ID: "catalog-b", Title: "Catalog second", RemoteFeed: "feed/2", RemoteCategories: []string{"user/alice/label/Other"}}}, "", "", "", false, catalog); e != nil {
|
||||
if e = s.store.CompleteFeed(context.Background(), claim, []store.FeedItem{{ID: "catalog-a", Title: "Catalog first", RemoteFeed: "feed/1", RemoteCategories: []string{"user/alice/label/Tech"}}, {ID: "catalog-b", Title: "Catalog second", RemoteFeed: "feed/2", RemoteCategories: []string{"user/alice/label/Other"}}}, "", "", "", false, store.FeedCatalogSnapshot{Subscriptions: catalog, Folders: []store.FeedCategory{{ID: "user/-/label/Empty/Folder", Label: "Empty/Folder"}}}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
s.store.BackgroundJobsDisabled = true
|
||||
|
||||
Vendored
+13
-5
@@ -4,6 +4,7 @@
|
||||
const frame=document.createElement('iframe');frame.style='display:block;width:100%;height:100vh;border:0';document.body.append(frame);
|
||||
try{
|
||||
await new Promise(resolve=>{frame.onload=resolve;frame.src='/v/feeds';});const d=frame.contentDocument,w=frame.contentWindow;
|
||||
for(const key of Object.keys(w.localStorage))if(key.startsWith('pageswiki.feed-folders.v1:'))w.localStorage.removeItem(key);
|
||||
await wait(()=>d.querySelectorAll('.feed-row').length===100);
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Viewport overflow');
|
||||
assert(d.title.startsWith('RSS ·'),'RSS title');assert(d.getElementById('feed-status').textContent==='','Unrequested status copy');assert(w.getComputedStyle(d.getElementById('feed-status')).display==='none','Empty status takes space');
|
||||
@@ -27,10 +28,15 @@
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'OPML overflow');d.querySelector('.feed-import-options input[type=checkbox]').checked=false;d.getElementById('feed-opml-preview').requestSubmit();await wait(()=>!d.getElementById('feed-opml-preview'));
|
||||
assert(d.getElementById('feed-sources').textContent.includes('Import '+w.innerWidth),'Imported source missing');d.getElementById('feed-opml').click();await wait(()=>d.getElementById('feed-opml-file'));choose();await wait(()=>d.querySelectorAll('#feed-opml-preview tbody tr').length===3);assert(d.querySelector('#feed-opml-preview tbody input').disabled,'Duplicate after import');
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'OPML preview overflow');
|
||||
[...d.querySelectorAll('.feed-source>button:first-child')].find(b=>b.textContent==='FreshRSS fixture').click();await wait(()=>d.querySelectorAll('.feed-subscriptions button').length===4&&d.querySelectorAll('.feed-row').length===2);
|
||||
const category=d.getElementById('feed-category');category.value='user/alice/label/Tech';category.dispatchEvent(new w.Event('change'));await wait(()=>d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog first'));
|
||||
assert(d.querySelectorAll('.feed-subscriptions button').length===2,'Category navigation');
|
||||
d.getElementById('feed-category').value='';d.getElementById('feed-category').dispatchEvent(new w.Event('change'));await wait(()=>d.querySelectorAll('.feed-row').length===2);
|
||||
const freshButton=()=>[...d.querySelectorAll('.feed-source>button:first-child')].find(b=>b.textContent==='FreshRSS fixture');freshButton().click();await wait(()=>d.querySelectorAll('.feed-folder').length===4&&d.querySelectorAll('.feed-row').length===2);
|
||||
const folder=id=>[...d.querySelectorAll('.feed-folder')].find(n=>n.dataset.category===id),tech=()=>folder('user/alice/label/Tech');
|
||||
tech().querySelector('.feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog first'));
|
||||
assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false','Selecting folder expands it unexpectedly');tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('button[data-feed="feed/1"]'));
|
||||
const empty=folder('user/-/label/Empty/Folder');assert(empty.querySelector('.feed-folder-name span').textContent==='Empty/Folder','Slash label split');empty.querySelector('.feed-folder-toggle').click();assert(!empty.querySelector('button[data-feed]'),'Empty folder fabricated a feed');empty.querySelector('.feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===0);
|
||||
d.querySelector('.feed-folder[data-mode="uncategorized"] .feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===0);
|
||||
d.querySelector('.feed-catalog .feed-tree-all').click();await wait(()=>d.querySelectorAll('.feed-row').length===2);
|
||||
[...d.querySelectorAll('.feed-source>button:first-child')].find(b=>b.textContent==='Synthetic news').click();await wait(()=>!d.querySelector('.feed-catalog'));freshButton().click();await wait(()=>tech()?.querySelector('button[data-feed="feed/1"]'));assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='true','Folder expansion not retained');
|
||||
folder('user/alice/label/Other').querySelector('.feed-folder-toggle').click();await wait(()=>d.querySelector('.feed-subscriptions button[data-feed="feed/2"]'));
|
||||
d.querySelector('.feed-subscriptions button[data-feed="feed/2"]').click();await wait(()=>d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog second'));
|
||||
d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));assert(d.querySelectorAll('#feed-reader .feed-actions button:disabled').length===2,'FreshRSS not read-only');
|
||||
[...d.querySelectorAll('.feed-source')].find(n=>n.textContent.includes('FreshRSS fixture')).querySelector('button:last-child').click();await wait(()=>d.querySelector('#feed-reader form'));
|
||||
@@ -52,6 +58,8 @@
|
||||
const hs=d.getElementById('feed-history-state');hs.value='all';hs.dispatchEvent(new w.Event('change'));await wait(()=>receipt(seed.missing)?.querySelector('[data-state=confirmed]'));
|
||||
d.dispatchEvent(new w.KeyboardEvent('keydown',{key:'Escape',bubbles:true}));assert(!d.querySelector('.feed-layout').classList.contains('action-history'),'History escape');
|
||||
d.getElementById('feed-history').click();await wait(()=>receipt(seed.orphan));d.getElementById('feed-history-state').value='all';d.getElementById('feed-history-state').dispatchEvent(new w.Event('change'));await wait(()=>receipt(seed.missing)?.querySelector('[data-state=confirmed]'));
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'History final overflow');document.body.dataset.vimReady='1';
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'History final overflow');
|
||||
const probe=document.createElement('iframe');probe.hidden=true;document.body.append(probe);await new Promise(resolve=>{probe.onload=resolve;probe.src='/v/feeds?source='+encodeURIComponent(source.uuid);});await wait(()=>probe.contentDocument.querySelector('.feed-folder[data-category="user/alice/label/Tech"] .feed-folder-toggle')?.getAttribute('aria-expanded')==='true');probe.remove();
|
||||
freshButton().click();await wait(()=>tech()?.querySelector('button[data-feed="feed/1"]'));if(w.innerWidth<=700){d.querySelector('#feed-toolbar button').click();await wait(()=>d.querySelector('.feed-layout').classList.contains('sources-open'));assert(w.getComputedStyle(d.getElementById('feed-sources')).display!=='none','Mobile folders hidden');}assert(d.documentElement.scrollWidth<=w.innerWidth,'Folder tree overflow');document.body.dataset.vimReady='1';
|
||||
}catch(e){const out=document.createElement('pre');out.id='error';out.textContent=e.stack;document.body.append(out);}
|
||||
})();
|
||||
+36
-6
@@ -54,6 +54,10 @@ var feedMigrations = []db.SQLMigration{{Version: 1, Name: "private_feed_reader",
|
||||
`CREATE TRIGGER feed_actions_source_change AFTER UPDATE OF version ON feed_sources BEGIN UPDATE feed_actions SET status=CASE WHEN status IN ('sending','unknown','check_queued','checking') THEN 'unknown' ELSE 'cancelled' END,error='source_changed' WHERE source_uuid=old.uuid AND status IN ('queued','preparing','sending','unknown','check_queued','checking'); END`,
|
||||
`CREATE TRIGGER feed_actions_source_delete AFTER DELETE ON feed_sources BEGIN UPDATE feed_actions SET status=CASE WHEN status IN ('sending','unknown','check_queued','checking') THEN 'unknown' ELSE 'cancelled' END,error='source_deleted' WHERE source_uuid=old.uuid AND status IN ('queued','preparing','sending','unknown','check_queued','checking'); END`,
|
||||
}, Assertions: []string{schemaColumns("feed_sources", "write_enabled"), schemaUnique("feed_actions", "domain_uuid,owner_uuid,request_id")},
|
||||
}, {
|
||||
Version: 6, Name: "freshrss_empty_folders", Statements: []string{
|
||||
`ALTER TABLE feed_sources ADD COLUMN remote_folders TEXT NOT NULL DEFAULT '[]'`,
|
||||
}, Assertions: []string{schemaColumns("feed_sources", "remote_folders")},
|
||||
}}
|
||||
|
||||
// CaptureFeedNote creates an inert Wiki note and receipt atomically. It does not
|
||||
@@ -330,7 +334,7 @@ func (s *Store) FeedSourceAction(ctx context.Context, domain, owner, id, action
|
||||
}
|
||||
func (s *Store) FeedItems(ctx context.Context, domain, owner, source, filter, query string, before int64, beforeID string, scope ...string) ([]FeedItem, error) {
|
||||
remoteFeed, category := "", ""
|
||||
if len(scope) > 2 {
|
||||
if len(scope) > 3 {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
if len(scope) > 0 {
|
||||
@@ -339,6 +343,13 @@ func (s *Store) FeedItems(ctx context.Context, domain, owner, source, filter, qu
|
||||
if len(scope) > 1 {
|
||||
category = scope[1]
|
||||
}
|
||||
mode := ""
|
||||
if len(scope) > 2 {
|
||||
mode = scope[2]
|
||||
}
|
||||
if mode != "" && (mode != "uncategorized" || source == "" || category != "") {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
if (remoteFeed != "" && !ValidFeedRemoteID(remoteFeed)) || (category != "" && !ValidFeedRemoteID(category)) || ((remoteFeed != "" || category != "") && source == "") {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
@@ -348,7 +359,14 @@ func (s *Store) FeedItems(ctx context.Context, domain, owner, source, filter, qu
|
||||
if e := feedActor(ctx, s.DB, domain, owner, false); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
rows, e := s.DB.QueryContext(ctx, `SELECT i.source_uuid,i.id,i.title,i.url,i.published_ms,i.feed,CASE WHEN s.folder<>'' THEN s.folder ELSE i.folder END,CASE WHEN s.provider='local' THEN COALESCE(t.is_read,0) ELSE i.is_read END,CASE WHEN s.provider='local' THEN COALESCE(t.starred,0) ELSE i.starred END,COALESCE(t.version,0),s.provider FROM feed_items i JOIN feed_sources s ON s.uuid=i.source_uuid LEFT JOIN feed_states t ON t.source_uuid=i.source_uuid AND t.id=i.id WHERE s.domain_uuid=? AND s.owner_uuid=? AND (?='' OR s.uuid=?) AND (?='' OR instr(lower(i.title),lower(?))>0 OR instr(lower(i.feed),lower(?))>0) AND (?<0 OR i.published_ms<? OR (i.published_ms=? AND (i.source_uuid||':'||i.id)<?)) AND (?<>'unread' OR (CASE WHEN s.provider='local' THEN COALESCE(t.is_read,0) ELSE i.is_read END)=0) AND (?<>'starred' OR (CASE WHEN s.provider='local' THEN COALESCE(t.starred,0) ELSE i.starred END)=1) AND (?='' OR i.remote_feed=?) AND (?='' OR EXISTS(SELECT 1 FROM json_each(i.remote_categories) WHERE value=?)) ORDER BY i.published_ms DESC,i.source_uuid||':'||i.id DESC LIMIT 101`, domain, owner, source, source, query, query, query, before, before, before, beforeID, filter, filter, remoteFeed, remoteFeed, category, category)
|
||||
args := []any{domain, owner, source, source, query, query, query, before, before, before, beforeID, filter, filter, remoteFeed, remoteFeed, category, category}
|
||||
extra := ""
|
||||
if mode == "uncategorized" {
|
||||
// The uncorrelated list is built once, not a catalog scan per article.
|
||||
extra = ` AND i.remote_feed IN (SELECT json_extract(c.value,'$.id') FROM feed_sources cs,json_each(cs.remote_catalog) c WHERE cs.uuid=? AND cs.domain_uuid=? AND cs.owner_uuid=? AND json_array_length(c.value,'$.categories')=0)`
|
||||
args = append(args, source, domain, owner)
|
||||
}
|
||||
rows, e := s.DB.QueryContext(ctx, `SELECT i.source_uuid,i.id,i.title,i.url,i.published_ms,i.feed,CASE WHEN s.folder<>'' THEN s.folder ELSE i.folder END,CASE WHEN s.provider='local' THEN COALESCE(t.is_read,0) ELSE i.is_read END,CASE WHEN s.provider='local' THEN COALESCE(t.starred,0) ELSE i.starred END,COALESCE(t.version,0),s.provider FROM feed_items i JOIN feed_sources s ON s.uuid=i.source_uuid LEFT JOIN feed_states t ON t.source_uuid=i.source_uuid AND t.id=i.id WHERE s.domain_uuid=? AND s.owner_uuid=? AND (?='' OR s.uuid=?) AND (?='' OR instr(lower(i.title),lower(?))>0 OR instr(lower(i.feed),lower(?))>0) AND (?<0 OR i.published_ms<? OR (i.published_ms=? AND (i.source_uuid||':'||i.id)<?)) AND (?<>'unread' OR (CASE WHEN s.provider='local' THEN COALESCE(t.is_read,0) ELSE i.is_read END)=0) AND (?<>'starred' OR (CASE WHEN s.provider='local' THEN COALESCE(t.starred,0) ELSE i.starred END)=1) AND (?='' OR i.remote_feed=?) AND (?='' OR EXISTS(SELECT 1 FROM json_each(i.remote_categories) WHERE value=?))`+extra+` ORDER BY i.published_ms DESC,i.source_uuid||':'||i.id DESC LIMIT 101`, args...)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
@@ -465,17 +483,29 @@ func (s *Store) ClaimFeed(ctx context.Context, v FeedSource) (FeedSource, error)
|
||||
}
|
||||
|
||||
// Failed fetches preserve the previous cache. Version and claim token fence stale workers.
|
||||
func (s *Store) CompleteFeed(ctx context.Context, v FeedSource, items []FeedItem, etag, modified, code string, unchanged bool, catalogs ...[]FeedRemoteSubscription) error {
|
||||
func (s *Store) CompleteFeed(ctx context.Context, v FeedSource, items []FeedItem, etag, modified, code string, unchanged bool, catalogs ...FeedCatalogSnapshot) error {
|
||||
if len(catalogs) > 1 {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
var catalog string
|
||||
var catalog, folders string
|
||||
if len(catalogs) == 1 {
|
||||
var e error
|
||||
catalog, e = FeedCatalogJSON(catalogs[0])
|
||||
catalog, folders, e = catalogs[0].Encode()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if v.Provider == "freshrss" {
|
||||
membership := map[string][]string{}
|
||||
for _, sub := range catalogs[0].Subscriptions {
|
||||
for _, c := range sub.Categories {
|
||||
membership[sub.ID] = append(membership[sub.ID], c.ID)
|
||||
}
|
||||
}
|
||||
items = append([]FeedItem(nil), items...)
|
||||
for n := range items {
|
||||
items[n].RemoteCategories = membership[items[n].RemoteFeed]
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(items) > 500 || len(etag) > 1024 || len(modified) > 1024 {
|
||||
return ErrTaskInvalid
|
||||
@@ -511,7 +541,7 @@ func (s *Store) CompleteFeed(ctx context.Context, v FeedSource, items []FeedItem
|
||||
return nil
|
||||
}
|
||||
if catalog != "" {
|
||||
if _, e = tx.ExecContext(ctx, `UPDATE feed_sources SET remote_catalog=? WHERE uuid=?`, catalog, v.UUID); e != nil {
|
||||
if _, e = tx.ExecContext(ctx, `UPDATE feed_sources SET remote_catalog=?,remote_folders=? WHERE uuid=?`, catalog, folders, v.UUID); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,51 @@ type FeedRemoteSubscription struct {
|
||||
Categories []FeedCategory `json:"categories"`
|
||||
}
|
||||
|
||||
type FeedCatalogSnapshot struct {
|
||||
Subscriptions []FeedRemoteSubscription `json:"subscriptions"`
|
||||
Folders []FeedCategory `json:"folders"`
|
||||
}
|
||||
|
||||
// Merge membership-derived folders with explicit folders, including empty
|
||||
// ones. IDs, not labels or slash-delimited paths, are the identity boundary.
|
||||
func FeedFolders(catalog []FeedRemoteSubscription, folders []FeedCategory) ([]FeedCategory, error) {
|
||||
out := []FeedCategory{}
|
||||
seen := map[string]string{}
|
||||
add := func(c FeedCategory) error {
|
||||
if !ValidFeedRemoteID(c.ID) || len(c.Label) > 512 || !utf8.ValidString(c.Label) {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
if label, ok := seen[c.ID]; ok {
|
||||
if label != c.Label {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
return nil
|
||||
}
|
||||
seen[c.ID] = c.Label
|
||||
out = append(out, c)
|
||||
if len(out) > 1000 {
|
||||
return ErrTaskDAVLimit
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if len(folders) > 1000 {
|
||||
return nil, ErrTaskDAVLimit
|
||||
}
|
||||
for _, c := range folders {
|
||||
if e := add(c); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
}
|
||||
for _, sub := range catalog {
|
||||
for _, c := range sub.Categories {
|
||||
if e := add(c); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func ValidFeedRemoteID(id string) bool {
|
||||
return id != "" && len(id) <= 2048 && utf8.ValidString(id) && !strings.ContainsAny(id, "\x00\r\n")
|
||||
}
|
||||
@@ -59,17 +104,47 @@ func FeedCatalogJSON(catalog []FeedRemoteSubscription) (string, error) {
|
||||
return string(raw), nil
|
||||
}
|
||||
|
||||
func (s *Store) FeedCatalog(ctx context.Context, domain, owner, source string) ([]FeedRemoteSubscription, error) {
|
||||
if e := feedActor(ctx, s.DB, domain, owner, false); e != nil {
|
||||
return nil, e
|
||||
// Validate the complete snapshot before persisting or reporting fetch success.
|
||||
func (v FeedCatalogSnapshot) Encode() (string, string, error) {
|
||||
catalog, e := FeedCatalogJSON(v.Subscriptions)
|
||||
if e != nil {
|
||||
return "", "", e
|
||||
}
|
||||
var raw string
|
||||
if e := s.DB.QueryRowContext(ctx, `SELECT remote_catalog FROM feed_sources WHERE uuid=? AND domain_uuid=? AND owner_uuid=?`, source, domain, owner).Scan(&raw); e != nil {
|
||||
return nil, e
|
||||
folders, e := FeedFolders(v.Subscriptions, v.Folders)
|
||||
if e != nil {
|
||||
return "", "", e
|
||||
}
|
||||
var catalog []FeedRemoteSubscription
|
||||
if e := json.Unmarshal([]byte(raw), &catalog); e != nil {
|
||||
return nil, e
|
||||
raw, e := json.Marshal(folders)
|
||||
if e != nil {
|
||||
return "", "", e
|
||||
}
|
||||
return catalog, nil
|
||||
if len(raw)+len(catalog) > 1<<20 {
|
||||
return "", "", ErrTaskDAVLimit
|
||||
}
|
||||
return catalog, string(raw), nil
|
||||
}
|
||||
|
||||
func (s *Store) FeedCatalog(ctx context.Context, domain, owner, source string) ([]FeedRemoteSubscription, error) {
|
||||
v, e := s.FeedCatalogSnapshot(ctx, domain, owner, source)
|
||||
return v.Subscriptions, e
|
||||
}
|
||||
|
||||
func (s *Store) FeedCatalogSnapshot(ctx context.Context, domain, owner, source string) (FeedCatalogSnapshot, error) {
|
||||
v := FeedCatalogSnapshot{}
|
||||
if e := feedActor(ctx, s.DB, domain, owner, false); e != nil {
|
||||
return v, e
|
||||
}
|
||||
var raw, folders string
|
||||
if e := s.DB.QueryRowContext(ctx, `SELECT remote_catalog,remote_folders FROM feed_sources WHERE uuid=? AND domain_uuid=? AND owner_uuid=?`, source, domain, owner).Scan(&raw, &folders); e != nil {
|
||||
return v, e
|
||||
}
|
||||
if e := json.Unmarshal([]byte(raw), &v.Subscriptions); e != nil {
|
||||
return v, e
|
||||
}
|
||||
if e := json.Unmarshal([]byte(folders), &v.Folders); e != nil {
|
||||
return v, e
|
||||
}
|
||||
var e error
|
||||
v.Folders, e = FeedFolders(v.Subscriptions, v.Folders)
|
||||
return v, e
|
||||
}
|
||||
@@ -188,3 +188,41 @@ func TestFeedActionsMigrationRollbackAndRepeat(t *testing.T) {
|
||||
t.Fatal(status, e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedFoldersMigrationRollbackAndRepeat(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if e := db.ApplySQLiteMigrations(ctx, st.DB, "feeds", feedMigrations[:5]); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
const catalog = `[{"id":"feed/1","title":"Title","categories":[{"id":"category","label":"Folder"}]}]`
|
||||
if _, e := st.DB.Exec(`INSERT INTO feed_sources(uuid,domain_uuid,owner_uuid,provider,title,folder,url,version,enabled,interval_seconds,lease,next_ms,remote_catalog) VALUES('s','d','u','freshrss','Title','','https://example.org',7,1,300,'worker',999,?);
|
||||
INSERT INTO feed_actions(domain_uuid,owner_uuid,request_id,source_uuid,item_id,field,desired,source_version,status,created_ms) VALUES('d','u','r','s','i','read',1,7,'queued',1)`, catalog); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
broken := append([]db.SQLMigration(nil), feedMigrations...)
|
||||
broken[5].Statements = append(append([]string(nil), feedMigrations[5].Statements...), `INSERT INTO no_such_feed_table VALUES(1)`)
|
||||
if e := db.ApplySQLiteMigrations(ctx, st.DB, "feeds", broken); e == nil {
|
||||
t.Fatal("expected failure")
|
||||
}
|
||||
var count int
|
||||
if e := st.DB.QueryRow(`SELECT count(*) FROM pragma_table_info('feed_sources') WHERE name='remote_folders'`).Scan(&count); e != nil || count != 0 {
|
||||
t.Fatal("partial schema", count, e)
|
||||
}
|
||||
for range 2 {
|
||||
if e := st.ensureSchemaComponent("feeds"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
var version, next int
|
||||
var got, folders, lease, status string
|
||||
if e := st.DB.QueryRow(`SELECT version,next_ms,lease,remote_catalog,remote_folders FROM feed_sources WHERE uuid='s'`).Scan(&version, &next, &lease, &got, &folders); e != nil || version != 7 || next != 999 || lease != "worker" || got != catalog || folders != "[]" {
|
||||
t.Fatal("existing state changed", version, next, lease, got, folders, e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT status FROM feed_actions WHERE request_id='r'`).Scan(&status); e != nil || status != "queued" {
|
||||
t.Fatal("pending action changed", status, e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`PRAGMA integrity_check`).Scan(&status); e != nil || status != "ok" {
|
||||
t.Fatal(status, e)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
.feeds-page{height:100dvh;overflow:hidden;display:flex;flex-direction:column;background:var(--bg);color:var(--fg)}
|
||||
.feed-folder-row{display:flex;align-items:center;min-width:0}#feeds-app .feed-folder-toggle{flex:0 0 1.7rem;border:0;padding:.15rem;min-width:1.7rem}#feeds-app .feed-folder-name{display:flex;align-items:center;gap:.3rem;flex:1;min-width:0;text-align:left;border:0;font-size:.78rem;padding:.2rem}.feed-folder-name span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.feed-folder-name svg{width:1rem;height:1rem;flex-shrink:0;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linejoin:round}.feed-folder>.feed-subscriptions{padding-left:1.1rem;border-left:1px solid var(--border,#8885);margin-left:.8rem}.feed-catalog .feed-subscriptions[hidden]{display:none}.feed-folder small{font-size:.7rem;opacity:.7;padding:.3rem}.feed-catalog button[aria-current=true]{background:color-mix(in srgb,var(--accent,#659de4) 22%,transparent)!important}.feed-tree-all{width:100%;text-align:left}.feed-folders{min-width:0}
|
||||
.feed-layout.action-history{grid-template-columns:12rem minmax(0,1fr)}.feed-layout.action-history .feed-index{display:none}.feed-layout.action-history #feed-reader{display:block}.feed-history-controls{display:flex;gap:.3rem;flex-wrap:wrap;margin:.4rem 0}.feed-history-controls select{max-width:100%}.feed-history table{width:100%;table-layout:fixed;border-collapse:collapse;font-size:.8rem}.feed-history th,.feed-history td{padding:.3rem .4rem;text-align:left;border-bottom:1px solid var(--border,#8885);vertical-align:middle;overflow-wrap:anywhere}.feed-history th:first-child{width:7.5rem}.feed-history th:nth-child(3){width:6rem}.feed-history th:last-child{width:7rem}.feed-history td:nth-child(2)>span,.feed-history small{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.feed-history small{font-size:.72rem;opacity:.7}.feed-history-buttons{display:flex;gap:.2rem;justify-content:flex-end}.feed-history-buttons a{display:inline-flex;align-items:center;justify-content:center;min-width:1.8rem;min-height:1.8rem;border:1px solid var(--border,#6666);border-radius:.2rem;text-decoration:none}.feed-history [data-state=unknown],.feed-history [data-state=conflict],.feed-history [data-state=failed]{color:var(--danger,#e57a7a)}.feed-history .feed-warning:empty{display:none}
|
||||
@media(max-width:1100px){.feed-layout.action-history{grid-template-columns:10rem minmax(0,1fr)}}
|
||||
@media(max-width:600px){.feed-history thead{display:none}.feed-history tbody,.feed-history tr{display:block}.feed-history tr{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:.15rem .3rem;padding:.5rem 0;border-bottom:1px solid var(--border,#8885)}.feed-history td{display:block;border:0;padding:0 .2rem;min-width:0}.feed-history td:first-child{grid-column:1;grid-row:1;font-size:.7rem;opacity:.7}.feed-history td:nth-child(2){grid-column:1;grid-row:2}.feed-history td:nth-child(3){grid-column:1;grid-row:3;font-size:.75rem}.feed-history td:last-child{grid-column:2;grid-row:1/4;align-self:center}.feed-history-buttons a{min-width:2.3rem;min-height:2.3rem}}
|
||||
|
||||
+34
-14
@@ -10,7 +10,9 @@
|
||||
async function request(path,options={}){const response=await fetch(api+path,{credentials:'same-origin',cache:'no-store',...options,headers:{'Content-Type':'application/json',...options.headers}});if(response.redirected||response.status===401)throw Error(t('Please sign in again.','再度ログインしてください。'));const data=await response.json().catch(()=>({}));if(!response.ok)throw Error(response.status===412?t('Changed elsewhere or refresh is cooling down. Reload before retrying.','別の操作と競合したか、更新の待機時間中です。再読込して確認してください。'):t('Request failed: ','操作に失敗しました: ')+(data.error||response.status));return data;}
|
||||
const post=(path,body)=>request(path,{method:'POST',body:JSON.stringify(body)});
|
||||
let sources=[],items=[],selected=-1,currentSource='',filter='',search='',next=null,loading=false,seq=0,detailSeq=0,editing=false,controller,detailController;
|
||||
let remoteFeed='',remoteCategory='',catalog=[],catalogSeq=0,catalogController;
|
||||
let remoteFeed='',remoteCategory='',categoryMode='',catalog=[],catalogFolders=[],catalogLoaded=false,catalogSearch='',catalogSeq=0,catalogController;
|
||||
const folderStates=new Map();
|
||||
function folderState(source){if(folderStates.has(source))return folderStates.get(source);let state=new Set();try{const raw=localStorage.getItem('pageswiki.feed-folders.v1:'+source);if(raw&&raw.length<=1<<20){const saved=JSON.parse(raw);if(Array.isArray(saved)&&saved.length<=1001)state=new Set(saved.filter(x=>typeof x==='string'&&x.length<=2100));}}catch{}folderStates.set(source,state);return state;}
|
||||
let actionTimer;
|
||||
const pendingAction=a=>a&&['queued','preparing','sending','unknown','check_queued','checking'].includes(a.status);
|
||||
async function updateAction(item){const version=detailSeq;const data=await request('action?'+new URLSearchParams({source:item.source,id:item.id}));if(version!==detailSeq||items[selected]!==item||editing)return;item.action=data.action;item.actionLoading=false;
|
||||
@@ -38,29 +40,47 @@
|
||||
}
|
||||
}
|
||||
function drawCatalog(parent){
|
||||
const nav=el('div',undefined,'feed-catalog'),categories=el('select'),names=new Map();categories.ariaLabel=t('FreshRSS category','FreshRSSカテゴリ');categories.id='feed-category';
|
||||
for(const sub of catalog)for(const cat of sub.categories)names.set(cat.id,cat.label);
|
||||
for(const [id,name]of [['',t('All categories','すべてのカテゴリ')],...Array.from(names).sort((a,b)=>a[1].localeCompare(b[1]))]){const option=el('option',name);option.value=id;categories.append(option);}categories.value=remoteCategory;
|
||||
categories.onchange=()=>{remoteCategory=categories.value;remoteFeed='';drawSources();load(false).catch(report);};nav.append(categories);
|
||||
const find=el('input');find.type='search';find.placeholder=find.ariaLabel=t('Find subscription','購読を絞り込む');nav.append(find);
|
||||
const list=el('div',undefined,'feed-subscriptions');nav.append(list);parent.append(nav);
|
||||
const draw=()=>{list.replaceChildren();const subs=catalog.filter(sub=>(!remoteCategory||sub.categories.some(c=>c.id===remoteCategory))&&sub.title.toLocaleLowerCase().includes(find.value.toLocaleLowerCase())).sort((a,b)=>a.title.localeCompare(b.title));
|
||||
const add=(id,title)=>{const b=button(title,title,async()=>{remoteFeed=id;for(const node of list.children)node.setAttribute('aria-current',String(node===b));layout.classList.remove('sources-open');await load(false);});b.dataset.feed=id;b.setAttribute('aria-current',String(id===remoteFeed));list.append(b);};add('',t('All subscriptions','すべての購読'));for(const sub of subs)add(sub.id,sub.title||sub.id);
|
||||
if(!catalogLoaded)return;
|
||||
const nav=el('nav',undefined,'feed-catalog');nav.ariaLabel=t('FreshRSS folders','FreshRSSのフォルダ');const source=currentSource,state=folderState(source),groups=new Map();
|
||||
for(const c of catalogFolders)groups.set(c.id,{id:c.id,label:c.label,mode:'',subs:[]});
|
||||
const uncategorized={id:'',label:t('Uncategorized','未分類'),mode:'uncategorized',subs:[]};
|
||||
for(const sub of catalog){if(!sub.categories.length)uncategorized.subs.push(sub);for(const c of sub.categories){if(!groups.has(c.id))groups.set(c.id,{id:c.id,label:c.label,mode:'',subs:[]});groups.get(c.id).subs.push(sub);}}
|
||||
const ordered=[...groups.values()].sort((a,b)=>a.label.localeCompare(b.label)||a.id.localeCompare(b.id));if(uncategorized.subs.length)ordered.push(uncategorized);
|
||||
const key=g=>JSON.stringify([g.mode,g.id]),valid=new Set(ordered.map(key));for(const k of state)if(!valid.has(k))state.delete(k);
|
||||
const persist=()=>{try{localStorage.setItem('pageswiki.feed-folders.v1:'+source,JSON.stringify([...state]));}catch{}};
|
||||
const mark=()=>{for(const b of nav.querySelectorAll('button[data-category]'))b.setAttribute('aria-current',String((b.dataset.feed||'')===remoteFeed&&b.dataset.category===remoteCategory&&b.dataset.mode===categoryMode));};
|
||||
const choose=async(id,mode,feed='')=>{remoteCategory=id;categoryMode=mode;remoteFeed=feed;mark();layout.classList.remove('sources-open');await load(false);};
|
||||
const select=(label,g,feed='')=>{const b=button(label,label,()=>choose(g.id,g.mode,feed));b.dataset.category=g.id;b.dataset.mode=g.mode;if(feed)b.dataset.feed=feed;b.setAttribute('aria-current',String(feed===remoteFeed&&g.id===remoteCategory&&g.mode===categoryMode));return b;};
|
||||
const all=select(t('All subscriptions','すべての購読'),{id:'',mode:''});all.className='feed-tree-all';nav.append(all);
|
||||
const find=el('input');find.type='search';find.placeholder=find.ariaLabel=t('Find subscription / folder','購読・フォルダを検索');find.value=catalogSearch;nav.append(find);
|
||||
const list=el('div',undefined,'feed-folders');nav.append(list);parent.append(nav);
|
||||
function subscriptions(target,subs,g){let count=0;const sorted=[...subs].sort((a,b)=>a.title.localeCompare(b.title)||a.id.localeCompare(b.id));const more=button('↓',t('More subscriptions','購読元をさらに表示'),append);
|
||||
function append(){more.remove();for(const sub of sorted.slice(count,count+50)){const group=g||{id:'',mode:''},b=select(sub.title||sub.id,group,sub.id);b.title=(sub.title||sub.id)+(sub.categories.length?' · '+sub.categories.map(c=>c.label).join(' / '):'');target.append(b);}count+=50;if(count<sorted.length)target.append(more);}append();
|
||||
}
|
||||
const draw=()=>{list.replaceChildren();const query=find.value.trim().toLocaleLowerCase();catalogSearch=find.value;
|
||||
if(query){const matches=catalog.filter(s=>s.title.toLocaleLowerCase().includes(query)||s.categories.some(c=>c.label.toLocaleLowerCase().includes(query)));const results=el('div',undefined,'feed-subscriptions');list.append(results);subscriptions(results,matches,null);if(!matches.length)results.append(el('small',t('No subscriptions','購読なし')));return;}
|
||||
for(const g of ordered){const group=el('div',undefined,'feed-folder'),line=el('div',undefined,'feed-folder-row'),children=el('div',undefined,'feed-subscriptions');group.dataset.category=g.id;group.dataset.mode=g.mode;
|
||||
const name=select(g.label||g.id,g);name.className='feed-folder-name';name.title=(g.label||g.id)+(g.id?' · '+g.id:'');const label=el('span',g.label||g.id);name.replaceChildren();
|
||||
const svg=document.createElementNS('http://www.w3.org/2000/svg','svg'),path=document.createElementNS(svg.namespaceURI,'path');svg.setAttribute('viewBox','0 0 24 24');svg.setAttribute('aria-hidden','true');path.setAttribute('d','M3 6h7l2 3h9v11H3z');svg.append(path);name.append(svg,label);
|
||||
let open=state.has(key(g));const toggle=button('',t('Expand folder','フォルダを展開')+' · '+g.label,()=>{open=!open;if(open)state.add(key(g));else state.delete(key(g));persist();paint();});toggle.className='feed-folder-toggle';
|
||||
const paint=()=>{toggle.textContent=open?'▾':'▸';toggle.setAttribute('aria-expanded',String(open));toggle.title=toggle.ariaLabel=(open?t('Collapse folder','フォルダを折りたたむ'):t('Expand folder','フォルダを展開'))+' · '+g.label;children.hidden=!open;children.replaceChildren();if(open){subscriptions(children,g.subs,g);if(!g.subs.length)children.append(el('small',t('Empty folder','空のフォルダ')));}};
|
||||
line.append(toggle,name);group.append(line,children);list.append(group);paint();
|
||||
}mark();
|
||||
};find.oninput=draw;draw();
|
||||
}
|
||||
async function loadCatalog(){catalogController?.abort();catalogController=new AbortController();const version=++catalogSeq;catalog=[];if(sources.find(s=>s.uuid===currentSource)?.provider!=='freshrss')return;
|
||||
const data=await request('catalog?'+new URLSearchParams({source:currentSource}),{signal:catalogController.signal});if(version!==catalogSeq)return;catalog=data.subscriptions;drawSources();
|
||||
async function loadCatalog(){catalogController?.abort();catalogController=new AbortController();const version=++catalogSeq;catalogLoaded=false;catalog=[];catalogFolders=[];if(sources.find(s=>s.uuid===currentSource)?.provider!=='freshrss')return;
|
||||
const data=await request('catalog?'+new URLSearchParams({source:currentSource}),{signal:catalogController.signal});if(version!==catalogSeq)return;catalog=data.subscriptions;catalogFolders=data.folders||[];catalogLoaded=true;drawSources();
|
||||
}
|
||||
async function chooseSource(id){currentSource=id;remoteFeed=remoteCategory='';catalog=[];drawSources();layout.classList.remove('reading');editing=false;await Promise.all([loadCatalog(),load(false)]);if(sources.find(s=>s.uuid===id)?.provider!=='freshrss')layout.classList.remove('sources-open');}
|
||||
async function chooseSource(id){currentSource=id;remoteFeed=remoteCategory=categoryMode=catalogSearch='';catalog=[];catalogFolders=[];catalogLoaded=false;drawSources();layout.classList.remove('reading');editing=false;await Promise.all([loadCatalog(),load(false)]);if(sources.find(s=>s.uuid===id)?.provider!=='freshrss')layout.classList.remove('sources-open');}
|
||||
function rowNode(item,index){const row=el('div',undefined,'feed-row'+(item.read?'':' unread'));row.id='feed-row-'+index;row.setAttribute('role','option');row.setAttribute('aria-selected',String(index===selected));for(const text of [(item.starred?'★':item.read?' ':'●'),date(item.published_ms),item.feed||sources.find(s=>s.uuid===item.source)?.title||'',item.title||t('(Untitled)','(無題)')])row.append(el('span',text));row.title=item.title;row.onclick=()=>open(index).catch(report);return row;}
|
||||
function drawRows(){rows.replaceChildren(...items.map(rowNode));more.hidden=!next;more.textContent='↓';more.title=more.ariaLabel=t('More articles','続きを表示');if(!items.length)rows.append(el('p',t('No articles','記事なし'),'feed-warning'));}
|
||||
async function load(append){if(append&&(!next||loading))return;controller?.abort();controller=new AbortController();const version=++seq;loading=true;more.disabled=true;
|
||||
try{const q=new URLSearchParams({source:currentSource,filter,q:search,feed:remoteFeed,category:remoteCategory});if(append){q.set('before',next.ms);q.set('key',next.key);}const data=await request('items?'+q,{signal:controller.signal});if(version!==seq)return;
|
||||
try{const q=new URLSearchParams({source:currentSource,filter,q:search,feed:remoteFeed,category:remoteCategory,category_mode:categoryMode});if(append){q.set('before',next.ms);q.set('key',next.key);}const data=await request('items?'+q,{signal:controller.signal});if(version!==seq)return;
|
||||
if(!append){detailSeq++;items=[];selected=-1;reader.replaceChildren();layout.classList.remove('reading','action-history');editing=false;}items.push(...data.items);const last=data.items.at(-1);next=data.more&&last?{ms:last.published_ms,key:last.source+':'+last.id}:null;drawRows();status.textContent='';
|
||||
}finally{if(version===seq){loading=false;more.disabled=false;}}
|
||||
}
|
||||
more.onclick=()=>load(true).catch(report);
|
||||
async function reload(){sources=(await request('sources')).sources;if(!sources.some(s=>s.uuid===currentSource)){currentSource=remoteFeed=remoteCategory='';}drawSources();await loadCatalog();if(remoteCategory&&!catalog.some(s=>s.categories.some(c=>c.id===remoteCategory)))remoteCategory='';if(remoteFeed&&!catalog.some(s=>s.id===remoteFeed))remoteFeed='';drawSources();await load(false);}
|
||||
async function reload(){sources=(await request('sources')).sources;if(!sources.some(s=>s.uuid===currentSource)){currentSource=remoteFeed=remoteCategory=categoryMode='';}drawSources();await loadCatalog();if(remoteCategory&&!catalogFolders.some(c=>c.id===remoteCategory))remoteCategory='';if(remoteFeed&&!catalog.some(s=>s.id===remoteFeed))remoteFeed='';drawSources();await load(false);}
|
||||
async function queueRefresh(){const targets=sources.filter(s=>s.enabled&&(!currentSource||currentSource===s.uuid));for(const s of targets)await post('sources/'+s.uuid+'/refresh',{version:s.version});status.textContent=t('Refresh queued','更新を予約しました');}
|
||||
toolbar.append(button('⟳',t('Reload cached list','取得済み一覧を再読込'),reload));
|
||||
async function open(index){if(index<0||index>=items.length)return;editing=false;selected=index;detailController?.abort();detailController=new AbortController();const version=++detailSeq;for(const [i,row]of [...rows.querySelectorAll('.feed-row')].entries())row.setAttribute('aria-selected',String(i===index));rows.setAttribute('aria-activedescendant','feed-row-'+index);document.getElementById('feed-row-'+index)?.scrollIntoView({block:'nearest'});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{{ define "feeds.gohtml" }}<!doctype html>
|
||||
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>{{ T "feeds.title" }} · {{ .WikiName }}</title>
|
||||
<link rel="stylesheet" href="/static/css/main.css"><link rel="stylesheet" href="/static/css/theme/base.css"><link rel="stylesheet" href="{{ .ThemeCSS }}"><link rel="stylesheet" href="/static/css/feeds.css?v=6"></head>
|
||||
<link rel="stylesheet" href="/static/css/main.css"><link rel="stylesheet" href="/static/css/theme/base.css"><link rel="stylesheet" href="{{ .ThemeCSS }}"><link rel="stylesheet" href="/static/css/feeds.css?v=7"></head>
|
||||
<body class="mode-view organizer-page feeds-page"><header class="topbar"><div class="brand"><a href="/">{{ .WikiName }}</a></div>{{ template "auth-menu" . }}</header>{{ template "organizer-nav" . }}
|
||||
<main id="feeds-app" data-writable="{{ .FeedWritable }}" data-tasks="{{ .TasksEnabled }}">
|
||||
<div id="feed-toolbar"></div><p id="feed-status" role="status" aria-live="polite"></p>
|
||||
<div class="feed-layout"><aside id="feed-sources" aria-label="{{ T "feeds.title" }}"></aside><section class="feed-index"><div id="feed-columns" aria-hidden="true"></div><div id="feed-rows" tabindex="0" role="listbox" aria-label="{{ T "feeds.title" }}"></div><button type="button" id="feed-more" hidden>↓</button></section><article id="feed-reader" tabindex="0"></article></div>
|
||||
</main><script src="/static/js/feeds.js?v=6" defer></script></body></html>{{ end }}
|
||||
</main><script src="/static/js/feeds.js?v=7" defer></script></body></html>{{ end }}
|
||||
Reference in new issue
Block a user