feat: render RSS HTML bodies and simplify reader navigation
Build and publish container images / images (push) Successful in 12m32s
Build and publish container images / images (push) Successful in 12m32s
This commit is contained in:
1 parent
0d8997972c
commit
38daea737d
12 files changed
+208
-49
No files matched your search
+13
-6
@@ -37,7 +37,7 @@ FreshRSSの記事・既読・starは取得しますが、状態の変更は送
|
||||
FreshRSS passwordを設定時以外にブラウザへ返さず、login tokenはbackend内でのみ利用します。
|
||||
資格情報は既存の暗号化機構を使い、Domain・所有者・source UUID・用途に束縛します。
|
||||
|
||||
cacheはsource UUID、remote item ID、title、安全なテキスト本文、記事URL、公開日時、配信元、
|
||||
cacheはsource UUID、remote item ID、title、安全化したHTML本文とテキスト本文、記事URL、公開日時、配信元、
|
||||
フォルダ、read/starを保持します。取得時刻・ETag・Last-Modified・失敗分類はsource側に持ちます。
|
||||
IDなしRSSは記事URL、URLもなければ題名・日時・本文の組合せから代替キーを作り、題名だけで
|
||||
重複排除しません。Atomはentry IDを使います。[Atom仕様](https://www.rfc-editor.org/rfc/rfc4287)。
|
||||
@@ -46,14 +46,19 @@ IDなしRSSは記事URL、URLもなければ題名・日時・本文の組合せ
|
||||
|
||||
newsboat/neomuttを参考に、デスクトップは左から購読元・一行記事一覧・本文の3ペインとします。
|
||||
一覧には未読/star、日付、配信元、件名を並べます。狭幅は一覧と本文を切り替え、スマホでは
|
||||
行とボタンのタッチ領域を広げます。設定と保存フォームは本文ペイン内に置き、モーダルを増やしません。
|
||||
行とボタンのタッチ領域を広げます。モバイルの共通ナビはアイコンのみとし、名称はアクセシブル名と
|
||||
tooltipに残します。タブ名は「RSS」、原文リンクはアイコンです。件数・保持上限・操作の説明は常設せず、
|
||||
キー案内は`?`で表示します。設定と保存フォームは本文ペイン内に置き、モーダルを増やしません。
|
||||
|
||||
`j/k`・上下矢印で移動、`Enter/l`で本文、`Esc/h`で一覧、`/`で件名・配信元検索、`n`で次の未読、
|
||||
`m`で既読切替、`*`でstar、`r`で背景更新予約、`?`でキー案内です。フォーム入力・IME変換中は
|
||||
一覧ショートカットを抑止します。FreshRSSでは`m`と`*`も外部変更を行いません。
|
||||
|
||||
本文は常にtext表示です。script・画像・CSS・Wiki macroを実行せず、記事表示のための外部画像や
|
||||
原文サイトのfetchも行いません。検索とページングは保存済みcacheだけを対象にし、画面表示で
|
||||
HTML本文は見出し・表・箇条書き・強調・リンクを保持して描画し、plain textは文字情報として表示します。
|
||||
server側の許可リストでscript・イベント属性・任意CSS・form・iframe・画像等を除去し、表示時にも再検査します。
|
||||
Shadow DOMでWiki UIと表示スタイルを分離し、本文リンクは安全なHTTP(S) URLに解決して別タブで開きます。
|
||||
Wiki macroは展開せず、記事表示のための外部画像や原文サイトのfetchも行いません。
|
||||
検索とページングは保存済みcacheだけを対象にし、画面表示で
|
||||
feed取得の完了を待ちません。ダッシュボードには任意追加のRSS widgetを用意します。
|
||||
|
||||
### APIと保存層
|
||||
@@ -71,7 +76,9 @@ API prefixは `/_/api/v1/extension/organizer.feeds/`。Domain内の本人専用
|
||||
| `POST state` | 内蔵read/starの条件付き変更。FreshRSSは拒否 |
|
||||
| `POST note` | 公開範囲確認付きのWiki単独保存。request_idと入力hashで再送を識別 |
|
||||
|
||||
managed schema `feeds` v1に `feed_sources`、`feed_items`、`feed_states`、`feed_note_receipts`を追加します。
|
||||
managed schema `feeds` v1に `feed_sources`、`feed_items`、`feed_states`、`feed_note_receipts`を追加し、
|
||||
v2で`feed_items.body_html`を追加します。既存のテキスト本文・既読・starは保持し、条件付きGETのvalidatorを
|
||||
一度クリアして次回背景取得でHTMLを取り直します。migration前のworkerは設定versionで無効化します。
|
||||
既存テーブルを破壊・再構成しません。SQLiteのforeign_keys設定に依存せず削除を完遂するtriggerを
|
||||
持ちます。内蔵read/starを本文cacheから分離し、記事を保持窓から落としても状態は黙って消しません。
|
||||
DBは内蔵購読・状態・保存receiptの正本であり、全体を捨てられるcacheとは扱いません。
|
||||
@@ -89,7 +96,7 @@ sourceのprovider・URL・資格情報の変更は別sourceを作る契約です
|
||||
| source更新間隔 | 5〜1440分、既定30分。取得候補になる間隔であり、混雑時の完了時刻保証ではない |
|
||||
| 通信予算 | 1 source 8秒、batch 35秒、応答/展開後本文4 MiB |
|
||||
| 外部接続 | 公開HTTPS/443のみ。DNS検査・接続先固定、内部アドレス・redirect・proxyを拒否 |
|
||||
| 内蔵記事cache | 1 source最大500件、本文32 KiB。超過本文は切詰めを明示 |
|
||||
| 内蔵記事cache | 1 source最大500件、text本文32 KiB・HTML本文128 KiB。HTML上限超過はtextへフォールバックし、text切詰めを明示 |
|
||||
| 内蔵read/star | 1 source最大10,000件。上限では新規状態保存を拒否し、既存状態を捨てない |
|
||||
| FreshRSS | reading-list最新200件の窓を取得。更新成功時はその窓で置換し、全履歴同期とはしない |
|
||||
| 再試行 | 次の設定間隔まで待機。手動予約にも最終成功から60秒の制限、取得中の重複claim拒否 |
|
||||
|
||||
@@ -172,6 +172,8 @@ func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
// Defense in depth for restored/older caches, not just freshly fetched data.
|
||||
v.BodyHTML = feedHTML(v.BodyHTML, v.URL)
|
||||
writeEventJSON(w, 200, map[string]any{"item": v})
|
||||
return
|
||||
case key == "state" && r.Method == "POST":
|
||||
@@ -195,8 +197,8 @@ func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
func init() {
|
||||
translations["en"]["feeds.title"] = "RSS reader"
|
||||
translations["ja"]["feeds.title"] = "RSSリーダー"
|
||||
translations["en"]["feeds.title"] = "RSS"
|
||||
translations["ja"]["feeds.title"] = "RSS"
|
||||
translations["en"]["feeds.help"] = "Private local feeds and read-only FreshRSS integration"
|
||||
translations["ja"]["feeds.help"] = "個人用の簡易RSSとFreshRSS読取連携"
|
||||
}
|
||||
@@ -19,15 +19,71 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
xhtml "golang.org/x/net/html"
|
||||
"golang.org/x/net/html/charset"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
var errFeedInvalid = errors.New("invalid_feed")
|
||||
var feedTextPolicy = bluemonday.StrictPolicy()
|
||||
var feedHTMLPolicy = func() *bluemonday.Policy {
|
||||
p := bluemonday.NewPolicy()
|
||||
p.AllowElements("p", "div", "span", "br", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "strong", "b", "em", "i", "u", "s", "del", "ins", "sub", "sup", "mark", "small", "blockquote", "pre", "code", "kbd", "samp", "ul", "ol", "li", "dl", "dt", "dd", "table", "caption", "thead", "tbody", "tfoot", "tr", "th", "td", "a")
|
||||
p.AllowAttrs("href", "target", "rel").OnElements("a")
|
||||
p.AllowAttrs("colspan", "rowspan", "scope").OnElements("th", "td")
|
||||
p.AllowStandardURLs()
|
||||
p.AllowRelativeURLs(false)
|
||||
return p
|
||||
}()
|
||||
|
||||
// Keep article structure without granting fetched HTML script, style, form,
|
||||
// embedding or automatic network capabilities. Wiki capture still uses Body.
|
||||
func feedHTML(raw, base string) string {
|
||||
if raw == "" || len(raw) > 128<<10 {
|
||||
return ""
|
||||
}
|
||||
z := xhtml.NewTokenizer(strings.NewReader(raw))
|
||||
var out strings.Builder
|
||||
markup := false
|
||||
for {
|
||||
typeOf := z.Next()
|
||||
if typeOf == xhtml.ErrorToken {
|
||||
if z.Err() != io.EOF {
|
||||
return ""
|
||||
}
|
||||
break
|
||||
}
|
||||
if typeOf == xhtml.StartTagToken || typeOf == xhtml.SelfClosingTagToken {
|
||||
markup = true
|
||||
tok := z.Token()
|
||||
if tok.Data == "a" {
|
||||
attrs := []xhtml.Attribute{}
|
||||
for _, attr := range tok.Attr {
|
||||
if attr.Key == "href" {
|
||||
if link := feedLink(base, attr.Val); link != "" {
|
||||
attrs = append(attrs, xhtml.Attribute{Key: "href", Val: link})
|
||||
}
|
||||
}
|
||||
}
|
||||
tok.Attr = append(attrs, xhtml.Attribute{Key: "target", Val: "_blank"}, xhtml.Attribute{Key: "rel", Val: "noopener noreferrer"})
|
||||
}
|
||||
out.WriteString(tok.String())
|
||||
} else {
|
||||
out.Write(z.Raw())
|
||||
}
|
||||
}
|
||||
if !markup {
|
||||
return ""
|
||||
}
|
||||
clean := feedHTMLPolicy.Sanitize(out.String())
|
||||
if len(clean) > 128<<10 {
|
||||
return ""
|
||||
}
|
||||
return clean
|
||||
}
|
||||
|
||||
func feedText(raw string, limit int) string {
|
||||
// Text-only reader: no remote images, CSS, script, macros or active HTML.
|
||||
// Plain text for fallback and inert Wiki/task capture.
|
||||
for _, tag := range []string{"</p>", "</div>", "<br>", "<br/>", "<br />", "</li>"} {
|
||||
raw = strings.ReplaceAll(raw, tag, tag+"\n")
|
||||
}
|
||||
@@ -81,6 +137,19 @@ type rssEntry struct {
|
||||
Date string `xml:"pubDate"`
|
||||
Category string `xml:"category"`
|
||||
}
|
||||
type atomText struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Text string `xml:",chardata"`
|
||||
Inner string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
func (v atomText) body() (string, bool) {
|
||||
if v.Type == "xhtml" {
|
||||
return v.Inner, true
|
||||
}
|
||||
return v.Text, v.Type == "html"
|
||||
}
|
||||
|
||||
type atomEntry struct {
|
||||
ID string `xml:"id"`
|
||||
Title string `xml:"title"`
|
||||
@@ -88,13 +157,10 @@ type atomEntry struct {
|
||||
Href string `xml:"href,attr"`
|
||||
Rel string `xml:"rel,attr"`
|
||||
} `xml:"link"`
|
||||
Summary string `xml:"summary"`
|
||||
Content struct {
|
||||
Text string `xml:",chardata"`
|
||||
Inner string `xml:",innerxml"`
|
||||
} `xml:"content"`
|
||||
Published string `xml:"published"`
|
||||
Updated string `xml:"updated"`
|
||||
Summary atomText `xml:"summary"`
|
||||
Content atomText `xml:"content"`
|
||||
Published string `xml:"published"`
|
||||
Updated string `xml:"updated"`
|
||||
Category struct {
|
||||
Term string `xml:"term,attr"`
|
||||
} `xml:"category"`
|
||||
@@ -138,6 +204,7 @@ func parseFeed(raw []byte, base string) ([]store.FeedItem, error) {
|
||||
}
|
||||
var item store.FeedItem
|
||||
isItem := false
|
||||
htmlBody := false
|
||||
if root == "rss" && t.Name.Local == "item" && depth == 3 {
|
||||
var v rssEntry
|
||||
if d.DecodeElement(&v, &t) != nil {
|
||||
@@ -150,19 +217,18 @@ func parseFeed(raw []byte, base string) ([]store.FeedItem, error) {
|
||||
}
|
||||
item = store.FeedItem{ID: v.ID, Title: v.Title, URL: feedLink(base, v.Link), Body: body, PublishedMS: feedDate(v.Date), Folder: v.Category}
|
||||
isItem = true
|
||||
htmlBody = true
|
||||
} else if root == "feed" && t.Name.Local == "entry" && depth == 2 {
|
||||
var v atomEntry
|
||||
if d.DecodeElement(&v, &t) != nil {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
depth--
|
||||
body := v.Content.Text
|
||||
body, isHTML := v.Content.body()
|
||||
if body == "" {
|
||||
body = v.Content.Inner
|
||||
}
|
||||
if body == "" {
|
||||
body = v.Summary
|
||||
body, isHTML = v.Summary.body()
|
||||
}
|
||||
htmlBody = isHTML
|
||||
link := ""
|
||||
for _, l := range v.Links {
|
||||
if l.Rel == "" || l.Rel == "alternate" {
|
||||
@@ -187,7 +253,13 @@ func parseFeed(raw []byte, base string) ([]store.FeedItem, error) {
|
||||
return nil, errors.New("limit")
|
||||
}
|
||||
item.Title = feedText(item.Title, 2048)
|
||||
item.Body = feedText(item.Body, 32768)
|
||||
if htmlBody {
|
||||
item.BodyHTML = feedHTML(item.Body, base)
|
||||
item.Body = feedText(item.Body, 32768)
|
||||
} else {
|
||||
// Atom type=text is literal, even when it contains HTML-looking text.
|
||||
item.Body = feedText(html.EscapeString(item.Body), 32768)
|
||||
}
|
||||
item.Feed = feedText(title, 512)
|
||||
item.Folder = feedText(item.Folder, 512)
|
||||
if item.ID == "" {
|
||||
@@ -314,6 +386,7 @@ func fetchFreshRSS(ctx context.Context, client *http.Client, v store.FeedSource,
|
||||
body = i.Content.Content
|
||||
}
|
||||
item.Body = feedText(body, 32768)
|
||||
item.BodyHTML = feedHTML(body, base)
|
||||
if len(i.Alternate) > 0 {
|
||||
item.URL = feedLink(base, i.Alternate[0].Href)
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ func TestFreshRSSReadOnlyContract(t *testing.T) {
|
||||
}))
|
||||
defer remote.Close()
|
||||
items, e := fetchFreshRSS(context.Background(), remote.Client(), store.FeedSource{URL: remote.URL + "/api/greader.php"}, "reader", "api-secret")
|
||||
if e != nil || len(items) != 1 || !items[0].Read || !items[0].Starred || items[0].Folder != "Tech" || items[0].Body != "Text" || len(requests) != 2 {
|
||||
if e != nil || len(items) != 1 || !items[0].Read || !items[0].Starred || items[0].Folder != "Tech" || items[0].Body != "Text" || items[0].BodyHTML != "<p>Text</p>" || len(requests) != 2 {
|
||||
t.Fatal(items, e, requests)
|
||||
}
|
||||
for _, bad := range []string{"http://example.org/feed", "https://127.0.0.1/feed", "https://10.0.0.1/feed", "https://example.org:8443/feed", "https://user:pass@example.org/feed"} {
|
||||
@@ -185,6 +185,45 @@ func TestFreshRSSReadOnlyContract(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedHTMLFormattingAndIsolation(t *testing.T) {
|
||||
raw := `<h2>Title</h2><p class="x" style="position:fixed" onclick="bad()"><strong>Bold</strong></p><table><tr><td colspan="2">Cell</td></tr></table><a href="../story" target="_top">Story</a><a href="javascript:bad()">bad</a><script>bad()</script><style>@import '/__feed_leak';</style><form action="/__feed_leak"><input autofocus></form><img src="/__feed_leak"><iframe src="/__feed_leak"></iframe><svg onload="bad()"></svg>`
|
||||
clean := feedHTML(raw, "https://example.org/news/feed.xml")
|
||||
for _, want := range []string{`<h2>Title</h2>`, `<strong>Bold</strong>`, `<table>`, `colspan="2"`, `href="https://example.org/story"`, `target="_blank"`, `noopener`} {
|
||||
if !strings.Contains(clean, want) {
|
||||
t.Fatal("format lost", want, clean)
|
||||
}
|
||||
}
|
||||
for _, bad := range []string{"<script", "<style", "<form", "<input", "<img", "<iframe", "<svg", "onclick", "javascript:", "position:", "_top", "__feed_leak"} {
|
||||
if strings.Contains(clean, bad) {
|
||||
t.Fatal("unsafe markup", bad, clean)
|
||||
}
|
||||
}
|
||||
if feedHTML(clean, "https://example.org/news/feed.xml") != clean {
|
||||
t.Fatal("sanitizer not stable")
|
||||
}
|
||||
if feedHTML(strings.Repeat("<p>x</p>", 17000), "https://example.org") != "" {
|
||||
t.Fatal("HTML cap")
|
||||
}
|
||||
for _, kind := range []string{"text", "html", "xhtml"} {
|
||||
content := `<b>bold</b>`
|
||||
if kind == "xhtml" {
|
||||
content = `<div xmlns="http://www.w3.org/1999/xhtml"><b>bold</b></div>`
|
||||
}
|
||||
items, e := parseFeed([]byte(`<feed xmlns="http://www.w3.org/2005/Atom"><entry><id>x</id><content type="`+kind+`">`+content+`</content></entry></feed>`), "https://example.org")
|
||||
if e != nil || len(items) != 1 {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if kind == "text" {
|
||||
if items[0].BodyHTML != "" || items[0].Body != "<b>bold</b>" {
|
||||
t.Fatal("literal Atom text", items)
|
||||
}
|
||||
} else if !strings.Contains(items[0].BodyHTML, "<b>bold</b>") {
|
||||
t.Fatal("Atom markup", kind, items)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedPaginationFailureAndDelete(t *testing.T) {
|
||||
s, token, domain, actor, source := feedFixture(t)
|
||||
ctx := context.Background()
|
||||
@@ -500,6 +539,7 @@ func TestFeedsChromium(t *testing.T) {
|
||||
for i := 0; i < 120; i++ {
|
||||
items = append(items, store.FeedItem{ID: fmt.Sprint(i), Title: fmt.Sprintf("%03d 日本語のRSS記事 — リーダーの密度とキーボード操作", i), Body: "安全な本文です。\n\n<script>display as text</script> {{children}}\n\nSource content stays inert.", Feed: "技術ニュース", URL: "https://example.org/article", PublishedMS: int64(1793500000000 + i)})
|
||||
}
|
||||
items[119].BodyHTML = `<h2>HTMLの記事本文</h2><p><strong>強調</strong>や<a href="/article">リンク</a>をそのまま読めます。</p><ul><li>見出しと箇条書き</li><li>テーマに沿った表示</li></ul><table><tr><th>項目</th><th>内容</th></tr><tr><td>本文</td><td>HTML表示</td></tr></table><script>window.rssAttack=1</script><img src="/__feed_leak" onerror="window.rssAttack=1"><style>body{display:none}</style>`
|
||||
if e = s.store.CompleteFeed(context.Background(), claim, items, "", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
|
||||
Vendored
+4
-1
@@ -6,8 +6,11 @@
|
||||
await new Promise(resolve=>{frame.onload=resolve;frame.src='/v/feeds';});const d=frame.contentDocument,w=frame.contentWindow;
|
||||
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');
|
||||
for(const a of d.querySelectorAll('.organizer-nav a')){assert(a.getAttribute('aria-label'),'Unnamed navigation');if(w.innerWidth<=700)assert(w.getComputedStyle(a.querySelector('span')).display==='none','Mobile tab label visible');}
|
||||
d.getElementById('feed-rows').focus();d.dispatchEvent(new w.KeyboardEvent('keydown',{key:'j',bubbles:true}));
|
||||
await wait(()=>d.querySelector('#feed-reader .feed-body'));assert(d.querySelector('#feed-reader .feed-body').textContent.includes('<script>'),'Text not preserved');assert(!d.querySelector('#feed-reader script'),'Active article HTML');
|
||||
await wait(()=>d.querySelector('#feed-reader .feed-body'));const html=d.querySelector('#feed-reader .feed-body').shadowRoot;assert(html?.querySelector('h2')&&html.querySelector('table')&&html.querySelector('strong'),'HTML not rendered');assert(!html.querySelector('script,img,iframe,form'),'Active article HTML');assert(!w.rssAttack,'Script executed');assert(html.querySelector('a').target==='_blank','Article link target');assert(d.querySelector('.feed-original svg')&&!d.querySelector('.feed-original').textContent,'Original link not icon');
|
||||
d.querySelectorAll('.feed-row')[1].click();await wait(()=>d.querySelector('#feed-reader .feed-body')&&!d.querySelector('#feed-reader .feed-body').shadowRoot);assert(d.querySelector('#feed-reader .feed-body').textContent.includes('<script>'),'Literal text not preserved');d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body')?.shadowRoot);
|
||||
d.dispatchEvent(new w.KeyboardEvent('keydown',{key:'*',bubbles:true}));await wait(()=>d.querySelector('.feed-row[aria-selected=true]').textContent.includes('★'));
|
||||
d.dispatchEvent(new w.KeyboardEvent('keydown',{key:'Escape',bubbles:true}));await wait(()=>!d.querySelector('.feed-layout').classList.contains('reading'));
|
||||
d.getElementById('feed-more').click();await wait(()=>d.querySelectorAll('.feed-row').length===120);
|
||||
|
||||
+12
-4
@@ -26,7 +26,14 @@ var feedMigrations = []db.SQLMigration{{Version: 1, Name: "private_feed_reader",
|
||||
`CREATE TABLE feed_states(source_uuid TEXT NOT NULL REFERENCES feed_sources(uuid) ON DELETE CASCADE,id TEXT NOT NULL,is_read INTEGER NOT NULL,starred INTEGER NOT NULL,version INTEGER NOT NULL,PRIMARY KEY(source_uuid,id))`,
|
||||
`CREATE TRIGGER feed_source_delete AFTER DELETE ON feed_sources BEGIN DELETE FROM feed_items WHERE source_uuid=old.uuid; DELETE FROM feed_states WHERE source_uuid=old.uuid; END`,
|
||||
`CREATE TABLE feed_note_receipts(domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,request_id TEXT NOT NULL,input_hash TEXT NOT NULL,page_uuid TEXT NOT NULL,PRIMARY KEY(domain_uuid,owner_uuid,request_id))`,
|
||||
}, Assertions: []string{schemaColumns("feed_sources", "uuid,domain_uuid,owner_uuid,provider,title,folder,url,credential,version,enabled,interval_seconds,next_ms,lease,lease_until,last_ms,error,etag,modified"), schemaColumns("feed_items", "source_uuid,id,title,url,body,published_ms,feed,folder,is_read,starred"), schemaUnique("feed_items", "source_uuid,id"), schemaUnique("feed_states", "source_uuid,id"), schemaUnique("feed_note_receipts", "domain_uuid,owner_uuid,request_id"), `SELECT 1 WHERE NOT EXISTS(SELECT 1 FROM sqlite_master WHERE type='trigger' AND name='feed_source_delete')`}}}
|
||||
}, Assertions: []string{schemaColumns("feed_sources", "uuid,domain_uuid,owner_uuid,provider,title,folder,url,credential,version,enabled,interval_seconds,next_ms,lease,lease_until,last_ms,error,etag,modified"), schemaColumns("feed_items", "source_uuid,id,title,url,body,published_ms,feed,folder,is_read,starred"), schemaUnique("feed_items", "source_uuid,id"), schemaUnique("feed_states", "source_uuid,id"), schemaUnique("feed_note_receipts", "domain_uuid,owner_uuid,request_id"), `SELECT 1 WHERE NOT EXISTS(SELECT 1 FROM sqlite_master WHERE type='trigger' AND name='feed_source_delete')`}}, {
|
||||
Version: 2, Name: "feed_html_body", Statements: []string{
|
||||
`ALTER TABLE feed_items ADD COLUMN body_html TEXT NOT NULL DEFAULT ''`,
|
||||
// Text-only caches cannot recover markup from a 304. Request one full
|
||||
// background fetch while fencing workers started before this migration.
|
||||
`UPDATE feed_sources SET etag='',modified='',next_ms=0,lease='',lease_until=0,version=version+1`,
|
||||
}, Assertions: []string{schemaColumns("feed_items", "body_html")},
|
||||
}}
|
||||
|
||||
// CaptureFeedNote creates an inert Wiki note and receipt atomically. It does not
|
||||
// mutate the feed or create a task, and rechecks grants under the writer lock.
|
||||
@@ -118,6 +125,7 @@ type FeedItem struct {
|
||||
Title string `json:"title"`
|
||||
URL string `json:"url"`
|
||||
Body string `json:"body,omitempty"`
|
||||
BodyHTML string `json:"body_html,omitempty"`
|
||||
PublishedMS int64 `json:"published_ms"`
|
||||
Feed string `json:"feed"`
|
||||
Folder string `json:"folder"`
|
||||
@@ -309,7 +317,7 @@ func (s *Store) FeedItem(ctx context.Context, domain, owner, source, id string)
|
||||
if e := feedActor(ctx, s.DB, domain, owner, false); e != nil {
|
||||
return v, e
|
||||
}
|
||||
e := s.DB.QueryRowContext(ctx, `SELECT i.source_uuid,i.id,i.title,i.url,i.body,i.published_ms,i.feed,i.folder,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 s.uuid=? AND i.id=?`, domain, owner, source, id).Scan(&v.Source, &v.ID, &v.Title, &v.URL, &v.Body, &v.PublishedMS, &v.Feed, &v.Folder, &v.Read, &v.Starred, &v.Version, &v.Provider)
|
||||
e := s.DB.QueryRowContext(ctx, `SELECT i.source_uuid,i.id,i.title,i.url,i.body,i.body_html,i.published_ms,i.feed,i.folder,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 s.uuid=? AND i.id=?`, domain, owner, source, id).Scan(&v.Source, &v.ID, &v.Title, &v.URL, &v.Body, &v.BodyHTML, &v.PublishedMS, &v.Feed, &v.Folder, &v.Read, &v.Starred, &v.Version, &v.Provider)
|
||||
return v, e
|
||||
}
|
||||
func (s *Store) SetFeedState(ctx context.Context, domain, owner, source, id string, read, star bool, version int64) error {
|
||||
@@ -416,7 +424,7 @@ func (s *Store) CompleteFeed(ctx context.Context, v FeedSource, items []FeedItem
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
for _, i := range items {
|
||||
if i.ID == "" || len(i.ID) > 1024 || len(i.Title) > 2048 || len(i.URL) > 4096 || len(i.Body) > 32768 || len(i.Feed) > 512 || len(i.Folder) > 512 || i.PublishedMS < 0 {
|
||||
if i.ID == "" || len(i.ID) > 1024 || len(i.Title) > 2048 || len(i.URL) > 4096 || len(i.Body) > 32768 || len(i.BodyHTML) > 128<<10 || len(i.Feed) > 512 || len(i.Folder) > 512 || i.PublishedMS < 0 {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
}
|
||||
@@ -440,7 +448,7 @@ func (s *Store) CompleteFeed(ctx context.Context, v FeedSource, items []FeedItem
|
||||
}
|
||||
}
|
||||
for _, i := range items {
|
||||
_, e = tx.ExecContext(ctx, `INSERT INTO feed_items(source_uuid,id,title,url,body,published_ms,feed,folder,is_read,starred) VALUES(?,?,?,?,?,?,?,?,?,?) ON CONFLICT(source_uuid,id) DO UPDATE SET title=excluded.title,url=excluded.url,body=excluded.body,published_ms=excluded.published_ms,feed=excluded.feed,folder=excluded.folder,is_read=excluded.is_read,starred=excluded.starred`, v.UUID, i.ID, i.Title, i.URL, i.Body, i.PublishedMS, i.Feed, i.Folder, i.Read, i.Starred)
|
||||
_, e = tx.ExecContext(ctx, `INSERT INTO feed_items(source_uuid,id,title,url,body,body_html,published_ms,feed,folder,is_read,starred) VALUES(?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(source_uuid,id) DO UPDATE SET title=excluded.title,url=excluded.url,body=excluded.body,body_html=excluded.body_html,published_ms=excluded.published_ms,feed=excluded.feed,folder=excluded.folder,is_read=excluded.is_read,starred=excluded.starred`, v.UUID, i.ID, i.Title, i.URL, i.Body, i.BodyHTML, i.PublishedMS, i.Feed, i.Folder, i.Read, i.Starred)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
@@ -20,17 +20,41 @@ func TestFeedMigrationAtomicRepeatAndCleanup(t *testing.T) {
|
||||
if e := st.DB.QueryRow(`SELECT count(*) FROM sqlite_master WHERE name='feed_sources'`).Scan(&count); e != nil || count != 0 {
|
||||
t.Fatal("partial schema", count, e)
|
||||
}
|
||||
if e := st.ensureSchemaComponent("feeds"); e != nil {
|
||||
// Upgrade an existing v1 cache, not just an empty database.
|
||||
if e := db.ApplySQLiteMigrations(ctx, st.DB, "feeds", feedMigrations[:1]); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e := st.DB.Exec(`INSERT INTO feed_sources(uuid,domain_uuid,owner_uuid,provider,title,folder,url,version,enabled,interval_seconds) VALUES('s','d','u','local','title','','https://example.org',1,1,300); INSERT INTO feed_items VALUES('s','i','title','','body',0,'','',0,0); INSERT INTO feed_states VALUES('s','i',1,1,1)`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e := st.DB.Exec(`UPDATE feed_sources SET etag='old',modified='date',next_ms=999,lease='old-worker',lease_until=999`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
broken = append([]db.SQLMigration(nil), feedMigrations...)
|
||||
broken[1].Statements = append(append([]string(nil), feedMigrations[1].Statements...), `INSERT INTO no_such_feed_table VALUES(1)`)
|
||||
if e := db.ApplySQLiteMigrations(ctx, st.DB, "feeds", broken); e == nil {
|
||||
t.Fatal("expected v2 failure")
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT count(*) FROM pragma_table_info('feed_items') WHERE name='body_html'`).Scan(&count); e != nil || count != 0 {
|
||||
t.Fatal("partial v2 schema", count, e)
|
||||
}
|
||||
var oldETag string
|
||||
if e := st.DB.QueryRow(`SELECT etag FROM feed_sources WHERE uuid='s'`).Scan(&oldETag); e != nil || oldETag != "old" {
|
||||
t.Fatal("partial v2 metadata", oldETag, e)
|
||||
}
|
||||
for range 2 {
|
||||
if e := st.ensureSchemaComponent("feeds"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
var body, markup, etag, lease string
|
||||
var version, next int64
|
||||
if e := st.DB.QueryRow(`SELECT body,body_html FROM feed_items WHERE source_uuid='s'`).Scan(&body, &markup); e != nil || body != "body" || markup != "" {
|
||||
t.Fatal("body migration", body, markup, e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT version,next_ms,etag,lease FROM feed_sources WHERE uuid='s'`).Scan(&version, &next, &etag, &lease); e != nil || version != 2 || next != 0 || etag != "" || lease != "" {
|
||||
t.Fatal("refetch/fence", version, next, etag, lease, e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT count(*) FROM feed_items`).Scan(&count); e != nil || count != 1 {
|
||||
t.Fatal("lost data", e)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.feeds-page{height:100dvh;overflow:hidden;display:flex;flex-direction:column;background:var(--bg);color:var(--fg)}
|
||||
#feed-status:empty{display:none}#feed-reader .feed-body-html{white-space:normal}.feed-original{display:inline-flex;align-items:center;justify-content:center;min-width:2rem;min-height:2rem;border-radius:.2rem}.feed-original:hover{background:var(--border,#8883)}.feed-original svg{width:1.1rem;height:1.1rem;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
|
||||
.feeds-page .topbar,.feeds-page .organizer-nav{flex-shrink:0}.feeds-page #feeds-app{flex:1;min-height:0;display:flex;flex-direction:column;width:100%;max-width:none;margin:0;padding:0 .5rem .25rem;box-sizing:border-box}
|
||||
#feed-toolbar{display:flex;align-items:center;gap:.35rem;min-height:2.5rem;flex-wrap:wrap}#feed-toolbar input{flex:1;min-width:8rem;max-width:32rem}#feeds-app button,#feeds-app input,#feeds-app select{font:inherit;color:inherit;background:var(--panel,var(--bg));border:1px solid var(--border,#6666);border-radius:.2rem;padding:.2rem .45rem;min-height:1.8rem}#feeds-app button{cursor:pointer}#feeds-app button:disabled{opacity:.45;cursor:default}#feeds-app a{color:var(--accent,#659de4)}#feed-status{margin:0;min-height:1.25rem;font-size:.78rem;color:var(--muted,var(--fg));overflow-wrap:anywhere}
|
||||
.feed-layout{flex:1;min-height:0;display:grid;grid-template-columns:12rem minmax(18rem,1fr) minmax(18rem,42%);border:1px solid var(--border,#6666)}#feed-sources,.feed-index,#feed-reader{min-width:0;min-height:0;overflow:auto;overscroll-behavior:contain}#feed-sources{border-right:1px solid var(--border,#6666);padding:.3rem}.feed-source{display:flex;align-items:center}.feed-source>button:first-child{flex:1;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border:0!important}.feed-source small{font-size:.68rem}.feed-source[aria-current=true]{background:color-mix(in srgb,var(--accent,#659de4) 20%,transparent)}#feed-sources h3{font-size:.75rem;margin:.5rem 0 .15rem}.feed-index{display:flex;flex-direction:column}#feed-rows{flex:1;min-height:0;overflow:auto;outline-offset:-2px}#feed-columns,.feed-row{display:grid;grid-template-columns:1.8rem 5.4rem 8rem minmax(0,1fr);align-items:center;gap:.3rem;font-size:.8rem;padding:.25rem .4rem;box-sizing:border-box}#feed-columns{font-size:.7rem;border-bottom:1px solid var(--border,#6666);opacity:.7}.feed-row{cursor:pointer;min-height:1.85rem;content-visibility:auto;contain-intrinsic-size:auto 30px}.feed-row>span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.feed-row.unread{font-weight:650}.feed-row[aria-selected=true]{background:color-mix(in srgb,var(--accent,#659de4) 24%,var(--bg,#16191f));box-shadow:inset 3px 0 var(--accent,#659de4)}.feed-row:hover{background:color-mix(in srgb,var(--accent,#659de4) 12%,transparent)}#feed-reader{border-left:1px solid var(--border,#6666);padding:.75rem}#feed-reader h1{font-size:1.1rem;margin:0 0 .4rem;overflow-wrap:anywhere}#feed-reader .feed-body{white-space:pre-wrap;overflow-wrap:anywhere;font-family:inherit;font-size:.9rem;line-height:1.6}.feed-actions{display:flex;flex-wrap:wrap;gap:.3rem;align-items:center}.feed-meta{font-size:.75rem;opacity:.7;margin:.4rem 0}#feed-keys{font-size:.72rem;padding:.3rem;opacity:.75}#feeds-app form{display:grid;gap:.5rem}#feeds-app form label{display:grid;gap:.2rem;font-size:.85rem}#feeds-app form input,#feeds-app form select{width:100%;box-sizing:border-box}#feeds-app form .feed-actions{display:flex}#feeds-app .feed-warning{font-size:.8rem;line-height:1.5;opacity:.8}.feed-source-error{color:var(--danger,#e57a7a)}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
.organizer-nav a{display:flex;align-items:center;gap:.4rem;padding:.4rem .7rem;border-radius:.4rem;color:var(--link,var(--accent));text-decoration:none;white-space:nowrap;font-size:.9rem}
|
||||
.organizer-nav a[aria-current=page]{background:color-mix(in srgb,var(--accent,#478ddd) 15%,transparent);box-shadow:inset 0 -2px var(--accent,#478ddd);color:var(--fg)}
|
||||
.organizer-nav a:hover{background:var(--row-hover,var(--border-soft,#8882))}
|
||||
@media(max-width:700px){.organizer-nav a span{display:none}.organizer-nav a{justify-content:center;min-width:2.75rem;min-height:2.75rem;box-sizing:border-box}}
|
||||
.organizer-nav-icons{display:flex;align-items:center;gap:.15rem}.organizer-launch{display:inline-flex;align-items:center;justify-content:center;color:var(--fg);width:2.1rem;height:2.1rem;box-sizing:border-box;padding:.35rem;border-radius:50%}
|
||||
.organizer-launch svg{width:100%;height:100%;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}.organizer-launch:hover{color:var(--accent)}
|
||||
.organizer-page .topbar{flex-wrap:wrap;gap:.2rem}.organizer-settings-content{min-width:0;padding:.75rem 1rem}.organizer-settings-content #task-productivity{margin:0;padding:0}.organizer-calendar-options{display:grid;gap:.4rem}.organizer-calendar-options label{display:flex;align-items:center;gap:.5rem;min-height:2rem}
|
||||
|
||||
+12
-12
@@ -18,37 +18,39 @@
|
||||
toolbar.append(button('?',t('Keyboard shortcuts','キー操作'),showHelp));
|
||||
let debounce;searchbox.addEventListener('input',()=>{clearTimeout(debounce);debounce=setTimeout(()=>{search=searchbox.value.trim();load(false).catch(report);},180);});
|
||||
const columns=document.getElementById('feed-columns');for(const s of ['',t('Date','日付'),t('Feed','配信元'),t('Subject','件名')])columns.append(el('span',s));
|
||||
document.getElementById('feed-keys').textContent=t('j/k move · Enter read · Esc index · / search · n unread · m read/unread · * star · r refresh · ? help','j/k 移動 · Enter 本文 · Esc 一覧 · / 検索 · n 次の未読 · m 既読/未読 · * star · r 背景更新 · ? ヘルプ');
|
||||
function showHelp(){status.textContent=document.getElementById('feed-keys').textContent+' · '+t('FreshRSS state is read-only. Reading never marks it read automatically.','FreshRSSの状態は読取専用です。表示だけで自動既読にはしません。');}
|
||||
function showHelp(){status.textContent=t('j/k move · Enter read · Esc index · / search · n unread · m read/unread · * star · r refresh','j/k 移動 · Enter 本文 · Esc 一覧 · / 検索 · n 次の未読 · m 既読/未読 · * star · r 更新');}
|
||||
function date(ms){return ms?new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{month:'2-digit',day:'2-digit'}).format(new Date(ms)):'—';}
|
||||
function closeReader(){editing=false;detailSeq++;detailController?.abort();layout.classList.remove('reading');rows.focus();}
|
||||
function drawSources(){sourcesView.replaceChildren();const all=button(t('All sources','すべての購読元'),'',()=>chooseSource(''));sourcesView.append(all);let folder=null;
|
||||
for(const source of sources){if(folder!==source.folder){folder=source.folder;sourcesView.append(el('h3',folder||t('Sources','購読元')));}const row=el('div',undefined,'feed-source');row.setAttribute('aria-current',String(currentSource===source.uuid));
|
||||
const b=button((source.enabled?'':'⏸ ')+source.title,source.title,()=>chooseSource(source.uuid));if(source.error){b.classList.add('feed-source-error');b.title+=' · '+source.error;}row.append(b);if(writable)row.append(button('⚙',t('Source settings','購読元設定'),()=>sourceForm(source)));sourcesView.append(row);
|
||||
}if(!sources.length)sourcesView.append(el('p',t('Add an RSS/Atom URL or FreshRSS API source.','RSS/Atom URLまたはFreshRSS APIを追加してください。'),'feed-warning'));
|
||||
}
|
||||
}
|
||||
async function chooseSource(id){currentSource=id;drawSources();layout.classList.remove('sources-open','reading');editing=false;await load(false);}
|
||||
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=t('Load next 100 ↓','次の100件 ↓');if(!items.length)rows.append(el('p',t('No cached articles. Add a source or wait for background refresh.','取得済みの記事はありません。購読元を追加し、背景更新をお待ちください。'),'feed-warning'));}
|
||||
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});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(el('p',t('Select an article.','記事を選択してください。')));layout.classList.remove('reading');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=items.length+t(' cached articles · up to 500/source; FreshRSS fetches the latest 200 per refresh.','件を表示 · 購読元ごとに最大500件保持/FreshRSSは更新ごとに最新200件取得。');
|
||||
if(!append){detailSeq++;items=[];selected=-1;reader.replaceChildren();layout.classList.remove('reading');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;drawSources();await load(false);}
|
||||
async function queueRefresh(){const targets=sources.filter(s=>s.enabled&&(!currentSource||currentSource===s.uuid));let queued=0;for(const s of targets){await post('sources/'+s.uuid+'/refresh',{version:s.version});queued++;}status.textContent=queued+t(' sources queued. Refreshing runs in the background; reload the list shortly.','件を予約しました。取得は背景で実行されます。少し待って一覧を再読込してください。');}
|
||||
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'});
|
||||
layout.classList.add('reading');reader.replaceChildren(el('p',t('Loading…','読み込み中…')));const item=(await request('item?'+new URLSearchParams({source:items[index].source,id:items[index].id}),{signal:detailController.signal})).item;if(version!==detailSeq)return;items[index]=item;renderItem(item);
|
||||
}
|
||||
function renderItem(item){reader.replaceChildren();const actions=el('div',undefined,'feed-actions');actions.append(button('←',t('Back to list','一覧へ戻る'),closeReader));
|
||||
const read=button(item.read?'●':'○',t('Toggle read state (m)','既読/未読 (m)'),()=>setState(!item.read,item.starred));const star=button(item.starred?'★':'☆',t('Toggle star (*)','star切替 (*)'),()=>setState(item.read,!item.starred));read.disabled=star.disabled=!writable||item.provider!=='local';actions.append(read,star);
|
||||
if(item.url){const a=el('a',t('Original ↗','原文 ↗'));a.href=item.url;a.target='_blank';a.rel='noopener noreferrer';actions.append(a);}
|
||||
if(item.url){const a=el('a',undefined,'feed-original');a.title=a.ariaLabel=t('Open original','原文を開く');a.href=item.url;a.target='_blank';a.rel='noopener noreferrer';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','M14 3h7v7M21 3l-11 11M10 5H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5');svg.append(path);a.append(svg);actions.append(a);}
|
||||
if(writable)actions.append(button(t('+ Wiki / Task','+ Wiki・タスク'),t('Capture with attribution','出典付きで取り込む'),()=>captureForm(item)));
|
||||
reader.append(actions,el('h1',item.title||t('(Untitled)','(無題)')),el('p',(item.feed||'')+' · '+(item.published_ms?new Date(item.published_ms).toLocaleString():t('Date unknown','日付不明')),'feed-meta'));
|
||||
if(item.provider==='freshrss')reader.append(el('p',t('FreshRSS is authoritative. Read/star changes are not enabled in this read-only connector.','FreshRSSが正本です。この読取連携では既読・starを変更しません。'),'feed-warning'));
|
||||
reader.append(el('div',item.body||t('(No article text)','(本文なし)'),'feed-body'));
|
||||
if(item.provider==='freshrss')read.title=star.title=t('FreshRSS · read only','FreshRSS · 読取専用');
|
||||
const body=el('div',undefined,'feed-body');
|
||||
if(item.body_html){body.classList.add('feed-body-html');const shadow=body.attachShadow({mode:'open'}),style=el('style',':host{display:block;overflow-wrap:anywhere;line-height:1.6}p{margin:.6em 0}h1,h2,h3{line-height:1.3}a{color:var(--link,var(--accent,#659de4))}pre{white-space:pre-wrap;overflow-wrap:anywhere;padding:.5em;background:color-mix(in srgb,currentColor 5%,transparent)}blockquote{margin:.5em 0;padding-left:1em;border-left:3px solid var(--border,#8885)}table{border-collapse:collapse;max-width:100%;display:block;overflow:auto}th,td{padding:.3em .6em;border:1px solid var(--border,#8885)}');const content=el('div');content.innerHTML=item.body_html;shadow.append(style,content);}
|
||||
else body.textContent=item.body||t('(No article text)','(本文なし)');
|
||||
reader.append(body);
|
||||
}
|
||||
async function setState(read,starred){const item=items[selected];if(!item||!writable||item.provider!=='local')return;const source=item.source,id=item.id;const data=await post('state',{source,id,read,starred,version:item.version});Object.assign(item,{read,starred,version:data.version});drawRows();if(items[selected]===item&&!editing)renderItem(item);}
|
||||
function field(form,label,value='',type='text'){const wrap=el('label',label),input=el('input');input.type=type;input.value=value;wrap.append(input);form.append(wrap);return input;}
|
||||
@@ -60,11 +62,10 @@
|
||||
const interval=field(form,t('Refresh interval (minutes, 5–1440)','更新間隔(分、5〜1440)'),String((source?.interval_seconds||1800)/60),'number');interval.min='5';interval.max='1440';interval.required=true;
|
||||
const enabled=field(form,t('Enabled','有効'),'','checkbox');enabled.checked=source?source.enabled:true;
|
||||
const toggle=()=>{user.parentElement.hidden=password.parentElement.hidden=!!source||provider.value!=='freshrss';user.required=password.required=!source&&provider.value==='freshrss';};provider.onchange=toggle;toggle();
|
||||
form.append(el('p',t('Background only. Public HTTPS/443, no redirects or private addresses. To change the endpoint or credentials, create a new source. Existing Wiki/tasks are not deleted with a source.','背景取得のみ。公開HTTPS/443に限定し、リダイレクト・内部アドレスは拒否します。接続先や資格情報の変更は新しい購読元を作成してください。削除しても保存済みWiki・タスクは残ります。'),'feed-warning'));
|
||||
if(source)form.append(el('p',t('Last success: ','最終成功: ')+(source.last_ms?new Date(source.last_ms).toLocaleString():'—')+' · '+(source.error||'OK'),'feed-meta'));
|
||||
const sourceID=source?.uuid||crypto.randomUUID();
|
||||
const save=el('button',t('Save','保存'));save.type='submit';buttons.append(save,button(t('Cancel','取消'),'',closeReader));if(source)buttons.append(button(t('Delete source','購読元を削除'),'',async()=>{if(!confirm(t('Delete this source, cached articles and local read/star state?','購読元・取得記事・内蔵の既読/star状態を削除しますか?')))return;await post('sources/'+source.uuid+'/delete',{version:source.version});currentSource='';await reload();}));form.append(buttons);
|
||||
form.onsubmit=async event=>{event.preventDefault();save.disabled=true;try{await post('sources',{uuid:sourceID,version:source?.version||0,provider:provider.value,title:title.value,folder:folder.value,url:url.value,interval_seconds:Number(interval.value)*60,enabled:enabled.checked,username:user.value,password:password.value});password.value='';await reload();status.textContent=t('Saved. Background synchronization will run shortly.','保存しました。背景同期が順次実行されます。');}catch(e){report(e);}finally{save.disabled=false;}};title.focus();
|
||||
form.onsubmit=async event=>{event.preventDefault();save.disabled=true;try{await post('sources',{uuid:sourceID,version:source?.version||0,provider:provider.value,title:title.value,folder:folder.value,url:url.value,interval_seconds:Number(interval.value)*60,enabled:enabled.checked,username:user.value,password:password.value});password.value='';await reload();status.textContent=t('Saved','保存しました');}catch(e){report(e);}finally{save.disabled=false;}};title.focus();
|
||||
}
|
||||
function captureForm(item){
|
||||
editing=true;detailSeq++;reader.replaceChildren();const form=el('form');reader.append(form);form.append(el('h1',t('Attributed Wiki note / task','出典付きWikiメモ・タスク')));
|
||||
@@ -74,7 +75,6 @@
|
||||
const notes=field(form,t('Your note','メモ'));const copy=field(form,t('Include cached text (explicit copy)','取得済み本文も保存する(明示コピー)'),'','checkbox');
|
||||
const confirm=field(form,t('I checked the destination publication policy and the material to copy.','保存先の公開範囲と、コピーする内容を確認しました。'),'','checkbox');confirm.required=true;
|
||||
const validate=()=>{prefix.required=!task.checked;confirm.required=!!prefix.value.trim()||!task.checked;};task.onchange=prefix.oninput=validate;
|
||||
form.append(el('p',t('Stored as inert text with attribution. No full website fetch. A Wiki note and optional task survive source deletion.','出典付きの安全なテキストとして保存します。原文サイトの全文取得はしません。購読元を削除してもWiki・タスクは残ります。'),'feed-warning'));
|
||||
const save=el('button',t('Create','作成'));save.type='submit';form.append(save,button(t('Cancel','取消'),'',()=>{editing=false;renderItem(item);}));let pending=null;
|
||||
form.onsubmit=async event=>{event.preventDefault();const body='Source: '+item.url+'\nFeed: '+item.feed+'\n\n'+notes.value+(copy.checked?'\n\n'+item.body:'');const spec={title:title.value,notes:notes.value,prefix:prefix.value.trim(),body,task:task.checked};const fingerprint=JSON.stringify(spec);if(!pending||pending.fingerprint!==fingerprint)pending={fingerprint,request_id:crypto.randomUUID()};save.disabled=true;
|
||||
try{let data;if(task.checked){const input={request_id:pending.request_id,title:title.value,notes:(notes.value+'\nSource: '+item.url).trim()};if(spec.prefix){input.wiki_prefix=spec.prefix;input.wiki_body=body;}const res=await fetch('/_/api/v1/extension/organizer.tasks/capture',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify(input)});data=await res.json().catch(()=>({}));if(!res.ok||res.redirected)throw Error(t('Capture failed: ','作成に失敗: ')+(data.error||res.status));}
|
||||
|
||||
@@ -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=1"></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=2"></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>
|
||||
<footer id="feed-keys"></footer></main><script src="/static/js/feeds.js?v=1" defer></script></body></html>{{ end }}
|
||||
</main><script src="/static/js/feeds.js?v=2" defer></script></body></html>{{ end }}
|
||||
@@ -1,11 +1,11 @@
|
||||
{{ define "organizer-nav" }}
|
||||
<link rel="stylesheet" href="/static/css/organizer.css?v=1">
|
||||
<link rel="stylesheet" href="/static/css/organizer.css?v=2">
|
||||
<nav class="organizer-nav" aria-label="{{ T "organizer.title" }}">
|
||||
{{ if .FeedsEnabled }}<a href="/v/feeds" {{ if eq .OrganizerSection "feeds" }}aria-current="page"{{ end }}>◉ <span>{{ T "feeds.title" }}</span></a>{{ end }}
|
||||
{{ if .TasksEnabled }}<a href="/v/plan/dashboard" {{ if eq .OrganizerSection "dashboard" }}aria-current="page"{{ end }}>▦ <span>{{ T "organizer.dashboard" }}</span></a><a href="/v/plan/tasks" {{ if eq .OrganizerSection "tasks" }}aria-current="page"{{ end }}>✓ <span>{{ T "tasks.title" }}</span></a>{{ end }}
|
||||
{{ if .CalendarEnabled }}<a href="/v/plan" {{ if eq .OrganizerSection "calendar" }}aria-current="page"{{ end }}>▤ <span>{{ T "calendar.title" }}</span></a>{{ end }}
|
||||
{{ if .ContactsEnabled }}<a href="/v/plan/contacts" {{ if eq .OrganizerSection "contacts" }}aria-current="page"{{ end }}>♧ <span>{{ T "organizer.contacts" }}</span></a>{{ end }}
|
||||
{{ if .AuthUser }}<a href="/-/sys/config?panel=organizer" {{ if eq .OrganizerSection "settings" }}aria-current="page"{{ end }}>⚙ <span>{{ T "organizer.settings" }}</span></a>{{ end }}
|
||||
{{ if .FeedsEnabled }}<a href="/v/feeds" title="{{ T "feeds.title" }}" aria-label="{{ T "feeds.title" }}" {{ if eq .OrganizerSection "feeds" }}aria-current="page"{{ end }}>◉ <span>{{ T "feeds.title" }}</span></a>{{ end }}
|
||||
{{ if .TasksEnabled }}<a href="/v/plan/dashboard" title="{{ T "organizer.dashboard" }}" aria-label="{{ T "organizer.dashboard" }}" {{ if eq .OrganizerSection "dashboard" }}aria-current="page"{{ end }}>▦ <span>{{ T "organizer.dashboard" }}</span></a><a href="/v/plan/tasks" title="{{ T "tasks.title" }}" aria-label="{{ T "tasks.title" }}" {{ if eq .OrganizerSection "tasks" }}aria-current="page"{{ end }}>✓ <span>{{ T "tasks.title" }}</span></a>{{ end }}
|
||||
{{ if .CalendarEnabled }}<a href="/v/plan" title="{{ T "calendar.title" }}" aria-label="{{ T "calendar.title" }}" {{ if eq .OrganizerSection "calendar" }}aria-current="page"{{ end }}>▤ <span>{{ T "calendar.title" }}</span></a>{{ end }}
|
||||
{{ if .ContactsEnabled }}<a href="/v/plan/contacts" title="{{ T "organizer.contacts" }}" aria-label="{{ T "organizer.contacts" }}" {{ if eq .OrganizerSection "contacts" }}aria-current="page"{{ end }}>♧ <span>{{ T "organizer.contacts" }}</span></a>{{ end }}
|
||||
{{ if .AuthUser }}<a href="/-/sys/config?panel=organizer" title="{{ T "organizer.settings" }}" aria-label="{{ T "organizer.settings" }}" {{ if eq .OrganizerSection "settings" }}aria-current="page"{{ end }}>⚙ <span>{{ T "organizer.settings" }}</span></a>{{ end }}
|
||||
</nav>{{ end }}
|
||||
{{ define "organizer-shortcuts" }}
|
||||
{{ if .FeedsEnabled }}<a href="/v/feeds" class="organizer-launch" data-home-shortcut="feeds" title="{{ T "feeds.title" }}" aria-label="{{ T "feeds.title" }}"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="5" cy="19" r="1"/><path d="M4 11a9 9 0 0 1 9 9M4 4a16 16 0 0 1 16 16"/></svg></a>{{ end }}
|
||||
|
||||
Reference in new issue
Block a user