Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16e572397b | ||
|
|
bfed3d20f5 | ||
|
|
7fe64113c7 | ||
|
|
38daea737d | ||
|
|
0d8997972c | ||
|
|
0c2cf263b6 | ||
|
|
269f835c3a | ||
|
|
b9e775de13 | ||
|
|
e65ca56f92 | ||
|
|
6e0aecdfb3 | ||
|
|
0964fdc5b7 | ||
|
|
c7aa4fd7dd | ||
|
|
1a451023f0 | ||
|
|
543814cbd6 | ||
|
|
3262f88005 | ||
|
|
0b6343aff0 |
No files matched your search
@@ -35,8 +35,8 @@ jobs:
|
||||
[worker.oci]
|
||||
max-parallelism = 2
|
||||
|
||||
- name: Test release tooling
|
||||
run: node --test tools/ci/release-images.test.mjs
|
||||
- name: Test release tooling and wallpaper palette
|
||||
run: node --test tools/ci/release-images.test.mjs static/js/home-palette-core.test.cjs
|
||||
|
||||
- name: Test
|
||||
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
|
||||
|
||||
+4
-1
@@ -11,7 +11,10 @@ RUN go mod download
|
||||
COPY . .
|
||||
|
||||
FROM source AS test
|
||||
RUN go test ./...
|
||||
# Test packages create independent SQLite stores. Serialize packages to avoid
|
||||
# concurrent server/store initialization exhausting the shared runner's I/O.
|
||||
# Keep production database deadlines and the complete test suite unchanged.
|
||||
RUN go test -p 1 ./...
|
||||
|
||||
FROM source AS runtime
|
||||
RUN go build -o /pageswiki ./cmd/pageswiki
|
||||
|
||||
@@ -1,5 +1,35 @@
|
||||
# Architecture Implementation Roadmap
|
||||
|
||||
## Current backlog reconciliation (2026-11-08)
|
||||
|
||||
Use the [Japanese implementation backlog](ja/implementation-backlog.md) for the current
|
||||
execution order, stable task IDs, acceptance criteria and explicit holds. Baseline: `e65ca56`.
|
||||
Broad historical checkboxes below may contain implemented slices; they are not a count of
|
||||
unimplemented features. Source completion, physical-client acceptance and production rollout
|
||||
remain separate gates. The 2026-10-31 UX priorities below are historical context.
|
||||
|
||||
## Daily email history and controlled retries (2026-11-08)
|
||||
|
||||
- [x] Private, paginated delivery history and explicit same-day retry from personal settings.
|
||||
- [x] Durable request receipts, attempt-generation fencing, opt-out/version/revocation rechecks and duplicate-delivery acknowledgment.
|
||||
- [x] Bounded 90-day detail cleanup; preserve daily reservations and retry receipts permanently.
|
||||
- [x] Additive schema v4 with old-state preservation, interrupted-migration rollback and integrity tests.
|
||||
- [ ] Production rollout; backup restoration must reconcile external SMTP effects before resuming delivery.
|
||||
- [ ] Retention controls, safe receipt compaction, queued-request cancellation and Inbox outcomes.
|
||||
|
||||
See [delivery contracts and recovery](ja/task-digest-delivery.md).
|
||||
|
||||
## Work history and project reporting (2026-11-08)
|
||||
|
||||
- [x] Owner-scoped paginated work history with inline correction/cancellation and lazy revision display.
|
||||
- [x] Atomic immutable audit snapshots, optimistic concurrency, current authorization and cross-Domain overlap checks.
|
||||
- [x] Exclude cancelled time from reports; aggregate by current project without per-project queries.
|
||||
- [x] Task/dashboard navigation, Japanese/English UI and desktop/mobile browser coverage.
|
||||
- [ ] Production rollout with an aligned DB backup; old binaries must not read the upgraded DB.
|
||||
- [ ] Revoked-Domain recording recovery, cancellation restoration and audit retention policy.
|
||||
|
||||
See [work history contracts and migration](ja/task-productivity-contacts.md).
|
||||
|
||||
## Organizer dashboard (2026-11-02)
|
||||
|
||||
- [x] Common navigation for tasks, calendars, contacts and dashboard; home/navbar contacts entry.
|
||||
@@ -17,7 +47,7 @@ See [dashboard contracts](ja/organizer-dashboard.md). Production rollout is a se
|
||||
- [x] Add home search commands with project/calendar suggestions and explicit creation confirmation.
|
||||
- [x] Add private contacts CRUD, trash/restore, vCard import/export and unknown-property preservation.
|
||||
- [x] Add private CardDAV serving with isolated credentials, conditional writes, bounded reports and sync tokens; revision preview/restore and whole-book export (2026-11-02).
|
||||
- [ ] Shared address books, external CardDAV connectors, physical-device compatibility, work-record corrections and manual digest retry.
|
||||
- [ ] Shared address books, external CardDAV connectors and physical-device compatibility.
|
||||
|
||||
See [CardDAV operation and limits](../operations/carddav-contacts.md). The private profile is not full CardDAV compliance; production rollout is tracked separately.
|
||||
|
||||
@@ -78,9 +108,11 @@ See [component names, boundaries and acceptance criteria](ja/component-names.md)
|
||||
All eight initial component extractions are implemented; unchecked items describe remaining capabilities.
|
||||
Released and deployed as [v0.2.0](../operations/deployments/2026-11-01-v0.2.0.md) on 2026-11-01.
|
||||
|
||||
- [ ] Priority follow-up: eliminate AddEventLog deferred read-to-write transaction contention;
|
||||
preserve atomic raw-log/bucket writes and test independent concurrent writers. Production
|
||||
start-log failures are now observable; job execution succeeded, but log completeness is not guaranteed.
|
||||
- [x] Eliminate AddEventLog deferred read-to-write transaction contention with writer-first
|
||||
acquisition, atomic raw-log/bucket writes and independent concurrent-writer tests.
|
||||
Completion-log failure does not replay successful business work; see [Dregarnuhr](ja/dregarnuhr.md).
|
||||
- [ ] Recover missing logs, improve event-only fallback/retention and define completion/log
|
||||
atomicity. Writer-first acquisition does not guarantee all logs survive prolonged contention.
|
||||
|
||||
### Storage portability and operations (2026-09-27)
|
||||
|
||||
@@ -141,7 +173,10 @@ See [active notification contract](ja/active-notifications.md) and
|
||||
- [x] Private local calendar time-block links, durable retry intents, current event time/ETag lookup, unlink tombstones; imported/shared/public calendars excluded.
|
||||
- [x] Persistent Pomodoro: start/pause/resume/finish/cancel, one active session per principal, conditional transitions, bounded scheduler completion and Inbox notification.
|
||||
- [x] Today bounded estimates/current local time blocks/recorded focus intervals, overlap and incomplete-total indicators. Calendar event summaries include an explicitly approved task-title snapshot, never notes.
|
||||
- [ ] Personal capacity, carry-over and period/project reports; historical focus-span backfill; calendar reminders, notification defaults/quiet hours/digests; Pomodoro personal defaults/cycles and routines.
|
||||
- [x] Daily carry-over, work-period/current-project reports, personal notification defaults and
|
||||
opt-in daily task digest with delivery history and manual retry (source through 2026-11-08).
|
||||
- [ ] Personal capacity, historical focus-span backfill, general calendar reminders, quiet hours,
|
||||
Pomodoro personal defaults/cycles and routines; see TASK-01 / ORG-01 in the current backlog.
|
||||
|
||||
See [time-block and Pomodoro contracts](ja/task-planning-focus.md) for API, privacy,
|
||||
two-store recovery, polling limits and remaining work. Canonical calendars and task
|
||||
@@ -190,14 +225,16 @@ System-service plugins are distinct from document adapters. See
|
||||
- [x] Separate system-extension catalog and settings area for trusted built-ins.
|
||||
- [x] Unified execution/resource monitor (running jobs only), paginated job history with lazy logs.
|
||||
- [x] Protect group owners from ordinary member downgrades and atomically retain an owner during concurrent removal.
|
||||
- [ ] Transactional activity outbox and Domain/principal recent-edit projections.
|
||||
- [x] Transactional Domain-sequenced activity outbox and independent typed consumer checkpoints;
|
||||
task/project source mutations append atomically. See [delivery contract](ja/outbox-delivery.md).
|
||||
- [ ] General Domain/principal recent-edit projections, consumer operations and safe outbox retention.
|
||||
- [x] Diary/blog initial built-ins: Page UUID metadata, calendar/recent entries,
|
||||
categories, read-filtered indices, per-Domain enable/disable and registration UI.
|
||||
See [initial scope](diary-blog-plugins.md); this is authenticated, existing-Page registration only.
|
||||
- [x] Diary/blog atomic Markdown new-post composition, transactional metadata/Revision,
|
||||
embedded-asset freezing, idempotent retry and create/write enforcement.
|
||||
- [ ] Diary/blog: anonymous metadata approval/feeds,
|
||||
recent comments and safe resumable tDiary import; declarative time/OS/sunset theme rules.
|
||||
- [x] Diary/blog approved anonymous metadata and full-body RSS feeds; see [current scope](ja/blog-diary.md).
|
||||
- [ ] Recent comments and safe resumable tDiary import; declarative time/OS/sunset theme rules.
|
||||
- [x] Diary/blog per-Domain prefixes, optional keyword URL planner, multiple articles
|
||||
per day, and authenticated Domain-root diary/blog entry view (2026-09-17).
|
||||
Legacy Page registration remains available.
|
||||
@@ -211,8 +248,8 @@ System-service plugins are distinct from document adapters. See
|
||||
filter, legacy-query redirects, and canonical calendar/filter/pagination navigation.
|
||||
- [x] Local same-Campus diary/blog index/calendar projection without copying articles;
|
||||
source and destination read-policy filtering, source body/edit links, target write guard.
|
||||
- [ ] Project article bodies on destination host, approved anonymous projection,
|
||||
cross-instance source transport/revocation and source-setting federation.
|
||||
- [x] Same-instance destination-host article bodies, approved anonymous projection and RSS.
|
||||
- [ ] Cross-instance source transport/revocation and source-setting federation.
|
||||
- [ ] Rankings, reactions and moderated Page/inline comment services.
|
||||
- [ ] Linkding-compatible bookmark-source injection with scoped credentials.
|
||||
- [ ] Explicit external-search fallback and PagesWiki/GROWI/PukiWiki connectors.
|
||||
@@ -456,7 +493,8 @@ See [Home layouts and sidebar design](navigation-home-sidebar.md).
|
||||
manifests, inert HTML, mutation invalidation and denial/revocation tests.
|
||||
- [ ] Extend those gates to anonymous discovery/dependencies and delegated
|
||||
shares with full impact-aware mutation/alias handling.
|
||||
- [ ] Add Domain groups, group Role bindings, and `/g/` management surfaces.
|
||||
- [x] Add Domain groups, group Role bindings, and `/g/` management surfaces.
|
||||
Full authorization auditing and external group mapping remain separate gates.
|
||||
- [ ] Add explicit OIDC/LDAP group mappings and policy-version invalidation;
|
||||
LDAP authentication must remain usable without enabling group synchronization.
|
||||
- [ ] Add auditable policy decisions.
|
||||
@@ -473,11 +511,12 @@ These items must land before the later feature that depends on them. They are
|
||||
listed separately because they replace concrete single-feature assumptions
|
||||
without changing user-visible Page identity.
|
||||
|
||||
- [ ] Put filesystem `DocumentRoot` access behind the seekable, content-addressed
|
||||
Document Store interface before adding S3 or multi-node payload placement.
|
||||
- [ ] Generalize topology/event-job records into a versioned transactional
|
||||
Domain event outbox before notifications, feeds, metrics, comments, or DR
|
||||
consume mutation events.
|
||||
- [x] Introduce the seekable, content-addressed Document Store interface and Geduldh
|
||||
local payload/materialization adapter. External backends, legacy context propagation
|
||||
and placement contracts remain open; see [Geduldh](ja/geduldh.md).
|
||||
- [x] Introduce a transactional Domain event outbox with typed subscriptions and checkpoints.
|
||||
- [ ] Extend producer coverage and replay/retention contracts before new consumers depend on it;
|
||||
see [remaining delivery work](ja/outbox-delivery.md).
|
||||
- [ ] Add a typed extension manifest and provider registry before adding third-
|
||||
party transpilers, widgets, scanners, storage backends, or themes.
|
||||
- [ ] Inventory process-local sessions, caches, preview slots, scheduler state,
|
||||
@@ -550,10 +589,11 @@ without changing user-visible Page identity.
|
||||
- [ ] Formalize a Domain-sequenced event outbox for Page, Revision, Path,
|
||||
topology, policy, share, comment, reaction, quality, and federation events.
|
||||
- [ ] Add Page/Spot/Street/Quartier subscription and change-notification rules.
|
||||
- [ ] Add a per-Principal notification inbox with unread state, grouping,
|
||||
filtering, retention, cursor pagination, and authorization-safe deep links.
|
||||
- [ ] Add delivery channels for Web inbox, email digest, webhook, and future
|
||||
push adapters, with retry/dead-letter state in the event scheduler.
|
||||
- [x] Per-Principal Inbox, unread state, cursor pagination, topbar/modal/detail UI,
|
||||
task/broadcast producers and current-authorization checks for supported types.
|
||||
- [ ] General notification grouping/filtering/retention and new-producer authorization coverage.
|
||||
- [x] Web Inbox, opt-in Web Push and daily task email; their delivery contracts are distinct.
|
||||
- [ ] General channel subscriptions, webhook delivery, quiet hours and retry/dead-letter operations.
|
||||
- [ ] Add recently edited and recently viewed Page projections; keep private
|
||||
activity private and provide retention/opt-out controls.
|
||||
- [ ] Add privacy-aware Page view counters with bot filtering, idempotent event
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Implementation status and hardening backlog
|
||||
|
||||
2026-11-08 reconciliation: use the [current Japanese implementation backlog](ja/implementation-backlog.md)
|
||||
for actionable IDs, priorities, dependencies and acceptance gates, based on `e65ca56`.
|
||||
This is a source/document audit, not a production audit or a new deployment.
|
||||
|
||||
For the consolidated current reading order, use the [Japanese handbook](ja/index.md)
|
||||
and [decision register](ja/decisions.md). Dated entries below preserve history;
|
||||
older statements about missing anonymous navigation, blog publication or RSS are
|
||||
@@ -13,6 +17,28 @@ security.
|
||||
|
||||
## Current state
|
||||
|
||||
2026-11-08 digest follow-up: private delivery history and explicit same-day retry
|
||||
are implemented in source. Manual requests are queued for the existing scheduler;
|
||||
attempt IDs fence stale completions, and consent/version/authorization are checked
|
||||
again before SMTP. Detailed terminal attempts expire after 90 days, while daily
|
||||
reservations and request receipts remain. Additive schema v4 and recovery rules
|
||||
preserve duplicate prevention; production rollout remains deferred. See
|
||||
[delivery history and migration](ja/task-digest-delivery.md).
|
||||
|
||||
2026-11-08 work history: owner-only bounded history, inline correction/cancellation,
|
||||
immutable audit snapshots and project-level reports are implemented in source.
|
||||
Cancelled spans leave the report but not the audit. Task/dashboard navigation and
|
||||
Japanese/English desktop/mobile UI are connected. Schema migration v3 requires an
|
||||
aligned DB backup before production rollout; do not hot-swap older binaries onto
|
||||
the upgraded DB. See [contracts and remaining scope](ja/task-productivity-contacts.md).
|
||||
|
||||
The dated task/inbox paragraphs below describe earlier slices. VTODO, time blocks,
|
||||
Pomodoro, active notifications, daily task email, private CardDAV and the organizer
|
||||
dashboard have since been implemented. Their remaining work is shared access,
|
||||
external connectors, conflict resolution and retention, not reimplementation of
|
||||
the existing private interfaces. The [Japanese roadmap](ja/roadmap.md) tracks the
|
||||
current order.
|
||||
|
||||
2026-09-25 task reminders: explicit per-task due/planned-date switches and a local
|
||||
notification time now schedule owner-only Inbox reminders. Reservations are updated
|
||||
in the source transaction; the bounded scheduler rechecks current state/authority,
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
| --- | --- | --- |
|
||||
| Wiki URL | 人が開く説明・知識への入口 | rename可能なPage Path |
|
||||
| iCalendar | 予定・タスク等の交換形式 | export/import、UIDと元データを保持 |
|
||||
| CalDAV | カレンダー資源を扱うWebDAV拡張 | remote connector、将来の提供面 |
|
||||
| CardDAV / vCard | 連絡先の通信 / データ形式 | 個人・共有address book |
|
||||
| CalDAV | カレンダー資源を扱うWebDAV拡張 | 読取remote connectorと限定VEVENT/VTODO提供面は実装済み |
|
||||
| CardDAV / vCard | 連絡先の通信 / データ形式 | 個人address book提供は実装済み、共有・外部connectorは後続 |
|
||||
|
||||
iCalendarとCalDAVは同義ではなく、`.ics`を配信するだけでCalDAVサーバーにはなりません。vCardとCardDAVも区別します。[RFC 5545](https://www.rfc-editor.org/rfc/rfc5545)、[RFC 4791](https://www.rfc-editor.org/rfc/rfc4791)、[RFC 6350](https://www.rfc-editor.org/rfc/rfc6350)、[RFC 6352](https://www.rfc-editor.org/rfc/rfc6352)。
|
||||
|
||||
@@ -29,7 +29,7 @@ local item UUID、calendar UID、remote href、Wiki Page UUIDを対応表に持
|
||||
|
||||
connectorはremote ETagとlocal versionを別々に持ち、更新前の値で条件付き操作します。ETagをDocument SHA-256と仮定しません。対応サーバーではcollection sync-tokenを利用する案ですが、無効なtokenからの再同期と未対応時のboundedな全量照合も必要です。[WebDAV同期仕様](https://www.rfc-editor.org/rfc/rfc6578)。
|
||||
|
||||
通信失敗では外部削除と見なさず、tombstoneは確認できた削除だけです。両側で変更された場合はbase/local/remoteを比較し、内容を保存した競合状態へ移します。勝手な最新版上書きはしません。
|
||||
外部connectorの設計では、通信失敗を外部削除と見なさず、tombstoneは確認できた削除だけにします。双方向書込を追加する際はbase/local/remoteを保存して競合選択へ進めます。これを現在の全DAV入口の挙動とは扱いません。タスク提供面では利用者指定により無条件PUT/DELETEを上書き受理し履歴を保持します。競合候補・通知・採否選択は[所属統一の後続](task-dav-project-unification.md)で、読取外部カレンダーconnectorとは別契約です。
|
||||
|
||||
## 連絡先
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
| ADR-O1 | organizerはtyped metadataと任意Page参照 | タスク初版は専用表+既存CAS Document Store(2026-09-24)。通常のObject閲覧・リンク・削除の権限境界を拡大せず、個人所有を確実に分離する。DBは捨てられる索引ではない。[実装契約](tasks-implementation.md) |
|
||||
| ADR-O2 | task共通部+ticket workflow | 提案。番号・外部依頼者・遷移権限の要件確認 |
|
||||
| ADR-O3 | ICS/vCard入出力→read-only DAV→双方向 | 推奨順。対象サーバー/clientを選んで互換表を作る |
|
||||
| ADR-O4 | FreshRSS正本+PagesWiki connector+newsboat | 第一候補。利用環境・追加運用負荷を確認。内蔵readerは代案 |
|
||||
| ADR-O4 | 簡易利用は内蔵正本、本格運用はFreshRSS正本+PagesWiki connector+newsboat | 2026-11-08利用者指定で採用。内蔵・FreshRSS読取・共通UI・OPML入出力まで実装。source単位で正本を分離し、自動fallbackや二重管理はしない。外部書戻しは残件。実環境の接続先・版・資格情報は別途指定 |
|
||||
| ADR-O5 | IMAP read-only、Wikiコピーは明示操作 | 初期設計方針。providerとsampleが実装前提 |
|
||||
| ADR-O6 | HTMLパーツを先行し全面WYSIWYGは保留 | 提案。round-tripと操作改善の評価でgo/no-go |
|
||||
| ADR-O7 | Wiki Pathと外部UID/hrefを分離 | 共通の設計制約。rename fixtureを全connectorで実施 |
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
## 未決事項
|
||||
|
||||
利用するFreshRSSの有無と版、対象CalDAV/CardDAV client、IMAP provider、taskの共有単位、ticketの依頼者公開範囲、保持期限、外部接続を許可するhost、RPO/RTO、WYSIWYG採用基準です。これらが未決でもlocal fixtureと設計は進められますが、外部サービスを勝手に立ち上げたり資格情報を流用したりしません。
|
||||
利用するFreshRSSの接続先・版・資格情報、対象CalDAV/CardDAV client、IMAP provider、taskの共有単位、ticketの依頼者公開範囲、保持期限、外部接続を許可するhost、RPO/RTO、WYSIWYG採用基準です。これらが未決でもlocal fixtureと設計は進められますが、外部サービスを勝手に立ち上げたり資格情報を流用したりしません。
|
||||
|
||||
## 文書運用
|
||||
|
||||
|
||||
+227
-14
@@ -1,24 +1,131 @@
|
||||
# 15. RSSビューア・FreshRSS・newsboat
|
||||
|
||||
状態:設計案。既存のブログRSS「配信」と、本章の外部RSS「購読」は別機能。
|
||||
状態:内蔵簡易reader、FreshRSS読取connector、共通viewer、Wiki保存・タスク化、ダッシュボードを実装。
|
||||
OPMLの確認付き追加取り込み・書出し、FreshRSS購読・カテゴリのnavigationも実装済み。FreshRSSへの書戻しは残件。本番反映と実FreshRSSへの接続は未実施。
|
||||
既存のブログRSS「配信」と、本章の外部RSS「購読」は別機能。
|
||||
|
||||
## 選択肢と推奨する試作順
|
||||
2026-11-08:利用者指定のサブプロジェクト順で最初に実施する。内蔵readerは簡易利用の
|
||||
正本、本格運用はFreshRSSを正本とする。実環境の接続先・版・資格情報は別途指定する。
|
||||
|
||||
| 案 | 正本 | 利点 | 追加する責任 |
|
||||
## 正本と責務
|
||||
|
||||
| モード | 正本 | PagesWikiの役割 | 範囲 |
|
||||
| --- | --- | --- | --- |
|
||||
| PagesWiki内蔵reader | ローカルの購読と状態 | Wiki保存と一体のUI | 取得・既読・同期・client対応を全て持つ |
|
||||
| FreshRSS connector | FreshRSSの購読・既読 | 既存reader資産を利用 | API互換性、権限、cacheと失効 |
|
||||
| newsboat単独の橋渡し | newsboat側の購読・状態 | CLI利用に合わせやすい | ローカル連携経路・export/importの設計 |
|
||||
| 内蔵簡易reader | PagesWikiの購読・フォルダ・既読・star | feed取得、保持上限内の記事保存、閲覧とWiki保存 | 個人の簡易利用。外部reader向け同期サーバーや高度なルール機能は初期範囲外 |
|
||||
| FreshRSS連携 | FreshRSSの購読・フォルダ・記事・既読・star | 表示用cache、連携UI、Wiki保存・タスク化 | 本格運用。PagesWikiは独立した購読・既読の正本を重ねない |
|
||||
| newsboat等のclient | 接続先FreshRSS | PagesWikiと同じ正本を使う別clientとして扱う | PagesWiki経由の代理同期やnewsboatのDB共有は行わない |
|
||||
|
||||
FreshRSSにはGoogle Reader互換APIがあり、APIの有効化と専用passwordを使います。newsboatにはFreshRSS連携が用意され、カテゴリのtag化やstar操作を扱えます。[FreshRSS公式API](https://freshrss.github.io/FreshRSS/en/developers/06_GoogleReader_API.html)、[newsboat公式マニュアル](https://newsboat.org/releases/2.42/docs/newsboat.html#_freshrss)。
|
||||
|
||||
このため最初の候補は **FreshRSSを正本、PagesWikiを読取connector、newsboatを同じFreshRSSのclient** とする構成です。これは設計上の提案で、ユーザー環境のFreshRSS導入・採用決定ではありません。PagesWikiがnewsboatをサーバー上で起動したり、そのSQLiteを共有したりする必要はありません。
|
||||
本格運用は **FreshRSSを正本、PagesWikiとnewsboatをそのclient** とする構成を採用します。
|
||||
内蔵簡易readerも別providerとして提供し、共通の一覧・保存UIを使用します。FreshRSSを
|
||||
PagesWiki全体の必須依存にはせず、外部サービスの新設・接続は設定時の明示操作とします。
|
||||
|
||||
## 読取MVP
|
||||
sourceは一つのproviderに束縛し、記事キーはDomain/所有者/source UUID/remote IDで
|
||||
区別します。同じURLの記事でも別sourceの既読を自動統合しません。FreshRSSのcacheは
|
||||
再取得可能な派生データですが、内蔵の購読・状態は正本として保全対象にします。
|
||||
|
||||
購読一覧、フォルダ、記事一覧、外部原文、Wiki保存を提供します。初期段階では表示しただけでFreshRSSへ既読を送りません。UIには「読取専用・既読は同期していない」と明示します。ブラウザへFreshRSS password/tokenを渡さず、backend connectorがsecret参照を使います。
|
||||
FreshRSS停止時は取得済みcacheと鮮度・接続状態を示し、内蔵正本へ自動切替しません。
|
||||
外部操作の未送信状態は正本と区別し、成功していない既読・starを同期済みと表示しません。
|
||||
内蔵からFreshRSSへの移行はOPML等による明示的なexport/importとし、初期版では既読・star・
|
||||
記事IDの完全移行を保証しません。移行完了の確認前に内蔵データを削除しません。
|
||||
|
||||
最小cache案はsource UUID、remote feed/item ID、title、safe excerpt/body hash、canonical URL、published/updated/fetched時刻、remote state/versionです。IDなしRSSにはfeed単位の保守的な代替キーを使い、題名だけで重複排除しません。Atomはentry IDと更新情報を持つ形式です。[Atom仕様](https://www.rfc-editor.org/rfc/rfc4287)。
|
||||
## 実装済みの読取機能
|
||||
|
||||
`/v/feeds` に購読一覧、フォルダ、記事一覧、外部原文へのリンク、Wiki保存を提供します。
|
||||
FreshRSSの記事・既読・starは取得しますが、状態の変更は送信しません。UIにも読取専用と明示し、
|
||||
FreshRSS passwordを設定時以外にブラウザへ返さず、login tokenはbackend内でのみ利用します。
|
||||
資格情報は既存の暗号化機構を使い、Domain・所有者・source UUID・用途に束縛します。
|
||||
|
||||
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)。
|
||||
|
||||
### 高密度ビューア
|
||||
|
||||
newsboat/neomuttを参考に、デスクトップは左から購読元・一行記事一覧・本文の3ペインとします。
|
||||
一覧には未読/star、日付、配信元、件名を並べます。狭幅は一覧と本文を切り替え、スマホでは
|
||||
行とボタンのタッチ領域を広げます。モバイルの共通ナビはアイコンのみとし、名称はアクセシブル名と
|
||||
tooltipに残します。タブ名は「RSS」、原文リンクはアイコンです。件数・保持上限・操作の説明は常設せず、
|
||||
キー案内は`?`で表示します。設定と保存フォームは本文ペイン内に置き、モーダルを増やしません。
|
||||
|
||||
`j/k`・上下矢印で移動、`Enter/l`で本文、`Esc/h`で一覧、`/`で件名・配信元検索、`n`で次の未読、
|
||||
`m`で既読切替、`*`でstar、`r`で背景更新予約、`?`でキー案内です。フォーム入力・IME変換中は
|
||||
一覧ショートカットを抑止します。FreshRSSでは`m`と`*`も外部変更を行いません。
|
||||
|
||||
HTML本文は見出し・表・箇条書き・強調・リンクを保持して描画し、plain textは文字情報として表示します。
|
||||
server側の許可リストでscript・イベント属性・任意CSS・form・iframe・画像等を除去し、表示時にも再検査します。
|
||||
Shadow DOMでWiki UIと表示スタイルを分離し、本文リンクは安全なHTTP(S) URLに解決して別タブで開きます。
|
||||
Wiki macroは展開せず、記事表示のための外部画像や原文サイトのfetchも行いません。
|
||||
検索とページングは保存済みcacheだけを対象にし、画面表示で
|
||||
feed取得の完了を待ちません。ダッシュボードには任意追加のRSS widgetを用意します。
|
||||
|
||||
### APIと保存層
|
||||
|
||||
API prefixは `/_/api/v1/extension/organizer.feeds/`。Domain内の本人専用で、匿名・他人のsourceには
|
||||
アクセスできません。readonlyアカウントは読取のみです。すべての応答はprivate/no-storeとします。
|
||||
|
||||
| endpoint | 操作 |
|
||||
| --- | --- |
|
||||
| `GET sources` / `POST sources` | source一覧/追加・設定更新。新規はUUIDで再送を識別、更新はversion CAS |
|
||||
| `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 item?source=…&id=…` | 本人の記事本文 |
|
||||
| `POST state` | 内蔵read/starの条件付き変更。FreshRSSは拒否 |
|
||||
| `POST note` | 公開範囲確認付きのWiki単独保存。request_idと入力hashで再送を識別 |
|
||||
| `GET opml/export` | 本人の内蔵購読をOPML 2.0としてダウンロード |
|
||||
| `POST opml/preview` | ファイルを解析し、追加可能・登録済み・重複・未対応等を返す。保存・外部通信なし |
|
||||
| `POST opml/import` | 選択行を再解析・検査し、確認時の購読設定と一致する場合だけ原子的に追加 |
|
||||
|
||||
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で無効化します。
|
||||
v3で`feed_import_receipts`を追加し、購読の一括追加と再送記録を同時保存します。
|
||||
v4でsourceに購読一覧、記事にremote feed ID・カテゴリIDを追加します。FreshRSSの旧workerを
|
||||
versionで無効化し、次の背景取得を予約します。内蔵sourceのversion・取得予約は変更しません。
|
||||
既存テーブルを破壊・再構成しません。SQLiteのforeign_keys設定に依存せず削除を完遂するtriggerを
|
||||
持ちます。内蔵read/starを本文cacheから分離し、記事を保持窓から落としても状態は黙って消しません。
|
||||
DBは内蔵購読・状態・保存receiptの正本であり、全体を捨てられるcacheとは扱いません。
|
||||
|
||||
sourceのprovider・URL・資格情報の変更は別sourceを作る契約です。設定versionとworker claimの
|
||||
両方を照合し、停止/削除/設定更新後に古い取得結果を書き戻しません。完了保存時にも本人の
|
||||
所属・状態・extension有効状態をwriter transaction内で確認します。
|
||||
|
||||
### 背景取得の上限
|
||||
|
||||
| 項目 | 初期実装の値・挙動 |
|
||||
| --- | --- |
|
||||
| 個人のsource数 | Domain・本人ごとに32 |
|
||||
| 定期event | `feed.source.sync`、既定60秒周期、低優先度、1回最大4 sourceを直列取得 |
|
||||
| source更新間隔 | 5〜1440分、既定30分。取得候補になる間隔であり、混雑時の完了時刻保証ではない |
|
||||
| 通信予算 | 1 source 8秒、batch 35秒、応答/展開後本文4 MiB |
|
||||
| 外部接続 | 公開HTTPS/443のみ。DNS検査・接続先固定、内部アドレス・redirect・proxyを拒否 |
|
||||
| 内蔵記事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。記事と同じ取得予算で収集 |
|
||||
| 再試行 | 次の設定間隔まで待機。手動予約にも最終成功から60秒の制限、取得中の重複claim拒否 |
|
||||
|
||||
内蔵は条件付きGET、304ではcacheを保持します。どちらのproviderも通信・認証・構文失敗で
|
||||
前回cacheを消しません。sourceには安全な失敗分類と最終成功日時を表示し、イベントログには
|
||||
成功/失敗件数だけを記録します。資格情報・生本文・秘密を含み得るURLをログへ出しません。
|
||||
extension無効化は画面・API・取得・完了保存に適用します。購読を登録するまで外部通信は発生しません。
|
||||
|
||||
### FreshRSSの購読とカテゴリ
|
||||
|
||||
背景取得ではlogin後にreading-listと`subscription/list`を読み、両方に成功した場合だけ
|
||||
記事・購読一覧を同じtransactionで置換します。一方の取得失敗、上限超過、不正なsnapshotでは
|
||||
前回の両cacheを保持します。記事が取得窓内にない購読も一覧には残します。
|
||||
|
||||
左ペインでFreshRSS sourceを選ぶとカテゴリ選択・購読名の検索・購読一覧を表示します。
|
||||
カテゴリは表示名でなくremote category ID、購読は`origin.streamId`とsubscription IDを対応させます。
|
||||
同名でも混同せず、複数カテゴリに属する購読も扱います。`GET items`の`feed`/`category`は
|
||||
source指定と組み合わせ、既存の未読・star・検索・keysetページングと併用できます。
|
||||
絞り込み対象は最新200記事のcache内に限られ、購読を選んでも履歴全件を外部取得しません。
|
||||
購読の追加・削除やカテゴリの編集はFreshRSS側で行います。
|
||||
|
||||
## 既読・star同期を追加する条件
|
||||
|
||||
@@ -26,16 +133,122 @@ server-authoritative stateと未送信の操作を分けます。操作ごとの
|
||||
|
||||
FreshRSS APIに条件付き更新がない操作もあり得るため、対応版の実機fixtureで競合動作を確認するまで完全な双方向同期を約束しません。
|
||||
|
||||
## 内蔵fetcherを選ぶ場合
|
||||
### 書戻しの次段階設計
|
||||
|
||||
定期event、条件付きGET、host別同時数、timeout、応答サイズ、展開サイズ、backoffを設けます。XML外部entityを無効にし、feed HTMLを安全化します。redirect/DNSを含むSSRF対策、外部画像の同意、個人購読URLや認証情報の秘匿が必要です。
|
||||
以下は未実装のRSS-3です。購読navigationの追加だけでは書戻しを有効にしません。
|
||||
sourceごとに既定OFFの書戻し設定を設け、操作は`read`または`starred`の一項目と希望値に限定します。
|
||||
cache内の他項目を同時に送らず、全件既読・購読編集も初期対象に含めません。
|
||||
|
||||
OPMLは購読の入出力として扱い、既読・star・全本文のバックアップと同一視しません。importはpreview・追加/置換選択・重複確認を行い、既存購読を黙って削除しません。
|
||||
操作記録は記事cacheから分離し、Domain・本人・request_id、source・記事ID、対象項目、希望値、
|
||||
source version、状態、claim期限を保持します。同一request_idの同じ入力は同じ記録を返し、
|
||||
違う入力は拒否します。同じ記事に未解決の操作がある間は次の操作を受け付けません。
|
||||
受付APIは外部通信せず、低優先度workerが送信します。記録数とworkerの時間予算は必ず有限にします。
|
||||
|
||||
| 状態 | 次の処理 |
|
||||
| --- | --- |
|
||||
| queued | sourceの有効状態・書戻し設定・version・本人の権限を再検査してclaim。古すぎる未送信操作は中止 |
|
||||
| preparing | FreshRSSの現在値を取得。すでに希望値なら書き込まず確認済み。異なる場合だけ変更tokenを取得 |
|
||||
| sending | この状態をDBに確定してから変更を送る。再起動やtimeoutでも自動再送しない |
|
||||
| confirmed | 送信後の読取で希望値を確認。確認できた値だけcacheへ反映 |
|
||||
| unknown | 送信済みか適用済みか判断できない。成功扱いにせず、利用者の再確認操作を待つ |
|
||||
| checking | unknownの再確認。読取のみで、希望値ならconfirmed、異なれば競合として提示 |
|
||||
| failed / cancelled / conflict | 原因を示して終了。新たに送る場合は利用者の明示操作を必要とする |
|
||||
|
||||
通常取得と書戻しはsourceのleaseを共有し、古い取得結果が書戻し後の値を上書きしないようにします。
|
||||
設定変更・無効化・削除は未送信操作を止めますが、すでに外へ送った要求は取り消せません。
|
||||
その場合はunknownを保持し、設定変更後のcacheへ旧workerが反映することを拒否します。
|
||||
外部clientとの同時変更を原子的に防げないAPIでは、確認直後に状態が再変更される可能性もあります。
|
||||
readbackは観測結果であり、exactly-onceやリモートCASの保証とは区別します。
|
||||
|
||||
受入テストは、opt-inなしの拒否、同じ操作の再送、別項目の保持、送信前の権限失効、
|
||||
送信直後の応答喪失、worker停止・再起動、unknownの読取専用再確認、source削除・設定変更、
|
||||
通常取得との排他、他clientによる同時変更を含めます。実サービスを使わない合成fixtureで
|
||||
これらを通した後、指定版FreshRSSでの受入を別途行います。
|
||||
|
||||
## 内蔵簡易reader
|
||||
|
||||
購読追加/削除、フォルダ、記事一覧、既読/未読、star、更新間隔と保持上限を初期範囲に
|
||||
します。取得は背景ジョブで行い、更新失敗で購読や状態を消しません。記事本文cacheと
|
||||
既読・starの保持期間を分離し、古い記事を再取得しただけで未読へ戻る挙動を防ぎます。
|
||||
高度な自動分類、全文収集、reader向け互換APIはFreshRSSとの機能競争として追加しません。
|
||||
|
||||
初期版では全体を直列化し、上記の予算内で取得します。将来の並列化時にhost別同時数・公平性・
|
||||
指数backoff/Retry-Afterを追加します。RSS 2.0とAtomを対象とし、XML外部entityは展開しません。
|
||||
外部画像の同意付き表示は未実装で、現在は一律に取得・表示しません。
|
||||
|
||||
### OPML入出力
|
||||
|
||||
RSSツールバーの`⇄`から、本文ペイン内でファイル選択・確認・追加を行います。書出しは本人の内蔵購読の
|
||||
名前・URL・フォルダをOPML 2.0に保存し、停止中の購読も含みます。FreshRSS接続・資格情報は含めません。
|
||||
購読URLのqueryに秘密がある場合はそのURLも書き出されるため、ファイルは本人用として扱います。
|
||||
既読・star・記事本文・有効状態・更新間隔のバックアップではありません。
|
||||
|
||||
取込はUTF-8のOPML 1.0/1.1/2.0を対象とします。OPMLは購読と階層outlineを交換する形式であり、
|
||||
この実装はfeed購読部分のみ扱います。[OPML公式仕様](https://2005.opml.org/spec2.html)。
|
||||
ネストしたフォルダは`親 / 子`という一つのフォルダ名へ投影します。名前のmarkupは文字情報にし、
|
||||
`include`・外部outline・HTMLページの参照は取得しません。コメント扱いのoutline配下も追加対象外です。
|
||||
|
||||
確認表では、追加・登録済み・ファイル内重複・未対応URL/形式・名前不正を区別し、追加可能な行を選択します。
|
||||
HTTPS/443と内部アドレス拒否の既存契約は維持し、ファイル取り込みを検証の迂回経路にはしません。
|
||||
初期版は**追加のみ**で、置換/既存購読の削除は提供しません。有効状態と更新間隔は追加時に指定します。
|
||||
保存後のfeed取得は既存の背景eventが行い、previewやimportのHTTP request中には通信しません。
|
||||
|
||||
上限はファイル512 KiB、記事購読候補500行、outline 1,000個、XML階層16段です。既存sourceと合わせた
|
||||
32件上限を確認画面とwriter transactionの両方で検査します。既存・ファイル内重複は、hostの大小文字・
|
||||
既定443 port・空pathを正規化して判定します。queryの順序、pathの大小文字、redirect先を同一視しません。
|
||||
|
||||
previewはsource UUID・設定versionのsnapshotを返し、適用時に一致しなければ412で再確認を求めます。
|
||||
選択行の再解析、本人・Domain・有効状態の確認、source追加とreceipt保存を一つのtransactionで実行します。
|
||||
同じrequest_id・同じ入力は保存結果を返し、入力が異なれば拒否します。後でsourceを削除してもreceiptを
|
||||
保持するため、古い要求を再送して購読が復活することはありません。receiptはDomain・本人ごとに1,000件まで
|
||||
保持し、上限時は新しいimportを拒否します。既存のWiki/タスク・既読/starは変更しません。
|
||||
|
||||
## Wiki保存と権利・公開
|
||||
|
||||
既定はURL、出典、短いメモの保存です。全文保存は取得可能性・利用条件・個人用途等を確認する独立操作とし、feedが短いからといって有料記事を自動取得しません。保存先が自動公開範囲なら内容と添付の公開を明示確認します。
|
||||
|
||||
Wiki単独は親Path配下の `rss-{request UUID}` に新規作成します。既存Pathを上書きせず、Page・Path・
|
||||
初回Revision・活動outbox・再送receiptを同じDB transactionで保存します。権限はtransaction内でも
|
||||
再確認します。初期版の単独保存は通常Wiki空間のみで、独自所有契約を持つ`/u`・`/g`は対象外です。
|
||||
タスクも作成する場合は既存capture APIの原子的なWiki+タスク保存を使います。この経路のPathは
|
||||
既存契約の`mail-{request UUID}`です。途中失敗時は部分的なPage/タスクを残さず、同じ要求で再試行できます。
|
||||
保存先の公開範囲確認を必須にし、取得済み本文のコピーは別チェックとします。
|
||||
|
||||
購読削除で明示保存したWikiやタスクは消しません。内蔵cacheを削除しても既存Wikiへの参照と
|
||||
再送receiptは残します。文書payloadの不変ファイルは既存Document Storeに保存するため、DB失敗時に
|
||||
未参照payloadが残る可能性は既存GC契約に従い、参照のないPage/Pathとは区別します。
|
||||
|
||||
## TODOと受け入れ
|
||||
|
||||
RSS-1:read-only FreshRSS fixture。RSS-2:安全な一覧と出典付きWiki保存。RSS-3:必要なら既読/star送信。RSS-4:内蔵reader採用判断とOPML。オフライン、欠落ID、巨大feed、未知HTML、同期再送、他user情報、feed削除後の保存Page維持を試験します。
|
||||
- [x] RSS-1:read-only FreshRSS connectorと合成fixture。実接続の受入は別。
|
||||
- [x] RSS-2:安全な共通一覧、出典付きWiki保存、任意のタスク化、ダッシュボード。
|
||||
- [ ] RSS-3:FreshRSSへの明示的な既読/star操作と送信状態・競合・再送の契約。
|
||||
- [x] RSS-4a:内蔵簡易reader、購読設定、既読・star、背景取得。
|
||||
- [x] RSS-4b:OPML export/importのpreview、選択追加、重複確認、原子的な保存と再送防止。置換・状態移行は範囲外。
|
||||
- [ ] RSS-5:FreshRSS実環境の接続先・版・API資格情報を指定してread-only受入。
|
||||
- [ ] RSS-6:大規模利用時の公平性、host別並列上限、Retry-After/backoff、資格情報rotation UI。
|
||||
- [x] RSS-7:FreshRSSの購読一覧・カテゴリを使うnavigation。同名ID分離、複数カテゴリ、cache内絞り込み、背景での原子的更新、失敗時保持。
|
||||
|
||||
隔離試験はRSS/Atom・FreshRSS login/read、欠落ID・巨大/不正feed、条件付きGET、失敗時cache保持、
|
||||
本人分離・失効・readonly、二重送信・版競合・旧worker拒否、migration再実行/失敗rollback、
|
||||
Wiki保存失敗の原子性を含みます。Chromiumの1440px/390pxで一覧・本文・検索・キー操作・
|
||||
Wiki保存を試験します。実FreshRSS、newsboat、実機Safariの受入はこの合成試験に含めません。
|
||||
|
||||
## 実施段階
|
||||
|
||||
1. **共通契約とfixture**:Domain/本人のsource所有、provider ID、remote ID、cursor、取得予算、
|
||||
最終成功/失敗と無効化を定義する。FreshRSS読取connectorを合成fixtureで先に検証し、
|
||||
内蔵providerも同じ表示契約へ接続する。sourceの資格情報をブラウザ・ログへ出さない。
|
||||
2. **読取UIと背景取得**:購読/フォルダ、記事の一行一覧、本文表示、出典リンクを用意する。
|
||||
デスクトップでは一覧を見渡せる配置、スマホでは一覧と本文を切り替える。画面表示で外部fetchを
|
||||
待たず、schedulerで有界に更新し、取得済みcacheと鮮度を表示する。source停止・失効も検証する。
|
||||
3. **Wiki保存とタスク化**:タイトル・URL・出典・短いメモをpreviewし、保存先Pathを選ぶ。
|
||||
既存captureと権限確認を再利用し、二重送信・保存先競合・自動公開範囲を検査する。全文保存は
|
||||
独立した明示操作。Wiki単独保存とWiki+タスクの原子保存を分け、要求内の失敗では部分成功を
|
||||
残さない。過去に保存済みのWikiは別のタスク作成失敗で削除しない。
|
||||
4. **ダッシュボードとprovider完成**:読める記事だけのwidget、内蔵簡易readerとOPML、
|
||||
FreshRSSの明示的な既読/star操作を段階的に追加する。接続先・対象版の指定後に実環境で
|
||||
read-only→書込の順に受入し、read-only連携を有効化しただけで外部状態を変更しない。
|
||||
|
||||
各段階で無効化、件数・時間・容量上限、移行の再実行、ユーザー/Domain間の分離を試験する。
|
||||
source解除時のcache清掃と、利用者が明示保存したWiki/タスクの保持は別操作とする。
|
||||
@@ -0,0 +1,148 @@
|
||||
# 実装残件台帳
|
||||
|
||||
更新日:2026-11-08。全体照合基準は `e65ca56`(作業履歴・日次メールの後続実装まで)。
|
||||
RSS-01はその後の内蔵reader・FreshRSS読取・共通UI実装まで個別更新。
|
||||
設計書の大項目をそのまま未実装機能と数えず、既存機能の続きとして着手できる単位に整理する。
|
||||
実装順は本書、個別契約はリンク先、過去の経緯は[原ロードマップ](../implementation-roadmap.md)と
|
||||
[実装記録](../implementation-status.md)を参照する。将来の更新でも以下のIDを再利用する。
|
||||
|
||||
## 調査範囲と状態の読み方
|
||||
|
||||
日本語設計書、原ロードマップ、実装記録と、対応するstore/HTTP handler/テストを静的照合した。
|
||||
全エンドポイントの再監査や本番の再試験ではない。実データ、外部カレンダー、メールボックスには
|
||||
アクセスしていない。独立した `anya/pages-cli` の現行HEAD・配布バイナリも今回の照合対象外。
|
||||
|
||||
- **実装済み**:記載した範囲のコードと試験がある。全機能完成・本番適用を意味しない。
|
||||
- **一部実装**:基盤や初期機能はあるが、記載した後続が必要。
|
||||
- **未実装**:設計・TODOの段階。API例や予約URIだけでは利用可能としない。
|
||||
- **確認待ち**:実装の追加ではなく、指定端末・環境・運用での受入が必要。
|
||||
- **保留**:利用者の保留指定、外部環境の選定、保存契約の合意が必要。
|
||||
|
||||
P0は認可・整合性・復旧の安全条件、P1は日常利用の回復性と負荷、P2は機能拡張、P3は
|
||||
別サブプロジェクト。P0の記載は全項目で現に障害や脆弱性を再現したという意味ではない。
|
||||
本番反映は別作業とし、今はソースと隔離fixtureを進められる。
|
||||
|
||||
## 未実装として数え直さないもの
|
||||
|
||||
| 範囲 | 確認できる実装 | 残す境界・根拠 |
|
||||
| --- | --- | --- |
|
||||
| 8つの命名部品 | GrammaraturからSeheweitまでの初期分離 | 分離はHA・全provider対応の完成ではない。[部品一覧](component-names.md) |
|
||||
| イベントログ競合 | writer lockを先に取得、raw/bucket原子保存、完了ログ失敗で業務を再実行しない | `event_log_write.go`、`event_log_write_test.go`、`event_log_reporting_test.go`。[Dregarnuhr](dregarnuhr.md)。ログ欠落の自動回収は別件 |
|
||||
| 共通outbox | Domain sequence、型別購読、checkpoint、タスクと正本の同時保存 | `activity_outbox.go`。[配送契約](outbox-delivery.md)。全producer・保持・分散配送は未完成 |
|
||||
| タスク | 日別計画・持ち越し、親子、Wikiメモ、時間枠、Pomodoro、既定値、達成度・プロジェクト集計 | [生産性と連絡先](task-productivity-contacts.md)、[日別計画](task-daily-notes.md)。共有・日課・競合採否は別件 |
|
||||
| 作業記録・日次メール | 作業訂正/取消/監査、配信履歴、同日手動再送、世代fence | `task_work_history*.go`、`task_digest_history*.go`。managed schema v3/v4。本番未反映 |
|
||||
| オーガナイザー | 共通ナビ、個人設定、配置/サイズを保存するダッシュボード | [ダッシュボード](organizer-dashboard.md)。共有・任意widget runtimeとは別 |
|
||||
| 連絡先 | 個人帳、vCard、履歴復元、trash、個人CardDAVとsync-token | [運用契約](../../operations/carddav-contacts.md)。外部CardDAV connector・共有帳・全端末互換ではない |
|
||||
| DAV | 共通principal/資格情報、限定VEVENT/VTODO、プロジェクト対応、既定リスト名変更 | [所属統一](task-dav-project-unification.md)。CardDAVのsync-tokenを全CalDAV対応と読み替えない |
|
||||
| グループ・公開 | `/g/` 管理、built-in管理グループ、匿名children/tree/City、明示/自動公開 | `groups_handler.go`、`groups_inheritance.go`、[公開契約](publication.md)。委譲shareと完全な権限配信は別 |
|
||||
| 承認・通知 | 要求/決裁APIの限定slice、共通Inbox、アナウンス、タスク通知、Web Push | `publication_approval_api.go`。[Schutzaria](schutzaria.md)。継承reviewer・定足数・現行Revision再検査・決裁UIは残件 |
|
||||
| ブログ・日記 | 作成、公開、同一Campus・同一instanceの射影、本文RSS、記事ナビ | [ブログ・日記](blog-diary.md)。遠隔射影、コメント、tDiary importは別 |
|
||||
| エディタ | E1–E5、下書き、条件付き保存、競合確認、復元、言語分岐、保護HTML | [編集契約](editor-resilience.md)。全入口の同一契約・E6共同編集は未完成 |
|
||||
| ストレージ・DR | Geduldhローカル不変payload、migration台帳、offline snapshot/verify/restore/手動promote | `internal/dr/snapshot.go`、`node.go`。[DR計画](dr-delivery-plan.md)。オンライン同期・自動切替ではない |
|
||||
|
||||
## 次の実施順
|
||||
|
||||
2026-11-08、利用者指定により、大きな機能を提供するサブプロジェクトを以下の順で進める。
|
||||
前案の小規模な回復・基盤改善を先に一巡する順序は、この順序へ置き換える。
|
||||
|
||||
| 順番 | サブプロジェクト | 主な残件ID | 利用できる機能のまとまり |
|
||||
| --- | --- | --- | --- |
|
||||
| 1 | RSS・情報収集オーガナイザー | RSS-01 | 購読・フォルダ・記事一覧、出典付きWiki保存、タスク化、ダッシュボード連携 |
|
||||
| 2 | 構造化ドキュメントと編集部品 | CSV-01、DIAGRAM-01、EDIT-01の関連部分 | CSV埋め込み/編集、図表部品挿入、nwdiag/Draw.io等のpreviewと安全な保存 |
|
||||
| 3 | 料理レシピ管理 | RECIPE-01 | 材料・手順・分量変更・材料検索・買い物リスト |
|
||||
| 4 | タスク・プロジェクト管理の第2段階 | TASK-01、DAV-01、REC-01/02、ORG-01の関連部分 | 日課・週次計画・capacity・依存関係・進捗・同期競合の採否 |
|
||||
| 5 | 共同作業・公開承認・共有 | PUB-01、SHARE-01、COLLAB-01の関連部分 | 承認者Inbox/決裁、公開影響確認、期限付き共有、権限総覧 |
|
||||
|
||||
各表のP0〜P3は安全性・負荷等の性質を示す分類として残し、このサブプロジェクト順を覆す
|
||||
一律の実行順にはしない。AUTH-01、OUT-01、QUEUE-01、STORE-01等は、対象機能に必要な
|
||||
範囲を各段階へ組み込む。必須の認可・DB整合性・再送防止は省略せず、無関係な基盤改修を
|
||||
すべて完了させるまで機能開発を止める構成にも戻さない。
|
||||
|
||||
最初のRSSは[着手単位](feeds.md#実施段階)に従う。内蔵は簡易正本、本格運用はFreshRSS正本と
|
||||
する方針を採用。接続先・版・資格情報は別途指定し、まずprovider契約と合成fixtureで一覧・
|
||||
保存フローを検証する。各サブプロジェクトはUI・API・
|
||||
保存・試験が揃った単位でコミットし、本番反映は別ゲートとする。
|
||||
別セッションとの保存層の競合がある場合は、該当ファイルの作業境界を合意してから進める。
|
||||
|
||||
## A. 整合性・回復・認可
|
||||
|
||||
| ID / 優先 | 状態・次の作業 | 依存・完了条件 | 詳細 |
|
||||
| --- | --- | --- | --- |
|
||||
| REC-01 / P1 | 一部実装:失効Domainの取り残された作業記録を終了・回復 | 現在の文書閲覧権限を再付与せず、本人の停止に必要な最小情報だけ扱う。他Domainタイトル非露出、同時停止・新規開始・失効競合を検証 | [作業記録](task-productivity-contacts.md) |
|
||||
| REC-02 / P1 | 一部実装:取消からの復元、監査保持/export | REC-01と既存CAS。復元も新監査版、重複時間再検査、履歴の削除と正本の保持を分離。保持期間を決めるまで削除しない | 同上 |
|
||||
| AUTH-01 / P0 | 一部実装:policy snapshot・ユーザー領域事前読込、更新時の認可fence | 入口一覧を作り、revokeと更新、alias、owner移管、公開境界移動をfixture化。接続1本でも認可callbackが別接続待ちにならない | [Schutzaria](schutzaria.md)、[認証](auth-permissions.md) |
|
||||
| AUTH-02 / P0 | 一部実装:identity連結解除・メール所有・最後の管理者保護、外部group mapping | OIDC/LDAP認証自体は維持。由来付きgrant、解除・同期失効・最後の管理者の並行操作を検証 | [認証](auth-permissions.md) |
|
||||
| PUB-01 / P0 | 一部実装:承認者継承/定足数/対象再検証/決裁UI、広域公開影響のページング | AUTH-01。現行source/policy/generation一致、権限失効後の決裁拒否、alias・依存Asset・移動で公開を広げない | [公開](publication.md) |
|
||||
| PUSH-01 / P0 | 一部実装:claim世代をattemptから分離、購読version付き削除、Retry-After | 古いworker結果と新購読の競合、送信成功後DB失敗、lease超過を注入。配送はexactly-onceと表現しない | [Ordoschnellic](ordoschnellic.md) |
|
||||
| QUEUE-01 / P0 | 一部実装:終了context/drain、汎用lease・heartbeat・fencing | 所有世代を比較して完了、旧worker遅延完了を拒否。全worker/CLIを含むwriter契約が揃うまで多重運転しない | [Dregarnuhr](dregarnuhr.md) |
|
||||
| OUT-01 / P1 | 一部実装:未接続producer、consumer別再生/backoff/公平性、保持 | consumer変更時のbootstrap、一意キーtombstone、最遅必須consumerを含む安全な清掃。heads/checkpointだけ残して履歴を安易に削除しない | [outbox](outbox-delivery.md) |
|
||||
| MAIL-01 / P1 | 一部実装:キュー中再送の取消、Inbox結果、保持設定/receipt整理 | attempt世代、同意、設定versionを再検査。詳細90日整理と重複防止記録の寿命を区別。SMTP結果不明を自動再送しない | [日次メール](task-digest-delivery.md) |
|
||||
| STORE-01 / P0 | 一部実装:legacy schema/context整理、整合snapshot・restore契約、GC pin | migrationの再実行・途中失敗・旧データ保持・参照整合性。DB、CAS、可変正本、暗号鍵、外部副作用を一体で復旧判断 | [保存移植性](../storage-portability-and-operations.md)、[Geduldh](geduldh.md) |
|
||||
|
||||
## B. スケーリングと日常UX
|
||||
|
||||
| ID / 優先 | 状態・次の作業 | 依存・完了条件 | 詳細 |
|
||||
| --- | --- | --- | --- |
|
||||
| SEARCH-01 / P1 | 一部実装:現行head/Domain/言語別索引、H1 metadata、再開可能backfill | AUTH-01。候補上限を網羅性と混同せず、watermark・continuation・日本語検索・起動時間を測定。失効した結果をcacheから戻さない | [Mestionora](mestionora.md) |
|
||||
| CITY-01 / P1 | 一部実装:生成由来/手動上書き/除外tombstone、局所reconcile | OUT-01の既存基盤を再利用。同入力で無変更、rename/merge後も手動名を保持、URL更新と所属の整合性 | [City](knowledge-city.md)、原ロードマップCITY-A〜D |
|
||||
| NAV-01 / P1 | 一部実装:directory索引、有界children/Cityページング、共通sidebar | AUTH-01、CITY-01。隠れた件数・ラベルを出さず、Domain全件読込に依存しない。巨大階層の時間・行数・heapを測定 | [ナビ](navigation-search.md) |
|
||||
| RENDER-01 / P1 | 一部実装:provider版付きcache、同一描画の集約/同時数/清掃、隔離 | 描画をforegroundより低優先にする。停止・更新・認可失効・cache破損・容量不足・外部参照を検証 | [Kunstzeal](kunstzeal.md) |
|
||||
| OBS-01 / P1 | 一部実装:情報源別availability、収集共有、rollup/清掃予算、component metrics | 欠測を0としない。返却点数だけでなく走査量を制限。CPU/RAMを根拠なくproviderへ按分しない。SNMPは別選定 | [Seheweit](seheweit.md) |
|
||||
| EDIT-01 / P1 | 一部実装:新規GET時のPage作成を保存まで延期、全入口CAS、block単位保護HTML/挿入palette | 既存E1–E5を回帰。Page+Path+初回Revisionを原子的に作り、閉じるだけでは空Pageを残さない。PlainText変換は欠落を明示 | [編集](editor-resilience.md)、[日常UX](priority-ux-20261031.md) |
|
||||
| UX-01 / P1 | 一部実装:idle session timeout/個人短縮設定、独立CLIとの契約整理 | 絶対期限とは区別。読み取りpollだけで無期限延長しない。CLI本体の検索・転送等は独立repoを確認して別issue化 | [日常UX](priority-ux-20261031.md)、[CLI契約](remote-cli.md) |
|
||||
|
||||
## C. オーガナイザーと利用機能
|
||||
|
||||
| ID / 優先 | 状態・次の作業 | 依存・完了条件 | 詳細 |
|
||||
| --- | --- | --- | --- |
|
||||
| DAV-01 / P1 | 一部実装:上書き競合の候補保存、Inbox、比較/採否 | task履歴と通知を原子的に対応付け、再同期で候補を重複させない。別人・別Domainへ候補本文を漏らさない | [所属統一](task-dav-project-unification.md) |
|
||||
| DAV-02 / P2 | 一部実装:VTODO時刻期限/繰返し/alarm、VEVENT temporal拡張、差分同期 | 対応profileを分離。未知propertyの保持・拒否、削除tombstone、期限切れtokenからの復旧。選定clientで認定するまで完全準拠としない | [共通DAV](caldav-common.md)、[calendar](calendar-implementation.md) |
|
||||
| TASK-01 / P2 | 一部実装:日別capacity、一括計画、focus backfill、Pomodoro周期/日課 | 見積・実績・予定を混同せず、次回生成を冪等化。親子2階層と一般依存DAGを別に扱う | [時間枠](task-planning-focus.md)、[タスク](tasks-tickets.md) |
|
||||
| ORG-01 / P2 | 一部実装:一般予定通知、共有タスク/アドレス帳、owner回復 | AUTH-01、OUT-01。共有相手失効、担当だけでは本文権限を増やさない、通知の重複抑止。外部CardDAV書込は別ゲート | [予定・連絡先](calendar-contacts.md) |
|
||||
| DASH-01 / P2 | 一部実装:同種widget複数、共有layout、plugin widget | 個人layoutとの分離、配置版競合、widgetごとの認可/取得上限。第三者実行はEXT-01後 | [dashboard](organizer-dashboard.md) |
|
||||
| SHARE-01 / P2 | 未実装:委譲share URL、期限/失効/監査、説明可能な権限総覧 | AUTH-01、PUB-01。login/adapter/federation資格情報と別目的、単一Page投影、caveat・依存物の失効を検証 | [公開](publication.md)、[Schutzaria](schutzaria.md) |
|
||||
| COLLAB-01 / P2 | 一部実装:Page等の変更購読、最近閲覧/編集、集約通知。コメント/反応/評価は未実装 | OUT-01。現在権限で再投影、private履歴のopt-in/保持。inline commentはRevision変更時の孤立・再接続を扱う | [拡張](extensions.md) |
|
||||
| BLOG-01 / P2 | 一部実装:安全なtDiary import、最近コメント、遠隔ブログ射影 | COLLAB-01、遠隔はFED-01。importは再開/重複抑止/dry-run。同一instance射影を再実装しない | [ブログ・日記](blog-diary.md) |
|
||||
| CSV-01 / P2 | viewerのみ実装:別Documentを投影するCSV macro/editor、ODS境界 | 行列・セル・総量上限、Revision固定、権限、CSV引用/改行fixture。表示HTMLをCSV正本へ逆流させない | [表設計](extensions.md) |
|
||||
| DIAGRAM-01 / P2 | 一部実装:nwdiag/Draw.io provider、slide preview/editor | RENDER-01。安全なSVG・include拒否・renderer版固定、ticket/CAS保存、print。既存Excalidraw/Krokiとは分ける | [Kunstzeal](kunstzeal.md) |
|
||||
| RECIPE-01 / P2 | 未実装:構造化レシピmetadataとPage投影の初期slice | 材料・数量・未知単位を保持、人数変更は派生値、Asset認可、版競合、出典・公開確認 | [料理レシピ](recipe-management.md) |
|
||||
|
||||
## D. 選定・別サブプロジェクト
|
||||
|
||||
| ID / 優先 | 状態・次の作業 | 着手ゲート・最初の検証 | 詳細 |
|
||||
| --- | --- | --- | --- |
|
||||
| RSS-01 / P2 | 一部実装:内蔵簡易正本、FreshRSS読取connector、3ペインUI・HTML本文、Wiki保存・タスク化・dashboard、OPML確認付き入出力 | 残件はFreshRSS既読/star書戻し、購読/カテゴリnavigation、実接続受入、公平性/backoff。managed schema feeds v3・隔離fixture。本番未反映。二重正本・停止時の自動切替なし | [RSS](feeds.md) |
|
||||
| IMAP-01 / P3 | 未実装・選定待ち:IMAP読取同期 | provider/認証/保持を決める。UIDVALIDITY/UID、添付量、外部画像、失効をfixture化。neomutt captureは実装済みで別 | [メール](mail.md) |
|
||||
| TICKET-01 / P3 | 未実装:queue/番号/workflow/外部依頼者 | 共有範囲と状態遷移を定義、同時採番・失効・監査。既存個人タスクをticketと呼び替えない | [タスクとticket](tasks-tickets.md) |
|
||||
| EXT-01 / P3 | built-inのみ:第三者manifest/署名/隔離runtime、停止・rollback・観測 | capability・secret・host・予算・export契約。任意コードをGoプロセス内へ直接ロードしない | [拡張](extensions.md) |
|
||||
| FED-01 / P3 | 一部実装:管理設定ACK/鮮度、選択権限情報の署名付きDomain配信 | 既存group継承を保持。origin/sequence/競合/revoke/再参加を定義し、独立ローカルgrantを消さない | [Campus](campus-federation.md) |
|
||||
| BACKEND-01 / P3 | 未実装:S3/SFTP、読取WebDAV/SSH、外部SQL、設定/復旧UI | STORE-01。conditional create、Range、破損・切断・遅延・mount喪失の共通試験。単なるmountを正式対応としない | [Geduldh](geduldh.md)、[運用](operations.md) |
|
||||
| DR-01 / P3 | D1未実装:DR01〜13、LB/HA、controller/data authority分離 | 最初は型・pure state machine・mock probe。writer境界合意、fence設備、RPO/RTO、復旧訓練なしで自動昇格しない | [DR実施計画](dr-delivery-plan.md) |
|
||||
| NETWORK-01 / P3 | 未実装:IPAM/DNS/資産管理、検疫scanner | 型付き正本、権限、dry-run→承認→apply、冪等性。スキャン/外部DNS更新を閲覧リクエスト内で行わない | [拡張](extensions.md)、[原ロードマップ](../implementation-roadmap.md) |
|
||||
| CONTENT-01 / P3 | 未実装部分:他Wiki記法、widget、外部検索/Linkding、時刻・日没theme | provider単位の送信同意・上限・失効・変換欠落試験。既存壁紙色themeと時刻条件themeを区別 | [拡張](extensions.md)、[viewer/editor](viewer-editor.md) |
|
||||
|
||||
### 明示的に保留するもの
|
||||
|
||||
- **HOLD-01**:`/tasks/` 配下のメールWikiルーティング調査。利用者の棚上げ指定を維持。関連未コミットファイルを今回の実装・文書コミットへ混ぜない。
|
||||
- **HOLD-02**:vim.wasm runtime改善とnativeアプリ起動。既存設定UIは残すが、自動的に再開しない。
|
||||
- **HOLD-03**:全面WYSIWYG、E6 CRDT/OT共同編集。まずEDIT-01と認可/presence契約、保存量・オフライン・競合モデルを確定する。
|
||||
- **HOLD-04**:本番への反映。作業履歴/日次メールのv3/v4移行を含む同世代保全と隔離復元試験、容量確認、SMTP副作用照合が必要。古いbinaryを新schemaへ向ける切戻しは禁止。
|
||||
|
||||
## 実装と分けて管理する受入
|
||||
|
||||
| ID | 確認待ち | 今回確認していない範囲 |
|
||||
| --- | --- | --- |
|
||||
| ACCEPT-01 | iPhone SE/Safariのカレンダー、IME、電話handoff | Chromiumの狭幅fixtureだけでは実機受入としない |
|
||||
| ACCEPT-02 | Pushの背景受信・再訪・logout・VAPID rotation | 同意済みテスト端末を使う。実通知先へ勝手に送信しない |
|
||||
| ACCEPT-03 | CardDAV/CalDAV clientごとの操作matrix | 過去のTasks.org動作確認は保持するが、全版・全操作の保証に広げない |
|
||||
| ACCEPT-04 | 独立pages-cliの現行契約・配布物 | このrepoの旧Python版でWindows/TLS設定/配布状態を判定しない |
|
||||
|
||||
## 完了・コミット・文書更新の規則
|
||||
|
||||
変更単位ごとに契約、実装、拒否/競合/再送/上限試験を揃えてコミットする。DB変更では
|
||||
旧schema fixture、migration再実行、途中失敗rollback、参照整合性、復旧方式を必要条件にする。
|
||||
破壊的変更・GC・外部副作用は、単に全Goテストが通ることだけで実施可能と判定しない。
|
||||
|
||||
完了時は本書の該当IDと詳細書の状態を同時更新し、ソースcommit、試験、release、本番適用を
|
||||
別々に記録する。旧Phaseの大項目は後続が残る限り丸ごとチェックせず、完了sliceを分ける。
|
||||
残件の総数を完了率には使わない。各行は規模が異なり、着手時に実装・受入単位へ分割する。
|
||||
@@ -1,9 +1,13 @@
|
||||
# PagesWiki 開発設計書
|
||||
|
||||
更新日:2026-09-19。日本語の統合設計版。実装の変更履歴ではなく、現在の境界と次の設計判断を確認するための入口です。
|
||||
更新日:2026-11-08(統合版の初版は2026-09-19)。実装の変更履歴ではなく、現在の境界と次の設計判断を確認するための入口です。
|
||||
|
||||
## この設計書の読み方
|
||||
|
||||
**次に実装する作業は[実装残件台帳](implementation-backlog.md)を入口にする。** `e65ca56`を基準に、実装済みsliceと後続、優先順、依存・完了条件、実機確認待ちと保留を整理した。古い大項目の未チェックを、そのまま全機能未実装と解釈しない。
|
||||
|
||||
2026-11-08追加:[日次タスクメールの配信履歴と手動再送](task-digest-delivery.md)。予約・要求receipt・詳細履歴の保持境界と、DB移行・復旧時の二重送信防止。
|
||||
|
||||
2026-11-02追加:[オーガナイザーの共通ナビゲーションと個人ダッシュボード](organizer-dashboard.md)。配置可能なウィジェット、個人設定への統合、保存・認可・読込負荷の契約。
|
||||
|
||||
2026-11-01追加:[タスク作成・作業記録・達成度レポート・日次メール・個人アドレス帳](task-productivity-contacts.md)。[neomuttとCLIの操作リファレンス](../../operations/neomutt-tasks.md)も参照。
|
||||
@@ -52,6 +56,6 @@
|
||||
21. [決定事項・矛盾の整理・未決事項](/lab/pageswiki-dev/decisions)
|
||||
22. [原資料との対応と外部仕様](/lab/pageswiki-dev/sources)
|
||||
|
||||
## 今回の範囲
|
||||
## 初版の範囲とその後の更新
|
||||
|
||||
今回行うのは設計の再整理と日本語設計書の配置です。オーガナイザー、外部サービス、DAVサーバー、メールアカウント、公開権限の新設は行いません。設計書の配置も匿名公開の許可とは別です。
|
||||
2026-09-19の初版は設計整理と日本語設計書の配置を対象にした。その後の実装は各章の日付付き記録と残件台帳に反映する。2026-11-08の再照合は文書とソースの静的確認であり、本番データの監査・外部サービスへの接続・本番適用は行っていない。設計書の配置も匿名公開の許可とは別です。
|
||||
@@ -38,7 +38,8 @@
|
||||
|
||||
- [x] HTTPクライアント初期版 `pages-cli`/コマンド `pages`(2026-11-01ホストのユーザーPATHへ配置済み。実ユーザログインは未実施):configureによる接続先・既定プロファイル・言語管理、パスワード/TOTP、Bearer保持・失効、ls/cd/cat/view/get、既存Page edit/put、Path補完、メモリ内履歴、検索候補、ブラウザ引き継ぎ。詳細と原設計整合は [遠隔CLI](remote-cli.md)。既存DB直アクセスCLIは変更しない。
|
||||
- [x] 専用起動コマンドとセッション保持は独立HTTPクライアント `pages` として実装。既存 `data/pageswiki-cli` のDB直接操作とは分離し、資格情報に0600の保護と失効/ログアウトを設ける。
|
||||
- [ ] `Ctrl+P` のfuzzy検索と、ローカル `$EDITOR` 編集。現在版/ETagを保持してアップロード時の競合を検出し、上書き・差分・キャンセルを選べるようにする。
|
||||
- [x] ローカル `$EDITOR` 編集、現在Revisionを指定した保存、409時の原稿保全(分離前のHTTPクライアント)。
|
||||
- [ ] `Ctrl+P` のfuzzy検索と競合の対話選択。独立CLI側の現状を確認して追跡する。サーバーの新規作成契約とは分ける。
|
||||
- [x] ターミナルにURLを表示するブラウザ認証(OIDC)。`pages login --oidc [--no-browser]`、S256、5分の単回grant、確認コード/CSRF/TOTP、失効再確認、poll・発行上限を実装。2026-11-01 v0.3.0でサーバー・ホストCLIへ本番反映済み。実providerでの本人承認は利用者確認が残る。契約は[遠隔CLI](remote-cli.md)を参照。
|
||||
- [ ] ターミナル表示が難しい内容はブラウザに引き継ぐ。short linkは認証を迂回しない内部リンクとし、公開share link発行とは分離する。自動公開しない。
|
||||
|
||||
@@ -123,7 +124,7 @@
|
||||
|
||||
現行 `data/pageswiki-cli` はSQLite/Document Storeへ直接アクセスする運用CLI。shell、補完、履歴、`$PAGER`/`$EDITOR` は既にあるが、Web認証を受けるリモートクライアントではない。Webユーザの認可をSQLite直アクセスへ継ぎ足さず、HTTP transportを持つ別コマンド(仮称 `pageswiki remote`)として段階導入する。
|
||||
|
||||
2026-11-01:試作名 `data/pageswiki-remote` から、ユーザ指定によりサブプロジェクト `pages-cli`/実行名 `pages` へ整理。`pages configure` と既定値により通常操作のprofile/lang引数を不要とした。OIDCハンドオフはv0.3.0で本番反映済み。実providerでの本人承認、Ctrl+P、新規作成、強制上書きの対話選択、short linkは残件。[範囲・制限・検証](remote-cli.md)を参照。
|
||||
2026-11-01:試作名 `data/pageswiki-remote` から、ユーザ指定によりサブプロジェクト `pages-cli`/実行名 `pages` へ整理。`pages configure` と既定値により通常操作のprofile/lang引数を不要とした。OIDCハンドオフはv0.3.0で本番反映・利用者確認済み。既存Pageの言語分岐と編集はv0.4.0で対応済み。新規Pageの原子的な作成は別件。2026-11-06以降のCLI本体は独立repoを正とし、Ctrl+P・転送・配布対応等の現状を旧同梱版だけで判定しない。[範囲・制限・検証](remote-cli.md)を参照。以下の番号付き項目は初期実装時の契約で、すべて未着手という意味ではない。
|
||||
|
||||
1. パスワード+TOTPの既存JSONログイン、失効/logout、接続先・Principal・Domain別セッション保存。秘密情報はコマンド引数/履歴/ログへ出さず、保存先0700・資格情報0600相当、TLS検証必須。
|
||||
2. `ls/cd/view/get/edit` と現在Pathの保持。検索は認可付き・件数制限・キャンセル可能なAPIを使用し、`Ctrl+P` のfuzzy選択へ接続。端末の制御シーケンスは本文/タイトルから除去する。
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 6. 公開・承認・共有・匿名ナビゲーション
|
||||
|
||||
状態:明示的なRevision公開、Street/Spotの自動公開、匿名ナビゲーションは実装済み。承認者Inboxは受信者単位の保存・既読APIまで実装済みで、承認要求の生成・決裁UI・配送ワーカーはTODO。共有URL管理もTODO。
|
||||
状態:明示的なRevision公開、Street/Spotの自動公開、匿名ナビゲーションは実装済み。承認要求の登録・限定決裁APIと受信者別Inboxは実装済み。上位方針・reviewer継承、定足数、現行Revisionの再検証、決裁UIを含む公開運用フローは未完成。共有URL管理もTODO。2026-11-08、`publication_approval_api.go`と照合。
|
||||
|
||||
## 三つの異なるもの
|
||||
|
||||
@@ -42,9 +42,9 @@ Domain・Quartierもrequiredの上限制約を設定できます。automaticは
|
||||
|
||||
状態はdraft → requested → approved / rejected / expired / supersededを案とします。取り消し・公開撤回は別監査イベントです。上位の承認必須設定を下位が解除できないこと、自動公開との優先順位、本人承認の可否を実装前に確定します。
|
||||
|
||||
共通通知Inboxの第一段階として、`notification_inbox`にDomain・受信者・イベント・種別を保存し、同じ組合せを重複排除します。`GET /_/api/v1/notifications` は現在のPrincipalに限定して `unread`、`limit`、`before` のkeyset取得を行い、`POST/PATCH /_/api/v1/notifications/read` は同じDomain・受信者の通知だけを既読化します。通知は権限や承認を付与せず、本文や秘密を保存しません。承認要求からの生成と再表示時の権限再検査は次段階です。
|
||||
共通通知Inboxの第一段階として、`notification_inbox`にDomain・受信者・イベント・種別を保存し、同じ組合せを重複排除します。`GET /_/api/v1/notifications` は現在のPrincipalに限定して `unread`、`limit`、`before` のkeyset取得を行い、`POST/PATCH /_/api/v1/notifications/read` は同じDomain・受信者の通知だけを既読化します。通知は権限や承認を付与せず、承認対象の本文や秘密を保存しません。要求登録からの限定的なInbox生成は下記のAPIに接続済み。現行対象の再検査を含む完全な決裁フローは次段階です。
|
||||
|
||||
承認要求の対象(Path/Object/RevisionのハッシュとJSON)、policy version、generation、期限、要求者を`publication_requests`に固定保存し、決裁履歴を`publication_decisions`へ追記します。期限付きpending要求はスケジューラが小さなbatchでexpiredへ遷移させます。レビュアーの現在権限を再検査する決裁APIとInbox UIは、まだ公開していません。
|
||||
承認要求の対象(Path/Object/RevisionのハッシュとJSON)、policy version、generation、期限、要求者を`publication_requests`に固定保存し、決裁履歴を`publication_decisions`へ追記します。期限付きpending要求はスケジューラが小さなbatchでexpiredへ遷移させます。Domain管理者向けの限定決裁APIは存在しますが、委譲レビュアーの決裁UI・完全な公開承認フローを提供した状態ではありません。
|
||||
|
||||
認証済みのDomain管理者向けに、`POST /_/api/v1/publication/requests`でboundedな対象manifestを登録できます。idempotency keyで再送をまとめ、指定されたレビュアーがDomain管理権限を持つ場合だけInbox通知を作成します。`POST /_/api/v1/publication/requests/{uuid}/decisions`はDomainとgenerationを再検査し、承認・拒否をCASで一度だけ適用します。上位方針の継承、定足数、対象Revisionの現在性検査は、公開運用へ進む前の残タスクです。
|
||||
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
2026-11-06:利用者向けの[クライアント契約](https://git.anya.jp/anya/pages-cli/src/branch/main/docs/client-contract.md)と[NeoMutt連携](https://git.anya.jp/anya/pages-cli/src/branch/main/docs/neomutt.md)は独立した公開pages-cliリポジトリへ移転した。本書はサーバー側のHTTP・OIDC認証契約、結合テストと導入履歴を保持する。下記のv0.3.0/v0.4.0は分離前のサーバー同梱版の番号であり、独立CLIはv0.1.0から採番する。
|
||||
|
||||
2026-11-08整理:以下のPython実装・Windows未対応・TLSバイパスなし等の記述と末尾の
|
||||
「次段階」は分離前の同梱版の記録であり、独立CLIの現行制約ではない。独立版の実装・配布・
|
||||
残件は上記repoを正とする。今回の文書照合では独立版HEADを取得していない。
|
||||
サーバー側の新規作成/CAS等の後続は[残件台帳 EDIT-01 / UX-01](implementation-backlog.md)で追跡する。
|
||||
|
||||
2026-11-01。合成データで検証済み。同日、本番サーバのCity更新と合わせてクライアントをホストの `/home/anya/.local/bin/pages` に配置した。実ユーザの資格情報取得・ログイン・本番Page編集は未実施。接続設定とログインは利用者が行う。[反映記録](../../operations/deployments/2026-11-01-city-pages-cli.md)。
|
||||
|
||||
v0.3.0のOIDCログインは利用者の動作確認済み。v0.4.0ではOIDC承認時の追加ローカルTOTPを廃止し、CLIの `auto` 言語選択と既存Pageの新規言語版編集を実装した。2026-11-01 21:48 JSTに本番サーバー/PATH上のCLIへ反映済み。[v0.4.0反映記録](../../operations/deployments/2026-11-01-v0.4.0.md)。
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
# 20. 実装順序と受け入れ条件
|
||||
|
||||
状態:2026-09-19再整理。旧Phase番号は原ロードマップとの対応用に残し、実装は依存関係とリスク順に進めます。
|
||||
状態:2026-11-08再照合。旧Phase番号は原ロードマップとの対応用に残し、実装は依存関係とリスク順に進めます。
|
||||
|
||||
現在の作業単位・優先順・受入条件は[実装残件台帳](implementation-backlog.md)に集約しました。
|
||||
以下の日付付き追記と旧優先表は経緯を残すものです。共通outbox、限定DAV、個人連絡先、
|
||||
HTML保護、Inboxなどの初期sliceは実装済みで、旧表の項目全体が新規開発という意味ではありません。
|
||||
2026-11-08の利用者指定により、**RSS・情報収集 → 構造化ドキュメント/編集部品 →
|
||||
料理レシピ → タスク・プロジェクト管理の第2段階 → 共同作業・公開承認・共有**の順で進めます。
|
||||
必要な認可・整合性・性能対策は各機能の受入条件へ組み込みます。以前の回復・基盤改善を
|
||||
先に一巡する推奨順は置き換え、下記の日付付き「次は」は当時の記録として扱います。
|
||||
|
||||
## 優先順
|
||||
|
||||
2026-11-08:[日次メールの配信履歴・手動再送・保持境界](task-digest-delivery.md)をソース実装。migration v4は旧予約を保持し、詳細整理後も日別予約と要求receiptを残す。本番反映は保留して整合性検証を優先する。次は失効Domainに取り残された作業記録の回復、取消済み作業記録の復元と監査保持。共有・外部書き込みは別段階。
|
||||
|
||||
2026-11-08:[作業記録の訂正・取消と監査履歴、プロジェクト別集計](task-productivity-contacts.md#作業記録の訂正と取消)をソース実装。タスク一覧・ダッシュボードから履歴画面へ接続。DBのmanaged migration v3を伴うため、本番反映はバックアップと別工程にする。日次メールの配信結果・手動再送・保持契約は同日の後続実装へ進んだ。失効Domainに取り残された作業記録の回復、共有、外部書き込みは残件。
|
||||
|
||||
2026-11-02:[共通ナビゲーション・個人設定・ウィジェットダッシュボード](organizer-dashboard.md)を実装。タスク/カレンダー/連絡先の導線統一、トップ・ナビバーの連絡先、個人別の配置・サイズ保存。ソース実装と本番反映は区別し、共有・外部ウィジェットは後続。
|
||||
|
||||
2026-11-02:[個人CardDAV提供と履歴復元・一括export](../../operations/carddav-contacts.md)を実装。専用資格情報、条件付き更新、変更tokenと削除tombstone、bounded REPORTを追加。09:04:17 JSTに[v0.6.0として本番2系統へ反映](../../operations/deployments/2026-11-02-v0.6.0.md)。共有アドレス帳・外部CardDAV connector・実機互換確認は同資料の後続範囲。
|
||||
|
||||
2026-11-01:[タスク作成・作業記録・達成度・日次メール・個人アドレス帳](task-productivity-contacts.md)を追加。Web/CLI/neomuttの共通capture、時間記録、既定値、検索コマンドを接続。作業記録の事後訂正、日次メールの再送・保持期間は同設計の後続範囲へ集約する。
|
||||
2026-11-01:[タスク作成・作業記録・達成度・日次メール・個人アドレス帳](task-productivity-contacts.md)を追加。Web/CLI/neomuttの共通capture、時間記録、既定値、検索コマンドを接続。作業記録の事後訂正と日次メールの再送・保持境界は2026-11-08の実装へ進んだ。
|
||||
|
||||
2026-10-31:ユーザ指定により[日常操作・ブラウザ・エディタ・CLI](priority-ux-20261031.md)を次期開発の最優先とする。下記の従来機能追加より優先するが、認可・データ保全の安全条件は省略しない。TODO、受け入れ条件、復元用チェックポイントを同文書に集約する。
|
||||
|
||||
@@ -34,7 +46,7 @@
|
||||
| P1-3 | 検索・decode・大容量 | 現行上限と測定 | current-only検索、隔離、stream、cancel |
|
||||
| P2-1 | 通知と承認Inbox | P0、outbox | 現在権限で再表示・決裁・失効 |
|
||||
| P2-2 | HTMLパーツ | round-trip fixture | macro/asset/未知HTMLを壊さない |
|
||||
| P2-3 | local task | extension契約、原子的ジャーナル | 個人タスク/プロジェクト・Inbox通知・個人local時間枠・永続化Pomodoro・Todayの見積/時間枠/集中集約を実装済み。次は計画持ち越し、日課、共有 |
|
||||
| P2-3 | local task | extension契約、原子的ジャーナル | 個人タスク/プロジェクト・Inbox通知・個人local時間枠・永続化Pomodoro・日別計画と持ち越し・作業記録訂正と集計・日次メール再送を実装済み。次は失効Domainの作業記録回復、日課、共有 |
|
||||
| P2-4 | RSS読取・Wiki保存 | connector共通部 | FreshRSS fixtureと安全なcopy |
|
||||
| P2-6 | 料理レシピ管理 | Document/Asset、検索、権限 | 材料・分量・手順・調理時間・人数・タグを構造化し、単位変換と安全な共有を検証 |
|
||||
| P3 | calendar/contact/mail | import/secret/競合契約 | read-only同期、明示copy、障害復旧 |
|
||||
@@ -57,7 +69,7 @@ P2以降の順序は利用価値で入れ替え可能ですが、P0の該当安
|
||||
- 認証・グループ:実装あり。全endpoint監査・identity lifecycleが残り。
|
||||
- 匿名公開・children/tree/City:実装あり。大規模影響確認、share、承認Inboxが残り。
|
||||
- ブログ・日記・公開射影・本文RSS:実装あり。遠隔射影、コメント、tDiary等が残り。
|
||||
- オーガナイザー:カレンダーと限定CalDAV、個人タスク/プロジェクト・個別ONのInbox通知、個人local時間枠と永続化Pomodoroあり。[タスク実装契約](tasks-implementation.md)、[時間枠とPomodoro](task-planning-focus.md)参照。一般のカレンダー予定通知・共有・VTODO、RSS購読・IMAPは未実装。
|
||||
- オーガナイザー:カレンダーと限定CalDAV、個人タスク/プロジェクト・VTODO同期・個別ONのInbox通知・個人local時間枠・永続化Pomodoro・日次メール・個人CardDAV・ウィジェットダッシュボードあり。[タスク実装契約](tasks-implementation.md)、[時間枠とPomodoro](task-planning-focus.md)、[タスク所属とDAV同期](task-dav-project-unification.md)参照。一般のカレンダー予定通知・共有、DAV競合候補の通知と採否選択、RSS購読・IMAPは残件。
|
||||
- 全面WYSIWYG、native app起動、第三者runtime、vim.wasm改善:判断待ちまたは保留。
|
||||
|
||||
## 共通のDone
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
# 日次タスクメールの配信履歴と手動再送
|
||||
|
||||
2026-11-08、`organizer.tasks 0.14.0` のソース実装。個人設定で配信試行を確認し、当日分を明示的に再送できる。送信は既存の `task.digest.deliver` イベントが行い、Webリクエスト内ではSMTPに接続しない。本番反映は別工程とする。
|
||||
|
||||
## 利用者の操作と公開範囲
|
||||
|
||||
入口は `/-/sys/config?panel=organizer` の「メール配信履歴・再送」。初期は閉じておき、開いたときだけ履歴を取得する。自動ポーリングは行わず、更新ボタンとページ送りを用意する。PCは表、スマホは表の領域内だけ横スクロールする。
|
||||
|
||||
本人・現在のDomainの履歴だけを返す。管理者権限は他人の履歴を読む根拠にならない。readonlyは閲覧だけ可能。無効化したタスク拡張へのAPIアクセスは拒否する。履歴には対象日、定期/手動/移行前の区分、状態、更新時刻、理由コードだけを表示する。本文・宛先・SMTP認証情報・生のエラーを保存しない。
|
||||
|
||||
再送は保存済みの配信設定が有効で、当日の配信試行が既に存在する場合だけ可能とする。初回配信の前倒しや過去日のまとめ送りは含めない。現在のタスクから本文を再構成し、現在の本人のアカウントメールアドレスへ送る。元のメールの完全な再現ではない。設定画面の未保存値は使わない。
|
||||
|
||||
送信済みまたは結果不明の場合は、受信状況を確認し、重複配信の可能性を了承するチェックを必須にする。送信中・待機中には次の再送を受け付けない。同じDomain・本人・日付につき、手動要求は最大5件。処理前に中止された要求も回数に含める。
|
||||
|
||||
## API
|
||||
|
||||
基点は `/_/api/v1/extension/organizer.tasks/`。既存の個人タスクAPIと同じ認証を用いる。CalDAV専用資格情報を一般APIの資格情報へ拡張しない。
|
||||
|
||||
| 操作 | URI | 内容 |
|
||||
| --- | --- | --- |
|
||||
| GET | `digest-history?limit=25&after=...` | 新しい順のitems、次のcursor、設定timezoneのtoday、当日のcurrent、手動要求数retries、配信設定enabled、retention_days |
|
||||
| POST | `digest-history/retry` | request_id、day、expected_attempt、duplicate_acknowledgedを受け取り、受付成功は202とrequest_id |
|
||||
|
||||
一覧は1〜100件、既定50件、Webは25件。`created_ms, uuid` のkeysetを使う。cursorは256 bytes以内。expected_attemptは一覧で取得した当日のcurrent.uuidをそのまま送る。
|
||||
|
||||
要求IDはクライアント生成のcanonical UUID。同じ要求IDと同じ内容の再送は新たな予約を作らない。異なる内容での再利用、古いexpected_attempt、実行中、上限到達は412。対象日が現在の配信timezoneの今日でない場合や、必要な重複確認がない場合は422。配信設定OFF、readonly、権限不足は拒否する。APIはSMTP有効設定とアカウントのメール形式も確認する。
|
||||
|
||||
Webはネットワーク失敗時に同じ要求IDを保持して再試行する。受付済みの要求をGETで観測した場合は、再送を重ねず状態表示へ切り替える。古い要求のreceiptがある場合は、日付が過ぎたり詳細履歴が整理された後の同内容再送にも既存の受付IDを返す。新しいSMTP処理は起こさない。受付応答はメールの到達を意味しない。
|
||||
|
||||
## 状態とワーカー
|
||||
|
||||
| 状態 | 意味 | 次の扱い |
|
||||
| --- | --- | --- |
|
||||
| queued | 手動要求をDBで受付済み | スケジューラがclaimする |
|
||||
| sending | 1つの試行が送信処理を担当 | 通常はsent、uncertain、cancelledへ遷移 |
|
||||
| sent | SMTP処理が正常終了 | 受信箱への到達保証ではない。手動再送には確認が必要 |
|
||||
| uncertain | SMTP結果が不明、またはワーカー中断の可能性 | 自動再送しない。手動再送には確認が必要 |
|
||||
| cancelled | SMTPに渡す前に処理中止 | 原因を確認し、当日なら手動で再予約できる |
|
||||
|
||||
イベントは60秒周期。定期配信の候補は最大20件、手動キューは最大10件を取得し、両者を交互に処理する。全体の時間予算は30秒で、残りは次回へ持ち越す。手動キューは受付時の設定versionを固定する。claim時に権限・拡張機能・配信同意・設定version・対象日を確認し、変更されていれば送信中止にする。
|
||||
|
||||
SMTP直前にも、現在の権限・メールアドレス・同意version・拡張状態・対象日・試行IDを読み取りtransactionで再確認する。2分以上古いclaimでは送信を開始しない。処理の終了は現在の試行IDと状態が一致するときだけ保存し、古いワーカーが新しい試行を完了扱いにできないようにする。
|
||||
|
||||
10分以上sendingのままの試行は、イベントの保守処理で最大100件ずつuncertainへ移す。これは「未送信」との断定ではない。プロセス停止・長い休止・SMTPの応答喪失では送信済みの可能性がある。SMTPとDBを一つのtransactionにできないため、exactly-onceや、休止した古いプロセスからのネットワーク送信を完全に取り消す保証はしない。明示確認付きの再送でこの不確実性を扱う。
|
||||
|
||||
理由コードはSMTP未設定、タスク取得失敗、設定・権限変更、拡張無効化、対象日経過、SMTP結果不明、ワーカー中断に限定する。イベントログには件数だけを残す。
|
||||
|
||||
## DBの正本と保持境界
|
||||
|
||||
正本はSQLite。配信に関する以下の3つを分離する。
|
||||
|
||||
| テーブル | 役割 | 保持 |
|
||||
| --- | --- | --- |
|
||||
| organizer_digest_deliveries | Domain・本人・日付の予約と現在の試行ID/状態 | 恒久。日別の自動二重配信を防ぐ |
|
||||
| organizer_digest_requests | 手動要求IDと要求内容・重複確認・受付時刻 | 恒久。同じ要求の再受付を防ぐ |
|
||||
| organizer_digest_attempts | 個々の試行状態・理由・日時 | 終端状態のupdated_msから90日。queued/sendingは削除対象外 |
|
||||
|
||||
詳細の削除はイベント1回につき最大500件で、日時と状態のindexから選ぶ。設定や再送受付は別のwriter transactionで行い、削除と同じSQLite書き込みロックに従う。日別予約と手動receiptを削除・再作成しない。詳細が期限切れになると古い予約が指す試行の詳細行は存在しなくなるが、予約の状態と重複防止機能は残る。現時点では恒久記録の圧縮・失効は実装しない。
|
||||
|
||||
## 移行と復旧
|
||||
|
||||
task-productivityのmanaged migration v4で、既存の日別予約へattempt_uuidを追加し、試行・受付receiptのテーブルとindexを作る。既存の日別予約を削除せず、元のstateとupdated_msを保ってlegacy試行へ対応付ける。旧試行の設定version・timezoneは不明として扱い、現在の設定から過去の同意を推測しない。
|
||||
|
||||
DDL、旧データの対応付け、migration台帳の更新は同じtransactionで完了する。途中失敗なら旧スキーマと予約へ戻る。再実行でIDや予約を再生成しない。前段のv3を含め、旧migration定義の書き換えは行わない。
|
||||
|
||||
本番反映前には、書き込みを停止した整合DBバックアップと、対応するイメージを確保する。反映後にschema version、予約数、legacy試行との対応、`PRAGMA integrity_check` を確認する。旧イメージは更新DBに接続しない。forward-fixを基本とし、旧DBへ戻す場合は更新後の書き込みを保全して照合する。
|
||||
|
||||
特にメールはDB外で送信されるため、送信開始後のバックアップ復元だけでは重複防止を復元できない。復旧時はイベントの自動送信を止め、更新後の予約・receiptを保全して照合し、送信済みか不明な分を自動再送しないこと。移行・反映・復旧の成功と、実際の受信箱への到達は別の確認である。
|
||||
|
||||
## 受け入れ条件と後続
|
||||
|
||||
- 旧予約の全状態を保つ移行、反復、途中失敗のrollback、DB integrity check。
|
||||
- 二重クリック・応答喪失後の同一要求、異内容再利用、当日制約、5回上限。
|
||||
- readonly・別本人・未認証・配信OFF・権限失効・設定変更・日付経過の拒否または送信中止。
|
||||
- 古い試行の送信前チェックと完了通知の拒否、SMTP結果不明の扱い。
|
||||
- 詳細を削除した後も、手動receipt再送や日別自動claimで配信が復活しないこと。
|
||||
- fake SMTPを用いた予約から送信・結果保存までの試験。ブラウザはPCと390px幅。
|
||||
|
||||
検証結果:`go test ./...`、`go vet ./...`、追加の受付競合・権限・保持境界テストの `-race`、JavaScript構文検査が成功。Chromiumの1440px・390pxで、履歴の遅延読込、重複確認、受付応答の喪失後の同一ID再試行、キュー処理後の状態表示を確認した。DB移行の反復・途中失敗のrollbackと `PRAGMA integrity_check` は隔離DBで確認。本番DBは変更していない。
|
||||
|
||||
後続は保持期間の管理UI、恒久receiptの安全な圧縮、当日予約の明示取消、配信結果のInbox連携、複数ワーカーの運用メトリクス。共有送信先・任意宛先・過去日の送信はこの機能へ暗黙に追加しない。
|
||||
@@ -13,6 +13,9 @@
|
||||
| 実行中の記録 | GET `work` | itemがnullなら停止中 |
|
||||
| 開始 | POST `work` | action=start、uuid、task_uuid。開始時刻はサーバーで記録 |
|
||||
| 終了 | POST `work` | action=stopとGETで得たitem。versionで条件付き更新 |
|
||||
| 作業一覧 | GET `work-history?from=YYYY-MM-DD&to=YYYY-MM-DD&limit=50&after=...` | fromを含みtoを含まない期間と重なる本人の記録。最大367日、1ページ最大100件、取消済みを含む |
|
||||
| 作業の履歴 | GET `work-history/{uuid}?before=VERSION` | 新しい版から最大100件。nextが0なら終了。それ以外は次のbeforeへ渡す |
|
||||
| 作業の訂正・取消 | POST `work` | action=correctまたはcancel、uuid、version、reasonが必須。終了済み・未取消の記録のみ |
|
||||
| レポート | GET `report?from=YYYY-MM-DD&to=YYYY-MM-DD` | fromを含み、toを含まない。ドメインのtimezone、最大367日 |
|
||||
| 予定を作る | POST `calendar-capture` | request_id、calendar_uuid、title、from、to。本人所有・非公開・非共有・外部sourceなしのカレンダー限定 |
|
||||
|
||||
@@ -24,9 +27,15 @@ Webの新規作成・クイック追加・サブタスク追加でも既定値
|
||||
|
||||
### メール本文のWiki保存
|
||||
|
||||
v0.9.0は任意の `wiki_suffix` をcaptureに追加する。CLI v0.4.0はML連番なら `リスト名/連番`、それ以外は `YYYY/MM/UUID`(Message-IDあり)または `YYYY/MM/原文SHA-256`(なし)を送る。Dateの記載タイムゾーンの年月を採用し、不正・欠落時のみ初回取り込みUTC年月を用いる。判定はCLIで確定してoutboxに保持する。リスト名はASCII英数字で始まる100文字以内の英数字・`._-`、連番は先頭ゼロ除去後最大20桁。複数表記は先頭を採用する。不正な表記は年月方式へフォールバックする。
|
||||
|
||||
サーバーはMLの2階層または年月の3階層だけを受理し、絶対Path・`.`・`..`・予約セグメント・query/fragment・不正年月・不正識別子を拒否する。解決した親Pathの下へ結合し、その完全Pathのread/create/write権限を検証する。衝突は409で、別Message-IDのタスクも部分作成しない。wiki_suffixはwiki_body指定時のみ許可する。省略時は従来の `mail-request_id` とし、旧receiptのhash・保存先を維持する。新CLIは旧サーバーに暗黙フォールバックしない。既存ページの自動移動、同じ件名・同じ連番の上書きは行わない。設定変更や月替わりで保留要求を書き換えず、異なるオプションでの上書きを拒否する。
|
||||
|
||||
v0.8.0ではcaptureに省略可能な `wiki_body` と `wiki_prefix` を追加する。wiki_bodyを省略した従来クライアントの契約・receipt hashは変えない。本文を指定した場合、親Pathは要求のwiki_prefix、個人preferencesのwiki_prefix、選択プロジェクトの関連WikiとNotesSubpath(未設定はtasks)の順に解決する。いずれもなければ422 `wiki_prefix_required`。空の明示指定も拒否する。個人設定はDomain・本人単位で、既存preferences JSONに保存するため新規schema migrationは不要。
|
||||
|
||||
本文は256 KiBまでのUTF-8テキスト。H1に件名、preに本文をHTMLエスケープして格納し、波括弧も実体参照にしてマクロを実行しない。Pathは `親Path/安全化した件名--request_id`。既存Pathとの競合は409で、既存ページへ追記・上書きしない。新規Wikiのobject/path/revisionとactivity outbox、タスクのPageUUID、capture receiptは同一DBトランザクションで保存する。rollback時に未参照のcontent-addressed Documentファイルが残る可能性は既存DocumentStoreと同様だが、公開可能なページや片方だけのタスクは残さない。
|
||||
本文は256 KiBまでのUTF-8テキスト。H1に件名、preに本文をHTMLエスケープして格納し、波括弧も実体参照にしてマクロを実行しない。v0.8.1、およびv0.9.0以降でwiki_suffixを省略した場合のPathは `親Path/mail-request_id`。CLIは接続先・本人・Message-ID(なければ原文SHA-256)からrequest_idを生成するため、Path末尾は件名・日本語の文字数・ML連番に依存しないASCIIになる。Message-ID自体はURLへ露出しない。既存Pathとの競合は409で、既存ページへ追記・上書きしない。新規Wikiのobject/path/revisionとactivity outbox、タスクのPageUUID、capture receiptは同一DBトランザクションで保存する。rollback時に未参照のcontent-addressed Documentファイルが残る可能性は既存DocumentStoreと同様だが、公開可能なページや片方だけのタスクは残さない。
|
||||
|
||||
v0.8.0の件名入りPathは自動移動しない。既存receiptの同一要求再送は元のページを返す。CLI v0.3.1は先頭のML連番を除去し、長い自動件名は300 UTF-8 bytes以内に文字境界で省略、変更前のSubjectをWiki本文へ保持する。旧版で保存済みの要求を新しい件名・本文で再作成すると412となるため、通信失敗した要求は保存済みoutboxのretryを使う。v0.8.1ではサーバーAPIの入力フィールド・receipt hash形式を変更していない。v0.9.0ではwiki_suffix未指定時のhashを維持し、指定時はsuffixもhashの対象に含める。
|
||||
|
||||
保存前に対象Pathへのread/create/write権限を検証する。個人タスクの所有権はWikiへの権限を付与しない。Wiki本文の公開範囲は保存先のACLに従うため、個人設定UIに注意を表示する。再送は既定値の再解決より前にreceiptを確認し、既定Pathの変更で重複作成しない。成功応答はitemとpage_pathを返し、タスクの既存メモ操作から関連Wikiへ移動できる。
|
||||
|
||||
@@ -42,13 +51,35 @@ Webのタスク行の▶から開始し、上部の作業記録欄で終了す
|
||||
|
||||
深夜をまたぐ作業はローカル日付境界で分割し、夏時間の日も24時間固定にしない。Pomodoroと手動記録は別集計で、両者を合算しない。各系列は最大10,000件で、上限到達時はpartialを返して期間の絞り込みを促す。
|
||||
|
||||
### 作業記録の訂正と取消
|
||||
|
||||
2026-11-08に `organizer.tasks 0.13.0` としてソース実装。`/v/plan/tasks/work` で一覧と変更履歴を確認し、開始・終了をインラインで訂正する。タスク一覧とダッシュボードの達成度ウィジェットから移動できる。初期期間はドメイン時刻の今日を含む30日。ページ送りは開始時刻・UUIDのkeysetで行い、一度に全履歴を描画しない。変更履歴も開いた記録だけ取得する。スマホはラベル付き縦配置にし、操作部を44px以上とする。
|
||||
|
||||
訂正には `start_ms`・`end_ms`、または `start`・`end` の日時ペアを渡す。日時文字列はオフセット付きRFC 3339、あるいはドメインのタイムゾーンでの `YYYY-MM-DDTHH:mm[:ss]`。夏時間移行で存在しない・二通りに解釈できるローカル時刻は422。繰り返される時刻はAPIから明示オフセットを指定する。Webで未変更の時刻は元の瞬間をRFC 3339で送るため、ミリ秒やオフセットを失わない。
|
||||
|
||||
開始はUNIX epochより後、終了は開始より後かつ現在以前、訂正後の長さは31日以内。同じ本人の他の未取消記録と重なる区間は、別Domainも含めて412で拒否する。隣接区間は許可し、他Domainの記録内容は返さない。実行中は従来の終了操作を先に行う。`reason` は前後空白除去後1〜500 UTF-8 bytes、改行・NUL不可。Web入力は160文字まで。
|
||||
|
||||
取消は物理削除ではなく `cancelled_ms` を記録し、作業時間レポートから除外する。タスクの状態・完了ポイントは変更しない。元の時刻と全変更履歴は残る。訂正・取消後の自動復元、過去の記録の新規挿入はこの段階では扱わない。
|
||||
|
||||
現在値と監査snapshotは同じwriter transactionで保存する。認可・拡張機能の有効状態をロック内で再検査し、versionが一致しない更新は412。理由・変更前後の時刻・版・変更時刻を記録し、他人の記録を管理者権限だけで操作する経路は設けない。通信結果が不明な訂正・取消の再送もversionを検証し、古ければ412にする。最新値と履歴を再取得して判断する。Webは失敗時に入力を保持し、自動上書きしない。従来の開始・終了の再送契約は維持する。
|
||||
|
||||
移行前の記録には過去の編集履歴を捏造しない。初回の変更時に直前の値をbaselineとして捕捉する。baselineのchanged_msは捕捉時刻であり、過去の編集時刻ではない。未変更の旧記録を開いた際は現在値だけをbaselineとして表示する。
|
||||
|
||||
### プロジェクト別の集計
|
||||
|
||||
`report` の `projects` 配列にUUID・タイトル・完了数・ポイント・作業時間を返す。ダッシュボードの達成度ウィジェットに表を追加し、日付セルで選んだ日の内訳にも反映する。プロジェクトなしは独立した行とする。所属は現在のタスクから取得するため、過去時点の所属スナップショットではない。Pomodoroはプロジェクト表に合算しない。
|
||||
|
||||
集計は既存の上限付き取得結果を再利用し、プロジェクトごとに追加クエリを発行しない。10,000件上限でpartialとなる場合はプロジェクト表も部分集計であり、全件合計とは表示しない。
|
||||
|
||||
## 毎日のメール
|
||||
|
||||
`/-/sys/config?panel=organizer` の個人設定で本人が有効化する。旧 `/v/plan/tasks/settings` もここへ移動する。送信先は現在の本人のアカウントメールアドレスのみ。管理者のSMTP設定が必要。時刻はHH:mmとIANA timezoneを保存する。`task.digest.deliver` イベントが60秒周期で期限到来設定を最大20件ずつ処理する。キュー停止・負荷・SMTP遅延で配信時刻が遅れる場合がある。
|
||||
|
||||
当日の計画・期限到来タスクを最大100件送る。件名、期限、取り組む日、見積、タスクURLを含め、メモは送らない。送信直前にアカウント状態・同意のversion・送信先を再確認する。メールによる保存・転送の可能性があるため、既定は無効。
|
||||
|
||||
SMTPとSQLiteをまたぐexactly-onceは保証できない。送信前にDomain・本人・日付で予約し、配送結果はsent、uncertain、cancelled。予約後のクラッシュはsendingとして残す。結果不明の場合は自動再送せず、二重送信を避ける。翌日は通常通り処理し、過去日の取りこぼしをまとめて送らない。設定画面に直近結果を表示する。
|
||||
SMTPとSQLiteをまたぐexactly-onceは保証できない。送信前にDomain・本人・日付で予約し、結果不明の場合は自動再送しない。翌日は通常通り処理し、過去日の取りこぼしをまとめて送らない。
|
||||
|
||||
2026-11-08に `organizer.tasks 0.14.0` として[配信履歴・当日分の手動再送・詳細90日保持](task-digest-delivery.md)をソース実装。個人設定の折り畳み履歴から操作する。送信済み/結果不明の再送には重複の了承が必要。詳細の保持期限後も日別予約・再送receiptを残し、重複防止を維持する。migration v4とDB外のメール送信を考慮した復旧条件は同設計を参照。
|
||||
|
||||
## トップ検索コマンド
|
||||
|
||||
@@ -81,8 +112,18 @@ vCardの内容はDocumentStore snapshot、現在値と所有者・version・検
|
||||
managed schemaにtask-productivityとcontactsを追加。task-productivityは既存organizer_items作成後に実行し、旧完了タスクを1回だけ集計projectionへ移す。既存スキーマ定義の改変ではない。切戻しでは旧版のschema checkが新コンポーネントを未知とするため、単に旧イメージを起動できるとは扱わない。データを消して戻さない。
|
||||
|
||||
- 連絡先の共有アドレス帳、外部CardDAV connector、重複候補mergeは別段階。個人CardDAV提供面と外部サービスの取り込みは区別する。
|
||||
- 作業記録の事後修正・取消、失効Domainで取り残された記録の管理用終了手順、プロジェクト別集計、担当者への共有・通知は後続。
|
||||
- 日次メールの手動再送・配信ログの保管期間、receiptの失効設計は後続。安易な削除で重複作成・配信を復活させない。
|
||||
- 失効Domainで取り残された記録の管理用終了手順、取消済み記録の復元、作業監査履歴の保持期間、担当者への共有・通知は後続。
|
||||
- 日次メールの保持期間UI、恒久receiptの圧縮・失効、配信結果のInbox連携は後続。現在は詳細90日、重複防止記録は恒久保持とする。
|
||||
- vCard legacy変換・version間変換と履歴保持期間は後続。
|
||||
|
||||
利用手順は [neomuttとタスクCLI](../../operations/neomutt-tasks.md) を参照。
|
||||
|
||||
### 作業履歴の移行と検証
|
||||
|
||||
task-productivityのmanaged migration v3は、作業記録へのcancelled_ms追加、organizer_work_revisionsの作成、本人別の区間検索index追加を行う。既存の作業時刻・versionは保ち、既存記録は未取消とする。新しい監査データの正本はSQLiteで、アプリのDBバックアップに含める。
|
||||
|
||||
反映前に整合したDBバックアップを取得する。旧版は取消済み記録を正しく集計できず、schemaのversionも一致しないため、更新DBに旧イメージを向ける切戻しは禁止する。通常はforward-fixを選ぶ。復旧が必要ならアプリを停止し、移行前のDBと対応するイメージへ一緒に戻す。更新後の書き込みは別途保全・照合してから復旧する。本番反映は別工程。
|
||||
|
||||
受け入れ試験は、旧スキーマ移行の反復、本人・Domain分離、readonly・失効・無効化、版競合、重複時間、夏時間の欠落・重複、監査失敗時のrollback、並行訂正、取消による集計除外を対象とする。ブラウザはデスクトップと390px幅で訂正・取消・履歴・412時の入力保持を確認する。既存CLIの開始/終了とCalDAVの契約は変更しない。
|
||||
|
||||
2026-11-08の検証結果:`go test ./...`、`go vet ./...`、追加した競合・監査試験の `-race`、変更JSの構文検査が成功。Chromiumの1440px・390pxで、ダッシュボードのプロジェクト別表から履歴へ移動し、訂正・取消・監査表示・競合時の入力保持と横幅の収まりを確認した。すべて隔離fixtureによる試験で、本番移行は未実施。
|
||||
@@ -33,14 +33,14 @@ create/read/update/assign/transition/comment/manageは概念上分離します
|
||||
|
||||
iCalendarにはVTODOがあり、CalDAVはカレンダー資源を扱います。ただしクライアントごとのタスク・繰り返し対応を試験する必要があります。これは「CalDAVだけでチケット管理が完成する」という意味ではありません。[iCalendar](https://www.rfc-editor.org/rfc/rfc5545)、[CalDAV](https://www.rfc-editor.org/rfc/rfc4791)。
|
||||
|
||||
最初はlocal task一覧と期限表示、次にVTODOの明示export/import、最後に選定クライアントとの同期を検討します。workflow、コメント、細かな権限をVTODOへ無理に押し込みません。失われる情報を変換警告に残します。
|
||||
local task一覧と期限表示、限定VTODO/CalDAV同期は実装済みです。次は上書き競合の候補保存と採否、時刻期限・繰り返し・アラーム・差分同期を個別に扱います。workflow、コメント、細かな権限をVTODOへ無理に押し込みません。失われる情報を変換警告に残します。
|
||||
|
||||
## 実装TODO
|
||||
|
||||
- TASK-1:個人local作成/取得/更新、version競合、Page参照、所有者限定一覧は実装済み。削除は復元可能なアーカイブ、物理削除は未提供。
|
||||
- TASK-2:日付の期限/計画/見直し、タイトルフィルタ、archive、個別ONのInbox通知は実装済み。担当共有、通知集約、exportは未実装。
|
||||
- TASK-3:checklist/依存とboundedな一覧・calendar射影。
|
||||
- TASK-3:2階層サブタスク、boundedな一覧、日割り工程表・個人時間枠は実装済み。一般依存グラフ、共有、一括計画・日別capacityは後続。
|
||||
- TICKET-1:queue・番号予約・workflow版・権限付き遷移。
|
||||
- TASK-4:VTODO fixture、未対応property保持、繰り返し・同期の判断。
|
||||
- TASK-4:限定VTODO fixtureと同期、プロジェクト対応・既定リスト名変更は実装済み。繰り返し・時刻期限・差分同期と競合候補の通知/採否は後続。[所属統一](task-dav-project-unification.md)と[残件台帳](implementation-backlog.md)を参照。
|
||||
|
||||
同時採番、二重POST、完了取消、夏時間・終日、assignee失効、本文削除を受け入れ試験にします。
|
||||
@@ -43,6 +43,42 @@ Principalで直下の子だけを認可し、最大250件、`private, no-store`
|
||||
modeをdata属性で指定する。これにより今後のストレージ、アダプタ、City設定でも
|
||||
任意HTMLや専用ファイルブラウザを増やさず同じPickerを再利用できる。
|
||||
|
||||
## 実装済みの壁紙連動配色
|
||||
|
||||
壁紙の色調からアクセントとグラス面の配色を生成し、トップ画面 `/` とその上で開く
|
||||
ダイアログにだけ適用する。通常のViewer、Editor、設定画面、ログイン画面の配色は
|
||||
変更しない。iframe内に独立して表示されるビューにも配色は継承しない。
|
||||
|
||||
設定は `/-/sys/config?panel=home` またはトップ画面右下の歯車から行う。既存のトップ
|
||||
画面設定と同じ管理権限を必要とし、ドメイン共通で保存する。歯車のダイアログでは
|
||||
その場でプレビューし、キャンセル・ESCで保存前の状態に戻す。
|
||||
|
||||
| 項目 | 値と既定値 |
|
||||
| --- | --- |
|
||||
| 壁紙との色連動 | `off`、`accent`、`surface`。既定は `surface`(背景も連動) |
|
||||
| 色の反映量 | 0–100。既定は35。0では元のテーマを維持 |
|
||||
| 明暗 | `preserve`(既定、現在のテーマを維持)、`auto`(表示時の壁紙の明るさから判定) |
|
||||
|
||||
`home_wallpaper_palette` に `{"mode":"surface","strength":35,"brightness":"preserve"}`
|
||||
の形式で保存する。明暗の自動判定は背景も連動する場合だけ有効。グラスの透明度は
|
||||
既存の `home_glass_transparency` で独立して調整する。警告・エラー等の意味を持つ色は
|
||||
上書きしない。壁紙がない場合、画像が壊れている場合、Canvasから色を読めない場合、
|
||||
強制カラーモードの場合は元のテーマを維持する。
|
||||
|
||||
表示済みの画像を64×64へ縮小し、初回描画後のアイドル時間に平均色と彩度を重み付け
|
||||
したアクセント候補を抽出する。追加の画像取得、サーバでの画像解析、定期ジョブは不要。
|
||||
画像表示URLは選択したリビジョンに固定し、抽出結果をDomain UUIDと画像SHA256の組で
|
||||
sessionStorageに最大24件保存する。キャッシュにはRGB値と透明部分の割合だけを保存し、
|
||||
画像本体は保存しない。ストレージが使えない場合は表示中の画像から抽出する。
|
||||
|
||||
文字・リンクは推定したグラス背景とのコントラストを補正する。ただし画像の局所的な
|
||||
明暗までは保証しないため、細かい柄で読みにくい場合は透明度を下げるか色連動をオフにする。
|
||||
既存テーマを切り替えた際は新しいテーマを基準に再計算し、オフにするとそのテーマに戻る。
|
||||
|
||||
回帰テストは `node --test static/js/home-palette-core.test.cjs` と `TestHomePalette*`。
|
||||
`PAGESWIKI_BROWSER_TEST=1` でブラウザテストを有効化すると、一時DBと合成画像を使い、
|
||||
保存・キャンセル・再読み込み時のキャッシュ利用・テーマ切替・画面幅を通して検証する。
|
||||
|
||||
## サイドバー詳細設計(実装待ち)
|
||||
|
||||
管理画面のグループ化されたサイドバーは
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# PagesWiki v0.8.0 本番反映
|
||||
|
||||
2026-11-06 08:48:35 JST、本番のapp・app2・adaptor-gateway・excalidraw-viewerをv0.8.0へ更新した。このホストの `/home/anya/.local/bin/pages` も公開ELFのpages-cli v0.3.0へ更新した。機能・配布物は[リリース記録](../releases/2026-11-06-mail-wiki.md)を参照する。
|
||||
|
||||
## 保全と切替
|
||||
|
||||
`.deployment-backups/release-v0.8.0-20261106/` に構成とデータを保全した。configには旧 `.env`、`.env.release`、Compose、旧CLIの `pages-before-v0.3.0` がある。親ディレクトリ0700、構成コピー0600。data・data2は内容を解釈しないファイルコピーで、外部取り込みカレンダー要素にはアクセスしていない。
|
||||
|
||||
最終 `cutover/data`・`cutover/data2` は対象サービス停止後にchecksum付きrsyncで確定し、差分ゼロ、DB・WAL・SHMのバイト一致と稼働元と異なるinodeを確認した。未変更ファイルは前回の不変バックアップとのみlink-destで共有する。稼働元へのハードリンクは作らない。既存バックアップは削除していない。
|
||||
|
||||
| 時刻 JST | 操作 |
|
||||
| --- | --- |
|
||||
| 08:47:23 | 対象4サービス停止開始 |
|
||||
| 08:48:29 | 最終バックアップ検証完了 |
|
||||
| 08:48:35 | v0.8.0起動完了 |
|
||||
|
||||
停止開始から起動完了まで72秒。リリースイメージとSHAイメージのID・source revision一致を確認してから、`.env.release` をv0.8.0へ変更し、registry overlayの `up --no-build --no-deps` で対象4サービスだけ更新した。旧v0.7.1イメージは `rollback-before-v0.8.0-20261106` を付けて保持し、ローカルlatestを新リリースへ揃えた。registry latest、code-server、Kroki等は変更しない。
|
||||
|
||||
DBスキーマ変更はない。新イメージをネットワークなし・読み取り専用で起動するschema checkを切替前に両データ系統へ実施した。切戻し時は書込みを停止して現状も保全し、新CLIのWiki保存を停止する。旧版で個人設定を保存するとwiki_prefixが失われ得る。バックアップの自動復元は行っていない。
|
||||
|
||||
## 検証
|
||||
|
||||
- 対象4コンテナのsource revisionは `80d297dab40871b42ff2afb2ab6212661c465248` と一致。起動正常、再起動0回。appとExcalidrawはhealthy、app2の内部healthも成功。
|
||||
- 両系統の管理対象12コンポーネントはcurrent。legacy領域を含む全データ完全性の検査ではない。
|
||||
- 公開HTTPSでhealth・ログインは200。匿名のタスク・個人設定は303、preferences API・CardDAVは401。
|
||||
- 公開tasks.js・task-productivity.js・tasks.cssのSHA-256がv0.8.0と一致。
|
||||
- 初期ログのpanic、fatal、DB lock、job failed、scheduler claim failed、errorレベルの一致件数は0。
|
||||
- ホストCLIは公開ELFとバイト一致し、versionは0.3.0、from-mailの新オプションも確認した。既存資格情報・セッション・NeoMutt設定は変更していない。
|
||||
|
||||
認証済みのメール取り込み・個人設定操作は一時DBと合成データで検証し、本番にテストメールやタスクを追加していない。利用者の既定Pathは自動設定せず、保存先のACLを確認したうえで本人が選択する。反映後の空き容量は約33 GiB。
|
||||
@@ -0,0 +1,45 @@
|
||||
# ML連番・年月別メール保存先
|
||||
|
||||
PagesWiki v0.9.0とpages-cli v0.4.0は、メール本文を関連Wikiへ保存するとき、ML連番を優先してPathを決める。ML連番がないメールは年月で分割する。件名は表示に使い、日本語件名を識別用Pathには使わない。
|
||||
|
||||
| 優先順 | 判定 | 保存先 |
|
||||
| --- | --- | --- |
|
||||
| 1 | 先頭のML連番あり(例: `[hogehoge 00123]`) | `親Path/hogehoge/123` |
|
||||
| 2 | ML連番なし、Message-IDあり | `親Path/YYYY/MM/UUID` |
|
||||
| 3 | どちらもなし | `親Path/YYYY/MM/原文SHA-256` |
|
||||
|
||||
UUIDは接続先・本人・Message-IDから従来どおり生成する。Message-ID自体はURLへ露出しない。年月はメールのDateヘッダーに記載されたタイムゾーンを尊重する。Date欠落・不正時は初回取り込み時のUTC年月を採用し、再送用outboxへ保存する。月をまたいで同一の保留メールを再入力しても保存先は変えない。
|
||||
|
||||
MLリスト名はASCII英数字で始まる100文字以内の英数字・ピリオド・ハイフン・アンダースコア。連番は最大20桁で先頭ゼロを除く。安全なML表記として認識できないものは年月方式にする。同じML連番の別メールは409で拒否し、タスクの部分作成や既存Wikiの上書きを行わない。
|
||||
|
||||
APIの追加フィールドは省略可能なwiki_suffixのみ。省略時の旧Path・receipt hashは維持する。新CLIの本文取り込みには新サーバーが必要。既存メールの一括移動は行わず、旧版で保持済みの再送要求はそのまま扱う。DBスキーマ変更はない。
|
||||
|
||||
## ソースと検証
|
||||
|
||||
- サーバー: `1a451023f09f483f5efff450dc2c951c925eb999`
|
||||
- CLI: `e22af6a0ecc2b001d6cc0d41901470f535fd8126`
|
||||
- 手元のGo全体テスト・go vet、CLI単体44件が成功。
|
||||
- サーバーCI run 43の全体テストが成功。合成メールを使うHTTP結合試験は手元で実行し、Wiki Pathと本文取得を検証した。
|
||||
- CLI main CI run 42、タグCI run 44が成功。公開添付5ファイルを匿名取得し、4生成物のSHA-256を検証した。
|
||||
- 公開ELFでUTF-8/ISO-2022-JP件名、ML連番Path、Dateのローカル年月、Message-ID由来UUID、Message-IDなし原文hashの各保存先を確認した。同梱ELF・ガイドと検証済みソースの一致も確認した。
|
||||
- [CLI v0.4.0](https://git.anya.jp/anya/pages-cli/releases/tag/v0.4.0)と[NeoMuttガイド](https://git.anya.jp/anya/pages-cli/src/tag/v0.4.0/docs/neomutt.md)を公開。
|
||||
|
||||
## リリースと本番反映
|
||||
|
||||
[サーバーCI run 43](https://git.anya.jp/anya/wikipages/actions/runs/43)の全工程成功後、[run 45](https://git.anya.jp/anya/wikipages/actions/runs/45)で同じSHAイメージをv0.9.0へ昇格した。公開タグの付け替え・リリース時の再ビルドは行っていない。本番取得時にイメージIDとソースrevisionの一致を検証した。
|
||||
|
||||
| イメージ | v0.9.0 manifest digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:4a9b0b85330dac915e73e1aa5155f4691e46b2de945c76f1e14ae9735533a99b` |
|
||||
| pageswiki-adaptor-gateway | `sha256:4ff0dc5565537ae9d157df9515ac3b9df67090f1a69d8cc26f2bea5943885017` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:32a643778dff894f0ba679864e401d5605f80ad28bc4bd85bbcde453f2bc4127` |
|
||||
|
||||
2026-11-06 10:05:28 JSTに対象4サービスを停止開始、10:06:31に最終バックアップ照合完了、10:06:37に起動完了。停止から起動まで69秒。app・app2・adaptor gateway・Excalidraw viewerをregistry overlayでv0.9.0に更新し、他のサービスは変更していない。`.env.release`を更新し、ローカルlatestタグも稼働イメージへ揃えた。
|
||||
|
||||
保全先は `.deployment-backups/release-v0.9.0-20261106/`。旧構成と `cutover/data`・`cutover/data2` を保存し、停止後のchecksum付き同期・差分ゼロ・DB/WAL/SHMのバイト一致・稼働元と異なるinodeを確認した。変更のないファイルは前回の不変バックアップとだけlink-destで共有する。旧イメージは `rollback-before-v0.9.0-20261106` で保持し、既存バックアップは削除していない。
|
||||
|
||||
このホストの `/home/anya/.local/bin/pages` は公開ELF v0.4.0へ原子的に置換し、バイト一致とversionを検証した。旧CLIは保全先configの `pages-before-v0.4.0` に保持する。独立CLIの作業用リポジトリも公開コミット・タグへ同期した。資格情報・セッション・個人設定は変更していない。
|
||||
|
||||
対象4コンテナのrevision一致・起動・再起動0回、appとExcalidrawのhealthy、app2内部health、初期ログのエラーパターン0件を確認した。公開HTTPSのhealth・ログインは200、匿名のタスク画面・個人設定画面は303、preferences API・CardDAVは401。配信されたtasks.js・task-productivity.js・tasks.cssはリリースとSHA-256一致。両系統の管理対象12コンポーネントのschema checkは前後ともcurrent。ただしlegacy領域を含めた全データ完全性検査ではない。
|
||||
|
||||
実メール本文・外部取り込みカレンダーは検証に使用していない。本番には合成メールやタスクを追加せず、認証済み操作は一時DBで試験した。保全は内容を解釈しないファイルコピー。完了時の空き容量は約19 GiB。切戻し時もまず書込み停止と現状保全を行い、バックアップを自動復元しない。
|
||||
@@ -0,0 +1,40 @@
|
||||
# 日本語メール件名とWiki Pathの修正
|
||||
|
||||
PagesWiki v0.8.1とpages-cli v0.3.1はメールの表示名とPathの識別子を分離する。v0.8.0は件名全体をURLへ含め、CLIは300 UTF-8 bytesを超える件名を取り込み前に拒否していた。短い日本語Pathそのものは合成HTTP試験で取得可能だが、実メールの失敗入力は取得していないため、報告されたすべての失敗が同じ原因とは断定しない。
|
||||
|
||||
## 動作
|
||||
|
||||
- Wiki Pathの末尾は `mail-request_id`。接続先・本人・Message-IDから生成済みのUUIDを利用し、件名の文字コード・記号・長さに依存しない。Message-IDそのものをURLへ露出しない。Message-IDなしは原文SHA-256から識別する。
|
||||
- MIME Subjectを復号後、先頭の `[list 123]`・`[list:123]`・`[list#123]` を除去する。Re:/Fw:/Fwd:は維持し、その後の連番も除去する。連番を含まない `[重要]` や途中の括弧はそのまま。
|
||||
- 自動件名は300 UTF-8 bytes以内に文字境界で省略し「…」を付ける。元のSubjectはWiki本文へ保持する。明示的な `--title` は連番除去・省略をせず、上限を超えたら拒否する。
|
||||
- 既存ページのPath・タスク名を一括更新しない。既存receiptを使った同一要求の再送は元のページを返す。旧版で保存済みのメールを新しい本文・件名で再作成すると412となるため、通信失敗分は保持済み要求の `task retry` を使う。
|
||||
|
||||
個人設定の既定Wiki親Pathと保存先ACLは従来通り。APIフィールド・receipt hash形式・DBスキーマは変更しない。
|
||||
|
||||
## ソースと確認
|
||||
|
||||
サーバーの対象コミットは `3262f8800547e8ea343fe290153d4abc84ebd0d0`、CLIは `541c2bd069b5507281b0dde2810243447c098e71`。サーバーのCLI結合テスト用コピーも同じソースへ更新した。
|
||||
|
||||
CLI単体42件、全Goテスト、go vetを実施した。合成メールの日本語SubjectからWikiを作成し、関連メモAPIからPathを取得して本文をHTTP取得する結合テストが成功した。既存の日本語PathのHTTP取得・URLエンコードと再送時の非移動も検証した。
|
||||
|
||||
[CLI v0.3.1](https://git.anya.jp/anya/pages-cli/releases/tag/v0.3.1)はmain CI run 38、タグCI run 40で成功。公開添付5ファイルを匿名ダウンロードし、4生成物のSHA-256を照合した。公開ELFでUTF-8/ISO-2022-JPのSubject、ML連番除去、元件名保持、Message-IDによる同一識別子、通常のログイン・メール取り込み・連絡先スモークを確認した。
|
||||
|
||||
## リリースと本番反映
|
||||
|
||||
[サーバーCI run 39](https://git.anya.jp/anya/wikipages/actions/runs/39)の全工程が成功し、[run 41](https://git.anya.jp/anya/wikipages/actions/runs/41)で検証済みSHAイメージをv0.8.1へ昇格した。ソースrevisionとリリースイメージの一致を確認した。公開タグの付け替えは行っていない。
|
||||
|
||||
| イメージ | v0.8.1 manifest digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:44aa267d010568e6dd83354839d976429dc979ed283888009457bffcc2d37119` |
|
||||
| pageswiki-adaptor-gateway | `sha256:5ccf30103cf4f01a49de0d80289736cbca9cde6f0e34661a39652b3468843533` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:33b44cc2c061c3b66ce8e1124b9e25c43584aec508669564c9f4a260e1c53454` |
|
||||
|
||||
2026-11-06 09:15:57 JSTに対象4サービスの停止を開始、09:17:03に最終バックアップ照合完了、09:17:09にv0.8.1起動完了。停止から起動まで72秒。`.env.release` を更新し、registry overlayの対象4サービスだけを `up --no-build --no-deps` した。code-serverやKroki等は変更していない。
|
||||
|
||||
`.deployment-backups/release-v0.8.1-20261106/` に構成と `cutover/data`・`cutover/data2` を保持する。停止後のchecksum付き同期と差分ゼロ、DB・WAL・SHMのバイト一致と稼働元と異なるinodeを確認した。変更のないファイルは前回の不変バックアップとのみlink-destで共有する。旧イメージは `rollback-before-v0.8.1-20261106` を付けて保持した。既存バックアップは削除しない。
|
||||
|
||||
このホストの `/home/anya/.local/bin/pages` を公開ELFのv0.3.1へ原子的に置換し、バイト一致・versionを確認した。旧CLIは保全先configの `pages-before-v0.3.1` に保持する。利用者の資格情報・セッション・個人設定は変更していない。独立CLIリポジトリも対象コミットとタグへ同期した。
|
||||
|
||||
両系統の管理対象12コンポーネントは切替前後ともcurrent。全コンテナのrevision一致、起動正常・再起動0回、appとExcalidrawのhealthy、app2内部health、初期ログのエラーパターン0件を確認した。公開HTTPSのhealth・ログインは200、匿名のタスク・個人設定は303、preferences API・CardDAVは401。配信されたtasks.js・task-productivity.js・tasks.cssはリリースとSHA-256一致。これはlegacy領域を含む全データ完全性検査ではない。
|
||||
|
||||
実メール本文・外部取り込みカレンダーは検証に使用していない。本番には合成メールやタスクを追加せず、認証済み操作は一時DBで確認した。保全は内容を解釈しないファイルコピー。完了時の空き容量は約26 GiB。切戻しは書込みを停止し現状も保全して実施し、バックアップを自動復元しない。
|
||||
@@ -1,6 +1,6 @@
|
||||
# メール本文のWiki保存
|
||||
|
||||
PagesWiki v0.8.0とpages-cli v0.3.0で、NeoMuttからのメール取り込みを関連Wikiページ付きタスク作成へ拡張する。サーバーを先に更新し、その後CLIを更新する。
|
||||
PagesWiki v0.8.0とpages-cli v0.3.0で、NeoMuttからのメール取り込みを関連Wikiページ付きタスク作成へ拡張した。2026-11-06に本番サーバーと、このホストのCLIへの反映を完了した。別の端末ではサーバーv0.8.0以降への接続を確認してからCLIを更新する。
|
||||
|
||||
## 利用方法と互換性
|
||||
|
||||
@@ -19,11 +19,24 @@ CLIの本文非送信は `--metadata-only`。旧 `--include-body` は既定動
|
||||
|
||||
## ソースと検証
|
||||
|
||||
独立CLIの対象コミットは `cde94ed`。サーバー内の `pages-cli/pages` と `test_productivity.py` はこのソースに明示更新した結合テスト用スナップショットで、配布元ではない。
|
||||
独立CLIの対象コミットは `cde94ed936ddfa1911809f3d1a824bd48a815223`、サーバーは `80d297dab40871b42ff2afb2ab6212661c465248`。サーバー内の `pages-cli/pages` と `test_productivity.py` はこのCLIソースに明示更新した結合テスト用スナップショットで、配布元ではない。
|
||||
|
||||
- CLI単体テスト41件、合成HTTP経由のログイン・メール取り込み・連絡先・ログアウト。
|
||||
- GoのメールWiki作成、既定Path・明示Path・プロジェクト配下、再送、権限拒否、衝突、本文上限、トランザクションのロールバック。
|
||||
- 独立CLIスナップショットとGo APIの結合テスト。作成したページがタスクのメモ操作から開けることを確認。
|
||||
- Chromiumのデスクトップ・スマホ幅で、現在のプロジェクト選択・フォームリセット・Wiki Path保存を確認。デスクトップでは候補の先頭ページにないプロジェクトも検証。
|
||||
- 全Goテスト、go vet、JS構文検査、リリースツール8件も成功。オーガナイザーの全ブラウザ回帰15ケース(小型スマホ・英語を含む)も成功。
|
||||
|
||||
配布・本番切替結果は確認後に追記する。外部取り込みカレンダーや実メール本文を検証のために読まない。
|
||||
## 公開結果
|
||||
|
||||
[CLIのmain CI run 34](https://git.anya.jp/anya/pages-cli/actions/runs/34)と[タグCI run 36](https://git.anya.jp/anya/pages-cli/actions/runs/36)が成功し、[pages-cli v0.3.0](https://git.anya.jp/anya/pages-cli/releases/tag/v0.3.0)を公開した。Linux/amd64 ELF、tar.gz、ソース、メタデータ、SHA256SUMSの5添付を匿名取得した。4生成物のチェックサムとsource_revision、同梱ガイド・設定例を照合し、配布ELFで合成HTTPスモークとTLS回帰6件を実施した。macOS/Windowsの配布状態は変更しない。
|
||||
|
||||
[サーバービルド run 35](https://git.anya.jp/anya/wikipages/actions/runs/35)は全工程成功。[リリース run 37](https://git.anya.jp/anya/wikipages/actions/runs/37)でSHAイメージを再ビルドせずv0.8.0へ昇格した。Gitタグは注釈付きで、公開済みタグを付け替えていない。
|
||||
|
||||
| イメージ | v0.8.0 manifest digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:1817474559818898bd75c0bcc3e9ef7d0d02879604b46bd082668be557922482` |
|
||||
| pageswiki-adaptor-gateway | `sha256:264d545d8b8c8f9d1e48f79153f3a91d1d446f9e7cd3b067d8f3f7338d04053f` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:dbfcac6071db55f34ea52b7c00bdeb624ff2d71a9c8cdab5b5e522e8b745d38b` |
|
||||
|
||||
本番反映と切戻し用保全は[本番切替記録](../deployments/2026-11-06-v0.8.0.md)を参照。外部取り込みカレンダーや実メール本文は検証のために読んでいない。
|
||||
@@ -0,0 +1,39 @@
|
||||
# 壁紙連動配色のリリース
|
||||
|
||||
PagesWiki v0.10.0は、トップ画面の壁紙からアクセントとグラス面の配色を生成する機能を追加した。2026-11-07に本番反映済み。対象ソースは `0964fdc5b72a1ec24709d87172aaccb985e41c78`。公開APIの非互換変更とDBスキーマ変更はない。保留中のメール保存先 `/tasks` の調査変更は含めない。
|
||||
|
||||
## 操作と適用範囲
|
||||
|
||||
トップ画面右下の歯車、または `/-/sys/config?panel=home` から、色連動のオフ・アクセントのみ・背景も連動、反映量、明暗判定を選ぶ。既定は背景も連動・35%・現在の明暗を維持。グラス透明度は独立した設定を維持する。管理権限が必要なドメイン共通設定であり、ダイアログでの変更は保存前にプレビューできる。
|
||||
|
||||
通常Viewer・Editor・設定画面・ログイン画面には動的配色を適用しない。警告色などの意味を持つ色は変更しない。画像の追加取得はせず、表示済みの画像を64×64に縮小して描画後に解析する。色の抽出結果だけをDomain UUIDと画像SHA256単位でsessionStorageへ保存する。詳しくは[壁紙連動配色の設計](../../design/navigation-home-sidebar.md#実装済みの壁紙連動配色)を参照。
|
||||
|
||||
## 検証
|
||||
|
||||
- 手元のGo全体テスト、go vet、配色計算とリリースツールのJavaScriptテストが成功。
|
||||
- 一時DBと合成画像を用いたChromiumテストで、デスクトップ・390px幅の保存、キャンセル、テーマ切替、追加取得なし、キャッシュ再利用・破損時再生成、画像エラー時の復元を確認。
|
||||
- 非管理者からの設定変更は403。トップ画面以外に配色用スクリプトが混入しないことを検証。
|
||||
- スマホ幅で検索+ブックマーク画面の横はみ出しを修正。
|
||||
- [CI run 46](https://git.anya.jp/anya/wikipages/actions/runs/46)の初回job 60は既存の `TestAssetReferencesAreDomainScopedAndIncludeHistoricalHeads` の一時SQLite接続初期化で5秒タイムアウト。検査本体に入る前の失敗で、今回その処理の変更はない。手元で該当テストを10回連続成功後、同一コミットのjob 61を再実行し、全体テストが成功(server 170.870秒、store 84.240秒)。テスト省略やタイムアウト変更は行っていない。
|
||||
|
||||
CIでSQLite初期化のタイムアウトが再発する場合は、runnerのI/O負荷とパッケージ間の並列実行を調査する。本番の接続タイムアウトをこの事象だけで緩和しない。
|
||||
|
||||
## リリースと本番反映
|
||||
|
||||
[CI run 46](https://git.anya.jp/anya/wikipages/actions/runs/46)の再実行でテスト・3イメージのビルド・公開・後処理が成功。そのコミットに注釈付きタグ `v0.10.0` を付けてpushし、[release run 47](https://git.anya.jp/anya/wikipages/actions/runs/47)で再ビルドせずに昇格した。本番で取得したイメージのsource revisionとmanifest digestはリリース結果と一致する。
|
||||
|
||||
| イメージ | v0.10.0 manifest digest |
|
||||
| --- | --- |
|
||||
| pageswiki-app | `sha256:d43c5827e92ab8eef28290edd5d405f84d2c3480315d552cf5afe535bcf8a02d` |
|
||||
| pageswiki-adaptor-gateway | `sha256:6882e44ec667fd4fcaecf7a21a25dfb3432a1aa8c6e54c1d0e9fabe3dd448e50` |
|
||||
| pageswiki-excalidraw-viewer | `sha256:638e02520ce06c2d8267dc8514a4d6544ea8bf70f2d24a368193dad5e6aaa38d` |
|
||||
|
||||
23:12:21 JSTに対象4サービスを停止開始、23:13:31に最終バックアップ照合完了、23:13:37に起動完了。停止から起動まで76秒。`.env.release` をv0.10.0へ変更し、registry overlayの `up --no-build --no-deps` でapp・app2・adaptor gateway・Excalidraw viewerを更新した。ローカルlatestタグも同じイメージに揃えた。レジストリlatest、独立CLI、code-server、Kroki等は変更していない。
|
||||
|
||||
保全先は `.deployment-backups/release-v0.10.0-20261107/`。親ディレクトリ0700、構成コピー0600。旧 `.env`・`.env.release`・Composeと停止時点の `cutover/data`・`cutover/data2` を保持する。前回の不変バックアップとのみlink-destで共有し、checksum付き同期後の差分ゼロ、DB・WAL・SHM等のバイト一致と稼働元とのinode相違を確認した。旧v0.9.0イメージは `rollback-before-v0.10.0-20261107` タグで保持。旧バックアップや旧イメージは削除していない。完了時の空き容量は約12GiB。
|
||||
|
||||
切替後、4コンテナのsource revision一致・running・再起動0回、appとExcalidrawのhealthy、app2内部healthを確認した。起動直後のログでpanic・fatal・database locked・job failed等の検索パターンは0件。公開HTTPSのhealth・ログインは200、匿名のタスク画面・ホーム設定画面は303、preferences API・CardDAVは401。配信されたhome-palette.js、home-palette-core.js、home-appearance.js、home.css、config.cssはリリースソースとSHA256一致。両DBの管理対象12コンポーネントのschema checkは前後ともcurrentで、全データ完全性検査ではない。
|
||||
|
||||
認証後の設定操作は一時DBで試験し、本番の設定値やユーザデータを検証目的で変更していない。外部取り込みカレンダーと実メール本文を取得・表示していない。バックアップは内容を解釈しないファイルコピーとバイト照合のみ。
|
||||
|
||||
切戻しでは最初に書込みを停止し、切替後のデータも別途保全する。今回の新設定は旧版では利用されず、DBスキーマの差分はないが、稼働中データへバックアップを自動で上書きしない。旧構成は保全先configにある。
|
||||
@@ -21,8 +21,9 @@ type Manifest struct {
|
||||
|
||||
func Catalog() []Manifest {
|
||||
return []Manifest{
|
||||
{ID: "organizer.feeds", APIVersion: 1, Version: "0.1.0", Kind: "feeds", Scope: "domain", NameKey: "feeds.title", DescriptionKey: "feeds.help", Capabilities: []string{"feeds.own.read", "feeds.own.write"}, Events: []string{"feed.source.sync"}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "background+network+index"},
|
||||
{ID: "organizer.contacts", APIVersion: 1, Version: "0.2.0", Kind: "contacts", Scope: "domain", NameKey: "contacts.title", DescriptionKey: "contacts.help", Capabilities: []string{"contacts.own.read", "contacts.own.write"}, Events: []string{}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "foreground+index"},
|
||||
{ID: "organizer.tasks", APIVersion: 1, Version: "0.12.0", Kind: "tasks", Scope: "domain", NameKey: "tasks.title", DescriptionKey: "tasks.help", Capabilities: []string{"tasks.own.read", "tasks.own.write"}, Events: []string{"organizer.task.changed", "organizer.project.changed", "task.digest.deliver"}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "foreground+background+index"},
|
||||
{ID: "organizer.tasks", APIVersion: 1, Version: "0.14.0", Kind: "tasks", Scope: "domain", NameKey: "tasks.title", DescriptionKey: "tasks.help", Capabilities: []string{"tasks.own.read", "tasks.own.write"}, Events: []string{"organizer.task.changed", "organizer.project.changed", "task.digest.deliver"}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "foreground+background+index"},
|
||||
{ID: "organizer.calendar", APIVersion: 1, Version: "0.2.0", Kind: "calendar", Scope: "domain", NameKey: "calendar.title", DescriptionKey: "calendar.help", Capabilities: []string{"calendar.read", "calendar.write"}, Events: []string{}, SettingsPanel: "extensions", Builtin: true, Enabled: true, ResourceClass: "foreground+index"},
|
||||
{ID: "content.diary", APIVersion: 1, Version: "0.1.0", Kind: "diary", Scope: "domain", NameKey: "periodical.diary", DescriptionKey: "periodical.diary_help", Capabilities: []string{"path.read", "path.write", "domain.extensions.manage"}, Events: []string{"periodical.registered", "periodical.removed"}, SettingsPanel: "diary", Builtin: true, Enabled: true, ResourceClass: "foreground+index"},
|
||||
{ID: "content.blog", APIVersion: 1, Version: "0.1.0", Kind: "blog", Scope: "domain", NameKey: "periodical.blog", DescriptionKey: "periodical.blog_help", Capabilities: []string{"path.read", "path.write", "domain.extensions.manage"}, Events: []string{"periodical.registered", "periodical.removed"}, SettingsPanel: "blog", Builtin: true, Enabled: true, ResourceClass: "foreground+index"},
|
||||
|
||||
@@ -290,6 +290,11 @@ func (s *Server) handleConfig(
|
||||
}
|
||||
|
||||
case "home":
|
||||
palette, paletteErr := s.parseHomePalette(domainUUID, r.Form)
|
||||
if paletteErr != nil {
|
||||
http.Error(w, paletteErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if controlled, e := s.store.DomainEntryControlled(domainUUID); e != nil || controlled {
|
||||
http.Error(w, translate(s.getLocale(domainUUID), "periodical.controlled"), http.StatusConflict)
|
||||
return
|
||||
@@ -344,6 +349,10 @@ func (s *Server) handleConfig(
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err = s.saveHomePalette(domainUUID, palette); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err = s.store.SetConfigInDomain(domainUUID, "home_wallpaper_opacity", strconv.Itoa(wallpaperOpacity)); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -463,6 +472,11 @@ func (s *Server) handleConfig(
|
||||
}
|
||||
|
||||
case "home-appearance":
|
||||
palette, paletteErr := s.parseHomePalette(domainUUID, r.Form)
|
||||
if paletteErr != nil {
|
||||
http.Error(w, paletteErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if controlled, e := s.store.DomainEntryControlled(domainUUID); e != nil || controlled {
|
||||
http.Error(w, translate(s.getLocale(domainUUID), "periodical.controlled"), http.StatusConflict)
|
||||
return
|
||||
@@ -472,6 +486,10 @@ func (s *Server) handleConfig(
|
||||
http.Error(w, parseErr.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err = s.saveHomePalette(domainUUID, palette); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err = s.store.SetConfigInDomain(domainUUID, "home_glass_transparency", strconv.Itoa(glassTransparency)); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -1064,6 +1082,7 @@ func (s *Server) handleConfig(
|
||||
"HomeWallpaperPath": homeWallpaperPath,
|
||||
"HomeWallpaperOpacity": homeWallpaperOpacity,
|
||||
"HomeGlassTransparency": s.homeGlassTransparency(domainUUID),
|
||||
"HomePalette": s.homePalette(domainUUID),
|
||||
"HomeLayout": s.homeLayout(s.domainUUIDForRequest(r)),
|
||||
"HomeBookmarks": s.homeBookmarksText(s.domainUUIDForRequest(r)),
|
||||
"VirtualFolderPages": s.getVirtualFolderPages(s.domainUUIDForRequest(r)),
|
||||
|
||||
@@ -16,6 +16,7 @@ func (s *Server) registeredEventHandlers() *dregarnuhr.Registry {
|
||||
s.eventHandlersOnce.Do(func() {
|
||||
registry := &dregarnuhr.Registry{}
|
||||
handlers := map[string]dregarnuhr.Handler{
|
||||
store.FeedSyncEventType: s.syncFeedSources,
|
||||
store.TaskDigestEventType: s.deliverTaskDigests,
|
||||
store.NotificationPushEventType: func(ctx context.Context, job *store.EventJob) error {
|
||||
return s.deliverNotificationPushContext(ctx, job)
|
||||
|
||||
@@ -58,6 +58,9 @@ func (s *Server) startEventScheduler() {
|
||||
if s.store == nil {
|
||||
return
|
||||
}
|
||||
if err := s.store.EnsureFeedEvent(); err != nil {
|
||||
log.Printf("feed scheduler initialization failed")
|
||||
}
|
||||
if err := s.store.EnsureBuiltinResourceEvent(); err != nil {
|
||||
log.Printf("resource monitor initialization failed: %v", err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
const feedsAPI = "/_/api/v1/extension/organizer.feeds/"
|
||||
|
||||
func feedRoute(p string) bool { return p == "/v/feeds" || strings.HasPrefix(p, feedsAPI) }
|
||||
func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
if !s.systemExtensionEnabled(domain, "organizer.feeds") {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
actor, active := s.calendarActor(r)
|
||||
if actor == "" {
|
||||
s.authRequired(w, r)
|
||||
return
|
||||
}
|
||||
if r.Method != "GET" && r.Method != "HEAD" && !active {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/v/feeds" {
|
||||
if r.Method != "GET" && r.Method != "HEAD" {
|
||||
w.WriteHeader(405)
|
||||
return
|
||||
}
|
||||
if _, e := s.store.FeedSources(r.Context(), domain, actor); e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
s.renderWithContext(w, r, "feeds.gohtml", map[string]any{"Title": "RSS", "FeedWritable": active})
|
||||
return
|
||||
}
|
||||
key := strings.TrimPrefix(r.URL.Path, feedsAPI)
|
||||
if strings.HasPrefix(key, "opml/") {
|
||||
s.handleFeedOPML(w, r, domain, actor, key)
|
||||
return
|
||||
}
|
||||
switch {
|
||||
case key == "catalog" && r.Method == "GET":
|
||||
catalog, e := s.store.FeedCatalog(r.Context(), domain, actor, r.URL.Query().Get("source"))
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"subscriptions": catalog})
|
||||
return
|
||||
case key == "note" && r.Method == "POST":
|
||||
var input struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Source string `json:"source"`
|
||||
ID string `json:"id"`
|
||||
Path string `json:"path"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Confirm bool `json:"confirm_publication"`
|
||||
}
|
||||
if !taskJSONLimit(w, r, &input, 128<<10) {
|
||||
return
|
||||
}
|
||||
if !input.Confirm {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
for _, capability := range []string{"read", "create", "write"} {
|
||||
if s.authorizePathRequest(r, capability, input.Path) != nil {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
}
|
||||
page, e := s.store.CaptureFeedNote(r.Context(), domain, actor, input.RequestID, input.Source, input.ID, input.Path, input.Title, input.Body)
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 201, map[string]string{"page_uuid": page})
|
||||
return
|
||||
case key == "sources" && r.Method == "GET":
|
||||
sources, e := s.store.FeedSources(r.Context(), domain, actor)
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"sources": sources})
|
||||
return
|
||||
case key == "sources" && r.Method == "POST":
|
||||
var input struct {
|
||||
store.FeedSource
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
if !taskJSON(w, r, &input) {
|
||||
return
|
||||
}
|
||||
if !validCalendarSourceURL(input.URL) || len(input.Username) > 256 || len(input.Password) > 4096 {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
if input.Provider == "freshrss" {
|
||||
u, _ := url.Parse(input.URL)
|
||||
if u.RawQuery != "" || !strings.HasSuffix(strings.TrimRight(u.Path, "/"), "/greader.php") {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
}
|
||||
if input.UUID == "" {
|
||||
input.UUID = uuid.NewString()
|
||||
}
|
||||
if input.Version == 0 && input.Provider == "freshrss" {
|
||||
if input.Username == "" || input.Password == "" {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
cipher, e := s.store.SealFeedCredential(domain, actor, input.UUID, input.Username, input.Password)
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
input.Credential = cipher
|
||||
} else if input.Username != "" || input.Password != "" {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
v, e := s.store.SaveFeedSource(r.Context(), domain, actor, input.FeedSource)
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"source": v})
|
||||
return
|
||||
case strings.HasPrefix(key, "sources/") && r.Method == "POST":
|
||||
parts := strings.Split(key, "/")
|
||||
if len(parts) != 3 {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
var input struct {
|
||||
Version int64 `json:"version"`
|
||||
}
|
||||
if !taskJSON(w, r, &input) {
|
||||
return
|
||||
}
|
||||
if e := s.store.FeedSourceAction(r.Context(), domain, actor, parts[1], parts[2], input.Version); e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]bool{"ok": true})
|
||||
return
|
||||
case key == "items" && r.Method == "GET":
|
||||
q := r.URL.Query()
|
||||
before := int64(-1)
|
||||
if q.Has("before") {
|
||||
var e error
|
||||
before, e = strconv.ParseInt(q.Get("before"), 10, 64)
|
||||
if e != nil || before < 0 {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
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"))
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
more := len(items) > 100
|
||||
if more {
|
||||
items = items[:100]
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"items": items, "more": more})
|
||||
return
|
||||
case key == "item" && r.Method == "GET":
|
||||
v, e := s.store.FeedItem(r.Context(), domain, actor, r.URL.Query().Get("source"), r.URL.Query().Get("id"))
|
||||
if e != nil {
|
||||
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":
|
||||
var input struct {
|
||||
Source string `json:"source"`
|
||||
ID string `json:"id"`
|
||||
Read bool `json:"read"`
|
||||
Starred bool `json:"starred"`
|
||||
Version int64 `json:"version"`
|
||||
}
|
||||
if !taskJSON(w, r, &input) {
|
||||
return
|
||||
}
|
||||
if e := s.store.SetFeedState(r.Context(), domain, actor, input.Source, input.ID, input.Read, input.Starred, input.Version); e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"version": input.Version + 1})
|
||||
return
|
||||
}
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
func init() {
|
||||
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読取連携"
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
const testFeedCatalog = `{"subscriptions":[{"id":"feed/1","title":"Same title","categories":[{"id":"user/alice/label/Tech","label":"技術"}]},{"id":"feed/2","title":"Same title","categories":[{"id":"user/alice/label/Other","label":"技術"}]},{"id":"feed/3","title":"Empty feed","categories":[]}]}`
|
||||
|
||||
func TestFreshRSSCatalogValidation(t *testing.T) {
|
||||
catalog, e := parseFreshRSSCatalog([]byte(testFeedCatalog))
|
||||
if e != nil || len(catalog) != 3 || catalog[0].Categories[0].ID == catalog[1].Categories[0].ID {
|
||||
t.Fatal(catalog, e)
|
||||
}
|
||||
for _, raw := range []string{`{}`, `{"subscriptions":null}`, `{"subscriptions":[{"id":""}]}`, `{"subscriptions":[{"id":"feed/1"},{"id":"feed/1"}]}`, `{"subscriptions":[{"id":"feed/1","categories":[{"id":"cat","label":"A"},{"id":"cat","label":"A"}]}]}`, `{"subscriptions":[{"id":"feed/1","categories":[{"id":"cat","label":"A"}]},{"id":"feed/2","categories":[{"id":"cat","label":"B"}]}]}`} {
|
||||
if _, e := parseFreshRSSCatalog([]byte(raw)); e == nil {
|
||||
t.Fatal("accepted", raw)
|
||||
}
|
||||
}
|
||||
if c, e := parseFreshRSSCatalog([]byte(`{"subscriptions":[]}`)); e != nil || len(c) != 0 {
|
||||
t.Fatal(c, e)
|
||||
}
|
||||
big := make([]store.FeedRemoteSubscription, 1001)
|
||||
raw, _ := json.Marshal(map[string]any{"subscriptions": big})
|
||||
if _, e := parseFreshRSSCatalog(raw); e == nil {
|
||||
t.Fatal("unbounded catalog")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedCatalogBackgroundSnapshotIsolation(t *testing.T) {
|
||||
s, token, domain, actor, local := feedFixture(t)
|
||||
ctx := context.Background()
|
||||
if e := s.store.FeedSourceAction(ctx, domain, actor, local.UUID, "delete", local.Version); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
v := store.FeedSource{UUID: uuid.NewString(), Provider: "freshrss", Title: "FreshRSS", URL: "https://example.org/api/greader.php", Enabled: true, Interval: 300}
|
||||
v.Credential, _ = s.store.SealFeedCredential(domain, actor, v.UUID, "reader", "secret")
|
||||
if _, e := s.store.SaveFeedSource(ctx, domain, actor, v); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
calls := 0
|
||||
failCatalog := false
|
||||
client := &http.Client{Transport: feedTransportFunc(func(r *http.Request) (*http.Response, error) {
|
||||
calls++
|
||||
body := ""
|
||||
switch {
|
||||
case strings.HasSuffix(r.URL.Path, "/accounts/ClientLogin"):
|
||||
if r.Method != "POST" {
|
||||
t.Error("login method")
|
||||
}
|
||||
body = "Auth=synthetic"
|
||||
case strings.HasSuffix(r.URL.Path, "/stream/contents/reading-list"):
|
||||
if r.Method != "GET" || r.URL.Query().Get("n") != "200" {
|
||||
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 {
|
||||
body = `{"items":[]}`
|
||||
}
|
||||
case strings.HasSuffix(r.URL.Path, "/subscription/list"):
|
||||
if r.Method != "GET" || r.Header.Get("Authorization") != "GoogleLogin auth=synthetic" {
|
||||
t.Error("catalog request")
|
||||
}
|
||||
if failCatalog {
|
||||
return nil, errors.New("synthetic timeout")
|
||||
}
|
||||
body = testFeedCatalog
|
||||
default:
|
||||
t.Fatalf("unexpected external request %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
return &http.Response{StatusCode: 200, Header: http.Header{}, Body: io.NopCloser(strings.NewReader(body))}, nil
|
||||
})}
|
||||
run := func() {
|
||||
t.Helper()
|
||||
if _, e := s.store.DB.Exec(`UPDATE feed_sources SET next_ms=0 WHERE uuid=?`, v.UUID); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e := s.syncFeedSourcesWithClient(ctx, &store.EventJob{}, client); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
run()
|
||||
if calls != 3 {
|
||||
t.Fatal("fetch count", calls)
|
||||
}
|
||||
w := feedRequestTest(s, token, "GET", "catalog?source="+v.UUID, nil)
|
||||
if w.Code != 200 || !strings.Contains(w.Body.String(), "Empty feed") || strings.Contains(w.Body.String(), "secret") {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
for _, scope := range []string{"feed=feed%2F1", "category=" + url.QueryEscape("user/alice/label/Tech")} {
|
||||
w = feedRequestTest(s, token, "GET", "items?source="+v.UUID+"&"+scope, nil)
|
||||
var data struct {
|
||||
Items []store.FeedItem `json:"items"`
|
||||
}
|
||||
json.Unmarshal(w.Body.Bytes(), &data)
|
||||
if w.Code != 200 || len(data.Items) != 1 || data.Items[0].ID != "a" {
|
||||
t.Fatal(scope, w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
w = feedRequestTest(s, token, "GET", "items?feed=feed%2F1", nil)
|
||||
if w.Code != 422 {
|
||||
t.Fatal("unscoped remote ID", w.Code, w.Body)
|
||||
}
|
||||
other, e := s.store.CreatePasswordAccount(domain, "catalogother", "long test password", "Other", "")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
otherToken, e := s.store.CreateAuthSession(domain, other.UUID)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if w = feedRequestTest(s, otherToken, "GET", "catalog?source="+v.UUID, nil); w.Code == 200 {
|
||||
t.Fatal("cross-owner catalog leak")
|
||||
}
|
||||
if w = feedRequestTest(s, "", "GET", "catalog?source="+v.UUID, nil); w.Code == 200 {
|
||||
t.Fatal("anonymous catalog leak")
|
||||
}
|
||||
if _, e := s.store.FeedCatalog(ctx, uuid.NewString(), actor, v.UUID); e == nil {
|
||||
t.Fatal("cross-domain catalog leak")
|
||||
}
|
||||
if calls != 3 {
|
||||
t.Fatal("foreground external request")
|
||||
}
|
||||
failCatalog = true
|
||||
run()
|
||||
catalog, e := s.store.FeedCatalog(ctx, domain, actor, v.UUID)
|
||||
if e != nil || len(catalog) != 3 {
|
||||
t.Fatal("lost catalog", catalog, e)
|
||||
}
|
||||
items, e := s.store.FeedItems(ctx, domain, actor, v.UUID, "", "", -1, "")
|
||||
if e != nil || len(items) != 2 {
|
||||
t.Fatal("lost articles", items, e)
|
||||
}
|
||||
if e := s.setSystemExtensionEnabled(domain, "organizer.feeds", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e := s.store.FeedCatalog(ctx, domain, actor, v.UUID); !errors.Is(e, store.ErrAccessDenied) {
|
||||
t.Fatal("disabled read", e)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,536 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"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 {
|
||||
// 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")
|
||||
}
|
||||
text := strings.TrimSpace(html.UnescapeString(feedTextPolicy.Sanitize(raw)))
|
||||
if len(text) > limit {
|
||||
text = text[:limit-16]
|
||||
for !utf8.ValidString(text) {
|
||||
text = text[:len(text)-1]
|
||||
}
|
||||
text += "\n[… truncated]"
|
||||
}
|
||||
return text
|
||||
}
|
||||
func feedLink(base, raw string) string {
|
||||
if strings.TrimSpace(raw) == "" || len(raw) > 4096 {
|
||||
return ""
|
||||
}
|
||||
u, e := url.Parse(strings.TrimSpace(raw))
|
||||
if e != nil {
|
||||
return ""
|
||||
}
|
||||
b, e := url.Parse(base)
|
||||
if e != nil {
|
||||
return ""
|
||||
}
|
||||
u = b.ResolveReference(u)
|
||||
if (u.Scheme != "https" && u.Scheme != "http") || u.Hostname() == "" || u.User != nil {
|
||||
return ""
|
||||
}
|
||||
result := u.String()
|
||||
if len(result) > 4096 {
|
||||
return ""
|
||||
}
|
||||
return result
|
||||
}
|
||||
func feedDate(v string) int64 {
|
||||
for _, layout := range []string{time.RFC3339Nano, time.RFC1123Z, time.RFC1123, time.RFC822Z, time.RFC822, "2006-01-02T15:04:05-0700"} {
|
||||
if t, e := time.Parse(layout, v); e == nil && t.UnixMilli() > 0 && t.Before(time.Now().AddDate(1, 0, 0)) {
|
||||
return t.UnixMilli()
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type rssEntry struct {
|
||||
ID string `xml:"guid"`
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
Content string `xml:"encoded"`
|
||||
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"`
|
||||
Links []struct {
|
||||
Href string `xml:"href,attr"`
|
||||
Rel string `xml:"rel,attr"`
|
||||
} `xml:"link"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func parseFeed(raw []byte, base string) ([]store.FeedItem, error) {
|
||||
if len(raw) > 4<<20 {
|
||||
return nil, errors.New("limit")
|
||||
}
|
||||
d := xml.NewDecoder(bytes.NewReader(raw))
|
||||
d.CharsetReader = charset.NewReaderLabel
|
||||
root := ""
|
||||
title := ""
|
||||
depth := 0
|
||||
out := []store.FeedItem{}
|
||||
seen := map[string]bool{}
|
||||
for {
|
||||
tok, e := d.Token()
|
||||
if e == io.EOF {
|
||||
break
|
||||
}
|
||||
if e != nil {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
switch t := tok.(type) {
|
||||
case xml.Directive:
|
||||
return nil, errFeedInvalid // DTD/entities have no role in a feed.
|
||||
case xml.StartElement:
|
||||
depth++
|
||||
if depth == 1 && root != "" {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
if depth > 64 {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
if root == "" {
|
||||
root = t.Name.Local
|
||||
if root != "rss" && root != "feed" {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
}
|
||||
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 {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
depth--
|
||||
body := v.Content
|
||||
if body == "" {
|
||||
body = v.Description
|
||||
}
|
||||
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, isHTML := v.Content.body()
|
||||
if body == "" {
|
||||
body, isHTML = v.Summary.body()
|
||||
}
|
||||
htmlBody = isHTML
|
||||
link := ""
|
||||
for _, l := range v.Links {
|
||||
if l.Rel == "" || l.Rel == "alternate" {
|
||||
link = feedLink(base, l.Href)
|
||||
break
|
||||
}
|
||||
}
|
||||
date := v.Published
|
||||
if date == "" {
|
||||
date = v.Updated
|
||||
}
|
||||
item = store.FeedItem{ID: v.ID, Title: v.Title, URL: link, Body: body, PublishedMS: feedDate(date), Folder: v.Category.Term}
|
||||
isItem = true
|
||||
} else if t.Name.Local == "title" && ((root == "rss" && depth == 3) || (root == "feed" && depth == 2)) {
|
||||
if d.DecodeElement(&title, &t) != nil {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
depth--
|
||||
}
|
||||
if isItem {
|
||||
if len(out) >= 500 {
|
||||
return nil, errors.New("limit")
|
||||
}
|
||||
item.Title = feedText(item.Title, 2048)
|
||||
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 == "" {
|
||||
key := item.URL
|
||||
if key == "" {
|
||||
key = item.Title + "\x00" + strconv.FormatInt(item.PublishedMS, 10) + "\x00" + item.Body
|
||||
}
|
||||
h := sha256.Sum256([]byte(key))
|
||||
item.ID = "sha256:" + hex.EncodeToString(h[:])
|
||||
}
|
||||
if len(item.ID) > 1024 || seen[item.ID] {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
seen[item.ID] = true
|
||||
out = append(out, item)
|
||||
}
|
||||
case xml.EndElement:
|
||||
depth--
|
||||
}
|
||||
}
|
||||
if root == "" || depth != 0 {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func feedRequest(ctx context.Context, client *http.Client, method, target, auth string, form url.Values, headers map[string]string) ([]byte, http.Header, int, error) {
|
||||
var body io.Reader
|
||||
if form != nil {
|
||||
body = strings.NewReader(form.Encode())
|
||||
}
|
||||
r, e := http.NewRequestWithContext(ctx, method, target, body)
|
||||
if e != nil {
|
||||
return nil, nil, 0, errFeedInvalid
|
||||
}
|
||||
if auth != "" {
|
||||
r.Header.Set("Authorization", "GoogleLogin auth="+auth)
|
||||
}
|
||||
if form != nil {
|
||||
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
r.Header.Set("User-Agent", "PagesWiki-Feeds/0.1")
|
||||
for k, v := range headers {
|
||||
r.Header.Set(k, v)
|
||||
}
|
||||
res, e := client.Do(r)
|
||||
if e != nil {
|
||||
return nil, nil, 0, errors.New("network")
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode == 401 || res.StatusCode == 403 {
|
||||
return nil, nil, res.StatusCode, errors.New("credentials")
|
||||
}
|
||||
if res.StatusCode == 304 {
|
||||
return nil, res.Header, 304, nil
|
||||
}
|
||||
if res.StatusCode != 200 {
|
||||
return nil, nil, res.StatusCode, errors.New("remote_error")
|
||||
}
|
||||
raw, e := io.ReadAll(io.LimitReader(res.Body, (4<<20)+1))
|
||||
if e != nil {
|
||||
return nil, nil, 0, errors.New("network")
|
||||
}
|
||||
if len(raw) > 4<<20 {
|
||||
return nil, nil, 0, errors.New("limit")
|
||||
}
|
||||
return raw, res.Header, res.StatusCode, nil
|
||||
}
|
||||
func fetchFreshRSS(ctx context.Context, client *http.Client, v store.FeedSource, user, password string, catalogs ...*[]store.FeedRemoteSubscription) ([]store.FeedItem, error) {
|
||||
base := strings.TrimRight(v.URL, "/")
|
||||
raw, _, _, e := feedRequest(ctx, client, "POST", base+"/accounts/ClientLogin", "", url.Values{"Email": {user}, "Passwd": {password}}, nil)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
auth := ""
|
||||
for _, line := range strings.Split(string(raw), "\n") {
|
||||
if strings.HasPrefix(line, "Auth=") {
|
||||
auth = strings.TrimSpace(strings.TrimPrefix(line, "Auth="))
|
||||
}
|
||||
}
|
||||
if auth == "" || len(auth) > 4096 || strings.ContainsAny(auth, "\r\n") {
|
||||
return nil, errors.New("credentials")
|
||||
}
|
||||
raw, _, _, e = feedRequest(ctx, client, "GET", base+"/reader/api/0/stream/contents/reading-list?output=json&n=200", auth, nil, nil)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
var response struct {
|
||||
Items []struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Published int64 `json:"published"`
|
||||
Categories []string `json:"categories"`
|
||||
Origin struct {
|
||||
Title string `json:"title"`
|
||||
StreamID string `json:"streamId"`
|
||||
} `json:"origin"`
|
||||
Alternate []struct {
|
||||
Href string `json:"href"`
|
||||
} `json:"alternate"`
|
||||
Summary struct {
|
||||
Content string `json:"content"`
|
||||
} `json:"summary"`
|
||||
Content struct {
|
||||
Content string `json:"content"`
|
||||
} `json:"content"`
|
||||
} `json:"items"`
|
||||
}
|
||||
if json.Unmarshal(raw, &response) != nil || response.Items == nil || len(response.Items) > 200 {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
out := []store.FeedItem{}
|
||||
seen := map[string]bool{}
|
||||
for _, i := range response.Items {
|
||||
if i.ID == "" || len(i.ID) > 1024 || seen[i.ID] {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
seen[i.ID] = true
|
||||
if (i.Origin.StreamID != "" && !store.ValidFeedRemoteID(i.Origin.StreamID)) || len(i.Categories) > 64 {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
item := store.FeedItem{ID: i.ID, Title: feedText(i.Title, 2048), Feed: feedText(i.Origin.Title, 512), RemoteFeed: i.Origin.StreamID, RemoteCategories: []string{}}
|
||||
if i.Published > 0 && i.Published < time.Now().AddDate(1, 0, 0).Unix() {
|
||||
item.PublishedMS = i.Published * 1000
|
||||
}
|
||||
body := i.Summary.Content
|
||||
if body == "" {
|
||||
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)
|
||||
}
|
||||
for _, c := range i.Categories {
|
||||
if !store.ValidFeedRemoteID(c) {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
if strings.HasSuffix(c, "/state/com.google/read") {
|
||||
item.Read = true
|
||||
}
|
||||
if strings.HasSuffix(c, "/state/com.google/starred") {
|
||||
item.Starred = true
|
||||
}
|
||||
if pos := strings.Index(c, "/label/"); pos >= 0 {
|
||||
item.Folder = feedText(c[pos+7:], 512)
|
||||
item.RemoteCategories = append(item.RemoteCategories, c)
|
||||
}
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
if len(catalogs) > 0 {
|
||||
raw, _, _, e = feedRequest(ctx, client, "GET", base+"/reader/api/0/subscription/list?output=json", auth, nil, nil)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
catalog, e := parseFreshRSSCatalog(raw)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
*catalogs[0] = catalog
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func parseFreshRSSCatalog(raw []byte) ([]store.FeedRemoteSubscription, error) {
|
||||
if len(raw) > 4<<20 || !utf8.Valid(raw) {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
var response struct {
|
||||
Subscriptions []store.FeedRemoteSubscription `json:"subscriptions"`
|
||||
}
|
||||
if json.Unmarshal(raw, &response) != nil || response.Subscriptions == nil {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
if len(response.Subscriptions) > 1000 {
|
||||
return nil, errors.New("limit")
|
||||
}
|
||||
for i := range response.Subscriptions {
|
||||
sub := &response.Subscriptions[i]
|
||||
sub.Title = feedText(sub.Title, 512)
|
||||
if sub.Categories == nil {
|
||||
sub.Categories = []store.FeedCategory{}
|
||||
}
|
||||
for j := range sub.Categories {
|
||||
sub.Categories[j].Label = feedText(sub.Categories[j].Label, 512)
|
||||
}
|
||||
}
|
||||
if _, e := store.FeedCatalogJSON(response.Subscriptions); e != nil {
|
||||
return nil, errFeedInvalid
|
||||
}
|
||||
return response.Subscriptions, nil
|
||||
}
|
||||
func (s *Server) syncFeedSources(ctx context.Context, job *store.EventJob) error {
|
||||
client := calendarSourceClient()
|
||||
client.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }
|
||||
defer client.CloseIdleConnections()
|
||||
return s.syncFeedSourcesWithClient(ctx, job, client)
|
||||
}
|
||||
|
||||
// Tests inject a synthetic transport; production always uses the DNS-pinned,
|
||||
// public HTTPS-only transport above, never a user-configurable HTTP client.
|
||||
func (s *Server) syncFeedSourcesWithClient(ctx context.Context, job *store.EventJob, client *http.Client) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, 35*time.Second)
|
||||
defer cancel()
|
||||
sources, e := s.store.DueFeedSources(ctx)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
done, failed := 0, 0
|
||||
for _, v := range sources {
|
||||
if ctx.Err() != nil {
|
||||
break
|
||||
}
|
||||
if !s.systemExtensionEnabled(v.Domain, "organizer.feeds") {
|
||||
continue
|
||||
}
|
||||
v, e = s.store.ClaimFeed(ctx, v)
|
||||
if e != nil {
|
||||
continue
|
||||
}
|
||||
child, stop := context.WithTimeout(ctx, 8*time.Second)
|
||||
var items []store.FeedItem
|
||||
var catalog []store.FeedRemoteSubscription
|
||||
etag, modified := v.ETag, v.Modified
|
||||
unchanged := false
|
||||
if !validCalendarSourceURL(v.URL) {
|
||||
e = errFeedInvalid
|
||||
} else if v.Provider == "freshrss" {
|
||||
var user, password string
|
||||
user, password, e = s.store.OpenFeedCredential(v)
|
||||
if e == nil {
|
||||
items, e = fetchFreshRSS(child, client, v, user, password, &catalog)
|
||||
} else {
|
||||
e = errors.New("credentials")
|
||||
}
|
||||
} else {
|
||||
var raw []byte
|
||||
var h http.Header
|
||||
var status int
|
||||
raw, h, status, e = feedRequest(child, client, "GET", v.URL, "", nil, map[string]string{"If-None-Match": v.ETag, "If-Modified-Since": v.Modified})
|
||||
if e == nil {
|
||||
unchanged = status == 304
|
||||
if !unchanged {
|
||||
items, e = parseFeed(raw, v.URL)
|
||||
etag, modified = h.Get("ETag"), h.Get("Last-Modified")
|
||||
}
|
||||
}
|
||||
}
|
||||
stop()
|
||||
if e == nil && (len(etag) > 1024 || len(modified) > 1024) {
|
||||
e = errors.New("limit")
|
||||
etag, modified = v.ETag, v.Modified
|
||||
items = nil
|
||||
}
|
||||
code := ""
|
||||
if e != nil {
|
||||
code = e.Error()
|
||||
switch code {
|
||||
case "network", "invalid_feed", "credentials", "remote_error", "limit":
|
||||
default:
|
||||
code = "invalid_feed"
|
||||
}
|
||||
failed++
|
||||
} else {
|
||||
done++
|
||||
}
|
||||
if e = s.store.CompleteFeed(ctx, v, items, etag, modified, code, unchanged, catalog); e != nil && !errors.Is(e, store.ErrAccessDenied) && !errors.Is(e, store.ErrTaskConflict) {
|
||||
return e
|
||||
}
|
||||
}
|
||||
s.addEventProgressLog(ctx, job, fmt.Sprintf("feed sources updated=%d failed=%d", done, failed))
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
const feedOPMLMaxBytes = 512 << 10
|
||||
|
||||
type feedOPMLRow struct {
|
||||
store.FeedSubscription
|
||||
Index int `json:"index"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// Parse only the uploaded document. OPML includes and HTML links are never
|
||||
// fetched. Every token participates in the depth/outline/DTD checks.
|
||||
func parseFeedOPML(raw string) ([]feedOPMLRow, error) {
|
||||
if len(raw) > feedOPMLMaxBytes {
|
||||
return nil, store.ErrTaskDAVLimit
|
||||
}
|
||||
d := xml.NewDecoder(strings.NewReader(strings.TrimPrefix(raw, "\ufeff")))
|
||||
// JSON and the browser's File.text() carry UTF-8, not the original legacy
|
||||
// bytes. Reject other XML encodings instead of silently corrupting names.
|
||||
type frame struct {
|
||||
name xml.Name
|
||||
folder string
|
||||
commented bool
|
||||
}
|
||||
stack := []frame{}
|
||||
rows := []feedOPMLRow{}
|
||||
root, head, body, outlines := 0, 0, 0, 0
|
||||
for {
|
||||
token, err := d.Token()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
switch t := token.(type) {
|
||||
case xml.Directive:
|
||||
return nil, store.ErrTaskInvalid
|
||||
case xml.CharData:
|
||||
if len(stack) == 0 && strings.TrimSpace(string(t)) != "" {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
case xml.StartElement:
|
||||
if len(stack) >= 16 {
|
||||
return nil, store.ErrTaskDAVLimit
|
||||
}
|
||||
attrs := map[string]string{}
|
||||
seen := map[xml.Name]bool{}
|
||||
for _, a := range t.Attr {
|
||||
if seen[a.Name] {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
seen[a.Name] = true
|
||||
if a.Name.Space == "" {
|
||||
attrs[a.Name.Local] = a.Value
|
||||
}
|
||||
}
|
||||
f := frame{name: t.Name}
|
||||
if len(stack) == 0 {
|
||||
root++
|
||||
if root != 1 || t.Name.Space != "" || t.Name.Local != "opml" || (attrs["version"] != "1.0" && attrs["version"] != "1.1" && attrs["version"] != "2.0") {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
} else {
|
||||
parent := stack[len(stack)-1]
|
||||
f.folder = parent.folder
|
||||
f.commented = parent.commented
|
||||
if len(stack) == 1 && t.Name.Space == "" {
|
||||
switch t.Name.Local {
|
||||
case "head":
|
||||
head++
|
||||
if head != 1 || body != 0 {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
case "body":
|
||||
body++
|
||||
if head != 1 || body != 1 {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
default:
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
}
|
||||
inBody := len(stack) >= 2 && stack[1].name == (xml.Name{Local: "body"})
|
||||
if inBody && t.Name.Space == "" && parent.name.Space == "" && (parent.name.Local == "body" || parent.name.Local == "outline") && t.Name.Local != "outline" {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
if inBody && t.Name.Space == "" && t.Name.Local == "outline" && parent.name.Space == "" && (parent.name.Local == "body" || parent.name.Local == "outline") {
|
||||
outlines++
|
||||
if outlines > 1000 {
|
||||
return nil, store.ErrTaskDAVLimit
|
||||
}
|
||||
f.commented = f.commented || strings.EqualFold(attrs["isComment"], "true")
|
||||
label := attrs["text"]
|
||||
if label == "" {
|
||||
label = attrs["title"]
|
||||
}
|
||||
label = feedText(label, 1024)
|
||||
kind := strings.ToLower(attrs["type"])
|
||||
if attrs["xmlUrl"] != "" || kind != "" {
|
||||
if len(rows) >= 500 {
|
||||
return nil, store.ErrTaskDAVLimit
|
||||
}
|
||||
row := feedOPMLRow{FeedSubscription: store.FeedSubscription{Title: label, Folder: f.folder, URL: strings.TrimSpace(attrs["xmlUrl"])}, Index: len(rows), Status: "add"}
|
||||
switch {
|
||||
case f.commented:
|
||||
row.Status = "commented"
|
||||
case kind != "" && kind != "rss" && kind != "atom":
|
||||
row.Status = "unsupported_type"
|
||||
case !validCalendarSourceURL(row.URL):
|
||||
row.Status = "unsupported_url"
|
||||
case label == "" || len(label) > 200 || len(f.folder) > 200:
|
||||
row.Status = "invalid_fields"
|
||||
}
|
||||
rows = append(rows, row)
|
||||
} else if label != "" {
|
||||
if f.folder != "" {
|
||||
f.folder += " / "
|
||||
}
|
||||
f.folder += label
|
||||
}
|
||||
}
|
||||
}
|
||||
stack = append(stack, f)
|
||||
case xml.EndElement:
|
||||
if len(stack) == 0 {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
stack = stack[:len(stack)-1]
|
||||
}
|
||||
}
|
||||
if root != 1 || head != 1 || body != 1 || len(stack) != 0 {
|
||||
return nil, store.ErrTaskInvalid
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func classifyFeedOPML(rows []feedOPMLRow, sources []store.FeedSource) {
|
||||
existing := map[string]bool{}
|
||||
seen := map[string]bool{}
|
||||
for _, s := range sources {
|
||||
if s.Provider == "local" {
|
||||
existing[store.FeedURLKey(s.URL)] = true
|
||||
}
|
||||
}
|
||||
for i := range rows {
|
||||
row := &rows[i]
|
||||
if row.Status != "add" {
|
||||
continue
|
||||
}
|
||||
key := store.FeedURLKey(row.URL)
|
||||
if existing[key] {
|
||||
row.Status = "existing"
|
||||
} else if seen[key] {
|
||||
row.Status = "duplicate"
|
||||
}
|
||||
seen[key] = true
|
||||
}
|
||||
}
|
||||
|
||||
type feedOPMLOutline struct {
|
||||
Text string `xml:"text,attr"`
|
||||
Title string `xml:"title,attr,omitempty"`
|
||||
Type string `xml:"type,attr,omitempty"`
|
||||
URL string `xml:"xmlUrl,attr,omitempty"`
|
||||
Children []feedOPMLOutline `xml:"outline"`
|
||||
}
|
||||
|
||||
func encodeFeedOPML(sources []store.FeedSource) ([]byte, error) {
|
||||
var doc struct {
|
||||
XMLName xml.Name `xml:"opml"`
|
||||
Version string `xml:"version,attr"`
|
||||
Title string `xml:"head>title"`
|
||||
Outlines []feedOPMLOutline `xml:"body>outline"`
|
||||
}
|
||||
doc.Version = "2.0"
|
||||
doc.Title = "PagesWiki RSS"
|
||||
groups := map[string]int{}
|
||||
for _, source := range sources {
|
||||
if source.Provider != "local" {
|
||||
continue
|
||||
}
|
||||
entry := feedOPMLOutline{Text: source.Title, Title: source.Title, Type: "rss", URL: source.URL}
|
||||
if source.Folder == "" {
|
||||
doc.Outlines = append(doc.Outlines, entry)
|
||||
continue
|
||||
}
|
||||
i, ok := groups[source.Folder]
|
||||
if !ok {
|
||||
i = len(doc.Outlines)
|
||||
groups[source.Folder] = i
|
||||
doc.Outlines = append(doc.Outlines, feedOPMLOutline{Text: source.Folder})
|
||||
}
|
||||
doc.Outlines[i].Children = append(doc.Outlines[i].Children, entry)
|
||||
}
|
||||
raw, err := xml.MarshalIndent(doc, "", " ")
|
||||
return append([]byte(xml.Header), raw...), err
|
||||
}
|
||||
|
||||
func (s *Server) handleFeedOPML(w http.ResponseWriter, r *http.Request, domain, actor, key string) {
|
||||
if key == "opml/export" && r.Method == http.MethodGet {
|
||||
sources, err := s.store.FeedSources(r.Context(), domain, actor)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
raw, err := encodeFeedOPML(sources)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/x-opml; charset=utf-8")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="pageswiki-feeds.opml"`)
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Write(raw)
|
||||
return
|
||||
}
|
||||
if r.Method != http.MethodPost || (key != "opml/preview" && key != "opml/import") {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
var input struct {
|
||||
OPML string `json:"opml"`
|
||||
Selected []int `json:"selected"`
|
||||
RequestID string `json:"request_id"`
|
||||
Expected string `json:"expected"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Interval int `json:"interval_seconds"`
|
||||
}
|
||||
if !taskJSONLimit(w, r, &input, 2<<20) {
|
||||
return
|
||||
}
|
||||
rows, err := parseFeedOPML(input.OPML)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
if key == "opml/preview" {
|
||||
sources, err := s.store.FeedSources(r.Context(), domain, actor)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
classifyFeedOPML(rows, sources)
|
||||
writeEventJSON(w, 200, map[string]any{"rows": rows, "expected": store.FeedSourcesSnapshot(sources), "available": 32 - len(sources)})
|
||||
return
|
||||
}
|
||||
// Reparse on apply; client-supplied titles, URLs or row eligibility are not trusted.
|
||||
classifyFeedOPML(rows, nil)
|
||||
seen := map[int]bool{}
|
||||
plan := store.FeedImport{RequestID: input.RequestID, Expected: input.Expected, Enabled: input.Enabled, Interval: input.Interval}
|
||||
for _, index := range input.Selected {
|
||||
if index < 0 || index >= len(rows) || seen[index] || rows[index].Status != "add" {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
seen[index] = true
|
||||
plan.Entries = append(plan.Entries, rows[index].FeedSubscription)
|
||||
}
|
||||
ids, err := s.store.ImportFeedSubscriptions(r.Context(), domain, actor, plan)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 201, map[string]any{"source_ids": ids})
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func opmlDoc(outlines string) string {
|
||||
return `<?xml version="1.0"?><opml version="2.0"><head><title>Test</title></head><body>` + outlines + `</body></opml>`
|
||||
}
|
||||
func opmlEntry(name, link string) string {
|
||||
return `<outline text="` + name + `" type="rss" xmlUrl="` + link + `"/>`
|
||||
}
|
||||
|
||||
func TestFeedOPMLParserAndExport(t *testing.T) {
|
||||
for _, version := range []string{"1.0", "1.1", "2.0"} {
|
||||
raw := strings.Replace(opmlDoc(`<outline text="技術"><outline text="Go">`+opmlEntry("A & B", "https://example.org/feed?a=1&b=2")+`</outline></outline>`), `version="2.0"`, `version="`+version+`"`, 1)
|
||||
rows, err := parseFeedOPML(raw)
|
||||
if err != nil || len(rows) != 1 || rows[0].Title != "A & B" || rows[0].Folder != "技術 / Go" || rows[0].URL != "https://example.org/feed?a=1&b=2" || rows[0].Status != "add" {
|
||||
t.Fatal(rows, err)
|
||||
}
|
||||
}
|
||||
for _, bad := range []string{
|
||||
strings.Replace(opmlDoc(""), `version="1.0"?>`, `version="1.0" encoding="iso-8859-1"?>`, 1),
|
||||
`<!DOCTYPE opml [<!ENTITY external SYSTEM "file:///etc/passwd">]>` + opmlDoc(""),
|
||||
opmlDoc("") + opmlDoc(""), opmlDoc("") + "garbage", `<opml version="2.0"><body/></opml>`,
|
||||
opmlDoc(`<outline text="x" text="y"/>`), opmlDoc(strings.Repeat(`<outline text="deep">`, 20) + strings.Repeat(`</outline>`, 20)),
|
||||
opmlDoc(strings.Repeat(opmlEntry("x", "https://example.org"), 501)), strings.Repeat("x", feedOPMLMaxBytes+1),
|
||||
opmlDoc(`<unexpected>` + opmlEntry("x", "https://example.org") + `</unexpected>`),
|
||||
} {
|
||||
if _, err := parseFeedOPML(bad); err == nil {
|
||||
t.Fatal("accepted invalid OPML")
|
||||
}
|
||||
}
|
||||
sources := []store.FeedSource{{Provider: "local", Title: "A & B", Folder: "技術 / Go", URL: "https://example.org/feed?a=1&b=2"}, {Provider: "local", Title: "Paused", Enabled: false, URL: "https://example.org/paused"}, {Provider: "freshrss", Title: "Remote", URL: "https://private.example.org/api/greader.php", Credential: "secret"}}
|
||||
raw, err := encodeFeedOPML(sources)
|
||||
if err != nil || strings.Contains(string(raw), "private.example.org") || strings.Contains(string(raw), "secret") {
|
||||
t.Fatal("export leak", err)
|
||||
}
|
||||
rows, err := parseFeedOPML(string(raw))
|
||||
if err != nil || len(rows) != 2 || rows[0].Folder != "技術 / Go" || rows[0].Title != "A & B" {
|
||||
t.Fatal("roundtrip", string(raw), rows, err)
|
||||
}
|
||||
raw, err = encodeFeedOPML(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if rows, err = parseFeedOPML(string(raw)); err != nil || len(rows) != 0 {
|
||||
t.Fatal("empty export", string(raw), err)
|
||||
}
|
||||
}
|
||||
|
||||
type opmlPreview struct {
|
||||
Rows []feedOPMLRow `json:"rows"`
|
||||
Expected string `json:"expected"`
|
||||
Available int `json:"available"`
|
||||
}
|
||||
|
||||
func previewOPML(t *testing.T, s *Server, token, raw string) opmlPreview {
|
||||
t.Helper()
|
||||
w := feedRequestTest(s, token, "POST", "opml/preview", map[string]string{"opml": raw})
|
||||
var preview opmlPreview
|
||||
if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &preview) != nil {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
return preview
|
||||
}
|
||||
|
||||
func TestFeedOPMLPreviewImportReplayAndOwnership(t *testing.T) {
|
||||
s, token, domain, actor, source := feedFixture(t)
|
||||
raw := opmlDoc(`<outline text="日本語">` + opmlEntry("New", "https://example.org/new") + opmlEntry("Existing", "https://EXAMPLE.org:443/feed.xml") + opmlEntry("Duplicate", "https://example.org/new") + opmlEntry("Private", "https://127.0.0.1/feed") + `<outline text="Skipped" isComment="true">` + opmlEntry("Hidden", "https://example.org/hidden") + `</outline><outline type="include" text="Include" url="https://example.org/external.opml"/>` + opmlEntry("", "https://example.org/empty-title") + `</outline>`)
|
||||
p := previewOPML(t, s, token, raw)
|
||||
if p.Available != 31 || len(p.Rows) != 7 {
|
||||
t.Fatal(p)
|
||||
}
|
||||
for i, want := range []string{"add", "existing", "duplicate", "unsupported_url", "commented", "unsupported_type", "invalid_fields"} {
|
||||
if p.Rows[i].Status != want {
|
||||
t.Fatal(i, p.Rows[i])
|
||||
}
|
||||
}
|
||||
all, _ := s.store.FeedSources(context.Background(), domain, actor)
|
||||
if len(all) != 1 {
|
||||
t.Fatal("preview wrote sources")
|
||||
}
|
||||
for _, index := range []int{2, 3, 4, 5, 6} {
|
||||
w := feedRequestTest(s, token, "POST", "opml/import", map[string]any{"opml": raw, "expected": p.Expected, "selected": []int{index}, "request_id": uuid.NewString(), "interval_seconds": 1800})
|
||||
if w.Code != 422 {
|
||||
t.Fatal("ineligible row accepted", index, w.Code)
|
||||
}
|
||||
}
|
||||
input := map[string]any{"opml": raw, "expected": p.Expected, "selected": []int{0}, "request_id": uuid.NewString(), "enabled": false, "interval_seconds": 1800}
|
||||
w := feedRequestTest(s, token, "POST", "opml/import", input)
|
||||
if w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
original := w.Body.String()
|
||||
if retry := feedRequestTest(s, token, "POST", "opml/import", input); retry.Code != 201 || retry.Body.String() != original {
|
||||
t.Fatal("retry", retry.Code, retry.Body)
|
||||
}
|
||||
input["enabled"] = true
|
||||
if retry := feedRequestTest(s, token, "POST", "opml/import", input); retry.Code != 412 {
|
||||
t.Fatal("changed retry", retry.Code)
|
||||
}
|
||||
input["enabled"] = false
|
||||
all, _ = s.store.FeedSources(context.Background(), domain, actor)
|
||||
if len(all) != 2 {
|
||||
t.Fatal("duplicate import", len(all))
|
||||
}
|
||||
for _, v := range all {
|
||||
if v.UUID != source.UUID {
|
||||
if v.Enabled || v.Title != "New" || v.Folder != "日本語" {
|
||||
t.Fatal(v)
|
||||
}
|
||||
if err := s.store.FeedSourceAction(context.Background(), domain, actor, v.UUID, "delete", v.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if retry := feedRequestTest(s, token, "POST", "opml/import", input); retry.Code != 201 || retry.Body.String() != original {
|
||||
t.Fatal("deleted retry", retry.Code, retry.Body)
|
||||
}
|
||||
all, _ = s.store.FeedSources(context.Background(), domain, actor)
|
||||
if len(all) != 1 {
|
||||
t.Fatal("resurrected source")
|
||||
}
|
||||
w = feedRequestTest(s, token, "GET", "opml/export", nil)
|
||||
if w.Code != 200 || !strings.Contains(w.Header().Get("Content-Disposition"), "attachment") || !strings.Contains(w.Header().Get("Cache-Control"), "no-store") {
|
||||
t.Fatal(w.Code, w.Header())
|
||||
}
|
||||
other, err := s.store.CreatePasswordAccount(domain, "opmlother", "long test password", "Other", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
otherToken, err := s.store.CreateAuthSession(domain, other.UUID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w = feedRequestTest(s, otherToken, "GET", "opml/export", nil)
|
||||
if w.Code != 200 || strings.Contains(w.Body.String(), source.URL) {
|
||||
t.Fatal("owner leak", w.Code, w.Body)
|
||||
}
|
||||
if w = feedRequestTest(s, "", "GET", "opml/export", nil); w.Code == 200 {
|
||||
t.Fatal("anonymous export")
|
||||
}
|
||||
if err = s.store.SetPrincipalState(domain, actor, "readonly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, err = s.store.CreateAuthSession(domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w = feedRequestTest(s, token, "GET", "opml/export", nil); w.Code != 200 {
|
||||
t.Fatal("readonly export", w.Code)
|
||||
}
|
||||
if w = feedRequestTest(s, token, "POST", "opml/import", input); w.Code != 403 {
|
||||
t.Fatal("readonly mutation", w.Code)
|
||||
}
|
||||
if err = s.setSystemExtensionEnabled(domain, "organizer.feeds", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w = feedRequestTest(s, token, "GET", "opml/export", nil); w.Code != 404 {
|
||||
t.Fatal("disabled export", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedOPMLAtomicityLimitsAndConcurrentApply(t *testing.T) {
|
||||
s, token, domain, actor, source := feedFixture(t)
|
||||
raw := opmlDoc(opmlEntry("A", "https://example.org/a") + opmlEntry("B", "https://example.org/b"))
|
||||
p := previewOPML(t, s, token, raw)
|
||||
input := map[string]any{"opml": raw, "expected": p.Expected, "selected": []int{0, 1}, "request_id": uuid.NewString(), "interval_seconds": 1800}
|
||||
if _, err := s.store.DB.Exec(`CREATE TRIGGER fail_feed_import BEFORE INSERT ON feed_import_receipts BEGIN SELECT RAISE(ABORT,'synthetic failure'); END`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := feedRequestTest(s, token, "POST", "opml/import", input); w.Code != 500 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
all, _ := s.store.FeedSources(context.Background(), domain, actor)
|
||||
if len(all) != 1 {
|
||||
t.Fatal("partial source insert")
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`DROP TRIGGER fail_feed_import`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// A configuration edit invalidates the preview; neither new source is applied.
|
||||
source.Title = "Changed"
|
||||
if _, err := s.store.SaveFeedSource(context.Background(), domain, actor, source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := feedRequestTest(s, token, "POST", "opml/import", input); w.Code != 412 {
|
||||
t.Fatal("stale preview", w.Code)
|
||||
}
|
||||
p = previewOPML(t, s, token, raw)
|
||||
input["expected"] = p.Expected
|
||||
var wg sync.WaitGroup
|
||||
codes := make(chan int, 2)
|
||||
for range 2 {
|
||||
wg.Add(1)
|
||||
go func() { defer wg.Done(); codes <- feedRequestTest(s, token, "POST", "opml/import", input).Code }()
|
||||
}
|
||||
wg.Wait()
|
||||
close(codes)
|
||||
for code := range codes {
|
||||
if code != 201 {
|
||||
t.Fatal("concurrent retry", code)
|
||||
}
|
||||
}
|
||||
all, _ = s.store.FeedSources(context.Background(), domain, actor)
|
||||
if len(all) != 3 {
|
||||
t.Fatal("duplicate concurrent import")
|
||||
}
|
||||
entries := ""
|
||||
selected := []int{}
|
||||
for i := 0; i < 32; i++ {
|
||||
entries += opmlEntry(fmt.Sprint(i), fmt.Sprintf("https://example.org/large/%d", i))
|
||||
selected = append(selected, i)
|
||||
}
|
||||
raw = opmlDoc(entries)
|
||||
p = previewOPML(t, s, token, raw)
|
||||
input = map[string]any{"opml": raw, "expected": p.Expected, "selected": selected, "request_id": uuid.NewString(), "interval_seconds": 1800}
|
||||
if w := feedRequestTest(s, token, "POST", "opml/import", input); w.Code != 507 {
|
||||
t.Fatal("capacity", w.Code, w.Body)
|
||||
}
|
||||
all, _ = s.store.FeedSources(context.Background(), domain, actor)
|
||||
if len(all) != 3 {
|
||||
t.Fatal("partial limit import")
|
||||
}
|
||||
for _, selection := range [][]int{{-1}, {99}, {0, 0}, {}} {
|
||||
input["selected"] = selection
|
||||
if w := feedRequestTest(s, token, "POST", "opml/import", input); w.Code != 422 {
|
||||
t.Fatal("invalid selection", selection, w.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,597 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func feedFixture(t *testing.T) (*Server, string, string, string, store.FeedSource) {
|
||||
t.Helper()
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
source, e := s.store.SaveFeedSource(context.Background(), domain, actor, store.FeedSource{UUID: uuid.NewString(), Provider: "local", Title: "Synthetic news", Folder: "Tech", URL: "https://example.org/feed.xml", Enabled: true, Interval: 300})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
sources, e := s.store.FeedSources(context.Background(), domain, actor)
|
||||
if e != nil || len(sources) != 1 {
|
||||
t.Fatal(e)
|
||||
}
|
||||
source = sources[0]
|
||||
return s, token, domain, actor, source
|
||||
}
|
||||
func feedRequestTest(s *Server, token, method, key string, body any) *httptest.ResponseRecorder {
|
||||
raw, _ := json.Marshal(body)
|
||||
r := httptest.NewRequest(method, "http://localhost"+feedsAPI+key, strings.NewReader(string(raw)))
|
||||
r.Header.Set("Content-Type", "application/json")
|
||||
if token != "" {
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
return w
|
||||
}
|
||||
func TestFeedReaderStateIsolationAndFencing(t *testing.T) {
|
||||
s, token, domain, actor, source := feedFixture(t)
|
||||
ctx := context.Background()
|
||||
claim, e := s.store.ClaimFeed(ctx, source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.store.ClaimFeed(ctx, source); !errors.Is(e, store.ErrTaskConflict) {
|
||||
t.Fatal("double claim", e)
|
||||
}
|
||||
item := store.FeedItem{ID: "one", Title: "日本語 news", Body: "safe text", URL: "https://example.org/one", PublishedMS: 1}
|
||||
if e = s.store.CompleteFeed(ctx, claim, []store.FeedItem{item}, "e1", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if w := feedRequestTest(s, token, "GET", "items", nil); w.Code != 200 || !strings.Contains(w.Body.String(), "日本語") {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w := feedRequestTest(s, "", "GET", "items", nil); w.Code == 200 {
|
||||
t.Fatal("anonymous")
|
||||
}
|
||||
if _, e = s.store.FeedItem(ctx, domain, uuid.NewString(), source.UUID, "one"); !errors.Is(e, store.ErrAccessDenied) {
|
||||
t.Fatal(e)
|
||||
}
|
||||
state := map[string]any{"source": source.UUID, "id": "one", "read": true, "starred": true, "version": 0}
|
||||
if w := feedRequestTest(s, token, "POST", "state", state); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w := feedRequestTest(s, token, "POST", "state", state); w.Code != 412 {
|
||||
t.Fatal("stale state", w.Code, w.Body)
|
||||
}
|
||||
got, e := s.store.FeedItem(ctx, domain, actor, source.UUID, "one")
|
||||
if e != nil || !got.Read || !got.Starred || got.Version != 1 {
|
||||
t.Fatal(got, e)
|
||||
}
|
||||
if e = s.store.CompleteFeed(ctx, claim, nil, "", "", "", false); !errors.Is(e, store.ErrTaskConflict) {
|
||||
t.Fatal("old completion", e)
|
||||
}
|
||||
// Re-fetch must preserve local read/star; config edits invalidate in-flight work.
|
||||
source.Version = 1
|
||||
source, e = s.store.SaveFeedSource(ctx, domain, actor, source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
sources, _ := s.store.FeedSources(ctx, domain, actor)
|
||||
claim, e = s.store.ClaimFeed(ctx, sources[0])
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.store.CompleteFeed(ctx, claim, []store.FeedItem{item}, "", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, _ = s.store.FeedItem(ctx, domain, actor, source.UUID, "one")
|
||||
if !got.Read || !got.Starred {
|
||||
t.Fatal("lost state")
|
||||
}
|
||||
source, e = s.store.SaveFeedSource(ctx, domain, actor, source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
sources, _ = s.store.FeedSources(ctx, domain, actor)
|
||||
claim, e = s.store.ClaimFeed(ctx, sources[0])
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
source.Enabled = false
|
||||
source, e = s.store.SaveFeedSource(ctx, domain, actor, source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.store.CompleteFeed(ctx, claim, []store.FeedItem{item}, "", "", "", false); !errors.Is(e, store.ErrTaskConflict) {
|
||||
t.Fatal("disabled late commit", e)
|
||||
}
|
||||
if e = s.setSystemExtensionEnabled(domain, "organizer.feeds", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.store.FeedItems(ctx, domain, actor, "", "", "", -1, ""); !errors.Is(e, store.ErrAccessDenied) {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if w := feedRequestTest(s, token, "GET", "items", nil); w.Code != 404 {
|
||||
t.Fatal(w.Code)
|
||||
}
|
||||
}
|
||||
func TestFeedParserSafetyAndFormats(t *testing.T) {
|
||||
rss := `<?xml version="1.0"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>News</title><item><guid>id</guid><title>日本語</title><link>/one</link><content:encoded><![CDATA[<p>Hello</p><script>alert(1)</script><img src="https://evil.invalid/pixel"><b>world</b>]]></content:encoded><pubDate>Fri, 06 Nov 2026 10:00:00 +0000</pubDate></item></channel></rss>`
|
||||
items, e := parseFeed([]byte(rss), "https://example.org/feed")
|
||||
if e != nil || len(items) != 1 || items[0].URL != "https://example.org/one" || strings.Contains(items[0].Body, "alert") || strings.Contains(items[0].Body, "pixel") || items[0].PublishedMS == 0 {
|
||||
t.Fatal(items, e)
|
||||
}
|
||||
atom := `<feed xmlns="http://www.w3.org/2005/Atom"><title>Atom</title><entry><id>urn:one</id><title>One</title><link href="https://example.org/one"/><updated>2026-11-01T10:00:00Z</updated><content type="html"><p>Body</p></content></entry></feed>`
|
||||
items, e = parseFeed([]byte(atom), "https://example.org")
|
||||
if e != nil || len(items) != 1 || items[0].Body != "Body" {
|
||||
t.Fatal(items, e)
|
||||
}
|
||||
for _, raw := range []string{`<!DOCTYPE rss [<!ENTITY x SYSTEM "file:///etc/passwd">]><rss/>`, `<html>error</html>`, `<rss/><rss/>`, `<rss><channel><item><guid>x</guid></item><item><guid>x</guid></item></channel></rss>`, strings.Repeat("x", (4<<20)+1)} {
|
||||
if _, e = parseFeed([]byte(raw), "https://example.org"); e == nil {
|
||||
t.Fatal("accepted malformed feed")
|
||||
}
|
||||
}
|
||||
if feedLink("https://example.org", "javascript:alert(1)") != "" || feedLink("https://example.org", "https://user:pass@example.org") != "" {
|
||||
t.Fatal("unsafe link")
|
||||
}
|
||||
items, e = parseFeed([]byte(`<rss><channel><item><title>No ID or link</title><description>First body</description></item><item><title>No ID or link</title><description>Second body</description></item></channel></rss>`), "https://example.org/feed")
|
||||
if e != nil || len(items) != 2 || items[0].ID == items[1].ID || items[0].URL != "" {
|
||||
t.Fatal("missing IDs must not collapse to the feed URL", items, e)
|
||||
}
|
||||
}
|
||||
func TestFreshRSSReadOnlyContract(t *testing.T) {
|
||||
requests := []string{}
|
||||
remote := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests = append(requests, r.Method+" "+r.URL.Path)
|
||||
switch r.URL.Path {
|
||||
case "/api/greader.php/accounts/ClientLogin":
|
||||
if r.Method != "POST" {
|
||||
t.Error("login method")
|
||||
}
|
||||
r.ParseForm()
|
||||
if r.Form.Get("Email") != "reader" || r.Form.Get("Passwd") != "api-secret" {
|
||||
t.Error("login form")
|
||||
}
|
||||
fmt.Fprint(w, "SID=x\nAuth=reader/token\n")
|
||||
case "/api/greader.php/reader/api/0/stream/contents/reading-list":
|
||||
if r.Header.Get("Authorization") != "GoogleLogin auth=reader/token" || r.URL.Query().Get("n") != "200" {
|
||||
t.Error("request contract")
|
||||
}
|
||||
fmt.Fprint(w, `{"items":[{"id":"tag:1","title":"Title","summary":{"content":"<p>Text</p>"},"published":1793500000,"categories":["user/reader/state/com.google/read","user/reader/state/com.google/starred","user/reader/label/Tech"],"origin":{"title":"Feed"},"alternate":[{"href":"https://example.org/article"}]}]}`)
|
||||
default:
|
||||
t.Error("unexpected mutation", r.URL.Path)
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
}))
|
||||
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" || 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"} {
|
||||
if validCalendarSourceURL(bad) {
|
||||
t.Fatal("SSRF URL", bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
claim, e := s.store.ClaimFeed(ctx, source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
items := []store.FeedItem{}
|
||||
for i := 0; i < 205; i++ {
|
||||
items = append(items, store.FeedItem{ID: fmt.Sprintf("id-%03d", i), Title: "Title", Body: "Body", PublishedMS: 100})
|
||||
}
|
||||
if e = s.store.CompleteFeed(ctx, claim, items, "old", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
before := int64(-1)
|
||||
key := ""
|
||||
for {
|
||||
batch, e := s.store.FeedItems(ctx, domain, actor, "", "", "", before, key)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
more := len(batch) > 100
|
||||
if more {
|
||||
batch = batch[:100]
|
||||
}
|
||||
for _, item := range batch {
|
||||
if seen[item.ID] {
|
||||
t.Fatal("duplicate")
|
||||
}
|
||||
seen[item.ID] = true
|
||||
}
|
||||
if !more {
|
||||
break
|
||||
}
|
||||
last := batch[len(batch)-1]
|
||||
before = last.PublishedMS
|
||||
key = last.Source + ":" + last.ID
|
||||
}
|
||||
if len(seen) != 205 {
|
||||
t.Fatal(len(seen))
|
||||
}
|
||||
source, e = s.store.SaveFeedSource(ctx, domain, actor, source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
sources, _ := s.store.FeedSources(ctx, domain, actor)
|
||||
claim, e = s.store.ClaimFeed(ctx, sources[0])
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.store.CompleteFeed(ctx, claim, nil, "", "", "network", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.store.FeedItem(ctx, domain, actor, source.UUID, "id-001"); e != nil {
|
||||
t.Fatal("cache lost on failure", e)
|
||||
}
|
||||
if w := feedRequestTest(s, token, "POST", "sources/"+source.UUID+"/delete", map[string]int64{"version": source.Version}); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
var count int
|
||||
if e = s.store.DB.QueryRow(`SELECT count(*) FROM feed_items`).Scan(&count); e != nil || count != 0 {
|
||||
t.Fatal("cascade", count, e)
|
||||
}
|
||||
var integrity string
|
||||
if e = s.store.DB.QueryRow(`PRAGMA integrity_check`).Scan(&integrity); e != nil || integrity != "ok" {
|
||||
t.Fatal(integrity, e)
|
||||
}
|
||||
}
|
||||
func TestFeedSourceAPIAndCredentialBinding(t *testing.T) {
|
||||
s, token, domain, actor, _ := feedFixture(t)
|
||||
input := map[string]any{"uuid": uuid.NewString(), "provider": "freshrss", "title": "Remote", "url": "https://rss.example.org/api/greader.php", "interval_seconds": 300, "enabled": true, "username": "reader", "password": "top-secret"}
|
||||
w := feedRequestTest(s, token, "POST", "sources", input)
|
||||
if w.Code != 200 || strings.Contains(w.Body.String(), "secret") {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
// Each HTTP retry seals a different ciphertext, but identical credentials and
|
||||
// request UUID must still return the same source, not create a duplicate.
|
||||
if retry := feedRequestTest(s, token, "POST", "sources", input); retry.Code != 200 || retry.Body.String() != w.Body.String() {
|
||||
t.Fatal("source replay", retry.Code, retry.Body)
|
||||
}
|
||||
input["password"] = "changed-secret"
|
||||
if retry := feedRequestTest(s, token, "POST", "sources", input); retry.Code != 412 {
|
||||
t.Fatal("changed source replay", retry.Code, retry.Body)
|
||||
}
|
||||
input["password"] = "top-secret"
|
||||
sources, e := s.store.FeedSources(context.Background(), domain, actor)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(sources) != 2 {
|
||||
t.Fatal("duplicate source", len(sources))
|
||||
}
|
||||
var remote store.FeedSource
|
||||
for _, v := range sources {
|
||||
if v.Provider == "freshrss" {
|
||||
remote = v
|
||||
}
|
||||
}
|
||||
u, p, e := s.store.OpenFeedCredential(remote)
|
||||
if e != nil || u != "reader" || p != "top-secret" {
|
||||
t.Fatal("credential", e)
|
||||
}
|
||||
remote.Owner = uuid.NewString()
|
||||
if _, _, e = s.store.OpenFeedCredential(remote); e == nil {
|
||||
t.Fatal("credential rebound")
|
||||
}
|
||||
if w = feedRequestTest(s, token, "GET", "sources", nil); w.Code != 200 || strings.Contains(w.Body.String(), "top-secret") || strings.Contains(w.Body.String(), "credential") {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
input["url"] = "https://127.0.0.1/api/greader.php"
|
||||
if w = feedRequestTest(s, token, "POST", "sources", input); w.Code != 422 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedFreshRSSAuthorityAndRevocation(t *testing.T) {
|
||||
s, token, domain, actor, local := feedFixture(t)
|
||||
ctx := context.Background()
|
||||
v, e := s.store.SaveFeedSource(ctx, domain, actor, store.FeedSource{UUID: uuid.NewString(), Provider: "freshrss", Title: "FreshRSS", URL: "https://example.org/api/greader.php", Enabled: true, Interval: 300})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
claim := func() store.FeedSource {
|
||||
t.Helper()
|
||||
// Simulate the next scheduler tick without a wall-clock wait.
|
||||
if _, err := s.store.DB.Exec(`UPDATE feed_sources SET next_ms=0 WHERE uuid=?`, v.UUID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
all, err := s.store.FeedSources(ctx, domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, source := range all {
|
||||
if source.UUID == v.UUID {
|
||||
v = source
|
||||
}
|
||||
}
|
||||
c, err := s.store.ClaimFeed(ctx, v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
c := claim()
|
||||
if e = s.store.CompleteFeed(ctx, c, []store.FeedItem{{ID: "removed", Title: "Removed"}, {ID: "kept", Title: "Kept", Read: true, Starred: true}}, "", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.store.SetFeedState(ctx, domain, actor, v.UUID, "kept", false, false, 0); !errors.Is(e, store.ErrAccessDenied) {
|
||||
t.Fatal("remote state mutation", e)
|
||||
}
|
||||
c = claim()
|
||||
if e = s.store.CompleteFeed(ctx, c, []store.FeedItem{{ID: "kept", Title: "Changed elsewhere", Read: false}}, "", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
items, e := s.store.FeedItems(ctx, domain, actor, v.UUID, "", "", -1, "")
|
||||
if e != nil || len(items) != 1 || items[0].Read || items[0].Starred || items[0].Title != "Changed elsewhere" {
|
||||
t.Fatal("non-authoritative cache", items, e)
|
||||
}
|
||||
c = claim()
|
||||
if e = s.store.SetPrincipalState(domain, actor, "readonly"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
// Changing principal state invalidates the previous session.
|
||||
token, e = s.store.CreateAuthSession(domain, actor)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.store.FeedItems(ctx, domain, actor, "", "", "", -1, ""); e != nil {
|
||||
t.Fatal("readonly read", e)
|
||||
}
|
||||
if e = s.store.CompleteFeed(ctx, c, nil, "", "", "", false); !errors.Is(e, store.ErrAccessDenied) {
|
||||
t.Fatal("late revoked worker", e)
|
||||
}
|
||||
if w := feedRequestTest(s, token, "POST", "sources/"+local.UUID+"/delete", map[string]int64{"version": 1}); w.Code != 403 {
|
||||
t.Fatal("readonly API", w.Code, w.Body)
|
||||
}
|
||||
if due, err := s.store.DueFeedSources(ctx); err != nil || len(due) != 0 {
|
||||
t.Fatal("inactive source starves queue", due, err)
|
||||
}
|
||||
if e = s.store.SetPrincipalState(domain, actor, "active"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.setSystemExtensionEnabled(domain, "organizer.feeds", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if due, err := s.store.DueFeedSources(ctx); err != nil || len(due) != 0 {
|
||||
t.Fatal("disabled extension starves queue", due, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedNoteAtomicReceiptAndPermissions(t *testing.T) {
|
||||
s, token, domain, _, source := feedFixture(t)
|
||||
ctx := context.Background()
|
||||
claim, e := s.store.ClaimFeed(ctx, source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.store.CompleteFeed(ctx, claim, []store.FeedItem{{ID: "note", Title: "Title", Body: "Body"}}, "", "", "", false); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
id := uuid.NewString()
|
||||
input := map[string]any{"request_id": id, "source": source.UUID, "id": "note", "path": "/notes/rss-" + id, "title": "RSS title", "body": "Source: https://example.org\n{{children}} <script>bad()</script>", "confirm_publication": true}
|
||||
w := feedRequestTest(s, token, "POST", "note", input)
|
||||
if w.Code != 201 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
original := w.Body.String()
|
||||
if w = feedRequestTest(s, token, "POST", "note", input); w.Code != 201 || w.Body.String() != original {
|
||||
t.Fatal("replay", w.Code, w.Body)
|
||||
}
|
||||
var response map[string]string
|
||||
json.Unmarshal(w.Body.Bytes(), &response)
|
||||
rev, e := s.store.GetLatestRevision(response["page_uuid"])
|
||||
if e != nil || strings.Contains(rev.Body, "{{children}}") || strings.Contains(rev.Body, "<script>") {
|
||||
t.Fatal(rev, e)
|
||||
}
|
||||
input["body"] = "changed"
|
||||
if w = feedRequestTest(s, token, "POST", "note", input); w.Code != 412 {
|
||||
t.Fatal("changed replay", w.Code, w.Body)
|
||||
}
|
||||
input["request_id"] = uuid.NewString()
|
||||
if w = feedRequestTest(s, token, "POST", "note", input); w.Code != 409 {
|
||||
t.Fatal("path exists", w.Code, w.Body)
|
||||
}
|
||||
input["path"] = "/u/other/rss"
|
||||
if w = feedRequestTest(s, token, "POST", "note", input); w.Code != 403 {
|
||||
t.Fatal("reserved user space", w.Code, w.Body)
|
||||
}
|
||||
// Roll back page/path when the durable receipt cannot be committed.
|
||||
if _, e = s.store.DB.Exec(`CREATE TRIGGER fail_feed_receipt BEFORE INSERT ON feed_note_receipts BEGIN SELECT RAISE(ABORT,'synthetic failure'); END`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
input["path"] = "/notes/rollback"
|
||||
if w = feedRequestTest(s, token, "POST", "note", input); w.Code != 500 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
var n int
|
||||
if e = s.store.DB.QueryRow(`SELECT count(*) FROM paths WHERE domain_uuid=? AND path='/notes/rollback'`, domain).Scan(&n); e != nil || n != 0 {
|
||||
t.Fatal("partial note", n, e)
|
||||
}
|
||||
}
|
||||
|
||||
type feedTransportFunc func(*http.Request) (*http.Response, error)
|
||||
|
||||
func (f feedTransportFunc) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
|
||||
|
||||
func TestFeedBackgroundConditionalFetch(t *testing.T) {
|
||||
s, _, domain, actor, source := feedFixture(t)
|
||||
ctx := context.Background()
|
||||
step := 0
|
||||
client := &http.Client{Transport: feedTransportFunc(func(r *http.Request) (*http.Response, error) {
|
||||
step++
|
||||
if r.URL.String() != source.URL || r.Method != "GET" {
|
||||
t.Fatal("unexpected request", r.Method, r.URL)
|
||||
}
|
||||
deadline, ok := r.Context().Deadline()
|
||||
if !ok || time.Until(deadline) > 8*time.Second {
|
||||
t.Fatal("unbounded fetch")
|
||||
}
|
||||
switch step {
|
||||
case 1:
|
||||
return &http.Response{StatusCode: 200, Header: http.Header{"Etag": {`"feed-1"`}}, Body: io.NopCloser(strings.NewReader(`<rss><channel><item><guid>id</guid><title>First</title></item></channel></rss>`))}, nil
|
||||
case 2:
|
||||
if r.Header.Get("If-None-Match") != `"feed-1"` {
|
||||
t.Fatal("missing conditional GET")
|
||||
}
|
||||
return &http.Response{StatusCode: 304, Header: http.Header{}, Body: io.NopCloser(strings.NewReader(""))}, nil
|
||||
default:
|
||||
return nil, errors.New("synthetic failure containing a secret URL; must not be persisted")
|
||||
}
|
||||
})}
|
||||
for tick := 1; tick <= 3; tick++ {
|
||||
if _, e := s.store.DB.Exec(`UPDATE feed_sources SET next_ms=0 WHERE uuid=?`, source.UUID); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e := s.syncFeedSourcesWithClient(ctx, &store.EventJob{UUID: uuid.NewString(), Type: store.FeedSyncEventType}, client); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if step != tick {
|
||||
t.Fatal("wrong fetch count", step, tick)
|
||||
}
|
||||
item, e := s.store.FeedItem(ctx, domain, actor, source.UUID, "id")
|
||||
if e != nil || item.Title != "First" {
|
||||
t.Fatal("cache not preserved", item, e)
|
||||
}
|
||||
all, e := s.store.FeedSources(ctx, domain, actor)
|
||||
if e != nil || len(all) != 1 || all[0].ETag != `"feed-1"` || all[0].Lease != "" || all[0].NextMS <= time.Now().UnixMilli() {
|
||||
t.Fatal("worker metadata", all, e)
|
||||
}
|
||||
if tick == 3 && all[0].Error != "network" {
|
||||
t.Fatal("secret error leaked", all[0].Error)
|
||||
}
|
||||
if e := s.syncFeedSourcesWithClient(ctx, &store.EventJob{UUID: uuid.NewString()}, client); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if step != tick {
|
||||
t.Fatal("cooldown ignored")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedsChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
s, token, domain, actor, source := feedFixture(t)
|
||||
claim, e := s.store.ClaimFeed(context.Background(), source)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
items := []store.FeedItem{}
|
||||
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)
|
||||
}
|
||||
fresh, e := s.store.SaveFeedSource(context.Background(), domain, actor, store.FeedSource{UUID: uuid.NewString(), Provider: "freshrss", Title: "FreshRSS fixture", URL: "https://example.org/api/greader.php", Enabled: true, Interval: 300})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
all, e := s.store.FeedSources(context.Background(), domain, actor)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, v := range all {
|
||||
if v.UUID == fresh.UUID {
|
||||
fresh = v
|
||||
}
|
||||
}
|
||||
claim, e = s.store.ClaimFeed(context.Background(), fresh)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
catalog, e := parseFreshRSSCatalog([]byte(testFeedCatalog))
|
||||
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 {
|
||||
t.Fatal(e)
|
||||
}
|
||||
s.store.BackgroundJobsDisabled = true
|
||||
s = New(s.store)
|
||||
script, e := os.ReadFile("internal/server/testdata/feeds.js")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
handler := s.handler()
|
||||
web := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.URL.Path == "/fixture" {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprint(w, "<!doctype html><body style='margin:0'><script>"+string(script)+"</script></body>")
|
||||
return
|
||||
}
|
||||
handler.ServeHTTP(w, r)
|
||||
}))
|
||||
defer web.Close()
|
||||
for _, width := range []string{"1440", "390"} {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
||||
args := []string{"internal/server/testdata/vim-browser-smoke.mjs", web.URL + "/fixture?width=" + url.QueryEscape(width), t.TempDir(), "/tmp/pageswiki-feeds-" + width + ".png", width, "850"}
|
||||
out, e := exec.CommandContext(ctx, "node", args...).CombinedOutput()
|
||||
cancel()
|
||||
if e != nil {
|
||||
t.Fatalf("browser %s: %v %s", width, e, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type homePaletteSettings struct {
|
||||
Mode string `json:"mode"`
|
||||
Strength int `json:"strength"`
|
||||
Brightness string `json:"brightness"`
|
||||
}
|
||||
|
||||
func validHomePalette(p homePaletteSettings) bool {
|
||||
return (p.Mode == "off" || p.Mode == "accent" || p.Mode == "surface") && p.Strength >= 0 && p.Strength <= 100 && (p.Brightness == "preserve" || p.Brightness == "auto")
|
||||
}
|
||||
|
||||
func (s *Server) homePalette(domain string) homePaletteSettings {
|
||||
p := homePaletteSettings{Mode: "surface", Strength: 35, Brightness: "preserve"}
|
||||
var saved homePaletteSettings
|
||||
if json.Unmarshal([]byte(s.getDomainConfig("home_wallpaper_palette", domain)), &saved) == nil && validHomePalette(saved) {
|
||||
return saved
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (s *Server) parseHomePalette(domain string, form url.Values) (homePaletteSettings, error) {
|
||||
p := s.homePalette(domain)
|
||||
if form.Has("home_palette_mode") {
|
||||
p.Mode = form.Get("home_palette_mode")
|
||||
}
|
||||
if form.Has("home_palette_brightness") {
|
||||
p.Brightness = form.Get("home_palette_brightness")
|
||||
}
|
||||
if form.Has("home_palette_strength") {
|
||||
n, err := strconv.Atoi(form.Get("home_palette_strength"))
|
||||
if err != nil {
|
||||
return p, errors.New("invalid wallpaper palette strength")
|
||||
}
|
||||
p.Strength = n
|
||||
}
|
||||
if !validHomePalette(p) {
|
||||
return p, errors.New("invalid wallpaper palette settings")
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (s *Server) saveHomePalette(domain string, p homePaletteSettings) error {
|
||||
b, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.store.SetConfigInDomain(domain, "home_wallpaper_palette", string(b))
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHomePaletteSettingsAndScope(t *testing.T) {
|
||||
s, token, domain := configFixture(t)
|
||||
s.mux.HandleFunc("/", s.handleHome)
|
||||
saveWallpaperFixture(t, s, domain, "/wallpapers/a.jpg", "image/jpeg")
|
||||
if err := s.store.SetConfigInDomain(domain, "home_wallpaper_path", "/wallpapers/a.jpg"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
initial := s.homePalette(domain)
|
||||
if initial.Mode != "surface" || initial.Strength != 35 || initial.Brightness != "preserve" {
|
||||
t.Fatal(initial)
|
||||
}
|
||||
for _, values := range []url.Values{{"home_palette_mode": {"bad"}}, {"home_palette_strength": {"101"}}, {"home_palette_strength": {"-1"}}, {"home_palette_strength": {"bad"}}, {"home_palette_brightness": {"bad"}}} {
|
||||
values.Set("section", "home-appearance")
|
||||
values.Set("home_glass_transparency", "47")
|
||||
if w := configRequest(s, token, "POST", "/-/sys/config", values); w.Code != 400 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if s.homePalette(domain) != initial || s.homeGlassTransparency(domain) != 42 {
|
||||
t.Fatal("invalid request partially saved")
|
||||
}
|
||||
}
|
||||
values := url.Values{"section": {"home-appearance"}, "home_glass_transparency": {"47"}, "home_palette_mode": {"accent"}, "home_palette_strength": {"70"}, "home_palette_brightness": {"auto"}}
|
||||
if w := configRequest(s, token, "POST", "/-/sys/config", values); w.Code != http.StatusFound {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if p := s.homePalette(domain); p.Mode != "accent" || p.Strength != 70 || p.Brightness != "auto" {
|
||||
t.Fatal(p)
|
||||
}
|
||||
member, err := s.store.CreatePasswordAccount(domain, "palette-reader", "a long test password", "Reader", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
memberToken, err := s.store.CreateAuthSession(domain, member.UUID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := configRequest(s, memberToken, "POST", "/-/sys/config", url.Values{"section": {"home-appearance"}, "home_palette_mode": {"off"}, "home_glass_transparency": {"47"}}); w.Code != http.StatusForbidden {
|
||||
t.Fatalf("member changed domain appearance: %d", w.Code)
|
||||
}
|
||||
if s.homePalette(domain).Mode != "accent" {
|
||||
t.Fatal("member overwrote settings")
|
||||
}
|
||||
for _, layout := range []string{"classic", "search", "directory"} {
|
||||
if err := s.store.SetConfigInDomain(domain, "home_layout", layout); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := configRequest(s, token, "GET", "/", nil)
|
||||
for _, want := range []string{`data-home-palette`, `data-mode="accent"`, `data-strength="70"`, `data-home-appearance-open`, `/static/js/home-palette.js?v=1`} {
|
||||
if w.Code != 200 || !strings.Contains(w.Body.String(), want) {
|
||||
t.Fatal(layout, w.Code, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, path := range []string{"/-/sys/config?panel=home", "/missing-page"} {
|
||||
w := configRequest(s, token, http.MethodGet, path, nil)
|
||||
if strings.Contains(w.Body.String(), `data-home-palette `) || strings.Contains(w.Body.String(), `src="/static/js/home-palette.js`) {
|
||||
t.Fatal("theme leaked outside home", path)
|
||||
}
|
||||
}
|
||||
settings := configRequest(s, token, http.MethodGet, "/-/sys/config?panel=home", nil)
|
||||
if settings.Code != http.StatusOK || !strings.Contains(settings.Body.String(), `name="home_palette_mode"`) || !strings.Contains(settings.Body.String(), `value="accent" selected`) {
|
||||
t.Fatal("settings panel did not load saved palette")
|
||||
}
|
||||
for _, section := range []string{"home", "home-appearance"} {
|
||||
invalid := url.Values{"section": {section}, "home_palette_strength": {"NaN"}, "home_layout": {"search"}}
|
||||
if w := configRequest(s, token, http.MethodPost, "/-/sys/config", invalid); w.Code != http.StatusBadRequest {
|
||||
t.Fatal(section, w.Code)
|
||||
}
|
||||
}
|
||||
// Old forms may omit the new fields without resetting their saved settings.
|
||||
delete(values, "home_palette_mode")
|
||||
delete(values, "home_palette_strength")
|
||||
delete(values, "home_palette_brightness")
|
||||
if w := configRequest(s, token, "POST", "/-/sys/config", values); w.Code != http.StatusFound {
|
||||
t.Fatal(w.Code)
|
||||
}
|
||||
if s.homePalette(domain).Mode != "accent" {
|
||||
t.Fatal("old form reset settings")
|
||||
}
|
||||
if err := s.store.SetConfigInDomain(domain, "home_wallpaper_path", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := configRequest(s, token, "GET", "/", nil)
|
||||
if strings.Contains(w.Body.String(), `src="/static/js/home-palette.js`) {
|
||||
t.Fatal("loaded extractor without wallpaper")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHomePaletteChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
s, token, domain := configFixture(t)
|
||||
s.store.BackgroundJobsDisabled = true
|
||||
s = New(s.store)
|
||||
picture := image.NewRGBA(image.Rect(0, 0, 480, 320))
|
||||
for y := 0; y < 320; y++ {
|
||||
for x := 0; x < 480; x++ {
|
||||
picture.SetRGBA(x, y, color.RGBA{uint8(30 + x/4), uint8(60 + y/3), uint8(180 + y/5), 255})
|
||||
}
|
||||
}
|
||||
var content bytes.Buffer
|
||||
if err := png.Encode(&content, picture); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
object, err := s.store.CreatePageAtPathInDomain(domain, "/wallpapers/test.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.SaveRevisionContent(object, content.Bytes(), "test", "und", "image/png", "test.png"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for k, v := range map[string]string{"home_layout": "directory", "home_wallpaper_path": "/wallpapers/test.png", "home_wallpaper_opacity": "70", "theme": "nanoha-dark"} {
|
||||
if err := s.store.SetConfigInDomain(domain, k, v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
script, err := os.ReadFile("internal/server/testdata/home-palette.js")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
handler := s.handler()
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.URL.Path == "/fixture" {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_, _ = w.Write([]byte("<!doctype html><body style='margin:0'><script>" + string(script) + "</script></body>"))
|
||||
return
|
||||
}
|
||||
handler.ServeHTTP(w, r)
|
||||
}))
|
||||
defer server.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 55*time.Second)
|
||||
defer cancel()
|
||||
width := os.Getenv("HOME_PALETTE_WIDTH")
|
||||
if width == "" {
|
||||
width = "1440"
|
||||
}
|
||||
args := []string{"internal/server/testdata/vim-browser-smoke.mjs", server.URL + "/fixture", t.TempDir(), os.Getenv("HOME_PALETTE_SCREENSHOT"), width, "850"}
|
||||
if out, err := exec.CommandContext(ctx, "node", args...).CombinedOutput(); err != nil {
|
||||
t.Fatalf("palette: %v\n%s", err, out)
|
||||
}
|
||||
if p := s.homePalette(domain); p.Mode != "accent" || p.Strength != 70 || p.Brightness != "auto" {
|
||||
t.Fatalf("browser save not persisted: %+v", p)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ type homeWallpaperView struct {
|
||||
Path string
|
||||
URL string
|
||||
Opacity string
|
||||
Key string
|
||||
}
|
||||
|
||||
// configuredLoginWallpaper returns only the image selected by the Domain
|
||||
@@ -143,7 +144,8 @@ func (s *Server) homeWallpaperForRequest(r *http.Request) homeWallpaperView {
|
||||
httpRequest := r
|
||||
if objectUUID, err := s.store.ResolvePathInDomain(domainUUID, configured); err == nil && s.requestCanReadPath(httpRequest, configured) {
|
||||
if revision, err := s.latestRevisionMetadataForRequest(httpRequest, objectUUID); err == nil && imageContentType(revision.ContentType) {
|
||||
view.URL = rawProjectionURL("path:" + configured)
|
||||
view.URL = rawProjectionURL("rev:" + revision.UUID)
|
||||
view.Key = revision.DocumentHash
|
||||
return view
|
||||
}
|
||||
}
|
||||
@@ -165,6 +167,7 @@ func (s *Server) homeWallpaperForRequest(r *http.Request) homeWallpaperView {
|
||||
if value, err := rand.Int(rand.Reader, big.NewInt(int64(len(candidates)))); err == nil {
|
||||
index = int(value.Int64())
|
||||
}
|
||||
view.URL = rawProjectionURL("path:" + candidates[index].Path)
|
||||
view.URL = rawProjectionURL("rev:" + candidates[index].RevisionUUID)
|
||||
view.Key = candidates[index].DocumentHash
|
||||
return view
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func TestHomeWallpaperFolderPickerAndTheme(t *testing.T) {
|
||||
r := httptest.NewRequest(http.MethodGet, "http://localhost/", nil)
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
view := s.homeWallpaperForRequest(r)
|
||||
if view.Opacity != "0.41" || (view.URL != "/v/raw/path:/wallpapers/a.jpg" && view.URL != "/v/raw/path:/wallpapers/b.png") {
|
||||
if view.Opacity != "0.41" || !strings.HasPrefix(view.URL, "/v/raw/rev:") || len(view.Key) != 64 {
|
||||
t.Fatalf("view=%#v", view)
|
||||
}
|
||||
homeResponse := httptest.NewRecorder()
|
||||
|
||||
@@ -231,6 +231,15 @@ var translations = map[string]map[string]string{
|
||||
"home.wallpaper_opacity": "Wallpaper opacity (%)",
|
||||
"home.wallpaper_help": "Choose one image, or a folder whose direct image children are selected on each reload. Access permissions still apply.",
|
||||
"home.appearance": "Home appearance",
|
||||
"home.palette_mode": "Wallpaper color matching",
|
||||
"home.palette_off": "Off — use the selected theme",
|
||||
"home.palette_accent": "Accent only",
|
||||
"home.palette_surface": "Accent and surfaces",
|
||||
"home.palette_strength": "Color influence",
|
||||
"home.palette_brightness": "Light and dark",
|
||||
"home.palette_preserve": "Keep the current theme brightness",
|
||||
"home.palette_auto": "Choose from the displayed wallpaper",
|
||||
"home.palette_help": "Applies only to the home page and its dialogs. Warning colors are preserved. If extraction fails, the selected theme remains. Shared by this domain.",
|
||||
"home.glass_transparency": "Glass transparency (%)",
|
||||
"home.glass_help": "Controls the shared transparency of the home search, menus, suggestions, cards, and dialogs. Higher values are more transparent.",
|
||||
"picker.open": "Browse PagesWiki",
|
||||
@@ -1002,6 +1011,15 @@ var translations = map[string]map[string]string{
|
||||
"home.wallpaper_opacity": "壁紙の透明度(%)",
|
||||
"home.wallpaper_help": "画像を1つ選ぶか、直下の画像をリロードごとに選択するフォルダを指定します。閲覧権限はそのまま適用されます。",
|
||||
"home.appearance": "トップ画面の外観",
|
||||
"home.palette_mode": "壁紙との色連動",
|
||||
"home.palette_off": "オフ — 選択中のテーマを使用",
|
||||
"home.palette_accent": "アクセントのみ",
|
||||
"home.palette_surface": "背景も連動",
|
||||
"home.palette_strength": "色の反映量",
|
||||
"home.palette_brightness": "明暗",
|
||||
"home.palette_preserve": "現在のテーマの明暗を維持",
|
||||
"home.palette_auto": "表示中の壁紙から自動判定",
|
||||
"home.palette_help": "トップ画面とその上のダイアログにのみ適用します。警告色は変更しません。色を抽出できない場合は選択中のテーマを維持します。このドメインで共通の設定です。",
|
||||
"home.glass_transparency": "グラスの透明度(%)",
|
||||
"home.glass_help": "トップ画面の検索、メニュー、サジェスト、カード、ダイアログに共通の透明度です。数値を上げるほど背景が透けます。",
|
||||
"picker.open": "PagesWikiから選択",
|
||||
|
||||
@@ -93,6 +93,8 @@ func (s *Server) handleDashboardData(w http.ResponseWriter, r *http.Request, act
|
||||
|
||||
func organizerSection(path string) string {
|
||||
switch {
|
||||
case feedRoute(path):
|
||||
return "feeds"
|
||||
case path == "/v/plan/dashboard":
|
||||
return "dashboard"
|
||||
case strings.HasPrefix(path, "/-/sys/config"):
|
||||
@@ -108,6 +110,8 @@ func organizerSection(path string) string {
|
||||
}
|
||||
|
||||
func init() {
|
||||
translations["en"]["task.work_history"] = "Work history"
|
||||
translations["ja"]["task.work_history"] = "作業記録"
|
||||
for lang, entries := range map[string]map[string]string{
|
||||
"en": {"organizer.title": "Organizer", "organizer.dashboard": "Dashboard", "organizer.settings": "Personal settings", "organizer.contacts": "Contacts", "organizer.private": "Preferences apply only to you in this Domain. System administration is separate.", "organizer.calendar_defaults": "Default calendars", "organizer.open": "Open"},
|
||||
"ja": {"organizer.title": "オーガナイザー", "organizer.dashboard": "ダッシュボード", "organizer.settings": "個人設定", "organizer.contacts": "連絡先", "organizer.private": "このドメイン内の自分だけに適用する設定です。システムの管理設定とは別です。", "organizer.calendar_defaults": "既定のカレンダー", "organizer.open": "開く"},
|
||||
|
||||
@@ -68,6 +68,7 @@ func (s *Server) renderWithContext(
|
||||
data["CalendarEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.calendar")
|
||||
data["TasksEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.tasks")
|
||||
data["ContactsEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.contacts")
|
||||
data["FeedsEnabled"] = s.systemExtensionEnabled(domainUUID, "organizer.feeds")
|
||||
data["OrganizerSection"] = organizerSection(r.URL.Path)
|
||||
if r.URL.Path == "/" {
|
||||
data["IsHome"] = true
|
||||
@@ -84,6 +85,9 @@ func (s *Server) renderWithContext(
|
||||
wallpaper := s.homeWallpaperForRequest(r)
|
||||
data["HomeWallpaperURL"] = wallpaper.URL
|
||||
data["HomeWallpaperOpacity"] = wallpaper.Opacity
|
||||
data["HomeWallpaperKey"] = wallpaper.Key
|
||||
data["HomePalette"] = s.homePalette(domainUUID)
|
||||
data["HomePaletteDomain"] = domainUUID
|
||||
if wallpaper.URL != "" {
|
||||
w.Header().Set("Cache-Control", "private, no-cache")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -15,6 +17,7 @@ import (
|
||||
|
||||
func TestTaskMailWikiCapture(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
s.mux.HandleFunc("/v/raw/", s.handleRawView)
|
||||
ctx := context.Background()
|
||||
p, err := s.store.TaskPreferences(ctx, domain, actor)
|
||||
if err != nil {
|
||||
@@ -51,6 +54,29 @@ func TestTaskMailWikiCapture(t *testing.T) {
|
||||
if err != nil || !strings.Contains(rev.Body, "<script>bad()</script>") || strings.Contains(rev.Body, "{{children}}") {
|
||||
t.Fatal(rev, err)
|
||||
}
|
||||
// Existing Japanese paths are not renamed or broken by receipt replay.
|
||||
legacy := "/private/mail/日本語の件名 [list 123]--" + id
|
||||
if _, err = s.store.DB.Exec(`UPDATE paths SET path=? WHERE domain_uuid=? AND object_uuid=?`, legacy, domain, response.Item.PageUUID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
note := taskRequest(s, token, "GET", "items/"+id+"/note", nil, "")
|
||||
var links struct {
|
||||
URL string `json:"url"`
|
||||
}
|
||||
if err = json.Unmarshal(note.Body.Bytes(), &links); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
u, err := url.Parse(links.URL)
|
||||
if err != nil || u.Path != legacy || u.RawQuery != "" || u.Fragment != "" {
|
||||
t.Fatal("Japanese note URL", links.URL, err)
|
||||
}
|
||||
request := httptest.NewRequest("GET", "http://localhost/v/raw/path:"+links.URL, nil)
|
||||
request.Header.Set("Authorization", "Bearer "+token)
|
||||
rawResult := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(rawResult, request)
|
||||
if rawResult.Code != 200 || rawResult.Body.String() != rev.Body {
|
||||
t.Fatal("Japanese path fetch", rawResult.Code)
|
||||
}
|
||||
// A committed retry remains stable even if the preference changes.
|
||||
p, err = s.store.TaskPreferences(ctx, domain, actor)
|
||||
if err != nil {
|
||||
@@ -63,6 +89,9 @@ func TestTaskMailWikiCapture(t *testing.T) {
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 || !strings.Contains(w.Body.String(), response.Item.PageUUID) {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if !strings.Contains(w.Body.String(), legacy) {
|
||||
t.Fatal("retry changed existing path", w.Body)
|
||||
}
|
||||
input["wiki_body"] = "different"
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 412 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
@@ -74,6 +103,18 @@ func TestTaskMailWikiCapture(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMailWikiPathDoesNotContainSubject(t *testing.T) {
|
||||
id := uuid.NewString()
|
||||
for _, title := range []string{"日本語", "[hogehoge 123] 件名", strings.Repeat("長い", 100), "?#/\\% []"} {
|
||||
if got := store.TaskCaptureWikiPath("/mail", title, id); got != "/mail/mail-"+id {
|
||||
t.Fatal(got)
|
||||
}
|
||||
}
|
||||
if store.TaskCaptureWikiPath("/mail", "日本語", uuid.NewString()) == store.TaskCaptureWikiPath("/mail", "日本語", id) {
|
||||
t.Fatal("different mails collided")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskMailWikiRollbackAndAccess(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -16,6 +16,7 @@ func TestTaskCLIHTTPIntegration(t *testing.T) {
|
||||
t.Skip("python3 not installed")
|
||||
}
|
||||
s, token, _, _ := taskFixture(t)
|
||||
s.mux.HandleFunc("/v/raw/", s.handleRawView)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
|
||||
@@ -38,67 +38,110 @@ func sendTaskDigestSMTP(ctx context.Context, config store.AuthProviderConfig, re
|
||||
func (s *Server) deliverTaskDigests(ctx context.Context, job *store.EventJob) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
if _, err := s.store.MaintainTaskDigests(ctx, time.Now()); err != nil {
|
||||
return err
|
||||
}
|
||||
queued, err := s.store.QueuedTaskDigests(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
due, err := s.store.DueTaskDigests(ctx, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sent, uncertain := 0, 0
|
||||
for _, candidate := range due {
|
||||
sent, uncertain, checked := 0, 0, 0
|
||||
deliver := func(claim store.TaskDigestClaim) error {
|
||||
state, reason := s.deliverTaskDigest(ctx, claim)
|
||||
if state == "sent" {
|
||||
sent++
|
||||
}
|
||||
if state == "uncertain" {
|
||||
uncertain++
|
||||
}
|
||||
checked++
|
||||
finish, stop := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer stop()
|
||||
err := s.store.FinishTaskDigestReason(finish, claim, state, reason, time.Now())
|
||||
// A reclaimed generation cannot complete a newer attempt.
|
||||
if errors.Is(err, store.ErrTaskConflict) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
// Alternate automatic delivery and manual retries within the shared time
|
||||
// budget, so a retry backlog cannot monopolize scheduled deliveries.
|
||||
for i := 0; i < max(len(due), len(queued)); i++ {
|
||||
for _, manual := range []bool{false, true} {
|
||||
if ctx.Err() != nil {
|
||||
break
|
||||
}
|
||||
var claim store.TaskDigestClaim
|
||||
var e error
|
||||
if manual {
|
||||
if i >= len(queued) {
|
||||
continue
|
||||
}
|
||||
claim, e = s.store.ClaimQueuedTaskDigest(ctx, queued[i], time.Now())
|
||||
} else {
|
||||
if i >= len(due) {
|
||||
continue
|
||||
}
|
||||
claim, e = s.store.ClaimTaskDigest(ctx, due[i], time.Now())
|
||||
}
|
||||
if errors.Is(e, sql.ErrNoRows) {
|
||||
continue
|
||||
}
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if e = deliver(claim); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
break
|
||||
}
|
||||
claim, e := s.store.ClaimTaskDigest(ctx, candidate, time.Now())
|
||||
if errors.Is(e, sql.ErrNoRows) {
|
||||
continue
|
||||
}
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
state := "cancelled"
|
||||
if s.systemExtensionEnabled(claim.Domain, "organizer.tasks") {
|
||||
config, e := s.store.AuthProviderConfig(claim.Domain, "smtp")
|
||||
if e == nil && config.Enabled {
|
||||
items, next, e := s.store.ListTasks(ctx, claim.Domain, claim.Owner, store.TaskQuery{Kind: "task", View: "today", Today: claim.Day, Limit: 100})
|
||||
if e == nil {
|
||||
var body strings.Builder
|
||||
host, _ := s.store.GetDomainEffectiveHost(claim.Domain)
|
||||
base := ""
|
||||
if host != "" && !strings.ContainsAny(host, "/\\\r\n\t @") {
|
||||
base = "https://" + host
|
||||
}
|
||||
fmt.Fprintf(&body, "Tasks / やることリスト — %s (%s)\n\n", claim.Day, claim.Timezone)
|
||||
if len(items) == 0 {
|
||||
body.WriteString("No tasks due or planned today. / 今日の対象タスクはありません。\n")
|
||||
}
|
||||
for _, item := range items {
|
||||
fmt.Fprintf(&body, "- %s\n due/期限: %s | planned/予定: %s | estimate/見積: %d min\n %s/v/plan/task/%s\n", item.Title, item.DueOn, item.PlannedOn, item.Estimate, base, item.UUID)
|
||||
}
|
||||
if next != "" {
|
||||
body.WriteString("\nFirst 100 items only. / 最初の100件です。続きはタスク画面で確認してください。\n")
|
||||
}
|
||||
// Check consent and current account email immediately before send.
|
||||
if recipient, e := s.store.TaskDigestRecipient(ctx, claim); e == nil {
|
||||
state = "uncertain"
|
||||
if e = sendTaskDigestSMTP(ctx, config, recipient, claim.Day, body.String()); e == nil {
|
||||
state = "sent"
|
||||
sent++
|
||||
} else {
|
||||
uncertain++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Persist delivery outcome even if the scheduler context was cancelled.
|
||||
finish, stop := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
e = s.store.FinishTaskDigest(finish, claim, state)
|
||||
stop()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
if len(due) > 0 {
|
||||
s.addEventProgressLog(ctx, job, fmt.Sprintf("task digest checked=%d sent=%d uncertain=%d", len(due), sent, uncertain))
|
||||
if checked > 0 {
|
||||
s.addEventProgressLog(ctx, job, fmt.Sprintf("task digest checked=%d sent=%d uncertain=%d", checked, sent, uncertain))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) deliverTaskDigest(ctx context.Context, claim store.TaskDigestClaim) (string, string) {
|
||||
if !s.systemExtensionEnabled(claim.Domain, "organizer.tasks") {
|
||||
return "cancelled", "extension_disabled"
|
||||
}
|
||||
config, err := s.store.AuthProviderConfig(claim.Domain, "smtp")
|
||||
if err != nil || !config.Enabled {
|
||||
return "cancelled", "smtp_unavailable"
|
||||
}
|
||||
items, next, err := s.store.ListTasks(ctx, claim.Domain, claim.Owner, store.TaskQuery{Kind: "task", View: "today", Today: claim.Day, Limit: 100})
|
||||
if err != nil {
|
||||
return "cancelled", "tasks_unavailable"
|
||||
}
|
||||
var body strings.Builder
|
||||
host, _ := s.store.GetDomainEffectiveHost(claim.Domain)
|
||||
base := ""
|
||||
if host != "" && !strings.ContainsAny(host, "/\\\r\n\t @") {
|
||||
base = "https://" + host
|
||||
}
|
||||
fmt.Fprintf(&body, "Tasks / やることリスト — %s (%s)\n\n", claim.Day, claim.Timezone)
|
||||
if len(items) == 0 {
|
||||
body.WriteString("No tasks due or planned today. / 今日の対象タスクはありません。\n")
|
||||
}
|
||||
for _, item := range items {
|
||||
fmt.Fprintf(&body, "- %s\n due/期限: %s | planned/予定: %s | estimate/見積: %d min\n %s/v/plan/task/%s\n", item.Title, item.DueOn, item.PlannedOn, item.Estimate, base, item.UUID)
|
||||
}
|
||||
if next != "" {
|
||||
body.WriteString("\nFirst 100 items only. / 最初の100件です。続きはタスク画面で確認してください。\n")
|
||||
}
|
||||
recipient, err := s.store.TaskDigestRecipient(ctx, claim)
|
||||
if err != nil {
|
||||
return "cancelled", "consent_changed"
|
||||
}
|
||||
if err = sendTaskDigestSMTP(ctx, config, recipient, claim.Day, body.String()); err != nil {
|
||||
return "uncertain", "transport_uncertain"
|
||||
}
|
||||
return "sent", ""
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func (s *Server) handleTaskDigestHistory(w http.ResponseWriter, r *http.Request, actor string, active bool, parts []string) {
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
if len(parts) == 1 && r.Method == "GET" {
|
||||
limit := 50
|
||||
if raw := r.URL.Query().Get("limit"); raw != "" {
|
||||
v, e := strconv.Atoi(raw)
|
||||
if e != nil {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
limit = v
|
||||
}
|
||||
result, err := s.store.TaskDigestHistory(r.Context(), domain, actor, r.URL.Query().Get("after"), limit, time.Now())
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, result)
|
||||
return
|
||||
}
|
||||
if len(parts) == 2 && parts[1] == "retry" && r.Method == "POST" {
|
||||
if !active {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
var input store.TaskDigestRetry
|
||||
if !taskJSON(w, r, &input) {
|
||||
return
|
||||
}
|
||||
if id, err := s.store.TaskDigestRetryReceipt(r.Context(), domain, actor, input); err == nil {
|
||||
writeEventJSON(w, 202, map[string]string{"request_id": id})
|
||||
return
|
||||
} else if !errors.Is(err, sql.ErrNoRows) {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
principal, err := s.store.PrincipalForSession(domain, s.authTokenFromRequest(r))
|
||||
if err != nil {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
if _, err = smtpMailbox(principal.Email); err != nil {
|
||||
writeEventJSON(w, 422, map[string]string{"error": "email_required"})
|
||||
return
|
||||
}
|
||||
config, err := s.store.AuthProviderConfig(domain, "smtp")
|
||||
if err != nil || !config.Enabled {
|
||||
writeEventJSON(w, 422, map[string]string{"error": "smtp_unavailable"})
|
||||
return
|
||||
}
|
||||
id, err := s.store.QueueTaskDigestRetry(r.Context(), domain, actor, input, time.Now())
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 202, map[string]string{"request_id": id})
|
||||
return
|
||||
}
|
||||
if len(parts) == 1 {
|
||||
w.Header().Set("Allow", "GET")
|
||||
w.WriteHeader(405)
|
||||
return
|
||||
}
|
||||
if len(parts) == 2 && parts[1] == "retry" {
|
||||
w.Header().Set("Allow", "POST")
|
||||
w.WriteHeader(405)
|
||||
return
|
||||
}
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
@@ -0,0 +1,447 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func digestHistoryFixture(t *testing.T) (*Server, string, string, string, time.Time, store.TaskDigestClaim) {
|
||||
t.Helper()
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
now := time.Now().UTC()
|
||||
p := store.TaskPreferences{Complexity: 1, DigestEnabled: true, DigestTime: "00:00", Timezone: "UTC"}
|
||||
if _, err := s.store.SaveTaskPreferences(ctx, domain, actor, p, now.Add(-24*time.Hour)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`UPDATE principals SET email='reader@example.test' WHERE uuid=?`, actor); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.store.SetAuthProviderConfig(domain, store.AuthProviderConfig{Kind: "smtp", Enabled: true, SMTPAddress: "127.0.0.1:1", SMTPFrom: "wiki@example.test"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c, err := s.store.ClaimTaskDigest(ctx, store.TaskDigestDue{Domain: domain, Owner: actor}, now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return s, token, domain, actor, now, c
|
||||
}
|
||||
|
||||
func TestTaskDigestHistoryRetryGenerationAndConsent(t *testing.T) {
|
||||
s, token, domain, actor, now, c := digestHistoryFixture(t)
|
||||
ctx := context.Background()
|
||||
if recipient, err := s.store.TaskDigestRecipient(ctx, c); err != nil || recipient != "reader@example.test" {
|
||||
t.Fatal(recipient, err)
|
||||
}
|
||||
input := store.TaskDigestRetry{RequestID: uuid.NewString(), Day: c.Day, ExpectedAttempt: c.AttemptUUID}
|
||||
post := func(v store.TaskDigestRetry) int {
|
||||
return taskRequest(s, token, "POST", "digest-history/retry", v, "").Code
|
||||
}
|
||||
if got := post(input); got != 412 {
|
||||
t.Fatal("retried active delivery", got)
|
||||
}
|
||||
if err := s.store.FinishTaskDigest(ctx, c, "sent"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := post(input); got != 422 {
|
||||
t.Fatal("missing duplicate acknowledgment", got)
|
||||
}
|
||||
input.DuplicateAcknowledged = true
|
||||
var wg sync.WaitGroup
|
||||
results := make(chan int, 2)
|
||||
for range 2 {
|
||||
wg.Add(1)
|
||||
go func() { defer wg.Done(); results <- post(input) }()
|
||||
}
|
||||
wg.Wait()
|
||||
close(results)
|
||||
for code := range results {
|
||||
if code != 202 {
|
||||
t.Fatal("idempotent retry", code)
|
||||
}
|
||||
}
|
||||
q, err := s.store.QueuedTaskDigests(ctx)
|
||||
if err != nil || len(q) != 1 || q[0].AttemptUUID != input.RequestID {
|
||||
t.Fatal(q, err)
|
||||
}
|
||||
if err = s.store.SetAuthProviderConfig(domain, store.AuthProviderConfig{Kind: "smtp", Enabled: false, SMTPAddress: "127.0.0.1:1", SMTPFrom: "wiki@example.test"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := post(input); got != 202 {
|
||||
t.Fatal("accepted receipt lost after SMTP disabled", got)
|
||||
}
|
||||
if err = s.store.SetAuthProviderConfig(domain, store.AuthProviderConfig{Kind: "smtp", Enabled: true, SMTPAddress: "127.0.0.1:1", SMTPFrom: "wiki@example.test"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
changed := input
|
||||
changed.DuplicateAcknowledged = false
|
||||
if got := post(changed); got != 412 {
|
||||
t.Fatal("changed replay", got)
|
||||
}
|
||||
changed = input
|
||||
changed.RequestID = uuid.NewString()
|
||||
if got := post(changed); got != 412 {
|
||||
t.Fatal("second queued request", got)
|
||||
}
|
||||
newClaim, err := s.store.ClaimQueuedTaskDigest(ctx, q[0], now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.ClaimQueuedTaskDigest(ctx, q[0], now); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("double claim", err)
|
||||
}
|
||||
if err = s.store.FinishTaskDigest(ctx, c, "cancelled"); !errors.Is(err, store.ErrTaskConflict) {
|
||||
t.Fatal("old generation finished new attempt", err)
|
||||
}
|
||||
if _, err = s.store.TaskDigestRecipient(ctx, c); err == nil {
|
||||
t.Fatal("old generation can send")
|
||||
}
|
||||
if _, err = s.store.TaskDigestRecipient(ctx, newClaim); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, err := s.store.TaskPreferences(ctx, domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.DigestEnabled = false
|
||||
if _, err = s.store.SaveTaskPreferences(ctx, domain, actor, p, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.TaskDigestRecipient(ctx, newClaim); err == nil {
|
||||
t.Fatal("opt out ignored")
|
||||
}
|
||||
if err = s.store.FinishTaskDigestReason(ctx, newClaim, "cancelled", "consent_changed", now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := taskRequest(s, token, "GET", "digest-history?limit=1", nil, "")
|
||||
if w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
var page store.TaskDigestHistory
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &page); err != nil || len(page.Items) != 1 || page.Next == "" || page.Retries != 1 || page.Current.UUID != input.RequestID {
|
||||
t.Fatal(page, err)
|
||||
}
|
||||
w = taskRequest(s, token, "GET", "digest-history?limit=1&after="+page.Next, nil, "")
|
||||
if w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
for _, suffix := range []string{"?limit=101", "?after=bad", "?limit=NaN"} {
|
||||
if w = taskRequest(s, token, "GET", "digest-history"+suffix, nil, ""); w.Code != 422 {
|
||||
t.Fatal(suffix, w.Code)
|
||||
}
|
||||
}
|
||||
if strings.Contains(w.Body.String(), "reader@example.test") {
|
||||
t.Fatal("email in history")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDigestHistoryQueueExpiryAndPermissions(t *testing.T) {
|
||||
for _, change := range []string{"preference", "extension", "suspended", "tomorrow"} {
|
||||
t.Run(change, func(t *testing.T) {
|
||||
s, _, domain, actor, now, c := digestHistoryFixture(t)
|
||||
ctx := context.Background()
|
||||
if err := s.store.FinishTaskDigest(ctx, c, "cancelled"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
input := store.TaskDigestRetry{RequestID: uuid.NewString(), Day: c.Day, ExpectedAttempt: c.AttemptUUID}
|
||||
if _, err := s.store.QueueTaskDigestRetry(ctx, domain, actor, input, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
q, err := s.store.QueuedTaskDigests(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
switch change {
|
||||
case "preference":
|
||||
p, e := s.store.TaskPreferences(ctx, domain, actor)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
p.Estimate++
|
||||
_, err = s.store.SaveTaskPreferences(ctx, domain, actor, p, now)
|
||||
case "extension":
|
||||
err = s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":false}`)
|
||||
case "suspended":
|
||||
_, err = s.store.DB.Exec(`UPDATE domain_memberships SET state='suspended' WHERE domain_uuid=? AND principal_uuid=?`, domain, actor)
|
||||
case "tomorrow":
|
||||
now = now.Add(24 * time.Hour)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.ClaimQueuedTaskDigest(ctx, q[0], now); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("cancelled queue returned live claim", err)
|
||||
}
|
||||
var state string
|
||||
if err = s.store.DB.QueryRow(`SELECT state FROM organizer_digest_attempts WHERE uuid=?`, input.RequestID).Scan(&state); err != nil || state != "cancelled" {
|
||||
t.Fatal(state, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
s, token, domain, actor, now, c := digestHistoryFixture(t)
|
||||
ctx := context.Background()
|
||||
if err := s.store.FinishTaskDigest(ctx, c, "cancelled"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other, err := s.store.CreatePasswordAccount(domain, "digest-other", "a long test password", "Other", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
otherToken, err := s.store.CreateAuthSession(domain, other.UUID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := taskRequest(s, otherToken, "GET", "digest-history", nil, "")
|
||||
if w.Code != 200 || !strings.Contains(w.Body.String(), `"items":[]`) {
|
||||
t.Fatal("history privacy", w.Code, w.Body)
|
||||
}
|
||||
input := store.TaskDigestRetry{RequestID: uuid.NewString(), Day: c.Day, ExpectedAttempt: c.AttemptUUID}
|
||||
if _, err = s.store.QueueTaskDigestRetry(ctx, domain, other.UUID, input, now); err == nil {
|
||||
t.Fatal("retried other's mail")
|
||||
}
|
||||
if err = s.store.SetPrincipalState(domain, actor, "readonly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, err = s.store.CreateAuthSession(domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w = taskRequest(s, token, "POST", "digest-history/retry", input, ""); w.Code != 403 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w = taskRequest(s, token, "GET", "digest-history", nil, ""); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w = taskRequest(s, "", "GET", "digest-history", nil, ""); w.Code == 200 {
|
||||
t.Fatal("anonymous history")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDigestHistoryRetentionAndStaleWorker(t *testing.T) {
|
||||
s, _, domain, actor, now, c := digestHistoryFixture(t)
|
||||
ctx := context.Background()
|
||||
// Keep synthetic stale-worker time within the same date even near midnight.
|
||||
now = time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, time.UTC)
|
||||
if _, err := s.store.DB.Exec(`UPDATE organizer_digest_attempts SET updated_ms=? WHERE uuid=?`, now.UnixMilli(), c.AttemptUUID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.MaintainTaskDigests(ctx, now.Add(11*time.Minute)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
page, err := s.store.TaskDigestHistory(ctx, domain, actor, "", 50, now)
|
||||
if err != nil || page.Current.State != "uncertain" {
|
||||
t.Fatal(page, err)
|
||||
}
|
||||
input := store.TaskDigestRetry{RequestID: uuid.NewString(), Day: c.Day, ExpectedAttempt: c.AttemptUUID, DuplicateAcknowledged: true}
|
||||
if _, err = s.store.QueueTaskDigestRetry(ctx, domain, actor, input, now.Add(12*time.Minute)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
q, err := s.store.QueuedTaskDigests(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
claim, err := s.store.ClaimQueuedTaskDigest(ctx, q[0], now.Add(12*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.FinishTaskDigest(ctx, c, "sent"); !errors.Is(err, store.ErrTaskConflict) {
|
||||
t.Fatal("stale completion", err)
|
||||
}
|
||||
if err = s.store.FinishTaskDigestReason(ctx, claim, "sent", "", now.Add(12*time.Minute)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
deleted, err := s.store.MaintainTaskDigests(ctx, now.Add(91*24*time.Hour))
|
||||
if err != nil || deleted != 2 {
|
||||
t.Fatal("retention", deleted, err)
|
||||
}
|
||||
var reservations, receipts int
|
||||
if err = s.store.DB.QueryRow(`SELECT count(*) FROM organizer_digest_deliveries WHERE domain_uuid=? AND owner_uuid=?`, domain, actor).Scan(&reservations); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.DB.QueryRow(`SELECT count(*) FROM organizer_digest_requests WHERE domain_uuid=? AND owner_uuid=?`, domain, actor).Scan(&receipts); err != nil || reservations != 1 || receipts != 1 {
|
||||
t.Fatal("deduplication lost", reservations, receipts, err)
|
||||
}
|
||||
// Even an old request replay after retention returns its receipt without requeueing.
|
||||
if id, err := s.store.QueueTaskDigestRetry(ctx, domain, actor, input, now.Add(91*24*time.Hour)); err != nil || id != input.RequestID {
|
||||
t.Fatal(id, err)
|
||||
}
|
||||
q, err = s.store.QueuedTaskDigests(ctx)
|
||||
if err != nil || len(q) != 0 {
|
||||
t.Fatal("retention resurrected mail", q, err)
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`UPDATE organizer_task_preferences SET next_digest_ms=? WHERE domain_uuid=? AND owner_uuid=?`, now.Add(-time.Minute).UnixMilli(), domain, actor); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.ClaimTaskDigest(ctx, store.TaskDigestDue{Domain: domain, Owner: actor}, now); !errors.Is(err, sql.ErrNoRows) {
|
||||
t.Fatal("reservation lost", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDigestHistorySMTPWorker(t *testing.T) {
|
||||
s, _, domain, actor, now, c := digestHistoryFixture(t)
|
||||
ctx := context.Background()
|
||||
if err := s.store.FinishTaskDigest(ctx, c, "cancelled"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
input := store.TaskDigestRetry{RequestID: uuid.NewString(), Day: c.Day, ExpectedAttempt: c.AttemptUUID}
|
||||
if _, err := s.store.QueueTaskDigestRetry(ctx, domain, actor, input, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
address, _, done := fakeSMTP(t, "", false)
|
||||
if err := s.store.SetAuthProviderConfig(domain, store.AuthProviderConfig{Kind: "smtp", Enabled: true, SMTPAddress: address, SMTPFrom: "wiki@example.test"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.deliverTaskDigests(ctx, &store.EventJob{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
delivery := <-done
|
||||
if !strings.Contains(delivery.message, "Subject: PagesWiki tasks "+c.Day) {
|
||||
t.Fatal("message missing")
|
||||
}
|
||||
page, err := s.store.TaskDigestHistory(ctx, domain, actor, "", 50, now)
|
||||
if err != nil || page.Current.State != "sent" || len(page.Items) != 2 {
|
||||
t.Fatal(page, err)
|
||||
}
|
||||
if err := s.deliverTaskDigests(ctx, &store.EventJob{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDigestHistoryLimitsAndAtomicQueue(t *testing.T) {
|
||||
s, _, domain, actor, now, c := digestHistoryFixture(t)
|
||||
ctx := context.Background()
|
||||
if err := s.store.FinishTaskDigest(ctx, c, "cancelled"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
input := store.TaskDigestRetry{RequestID: uuid.NewString(), Day: c.Day, ExpectedAttempt: c.AttemptUUID}
|
||||
if _, err := s.store.DB.Exec(`CREATE TRIGGER fail_digest_queue BEFORE INSERT ON organizer_digest_attempts WHEN NEW.kind='manual' BEGIN SELECT RAISE(ABORT,'test queue failure'); END`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.QueueTaskDigestRetry(ctx, domain, actor, input, now); err == nil {
|
||||
t.Fatal("injected failure ignored")
|
||||
}
|
||||
var count int
|
||||
if err := s.store.DB.QueryRow(`SELECT count(*) FROM organizer_digest_requests`).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatal("partial receipt", count, err)
|
||||
}
|
||||
if _, err := s.store.DB.Exec(`DROP TRIGGER fail_digest_queue`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i := 0; i < 5; i++ {
|
||||
input.RequestID = uuid.NewString()
|
||||
if _, err := s.store.QueueTaskDigestRetry(ctx, domain, actor, input, now); err != nil {
|
||||
t.Fatal(i, err)
|
||||
}
|
||||
q, err := s.store.QueuedTaskDigests(ctx)
|
||||
if err != nil || len(q) != 1 {
|
||||
t.Fatal(q, err)
|
||||
}
|
||||
claim, err := s.store.ClaimQueuedTaskDigest(ctx, q[0], now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.FinishTaskDigest(ctx, claim, "cancelled"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
input.ExpectedAttempt = claim.AttemptUUID
|
||||
}
|
||||
input.RequestID = uuid.NewString()
|
||||
if _, err := s.store.QueueTaskDigestRetry(ctx, domain, actor, input, now); !errors.Is(err, store.ErrTaskConflict) {
|
||||
t.Fatal("retry cap", err)
|
||||
}
|
||||
input.Day = now.AddDate(0, 0, -1).Format("2006-01-02")
|
||||
if _, err := s.store.QueueTaskDigestRetry(ctx, domain, actor, input, now); !errors.Is(err, store.ErrTaskInvalid) {
|
||||
t.Fatal("past day accepted", err)
|
||||
}
|
||||
// A bounded retention pass leaves queued rows and durable guards untouched.
|
||||
_, err := s.store.DB.Exec(`WITH RECURSIVE n(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM n WHERE i<501) INSERT INTO organizer_digest_attempts SELECT 'old-'||i,'d','u','2000-01-01','scheduled','sent',1,'UTC','',1,1 FROM n`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
deleted, err := s.store.MaintainTaskDigests(ctx, now)
|
||||
if err != nil || deleted != 500 {
|
||||
t.Fatal("unbounded retention", deleted, err)
|
||||
}
|
||||
if err = s.store.DB.QueryRow(`SELECT count(*) FROM organizer_digest_attempts WHERE uuid LIKE 'old-%'`).Scan(&count); err != nil || count != 1 {
|
||||
t.Fatal(count, err)
|
||||
}
|
||||
var integrity string
|
||||
if err = s.store.DB.QueryRow(`PRAGMA integrity_check`).Scan(&integrity); err != nil || integrity != "ok" {
|
||||
t.Fatal(integrity, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskDigestHistoryChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
s, token, domain, actor, now, c := digestHistoryFixture(t)
|
||||
s.store.BackgroundJobsDisabled = true
|
||||
s = New(s.store)
|
||||
if err := s.store.FinishTaskDigest(context.Background(), c, "uncertain"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
address, _, done := fakeSMTP(t, "", false)
|
||||
if err := s.store.SetAuthProviderConfig(domain, store.AuthProviderConfig{Kind: "smtp", Enabled: true, SMTPAddress: address, SMTPFrom: "wiki@example.test"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
script, err := os.ReadFile("internal/server/testdata/task-digest-history.js")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
handler := s.handler()
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.URL.Path == "/fixture" {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_, _ = w.Write([]byte("<!doctype html><body style='margin:0'><script>" + string(script) + "</script></body>"))
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/fixture/tick" && r.Method == "POST" {
|
||||
if e := s.deliverTaskDigests(r.Context(), &store.EventJob{}); e != nil {
|
||||
http.Error(w, "worker failed", 500)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(204)
|
||||
return
|
||||
}
|
||||
handler.ServeHTTP(w, r)
|
||||
}))
|
||||
defer server.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 55*time.Second)
|
||||
defer cancel()
|
||||
width := os.Getenv("DIGEST_HISTORY_WIDTH")
|
||||
if width == "" {
|
||||
width = "1440"
|
||||
}
|
||||
args := []string{"internal/server/testdata/vim-browser-smoke.mjs", server.URL + "/fixture", t.TempDir(), os.Getenv("DIGEST_HISTORY_SCREENSHOT"), width, "850"}
|
||||
if out, err := exec.CommandContext(ctx, "node", args...).CombinedOutput(); err != nil {
|
||||
t.Fatalf("browser: %v\n%s", err, out)
|
||||
}
|
||||
select {
|
||||
case delivery := <-done:
|
||||
if !strings.Contains(delivery.message, "Subject: PagesWiki tasks "+c.Day) {
|
||||
t.Fatal("mail missing")
|
||||
}
|
||||
case <-ctx.Done():
|
||||
t.Fatal("SMTP not observed")
|
||||
}
|
||||
page, err := s.store.TaskDigestHistory(context.Background(), domain, actor, "", 50, now)
|
||||
if err != nil || page.Retries != 1 || len(page.Items) != 2 || page.Current.State != "sent" {
|
||||
t.Fatal(page, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func TestTaskMailLayouts(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
for _, suffix := range []string{"hogehoge/123", "v/0", "2026/01/" + uuid.NewString(), "2026/12/" + strings.Repeat("a", 64)} {
|
||||
id := uuid.NewString()
|
||||
input := map[string]any{"request_id": id, "title": "日本語の件名", "wiki_body": "Body", "wiki_prefix": "/mail", "wiki_suffix": suffix}
|
||||
w := taskRequest(s, token, "POST", "capture", input, "")
|
||||
if w.Code != 201 {
|
||||
t.Fatal(suffix, w.Code, w.Body)
|
||||
}
|
||||
var response struct {
|
||||
Path string `json:"page_path"`
|
||||
Item store.TaskRecord `json:"item"`
|
||||
}
|
||||
if e := json.Unmarshal(w.Body.Bytes(), &response); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if response.Path != "/mail/"+suffix {
|
||||
t.Fatal(response.Path)
|
||||
}
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 {
|
||||
t.Fatal("replay", w.Code, w.Body)
|
||||
}
|
||||
// A different Message-ID produces a different request UUID, never an overwrite.
|
||||
other := uuid.NewString()
|
||||
input["request_id"] = other
|
||||
input["wiki_body"] = "Different mail"
|
||||
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 409 {
|
||||
t.Fatal("collision", w.Code, w.Body)
|
||||
}
|
||||
if _, e := s.store.GetTask(context.Background(), domain, actor, other); !errors.Is(e, sql.ErrNoRows) {
|
||||
t.Fatal("partial task", e)
|
||||
}
|
||||
rev, e := s.store.GetLatestRevision(response.Item.PageUUID)
|
||||
if e != nil || strings.Contains(rev.Body, "Different") {
|
||||
t.Fatal("page overwritten", e)
|
||||
}
|
||||
}
|
||||
for _, suffix := range []string{"", "../123", "/list/123", "a/../../123", "list/001", "list/-1", "list/1?x", "list%2f/1", "list/1/2", "_/123", "2026/13/" + uuid.NewString(), "0000/01/" + uuid.NewString(), "2026/01/not-an-id"} {
|
||||
input := map[string]any{"request_id": uuid.NewString(), "title": "Bad", "wiki_body": "Body", "wiki_prefix": "/mail", "wiki_suffix": suffix}
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 422 {
|
||||
t.Fatal(suffix, w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
input := map[string]any{"request_id": uuid.NewString(), "title": "No body", "wiki_suffix": "list/123"}
|
||||
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 422 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
other, e := s.store.CreatePasswordAccount(domain, "mail-layout-other", "fixture password long", "Other", "")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
otherToken, e := s.store.CreateAuthSession(domain, other.UUID)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
input = map[string]any{"request_id": uuid.NewString(), "title": "No Wiki permission", "wiki_body": "Body", "wiki_prefix": "/mail", "wiki_suffix": "private/123"}
|
||||
if w := taskRequest(s, otherToken, "POST", "capture", input, ""); w.Code != 403 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ type taskCaptureInput struct {
|
||||
Complexity *int `json:"complexity"`
|
||||
WikiBody *string `json:"wiki_body,omitempty"`
|
||||
WikiPrefix *string `json:"wiki_prefix,omitempty"`
|
||||
WikiSuffix *string `json:"wiki_suffix,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request, actor string, active bool, kind string) {
|
||||
@@ -260,6 +261,13 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
return
|
||||
}
|
||||
target = store.TaskCaptureWikiPath(prefix, item.Title, input.RequestID)
|
||||
if input.WikiSuffix != nil {
|
||||
if !store.ValidTaskMailSuffix(*input.WikiSuffix) {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
target = strings.TrimRight(prefix, "/") + "/" + *input.WikiSuffix
|
||||
}
|
||||
for _, capability := range []string{"read", "create", "write"} {
|
||||
if s.authorizePathRequest(r, capability, target) != nil {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
@@ -267,7 +275,7 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
}
|
||||
body = *input.WikiBody
|
||||
} else if input.WikiPrefix != nil {
|
||||
} else if input.WikiPrefix != nil || input.WikiSuffix != nil {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
@@ -293,11 +301,24 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
|
||||
var input struct {
|
||||
store.TaskWork
|
||||
Action string `json:"action"`
|
||||
Reason string `json:"reason"`
|
||||
Start string `json:"start"`
|
||||
End string `json:"end"`
|
||||
}
|
||||
if !taskJSON(w, r, &input) {
|
||||
return
|
||||
}
|
||||
v, err := s.store.ChangeTaskWork(r.Context(), domain, actor, input.Action, input.TaskWork, time.Now())
|
||||
if input.Action == "correct" && (input.Start != "" || input.End != "") {
|
||||
a, e1 := parseWorkInstant(input.Start, s.getLocation(domain))
|
||||
b, e2 := parseWorkInstant(input.End, s.getLocation(domain))
|
||||
if e1 != nil || e2 != nil {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
input.StartMS = a.UnixMilli()
|
||||
input.EndMS = b.UnixMilli()
|
||||
}
|
||||
v, err := s.store.ChangeTaskWork(r.Context(), domain, actor, input.Action, input.TaskWork, time.Now(), input.Reason)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
|
||||
@@ -222,6 +222,9 @@ func TestTaskWorkReportSplitsMidnightAndCompletion(t *testing.T) {
|
||||
if err != nil || report.Days[0].Points != 7 || report.Days[0].Completed != 1 {
|
||||
t.Fatal("points", report, err)
|
||||
}
|
||||
if len(report.Projects) != 1 || report.Projects[0].UUID != "" || report.Projects[0].Points != 7 || report.Projects[0].Completed != 1 {
|
||||
t.Fatal("unassigned project totals", report.Projects)
|
||||
}
|
||||
item.Status = "todo"
|
||||
if _, err = s.store.SaveTask(ctx, domain, actor, item, item.Version); err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"pageswiki/internal/store"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func parseWorkInstant(raw string, loc *time.Location) (time.Time, error) {
|
||||
if v, err := time.Parse(time.RFC3339Nano, raw); err == nil {
|
||||
return v, nil
|
||||
}
|
||||
for _, format := range []string{"2006-01-02T15:04:05", "2006-01-02T15:04"} {
|
||||
v, err := time.ParseInLocation(format, raw, loc)
|
||||
if err != nil || v.Format(format) != raw {
|
||||
continue
|
||||
}
|
||||
// A repeated wall time needs an explicit offset. Do not silently choose
|
||||
// the earlier/later occurrence when a browser datetime-local cannot express it.
|
||||
for _, delta := range []time.Duration{-24 * time.Hour, -2 * time.Hour, -time.Hour, -30 * time.Minute, 30 * time.Minute, time.Hour, 2 * time.Hour, 24 * time.Hour} {
|
||||
if v.Add(delta).In(loc).Format(format) == raw {
|
||||
return time.Time{}, store.ErrTaskInvalid
|
||||
}
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
return time.Time{}, store.ErrTaskInvalid
|
||||
}
|
||||
|
||||
func (s *Server) handleTaskWorkHistory(w http.ResponseWriter, r *http.Request, actor string, parts []string) {
|
||||
if r.Method != "GET" {
|
||||
w.Header().Set("Allow", "GET")
|
||||
w.WriteHeader(405)
|
||||
return
|
||||
}
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
if len(parts) == 2 && parts[1] != "" {
|
||||
var before int64
|
||||
if raw := r.URL.Query().Get("before"); raw != "" {
|
||||
var err error
|
||||
before, err = strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || before < 0 {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
}
|
||||
items, err := s.store.TaskWorkRevisions(r.Context(), domain, actor, parts[1], before)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
var next int64
|
||||
if len(items) == 100 {
|
||||
next = items[len(items)-1].Item.Version
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"items": items, "next": next})
|
||||
return
|
||||
}
|
||||
if len(parts) != 1 {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
now := time.Now().In(s.getLocation(domain))
|
||||
end := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, now.Location())
|
||||
start := end.AddDate(0, 0, -30)
|
||||
for _, v := range []struct {
|
||||
key string
|
||||
target *time.Time
|
||||
}{{"from", &start}, {"to", &end}} {
|
||||
if raw := r.URL.Query().Get(v.key); raw != "" {
|
||||
date, err := time.ParseInLocation("2006-01-02", raw, now.Location())
|
||||
if err != nil || date.Format("2006-01-02") != raw {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
*v.target = date
|
||||
}
|
||||
}
|
||||
limit := 50
|
||||
if raw := r.URL.Query().Get("limit"); raw != "" {
|
||||
var err error
|
||||
limit, err = strconv.Atoi(raw)
|
||||
if err != nil {
|
||||
taskError(w, store.ErrTaskInvalid)
|
||||
return
|
||||
}
|
||||
}
|
||||
result, err := s.store.TaskWorkHistory(r.Context(), domain, actor, start, end, r.URL.Query().Get("after"), limit)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
writeEventJSON(w, 200, map[string]any{"items": result.Items, "next": result.Next, "from": start.Format("2006-01-02"), "to": end.Format("2006-01-02"), "timezone": now.Location().String()})
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func recordedWork(t *testing.T, s *Server, domain, actor, task string, start time.Time) store.TaskWork {
|
||||
t.Helper()
|
||||
v, err := s.store.ChangeTaskWork(context.Background(), domain, actor, "start", store.TaskWork{UUID: uuid.NewString(), TaskUUID: task, CancelledMS: 99}, start)
|
||||
if err != nil || v.CancelledMS != 0 {
|
||||
t.Fatal(v, err)
|
||||
}
|
||||
v, err = s.store.ChangeTaskWork(context.Background(), domain, actor, "stop", v, start.Add(time.Hour))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func TestWorkHistoryCorrectionCancellationAndReports(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
project, err := s.store.SaveTask(ctx, domain, actor, newTaskRecord("project", "Project A"), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
item := newTaskRecord("task", "Audited work")
|
||||
item.ProjectUUID = project.UUID
|
||||
item, err = s.store.SaveTask(ctx, domain, actor, item, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
start := time.Date(2026, 1, 2, 12, 0, 0, 0, time.UTC)
|
||||
first := recordedWork(t, s, domain, actor, item.UUID, start)
|
||||
second := recordedWork(t, s, domain, actor, item.UUID, start.Add(2*time.Hour))
|
||||
post := func(v store.TaskWork, action, reason string) int {
|
||||
return taskRequest(s, token, "POST", "work", map[string]any{"uuid": v.UUID, "task_uuid": v.TaskUUID, "version": v.Version, "action": action, "reason": reason, "start_ms": v.StartMS, "end_ms": v.EndMS}, "").Code
|
||||
}
|
||||
if got := post(first, "correct", ""); got != 422 {
|
||||
t.Fatal("missing reason", got)
|
||||
}
|
||||
bad := first
|
||||
bad.EndMS = second.EndMS
|
||||
if got := post(bad, "correct", "overlap"); got != 412 {
|
||||
t.Fatal("overlap", got)
|
||||
}
|
||||
bad = first
|
||||
bad.EndMS = bad.StartMS
|
||||
if got := post(bad, "correct", "empty"); got != 422 {
|
||||
t.Fatal("empty interval", got)
|
||||
}
|
||||
first.EndMS = start.Add(2 * time.Hour).UnixMilli() // adjacency is valid
|
||||
if got := post(first, "correct", "Finished later"); got != 200 {
|
||||
t.Fatal("correct", got)
|
||||
}
|
||||
if got := post(first, "correct", "stale mutation"); got != 412 {
|
||||
t.Fatal("stale version", got)
|
||||
}
|
||||
first.Version++
|
||||
report, err := s.store.TaskReport(ctx, domain, actor, start.Add(-time.Hour), start.Add(5*time.Hour), time.Now())
|
||||
if err != nil || len(report.Projects) != 1 || report.Projects[0].Title != "Project A" || report.Projects[0].WorkMS != 3*3600000 {
|
||||
t.Fatal(report, err)
|
||||
}
|
||||
if got := post(first, "cancel", "Duplicate recording"); got != 200 {
|
||||
t.Fatal("cancel", got)
|
||||
}
|
||||
report, err = s.store.TaskReport(ctx, domain, actor, start.Add(-time.Hour), start.Add(5*time.Hour), time.Now())
|
||||
if err != nil || report.Projects[0].WorkMS != 3600000 {
|
||||
t.Fatal("cancelled counted", report, err)
|
||||
}
|
||||
audit, err := s.store.TaskWorkRevisions(ctx, domain, actor, first.UUID, 0)
|
||||
if err != nil || len(audit) != 4 || audit[0].Action != "cancel" || audit[1].Action != "correct" || audit[2].Action != "stop" || audit[3].Action != "start" || audit[2].Item.EndMS != start.Add(time.Hour).UnixMilli() {
|
||||
t.Fatal(audit, err)
|
||||
}
|
||||
page, err := s.store.TaskWorkHistory(ctx, domain, actor, start.Add(-time.Hour), start.Add(5*time.Hour), "", 1)
|
||||
if err != nil || len(page.Items) != 1 || page.Items[0].UUID != second.UUID || page.Next == "" {
|
||||
t.Fatal(page, err)
|
||||
}
|
||||
page, err = s.store.TaskWorkHistory(ctx, domain, actor, start.Add(-time.Hour), start.Add(5*time.Hour), page.Next, 1)
|
||||
if err != nil || len(page.Items) != 1 || page.Items[0].UUID != first.UUID || page.Items[0].CancelledMS == 0 || page.Next != "" {
|
||||
t.Fatal(page, err)
|
||||
}
|
||||
for _, query := range []string{"limit=101", "after=bad", "from=2026-01-02&to=2026-01-01", "from=2020-01-01&to=2026-01-01"} {
|
||||
if w := taskRequest(s, token, "GET", "work-history?"+query, nil, ""); w.Code != 422 {
|
||||
t.Fatal(query, w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
if w := taskRequest(s, token, "GET", "work-history/"+first.UUID+"?before=3", nil, ""); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
if w := taskRequest(s, token, "POST", "work-history", nil, ""); w.Code != 405 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
stranger, err := s.store.CreatePasswordAccount(domain, "history-stranger", "a long test password", "Stranger", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
strangerToken, err := s.store.CreateAuthSession(domain, stranger.UUID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, strangerToken, "GET", "work-history/"+first.UUID, nil, ""); w.Code != 404 {
|
||||
t.Fatal("history leaked", w.Code, w.Body)
|
||||
}
|
||||
if w := taskRequest(s, strangerToken, "GET", "work-history?from=2026-01-01&to=2026-01-04", nil, ""); w.Code != 200 || !strings.Contains(w.Body.String(), `"items":[]`) {
|
||||
t.Fatal("list leaked", w.Code, w.Body)
|
||||
}
|
||||
if err = s.store.SetPrincipalState(domain, actor, "readonly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token, err = s.store.CreateAuthSession(domain, actor)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := post(second, "cancel", "No permission"); got != 403 {
|
||||
t.Fatal("readonly mutation", got)
|
||||
}
|
||||
if err = s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":false}`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if w := taskRequest(s, token, "GET", "work-history", nil, ""); w.Code != 404 {
|
||||
t.Fatal("disabled extension", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkInstantTimezone(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
zone, input string
|
||||
valid bool
|
||||
}{{"Asia/Tokyo", "2026-01-02T12:30", true}, {"America/New_York", "2026-03-08T02:30", false}, {"America/New_York", "2026-11-01T01:30", false}, {"America/New_York", "2026-11-01T01:30:00-04:00", true}, {"Australia/Lord_Howe", "2026-04-05T01:45", false}, {"UTC", "bad", false}} {
|
||||
loc, err := time.LoadLocation(tc.zone)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = parseWorkInstant(tc.input, loc)
|
||||
if (err == nil) != tc.valid {
|
||||
t.Fatal(tc, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkHistoryFencingAndAtomicAudit(t *testing.T) {
|
||||
s, _, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
item, err := s.store.SaveTask(ctx, domain, actor, newTaskRecord("task", "Fenced work"), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
start := time.Now().Add(-10 * time.Hour)
|
||||
v := recordedWork(t, s, domain, actor, item.UUID, start)
|
||||
// Simulate a pre-upgrade session: capture its old value, never invent older versions.
|
||||
if _, err = s.store.DB.Exec(`DELETE FROM organizer_work_revisions WHERE work_uuid=?`, v.UUID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`CREATE TRIGGER fail_work_audit BEFORE INSERT ON organizer_work_revisions WHEN NEW.action='correct' BEGIN SELECT RAISE(ABORT,'test audit unavailable'); END`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
edit := v
|
||||
edit.EndMS += 60000
|
||||
if _, err = s.store.ChangeTaskWork(ctx, domain, actor, "correct", edit, time.Now(), "must rollback"); err == nil {
|
||||
t.Fatal("audit failure accepted")
|
||||
}
|
||||
var version int64
|
||||
if err = s.store.DB.QueryRow(`SELECT version FROM organizer_work_sessions WHERE uuid=?`, v.UUID).Scan(&version); err != nil || version != 2 {
|
||||
t.Fatal("partial mutation", version, err)
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`DROP TRIGGER fail_work_audit`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Two concurrent corrections must not overwrite one another.
|
||||
var wg sync.WaitGroup
|
||||
results := make(chan error, 2)
|
||||
for range 2 {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
_, e := s.store.ChangeTaskWork(ctx, domain, actor, "correct", edit, time.Now(), "racing correction")
|
||||
results <- e
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
close(results)
|
||||
wins, conflicts := 0, 0
|
||||
for err := range results {
|
||||
if err == nil {
|
||||
wins++
|
||||
} else if errors.Is(err, store.ErrTaskConflict) {
|
||||
conflicts++
|
||||
} else {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if wins != 1 || conflicts != 1 {
|
||||
t.Fatal(wins, conflicts)
|
||||
}
|
||||
history, err := s.store.TaskWorkRevisions(ctx, domain, actor, v.UUID, 0)
|
||||
if err != nil || len(history) != 2 || history[1].Action != "baseline" || history[1].Item.EndMS != v.EndMS {
|
||||
t.Fatal(history, err)
|
||||
}
|
||||
// Cross-Domain intervals belong to the same person, but never appear in this list.
|
||||
d, err := s.store.GetDomainByUUID(domain)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.store.CreateDomain(d.CampusUUID, "work-other", "Other", "work-other", "local", "", "", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
domains, err := s.store.ListDomains()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other := ""
|
||||
for _, d := range domains {
|
||||
if d.Name == "work-other" {
|
||||
other = d.UUID
|
||||
}
|
||||
}
|
||||
if other == "" {
|
||||
t.Fatal("missing domain")
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`INSERT OR IGNORE INTO domain_memberships(uuid,domain_uuid,principal_uuid,state,created_at_ms) VALUES(?,?,?,'active',0)`, uuid.NewString(), other, actor); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
otherTask, err := s.store.SaveTask(ctx, other, actor, newTaskRecord("task", "Private other work"), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foreign := recordedWork(t, s, other, actor, otherTask.UUID, start.Add(2*time.Hour))
|
||||
edit = history[0].Item
|
||||
edit.EndMS = foreign.EndMS
|
||||
if _, err = s.store.ChangeTaskWork(ctx, domain, actor, "correct", edit, time.Now(), "overlaps other domain"); !errors.Is(err, store.ErrTaskConflict) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.TaskWorkRevisions(ctx, domain, actor, foreign.UUID, 0); err == nil {
|
||||
t.Fatal("cross-domain audit leaked")
|
||||
}
|
||||
page, err := s.store.TaskWorkHistory(ctx, domain, actor, start.Add(-time.Hour), time.Now(), "", 50)
|
||||
if err != nil || len(page.Items) != 1 {
|
||||
t.Fatal(page, err)
|
||||
}
|
||||
active, err := s.store.ChangeTaskWork(ctx, domain, actor, "start", store.TaskWork{UUID: uuid.NewString(), TaskUUID: item.UUID}, start.Add(5*time.Hour))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, action := range []string{"correct", "cancel"} {
|
||||
if _, err = s.store.ChangeTaskWork(ctx, domain, actor, action, active, time.Now(), "active recording"); !errors.Is(err, store.ErrTaskConflict) {
|
||||
t.Fatal(action, err)
|
||||
}
|
||||
}
|
||||
if _, err = s.store.DB.Exec(`UPDATE domain_memberships SET state='suspended' WHERE domain_uuid=? AND principal_uuid=?`, domain, actor); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = s.store.ChangeTaskWork(ctx, domain, actor, "cancel", history[0].Item, time.Now(), "revoked"); !errors.Is(err, store.ErrAccessDenied) {
|
||||
t.Fatal("revocation not fenced", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkHistoryChromium(t *testing.T) {
|
||||
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
|
||||
t.Skip("opt-in Chromium")
|
||||
}
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
s.store.BackgroundJobsDisabled = true
|
||||
s = New(s.store)
|
||||
item, err := s.store.SaveTask(context.Background(), domain, actor, newTaskRecord("task", "Browser work record"), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v := recordedWork(t, s, domain, actor, item.UUID, time.Now().Add(-3*time.Hour))
|
||||
script, err := os.ReadFile("internal/server/testdata/task-work-history.js")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
handler := s.handler()
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Host = "localhost"
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
if r.URL.Path == "/fixture" {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_, _ = w.Write([]byte("<!doctype html><body style='margin:0'><script>" + string(script) + "</script></body>"))
|
||||
return
|
||||
}
|
||||
handler.ServeHTTP(w, r)
|
||||
}))
|
||||
defer server.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 55*time.Second)
|
||||
defer cancel()
|
||||
width := os.Getenv("WORK_HISTORY_WIDTH")
|
||||
if width == "" {
|
||||
width = "1440"
|
||||
}
|
||||
args := []string{"internal/server/testdata/vim-browser-smoke.mjs", server.URL + "/fixture", t.TempDir(), os.Getenv("WORK_HISTORY_SCREENSHOT"), width, "850"}
|
||||
if out, err := exec.CommandContext(ctx, "node", args...).CombinedOutput(); err != nil {
|
||||
t.Fatalf("browser: %v\n%s", err, out)
|
||||
}
|
||||
history, err := s.store.TaskWorkRevisions(context.Background(), domain, actor, v.UUID, 0)
|
||||
if err != nil || len(history) != 4 || history[0].Action != "cancel" || history[1].Action != "correct" {
|
||||
t.Fatal(history, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkHistoryLocalTimestampAPI(t *testing.T) {
|
||||
s, token, domain, actor := taskFixture(t)
|
||||
ctx := context.Background()
|
||||
item, err := s.store.SaveTask(ctx, domain, actor, newTaskRecord("task", "Timestamp"), 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
start := time.Date(2026, 1, 2, 12, 0, 0, 123000000, time.UTC)
|
||||
v := recordedWork(t, s, domain, actor, item.UUID, start)
|
||||
input := map[string]any{"uuid": v.UUID, "version": v.Version, "action": "correct", "reason": "API timestamp", "start": start.Format(time.RFC3339Nano), "end": start.Add(90 * time.Minute).Format(time.RFC3339Nano)}
|
||||
w := taskRequest(s, token, "POST", "work", input, "")
|
||||
if w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
var result struct {
|
||||
Item store.TaskWork `json:"item"`
|
||||
}
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
page, err := s.store.TaskWorkHistory(ctx, domain, actor, start.Add(-time.Hour), start.Add(3*time.Hour), "", 50)
|
||||
if err != nil || page.Items[0].StartMS != start.UnixMilli() {
|
||||
t.Fatal(page, err)
|
||||
}
|
||||
if w = taskRequest(s, token, "GET", "work-history?"+url.Values{"from": {"2026-01-02"}, "to": {"2026-01-03"}}.Encode(), nil, ""); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@ import (
|
||||
const tasksAPI = "/_/api/v1/extension/organizer.tasks/"
|
||||
|
||||
func taskRoute(p string) bool {
|
||||
if feedRoute(p) {
|
||||
return true
|
||||
}
|
||||
if p == "/v/plan/dashboard" {
|
||||
return true
|
||||
}
|
||||
@@ -30,6 +33,8 @@ func taskRoute(p string) bool {
|
||||
}
|
||||
|
||||
func (s *Server) registerTaskRoutes() {
|
||||
s.mux.HandleFunc("/v/feeds", s.handleFeeds)
|
||||
s.mux.HandleFunc(feedsAPI, s.handleFeeds)
|
||||
s.mux.HandleFunc("/v/plan/dashboard", s.handleOrganizerDashboard)
|
||||
s.mux.HandleFunc(contactDAV, s.handleContactDAV)
|
||||
s.mux.HandleFunc(strings.TrimSuffix(contactDAV, "/"), s.handleContactDAV)
|
||||
@@ -98,6 +103,10 @@ func (s *Server) handleTaskPage(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
if r.URL.Path == "/v/plan/tasks/work" {
|
||||
s.renderWithContext(w, r, "task_work_history.gohtml", map[string]any{"TaskWritable": active, "Timezone": s.getTimezoneName(domain)})
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/v/plan/tasks/report" || r.URL.Path == "/v/plan/tasks/settings" {
|
||||
s.handleTaskProductivityPage(w, r, active)
|
||||
return
|
||||
@@ -212,6 +221,14 @@ func (s *Server) handleTasksAPI(w http.ResponseWriter, r *http.Request) {
|
||||
r = r.WithContext(ctx)
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
parts := strings.Split(strings.TrimPrefix(r.URL.Path, tasksAPI), "/")
|
||||
if parts[0] == "digest-history" {
|
||||
s.handleTaskDigestHistory(w, r, actor, active, parts)
|
||||
return
|
||||
}
|
||||
if parts[0] == "work-history" {
|
||||
s.handleTaskWorkHistory(w, r, actor, parts)
|
||||
return
|
||||
}
|
||||
if len(parts) == 1 && (parts[0] == "dashboard" || parts[0] == "progress" || parts[0] == "calendar-capture" || parts[0] == "capture" || parts[0] == "preferences" || parts[0] == "work" || parts[0] == "report") {
|
||||
s.handleTaskProductivity(w, r, actor, active, parts[0])
|
||||
return
|
||||
|
||||
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
(async()=>{
|
||||
const delay=ms=>new Promise(r=>setTimeout(r,ms)),assert=(ok,msg)=>{if(!ok)throw Error(msg);};
|
||||
const wait=async check=>{for(let i=0;i<200;i++){if(check())return;await delay(30);}throw Error('Timeout: '+check);};
|
||||
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;
|
||||
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'));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===122);
|
||||
d.dispatchEvent(new w.KeyboardEvent('keydown',{key:'/',bubbles:true}));await wait(()=>d.activeElement.type==='search');d.activeElement.value='119';d.activeElement.dispatchEvent(new w.Event('input',{bubbles:true}));await wait(()=>d.querySelectorAll('.feed-row').length===1);
|
||||
d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
||||
d.querySelector('#feed-reader .feed-actions button:last-child').click();await wait(()=>d.querySelector('#feed-reader form'));
|
||||
const form=d.querySelector('#feed-reader form'),inputs=form.querySelectorAll('input');inputs[2].value='/notes/feed-ui';inputs[2].dispatchEvent(new w.Event('input'));inputs[5].checked=true;form.requestSubmit();await wait(()=>d.querySelector('#feed-reader a[href^="/v/uuid:"]'));
|
||||
const search=d.querySelector('#feed-toolbar input');search.value='';search.dispatchEvent(new w.Event('input',{bubbles:true}));await wait(()=>d.querySelectorAll('.feed-row').length===100);d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Reader overflow');
|
||||
d.getElementById('feed-opml').click();await wait(()=>d.getElementById('feed-opml-file'));
|
||||
const opml='<opml version="2.0"><head><title>Import</title></head><body><outline text="技術"><outline type="rss" text="Import '+w.innerWidth+'" xmlUrl="https://example.org/ui-'+w.innerWidth+'"/><outline type="rss" text="Existing" xmlUrl="https://example.org/feed.xml"/><outline type="rss" text="Private" xmlUrl="https://127.0.0.1/feed"/></outline></body></opml>';
|
||||
const choose=()=>{const transfer=new w.DataTransfer();transfer.items.add(new w.File([opml],'feeds.opml',{type:'text/x-opml'}));const f=d.getElementById('feed-opml-file');f.files=transfer.files;f.dispatchEvent(new w.Event('change',{bubbles:true}));};choose();
|
||||
await wait(()=>d.querySelectorAll('#feed-opml-preview tbody tr').length===3);const checks=d.querySelectorAll('#feed-opml-preview tbody input');assert(checks[0].checked&&!checks[0].disabled&&checks[1].disabled&&checks[2].disabled,'Import eligibility');
|
||||
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);
|
||||
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');
|
||||
if(w.innerWidth<=600)d.querySelector('#feed-toolbar button').click();
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Catalog overflow');document.body.dataset.vimReady='1';
|
||||
}catch(e){const out=document.createElement('pre');out.id='error';out.textContent=e.stack;document.body.append(out);}
|
||||
})();
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
(async () => {
|
||||
const assert = (ok, message) => { if (!ok) throw Error(message); };
|
||||
const delay = ms => new Promise(r => setTimeout(r, ms));
|
||||
const wait = async check => { for (let n=0;n<200;n++) { if(check()) return; await delay(25); } throw Error('Timed out: '+check); };
|
||||
const frame=document.createElement('iframe');frame.style='display:block;width:100%;height:100vh;border:0';document.body.append(frame);
|
||||
try {
|
||||
const load=()=>new Promise(resolve=>{frame.onload=resolve;frame.src='/';});
|
||||
await load();
|
||||
let w=frame.contentWindow,d=frame.contentDocument;
|
||||
await wait(()=>d.body.dataset.homePaletteActive==='surface');
|
||||
assert(d.querySelector('[data-home-palette]').dataset.paletteSource==='image','First palette not extracted');
|
||||
assert(w.performance.getEntriesByType('resource').filter(e=>e.name.includes('/v/raw/')).length===1,'Wallpaper fetched more than once');
|
||||
const before=d.body.style.getPropertyValue('--bg');
|
||||
const form=d.querySelector('[data-home-appearance-form]'),dialog=d.querySelector('[data-home-appearance-dialog]');
|
||||
const change=(name,value)=>{form.elements[name].value=value;form.elements[name].dispatchEvent(new w.Event('input',{bubbles:true}));};
|
||||
d.querySelector('[data-home-appearance-open]').click();
|
||||
change('home_palette_mode','off');
|
||||
assert(!d.body.dataset.homePaletteActive && !d.body.style.getPropertyValue('--bg'),'Off did not restore theme');
|
||||
d.querySelector('[data-home-appearance-cancel]').click();
|
||||
assert(d.body.style.getPropertyValue('--bg')===before,'Cancel did not restore palette');
|
||||
assert(!dialog.open,'Cancel did not close dialog');
|
||||
d.querySelector('[data-home-appearance-open]').click();
|
||||
change('home_palette_mode','accent');change('home_palette_strength','70');change('home_palette_brightness','auto');
|
||||
change('home_glass_transparency','47');
|
||||
assert(!d.body.style.getPropertyValue('--bg') && d.body.style.getPropertyValue('--accent'),'Accent mode tinted surface');
|
||||
form.requestSubmit();await wait(()=>!dialog.open);
|
||||
await load();w=frame.contentWindow;d=frame.contentDocument;
|
||||
await wait(()=>d.body.dataset.homePaletteActive==='accent');
|
||||
assert(d.querySelector('[data-home-palette]').dataset.paletteSource==='cache','Reload did not reuse palette');
|
||||
assert(d.querySelector('[name=home_palette_strength]').value==='70','Saved value not loaded');
|
||||
assert(d.body.style.getPropertyValue('--home-glass-opacity')==='53%','Glass setting lost');
|
||||
// A broken image must immediately remove derived colors, not retain a stale palette.
|
||||
d.querySelector('.home-wallpaper').dispatchEvent(new w.Event('error'));
|
||||
assert(!d.body.dataset.homePaletteActive && !d.body.style.getPropertyValue('--accent'),'Image error retained derived colors');
|
||||
w.sessionStorage.setItem('pageswiki.wallpaper-palette.v1','invalid cache');
|
||||
await load();w=frame.contentWindow;d=frame.contentDocument;
|
||||
await wait(()=>d.body.dataset.homePaletteActive==='accent');
|
||||
assert(d.querySelector('[data-home-palette]').dataset.paletteSource==='image','Invalid cache did not fall back to extraction');
|
||||
assert(Array.isArray(JSON.parse(w.sessionStorage.getItem('pageswiki.wallpaper-palette.v1'))),'Invalid cache was not repaired');
|
||||
const theme=d.querySelector('[data-theme-select]');
|
||||
theme.value='light';theme.dispatchEvent(new w.Event('change',{bubbles:true}));
|
||||
await wait(()=>!theme.disabled);await delay(100);
|
||||
assert(d.body.dataset.homePaletteActive==='accent','Theme switch disabled palette');
|
||||
d.querySelector('[data-home-appearance-open]').click();
|
||||
const form2=d.querySelector('[data-home-appearance-form]');
|
||||
form2.elements.home_palette_mode.value='off';form2.elements.home_palette_mode.dispatchEvent(new w.Event('input',{bubbles:true}));
|
||||
assert(w.getComputedStyle(d.body).backgroundColor==='rgb(247, 247, 247)','Off did not restore newly selected theme');
|
||||
d.querySelector('[data-home-appearance-cancel]').click();
|
||||
theme.value='nanoha-dark';theme.dispatchEvent(new w.Event('change',{bubbles:true}));await wait(()=>!theme.disabled);await delay(100);
|
||||
d.querySelector('[data-home-appearance-open]').click();
|
||||
form2.elements.home_palette_mode.value='surface';form2.elements.home_palette_mode.dispatchEvent(new w.Event('input',{bubbles:true}));
|
||||
const overflow=[...d.body.querySelectorAll('*')].filter(el=>{const r=el.getBoundingClientRect();return r.width>0 && r.right>w.innerWidth+1;}).slice(0,12).map(el=>el.tagName+'.'+el.className+':'+Math.round(el.getBoundingClientRect().right));
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Viewport overflows horizontally: '+d.documentElement.scrollWidth+'/'+w.innerWidth+' '+overflow.join(', '));
|
||||
const rect=d.querySelector('[data-home-appearance-dialog]').getBoundingClientRect();
|
||||
assert(rect.x>=0 && rect.right<=w.innerWidth && rect.top>=0 && rect.bottom<=w.innerHeight,'Dialog exceeds viewport');
|
||||
// Deliberately leave an unsaved surface preview visible for screenshot review.
|
||||
document.body.dataset.vimReady='1';
|
||||
} catch(error) { const out=document.createElement('pre');out.id='error';out.textContent=error.stack;document.body.append(out); }
|
||||
})();
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
(async()=>{
|
||||
const assert=(ok,msg)=>{if(!ok)throw Error(msg);},delay=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
const wait=async check=>{for(let n=0;n<240;n++){if(check())return;await delay(25);}throw Error('Timed out: '+check);};
|
||||
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='/-/sys/config?panel=organizer';});
|
||||
const w=frame.contentWindow,d=frame.contentDocument;await wait(()=>d.querySelector('#task-digest-history details'));
|
||||
const root=d.getElementById('task-digest-history'),details=root.querySelector('details');
|
||||
assert(!details.open,'History not lazy');assert(!w.performance.getEntriesByType('resource').some(x=>x.name.includes('/digest-history')),'History eagerly fetched');
|
||||
details.open=true;await wait(()=>root.querySelector('.digest-retry form'));
|
||||
const form=root.querySelector('.digest-retry form'),ack=form.querySelector('input');
|
||||
assert(ack.required&&!ack.checked,'Uncertain delivery must require confirmation');assert(!form.checkValidity(),'Unchecked acknowledgment valid');ack.checked=true;
|
||||
const original=w.fetch,requests=[];let lose=true;
|
||||
w.fetch=async(url,options)=>{if(String(url).endsWith('/digest-history/retry')){requests.push(JSON.parse(options.body));const response=await original(url,options);if(lose){lose=false;await response.text();throw new TypeError('Simulated lost response');}return response;}return original(url,options);};
|
||||
form.requestSubmit();await wait(()=>root.querySelector('[role=status]').textContent&&!form.querySelector('button').disabled);
|
||||
assert(root.contains(form),'Lost response removed retry controls');form.requestSubmit();
|
||||
await wait(()=>!root.querySelector('.digest-retry form')&&!root.querySelector('.productivity-controls button').disabled);
|
||||
assert(requests.length===2&&requests[0].request_id===requests[1].request_id,'Retry generated a second request ID');
|
||||
assert(root.querySelectorAll('tbody tr').length===2,'Duplicate attempt created');
|
||||
const tick=await fetch('/fixture/tick',{method:'POST'});assert(tick.ok,'Worker failed');
|
||||
root.querySelector('.productivity-controls button').click();await wait(()=>root.querySelector('.digest-retry form'));
|
||||
assert(root.querySelector('.digest-retry input').required,'Sent retry must require confirmation');
|
||||
assert(root.textContent.includes('メールサーバー受付済み')||root.textContent.includes('Accepted by mail server'),'Sent status missing');
|
||||
assert(!root.textContent.includes('reader@example.test'),'Recipient leaked in history');
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Settings overflow viewport');
|
||||
details.scrollIntoView({block:'start'});document.body.dataset.vimReady='1';
|
||||
}catch(error){const out=document.createElement('pre');out.id='error';out.textContent=error.stack;document.body.append(out);}
|
||||
})();
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
(async()=>{
|
||||
const assert=(ok,msg)=>{if(!ok)throw Error(msg);},delay=ms=>new Promise(r=>setTimeout(r,ms));
|
||||
const wait=async check=>{for(let n=0;n<200;n++){if(check())return;await delay(25);}throw Error('Timed out: '+check);};
|
||||
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/plan/dashboard';});
|
||||
await wait(()=>frame.contentDocument.querySelector('.productivity-table tbody tr'));
|
||||
const reportTable=frame.contentDocument.querySelector('.productivity-table');
|
||||
assert(reportTable.querySelectorAll('thead th').length===4,'Project aggregate table missing');
|
||||
assert(reportTable.querySelector('tbody tr').lastElementChild.textContent==='1.00','Project duration incorrect');
|
||||
const historyLink=frame.contentDocument.querySelector('a[href="/v/plan/tasks/work"]');assert(historyLink,'Dashboard history link missing');
|
||||
await new Promise(resolve=>{frame.onload=resolve;historyLink.click();});
|
||||
const w=frame.contentWindow,d=frame.contentDocument;
|
||||
await wait(()=>d.querySelector('.work-history-table tbody button'));
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'History overflows viewport');
|
||||
d.querySelector('.work-history-table tbody button').click();
|
||||
let form=d.querySelector('.work-history-edit');assert(form,'Inline correction missing');
|
||||
const inputs=form.querySelectorAll('input');inputs[2].value='Browser correction';
|
||||
form.requestSubmit();await wait(()=>!d.querySelector('.work-history-edit')&&!d.getElementById('work-history-list').inert);
|
||||
d.querySelector('#work-history-list details').open=true;await wait(()=>d.querySelector('#work-history-list details strong'));
|
||||
assert(d.querySelector('#work-history-list details').textContent.includes('Browser correction'),'Audit missing');
|
||||
const originalFetch=w.fetch;w.fetch=async(url,options)=>options?.method==='POST'?new w.Response(JSON.stringify({error:'conflict'}),{status:412}):originalFetch(url,options);
|
||||
d.querySelector('.work-history-table tbody button').click();form=d.querySelector('.work-history-edit');form.querySelector('input[type=text]').value='Retain my input';form.requestSubmit();
|
||||
await wait(()=>form.querySelector('[role=status]').textContent);assert(form.querySelector('input[type=text]').value==='Retain my input','Conflict discarded input');
|
||||
w.fetch=originalFetch;w.confirm=()=>true;form.querySelector('button[type=button]').click();
|
||||
d.querySelectorAll('.work-history-table tbody tr:first-child button')[1].click();form=d.querySelector('.work-history-edit');form.querySelector('input').value='Browser cancellation';form.requestSubmit();await wait(()=>!d.querySelector('.work-history-edit')&&!d.getElementById('work-history-list').inert);
|
||||
assert(!d.querySelector('.work-history-table tbody tr:first-child button'),'Cancelled work remains editable');
|
||||
d.querySelector('#work-history-list details').open=true;await wait(()=>d.querySelector('#work-history-list details strong'));
|
||||
assert(d.querySelector('#work-history-list details').textContent.includes('Browser cancellation'),'Cancellation audit missing');
|
||||
const report=await (await fetch('/_/api/v1/extension/organizer.tasks/report')).json();assert(report.days.every(day=>day.work_ms===0),'Cancelled time remains in report');
|
||||
assert(d.documentElement.scrollWidth<=w.innerWidth,'Expanded history overflows viewport');
|
||||
document.body.dataset.vimReady='1';
|
||||
}catch(error){const out=document.createElement('pre');out.id='error';out.textContent=error.stack;document.body.append(out);}
|
||||
})();
|
||||
@@ -0,0 +1,514 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"pageswiki/internal/db"
|
||||
)
|
||||
|
||||
const FeedSyncEventType = "feed.source.sync"
|
||||
|
||||
var feedMigrations = []db.SQLMigration{{Version: 1, Name: "private_feed_reader", Statements: []string{
|
||||
`CREATE TABLE feed_sources(uuid TEXT PRIMARY KEY,domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,provider TEXT NOT NULL CHECK(provider IN ('local','freshrss')),title TEXT NOT NULL,folder TEXT NOT NULL,url TEXT NOT NULL,credential TEXT NOT NULL DEFAULT '',version INTEGER NOT NULL,enabled INTEGER NOT NULL,interval_seconds INTEGER NOT NULL,next_ms INTEGER NOT NULL DEFAULT 0,lease TEXT NOT NULL DEFAULT '',lease_until INTEGER NOT NULL DEFAULT 0,last_ms INTEGER NOT NULL DEFAULT 0,error TEXT NOT NULL DEFAULT '',etag TEXT NOT NULL DEFAULT '',modified TEXT NOT NULL DEFAULT '')`,
|
||||
`CREATE INDEX feed_sources_owner ON feed_sources(domain_uuid,owner_uuid,uuid)`,
|
||||
`CREATE INDEX feed_sources_due ON feed_sources(enabled,next_ms,uuid)`,
|
||||
`CREATE TABLE feed_items(source_uuid TEXT NOT NULL REFERENCES feed_sources(uuid) ON DELETE CASCADE,id TEXT NOT NULL,title TEXT NOT NULL,url TEXT NOT NULL,body TEXT NOT NULL,published_ms INTEGER NOT NULL,feed TEXT NOT NULL,folder TEXT NOT NULL,is_read INTEGER NOT NULL,starred INTEGER NOT NULL,PRIMARY KEY(source_uuid,id))`,
|
||||
`CREATE INDEX feed_items_date ON feed_items(source_uuid,published_ms DESC,id DESC)`,
|
||||
`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')`}}, {
|
||||
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")},
|
||||
}, {
|
||||
Version: 3, Name: "feed_import_receipts", Statements: []string{
|
||||
`CREATE TABLE feed_import_receipts(domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,request_id TEXT NOT NULL,input_hash TEXT NOT NULL,result TEXT NOT NULL,PRIMARY KEY(domain_uuid,owner_uuid,request_id))`,
|
||||
}, Assertions: []string{schemaUnique("feed_import_receipts", "domain_uuid,owner_uuid,request_id")},
|
||||
}, {
|
||||
Version: 4, Name: "freshrss_catalog", Statements: []string{
|
||||
`ALTER TABLE feed_sources ADD COLUMN remote_catalog TEXT NOT NULL DEFAULT '[]'`,
|
||||
`ALTER TABLE feed_items ADD COLUMN remote_feed TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE feed_items ADD COLUMN remote_categories TEXT NOT NULL DEFAULT '[]'`,
|
||||
`UPDATE feed_sources SET next_ms=0,lease='',lease_until=0,version=version+1 WHERE provider='freshrss'`,
|
||||
}, Assertions: []string{schemaColumns("feed_sources", "remote_catalog"), schemaColumns("feed_items", "remote_feed,remote_categories")},
|
||||
}}
|
||||
|
||||
// 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.
|
||||
func (s *Store) CaptureFeedNote(ctx context.Context, domain, owner, request, source, id, target, title, body string) (string, error) {
|
||||
if _, e := uuid.Parse(request); e != nil {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
if !ValidTaskWikiPrefix(target) || target == "/" || len(target) > 500 || len(title) > 300 || title == "" || len(body) > 65536 {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
// User/group spaces have additional ownership/publication contracts. Initial
|
||||
// capture supports ordinary Wiki paths only, rather than bypassing those caps.
|
||||
first := strings.Split(strings.TrimPrefix(target, "/"), "/")[0]
|
||||
if first == "u" || first == "g" {
|
||||
return "", ErrAccessDenied
|
||||
}
|
||||
raw, _ := json.Marshal([]string{source, id, target, title, body})
|
||||
hash := fmt.Sprintf("%x", sha256.Sum256(raw))
|
||||
page := ""
|
||||
e := s.feedWrite(ctx, domain, owner, func(tx *sql.Tx) error {
|
||||
caps, e := loadLocalityAccess(tx, domain, owner)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
for _, capability := range []string{"read", "create", "write"} {
|
||||
basis := authorizeGrantFrom(tx, AuthorizationRequest{DomainUUID: domain, PrincipalUUID: owner, Capability: capability, TargetType: "path", TargetID: target}, false)
|
||||
if basis != nil && !errors.Is(basis, ErrAccessDenied) {
|
||||
return basis
|
||||
}
|
||||
if !caps.Decide(target, capability, basis == nil) {
|
||||
return ErrAccessDenied
|
||||
}
|
||||
}
|
||||
var oldHash string
|
||||
e = tx.QueryRowContext(ctx, `SELECT input_hash,page_uuid FROM feed_note_receipts WHERE domain_uuid=? AND owner_uuid=? AND request_id=?`, domain, owner, request).Scan(&oldHash, &page)
|
||||
if e == nil {
|
||||
if oldHash != hash {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if !errors.Is(e, sql.ErrNoRows) {
|
||||
return e
|
||||
}
|
||||
var exists bool
|
||||
if e = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM feed_items i JOIN feed_sources s ON s.uuid=i.source_uuid WHERE s.domain_uuid=? AND s.owner_uuid=? AND s.uuid=? AND i.id=?)`, domain, owner, source, id).Scan(&exists); e != nil {
|
||||
return e
|
||||
}
|
||||
if !exists {
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
item := TaskRecord{Title: title}
|
||||
if e = s.createCapturedTaskWiki(ctx, tx, domain, owner, &item, target, body); e != nil {
|
||||
return e
|
||||
}
|
||||
page = item.PageUUID
|
||||
_, e = tx.ExecContext(ctx, `INSERT INTO feed_note_receipts VALUES(?,?,?,?,?)`, domain, owner, request, hash, page)
|
||||
return e
|
||||
})
|
||||
if e == nil {
|
||||
s.InvalidatePathCaches()
|
||||
}
|
||||
return page, e
|
||||
}
|
||||
|
||||
type FeedSource struct {
|
||||
UUID string `json:"uuid"`
|
||||
Domain string `json:"-"`
|
||||
Owner string `json:"-"`
|
||||
Provider string `json:"provider"`
|
||||
Title string `json:"title"`
|
||||
Folder string `json:"folder"`
|
||||
URL string `json:"url"`
|
||||
Credential string `json:"-"`
|
||||
Version int64 `json:"version"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Interval int `json:"interval_seconds"`
|
||||
NextMS int64 `json:"next_ms"`
|
||||
Lease string `json:"-"`
|
||||
LeaseUntil int64 `json:"-"`
|
||||
LastMS int64 `json:"last_ms"`
|
||||
Error string `json:"error"`
|
||||
ETag string `json:"-"`
|
||||
Modified string `json:"-"`
|
||||
}
|
||||
type FeedItem struct {
|
||||
Source string `json:"source"`
|
||||
ID string `json:"id"`
|
||||
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"`
|
||||
Read bool `json:"read"`
|
||||
Starred bool `json:"starred"`
|
||||
Version int64 `json:"version"`
|
||||
Provider string `json:"provider"`
|
||||
RemoteFeed string `json:"remote_feed,omitempty"`
|
||||
RemoteCategories []string `json:"remote_categories,omitempty"`
|
||||
}
|
||||
|
||||
const feedSourceColumns = `uuid,domain_uuid,owner_uuid,provider,title,folder,url,credential,version,enabled,interval_seconds,next_ms,lease,lease_until,last_ms,error,etag,modified`
|
||||
|
||||
func scanFeedSource(row interface{ Scan(...any) error }) (v FeedSource, e error) {
|
||||
e = row.Scan(&v.UUID, &v.Domain, &v.Owner, &v.Provider, &v.Title, &v.Folder, &v.URL, &v.Credential, &v.Version, &v.Enabled, &v.Interval, &v.NextMS, &v.Lease, &v.LeaseUntil, &v.LastMS, &v.Error, &v.ETag, &v.Modified)
|
||||
return
|
||||
}
|
||||
func feedActor(ctx context.Context, q interface {
|
||||
QueryRowContext(context.Context, string, ...any) *sql.Row
|
||||
}, domain, owner string, write bool) error {
|
||||
if e := taskActor(ctx, q, domain, owner, write); e != nil {
|
||||
return e
|
||||
}
|
||||
var raw string
|
||||
e := q.QueryRowContext(ctx, `SELECT value FROM config WHERE domain_uuid=? AND key='system_extension_states'`, domain).Scan(&raw)
|
||||
if e != nil && !errors.Is(e, sql.ErrNoRows) {
|
||||
return e
|
||||
}
|
||||
states := map[string]bool{}
|
||||
if raw != "" && json.Unmarshal([]byte(raw), &states) != nil {
|
||||
return ErrAccessDenied
|
||||
}
|
||||
if enabled, ok := states["organizer.feeds"]; ok && !enabled {
|
||||
return ErrAccessDenied
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (s *Store) feedWrite(ctx context.Context, domain, owner string, fn func(*sql.Tx) error) error {
|
||||
if s.ReadOnly {
|
||||
return ErrReadOnly
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
tx, e := s.DB.BeginTx(ctx, nil)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, e = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=? AND principal_uuid=?`, domain, owner); e != nil {
|
||||
return e
|
||||
}
|
||||
if e = feedActor(ctx, tx, domain, owner, true); e != nil {
|
||||
return e
|
||||
}
|
||||
if e = fn(tx); e != nil {
|
||||
return e
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
func (s *Store) FeedSources(ctx context.Context, domain, owner string) ([]FeedSource, error) {
|
||||
if e := feedActor(ctx, s.DB, domain, owner, false); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
rows, e := s.DB.QueryContext(ctx, `SELECT `+feedSourceColumns+` FROM feed_sources WHERE domain_uuid=? AND owner_uuid=? ORDER BY folder,title,uuid LIMIT 32`, domain, owner)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []FeedSource{}
|
||||
for rows.Next() {
|
||||
v, e := scanFeedSource(rows)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
func (s *Store) SaveFeedSource(ctx context.Context, domain, owner string, v FeedSource) (FeedSource, error) {
|
||||
if _, e := uuid.Parse(v.UUID); e != nil {
|
||||
return v, ErrTaskInvalid
|
||||
}
|
||||
v.Title = strings.TrimSpace(v.Title)
|
||||
v.Folder = strings.TrimSpace(v.Folder)
|
||||
if v.Title == "" || len(v.Title) > 200 || len(v.Folder) > 200 || len(v.URL) > 4096 || !utf8.ValidString(v.Title+v.Folder) || v.Interval < 300 || v.Interval > 86400 || (v.Provider != "local" && v.Provider != "freshrss") {
|
||||
return v, ErrTaskInvalid
|
||||
}
|
||||
e := s.feedWrite(ctx, domain, owner, func(tx *sql.Tx) error {
|
||||
if v.Version == 0 {
|
||||
old, lookup := scanFeedSource(tx.QueryRowContext(ctx, `SELECT `+feedSourceColumns+` FROM feed_sources WHERE uuid=?`, v.UUID))
|
||||
if lookup == nil {
|
||||
if old.Domain != domain || old.Owner != owner || old.Version != 1 || old.Provider != v.Provider || old.Title != v.Title || old.Folder != v.Folder || old.URL != v.URL || old.Interval != v.Interval || old.Enabled != v.Enabled {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
if old.Credential != v.Credential {
|
||||
candidate := v
|
||||
candidate.Domain = domain
|
||||
candidate.Owner = owner
|
||||
u, p, e := s.OpenFeedCredential(candidate)
|
||||
if e != nil {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
ou, op, e := s.OpenFeedCredential(old)
|
||||
if e != nil || u != ou || p != op {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if !errors.Is(lookup, sql.ErrNoRows) {
|
||||
return lookup
|
||||
}
|
||||
var n int
|
||||
if e := tx.QueryRowContext(ctx, `SELECT count(*) FROM feed_sources WHERE domain_uuid=? AND owner_uuid=?`, domain, owner).Scan(&n); e != nil {
|
||||
return e
|
||||
}
|
||||
if n >= 32 {
|
||||
return ErrTaskDAVLimit
|
||||
}
|
||||
_, e := tx.ExecContext(ctx, `INSERT INTO feed_sources(uuid,domain_uuid,owner_uuid,provider,title,folder,url,credential,version,enabled,interval_seconds) VALUES(?,?,?,?,?,?,?,?,1,?,?)`, v.UUID, domain, owner, v.Provider, v.Title, v.Folder, v.URL, v.Credential, v.Enabled, v.Interval)
|
||||
return e
|
||||
}
|
||||
old, e := scanFeedSource(tx.QueryRowContext(ctx, `SELECT `+feedSourceColumns+` FROM feed_sources WHERE uuid=? AND domain_uuid=? AND owner_uuid=?`, v.UUID, domain, owner))
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
// Changing remote identity requires a new source, not reassignment of cached IDs.
|
||||
if old.Provider != v.Provider || old.URL != v.URL || v.Credential != "" {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
result, e := tx.ExecContext(ctx, `UPDATE feed_sources SET title=?,folder=?,enabled=?,interval_seconds=?,version=version+1,next_ms=0,lease='',lease_until=0 WHERE uuid=? AND version=?`, v.Title, v.Folder, v.Enabled, v.Interval, v.UUID, v.Version)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
n, _ := result.RowsAffected()
|
||||
if n != 1 {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
return nil
|
||||
})
|
||||
v.Version++
|
||||
v.Credential = ""
|
||||
return v, e
|
||||
}
|
||||
func (s *Store) FeedSourceAction(ctx context.Context, domain, owner, id, action string, version int64) error {
|
||||
return s.feedWrite(ctx, domain, owner, func(tx *sql.Tx) error {
|
||||
var result sql.Result
|
||||
var e error
|
||||
switch action {
|
||||
case "refresh":
|
||||
result, e = tx.ExecContext(ctx, `UPDATE feed_sources SET next_ms=0 WHERE uuid=? AND domain_uuid=? AND owner_uuid=? AND version=? AND enabled=1 AND lease_until<? AND (last_ms=0 OR last_ms<?)`, id, domain, owner, version, time.Now().UnixMilli(), time.Now().Add(-time.Minute).UnixMilli())
|
||||
case "delete":
|
||||
result, e = tx.ExecContext(ctx, `DELETE FROM feed_sources WHERE uuid=? AND domain_uuid=? AND owner_uuid=? AND version=?`, id, domain, owner, version)
|
||||
default:
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
n, _ := result.RowsAffected()
|
||||
if n != 1 {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
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 {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
if len(scope) > 0 {
|
||||
remoteFeed = scope[0]
|
||||
}
|
||||
if len(scope) > 1 {
|
||||
category = scope[1]
|
||||
}
|
||||
if (remoteFeed != "" && !ValidFeedRemoteID(remoteFeed)) || (category != "" && !ValidFeedRemoteID(category)) || ((remoteFeed != "" || category != "") && source == "") {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
if len(query) > 200 || len(beforeID) > 1200 {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
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)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []FeedItem{}
|
||||
for rows.Next() {
|
||||
var v FeedItem
|
||||
if e = rows.Scan(&v.Source, &v.ID, &v.Title, &v.URL, &v.PublishedMS, &v.Feed, &v.Folder, &v.Read, &v.Starred, &v.Version, &v.Provider); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
func (s *Store) FeedItem(ctx context.Context, domain, owner, source, id string) (FeedItem, error) {
|
||||
var v FeedItem
|
||||
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.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 {
|
||||
return s.feedWrite(ctx, domain, owner, func(tx *sql.Tx) error {
|
||||
var provider string
|
||||
if e := tx.QueryRowContext(ctx, `SELECT s.provider FROM feed_sources s JOIN feed_items i ON i.source_uuid=s.uuid WHERE s.uuid=? AND s.domain_uuid=? AND s.owner_uuid=? AND i.id=?`, source, domain, owner, id).Scan(&provider); e != nil {
|
||||
return e
|
||||
}
|
||||
if provider != "local" {
|
||||
return ErrAccessDenied
|
||||
}
|
||||
if version == 0 {
|
||||
var n int
|
||||
if e := tx.QueryRowContext(ctx, `SELECT count(*) FROM feed_states WHERE source_uuid=?`, source).Scan(&n); e != nil {
|
||||
return e
|
||||
}
|
||||
if n >= 10000 {
|
||||
return ErrTaskDAVLimit
|
||||
}
|
||||
}
|
||||
result, e := tx.ExecContext(ctx, `INSERT INTO feed_states(source_uuid,id,is_read,starred,version) SELECT ?,?,?,?,1 WHERE ?=0 ON CONFLICT(source_uuid,id) DO NOTHING`, source, id, read, star, version)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
n, _ := result.RowsAffected()
|
||||
if n == 1 {
|
||||
return nil
|
||||
}
|
||||
result, e = tx.ExecContext(ctx, `UPDATE feed_states SET is_read=?,starred=?,version=version+1 WHERE source_uuid=? AND id=? AND version=?`, read, star, source, id, version)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
n, _ = result.RowsAffected()
|
||||
if n != 1 {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
func (s *Store) SealFeedCredential(domain, owner, id, user, password string) (string, error) {
|
||||
b, _ := json.Marshal([]string{"feed-source-v1", domain, owner, id, user, password})
|
||||
return s.encryptAuthSecret(b)
|
||||
}
|
||||
func (s *Store) OpenFeedCredential(v FeedSource) (string, string, error) {
|
||||
b, e := s.decryptAuthSecret(v.Credential)
|
||||
if e != nil {
|
||||
return "", "", e
|
||||
}
|
||||
var f []string
|
||||
if json.Unmarshal(b, &f) != nil || len(f) != 6 || f[0] != "feed-source-v1" || f[1] != v.Domain || f[2] != v.Owner || f[3] != v.UUID {
|
||||
return "", "", ErrAccessDenied
|
||||
}
|
||||
return f[4], f[5], nil
|
||||
}
|
||||
func (s *Store) EnsureFeedEvent() error {
|
||||
if s.ReadOnly {
|
||||
return ErrReadOnly
|
||||
}
|
||||
now := time.Now().UnixMilli()
|
||||
_, e := s.DB.Exec(`INSERT OR IGNORE INTO event_definitions(uuid,name,event_type,event_key,payload,schedule_kind,interval_seconds,next_run_at_ms,enabled,priority,max_attempts,created_at_ms,updated_at_ms) VALUES('builtin.feed.sync','RSS source synchronization',?,'local','{}','interval',60,?,1,-5,1,?,?)`, FeedSyncEventType, now, now, now)
|
||||
return e
|
||||
}
|
||||
func (s *Store) DueFeedSources(ctx context.Context) ([]FeedSource, error) {
|
||||
rows, e := s.DB.QueryContext(ctx, `SELECT `+feedSourceColumns+` FROM feed_sources WHERE enabled=1 AND next_ms<=? AND lease_until<? AND EXISTS(SELECT 1 FROM principals p JOIN domain_memberships m ON m.principal_uuid=p.uuid JOIN domains d ON d.uuid=m.domain_uuid WHERE p.uuid=feed_sources.owner_uuid AND m.domain_uuid=feed_sources.domain_uuid AND p.state='active' AND m.state='active' AND d.enabled=1 AND COALESCE(d.placement,'local')='local') AND NOT EXISTS(SELECT 1 FROM config c WHERE c.domain_uuid=feed_sources.domain_uuid AND c.key='system_extension_states' AND COALESCE(json_extract(CASE WHEN json_valid(c.value) THEN c.value ELSE '{"organizer.feeds":false}' END,'$."organizer.feeds"'),1)=0) ORDER BY next_ms,uuid LIMIT 4`, time.Now().UnixMilli(), time.Now().UnixMilli())
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []FeedSource{}
|
||||
for rows.Next() {
|
||||
v, e := scanFeedSource(rows)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
func (s *Store) ClaimFeed(ctx context.Context, v FeedSource) (FeedSource, error) {
|
||||
v.Lease = uuid.NewString()
|
||||
e := s.feedWrite(ctx, v.Domain, v.Owner, func(tx *sql.Tx) error {
|
||||
now := time.Now().UnixMilli()
|
||||
result, e := tx.ExecContext(ctx, `UPDATE feed_sources SET lease=?,lease_until=?,next_ms=? WHERE uuid=? AND version=? AND enabled=1 AND lease_until<? AND next_ms<=?`, v.Lease, now+60000, now+int64(v.Interval)*1000, v.UUID, v.Version, now, now)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
n, _ := result.RowsAffected()
|
||||
if n != 1 {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return v, e
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if len(catalogs) > 1 {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
var catalog string
|
||||
if len(catalogs) == 1 {
|
||||
var e error
|
||||
catalog, e = FeedCatalogJSON(catalogs[0])
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
if len(items) > 500 || len(etag) > 1024 || len(modified) > 1024 {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
switch code {
|
||||
case "", "network", "invalid_feed", "credentials", "remote_error", "limit":
|
||||
default:
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
for _, i := range items {
|
||||
if (i.RemoteFeed != "" && !ValidFeedRemoteID(i.RemoteFeed)) || len(i.RemoteCategories) > 64 {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
for _, c := range i.RemoteCategories {
|
||||
if !ValidFeedRemoteID(c) {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
return s.feedWrite(ctx, v.Domain, v.Owner, func(tx *sql.Tx) error {
|
||||
result, e := tx.ExecContext(ctx, `UPDATE feed_sources SET lease='',lease_until=0,last_ms=CASE WHEN ?='' THEN ? ELSE last_ms END,error=?,etag=CASE WHEN ?='' THEN ? ELSE etag END,modified=CASE WHEN ?='' THEN ? ELSE modified END WHERE uuid=? AND version=? AND lease=? AND enabled=1`, code, time.Now().UnixMilli(), code, code, etag, code, modified, v.UUID, v.Version, v.Lease)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
n, _ := result.RowsAffected()
|
||||
if n != 1 {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
if code != "" || unchanged {
|
||||
return nil
|
||||
}
|
||||
if catalog != "" {
|
||||
if _, e = tx.ExecContext(ctx, `UPDATE feed_sources SET remote_catalog=? WHERE uuid=?`, catalog, v.UUID); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
// FreshRSS is authoritative: retain exactly this bounded recent window,
|
||||
// not stale rows from unsubscribed feeds or old external read/star state.
|
||||
if v.Provider == "freshrss" {
|
||||
if _, e = tx.ExecContext(ctx, `DELETE FROM feed_items WHERE source_uuid=?`, v.UUID); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
for _, i := range items {
|
||||
categories := i.RemoteCategories
|
||||
if categories == nil {
|
||||
categories = []string{}
|
||||
}
|
||||
raw, _ := json.Marshal(categories)
|
||||
_, e = tx.ExecContext(ctx, `INSERT INTO feed_items(source_uuid,id,title,url,body,body_html,published_ms,feed,folder,is_read,starred,remote_feed,remote_categories) 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,remote_feed=excluded.remote_feed,remote_categories=excluded.remote_categories`, v.UUID, i.ID, i.Title, i.URL, i.Body, i.BodyHTML, i.PublishedMS, i.Feed, i.Folder, i.Read, i.Starred, i.RemoteFeed, string(raw))
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
_, e = tx.ExecContext(ctx, `DELETE FROM feed_items WHERE source_uuid=? AND id NOT IN(SELECT id FROM feed_items WHERE source_uuid=? ORDER BY published_ms DESC,id DESC LIMIT 500)`, v.UUID, v.UUID)
|
||||
return e
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Remote IDs are opaque identities, not URLs to fetch or display labels.
|
||||
type FeedCategory struct {
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
type FeedRemoteSubscription struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Categories []FeedCategory `json:"categories"`
|
||||
}
|
||||
|
||||
func ValidFeedRemoteID(id string) bool {
|
||||
return id != "" && len(id) <= 2048 && utf8.ValidString(id) && !strings.ContainsAny(id, "\x00\r\n")
|
||||
}
|
||||
|
||||
// Bound both the number of entries and the encoded snapshot independently of
|
||||
// the HTTP response limit. Invalid snapshots must not erase a good cache.
|
||||
func FeedCatalogJSON(catalog []FeedRemoteSubscription) (string, error) {
|
||||
if len(catalog) > 1000 {
|
||||
return "", ErrTaskDAVLimit
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
labels := map[string]string{}
|
||||
for _, sub := range catalog {
|
||||
if !ValidFeedRemoteID(sub.ID) || seen[sub.ID] || len(sub.Title) > 512 || !utf8.ValidString(sub.Title) || len(sub.Categories) > 64 {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
seen[sub.ID] = true
|
||||
cats := map[string]bool{}
|
||||
for _, c := range sub.Categories {
|
||||
if !ValidFeedRemoteID(c.ID) || cats[c.ID] || len(c.Label) > 512 || !utf8.ValidString(c.Label) {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
if label, ok := labels[c.ID]; ok && label != c.Label {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
cats[c.ID], labels[c.ID] = true, c.Label
|
||||
}
|
||||
}
|
||||
if catalog == nil {
|
||||
catalog = []FeedRemoteSubscription{}
|
||||
}
|
||||
raw, e := json.Marshal(catalog)
|
||||
if e != nil {
|
||||
return "", e
|
||||
}
|
||||
if len(raw) > 1<<20 {
|
||||
return "", ErrTaskDAVLimit
|
||||
}
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
var catalog []FeedRemoteSubscription
|
||||
if e := json.Unmarshal([]byte(raw), &catalog); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return catalog, nil
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type FeedSubscription struct {
|
||||
Title string `json:"title"`
|
||||
Folder string `json:"folder"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// Only normalize syntactic equivalence; never reorder query parameters, change
|
||||
// path case or follow redirects to decide identity.
|
||||
func FeedURLKey(raw string) string {
|
||||
u, err := url.Parse(strings.TrimSpace(raw))
|
||||
if err != nil {
|
||||
return raw
|
||||
}
|
||||
u.Scheme = strings.ToLower(u.Scheme)
|
||||
u.Host = strings.ToLower(u.Host)
|
||||
if u.Scheme == "https" && u.Port() == "443" {
|
||||
u.Host = strings.TrimSuffix(u.Host, ":443")
|
||||
}
|
||||
if u.Path == "" {
|
||||
u.Path = "/"
|
||||
}
|
||||
u.Fragment = ""
|
||||
return u.String()
|
||||
}
|
||||
|
||||
func FeedSourcesSnapshot(sources []FeedSource) string {
|
||||
versions := make([]string, 0, len(sources))
|
||||
for _, s := range sources {
|
||||
versions = append(versions, fmt.Sprintf("%s:%d", s.UUID, s.Version))
|
||||
}
|
||||
sort.Strings(versions)
|
||||
return fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(versions, "\n"))))
|
||||
}
|
||||
|
||||
type FeedImport struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Expected string `json:"expected"`
|
||||
Entries []FeedSubscription `json:"entries"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Interval int `json:"interval_seconds"`
|
||||
}
|
||||
|
||||
// Append-only import: source inserts and the durable retry receipt commit as a
|
||||
// unit. A retry after later source deletion returns its receipt, never resurrects
|
||||
// the deleted subscription. Authorization is checked even on receipt replay.
|
||||
func (s *Store) ImportFeedSubscriptions(ctx context.Context, domain, owner string, input FeedImport) ([]string, error) {
|
||||
if _, err := uuid.Parse(input.RequestID); err != nil {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
if len(input.Expected) != 64 || len(input.Entries) == 0 || len(input.Entries) > 32 || input.Interval < 300 || input.Interval > 86400 {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
keys := map[string]bool{}
|
||||
for _, entry := range input.Entries {
|
||||
u, err := url.Parse(entry.URL)
|
||||
if err != nil || u.Scheme != "https" || u.Hostname() == "" || u.User != nil || u.Fragment != "" || (u.Port() != "" && u.Port() != "443") || len(entry.URL) > 4096 || strings.TrimSpace(entry.Title) == "" || len(entry.Title) > 200 || len(entry.Folder) > 200 || !utf8.ValidString(entry.Title+entry.Folder+entry.URL) {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
key := FeedURLKey(entry.URL)
|
||||
if keys[key] {
|
||||
return nil, ErrTaskInvalid
|
||||
}
|
||||
keys[key] = true
|
||||
}
|
||||
raw, _ := json.Marshal(input)
|
||||
hash := fmt.Sprintf("%x", sha256.Sum256(raw))
|
||||
ids := []string{}
|
||||
err := s.feedWrite(ctx, domain, owner, func(tx *sql.Tx) error {
|
||||
var oldHash, result string
|
||||
err := tx.QueryRowContext(ctx, `SELECT input_hash,result FROM feed_import_receipts WHERE domain_uuid=? AND owner_uuid=? AND request_id=?`, domain, owner, input.RequestID).Scan(&oldHash, &result)
|
||||
if err == nil {
|
||||
if oldHash != hash {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
return json.Unmarshal([]byte(result), &ids)
|
||||
}
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
return err
|
||||
}
|
||||
rows, err := tx.QueryContext(ctx, `SELECT uuid,version,provider,url FROM feed_sources WHERE domain_uuid=? AND owner_uuid=?`, domain, owner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
existing := []FeedSource{}
|
||||
for rows.Next() {
|
||||
var source FeedSource
|
||||
if err = rows.Scan(&source.UUID, &source.Version, &source.Provider, &source.URL); err != nil {
|
||||
rows.Close()
|
||||
return err
|
||||
}
|
||||
existing = append(existing, source)
|
||||
}
|
||||
err = rows.Err()
|
||||
rows.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if FeedSourcesSnapshot(existing) != input.Expected {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
if len(existing)+len(input.Entries) > 32 {
|
||||
return ErrTaskDAVLimit
|
||||
}
|
||||
for _, source := range existing {
|
||||
if source.Provider == "local" && keys[FeedURLKey(source.URL)] {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
}
|
||||
var receipts int
|
||||
if err = tx.QueryRowContext(ctx, `SELECT count(*) FROM feed_import_receipts WHERE domain_uuid=? AND owner_uuid=?`, domain, owner).Scan(&receipts); err != nil {
|
||||
return err
|
||||
}
|
||||
if receipts >= 1000 {
|
||||
return ErrTaskDAVLimit
|
||||
}
|
||||
for _, entry := range input.Entries {
|
||||
id := uuid.NewString()
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO feed_sources(uuid,domain_uuid,owner_uuid,provider,title,folder,url,version,enabled,interval_seconds) VALUES(?,?,?,'local',?,?,?,1,?,?)`, id, domain, owner, entry.Title, entry.Folder, entry.URL, input.Enabled, input.Interval); err != nil {
|
||||
return err
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
encoded, _ := json.Marshal(ids)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO feed_import_receipts VALUES(?,?,?,?,?)`, domain, owner, input.RequestID, hash, string(encoded))
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"pageswiki/internal/db"
|
||||
)
|
||||
|
||||
func TestFeedMigrationAtomicRepeatAndCleanup(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
// Fail after creating the tables, and verify the entire migration rolls back.
|
||||
broken := append([]db.SQLMigration(nil), feedMigrations...)
|
||||
broken[0].Statements = append(append([]string(nil), feedMigrations[0].Statements...), `INSERT INTO no_such_feed_table VALUES(1)`)
|
||||
if e := db.ApplySQLiteMigrations(ctx, st.DB, "feeds", broken); e == nil {
|
||||
t.Fatal("expected injected failure")
|
||||
}
|
||||
var count int
|
||||
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)
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
if _, e := st.DB.Exec(`PRAGMA foreign_keys=OFF; DELETE FROM feed_sources WHERE uuid='s'`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, table := range []string{"feed_items", "feed_states"} {
|
||||
if e := st.DB.QueryRow(`SELECT count(*) FROM ` + table).Scan(&count); e != nil || count != 0 {
|
||||
t.Fatal("orphan", table, count, e)
|
||||
}
|
||||
}
|
||||
var result string
|
||||
if e := st.DB.QueryRow(`PRAGMA integrity_check`).Scan(&result); e != nil || result != "ok" {
|
||||
t.Fatal(result, e)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedImportReceiptMigrationRollbackAndRepeat(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if err := db.ApplySQLiteMigrations(ctx, st.DB, "feeds", feedMigrations[:2]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := 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',7,1,300)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
broken := append([]db.SQLMigration(nil), feedMigrations...)
|
||||
broken[2].Statements = append(append([]string(nil), feedMigrations[2].Statements...), `INSERT INTO no_such_feed_table VALUES(1)`)
|
||||
if err := db.ApplySQLiteMigrations(ctx, st.DB, "feeds", broken); err == nil {
|
||||
t.Fatal("expected v3 failure")
|
||||
}
|
||||
var count int
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM sqlite_master WHERE name='feed_import_receipts'`).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatal("partial migration", count, err)
|
||||
}
|
||||
if err := st.ensureSchemaComponent("feeds"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := st.DB.Exec(`INSERT INTO feed_import_receipts VALUES('d','u','request','hash','["s"]')`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := st.ensureSchemaComponent("feeds"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := st.DB.QueryRow(`SELECT version FROM feed_sources WHERE uuid='s'`).Scan(&count); err != nil || count != 7 {
|
||||
t.Fatal("unrelated data changed", count, err)
|
||||
}
|
||||
if _, err := st.DB.Exec(`DELETE FROM feed_sources WHERE uuid='s'`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM feed_import_receipts`).Scan(&count); err != nil || count != 1 {
|
||||
t.Fatal("receipt must survive deletion", count, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeedCatalogMigrationRollbackAndRepeat(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if e := db.ApplySQLiteMigrations(ctx, st.DB, "feeds", feedMigrations[:3]); 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,lease,next_ms) VALUES('s','d','u','freshrss','Title','','https://example.org',7,1,300,'old',999); INSERT INTO feed_items(source_uuid,id,title,url,body,published_ms,feed,folder,is_read,starred,body_html) VALUES('s','i','Title','','Body',1,'','',1,1,'<p>Body</p>')`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
broken := append([]db.SQLMigration(nil), feedMigrations...)
|
||||
broken[3].Statements = append(append([]string(nil), feedMigrations[3].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_items') WHERE name='remote_feed'`).Scan(&count); e != nil || count != 0 {
|
||||
t.Fatal("partial migration", count, e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT version FROM feed_sources WHERE uuid='s'`).Scan(&count); e != nil || count != 7 {
|
||||
t.Fatal("partial fence", count, e)
|
||||
}
|
||||
for range 2 {
|
||||
if e := st.ensureSchemaComponent("feeds"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
var version, next int
|
||||
var catalog, lease, body string
|
||||
var read, star bool
|
||||
if e := st.DB.QueryRow(`SELECT version,next_ms,lease,remote_catalog FROM feed_sources WHERE uuid='s'`).Scan(&version, &next, &lease, &catalog); e != nil || version != 8 || next != 0 || lease != "" || catalog != "[]" {
|
||||
t.Fatal(version, next, lease, catalog, e)
|
||||
}
|
||||
if e := st.DB.QueryRow(`SELECT body_html,is_read,starred FROM feed_items WHERE source_uuid='s'`).Scan(&body, &read, &star); e != nil || body != "<p>Body</p>" || !read || !star {
|
||||
t.Fatal("lost old cache", body, read, star, e)
|
||||
}
|
||||
var integrity string
|
||||
if e := st.DB.QueryRow(`PRAGMA integrity_check`).Scan(&integrity); e != nil || integrity != "ok" {
|
||||
t.Fatal(integrity, e)
|
||||
}
|
||||
}
|
||||
@@ -21,13 +21,13 @@ func DefaultDashboard() []DashboardWidget {
|
||||
}
|
||||
|
||||
func ValidateDashboard(items []DashboardWidget) error {
|
||||
if len(items) > 6 {
|
||||
if len(items) > 7 {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, item := range items {
|
||||
switch item.ID {
|
||||
case "progress", "today", "tomorrow", "tasks", "schedule", "activity":
|
||||
case "progress", "today", "tomorrow", "tasks", "schedule", "activity", "feeds":
|
||||
default:
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
// Once released, add a new version; never edit an applied definition.
|
||||
// Auth, City, tasks and calendars remain in their existing migration paths.
|
||||
var managedStoreSchemas = map[string][]db.SQLMigration{
|
||||
"feeds": feedMigrations,
|
||||
"contacts": contactMigrations,
|
||||
"task-productivity": taskProductivityMigrations,
|
||||
"cli-auth": cliAuthMigrations,
|
||||
|
||||
@@ -110,6 +110,88 @@ func TestDashboardUpgradePreservesTaskPreferences(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkHistoryUpgradePreservesLegacySessions(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
if err := db.ApplySQLiteMigrations(context.Background(), st.DB, "task-productivity", taskProductivityMigrations[:2]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := st.DB.Exec(`INSERT INTO organizer_work_sessions VALUES('w','d','u','t',100,200,2)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for range 2 {
|
||||
if err := st.ensureSchemaComponent("task-productivity"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var start, end, version, cancelled int64
|
||||
if err := st.DB.QueryRow(`SELECT start_ms,end_ms,version,cancelled_ms FROM organizer_work_sessions WHERE uuid='w'`).Scan(&start, &end, &version, &cancelled); err != nil || start != 100 || end != 200 || version != 2 || cancelled != 0 {
|
||||
t.Fatal(start, end, version, cancelled, err)
|
||||
}
|
||||
var count int
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM organizer_work_revisions`).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatal("invented history", count, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDigestHistoryUpgradePreservesReservations(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if err := db.ApplySQLiteMigrations(ctx, st.DB, "task-productivity", taskProductivityMigrations[:3]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, state := range []string{"sent", "sending", "uncertain", "cancelled"} {
|
||||
if _, err := st.DB.Exec(`INSERT INTO organizer_digest_deliveries VALUES(?,?,?, ?,?)`, "d", state, "2026-11-01", state, 100+i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for range 2 {
|
||||
if err := st.ensureSchemaComponent("task-productivity"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var count int
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM organizer_digest_deliveries d JOIN organizer_digest_attempts a ON a.uuid=d.attempt_uuid AND a.domain_uuid=d.domain_uuid AND a.owner_uuid=d.owner_uuid AND a.day=d.day AND a.state=d.state AND a.updated_ms=d.updated_ms WHERE a.kind='legacy' AND a.preference_version=0`).Scan(&count); err != nil || count != 4 {
|
||||
t.Fatal("reservation migration", count, err)
|
||||
}
|
||||
var integrity string
|
||||
if err := st.DB.QueryRow(`PRAGMA integrity_check`).Scan(&integrity); err != nil || integrity != "ok" {
|
||||
t.Fatal(integrity, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDigestHistoryMigrationRollback(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if err := db.ApplySQLiteMigrations(ctx, st.DB, "task-productivity", taskProductivityMigrations[:3]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := st.DB.Exec(`INSERT INTO organizer_digest_deliveries VALUES('d','u','2026-11-01','sent',123)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
steps := append([]db.SQLMigration(nil), taskProductivityMigrations...)
|
||||
steps[3].Statements = append(append([]string(nil), steps[3].Statements...), `INVALID MIGRATION STATEMENT`)
|
||||
if err := db.ApplySQLiteMigrations(ctx, st.DB, "task-productivity", steps); err == nil {
|
||||
t.Fatal("failed migration committed")
|
||||
}
|
||||
var columns, ledger, attempts int
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM pragma_table_info('organizer_digest_deliveries')`).Scan(&columns); err != nil || columns != 5 {
|
||||
t.Fatal("DDL not rolled back", columns, err)
|
||||
}
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM schema_migration_steps WHERE component='task-productivity'`).Scan(&ledger); err != nil || ledger != 3 {
|
||||
t.Fatal(ledger, err)
|
||||
}
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM sqlite_master WHERE name='organizer_digest_attempts'`).Scan(&attempts); err != nil || attempts != 0 {
|
||||
t.Fatal(attempts, err)
|
||||
}
|
||||
var state string
|
||||
if err := st.DB.QueryRow(`SELECT state FROM organizer_digest_deliveries`).Scan(&state); err != nil || state != "sent" {
|
||||
t.Fatal(state, err)
|
||||
}
|
||||
if err := st.ensureSchemaComponent("task-productivity"); err != nil {
|
||||
t.Fatal("retry migration", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagedSchemasFreshRepeatAndReadOnly(t *testing.T) {
|
||||
for component := range managedStoreSchemas {
|
||||
t.Run(component, func(t *testing.T) {
|
||||
|
||||
@@ -111,6 +111,9 @@ func NewWithDocumentRoot(
|
||||
if err := st.ensureSchemaComponent("contacts"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := st.ensureSchemaComponent("feeds"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := st.EnsureBrowserNavigationSchema(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"html"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
@@ -34,11 +35,18 @@ func ValidTaskWikiPrefix(p string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// A request UUID suffix separates equal subjects and makes the target stable.
|
||||
// The CLI derives the request UUID from origin, user and Message-ID (or a raw
|
||||
// mail hash). Keep subjects in the title, never in the URL's identity segment.
|
||||
func TaskCaptureWikiPath(prefix, title, request string) string {
|
||||
item := TaskRecord{Title: title, UUID: request}
|
||||
name := path.Base(TaskNotePath("", TaskRecord{}, item))
|
||||
return strings.TrimRight(prefix, "/") + "/" + name + "--" + request
|
||||
return strings.TrimRight(prefix, "/") + "/mail-" + request
|
||||
}
|
||||
|
||||
var mailListSuffix = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]{0,99}/(0|[1-9][0-9]{0,19})$`)
|
||||
var mailMonthSuffix = regexp.MustCompile(`^[0-9]{4}/(0[1-9]|1[0-2])/([0-9a-f]{64}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`)
|
||||
|
||||
// Only the two mail layouts are accepted; no arbitrary relative path traversal.
|
||||
func ValidTaskMailSuffix(s string) bool {
|
||||
return mailListSuffix.MatchString(s) || (mailMonthSuffix.MatchString(s) && !strings.HasPrefix(s, "0000/"))
|
||||
}
|
||||
|
||||
func (s *Store) createCapturedTaskWiki(ctx context.Context, tx *sql.Tx, domain, actor string, item *TaskRecord, target, body string) error {
|
||||
@@ -65,7 +73,7 @@ func (s *Store) createCapturedTaskWiki(ctx context.Context, tx *sql.Tx, domain,
|
||||
}
|
||||
content := "<h1>" + escape(item.Title) + "</h1>\n<pre>" + escape(body) + "</pre>\n"
|
||||
now := time.Now()
|
||||
rev := &Revision{UUID: uuid.NewString(), ObjectUUID: item.PageUUID, DocumentHash: revisionHash(content), Language: "und", ContentType: "text/html; charset=utf-8", Body: content, Message: "Capture mail as task Wiki", CreatedAt: now.Unix(), CreatedAtMS: now.UnixMilli()}
|
||||
rev := &Revision{UUID: uuid.NewString(), ObjectUUID: item.PageUUID, DocumentHash: revisionHash(content), Language: "und", ContentType: "text/html; charset=utf-8", Body: content, Message: "Capture attributed text as Wiki", CreatedAt: now.Unix(), CreatedAtMS: now.UnixMilli()}
|
||||
if err := s.persistDocument(rev.DocumentHash, rev.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const TaskDigestEventType = "task.digest.deliver"
|
||||
@@ -16,9 +18,10 @@ type TaskDigestDue struct {
|
||||
}
|
||||
type TaskDigestClaim struct {
|
||||
TaskDigestDue
|
||||
Day string
|
||||
Version int64
|
||||
Timezone string
|
||||
Day string
|
||||
Version int64
|
||||
Timezone string
|
||||
AttemptUUID string
|
||||
}
|
||||
|
||||
func (s *Store) EnsureTaskDigestEvent() error {
|
||||
@@ -124,11 +127,17 @@ func (s *Store) ClaimTaskDigest(ctx context.Context, due TaskDigestDue, now time
|
||||
}
|
||||
return out, sql.ErrNoRows
|
||||
}
|
||||
res, err = tx.ExecContext(ctx, `INSERT OR IGNORE INTO organizer_digest_deliveries VALUES(?,?,?,'sending',?)`, due.Domain, due.Owner, out.Day, now.UnixMilli())
|
||||
out.AttemptUUID = uuid.NewString()
|
||||
res, err = tx.ExecContext(ctx, `INSERT OR IGNORE INTO organizer_digest_deliveries(domain_uuid,owner_uuid,day,state,updated_ms,attempt_uuid) VALUES(?,?,?,'sending',?,?)`, due.Domain, due.Owner, out.Day, now.UnixMilli(), out.AttemptUUID)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
n, _ = res.RowsAffected()
|
||||
if n == 1 {
|
||||
if err = insertDigestAttempt(ctx, tx, out, "scheduled", "sending", now); err != nil {
|
||||
return out, err
|
||||
}
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return out, err
|
||||
}
|
||||
@@ -139,12 +148,20 @@ func (s *Store) ClaimTaskDigest(ctx context.Context, due TaskDigestDue, now time
|
||||
}
|
||||
|
||||
func (s *Store) TaskDigestRecipient(ctx context.Context, c TaskDigestClaim) (string, error) {
|
||||
if err := taskActor(ctx, s.DB, c.Domain, c.Owner, true); err != nil {
|
||||
if s.ReadOnly {
|
||||
return "", ErrReadOnly
|
||||
}
|
||||
tx, err := s.DB.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if err := taskActor(ctx, tx, c.Domain, c.Owner, true); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var raw, email string
|
||||
var version int64
|
||||
err := s.DB.QueryRowContext(ctx, `SELECT f.data,f.version,p.email FROM organizer_task_preferences f JOIN principals p ON p.uuid=f.owner_uuid WHERE f.domain_uuid=? AND f.owner_uuid=?`, c.Domain, c.Owner).Scan(&raw, &version, &email)
|
||||
err = tx.QueryRowContext(ctx, `SELECT f.data,f.version,p.email FROM organizer_task_preferences f JOIN principals p ON p.uuid=f.owner_uuid JOIN organizer_digest_deliveries d ON d.domain_uuid=f.domain_uuid AND d.owner_uuid=f.owner_uuid JOIN organizer_digest_attempts a ON a.uuid=d.attempt_uuid WHERE f.domain_uuid=? AND f.owner_uuid=? AND d.day=? AND d.attempt_uuid=? AND d.state='sending' AND a.state='sending' AND a.updated_ms>?`, c.Domain, c.Owner, c.Day, c.AttemptUUID, time.Now().Add(-2*time.Minute).UnixMilli()).Scan(&raw, &version, &email)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -152,15 +169,22 @@ func (s *Store) TaskDigestRecipient(ctx context.Context, c TaskDigestClaim) (str
|
||||
if json.Unmarshal([]byte(raw), &p) != nil || !p.DigestEnabled || version != c.Version {
|
||||
return "", ErrAccessDenied
|
||||
}
|
||||
return email, nil
|
||||
loc, err := time.LoadLocation(c.Timezone)
|
||||
if err != nil || time.Now().In(loc).Format("2006-01-02") != c.Day {
|
||||
return "", ErrAccessDenied
|
||||
}
|
||||
on, err := taskReminderExtensionEnabled(ctx, tx, c.Domain)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !on {
|
||||
return "", ErrAccessDenied
|
||||
}
|
||||
return email, tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Store) FinishTaskDigest(ctx context.Context, c TaskDigestClaim, state string) error {
|
||||
if state != "sent" && state != "uncertain" && state != "cancelled" {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
_, err := s.DB.ExecContext(ctx, `UPDATE organizer_digest_deliveries SET state=?,updated_ms=? WHERE domain_uuid=? AND owner_uuid=? AND day=? AND state='sending'`, state, time.Now().UnixMilli(), c.Domain, c.Owner, c.Day)
|
||||
return err
|
||||
return s.FinishTaskDigestReason(ctx, c, state, "", time.Now())
|
||||
}
|
||||
|
||||
func (s *Store) LastTaskDigest(ctx context.Context, domain, actor string) (map[string]any, error) {
|
||||
|
||||
@@ -0,0 +1,382 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const TaskDigestRetentionDays = 90
|
||||
|
||||
type TaskDigestAttempt struct {
|
||||
UUID string `json:"uuid"`
|
||||
Day string `json:"day"`
|
||||
Kind string `json:"kind"`
|
||||
State string `json:"state"`
|
||||
Reason string `json:"reason"`
|
||||
Timezone string `json:"timezone"`
|
||||
CreatedMS int64 `json:"created_ms"`
|
||||
UpdatedMS int64 `json:"updated_ms"`
|
||||
}
|
||||
type TaskDigestRetry struct {
|
||||
RequestID string `json:"request_id"`
|
||||
Day string `json:"day"`
|
||||
ExpectedAttempt string `json:"expected_attempt"`
|
||||
DuplicateAcknowledged bool `json:"duplicate_acknowledged"`
|
||||
}
|
||||
type TaskDigestHistory struct {
|
||||
Items []TaskDigestAttempt `json:"items"`
|
||||
Next string `json:"next"`
|
||||
Today string `json:"today"`
|
||||
Current *TaskDigestAttempt `json:"current"`
|
||||
Retries int `json:"retries"`
|
||||
Enabled bool `json:"enabled"`
|
||||
RetentionDays int `json:"retention_days"`
|
||||
}
|
||||
|
||||
const digestAttemptColumns = `uuid,day,kind,state,reason,timezone,created_ms,updated_ms`
|
||||
|
||||
func scanDigestAttempt(row interface{ Scan(...any) error }) (TaskDigestAttempt, error) {
|
||||
var v TaskDigestAttempt
|
||||
err := row.Scan(&v.UUID, &v.Day, &v.Kind, &v.State, &v.Reason, &v.Timezone, &v.CreatedMS, &v.UpdatedMS)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func insertDigestAttempt(ctx context.Context, tx *sql.Tx, c TaskDigestClaim, kind, state string, now time.Time) error {
|
||||
_, err := tx.ExecContext(ctx, `INSERT INTO organizer_digest_attempts(uuid,domain_uuid,owner_uuid,day,kind,state,preference_version,timezone,created_ms,updated_ms) VALUES(?,?,?,?,?,?,?,?,?,?)`, c.AttemptUUID, c.Domain, c.Owner, c.Day, kind, state, c.Version, c.Timezone, now.UnixMilli(), now.UnixMilli())
|
||||
return err
|
||||
}
|
||||
|
||||
// Receipt lookup is read-only. It lets clients confirm an accepted request even
|
||||
// when SMTP is subsequently disabled; it never reactivates a delivery.
|
||||
func (s *Store) TaskDigestRetryReceipt(ctx context.Context, domain, actor string, input TaskDigestRetry) (string, error) {
|
||||
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
return "", err
|
||||
}
|
||||
id, err := uuid.Parse(input.RequestID)
|
||||
if err != nil || id.String() != input.RequestID {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
var day, expected string
|
||||
var ack bool
|
||||
err = s.DB.QueryRowContext(ctx, `SELECT day,expected_attempt,duplicate_ack FROM organizer_digest_requests WHERE uuid=? AND domain_uuid=? AND owner_uuid=?`, input.RequestID, domain, actor).Scan(&day, &expected, &ack)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if day != input.Day || expected != input.ExpectedAttempt || ack != input.DuplicateAcknowledged {
|
||||
return "", ErrTaskConflict
|
||||
}
|
||||
return input.RequestID, nil
|
||||
}
|
||||
|
||||
// A retry is durable queue admission, never an SMTP send in a browser request.
|
||||
// Keep request receipts and daily reservations even after detail retention.
|
||||
func (s *Store) QueueTaskDigestRetry(ctx context.Context, domain, actor string, input TaskDigestRetry, now time.Time) (string, error) {
|
||||
if s.ReadOnly {
|
||||
return "", ErrReadOnly
|
||||
}
|
||||
id, err := uuid.Parse(input.RequestID)
|
||||
if err != nil || id.String() != input.RequestID {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if err = taskProductivityWriter(ctx, tx, domain, actor); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var oldDomain, oldOwner, oldDay, oldExpected string
|
||||
var oldAck bool
|
||||
err = tx.QueryRowContext(ctx, `SELECT domain_uuid,owner_uuid,day,expected_attempt,duplicate_ack FROM organizer_digest_requests WHERE uuid=?`, input.RequestID).Scan(&oldDomain, &oldOwner, &oldDay, &oldExpected, &oldAck)
|
||||
if err == nil {
|
||||
if oldDomain != domain || oldOwner != actor || oldDay != input.Day || oldExpected != input.ExpectedAttempt || oldAck != input.DuplicateAcknowledged {
|
||||
return "", ErrTaskConflict
|
||||
}
|
||||
return input.RequestID, tx.Commit()
|
||||
}
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
return "", err
|
||||
}
|
||||
var raw string
|
||||
if err = tx.QueryRowContext(ctx, `SELECT data FROM organizer_task_preferences WHERE domain_uuid=? AND owner_uuid=?`, domain, actor).Scan(&raw); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var p TaskPreferences
|
||||
if err = json.Unmarshal([]byte(raw), &p); err != nil {
|
||||
return "", err
|
||||
}
|
||||
loc, err := time.LoadLocation(p.Timezone)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !p.DigestEnabled {
|
||||
return "", ErrAccessDenied
|
||||
}
|
||||
if input.Day != now.In(loc).Format("2006-01-02") {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
var state, current string
|
||||
if err = tx.QueryRowContext(ctx, `SELECT state,attempt_uuid FROM organizer_digest_deliveries WHERE domain_uuid=? AND owner_uuid=? AND day=?`, domain, actor, input.Day).Scan(&state, ¤t); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if current != input.ExpectedAttempt || state == "queued" || state == "sending" {
|
||||
return "", ErrTaskConflict
|
||||
}
|
||||
if state != "sent" && state != "uncertain" && state != "cancelled" {
|
||||
return "", ErrTaskConflict
|
||||
}
|
||||
if (state == "sent" || state == "uncertain") && !input.DuplicateAcknowledged {
|
||||
return "", ErrTaskInvalid
|
||||
}
|
||||
var count int
|
||||
if err = tx.QueryRowContext(ctx, `SELECT count(*) FROM organizer_digest_requests WHERE domain_uuid=? AND owner_uuid=? AND day=?`, domain, actor, input.Day).Scan(&count); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if count >= 5 {
|
||||
return "", ErrTaskConflict
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_digest_requests VALUES(?,?,?,?,?,?,?)`, input.RequestID, domain, actor, input.Day, input.ExpectedAttempt, input.DuplicateAcknowledged, now.UnixMilli())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
c := TaskDigestClaim{TaskDigestDue: TaskDigestDue{domain, actor}, Day: input.Day, Version: p.Version, Timezone: p.Timezone, AttemptUUID: input.RequestID}
|
||||
if err = insertDigestAttempt(ctx, tx, c, "manual", "queued", now); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE organizer_digest_deliveries SET state='queued',attempt_uuid=?,updated_ms=? WHERE domain_uuid=? AND owner_uuid=? AND day=?`, c.AttemptUUID, now.UnixMilli(), domain, actor, input.Day); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return c.AttemptUUID, tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Store) QueuedTaskDigests(ctx context.Context) ([]TaskDigestClaim, error) {
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT uuid,domain_uuid,owner_uuid,day,preference_version,timezone FROM organizer_digest_attempts WHERE state='queued' ORDER BY updated_ms,uuid LIMIT 10`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []TaskDigestClaim{}
|
||||
for rows.Next() {
|
||||
var c TaskDigestClaim
|
||||
if err = rows.Scan(&c.AttemptUUID, &c.Domain, &c.Owner, &c.Day, &c.Version, &c.Timezone); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, c)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func (s *Store) ClaimQueuedTaskDigest(ctx context.Context, c TaskDigestClaim, now time.Time) (TaskDigestClaim, error) {
|
||||
if s.ReadOnly {
|
||||
return c, ErrReadOnly
|
||||
}
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
res, err := tx.ExecContext(ctx, `UPDATE organizer_digest_attempts SET state='sending',updated_ms=? WHERE uuid=? AND domain_uuid=? AND owner_uuid=? AND state='queued' AND EXISTS(SELECT 1 FROM organizer_digest_deliveries d WHERE d.domain_uuid=? AND d.owner_uuid=? AND d.day=? AND d.attempt_uuid=? AND d.state='queued')`, now.UnixMilli(), c.AttemptUUID, c.Domain, c.Owner, c.Domain, c.Owner, c.Day, c.AttemptUUID)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
n, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
if n != 1 {
|
||||
return c, sql.ErrNoRows
|
||||
}
|
||||
// Reload all claim fields from the queue, not from an earlier enumeration.
|
||||
if err = tx.QueryRowContext(ctx, `SELECT day,preference_version,timezone FROM organizer_digest_attempts WHERE uuid=?`, c.AttemptUUID).Scan(&c.Day, &c.Version, &c.Timezone); err != nil {
|
||||
return c, err
|
||||
}
|
||||
state, reason := "sending", ""
|
||||
allowed := taskActor(ctx, tx, c.Domain, c.Owner, true)
|
||||
if allowed != nil && !errors.Is(allowed, ErrAccessDenied) {
|
||||
return c, allowed
|
||||
}
|
||||
on, err := taskReminderExtensionEnabled(ctx, tx, c.Domain)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
var raw string
|
||||
err = tx.QueryRowContext(ctx, `SELECT data FROM organizer_task_preferences WHERE domain_uuid=? AND owner_uuid=?`, c.Domain, c.Owner).Scan(&raw)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return c, err
|
||||
}
|
||||
var p TaskPreferences
|
||||
if err == nil {
|
||||
if err = json.Unmarshal([]byte(raw), &p); err != nil {
|
||||
return c, err
|
||||
}
|
||||
}
|
||||
if allowed != nil || !on || !p.DigestEnabled || p.Version != c.Version {
|
||||
state, reason = "cancelled", "consent_changed"
|
||||
}
|
||||
loc, e := time.LoadLocation(c.Timezone)
|
||||
if e != nil || now.In(loc).Format("2006-01-02") != c.Day {
|
||||
state, reason = "cancelled", "day_expired"
|
||||
}
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE organizer_digest_attempts SET state=?,reason=? WHERE uuid=?`, state, reason, c.AttemptUUID); err != nil {
|
||||
return c, err
|
||||
}
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE organizer_digest_deliveries SET state=?,updated_ms=? WHERE domain_uuid=? AND owner_uuid=? AND day=? AND attempt_uuid=?`, state, now.UnixMilli(), c.Domain, c.Owner, c.Day, c.AttemptUUID); err != nil {
|
||||
return c, err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return c, err
|
||||
}
|
||||
if state != "sending" {
|
||||
return c, sql.ErrNoRows
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (s *Store) FinishTaskDigestReason(ctx context.Context, c TaskDigestClaim, state, reason string, now time.Time) error {
|
||||
if s.ReadOnly {
|
||||
return ErrReadOnly
|
||||
}
|
||||
if state != "sent" && state != "uncertain" && state != "cancelled" {
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
switch reason {
|
||||
case "", "smtp_unavailable", "tasks_unavailable", "consent_changed", "transport_uncertain", "extension_disabled":
|
||||
default:
|
||||
return ErrTaskInvalid
|
||||
}
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
res, err := tx.ExecContext(ctx, `UPDATE organizer_digest_deliveries SET state=?,updated_ms=? WHERE domain_uuid=? AND owner_uuid=? AND day=? AND attempt_uuid=? AND state='sending'`, state, now.UnixMilli(), c.Domain, c.Owner, c.Day, c.AttemptUUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n != 1 {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
res, err = tx.ExecContext(ctx, `UPDATE organizer_digest_attempts SET state=?,reason=?,updated_ms=? WHERE uuid=? AND state='sending'`, state, reason, now.UnixMilli(), c.AttemptUUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err = res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n != 1 {
|
||||
return ErrTaskConflict
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Store) TaskDigestHistory(ctx context.Context, domain, actor, after string, limit int, now time.Time) (TaskDigestHistory, error) {
|
||||
out := TaskDigestHistory{Items: []TaskDigestAttempt{}, RetentionDays: TaskDigestRetentionDays}
|
||||
p, err := s.TaskPreferences(ctx, domain, actor)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
loc, err := time.LoadLocation(p.Timezone)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
out.Today = now.In(loc).Format("2006-01-02")
|
||||
out.Enabled = p.DigestEnabled
|
||||
if limit < 1 || limit > 100 {
|
||||
return out, ErrTaskInvalid
|
||||
}
|
||||
query := `SELECT ` + digestAttemptColumns + ` FROM organizer_digest_attempts WHERE domain_uuid=? AND owner_uuid=?`
|
||||
args := []any{domain, actor}
|
||||
if after != "" {
|
||||
if len(after) > 256 {
|
||||
return out, ErrTaskInvalid
|
||||
}
|
||||
var cursor struct {
|
||||
MS int64
|
||||
ID string
|
||||
}
|
||||
raw, e := base64.RawURLEncoding.DecodeString(after)
|
||||
if e != nil || json.Unmarshal(raw, &cursor) != nil || cursor.MS < 0 || len(cursor.ID) > 80 || cursor.ID == "" {
|
||||
return out, ErrTaskInvalid
|
||||
}
|
||||
query += ` AND (created_ms,uuid)<(?,?)`
|
||||
args = append(args, cursor.MS, cursor.ID)
|
||||
}
|
||||
query += ` ORDER BY created_ms DESC,uuid DESC LIMIT ?`
|
||||
args = append(args, limit+1)
|
||||
rows, err := s.DB.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
for rows.Next() {
|
||||
v, e := scanDigestAttempt(rows)
|
||||
if e != nil {
|
||||
rows.Close()
|
||||
return out, e
|
||||
}
|
||||
out.Items = append(out.Items, v)
|
||||
}
|
||||
err = rows.Err()
|
||||
rows.Close()
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
if len(out.Items) > limit {
|
||||
out.Items = out.Items[:limit]
|
||||
last := out.Items[limit-1]
|
||||
raw, _ := json.Marshal(struct {
|
||||
MS int64
|
||||
ID string
|
||||
}{last.CreatedMS, last.UUID})
|
||||
out.Next = base64.RawURLEncoding.EncodeToString(raw)
|
||||
}
|
||||
current, e := scanDigestAttempt(s.DB.QueryRowContext(ctx, `SELECT `+digestAttemptColumns+` FROM organizer_digest_attempts WHERE uuid=(SELECT attempt_uuid FROM organizer_digest_deliveries WHERE domain_uuid=? AND owner_uuid=? AND day=?)`, domain, actor, out.Today))
|
||||
if e == nil {
|
||||
out.Current = ¤t
|
||||
} else if !errors.Is(e, sql.ErrNoRows) {
|
||||
return out, e
|
||||
}
|
||||
err = s.DB.QueryRowContext(ctx, `SELECT count(*) FROM organizer_digest_requests WHERE domain_uuid=? AND owner_uuid=? AND day=?`, domain, actor, out.Today).Scan(&out.Retries)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// Only detailed terminal attempts expire. Reservations and request receipts are
|
||||
// permanent deduplication state; retention must never delete them.
|
||||
func (s *Store) MaintainTaskDigests(ctx context.Context, now time.Time) (int64, error) {
|
||||
if s.ReadOnly {
|
||||
return 0, ErrReadOnly
|
||||
}
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
_, err = tx.ExecContext(ctx, `UPDATE organizer_digest_attempts SET state='uncertain',reason='worker_interrupted',updated_ms=? WHERE uuid IN (SELECT uuid FROM organizer_digest_attempts WHERE state='sending' AND updated_ms<? ORDER BY updated_ms,uuid LIMIT 100)`, now.UnixMilli(), now.Add(-10*time.Minute).UnixMilli())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `UPDATE organizer_digest_deliveries SET state='uncertain',updated_ms=? WHERE state='sending' AND attempt_uuid IN (SELECT uuid FROM organizer_digest_attempts WHERE state='uncertain' AND reason='worker_interrupted' AND updated_ms=?)`, now.UnixMilli(), now.UnixMilli())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
res, err := tx.ExecContext(ctx, `DELETE FROM organizer_digest_attempts WHERE uuid IN (SELECT uuid FROM organizer_digest_attempts WHERE state IN ('sent','uncertain','cancelled') AND updated_ms<? ORDER BY updated_ms,uuid LIMIT 500)`, now.Add(-TaskDigestRetentionDays*24*time.Hour).UnixMilli())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
n, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return n, tx.Commit()
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -28,7 +29,36 @@ var taskProductivityMigrations = []db.SQLMigration{{Version: 1, Name: "task_capt
|
||||
schemaIndex("organizer_work_sessions", "organizer_work_period", "domain_uuid,owner_uuid,start_ms,uuid"),
|
||||
}}, {Version: 2, Name: "personal_dashboard_layout", Statements: []string{
|
||||
`CREATE TABLE organizer_dashboard_layouts(domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,version INTEGER NOT NULL,data TEXT NOT NULL,PRIMARY KEY(domain_uuid,owner_uuid))`,
|
||||
}, Assertions: []string{schemaColumns("organizer_dashboard_layouts", "domain_uuid,owner_uuid,version,data"), schemaUnique("organizer_dashboard_layouts", "domain_uuid,owner_uuid")}}}
|
||||
}, Assertions: []string{schemaColumns("organizer_dashboard_layouts", "domain_uuid,owner_uuid,version,data"), schemaUnique("organizer_dashboard_layouts", "domain_uuid,owner_uuid")}}, {
|
||||
Version: 3, Name: "work_corrections_and_audit",
|
||||
AddColumns: []db.SQLiteColumn{{Table: "organizer_work_sessions", Name: "cancelled_ms", Declaration: "INTEGER NOT NULL DEFAULT 0"}},
|
||||
Statements: []string{`CREATE TABLE organizer_work_revisions(work_uuid TEXT NOT NULL,version INTEGER NOT NULL,domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,action TEXT NOT NULL,reason TEXT NOT NULL,changed_ms INTEGER NOT NULL,data TEXT NOT NULL,PRIMARY KEY(work_uuid,version))`, `CREATE INDEX organizer_work_owner_period ON organizer_work_sessions(owner_uuid,start_ms,uuid)`},
|
||||
Assertions: []string{schemaColumns("organizer_work_sessions", "uuid,domain_uuid,owner_uuid,task_uuid,start_ms,end_ms,version,cancelled_ms"), schemaUnique("organizer_work_revisions", "work_uuid,version"), schemaUnique("organizer_dashboard_layouts", "domain_uuid,owner_uuid")},
|
||||
}, {
|
||||
Version: 4, Name: "digest_attempts_and_retry_receipts",
|
||||
Statements: []string{
|
||||
`ALTER TABLE organizer_digest_deliveries ADD COLUMN attempt_uuid TEXT NOT NULL DEFAULT ''`,
|
||||
`CREATE INDEX organizer_digest_delivery_state ON organizer_digest_deliveries(state,attempt_uuid)`,
|
||||
`CREATE TABLE organizer_digest_attempts(uuid TEXT PRIMARY KEY,domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,day TEXT NOT NULL,kind TEXT NOT NULL,state TEXT NOT NULL,preference_version INTEGER NOT NULL,timezone TEXT NOT NULL,reason TEXT NOT NULL DEFAULT '',created_ms INTEGER NOT NULL,updated_ms INTEGER NOT NULL)`,
|
||||
`CREATE INDEX organizer_digest_history ON organizer_digest_attempts(domain_uuid,owner_uuid,created_ms,uuid)`,
|
||||
`CREATE INDEX organizer_digest_pending ON organizer_digest_attempts(state,updated_ms,uuid)`,
|
||||
`CREATE TABLE organizer_digest_requests(uuid TEXT PRIMARY KEY,domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,day TEXT NOT NULL,expected_attempt TEXT NOT NULL,duplicate_ack INTEGER NOT NULL,created_ms INTEGER NOT NULL)`,
|
||||
`CREATE INDEX organizer_digest_request_day ON organizer_digest_requests(domain_uuid,owner_uuid,day)`,
|
||||
`UPDATE organizer_digest_deliveries SET attempt_uuid='legacy-'||lower(hex(randomblob(16)))`,
|
||||
`INSERT INTO organizer_digest_attempts SELECT attempt_uuid,domain_uuid,owner_uuid,day,'legacy',state,0,'','legacy',updated_ms,updated_ms FROM organizer_digest_deliveries`,
|
||||
}, Assertions: []string{
|
||||
schemaColumns("organizer_work_sessions", "uuid,domain_uuid,owner_uuid,task_uuid,start_ms,end_ms,version,cancelled_ms"),
|
||||
schemaUnique("organizer_work_revisions", "work_uuid,version"),
|
||||
schemaUnique("organizer_dashboard_layouts", "domain_uuid,owner_uuid"),
|
||||
schemaColumns("organizer_digest_deliveries", "domain_uuid,owner_uuid,day,state,updated_ms,attempt_uuid"),
|
||||
schemaUnique("organizer_digest_deliveries", "domain_uuid,owner_uuid,day"),
|
||||
schemaColumns("organizer_digest_attempts", "uuid,domain_uuid,owner_uuid,day,kind,state,preference_version,timezone,reason,created_ms,updated_ms"),
|
||||
schemaUnique("organizer_digest_attempts", "uuid"),
|
||||
schemaIndex("organizer_digest_attempts", "organizer_digest_pending", "state,updated_ms,uuid"),
|
||||
schemaColumns("organizer_digest_requests", "uuid,domain_uuid,owner_uuid,day,expected_attempt,duplicate_ack,created_ms"),
|
||||
schemaUnique("organizer_digest_requests", "uuid"),
|
||||
},
|
||||
}}
|
||||
|
||||
type TaskPreferences struct {
|
||||
Version int64 `json:"version"`
|
||||
@@ -235,20 +265,21 @@ func (s *Store) CaptureTaskWithWiki(ctx context.Context, domain, actor, request,
|
||||
}
|
||||
|
||||
type TaskWork struct {
|
||||
UUID string `json:"uuid"`
|
||||
TaskUUID string `json:"task_uuid"`
|
||||
StartMS int64 `json:"start_ms"`
|
||||
EndMS int64 `json:"end_ms"`
|
||||
Version int64 `json:"version"`
|
||||
UUID string `json:"uuid"`
|
||||
TaskUUID string `json:"task_uuid"`
|
||||
StartMS int64 `json:"start_ms"`
|
||||
EndMS int64 `json:"end_ms"`
|
||||
Version int64 `json:"version"`
|
||||
CancelledMS int64 `json:"cancelled_ms,omitempty"`
|
||||
}
|
||||
|
||||
func scanTaskWork(row interface{ Scan(...any) error }) (TaskWork, error) {
|
||||
var v TaskWork
|
||||
err := row.Scan(&v.UUID, &v.TaskUUID, &v.StartMS, &v.EndMS, &v.Version)
|
||||
err := row.Scan(&v.UUID, &v.TaskUUID, &v.StartMS, &v.EndMS, &v.Version, &v.CancelledMS)
|
||||
return v, err
|
||||
}
|
||||
|
||||
const taskWorkColumns = `uuid,task_uuid,start_ms,end_ms,version`
|
||||
const taskWorkColumns = `uuid,task_uuid,start_ms,end_ms,version,cancelled_ms`
|
||||
|
||||
func (s *Store) ActiveTaskWork(ctx context.Context, domain, actor string) (*TaskWork, error) {
|
||||
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
@@ -261,7 +292,7 @@ func (s *Store) ActiveTaskWork(ctx context.Context, domain, actor string) (*Task
|
||||
return &v, err
|
||||
}
|
||||
|
||||
func (s *Store) ChangeTaskWork(ctx context.Context, domain, actor, action string, v TaskWork, now time.Time) (TaskWork, error) {
|
||||
func (s *Store) ChangeTaskWork(ctx context.Context, domain, actor, action string, v TaskWork, now time.Time, reasons ...string) (TaskWork, error) {
|
||||
if s.ReadOnly {
|
||||
return v, ErrReadOnly
|
||||
}
|
||||
@@ -280,6 +311,16 @@ func (s *Store) ChangeTaskWork(ctx context.Context, domain, actor, action string
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return v, err
|
||||
}
|
||||
if action == "correct" || action == "cancel" {
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
reason := ""
|
||||
if len(reasons) > 0 {
|
||||
reason = reasons[0]
|
||||
}
|
||||
return correctTaskWork(ctx, tx, domain, actor, action, reason, v, old, now)
|
||||
}
|
||||
switch action {
|
||||
case "start":
|
||||
if v.Version != 0 {
|
||||
@@ -300,6 +341,7 @@ func (s *Store) ChangeTaskWork(ctx context.Context, domain, actor, action string
|
||||
}
|
||||
v.StartMS = now.UnixMilli()
|
||||
v.EndMS = 0
|
||||
v.CancelledMS = 0
|
||||
v.Version = 1
|
||||
res, e := tx.ExecContext(ctx, `INSERT OR IGNORE INTO organizer_work_sessions(uuid,domain_uuid,owner_uuid,task_uuid,start_ms) VALUES(?,?,?,?,?)`, v.UUID, domain, actor, v.TaskUUID, v.StartMS)
|
||||
if e != nil {
|
||||
@@ -313,6 +355,9 @@ func (s *Store) ChangeTaskWork(ctx context.Context, domain, actor, action string
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
if old.CancelledMS != 0 {
|
||||
return v, ErrTaskConflict
|
||||
}
|
||||
if old.EndMS > 0 {
|
||||
if v.Version == old.Version || v.Version == old.Version-1 {
|
||||
return old, tx.Commit()
|
||||
@@ -332,6 +377,14 @@ func (s *Store) ChangeTaskWork(ctx context.Context, domain, actor, action string
|
||||
default:
|
||||
return v, ErrTaskInvalid
|
||||
}
|
||||
if action == "stop" {
|
||||
if err = auditTaskWork(ctx, tx, domain, actor, "baseline", "", old, now); err != nil {
|
||||
return v, err
|
||||
}
|
||||
}
|
||||
if err = auditTaskWork(ctx, tx, domain, actor, action, "", v, now); err != nil {
|
||||
return v, err
|
||||
}
|
||||
return v, tx.Commit()
|
||||
}
|
||||
|
||||
@@ -344,19 +397,21 @@ type TaskReportDay struct {
|
||||
FocusMS int64 `json:"focus_ms"`
|
||||
}
|
||||
type TaskReportItem struct {
|
||||
UUID string `json:"uuid"`
|
||||
Title string `json:"title"`
|
||||
ProjectUUID string `json:"project_uuid"`
|
||||
WorkMS int64 `json:"work_ms"`
|
||||
Points int `json:"points"`
|
||||
Completed bool `json:"completed"`
|
||||
UUID string `json:"uuid"`
|
||||
Title string `json:"title"`
|
||||
ProjectUUID string `json:"project_uuid"`
|
||||
ProjectTitle string `json:"project_title"`
|
||||
WorkMS int64 `json:"work_ms"`
|
||||
Points int `json:"points"`
|
||||
Completed bool `json:"completed"`
|
||||
}
|
||||
type TaskReport struct {
|
||||
Days []TaskReportDay `json:"days"`
|
||||
Tasks []TaskReportItem `json:"tasks"`
|
||||
Sessions []TaskWork `json:"sessions"`
|
||||
Partial bool `json:"partial"`
|
||||
Timezone string `json:"timezone"`
|
||||
Days []TaskReportDay `json:"days"`
|
||||
Tasks []TaskReportItem `json:"tasks"`
|
||||
Sessions []TaskWork `json:"sessions"`
|
||||
Partial bool `json:"partial"`
|
||||
Timezone string `json:"timezone"`
|
||||
Projects []TaskReportProject `json:"projects"`
|
||||
}
|
||||
|
||||
func (s *Store) TaskReport(ctx context.Context, domain, actor string, start, end, now time.Time) (TaskReport, error) {
|
||||
@@ -373,7 +428,7 @@ func (s *Store) TaskReport(ctx context.Context, domain, actor string, start, end
|
||||
out.Days = append(out.Days, TaskReportDay{Date: day.Format("2006-01-02")})
|
||||
}
|
||||
byTask := map[string]int{}
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT m.completed_ms,m.estimate,m.complexity,m.task_uuid,COALESCE(i.title,''),COALESCE(i.project_uuid,'') FROM organizer_task_metrics m LEFT JOIN organizer_items i ON i.domain_uuid=m.domain_uuid AND i.owner_uuid=m.owner_uuid AND i.uuid=m.task_uuid WHERE m.domain_uuid=? AND m.owner_uuid=? AND m.completed_ms>=? AND m.completed_ms<? ORDER BY m.completed_ms,m.task_uuid LIMIT 10001`, domain, actor, start.UnixMilli(), end.UnixMilli())
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT m.completed_ms,m.estimate,m.complexity,m.task_uuid,COALESCE(i.title,''),COALESCE(i.project_uuid,''),COALESCE(p.title,'') FROM organizer_task_metrics m LEFT JOIN organizer_items i ON i.domain_uuid=m.domain_uuid AND i.owner_uuid=m.owner_uuid AND i.uuid=m.task_uuid LEFT JOIN organizer_items p ON p.uuid=i.project_uuid AND p.domain_uuid=m.domain_uuid AND p.owner_uuid=m.owner_uuid AND p.kind='project' WHERE m.domain_uuid=? AND m.owner_uuid=? AND m.completed_ms>=? AND m.completed_ms<? ORDER BY m.completed_ms,m.task_uuid LIMIT 10001`, domain, actor, start.UnixMilli(), end.UnixMilli())
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
@@ -381,8 +436,8 @@ func (s *Store) TaskReport(ctx context.Context, domain, actor string, start, end
|
||||
for rows.Next() {
|
||||
var ms int64
|
||||
var estimate, complexity int
|
||||
var id, title, project string
|
||||
if err = rows.Scan(&ms, &estimate, &complexity, &id, &title, &project); err != nil {
|
||||
var id, title, project, projectTitle string
|
||||
if err = rows.Scan(&ms, &estimate, &complexity, &id, &title, &project, &projectTitle); err != nil {
|
||||
rows.Close()
|
||||
return out, err
|
||||
}
|
||||
@@ -397,7 +452,7 @@ func (s *Store) TaskReport(ctx context.Context, domain, actor string, start, end
|
||||
d.Estimate += estimate
|
||||
d.Points += 1 + ((estimate+29)/30)*max(1, complexity)
|
||||
byTask[id] = len(out.Tasks)
|
||||
out.Tasks = append(out.Tasks, TaskReportItem{UUID: id, Title: title, ProjectUUID: project, Completed: true, Points: 1 + ((estimate+29)/30)*max(1, complexity)})
|
||||
out.Tasks = append(out.Tasks, TaskReportItem{UUID: id, Title: title, ProjectUUID: project, ProjectTitle: projectTitle, Completed: true, Points: 1 + ((estimate+29)/30)*max(1, complexity)})
|
||||
}
|
||||
}
|
||||
err = rows.Err()
|
||||
@@ -428,15 +483,15 @@ func (s *Store) TaskReport(ctx context.Context, domain, actor string, start, end
|
||||
}
|
||||
return total
|
||||
}
|
||||
rows, err = s.DB.QueryContext(ctx, `SELECT w.uuid,w.task_uuid,w.start_ms,w.end_ms,w.version,COALESCE(i.title,''),COALESCE(i.project_uuid,'') FROM organizer_work_sessions w LEFT JOIN organizer_items i ON i.domain_uuid=w.domain_uuid AND i.owner_uuid=w.owner_uuid AND i.uuid=w.task_uuid WHERE w.domain_uuid=? AND w.owner_uuid=? AND w.start_ms<? AND (w.end_ms=0 OR w.end_ms>?) ORDER BY w.start_ms DESC,w.uuid LIMIT 10001`, domain, actor, end.UnixMilli(), start.UnixMilli())
|
||||
rows, err = s.DB.QueryContext(ctx, `SELECT w.uuid,w.task_uuid,w.start_ms,w.end_ms,w.version,COALESCE(i.title,''),COALESCE(i.project_uuid,''),COALESCE(p.title,'') FROM organizer_work_sessions w LEFT JOIN organizer_items i ON i.domain_uuid=w.domain_uuid AND i.owner_uuid=w.owner_uuid AND i.uuid=w.task_uuid LEFT JOIN organizer_items p ON p.uuid=i.project_uuid AND p.domain_uuid=w.domain_uuid AND p.owner_uuid=w.owner_uuid AND p.kind='project' WHERE w.cancelled_ms=0 AND w.domain_uuid=? AND w.owner_uuid=? AND w.start_ms<? AND (w.end_ms=0 OR w.end_ms>?) ORDER BY w.start_ms DESC,w.uuid LIMIT 10001`, domain, actor, end.UnixMilli(), start.UnixMilli())
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
n = 0
|
||||
for rows.Next() {
|
||||
var v TaskWork
|
||||
var title, project string
|
||||
if err = rows.Scan(&v.UUID, &v.TaskUUID, &v.StartMS, &v.EndMS, &v.Version, &title, &project); err != nil {
|
||||
var title, project, projectTitle string
|
||||
if err = rows.Scan(&v.UUID, &v.TaskUUID, &v.StartMS, &v.EndMS, &v.Version, &title, &project, &projectTitle); err != nil {
|
||||
rows.Close()
|
||||
return out, err
|
||||
}
|
||||
@@ -458,7 +513,7 @@ func (s *Store) TaskReport(ctx context.Context, domain, actor string, start, end
|
||||
if !ok {
|
||||
index = len(out.Tasks)
|
||||
byTask[v.TaskUUID] = index
|
||||
out.Tasks = append(out.Tasks, TaskReportItem{UUID: v.TaskUUID, Title: title, ProjectUUID: project})
|
||||
out.Tasks = append(out.Tasks, TaskReportItem{UUID: v.TaskUUID, Title: title, ProjectUUID: project, ProjectTitle: projectTitle})
|
||||
}
|
||||
out.Tasks[index].WorkMS += elapsed
|
||||
}
|
||||
@@ -485,5 +540,39 @@ func (s *Store) TaskReport(ctx context.Context, domain, actor string, start, end
|
||||
}
|
||||
addSpan(a, b, true)
|
||||
}
|
||||
return out, rows.Err()
|
||||
if err = rows.Err(); err != nil {
|
||||
return out, err
|
||||
}
|
||||
groups := map[string]*TaskReportProject{}
|
||||
for _, task := range out.Tasks {
|
||||
p := groups[task.ProjectUUID]
|
||||
if p == nil {
|
||||
p = &TaskReportProject{UUID: task.ProjectUUID, Title: task.ProjectTitle}
|
||||
groups[task.ProjectUUID] = p
|
||||
}
|
||||
if task.Completed {
|
||||
p.Completed++
|
||||
}
|
||||
p.Points += task.Points
|
||||
p.WorkMS += task.WorkMS
|
||||
}
|
||||
out.Projects = []TaskReportProject{}
|
||||
for _, p := range groups {
|
||||
out.Projects = append(out.Projects, *p)
|
||||
}
|
||||
sort.Slice(out.Projects, func(i, j int) bool {
|
||||
if out.Projects[i].Title != out.Projects[j].Title {
|
||||
return out.Projects[i].Title < out.Projects[j].Title
|
||||
}
|
||||
return out.Projects[i].UUID < out.Projects[j].UUID
|
||||
})
|
||||
return out, nil
|
||||
}
|
||||
|
||||
type TaskReportProject struct {
|
||||
UUID string `json:"uuid"`
|
||||
Title string `json:"title"`
|
||||
Completed int `json:"completed"`
|
||||
Points int `json:"points"`
|
||||
WorkMS int64 `json:"work_ms"`
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type TaskWorkRevision struct {
|
||||
Item TaskWork `json:"item"`
|
||||
Action string `json:"action"`
|
||||
Reason string `json:"reason"`
|
||||
ChangedMS int64 `json:"changed_ms"`
|
||||
}
|
||||
|
||||
func auditTaskWork(ctx context.Context, tx *sql.Tx, domain, actor, action, reason string, v TaskWork, now time.Time) error {
|
||||
raw, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Legacy sessions acquire a baseline lazily. Never rewrite an earlier audit.
|
||||
query := `INSERT INTO organizer_work_revisions(work_uuid,version,domain_uuid,owner_uuid,action,reason,changed_ms,data) VALUES(?,?,?,?,?,?,?,?)`
|
||||
if action == "baseline" {
|
||||
query += ` ON CONFLICT(work_uuid,version) DO NOTHING`
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, query, v.UUID, v.Version, domain, actor, action, reason, now.UnixMilli(), string(raw))
|
||||
return err
|
||||
}
|
||||
|
||||
func correctTaskWork(ctx context.Context, tx *sql.Tx, domain, actor, action, reason string, v, old TaskWork, now time.Time) (TaskWork, error) {
|
||||
reason = strings.TrimSpace(reason)
|
||||
if reason == "" || len(reason) > 500 || !utf8.ValidString(reason) || strings.ContainsAny(reason, "\x00\r\n") {
|
||||
return v, ErrTaskInvalid
|
||||
}
|
||||
if v.Version < 1 || old.EndMS == 0 || old.CancelledMS != 0 {
|
||||
return v, ErrTaskConflict
|
||||
}
|
||||
if old.Version != v.Version {
|
||||
return v, ErrTaskConflict
|
||||
}
|
||||
if v.TaskUUID != "" && v.TaskUUID != old.TaskUUID {
|
||||
return v, ErrTaskInvalid
|
||||
}
|
||||
result := old
|
||||
if action == "correct" {
|
||||
if v.StartMS <= 0 || v.EndMS <= v.StartMS || v.EndMS > now.UnixMilli() || v.EndMS-v.StartMS > int64(31*24*time.Hour/time.Millisecond) {
|
||||
return v, ErrTaskInvalid
|
||||
}
|
||||
// Adjacent spans are valid; double-counted elapsed time is not. Scope across
|
||||
// Domains like the existing one-active-session constraint, without disclosing them.
|
||||
var overlap bool
|
||||
err := tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_work_sessions WHERE owner_uuid=? AND uuid<>? AND cancelled_ms=0 AND start_ms<? AND (end_ms=0 OR end_ms>?))`, actor, old.UUID, v.EndMS, v.StartMS).Scan(&overlap)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
if overlap {
|
||||
return v, ErrTaskConflict
|
||||
}
|
||||
result.StartMS = v.StartMS
|
||||
result.EndMS = v.EndMS
|
||||
} else {
|
||||
result.CancelledMS = now.UnixMilli()
|
||||
}
|
||||
if err := auditTaskWork(ctx, tx, domain, actor, "baseline", "", old, now); err != nil {
|
||||
return v, err
|
||||
}
|
||||
result.Version++
|
||||
updated, err := tx.ExecContext(ctx, `UPDATE organizer_work_sessions SET start_ms=?,end_ms=?,cancelled_ms=?,version=? WHERE uuid=? AND domain_uuid=? AND owner_uuid=? AND version=?`, result.StartMS, result.EndMS, result.CancelledMS, result.Version, old.UUID, domain, actor, old.Version)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
if count, err := updated.RowsAffected(); err != nil {
|
||||
return v, err
|
||||
} else if count != 1 {
|
||||
return v, ErrTaskConflict
|
||||
}
|
||||
if err := auditTaskWork(ctx, tx, domain, actor, action, reason, result, now); err != nil {
|
||||
return v, err
|
||||
}
|
||||
return result, tx.Commit()
|
||||
}
|
||||
|
||||
type TaskWorkEntry struct {
|
||||
TaskWork
|
||||
Title string `json:"title"`
|
||||
ProjectUUID string `json:"project_uuid"`
|
||||
}
|
||||
type TaskWorkPage struct {
|
||||
Items []TaskWorkEntry `json:"items"`
|
||||
Next string `json:"next"`
|
||||
}
|
||||
type workCursor struct {
|
||||
Start int64 `json:"start"`
|
||||
UUID string `json:"uuid"`
|
||||
}
|
||||
|
||||
func (s *Store) TaskWorkHistory(ctx context.Context, domain, actor string, start, end time.Time, after string, limit int) (TaskWorkPage, error) {
|
||||
out := TaskWorkPage{Items: []TaskWorkEntry{}}
|
||||
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
return out, err
|
||||
}
|
||||
if !end.After(start) || end.Sub(start) > 367*24*time.Hour || limit < 1 || limit > 100 {
|
||||
return out, ErrTaskInvalid
|
||||
}
|
||||
query := `SELECT w.uuid,w.task_uuid,w.start_ms,w.end_ms,w.version,w.cancelled_ms,COALESCE(i.title,''),COALESCE(i.project_uuid,'') FROM organizer_work_sessions w LEFT JOIN organizer_items i ON i.uuid=w.task_uuid AND i.domain_uuid=w.domain_uuid AND i.owner_uuid=w.owner_uuid WHERE w.domain_uuid=? AND w.owner_uuid=? AND w.start_ms<? AND (w.end_ms=0 OR w.end_ms>?)`
|
||||
args := []any{domain, actor, end.UnixMilli(), start.UnixMilli()}
|
||||
if after != "" {
|
||||
if len(after) > 256 {
|
||||
return out, ErrTaskInvalid
|
||||
}
|
||||
raw, err := base64.RawURLEncoding.DecodeString(after)
|
||||
var cursor workCursor
|
||||
if err != nil || json.Unmarshal(raw, &cursor) != nil || cursor.Start <= 0 {
|
||||
return out, ErrTaskInvalid
|
||||
}
|
||||
if id, err := uuid.Parse(cursor.UUID); err != nil || id.String() != cursor.UUID {
|
||||
return out, ErrTaskInvalid
|
||||
}
|
||||
query += ` AND (w.start_ms,w.uuid)<(?,?)`
|
||||
args = append(args, cursor.Start, cursor.UUID)
|
||||
}
|
||||
query += ` ORDER BY w.start_ms DESC,w.uuid DESC LIMIT ?`
|
||||
args = append(args, limit+1)
|
||||
rows, err := s.DB.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var v TaskWorkEntry
|
||||
if err = rows.Scan(&v.UUID, &v.TaskUUID, &v.StartMS, &v.EndMS, &v.Version, &v.CancelledMS, &v.Title, &v.ProjectUUID); err != nil {
|
||||
return out, err
|
||||
}
|
||||
out.Items = append(out.Items, v)
|
||||
}
|
||||
if len(out.Items) > limit {
|
||||
out.Items = out.Items[:limit]
|
||||
last := out.Items[limit-1]
|
||||
raw, _ := json.Marshal(workCursor{Start: last.StartMS, UUID: last.UUID})
|
||||
out.Next = base64.RawURLEncoding.EncodeToString(raw)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func (s *Store) TaskWorkRevisions(ctx context.Context, domain, actor, id string, before int64) ([]TaskWorkRevision, error) {
|
||||
out := []TaskWorkRevision{}
|
||||
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
return out, err
|
||||
}
|
||||
if before < 0 {
|
||||
return out, ErrTaskInvalid
|
||||
}
|
||||
current, err := scanTaskWork(s.DB.QueryRowContext(ctx, `SELECT `+taskWorkColumns+` FROM organizer_work_sessions WHERE uuid=? AND domain_uuid=? AND owner_uuid=?`, id, domain, actor))
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
if before == 0 {
|
||||
before = current.Version + 1
|
||||
}
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT action,reason,changed_ms,data FROM organizer_work_revisions WHERE work_uuid=? AND domain_uuid=? AND owner_uuid=? AND version<? ORDER BY version DESC LIMIT 100`, id, domain, actor, before)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var v TaskWorkRevision
|
||||
var raw string
|
||||
if err = rows.Scan(&v.Action, &v.Reason, &v.ChangedMS, &raw); err != nil {
|
||||
return out, err
|
||||
}
|
||||
if err = json.Unmarshal([]byte(raw), &v.Item); err != nil {
|
||||
return out, err
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
if len(out) == 0 && before > current.Version {
|
||||
out = append(out, TaskWorkRevision{Item: current, Action: "baseline"})
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
+43
-5
@@ -3,6 +3,8 @@
|
||||
import argparse
|
||||
import email.policy
|
||||
import email.parser
|
||||
import email.utils
|
||||
import datetime
|
||||
import uuid
|
||||
import base64
|
||||
import contextlib
|
||||
@@ -30,7 +32,7 @@ import urllib.parse as url
|
||||
import urllib.request as http
|
||||
import webbrowser
|
||||
|
||||
VERSION = '0.3.0'
|
||||
VERSION = '0.4.0'
|
||||
|
||||
class Failure(Exception):
|
||||
def __init__(self, message, status=0, payload=None):
|
||||
@@ -496,11 +498,37 @@ class MailText(HTMLParser):
|
||||
if not self.hidden: self.parts.append(data)
|
||||
|
||||
|
||||
def mail_subject(value):
|
||||
# Remove only leading mailing-list sequence markers, preserving meaningful
|
||||
# tags such as [Important], and any Re:/Fwd: prefix before the marker.
|
||||
marker = re.compile(r'^(?P<reply>(?:(?:re|fw|fwd)\s*:\s*)*)\[[^\[\]\r\n]+[\s:#]\s*[0-9]+\]\s*', re.IGNORECASE)
|
||||
while True:
|
||||
match = marker.match(value)
|
||||
if not match: return value.strip()
|
||||
value = match.group('reply') + value[match.end():]
|
||||
|
||||
|
||||
def task_mail_suffix(raw, request_id, now=None):
|
||||
message = email.parser.BytesParser(policy=email.policy.default).parsebytes(raw)
|
||||
subject = ' '.join(safe_text(str(message.get('Subject') or '')).split())
|
||||
marker = re.match(r'^(?:(?:re|fw|fwd)\s*:\s*)*\[([A-Za-z0-9][A-Za-z0-9._-]{0,99})[\s:#]+([0-9]{1,20})\]',subject,re.IGNORECASE)
|
||||
if marker:
|
||||
return marker[1]+'/'+str(int(marker[2]))
|
||||
try: date = email.utils.parsedate_to_datetime(str(message.get('Date') or ''))
|
||||
except (ValueError, TypeError, OverflowError): date = now or datetime.datetime.now(datetime.timezone.utc)
|
||||
# Preserve the month in the sender's Date timezone, not the receiving host's.
|
||||
ident = request_id if ' '.join(safe_text(str(message.get('Message-ID') or '')).split()) else hashlib.sha256(raw).hexdigest()
|
||||
return f'{date.year:04d}/{date.month:02d}/{ident}'
|
||||
|
||||
|
||||
def task_mail(raw, include_body=True, override_title=None):
|
||||
if len(raw) > 2 << 20: raise Failure('Mail input exceeds 2 MiB; pipe one message at a time.')
|
||||
message = email.parser.BytesParser(policy=email.policy.default).parsebytes(raw)
|
||||
clean = lambda value: ' '.join(safe_text(str(value or '')).split())
|
||||
title = override_title or clean(message.get('Subject')) or '(No subject)'
|
||||
subject = clean(message.get('Subject'))
|
||||
title = override_title or mail_subject(subject) or '(No subject)'
|
||||
if not override_title and len(title.encode()) > 300:
|
||||
title = title.encode()[:297].decode('utf-8',errors='ignore').rstrip() + '…'
|
||||
if len(title.encode()) > 300: raise Failure('Mail subject exceeds 300 UTF-8 bytes; use --title.')
|
||||
notes = '\n'.join(key+': '+clean(message.get(key)) for key in ('From','Date','Message-ID') if message.get(key))
|
||||
wiki_body = None
|
||||
@@ -513,7 +541,8 @@ def task_mail(raw, include_body=True, override_title=None):
|
||||
if not isinstance(content,str): raise Failure('Mail body is not readable text.')
|
||||
if part.get_content_type() == 'text/html':
|
||||
parser = MailText();parser.feed(content);parser.close();content = ''.join(parser.parts).strip()
|
||||
wiki_body = notes + '\n\n' + content
|
||||
# Retain the original subject when its mailing-list marker was removed.
|
||||
wiki_body = (('Subject: '+subject+'\n') if title != subject else '') + notes + '\n\n' + content
|
||||
if '\0' in wiki_body or len(wiki_body.encode()) > 256 << 10: raise Failure('Mail Wiki body must be valid text of at most 256 KiB; nothing was uploaded.')
|
||||
if len(notes.encode()) > 16384: raise Failure('Mail metadata exceeds 16 KiB.')
|
||||
return title, notes, clean(message.get('Message-ID')) or hashlib.sha256(raw).hexdigest(), wiki_body
|
||||
@@ -549,6 +578,7 @@ def tasks(client, profile, words):
|
||||
def capture(payload):
|
||||
pending=profile.data.setdefault('task_outbox',{})
|
||||
if len(pending)>=20 and payload['request_id'] not in pending:raise Failure('20 pending captures retained. Retry them before adding more.')
|
||||
if payload['request_id'] in pending and pending[payload['request_id']] != payload:raise Failure('A different draft with this request ID is retained. Use pages task retry '+payload['request_id'])
|
||||
pending[payload['request_id']]=payload;profile.save()
|
||||
try: result=client.json(TASK_API+'capture',method='POST',data=payload)
|
||||
except Failure as e:
|
||||
@@ -581,13 +611,21 @@ def tasks(client, profile, words):
|
||||
payload={'request_id':getattr(a,'request_id',None) or str(uuid.uuid4()),'title':a.title,'notes':a.notes or ''}
|
||||
if action=='from-mail':
|
||||
if a.metadata_only and a.wiki_prefix is not None: raise Failure('--wiki-prefix cannot be combined with --metadata-only.')
|
||||
title,notes,message_id,wiki_body=task_mail(sys.stdin.buffer.read((2<<20)+1),not a.metadata_only,a.title)
|
||||
raw=sys.stdin.buffer.read((2<<20)+1)
|
||||
title,notes,message_id,wiki_body=task_mail(raw,not a.metadata_only,a.title)
|
||||
payload.update(title=a.title or title,notes=a.notes if a.notes is not None else notes,request_id=str(uuid.uuid5(uuid.NAMESPACE_URL,client.base+'\n'+profile.data.get('username','')+'\n'+message_id)))
|
||||
if wiki_body is not None: payload['wiki_body']=wiki_body
|
||||
if wiki_body is not None:
|
||||
payload['wiki_body']=wiki_body
|
||||
payload['wiki_suffix']=task_mail_suffix(raw,payload['request_id'])
|
||||
if a.wiki_prefix is not None: payload['wiki_prefix']=a.wiki_prefix
|
||||
for attr,key in [('project','project_uuid'),('assignee','assignee_uuid'),('due','due_on'),('start_on','start_on'),('planned','planned_on'),('review','review_on'),('estimate','estimate_minutes'),('complexity','complexity')]:
|
||||
value=getattr(a,attr)
|
||||
if value is not None:payload[key]=task_project(client,value) if attr=='project' else value
|
||||
# A retry of the same pending mail must not drift across a month boundary
|
||||
# when Date was missing. Other changed options still fail closed.
|
||||
old=profile.data.get('task_outbox',{}).get(payload['request_id'])
|
||||
if action=='from-mail' and old and {k:v for k,v in old.items() if k!='wiki_suffix'}=={k:v for k,v in payload.items() if k!='wiki_suffix'}:
|
||||
payload=old.copy()
|
||||
emit(capture(payload));return
|
||||
if action=='project-add':
|
||||
emit(client.json(TASK_API+'items',method='POST',data={'uuid':str(uuid.uuid4()),'kind':'project','title':a.title,'notes':a.notes,'status':'todo','bucket':'inbox','priority':1}));return
|
||||
|
||||
@@ -9,6 +9,39 @@ import unittest
|
||||
m=runpy.run_path(str(Path(__file__).with_name('pages')))
|
||||
|
||||
class ProductivityTests(unittest.TestCase):
|
||||
def test_mail_path_priority_and_dates(self):
|
||||
import datetime,hashlib
|
||||
ident='06cb3a24-61f8-4a9f-a0bf-89eea9632f25'
|
||||
suffix=m['task_mail_suffix'];now=datetime.datetime(2030,2,1,tzinfo=datetime.timezone.utc)
|
||||
for marker in ('[hogehoge 00123]','Re: [hogehoge:123]','Fwd: [hogehoge#123]'):
|
||||
raw=('Subject: '+marker+' Title\r\n\r\nbody').encode()
|
||||
self.assertEqual(suffix(raw,ident,now),'hogehoge/123')
|
||||
raw=b'Subject: Plain\r\nDate: Sat, 31 Jan 2026 23:30:00 -0800\r\nMessage-ID: <id@example.invalid>\r\n\r\nbody'
|
||||
self.assertEqual(suffix(raw,ident,now),'2026/01/'+ident)
|
||||
noid=raw.replace(b'Message-ID: <id@example.invalid>\r\n',b'')
|
||||
self.assertEqual(suffix(noid,ident,now),'2026/01/'+hashlib.sha256(noid).hexdigest())
|
||||
for date in (b'',b'Date: broken\r\n'):
|
||||
raw=b'Subject: [../unsafe 123] Title\r\n'+date+b'\r\nbody'
|
||||
self.assertEqual(suffix(raw,ident,now),'2030/02/'+hashlib.sha256(raw).hexdigest())
|
||||
|
||||
def test_pending_mail_month_and_options_are_preserved(self):
|
||||
from unittest.mock import patch
|
||||
raw=b'Subject: Test\r\nMessage-ID: <same@example.invalid>\r\n\r\nbody'
|
||||
calls=[]
|
||||
def send(route,**kw):
|
||||
calls.append(kw['data'].copy())
|
||||
raise m['Failure']('offline')
|
||||
client=SimpleNamespace(base='https://example.invalid',json=send)
|
||||
profile=SimpleNamespace(data={'username':'test'},save=lambda:None)
|
||||
for month in ('2030/01','2030/02'):
|
||||
with patch.dict(m['tasks'].__globals__,task_mail_suffix=lambda raw,ident:month+'/'+ident),patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
|
||||
m['tasks'](client,profile,['from-mail'])
|
||||
self.assertEqual(calls[0],calls[1])
|
||||
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),self.assertRaises(m['Failure']):
|
||||
m['tasks'](client,profile,['from-mail','--wiki-prefix','/changed'])
|
||||
self.assertEqual(len(calls),2)
|
||||
self.assertEqual(next(iter(profile.data['task_outbox'].values())),calls[0])
|
||||
|
||||
def test_mail_privacy_and_long_subject_override(self):
|
||||
raw=b'Subject: Test\r\nFrom: Person <person@example.invalid>\r\nMessage-ID: <id@example.invalid>\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nPRIVATE BODY'
|
||||
title,notes,ident,body=m['task_mail'](raw)
|
||||
@@ -16,9 +49,27 @@ class ProductivityTests(unittest.TestCase):
|
||||
self.assertIn('PRIVATE BODY',body)
|
||||
self.assertIsNone(m['task_mail'](raw,False)[3])
|
||||
raw=raw.replace(b'Subject: Test',b'Subject: '+b'a'*301)
|
||||
with self.assertRaises(m['Failure']):m['task_mail'](raw)
|
||||
self.assertLessEqual(len(m['task_mail'](raw)[0].encode()),300)
|
||||
with self.assertRaises(m['Failure']):m['task_mail'](raw,True,'x'*301)
|
||||
self.assertEqual(m['task_mail'](raw,False,'Override')[0],'Override')
|
||||
|
||||
def test_japanese_subject_and_mailing_list_markers(self):
|
||||
from email.message import EmailMessage
|
||||
from email.header import Header
|
||||
for encoding in ('utf-8','iso-2022-jp'):
|
||||
subject='Re: [hogehoge 00123] [team:456] 日本語の依頼 [重要]'
|
||||
raw=('Subject: '+Header(subject,encoding).encode()+'\r\nMessage-ID: <same@example.invalid>\r\n\r\nbody').encode('ascii')
|
||||
title,notes,ident,body=m['task_mail'](raw)
|
||||
self.assertEqual(title,'Re: 日本語の依頼 [重要]')
|
||||
self.assertEqual(ident,'<same@example.invalid>');self.assertIn('Subject: '+subject,body)
|
||||
for subject in ('[重要] 日本語','報告 [list 123]','[release 1.2] 更新'):
|
||||
self.assertEqual(m['mail_subject'](subject),subject)
|
||||
msg=EmailMessage();msg['Subject']='[list 123] '+('日本語'*100);msg.set_content('Body')
|
||||
title,_,_,body=m['task_mail'](msg.as_bytes())
|
||||
self.assertLessEqual(len(title.encode()),300);self.assertTrue(title.endswith('…'))
|
||||
self.assertIn('日本語'*100,body)
|
||||
self.assertEqual(m['task_mail'](msg.as_bytes(),True,'[list 123] 手動指定')[0],'[list 123] 手動指定')
|
||||
|
||||
def test_html_mail_and_limits(self):
|
||||
raw=b'Subject: HTML\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<head><style>secret</style></head><p>Hello</p><script>evil()</script><img src="https://example.invalid/image"><p>World & friends</p>'
|
||||
body=m['task_mail'](raw)[3]
|
||||
|
||||
@@ -7,6 +7,7 @@ import runpy
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
from email.message import EmailMessage
|
||||
|
||||
def run():
|
||||
m=runpy.run_path(str(Path(__file__).with_name('pages')))
|
||||
@@ -29,15 +30,27 @@ def run():
|
||||
report=task('report','--json');assert sum(d['points'] for d in report['days'])==7
|
||||
assert any(i['uuid']==ident for i in report['tasks'])
|
||||
task('preferences','--wiki-prefix','/private/mail')
|
||||
mail=b'Subject: CLI mail\r\nMessage-ID: <integration@example.invalid>\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nPrivate mail body {{children}}'
|
||||
message=EmailMessage();message['Subject']='[hogehoge 123] 日本語の件名と依頼';message['Message-ID']='<integration@example.invalid>';message.set_content('Private mail body {{children}}')
|
||||
mail=message.as_bytes()
|
||||
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(mail))):
|
||||
captured=task('from-mail')
|
||||
assert captured['item']['page_uuid'] and captured['page_path'].startswith('/private/mail/CLI mail--')
|
||||
assert captured['item']['page_uuid'] and captured['page_path']=='/private/mail/hogehoge/123'
|
||||
assert captured['item']['title']=='日本語の件名と依頼'
|
||||
assert 'Private mail body' not in captured['item']['notes']
|
||||
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(mail))):
|
||||
assert task('from-mail')['item']['page_uuid']==captured['item']['page_uuid']
|
||||
note=client.json(m['TASK_API']+'items/'+captured['item']['uuid']+'/note')
|
||||
assert note['linked'] and note['path']==captured['page_path']
|
||||
raw,_=client.raw('path:'+captured['page_path'])
|
||||
assert '日本語の件名と依頼' in raw.decode() and 'Private mail body' in raw.decode()
|
||||
message.replace_header('Subject','連番なしの日本語');message.replace_header('Message-ID','<other@example.invalid>');message['Date']='Sat, 31 Jan 2026 23:30:00 -0800'
|
||||
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(message.as_bytes()))):dated=task('from-mail')
|
||||
assert dated['page_path']=='/private/mail/2026/01/'+dated['item']['uuid']
|
||||
del message['Message-ID']
|
||||
import hashlib
|
||||
raw_mail=message.as_bytes()
|
||||
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw_mail))):hashed=task('from-mail')
|
||||
assert hashed['page_path']=='/private/mail/2026/01/'+hashlib.sha256(raw_mail).hexdigest()
|
||||
path=Path(fixture['root'])/'person.vcf'
|
||||
path.write_text('BEGIN:VCARD\r\nVERSION:4.0\r\nUID:urn:test:cli\r\nFN:CLI Person\r\nEMAIL:cli@example.invalid\r\nEND:VCARD\r\n')
|
||||
output=io.StringIO()
|
||||
|
||||
@@ -107,6 +107,13 @@ body.mode-config .config-section {
|
||||
.asset-detail-dialog { width:min(72rem,calc(100vw - 2rem));max-height:calc(100vh - 2rem);overflow:auto;background:var(--bg);color:var(--fg);border:1px solid var(--border-soft);border-radius:.5rem;padding:1.25rem }
|
||||
.asset-detail-dialog::backdrop { background:rgba(0,0,0,.55) }
|
||||
.config-path-control,.config-range-control{display:flex;align-items:center;gap:.5rem;min-width:0}.config-path-control input{flex:1;min-width:0}.config-path-control button{flex:0 0 2.2rem;height:2.2rem;padding:0}.config-range-control input{flex:1;min-width:8rem}.config-range-control output{min-width:3.5rem;text-align:end;font-variant-numeric:tabular-nums}
|
||||
.mode-config .home-palette-controls{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,15rem),1fr));gap:.75rem;min-width:0}
|
||||
.mode-config .home-palette-controls label{display:grid;gap:.35rem;min-width:0}
|
||||
.mode-config .home-palette-controls select{width:100%;min-width:0}
|
||||
.mode-config .home-palette-controls p{grid-column:1/-1;margin:0}
|
||||
.mode-config .home-appearance-range{display:flex;gap:.5rem;align-items:center;min-width:0}
|
||||
.mode-config .home-appearance-range input{flex:1;min-width:0;accent-color:var(--accent)}
|
||||
.mode-config .home-appearance-range output{min-width:3.5rem;text-align:end;font-variant-numeric:tabular-nums}
|
||||
.config-path-picker{box-sizing:border-box;width:min(46rem,95vw);height:min(42rem,90dvh);margin:auto;padding:0;overflow:hidden;border:1px solid var(--border);border-radius:.8rem;background:var(--input-bg,var(--bg));color:var(--fg);box-shadow:0 1.5rem 5rem #0009}.config-path-picker[open]{display:grid;grid-template-rows:auto auto auto minmax(0,1fr) auto}.config-path-picker::backdrop{background:#0009;backdrop-filter:blur(3px)}.config-path-picker>header,.config-path-picker>nav,.config-path-picker>footer{display:flex;align-items:center;gap:.6rem;padding:.75rem 1rem;background:var(--input-bg,var(--bg))}.config-path-picker>header{justify-content:space-between;border-bottom:1px solid var(--border)}.config-path-picker>header h2{margin:0;font-size:1.05rem}.config-path-picker>header button{border:0;background:transparent;color:inherit;font-size:1.4rem}.config-path-picker>nav{border-bottom:1px solid var(--border-soft)}.config-path-picker>nav code{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.config-path-picker>[data-path-picker-status]{min-height:1.2rem;margin:0;padding:.45rem 1rem}.config-path-picker-list{min-height:10rem;padding:.25rem .5rem;overflow:auto;overscroll-behavior:contain}.config-path-picker-item{display:grid;grid-template-columns:1.5rem minmax(0,1fr) auto;align-items:center;gap:.55rem;width:100%;padding:.5rem .65rem;border:0;border-radius:.35rem;background:transparent;color:inherit;text-align:start}.config-path-picker-item:hover,.config-path-picker-item[aria-selected=true]{background:var(--row-hover,var(--border-soft))}.config-path-picker-item[aria-selected=true]{outline:1px solid var(--accent)}.config-path-picker-item span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.config-path-picker-item small{color:var(--muted)}.config-path-picker>footer{justify-content:flex-end;border-top:1px solid var(--border)}
|
||||
.asset-dialog-close { position:absolute;right:.75rem;top:.75rem }
|
||||
.table-scroll { overflow-x: auto; }
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
.feeds-page{height:100dvh;overflow:hidden;display:flex;flex-direction:column;background:var(--bg);color:var(--fg)}
|
||||
.feed-catalog{padding:.3rem 0 .4rem .5rem;display:grid;gap:.3rem;border-left:2px solid var(--border,#8885)}#feeds-app .feed-catalog select,#feeds-app .feed-catalog input{width:100%;min-width:0;box-sizing:border-box;font-size:.75rem}.feed-subscriptions{display:grid;gap:0}.feed-subscriptions button{text-align:left;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font-size:.75rem!important;border:0!important;content-visibility:auto;contain-intrinsic-size:auto 29px}.feed-subscriptions button[aria-current=true]{background:color-mix(in srgb,var(--accent,#659de4) 22%,transparent)!important}
|
||||
.feed-opml{display:grid;gap:.6rem;min-width:0}.feed-opml>label{display:grid;gap:.25rem}.feed-opml input[type=file]{width:100%;box-sizing:border-box}.feed-opml table{width:100%;table-layout:fixed;border-collapse:collapse;font-size:.8rem}.feed-opml th,.feed-opml td{text-align:left;vertical-align:top;padding:.3rem;border-bottom:1px solid var(--border,#8885);overflow-wrap:anywhere}.feed-opml th:first-child{width:1.6rem}.feed-opml th:nth-child(3){width:20%}.feed-opml th:last-child{width:20%}.feed-opml small{display:block;font-size:.7rem;opacity:.7;overflow-wrap:anywhere}#feeds-app .feed-opml input[type=checkbox]{width:auto;min-height:1.2rem}.feed-import-options{display:flex;gap:.75rem;align-items:center;flex-wrap:wrap}#feeds-app .feed-import-options label:has(input[type=checkbox]){display:flex;align-items:center}.feed-opml input:disabled{opacity:.4}
|
||||
#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)}
|
||||
@media(max-width:1100px){.feed-layout{grid-template-columns:10rem minmax(0,1fr)}#feed-reader{display:none}.feed-layout.reading .feed-index{display:none}.feed-layout.reading #feed-reader{display:block}#feed-columns,.feed-row{grid-template-columns:1.5rem 4.7rem 7rem minmax(0,1fr)}}
|
||||
@media(max-width:600px){.feed-layout{display:flex;flex-direction:column}#feed-sources{display:none;max-height:35%;flex-shrink:0;border-bottom:1px solid var(--border,#6666)}.feed-layout.sources-open #feed-sources{display:block}.feed-index,#feed-reader{flex:1;width:100%;box-sizing:border-box}#feed-columns,.feed-row{grid-template-columns:1.5rem 3.5rem minmax(0,1fr);font-size:.85rem}.feed-row{min-height:2.75rem}#feed-columns>span:nth-child(3),.feed-row>span:nth-child(3){display:none}#feeds-app button{min-height:2.3rem}#feed-keys{display:none}#feed-reader{border-left:0}.feeds-page .organizer-nav{font-size:.8rem}}
|
||||
+8
-1
@@ -72,6 +72,13 @@ body.periodical-top:has(> .home-wallpaper) .periodical-shell dialog header { bac
|
||||
.home-appearance-dialog h2 { font-size:1.1rem; }
|
||||
.home-appearance-dialog header button { border:0; background:transparent; color:inherit; font-size:1.5rem; cursor:pointer; }
|
||||
.home-appearance-dialog label { display:grid; gap:.55rem; }
|
||||
.home-palette-controls { display:grid; gap:.85rem; min-width:0; }
|
||||
.home-appearance-dialog { max-height:calc(100dvh - 2rem); overflow:auto; overscroll-behavior:contain; }
|
||||
.home-palette-controls label { display:grid; gap:.4rem; }
|
||||
.home-palette-controls select { width:100%; min-width:0; padding:.45rem .6rem; color:var(--input-fg,var(--fg)); background:var(--input-bg,var(--bg)); border:1px solid var(--input-border,var(--border)); border-radius:.4rem; }
|
||||
body[data-home-palette-active] { background-color:var(--bg); color:var(--fg); accent-color:var(--accent); }
|
||||
body[data-home-palette-active] .home-search :is(input,button) { color:var(--fg); }
|
||||
body[data-home-palette-active] :is(.home-wiki-title,.home-shortcuts) { text-shadow:0 1px 4px color-mix(in srgb,var(--bg) 85%,transparent); }
|
||||
.home-appearance-range { display:grid; grid-template-columns:minmax(0,1fr) 3.5rem; align-items:center; gap:.75rem; }
|
||||
.home-appearance-range input { width:100%; accent-color:var(--accent); }
|
||||
.home-appearance-range output { color:var(--fg); font-variant-numeric:tabular-nums; text-align:right; }
|
||||
@@ -92,7 +99,7 @@ body.periodical-top:has(> .home-wallpaper) .periodical-shell dialog header { bac
|
||||
.home-paged .home-main[data-home-page="bookmarks"] { transform:translate3d(0,calc(-100dvh + var(--home-pager-drag)),0); }
|
||||
.home-paged .home-main[data-home-dragging] { transition:none; user-select:none; }
|
||||
.home-pager-page { position:relative; min-width:0; height:100vh; height:100dvh; }
|
||||
.home-search-page { display:grid; place-items:center; padding:5rem 0; touch-action:pan-x; }
|
||||
.home-search-page { display:grid; grid-template-columns:minmax(0,1fr); place-items:center; padding:5rem 0; touch-action:pan-x; }
|
||||
.home-search-page .home-search { align-self:center; }
|
||||
.home-bookmarks-page { padding:4.5rem 0 3rem; overflow:auto; overscroll-behavior:contain; scrollbar-gutter:stable; touch-action:pan-y; }
|
||||
.home-bookmarks-page-head { display:flex; align-items:center; justify-content:space-between; gap:1rem; margin:0 0 1.25rem; padding-inline:.25rem; }
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#task-productivity{max-width:1200px;margin:1rem auto;padding:0 1rem;color:var(--fg,var(--text-color));box-sizing:border-box}
|
||||
#task-digest-history{min-width:0;margin:1rem 0}#task-digest-history summary{cursor:pointer;font-weight:600}#task-digest-history p{font-size:.9rem}#task-digest-history .digest-retry form{display:flex;gap:.6rem;align-items:center;flex-wrap:wrap}#task-digest-history .digest-retry label{display:flex;gap:.5rem;align-items:center}#task-digest-history button{font:inherit;color:inherit;background:var(--input-bg,var(--bg));border:1px solid var(--border);border-radius:.3rem;padding:.4rem .6rem;cursor:pointer}#task-digest-history th,#task-digest-history td{white-space:nowrap}#task-digest-history td:last-child{white-space:normal;min-width:10rem}@media(max-width:600px){#task-digest-history button,#task-digest-history .digest-retry label{min-height:44px}#task-digest-history .digest-retry input{min-width:24px;min-height:24px}}
|
||||
body:has(#task-productivity) .topbar,body:has(#contacts-app) .topbar{flex-wrap:wrap;gap:.5rem}
|
||||
#task-productivity,#contacts-app{min-width:0;width:100%;overflow-wrap:anywhere}
|
||||
@media(max-width:600px){body:has(#task-productivity) .topbar,body:has(#contacts-app) .topbar{padding:.5rem;gap:.3rem}body:has(#task-productivity) .topbar>.brand,body:has(#contacts-app) .topbar>.brand{flex:1}body:has(#task-productivity) .topbar>nav{display:none}}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#task-work-history{max-width:1320px;margin:1rem auto;padding:0 1rem;color:var(--fg);box-sizing:border-box}#task-work-history>header,.work-history-controls{display:flex;align-items:center;flex-wrap:wrap;gap:.75rem}#task-work-history>header{justify-content:space-between}#task-work-history a{color:var(--link,var(--accent))}.work-history-controls label,.work-history-edit label{display:grid;gap:.25rem}.work-history-controls{margin-block:1rem}#task-work-history input,#task-work-history button{font:inherit;color:var(--fg);background:var(--input-bg,var(--bg));border:1px solid var(--border);border-radius:.3rem;padding:.35rem .5rem;box-sizing:border-box}#task-work-history button{cursor:pointer}#work-history-list{overflow:auto}.work-history-table{width:100%;border-collapse:collapse}.work-history-table td,.work-history-table th{padding:.3rem .4rem;text-align:left;vertical-align:top;border-bottom:1px solid var(--border)}.work-history-table td:not(:first-child){white-space:nowrap}.work-history-table td:first-child{overflow-wrap:anywhere}.work-history-table td button+button{margin-left:.4rem}.work-history-extra td{white-space:normal!important}.work-history-extra summary{color:var(--muted);font-size:.85rem;cursor:pointer}.work-history-extra ol{max-height:20rem;overflow:auto}.work-history-extra p{margin:.25rem 0;overflow-wrap:anywhere}.work-history-edit{display:flex;align-items:end;flex-wrap:wrap;gap:.6rem;padding:.7rem 0}.work-history-edit label:last-of-type{flex:1;min-width:12rem}.work-history-edit>p{width:100%}.work-history-edit input{max-width:100%}#work-history-paging{display:flex;justify-content:flex-end;gap:.6rem;margin-block:1rem}@media(max-width:760px){.work-history-table thead{display:none}.work-history-table,.work-history-table tbody,.work-history-table tr,.work-history-table td{display:block}.work-history-table tr{border-bottom:1px solid var(--border);padding:.4rem 0}.work-history-table td{border:0;white-space:normal!important}.work-history-table td[data-label]::before{content:attr(data-label);display:inline-block;min-width:4rem;color:var(--muted);margin-right:.5rem}#task-work-history input,#task-work-history button{min-height:44px}.work-history-edit{align-items:stretch}.work-history-edit label{width:100%;min-width:0!important}.work-history-extra summary{padding:.6rem 0}.work-history-controls label{max-width:100%}}
|
||||
@@ -0,0 +1,134 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
const root=document.getElementById('feeds-app');if(!root)return;
|
||||
const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en;
|
||||
const api='/_/api/v1/extension/organizer.feeds/',writable=root.dataset.writable==='true';
|
||||
const toolbar=document.getElementById('feed-toolbar'),status=document.getElementById('feed-status'),sourcesView=document.getElementById('feed-sources'),rows=document.getElementById('feed-rows'),reader=document.getElementById('feed-reader'),layout=root.querySelector('.feed-layout'),more=document.getElementById('feed-more');
|
||||
const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
|
||||
const report=e=>{if(e.name!=='AbortError')status.textContent=e.message;};
|
||||
function button(text,label,fn){const b=el('button',text);b.type='button';b.title=b.ariaLabel=label;b.addEventListener('click',()=>Promise.resolve().then(fn).catch(report));return b;}
|
||||
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;
|
||||
const sourceLabel=el('strong','RSS'),searchbox=el('input');searchbox.type='search';searchbox.placeholder=t('Search titles / feeds… /','件名・配信元を検索… /');searchbox.ariaLabel=searchbox.placeholder;
|
||||
const filters=el('select');for(const [v,en,jp]of [['','All','すべて'],['unread','Unread','未読'],['starred','Starred','star付き']]){const o=el('option',t(en,jp));o.value=v;filters.append(o);}filters.ariaLabel=t('Filter','絞り込み');filters.onchange=()=>{filter=filters.value;load(false).catch(report);};
|
||||
const refresh=button('↻',t('Queue source refresh (r)','背景更新を予約 (r)'),queueRefresh);refresh.disabled=!writable;
|
||||
toolbar.append(button('☰',t('Sources','購読元'),()=>layout.classList.toggle('sources-open')),sourceLabel,searchbox,filters,refresh);
|
||||
if(writable)toolbar.append(button('+',t('Add source','購読元を追加'),()=>sourceForm()));
|
||||
const transfer=button('⇄','OPML',opmlForm);transfer.id='feed-opml';toolbar.append(transfer);
|
||||
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));
|
||||
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(source.uuid===currentSource&&source.provider==='freshrss')drawCatalog(sourcesView);
|
||||
}
|
||||
}
|
||||
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);
|
||||
};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 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');}
|
||||
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;
|
||||
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;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 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',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')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;}
|
||||
function opmlForm(){
|
||||
editing=true;detailSeq++;detailController?.abort();layout.classList.add('reading');reader.replaceChildren();
|
||||
const section=el('section',undefined,'feed-opml'),heading=el('div',undefined,'feed-actions');heading.append(el('h1','OPML'),button('←',t('Back','戻る'),closeReader));section.append(heading);reader.append(section);
|
||||
const exportLink=el('a',t('Export local subscriptions','内蔵購読を書き出す'));exportLink.href=api+'opml/export';exportLink.download='pageswiki-feeds.opml';section.append(exportLink);if(!writable)return;
|
||||
const fileLabel=el('label',t('Import local subscriptions','内蔵購読を取り込む')),file=el('input');file.type='file';file.accept='.opml,.xml,text/x-opml,application/xml,text/xml';file.id='feed-opml-file';fileLabel.append(file);section.append(fileLabel);
|
||||
const preview=el('div');section.append(preview);let generation=0;
|
||||
const reasons={add:t('Add','追加'),existing:t('Subscribed','登録済み'),duplicate:t('Duplicate','重複'),unsupported_url:t('Unsupported URL','未対応URL'),unsupported_type:t('Unsupported type','未対応形式'),invalid_fields:t('Invalid name/folder','名前・フォルダ不正'),commented:t('Commented','コメント扱い')};
|
||||
file.onchange=async()=>{
|
||||
const version=++generation,chosen=file.files[0];preview.replaceChildren();status.textContent='';if(!chosen)return;
|
||||
try{
|
||||
if(chosen.size>512*1024)throw Error(t('OPML must be at most 512 KiB.','OPMLは512 KiB以内で指定してください。'));
|
||||
const opml=await chosen.text(),data=await post('opml/preview',{opml});if(version!==generation||!section.isConnected)return;
|
||||
const form=el('form');form.id='feed-opml-preview';preview.append(form);const table=el('table'),head=el('thead'),tr=el('tr');for(const label of ['',t('Subscription','購読'),t('Folder','フォルダ'),t('Status','状態')])tr.append(el('th',label));head.append(tr);table.append(head);const body=el('tbody');table.append(body);form.append(table);
|
||||
const choices=[];let remaining=data.available;
|
||||
for(const row of data.rows){const tr=el('tr'),cell=el('td'),check=el('input');check.type='checkbox';check.value=row.index;check.ariaLabel=row.title;check.disabled=row.status!=='add';check.checked=!check.disabled&&remaining-->0;cell.append(check);const name=el('td');name.append(el('strong',row.title||'—'),el('small',row.url));tr.append(cell,name,el('td',row.folder||'—'),el('td',reasons[row.status]||row.status));body.append(tr);if(!check.disabled)choices.push(check);}
|
||||
const options=el('div',undefined,'feed-import-options'),enabled=field(options,t('Enable','有効'),'','checkbox');enabled.checked=true;const interval=field(options,t('Interval (min)','更新間隔(分)'),'30','number');interval.min='5';interval.max='1440';interval.required=true;form.append(options);
|
||||
const actions=el('div',undefined,'feed-actions'),save=el('button');save.type='submit';save.id='feed-opml-apply';actions.append(save);form.append(actions);
|
||||
let busy=false,pending=null;
|
||||
const update=()=>{const n=choices.filter(x=>x.checked).length;save.textContent=t('Add ','追加 ')+n;save.disabled=busy||n===0||n>data.available;save.title=n>data.available?t('Subscription limit exceeded','購読数の上限を超えています'):'';choices.forEach(check=>check.disabled=busy);enabled.disabled=interval.disabled=busy;};choices.forEach(check=>check.onchange=update);update();
|
||||
form.onsubmit=async event=>{
|
||||
event.preventDefault();if(busy)return;const selected=choices.filter(x=>x.checked).map(x=>Number(x.value));if(!selected.length||selected.length>data.available)return;
|
||||
const input={opml,selected,expected:data.expected,enabled:enabled.checked,interval_seconds:Number(interval.value)*60},fingerprint=JSON.stringify(input);if(!pending||pending.fingerprint!==fingerprint)pending={fingerprint,request_id:crypto.randomUUID()};input.request_id=pending.request_id;busy=true;file.disabled=true;update();
|
||||
try{await post('opml/import',input);if(!section.isConnected)return;await reload();status.textContent=t('Imported','取り込みました');}catch(e){report(e);}finally{busy=false;file.disabled=false;update();}
|
||||
};
|
||||
}catch(e){if(version===generation&§ion.isConnected)report(e);}
|
||||
};
|
||||
}
|
||||
function sourceForm(source){editing=true;detailSeq++;layout.classList.add('reading');reader.replaceChildren();const form=el('form'),buttons=el('div',undefined,'feed-actions');reader.append(form);form.append(el('h1',t('Source settings','購読元設定')));
|
||||
const title=field(form,t('Name','表示名'),source?.title||''),folder=field(form,t('Folder','フォルダ'),source?.folder||'');title.required=true;title.maxLength=folder.maxLength=200;
|
||||
const label=el('label',t('Provider','正本')),provider=el('select');for(const [id,name]of [['local',t('Local · RSS / Atom','内蔵 · RSS / Atom')],['freshrss','FreshRSS']]){const o=el('option',name);o.value=id;provider.append(o);}provider.value=source?.provider||'local';provider.disabled=!!source;label.append(provider);form.append(label);
|
||||
const url=field(form,t('Public HTTPS feed / greader.php API URL','公開HTTPSのfeed / greader.php API URL'),source?.url||'','url');url.required=true;url.readOnly=!!source;
|
||||
const user=field(form,t('FreshRSS user','FreshRSSユーザー')),password=field(form,t('FreshRSS API password','FreshRSS APIパスワード'),'','password');password.autocomplete='new-password';
|
||||
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();
|
||||
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','保存しました');}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メモ・タスク')));
|
||||
const title=field(form,t('Title','件名'),item.title.slice(0,250));title.required=true;title.maxLength=300;
|
||||
const task=field(form,t('Also create a task','タスクを作成する'),'','checkbox');task.disabled=root.dataset.tasks!=='true';
|
||||
const prefix=field(form,t('Wiki parent Path (empty = task only)','Wikiの親Path(空ならタスクのみ)'),'');prefix.placeholder='/notes/feeds';prefix.required=true;
|
||||
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;
|
||||
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));}
|
||||
else data=await post('note',{request_id:pending.request_id,source:item.source,id:item.id,path:spec.prefix.replace(/\/$/,'')+'/rss-'+pending.request_id,title:title.value,body,confirm_publication:confirm.checked});
|
||||
reader.replaceChildren(el('p',t('Created.','作成しました。')));if(data.item){const a=el('a',t('Open task','タスクを開く'));a.href='/v/plan/task/'+encodeURIComponent(data.item.uuid);reader.append(a);}const page=data.page_uuid||data.item?.page_uuid;if(page){const a=el('a',t('Open Wiki','Wikiを開く'));a.href='/v/uuid:'+encodeURIComponent(page);reader.append(el('p'),a);}editing=false;
|
||||
}catch(e){report(e);}finally{save.disabled=false;}
|
||||
};
|
||||
}
|
||||
document.addEventListener('keydown',event=>{if(event.defaultPrevented||event.isComposing||event.ctrlKey||event.altKey||event.metaKey)return;const input=event.target.closest?.('input,textarea,select,[contenteditable=true]');if(input){if(event.key==='Escape'){event.target.blur();event.preventDefault();}return;}if(event.key==='Enter'&&event.target.closest?.('button,a'))return;if(editing){if(event.key==='Escape'){closeReader();event.preventDefault();}return;}
|
||||
let action;switch(event.key){case 'j':case 'ArrowDown':action=()=>open(Math.min(items.length-1,selected+1));break;case 'k':case 'ArrowUp':action=()=>open(Math.max(0,selected-1));break;case 'Enter':case 'l':action=()=>open(Math.max(0,selected));break;case 'Escape':case 'h':action=closeReader;break;case '/':action=()=>searchbox.focus();break;case 'r':if(writable)action=queueRefresh;break;case 'm':action=()=>setState(!items[selected]?.read,!!items[selected]?.starred);break;case '*':action=()=>setState(!!items[selected]?.read,!items[selected]?.starred);break;case 'n':action=()=>{const i=items.findIndex((x,i)=>i>selected&&!x.read);if(i>=0)return open(i);};break;case '?':action=showHelp;break;}if(action){event.preventDefault();Promise.resolve().then(action).catch(report);}
|
||||
});
|
||||
(async()=>{const q=new URLSearchParams(location.search);currentSource=q.get('source')||'';await reload();if(q.has('settings')&&writable){sourceForm();return;}if(q.has('id')&¤tSource){let index=items.findIndex(x=>x.source===currentSource&&x.id===q.get('id'));if(index<0){const data=await request('item?'+new URLSearchParams({source:currentSource,id:q.get('id')}));items.unshift(data.item);index=0;drawRows();}await open(index);}})().catch(report);
|
||||
})();
|
||||
@@ -8,23 +8,35 @@
|
||||
if (!open || !dialog || !form || !input || !output || !status) return;
|
||||
|
||||
let saved = Number(input.value);
|
||||
const paletteNames = ['home_palette_mode','home_palette_strength','home_palette_brightness'];
|
||||
let savedPalette = paletteNames.map(name => form.elements[name]?.value);
|
||||
const palettePreview = () => {
|
||||
const strength = Number(form.elements.home_palette_strength?.value ?? 35);
|
||||
const label = form.querySelector('[data-palette-strength]');
|
||||
if (label) label.textContent = `${strength}%`;
|
||||
document.dispatchEvent(new CustomEvent('pageswiki:home-appearance', {detail:{mode:form.elements.home_palette_mode?.value || 'off', strength, brightness:form.elements.home_palette_brightness?.value || 'preserve'}}));
|
||||
};
|
||||
const preview = value => {
|
||||
const transparency = Math.max(0, Math.min(85, Number(value) || 0));
|
||||
document.body.style.setProperty('--home-glass-opacity', `${100 - transparency}%`);
|
||||
output.value = `${transparency}%`;
|
||||
output.textContent = `${transparency}%`;
|
||||
palettePreview();
|
||||
};
|
||||
const restore = () => {
|
||||
input.value = String(saved);
|
||||
paletteNames.forEach((name,i) => { if (form.elements[name]) form.elements[name].value=savedPalette[i]; });
|
||||
preview(saved);
|
||||
status.textContent = '';
|
||||
};
|
||||
const close = () => {
|
||||
if (form.querySelector('[type=submit]').disabled) return;
|
||||
restore();
|
||||
dialog.close();
|
||||
};
|
||||
|
||||
input.addEventListener('input', () => preview(input.value));
|
||||
paletteNames.forEach(name => form.elements[name]?.addEventListener('input',palettePreview));
|
||||
open.addEventListener('click', () => {
|
||||
restore();
|
||||
dialog.showModal();
|
||||
@@ -46,25 +58,29 @@
|
||||
event.preventDefault();
|
||||
const submit = form.querySelector('[type=submit]');
|
||||
if (submit.disabled) return;
|
||||
const submitted = new URLSearchParams(new FormData(form));
|
||||
const controls = [...form.querySelectorAll('input,select,button')].filter(node => !node.disabled);
|
||||
controls.forEach(node => { node.disabled=true; });
|
||||
submit.disabled = true;
|
||||
status.textContent = '';
|
||||
try {
|
||||
const response = await fetch(form.action, {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams(new FormData(form)),
|
||||
body: submitted,
|
||||
headers: {Accept: 'application/json'},
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
if (!response.ok) throw new Error((await response.text()).trim());
|
||||
await response.json();
|
||||
saved = Number(input.value);
|
||||
saved = Number(submitted.get('home_glass_transparency'));
|
||||
savedPalette = paletteNames.map(name => submitted.get(name));
|
||||
preview(saved);
|
||||
status.textContent = form.dataset.saved;
|
||||
window.setTimeout(() => dialog.open && dialog.close(), 350);
|
||||
} catch (error) {
|
||||
status.textContent = error.message;
|
||||
} finally {
|
||||
submit.disabled = false;
|
||||
controls.forEach(node => { node.disabled=false; });
|
||||
}
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,58 @@
|
||||
/* Bounded, dependency-free palette math; also exercised by node --test. */
|
||||
((root) => {
|
||||
'use strict';
|
||||
const clamp = (x, a = 0, b = 1) => Math.max(a, Math.min(b, x));
|
||||
const mix = (a, b, n) => a.map((x, i) => x * (1 - n) + b[i] * n);
|
||||
const luminance = c => c.map(x => { x /= 255; return x <= .04045 ? x / 12.92 : ((x + .055) / 1.055) ** 2.4; }).reduce((a, x, i) => a + x * [.2126, .7152, .0722][i], 0);
|
||||
const contrast = (a, b) => (Math.max(luminance(a), luminance(b)) + .05) / (Math.min(luminance(a), luminance(b)) + .05);
|
||||
const ink = bg => contrast([255,255,255], bg) >= contrast([0,0,0], bg) ? [255,255,255] : [0,0,0];
|
||||
const readable = (c, bg, ratio) => {
|
||||
const end = ink(bg);
|
||||
for (let n = 0; n <= 20; n++) { const v = mix(c, end, n / 20); if (contrast(v, bg) >= ratio) return v; }
|
||||
return end;
|
||||
};
|
||||
const css = c => '#' + c.map(v => Math.round(clamp(v,0,255)).toString(16).padStart(2,'0')).join('');
|
||||
function extract(pixels) {
|
||||
if (!pixels || pixels.length > 64 * 64 * 4 || pixels.length % 4) return null;
|
||||
const bins = new Map(), sum = [0,0,0]; let weight = 0;
|
||||
for (let i = 0; i < pixels.length; i += 4) {
|
||||
const a = pixels[i+3] / 255; if (a < .06) continue;
|
||||
const c = [pixels[i], pixels[i+1], pixels[i+2]], key = c.map(x => x >> 5).join(',');
|
||||
const bin = bins.get(key) || {sum:[0,0,0], weight:0};
|
||||
c.forEach((v,j) => { sum[j] += v*a; bin.sum[j] += v*a; });
|
||||
bin.weight += a; weight += a; bins.set(key, bin);
|
||||
}
|
||||
if (!weight) return null;
|
||||
const average = sum.map(x => x / weight); let accent = average, best = 0;
|
||||
for (const bin of bins.values()) {
|
||||
const c = bin.sum.map(x => x / bin.weight), hi = Math.max(...c), lo = Math.min(...c);
|
||||
const saturation = hi ? (hi-lo)/hi : 0, light = luminance(c);
|
||||
const score = Math.sqrt(bin.weight) * saturation * (light > .025 && light < .85 ? 1 : .1);
|
||||
if (score > best) { best = score; accent = c; }
|
||||
}
|
||||
return {average, accent, coverage:weight / (pixels.length / 4)};
|
||||
}
|
||||
function colors(p, base, opts) {
|
||||
if (!p || opts.mode === 'off' || !opts.strength || opts.opacity <= 0) return {};
|
||||
const strength = clamp(opts.strength / 100), opacity = clamp(opts.opacity * p.coverage);
|
||||
const backdrop = mix(base.bg, p.average, opacity);
|
||||
const dark = opts.brightness === 'auto' && opts.mode === 'surface' ? luminance(backdrop) < .36 : luminance(base.bg) < .36;
|
||||
const neutral = dark ? [18,20,26] : [244,246,250];
|
||||
const hue = mix(p.average, p.accent, .35);
|
||||
const tinted = mix(neutral, hue, dark ? .23 : .12);
|
||||
const bg = opts.mode === 'surface' ? mix(opts.brightness === 'auto' ? neutral : base.bg, tinted, strength) : base.bg;
|
||||
const behind = mix(bg, p.average, opacity), glass = mix(behind, bg, clamp(opts.glass));
|
||||
const accent = readable(mix(base.accent, p.accent, strength), glass, 3);
|
||||
const result = {'--accent':css(accent), '--link':css(readable(accent, glass, 4.5)), '--link-hover':css(readable(accent,glass,7))};
|
||||
if (opts.mode !== 'surface') return result;
|
||||
const fg = readable(dark ? [238,242,248] : [22,25,32], glass, 7);
|
||||
Object.assign(result, {'--bg':css(bg), '--panel':css(bg), '--fg':css(fg), '--muted':css(readable(mix(fg,glass,.3),glass,4.5)),
|
||||
'--border':css(mix(bg,accent,.32)), '--border-soft':css(mix(bg,accent,.18)),
|
||||
'--input-bg':css(bg), '--input-fg':css(fg), '--input-border':css(mix(bg,accent,.4)),
|
||||
'--button-bg':css(bg), '--button-fg':css(fg), '--button-border':css(mix(bg,accent,.4)), '--button-hover-bg':css(mix(bg,accent,.12))});
|
||||
return result;
|
||||
}
|
||||
const api = {extract, colors, luminance, contrast, mix};
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = api;
|
||||
else root.HomePalette = api;
|
||||
})(globalThis);
|
||||
@@ -0,0 +1,48 @@
|
||||
const test=require('node:test'), assert=require('node:assert/strict');
|
||||
const p=require('./home-palette-core.js');
|
||||
const pixels=(color,count=4096)=>new Uint8ClampedArray(Array.from({length:count},()=>color).flat());
|
||||
const rgb=hex=>[1,3,5].map(i=>parseInt(hex.slice(i,i+2),16));
|
||||
const base={bg:[17,17,17],fg:[240,240,240],accent:[176,119,255]};
|
||||
const opts={mode:'surface',strength:35,brightness:'preserve',opacity:.4,glass:.58};
|
||||
test('bounded transparent and invalid input',()=>{
|
||||
assert.equal(p.extract(pixels([0,0,0,0])),null);
|
||||
assert.equal(p.extract(new Uint8Array(64*64*4+4)),null);
|
||||
assert.equal(p.extract(new Uint8Array(3)),null);
|
||||
assert.equal(p.extract(new Uint8Array(0)),null);
|
||||
});
|
||||
test('solid colors and alpha coverage',()=>{
|
||||
assert.deepEqual(p.extract(pixels([10,70,180,255])).average,[10,70,180]);
|
||||
assert.ok(Math.abs(p.extract(pixels([10,70,180,128])).coverage-128/255)<1e-10);
|
||||
});
|
||||
test('colored minority is selected instead of a muddy average',()=>{
|
||||
const data=pixels([180,180,180,255]);for(let i=0;i<400*4;i+=4)data.set([20,90,220,255],i);
|
||||
assert.deepEqual(p.extract(data).accent,[20,90,220]);
|
||||
});
|
||||
test('off, invisible wallpaper and zero strength preserve all tokens',()=>{
|
||||
const palette=p.extract(pixels([40,90,220,255]));
|
||||
for(const change of [{mode:'off'},{strength:0},{opacity:0}])assert.deepEqual(p.colors(palette,base,{...opts,...change}),{});
|
||||
});
|
||||
test('accent only never changes surfaces, brightness or semantic colors',()=>{
|
||||
const c=p.colors(p.extract(pixels([240,100,30,255])),base,{...opts,mode:'accent',brightness:'auto'});
|
||||
assert.deepEqual(Object.keys(c).sort(),['--accent','--link','--link-hover']);
|
||||
});
|
||||
test('dark/light, black/white and colored wallpaper keep readable panel text',()=>{
|
||||
for(const bg of [[17,17,17],[245,245,245]])for(const color of [[0,0,0],[255,255,255],[200,30,100],[20,90,220]])for(const strength of [5,35,100]) {
|
||||
const palette=p.extract(pixels([...color,255]));
|
||||
const c=p.colors(palette,{...base,bg},{...opts,strength});
|
||||
const surface=rgb(c['--bg']),behind=p.mix(surface,palette.average,opts.opacity),glass=p.mix(behind,surface,opts.glass);
|
||||
// Target enhanced contrast where possible; mid-tone glass can only provide
|
||||
// normal contrast even with pure black/white. Allow for RGB rounding.
|
||||
assert.ok(p.contrast(rgb(c['--fg']),glass)>4.4);
|
||||
assert.ok(p.contrast(rgb(c['--muted']),glass)>4.4);
|
||||
assert.ok(!('--danger' in c));
|
||||
assert.ok(Object.values(c).every(v=>/^#[0-9a-f]{6}$/.test(v)));
|
||||
}
|
||||
});
|
||||
test('auto brightness follows composited wallpaper, not invisible source pixels',()=>{
|
||||
const palette=p.extract(pixels([255,255,255,255]));
|
||||
const dark=p.colors(palette,base,{...opts,brightness:'auto',opacity:.1});
|
||||
const light=p.colors(palette,base,{...opts,brightness:'auto',opacity:1});
|
||||
assert.ok(p.luminance(rgb(dark['--bg']))<.1);
|
||||
assert.ok(p.luminance(rgb(light['--bg']))>.5);
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
const config = document.querySelector('[data-home-palette]'), img = document.querySelector('body > .home-wallpaper');
|
||||
if (!config || !img || !window.HomePalette) return;
|
||||
const body = document.body, core = window.HomePalette, forced = matchMedia('(forced-colors: active)');
|
||||
let options = {mode:config.dataset.mode, strength:Number(config.dataset.strength), brightness:config.dataset.brightness};
|
||||
let palette = null, pending = false, attempted = false;
|
||||
const originals = new Map();
|
||||
const restore = () => {
|
||||
for (const [key, value] of originals) { if (value[0]) body.style.setProperty(key,...value); else body.style.removeProperty(key); }
|
||||
originals.clear(); delete body.dataset.homePaletteActive;
|
||||
};
|
||||
const valid = p => p && ['average','accent'].every(k => Array.isArray(p[k]) && p[k].length === 3 && p[k].every(v => Number.isFinite(v) && v >= 0 && v <= 255)) && Number.isFinite(p.coverage) && p.coverage > 0 && p.coverage <= 1;
|
||||
const cacheName = 'pageswiki.wallpaper-palette.v1';
|
||||
const key = /^[a-f0-9]{64}$/.test(config.dataset.key || '') ? config.dataset.domain + ':' + config.dataset.key : '';
|
||||
const cacheRead = () => { try { const rows = JSON.parse(sessionStorage.getItem(cacheName) || '[]'); if (!Array.isArray(rows) || rows.length > 24) return; const row = rows.find(x => x.key === key); if (row && valid(row.palette)) return row.palette; } catch {} };
|
||||
const cacheWrite = p => {
|
||||
if (!key) return;
|
||||
let rows=[];
|
||||
try { rows=JSON.parse(sessionStorage.getItem(cacheName) || '[]'); } catch {}
|
||||
if (!Array.isArray(rows)) rows=[];
|
||||
rows=rows.filter(x => x && x.key !== key && valid(x.palette)).slice(-23);
|
||||
rows.push({key,palette:p});
|
||||
try { sessionStorage.setItem(cacheName, JSON.stringify(rows)); } catch {}
|
||||
};
|
||||
// Resolve custom-theme CSS colors (including color-mix) through computed style.
|
||||
function baseColors() {
|
||||
const probe = document.createElement('span'), canvas = document.createElement('canvas');
|
||||
canvas.width=canvas.height=1;
|
||||
const ctx=canvas.getContext('2d',{willReadFrequently:true});
|
||||
probe.hidden=true; body.append(probe);
|
||||
try {
|
||||
const read = name => { probe.style.color=`var(--${name})`; ctx.clearRect(0,0,1,1); ctx.fillStyle=getComputedStyle(probe).color; ctx.fillRect(0,0,1,1); return [...ctx.getImageData(0,0,1,1).data].slice(0,3); };
|
||||
return {bg:read('bg'), fg:read('fg'), accent:read('accent')};
|
||||
} finally { probe.remove(); }
|
||||
}
|
||||
function apply() {
|
||||
restore();
|
||||
if (!palette || options.mode === 'off' || !options.strength || forced.matches) return;
|
||||
try {
|
||||
const glass = parseFloat(getComputedStyle(body).getPropertyValue('--home-glass-opacity')) / 100;
|
||||
const values=core.colors(palette,baseColors(),{...options,opacity:Number(getComputedStyle(img).opacity),glass:Number.isFinite(glass)?glass:.58});
|
||||
if (!Object.keys(values).length) return;
|
||||
for (const [name,value] of Object.entries(values)) { originals.set(name,[body.style.getPropertyValue(name),body.style.getPropertyPriority(name)]); body.style.setProperty(name,value); }
|
||||
body.dataset.homePaletteActive=options.mode;
|
||||
} catch { restore(); }
|
||||
}
|
||||
function schedule() {
|
||||
if (options.mode === 'off' || !options.strength || forced.matches) { restore(); return; }
|
||||
if (palette) { apply(); return; }
|
||||
if (!img.complete || !img.naturalWidth || pending || attempted) return;
|
||||
pending=true;
|
||||
const work=() => {
|
||||
pending=false;
|
||||
if (options.mode === 'off' || !options.strength || forced.matches) return;
|
||||
attempted=true;
|
||||
try {
|
||||
palette=key && cacheRead();
|
||||
if (!palette) {
|
||||
const canvas=document.createElement('canvas'); canvas.width=canvas.height=64;
|
||||
const ctx=canvas.getContext('2d',{willReadFrequently:true});
|
||||
// Reuse the already displayed/decoded image: no second fetch or random pick.
|
||||
ctx.drawImage(img,0,0,64,64); palette=core.extract(ctx.getImageData(0,0,64,64).data);
|
||||
if (valid(palette)) { cacheWrite(palette); config.dataset.paletteSource='image'; }
|
||||
} else config.dataset.paletteSource='cache';
|
||||
if (valid(palette)) apply();
|
||||
} catch { palette=null; restore(); }
|
||||
};
|
||||
if ('requestIdleCallback' in window) requestIdleCallback(work,{timeout:1500}); else setTimeout(work,32);
|
||||
}
|
||||
document.addEventListener('pageswiki:home-appearance', event => { if (event.detail) options={...options,...event.detail}; schedule(); });
|
||||
document.addEventListener('pageswiki:theme',schedule);
|
||||
document.addEventListener('load', event => { if (event.target instanceof HTMLLinkElement && event.target.rel === 'stylesheet') schedule(); },true);
|
||||
forced.addEventListener('change',schedule);
|
||||
img.addEventListener('load',schedule);
|
||||
img.addEventListener('error',() => { palette=null; restore(); });
|
||||
schedule();
|
||||
})();
|
||||
@@ -7,6 +7,8 @@
|
||||
const writable=root.dataset.writable==='true',today=root.dataset.today,zone=root.dataset.timezone;
|
||||
const names={progress:t('Today’s completion','本日の達成率'),today:t('Today’s tasks','本日のタスク'),tomorrow:t('Tomorrow’s tasks','明日のタスク'),tasks:t('Tasks','タスク'),schedule:t('Today’s schedule','本日のスケジュール'),activity:t('Activity report','達成度・作業レポート')};
|
||||
const defaults=[['progress',4,3],['today',4,3],['tomorrow',4,3],['tasks',8,4],['schedule',4,4],['activity',12,5]].map(([id,width,height])=>({id,width,height,...(id==='tasks'?{tab:'inbox'}:{})}));
|
||||
names.feeds=t('RSS · latest cached articles','RSS · 最近の取得記事');
|
||||
const available=[...defaults,{id:'feeds',width:6,height:4}];
|
||||
const tabs={inbox:'Inbox',backlog:'Backlog',someday:'Someday',review:'Review',all:'Incomplete',done:'Done'};
|
||||
const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
|
||||
function button(text,label,fn){const b=el('button',text);b.type='button';b.title=b.ariaLabel=label;b.onclick=fn;return b;}
|
||||
@@ -31,7 +33,7 @@
|
||||
});
|
||||
const edit=button('⚙',t('Arrange widgets','ウィジェットを配置'),()=>{editing=!editing;root.classList.toggle('is-arranging',editing);edit.setAttribute('aria-pressed',String(editing));});edit.setAttribute('aria-pressed','false');
|
||||
const refresh=button('↻',t('Refresh visible widgets','ウィジェットを更新'),()=>{for(const item of widgets){const card=cards.get(item.id);if(card)loadWidget(item,card);}});
|
||||
const add=el('select');add.ariaLabel=t('Add widget','ウィジェットを追加');add.onchange=()=>{const item=defaults.find(w=>w.id===add.value);if(item){widgets.push({...item});render();changed();}};
|
||||
const add=el('select');add.ariaLabel=t('Add widget','ウィジェットを追加');add.onchange=()=>{const item=available.find(w=>w.id===add.value);if(item){widgets.push({...item});render();changed();}};
|
||||
const reset=button(t('Reset layout','初期配置'),t('Reset layout','初期配置'),()=>{if(confirm(t('Replace this layout with the default layout? Save to apply.','初期配置に戻しますか? 保存するまでは確定しません。'))){widgets=defaults.map(x=>({...x}));render();changed();}});
|
||||
controls.append(refresh);if(writable)controls.append(edit,add,reset,save);
|
||||
function updateControls(){save.disabled=!dirty||saving||!loaded;edit.disabled=add.disabled=reset.disabled=saving||!loaded;refresh.disabled=!loaded;root.classList.toggle('dashboard-saving',saving);for(const card of cards.values())card.querySelectorAll('.widget-arrange button,.widget-arrange select,.widget-drag,.widget-resize').forEach(n=>n.disabled=saving);add.replaceChildren();const option=el('option',t('+ Add widget','+ ウィジェットを追加'));option.value='';add.append(option);for(const [id,name] of Object.entries(names)){if(widgets.some(w=>w.id===id)||id==='schedule'&&root.dataset.calendar!=='true')continue;const o=el('option',name);o.value=id;add.append(o);}}
|
||||
@@ -45,6 +47,7 @@
|
||||
const card=el('section',undefined,'dashboard-widget');card.id=item.id;card.dataset.widget=item.id;applySize(item,card);
|
||||
const header=el('header',undefined,'widget-header'),heading=el('h2',names[item.id]);heading.id='widget-title-'+item.id;card.setAttribute('aria-labelledby',heading.id);
|
||||
header.append(heading);const destinations={progress:'/v/plan/today',today:'/v/plan/today',tomorrow:'/v/plan/tasks/tomorrow',tasks:'/v/plan/tasks',schedule:'/v/plan',activity:'/v/plan/dashboard#activity'};
|
||||
destinations.feeds='/v/feeds';
|
||||
const open=link('↗',destinations[item.id]);open.title=open.ariaLabel=t('Open ','開く: ')+names[item.id];header.append(open);
|
||||
const arrange=el('div',undefined,'widget-arrange');
|
||||
if(writable){
|
||||
@@ -78,6 +81,11 @@
|
||||
if(controller.signal.aborted||!card.isConnected)return;
|
||||
const signal=AbortSignal.any([controller.signal,AbortSignal.timeout(15000)]);
|
||||
try{
|
||||
if(item.id==='feeds'){
|
||||
const data=await request('/_/api/v1/extension/organizer.feeds/items',{signal});if(controller.signal.aborted)return;
|
||||
const list=el('ul',undefined,'dashboard-list');for(const item of data.items.slice(0,12)){const row=el('li');row.append(el('span',item.read?'○':'●'),link(item.title||t('(Untitled)','(無題)'),'/v/feeds?'+new URLSearchParams({source:item.source,id:item.id})));list.append(row);}
|
||||
body.replaceChildren(list);if(!data.items.length)body.append(el('p',t('No cached articles.','取得済みの記事はありません。')));return;
|
||||
}
|
||||
if(item.id==='activity'){
|
||||
body.replaceChildren();const report=el('section');report.id='task-productivity';report.dataset.view='report';const h=el('h3');h.className='visually-hidden';const message=el('p');message.id='productivity-status';message.role='status';const content=el('div');content.id='productivity-content';report.append(h,message,content);body.append(report);await window.PagesWikiProductivityMount(report,controller.signal);return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
const root=document.getElementById('task-digest-history');if(!root)return;
|
||||
const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en;
|
||||
const api='/_/api/v1/extension/organizer.tasks/digest-history';
|
||||
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
|
||||
const states={queued:t('Queued','待機中'),sending:t('Sending / pending result','送信中・結果待ち'),sent:t('Accepted by mail server','メールサーバー受付済み'),uncertain:t('Delivery uncertain','結果不明'),cancelled:t('Not sent','送信中止')};
|
||||
const reasons={legacy:t('Migrated record; attempt details unknown','移行前の記録(詳細不明)'),smtp_unavailable:t('SMTP unavailable','SMTPを利用できません'),tasks_unavailable:t('Tasks unavailable','タスクを取得できません'),consent_changed:t('Settings or permission changed','設定・権限が変わりました'),transport_uncertain:t('SMTP result uncertain','SMTPの結果が不明です'),extension_disabled:t('Extension disabled','拡張機能が無効です'),day_expired:t('Requested date has passed','対象日を過ぎました'),worker_interrupted:t('Worker interrupted; check for delivery','処理中断の可能性・受信を確認してください')};
|
||||
const details=el('details'),summary=el('summary',t('Email delivery history and retry','メール配信履歴・再送'));details.append(summary);root.append(details);
|
||||
const status=el('p');status.role='status';status.setAttribute('aria-live','polite');
|
||||
const controls=el('div'),refresh=el('button','↻ '+t('Refresh','更新'));refresh.type='button';controls.className='productivity-controls';controls.append(refresh);
|
||||
const content=el('div'),pager=el('div');pager.className='productivity-controls';details.append(status,controls,content,pager);
|
||||
let loaded=false,busy=false,cursor='',stack=[],pending=null,generation=0;
|
||||
async function request(suffix='',options={}){
|
||||
const response=await fetch(api+suffix,{credentials:'same-origin',cache:'no-store',signal:AbortSignal.timeout(15000),...options,headers:{'Content-Type':'application/json'}});
|
||||
const data=await response.json().catch(()=>({}));
|
||||
if(!response.ok||response.redirected){const errors={conflict:t('Changed, already queued, or the daily retry limit was reached. Refresh to check.','状態の変更・処理中・再送回数上限のいずれかです。更新して確認してください。'),invalid:t('Check the date and duplicate-delivery confirmation.','対象日と重複送信の確認を見直してください。'),forbidden:t('Enable delivery and check your permissions.','配信設定と権限を確認してください。'),email_required:t('Set your account email first.','先にプロフィールのメールアドレスを設定してください。'),smtp_unavailable:t('SMTP is not configured or enabled.','SMTPが未設定または無効です。')};const error=Error(errors[data.error]||t('Unable to confirm the result. Retry uses the same request.','結果を確認できません。同じ要求で再試行できます。'));error.status=response.status;throw error;}
|
||||
return data;
|
||||
}
|
||||
function retryForm(data){
|
||||
const box=el('div');box.className='digest-retry';const current=data.current;
|
||||
box.append(el('p',t('Retries use current tasks and your current account email, not the original message. Saved settings apply. Up to 5 retries per day.','再送は元の本文ではなく、現在のタスクとアカウントのメールアドレスを使います。保存済み設定に従い、1日5回までです。')));
|
||||
if(pending&¤t?.uuid===pending.request_id){pending=null;status.textContent=t('Request is recorded. Check its status below.','要求は記録されています。以下の状態を確認してください。');}
|
||||
if(root.dataset.writable!=='true')return box;
|
||||
if(!pending&&(!data.enabled||!current||['queued','sending'].includes(current.state)||data.retries>=5)){
|
||||
box.append(el('p',!data.enabled?t('Enable daily email in the settings above.','上の設定で日次メールを有効にしてください。'):!current?t('No delivery attempt for today yet.','本日の配信記録はまだありません。'):data.retries>=5?t('Daily retry limit reached.','本日の再送回数上限に達しました。'):t('Request is queued or running. Refresh later.','待機中または実行中です。しばらくして更新してください。')));return box;
|
||||
}
|
||||
const form=el('form'),ack=el('input'),label=el('label');ack.type='checkbox';ack.checked=!!pending?.duplicate_acknowledged;
|
||||
const duplicate=pending?pending.duplicate_acknowledged:['sent','uncertain'].includes(current.state);
|
||||
ack.required=duplicate;label.append(ack,document.createTextNode(t('I checked my inbox and accept possible duplicate delivery.','受信状況を確認し、重複して届く可能性を了承します。')));if(duplicate)form.append(label);
|
||||
const send=el('button',pending?t('Retry the same request','同じ要求で再試行'):t('Queue today’s email again','本日分の再送を予約'));send.type='submit';form.append(send);box.append(form);
|
||||
form.onsubmit=async event=>{event.preventDefault();if(busy||!form.reportValidity())return;
|
||||
if(!pending)pending={request_id:crypto.randomUUID(),day:current.day,expected_attempt:current.uuid,duplicate_acknowledged:duplicate&&ack.checked};
|
||||
busy=true;send.disabled=refresh.disabled=ack.disabled=true;pager.inert=true;
|
||||
try{await request('/retry',{method:'POST',body:JSON.stringify(pending)});pending=null;cursor='';stack=[];const refreshed=await load();if(refreshed)status.textContent=t('Queued. The scheduler will process this request; queue delays may apply.','予約しました。スケジューラが処理するまでお待ちください。');else status.textContent=t('Request accepted. ','予約済みです。')+status.textContent;}
|
||||
catch(error){if(error.status>=400&&error.status<500)pending=null;status.textContent=error.message;send.textContent=pending?t('Retry the same request','同じ要求で再試行'):t('Queue today’s email again','本日分の再送を予約');}
|
||||
finally{busy=false;send.disabled=refresh.disabled=ack.disabled=false;pager.inert=false;}
|
||||
};return box;
|
||||
}
|
||||
async function load(){
|
||||
const ticket=++generation;refresh.disabled=true;content.inert=true;pager.inert=true;
|
||||
try{const data=await request('?'+new URLSearchParams({limit:'25',...(cursor?{after:cursor}:{})}));if(ticket!==generation)return;
|
||||
const table=el('table');table.className='productivity-table';const head=el('tr');for(const title of [t('Date','対象日'),t('Method','区分'),t('Status','状態'),t('Updated','更新'),t('Detail','詳細')])head.append(el('th',title));const thead=el('thead');thead.append(head);table.append(thead);const body=el('tbody');
|
||||
for(const item of data.items){const row=el('tr');const date=new Date(item.updated_ms).toLocaleString(ja?'ja-JP':'en-GB',{timeZone:item.timezone||undefined});for(const value of [item.day,item.kind==='manual'?t('Manual','手動'):item.kind==='legacy'?t('Legacy','移行前'):t('Scheduled','定期'),states[item.state]||item.state,date+(item.timezone?' · '+item.timezone:''),reasons[item.reason]||''])row.append(el('td',value));body.append(row);}table.append(body);
|
||||
const wrap=el('div');wrap.className='productivity-table-wrap';wrap.append(table);if(!data.items.length)wrap.append(el('p',t('No delivery history.','配信履歴はありません。')));
|
||||
status.textContent='';content.replaceChildren(retryForm(data),wrap,el('p',t('Detailed attempts: '+data.retention_days+' days. Duplicate-prevention receipts are retained. An accepted message is not a guarantee of inbox delivery.','詳細履歴は'+data.retention_days+'日保持します。重複防止記録は残します。メールサーバーの受付は受信箱への到達保証ではありません。')));
|
||||
pager.replaceChildren();const button=(title,fn)=>{const b=el('button',title);b.type='button';b.onclick=fn;pager.append(b);};
|
||||
if(stack.length)button(t('Previous','前へ'),()=>{if(!busy){cursor=stack.pop();load();}});
|
||||
if(data.next)button(t('Next','次へ'),()=>{if(!busy){stack.push(cursor);cursor=data.next;load();}});loaded=true;return true;
|
||||
}catch(error){status.textContent=error.message;}finally{if(ticket===generation){refresh.disabled=false;content.inert=false;pager.inert=false;}}
|
||||
}
|
||||
refresh.onclick=()=>{if(!busy){cursor='';stack=[];load();}};
|
||||
details.ontoggle=()=>{if(details.open&&!loaded)load();};
|
||||
})();
|
||||
@@ -30,22 +30,26 @@
|
||||
if(key==='reminder_time'){const help=el('p',ja?'新規タスクの対応する日付が設定されている場合だけ通知します。既存タスクは変更しません。通知時刻は保存時のドメインのタイムゾーン('+data.timezone+')を使用します。':'Reminders apply only to new tasks with the corresponding date. Existing tasks are unchanged. Times use the Domain timezone on save ('+data.timezone+').');help.className='productivity-note';form.append(help);}
|
||||
}
|
||||
const note=el('p',ja?'日数は作成日からの暦日です。空欄は未設定、0は当日。担当者の指定では閲覧権限は付与されません。メールは今日の計画・期限到来分を最大100件送ります。SMTPは管理者設定を使用し、配信時刻にはキュー待ちの遅延があります。':'Offsets are calendar days from creation; blank means unset, 0 means today. Assignment does not grant access. Email includes up to 100 tasks planned or due today, using administrator SMTP settings. Queue delays may apply.');note.className='productivity-note';form.append(note);
|
||||
if(data.last_digest){const states={sent:['Sent','送信済み'],sending:['Sending / result pending','送信中・結果未確定'],uncertain:['Delivery uncertain (no automatic retry)','結果不明(自動再送なし)'],cancelled:['Cancelled','送信取消']};form.append(el('p',(ja?'直近の配信: ':'Latest delivery: ')+data.last_digest.day+' · '+(states[data.last_digest.state]||['Unknown','不明'])[ja?1:0]));}
|
||||
const save=el('button',t('save'));save.type='submit';save.disabled=root.dataset.writable!=='true';form.append(save);content.replaceChildren(form);
|
||||
fields.project_uuid.value=p.project_uuid||'';
|
||||
form.onsubmit=async event=>{event.preventDefault();if(!form.reportValidity())return;save.disabled=true;const value={...p};for(const [key,input] of Object.entries(fields)){value[key]=input.type==='checkbox'?input.checked:input.type==='number'?(input.value===''?null:Number(input.value)):input.value;}try{const result=await request('preferences',{method:'PUT',body:JSON.stringify(value)});Object.assign(p,result.preferences);status.textContent=t('saved');}catch(e){error(e);}finally{save.disabled=false;}};
|
||||
}
|
||||
function taskTable(data){const wrap=el('div');wrap.className='productivity-table-wrap';const table=el('table');table.className='productivity-table';const head=el('tr');for(const name of [ja?'タスク':'Task',t('points'),t('work')])head.append(el('th',name));const thead=el('thead');thead.append(head);table.append(thead);const body=el('tbody');for(const task of data.tasks){const row=el('tr'),name=el('td'),link=el('a',(task.completed?'✓ ':'')+(task.title||task.uuid));link.href='/v/plan/task/'+encodeURIComponent(task.uuid);name.append(link);row.append(name,el('td',String(task.points||0)),el('td',(task.work_ms/3600000).toFixed(2)));body.append(row);}table.append(body);wrap.append(table);if(!data.tasks.length)wrap.append(el('p',t('empty')));return wrap;}
|
||||
function projectTable(data){
|
||||
const wrap=el('section');wrap.className='productivity-table-wrap';wrap.append(el('h3',ja?'プロジェクト別':'By project'));
|
||||
const table=el('table');table.className='productivity-table';const head=el('tr');for(const title of [ja?'プロジェクト':'Project',t('completed'),t('points'),t('work')])head.append(el('th',title));const thead=el('thead');thead.append(head);table.append(thead);const body=el('tbody');
|
||||
for(const p of data.projects||[]){const row=el('tr'),name=el('td');if(p.uuid){const link=el('a',p.title||p.uuid);link.href='/v/plan/project/'+encodeURIComponent(p.uuid);name.append(link);}else name.textContent=ja?'プロジェクトなし':'No project';row.append(name,el('td',String(p.completed)),el('td',String(p.points)),el('td',(p.work_ms/3600000).toFixed(2)));body.append(row);}table.append(body);wrap.append(table,el('small',ja?'現在の所属で集計します。集中時間(Pomodoro)は別集計です。':'Grouped by current project membership. Pomodoro time is reported separately.'));return wrap;
|
||||
}
|
||||
async function report(){
|
||||
const controls=el('form');controls.className='productivity-controls';const from=el('input'),to=el('input');from.type=to.type='date';from.required=to.required=true;from.ariaLabel=ja?'開始日':'From';to.ariaLabel=ja?'終了日(含まない)':'To (exclusive)';const refresh=el('button','↻ '+t('refresh'));controls.append(from,to,refresh);
|
||||
const controls=el('form');controls.className='productivity-controls';const from=el('input'),to=el('input');from.type=to.type='date';from.required=to.required=true;from.ariaLabel=ja?'開始日':'From';to.ariaLabel=ja?'終了日(含まない)':'To (exclusive)';const refresh=el('button','↻ '+t('refresh'));const history=el('a',ja?'作業記録・訂正':'Work history & corrections');history.href='/v/plan/tasks/work';controls.append(from,to,refresh,history);
|
||||
const results=el('section');content.replaceChildren(controls,results);let generation=0;
|
||||
async function load(){const ticket=++generation;refresh.disabled=true;try{const query=new URLSearchParams();if(from.value)query.set('from',from.value);if(to.value)query.set('to',to.value);const d=await request('report?'+query);if(ticket!==generation)return;status.textContent=d.partial?t('partial'):d.timezone;
|
||||
if(!from.value&&d.days.length){from.value=d.days[0].date;const end=new Date(d.days.at(-1).date+'T12:00:00Z');end.setUTCDate(end.getUTCDate()+1);to.value=end.toISOString().slice(0,10);}
|
||||
const stats=el('div');stats.className='productivity-stats';for(const [label,key,divisor] of [['completed','completed',1],['points','points',1],['work','work_ms',3600000],['focus','focus_ms',3600000]]){const card=el('div',t(label));card.className='productivity-stat';const sum=d.days.reduce((total,day)=>total+day[key],0)/divisor;card.append(el('strong',divisor===1?String(sum):sum.toFixed(2)));stats.append(card);}
|
||||
const scroll=el('div');scroll.className='productivity-heatmap-scroll';const grid=el('div');grid.className='productivity-heatmap';grid.ariaLabel=t('report');const detail=el('section');detail.append(taskTable(d));let detailSequence=0;
|
||||
const scroll=el('div');scroll.className='productivity-heatmap-scroll';const grid=el('div');grid.className='productivity-heatmap';grid.ariaLabel=t('report');const detail=el('section');detail.append(projectTable(d),taskTable(d));let detailSequence=0;
|
||||
if(d.days.length){const weekday=new Date(d.days[0].date+'T12:00:00Z').getUTCDay();for(let i=0;i<weekday;i++)grid.append(el('span'));}
|
||||
for(const day of d.days){const cell=el('button');cell.type='button';cell.className='productivity-day';cell.dataset.level=String(day.points===0?0:day.points<=3?1:day.points<=8?2:day.points<=20?3:4);cell.title=cell.ariaLabel=`${day.date}: ${day.completed} ${t('completed')}, ${day.points} ${t('points')}, ${(day.work_ms/3600000).toFixed(2)}h`;
|
||||
cell.onclick=async()=>{const sequence=++detailSequence;try{const next=new Date(day.date+'T12:00:00Z');next.setUTCDate(next.getUTCDate()+1);const single=await request('report?'+new URLSearchParams({from:day.date,to:next.toISOString().slice(0,10)}));if(sequence!==detailSequence)return;detail.replaceChildren(el('h2',day.date),taskTable(single));}catch(e){error(e);}};grid.append(cell);}
|
||||
cell.onclick=async()=>{const sequence=++detailSequence;try{const next=new Date(day.date+'T12:00:00Z');next.setUTCDate(next.getUTCDate()+1);const single=await request('report?'+new URLSearchParams({from:day.date,to:next.toISOString().slice(0,10)}));if(sequence!==detailSequence)return;detail.replaceChildren(el('h2',day.date),projectTable(single),taskTable(single));}catch(e){error(e);}};grid.append(cell);}
|
||||
scroll.append(grid);const note=el('p',ja?'1タスクのポイント = 1 + ⌈見積分数 / 30⌉ × 複雑度(1〜5)。完了取消は集計から除外。作業時間とPomodoroは別集計で、重複する場合は加算しません。':'Points per task = 1 + ceil(estimated minutes / 30) × complexity (1–5). Reopened tasks are excluded. Work and Pomodoro are separate; overlapping time is not added together.');note.className='productivity-note';results.replaceChildren(stats,scroll,note,detail);
|
||||
}catch(e){error(e);}finally{refresh.disabled=false;}}
|
||||
controls.onsubmit=e=>{e.preventDefault();load();};await load();
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
const root=document.getElementById('task-work-history');if(!root)return;
|
||||
const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en;
|
||||
const api='/_/api/v1/extension/organizer.tasks/',writable=root.dataset.writable==='true',zone=root.dataset.timezone;
|
||||
const status=document.getElementById('work-history-status'),list=document.getElementById('work-history-list'),paging=document.getElementById('work-history-paging');
|
||||
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
|
||||
const button=(text,fn)=>{const b=el('button',text);b.type='button';b.onclick=fn;return b;};
|
||||
const messages={conflict:t('The record changed or overlaps another recording. Reload and check before retrying.','他の更新または作業時間の重複があります。再読み込みして確認してください。'),forbidden:t('You cannot change this record.','この記録は変更できません。'),invalid:t('Check the time range and reason. End must not be in the future; corrections are limited to 31 days. Ambiguous daylight-saving times require an explicit offset via the API.','日時と理由を確認してください。終了は現在以前、期間は31日以内です。夏時間の曖昧な時刻はAPIでオフセット指定が必要です。')};
|
||||
let controller=null,sequence=0,cursor='',stack=[],editing=null,busy=false;
|
||||
const form=el('form'),from=el('input'),to=el('input');form.className='work-history-controls';
|
||||
for(const [input,label] of [[from,t('From','開始日')],[to,t('To (exclusive)','終了日(含まない)')]]){input.type='date';input.required=true;const l=el('label',label);l.append(input);form.append(l);}
|
||||
const refresh=el('button','↻ '+t('Refresh','更新'));refresh.type='submit';form.append(refresh,el('span',zone));document.getElementById('work-history-controls').append(form);
|
||||
async function request(path,options={}){const r=await fetch(api+path,{credentials:'same-origin',cache:'no-store',signal:AbortSignal.any([AbortSignal.timeout(15000),controller.signal]),...options,headers:{'Content-Type':'application/json'}});const d=await r.json().catch(()=>({}));if(!r.ok||r.redirected)throw Error(messages[d.error]||t('Request failed. Input is retained.','処理に失敗しました。入力は保持しています。'));return d;}
|
||||
const parts=new Intl.DateTimeFormat('en-CA',{timeZone:zone,year:'numeric',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit',hourCycle:'h23'});
|
||||
const wall=ms=>{const p=Object.fromEntries(parts.formatToParts(new Date(ms)).map(x=>[x.type,x.value]));return `${p.year}-${p.month}-${p.day}T${p.hour}:${p.minute}:${p.second}`;};
|
||||
const stamp=ms=>ms?wall(ms).replace('T',' '):t('Running','記録中');
|
||||
const dirty=()=>editing&&[...editing.querySelectorAll('input,textarea')].some(n=>n.value!==n.defaultValue);
|
||||
const canLeave=()=>!busy&&(!dirty()||confirm(t('Discard unsaved changes?','未保存の変更を破棄しますか?')));
|
||||
window.addEventListener('beforeunload',e=>{if(dirty()||busy){e.preventDefault();e.returnValue='';}});
|
||||
function editor(entry,slot,action){
|
||||
if(!canLeave())return;if(editing)editing.remove();
|
||||
const f=el('form');f.className='work-history-edit';editing=f;
|
||||
const start=el('input'),end=el('input');
|
||||
if(action==='correct')for(const [input,value,label] of [[start,entry.start_ms,t('Start','開始')],[end,entry.end_ms,t('End','終了')]]){input.type='datetime-local';input.step='1';input.value=input.defaultValue=wall(value);input.required=true;const l=el('label',label+' · '+zone);l.append(input);f.append(l);}
|
||||
else f.append(el('p',t('Exclude this recording from reports. Its values and audit history are retained.','この記録を集計対象から除外します。元の時刻と変更履歴は残ります。')));
|
||||
const reason=el('input');reason.type='text';reason.required=true;reason.maxLength=160;const label=el('label',t('Reason','変更理由'));label.append(reason);f.append(label);
|
||||
const message=el('p');message.role='status';const save=el('button',action==='correct'?t('Save correction','訂正を保存'):t('Cancel recording','記録を取り消す'));save.type='submit';
|
||||
const dismiss=button(t('Close','閉じる'),()=>{if(canLeave()){f.remove();editing=null;}});f.append(message,save,dismiss);slot.append(f);reason.focus();
|
||||
f.onsubmit=async e=>{e.preventDefault();if(busy||!f.reportValidity())return;busy=true;const controls=[...f.querySelectorAll('input,button')];controls.forEach(n=>n.disabled=true);
|
||||
const data={uuid:entry.uuid,task_uuid:entry.task_uuid,version:entry.version,action,reason:reason.value};
|
||||
if(action==='correct'){data.start=start.value===start.defaultValue?new Date(entry.start_ms).toISOString():start.value;data.end=end.value===end.defaultValue?new Date(entry.end_ms).toISOString():end.value;}
|
||||
try{await request('work',{method:'POST',body:JSON.stringify(data)});editing=null;f.remove();cursor='';stack=[];if(await load())status.textContent=t('Saved. Reports now use the corrected values.','保存しました。集計にも反映されます。');}
|
||||
catch(error){message.textContent=error.message;}finally{busy=false;controls.forEach(n=>n.disabled=false);}
|
||||
};
|
||||
}
|
||||
function audit(entry,slot){
|
||||
const details=el('details'),summary=el('summary',t('Change history','変更履歴')),body=el('div');details.append(summary,body);slot.append(details);let loaded=false;
|
||||
const names={start:t('Started','開始'),stop:t('Stopped','終了'),correct:t('Corrected','訂正'),cancel:t('Cancelled','取消'),baseline:t('Previous value','以前の値')};
|
||||
async function more(before=0){body.replaceChildren(el('p',t('Loading…','読み込み中…')));try{const data=await request('work-history/'+encodeURIComponent(entry.uuid)+(before?'?before='+before:''));const rows=el('ol');for(const revision of data.items){const li=el('li');li.append(el('strong',`v${revision.item.version} · ${names[revision.action]||revision.action}`),el('p',`${stamp(revision.item.start_ms)} → ${stamp(revision.item.end_ms)}`));if(revision.reason)li.append(el('p',revision.reason));if(revision.changed_ms)li.append(el('small',stamp(revision.changed_ms)));rows.append(li);}body.replaceChildren(rows);if(data.next)body.append(button(t('Older changes','以前の変更'),()=>more(data.next)));loaded=true;}catch(e){if(e.name!=='AbortError')body.replaceChildren(el('p',e.message),button(t('Retry','再試行'),()=>more(before)));}}
|
||||
details.ontoggle=()=>{if(details.open&&!loaded)more();};
|
||||
}
|
||||
function render(entries){
|
||||
const table=el('table');table.className='work-history-table';const thead=el('thead'),head=el('tr');for(const title of [t('Task','タスク'),t('Start','開始'),t('End','終了'),t('Duration','時間'),t('Actions','操作')])head.append(el('th',title));thead.append(head);table.append(thead);const tbody=el('tbody');
|
||||
for(const entry of entries){const row=el('tr'),name=el('td'),link=el('a',entry.title||entry.task_uuid);link.href='/v/plan/task/'+encodeURIComponent(entry.task_uuid);name.append(link);if(entry.cancelled_ms)name.append(el('span',t(' · Cancelled',' · 取消済み')));const controls=el('td'),slot=el('td'),extra=el('tr');slot.colSpan=5;extra.append(slot);extra.className='work-history-extra';
|
||||
if(writable&&entry.end_ms&&!entry.cancelled_ms){controls.append(button(t('Edit','訂正'),()=>editor(entry,slot,'correct')),button(t('Cancel','取消'),()=>editor(entry,slot,'cancel')));}
|
||||
audit(entry,slot);const values=[name,el('td',stamp(entry.start_ms)),el('td',stamp(entry.end_ms)),el('td',entry.end_ms?((entry.end_ms-entry.start_ms)/3600000).toFixed(2)+'h':'—'),controls];values.forEach((cell,i)=>{cell.dataset.label=head.children[i].textContent;row.append(cell);});tbody.append(row,extra);
|
||||
}table.append(tbody);list.replaceChildren(table);if(!entries.length)list.append(el('p',t('No recordings in this period.','この期間の記録はありません。')));
|
||||
}
|
||||
async function load(){const ticket=++sequence;controller?.abort();controller=new AbortController();refresh.disabled=true;list.inert=true;status.textContent=t('Loading…','読み込み中…');try{const query=new URLSearchParams({limit:'50'});if(from.value)query.set('from',from.value);if(to.value)query.set('to',to.value);if(cursor)query.set('after',cursor);const data=await request('work-history?'+query);if(ticket!==sequence)return;from.value=data.from;to.value=data.to;editing=null;render(data.items);status.textContent='';paging.replaceChildren();if(stack.length)paging.append(button(t('Previous','前のページ'),()=>{if(canLeave()){cursor=stack.pop();load();}}));if(data.next)paging.append(button(t('Next','次のページ'),()=>{if(canLeave()){stack.push(cursor);cursor=data.next;load();}}));return true;}catch(error){if(error.name!=='AbortError')status.textContent=error.message;}finally{if(ticket===sequence){refresh.disabled=false;list.inert=false;}}}
|
||||
form.onsubmit=e=>{e.preventDefault();if(canLeave()){cursor='';stack=[];load();}};load();
|
||||
})();
|
||||
+1
-1
@@ -33,7 +33,7 @@
|
||||
const routes = {today:'/v/plan/today',all:'/v/plan/tasks',projects:'/v/plan/projects'};
|
||||
const icons = {carryover:'↶',today:'☀',tomorrow:'⇢',inbox:'↓',backlog:'≡',someday:'◇',review:'↻',all:'☷',projects:'▱',done:'✓',archived:'▣'};
|
||||
Object.keys(icons).forEach(key => { const a = el('a'); a.href = routes[key] || '/v/plan/tasks/' + key; a.append(el('span',icons[key]),el('span',t(key))); if(view===key||(key==='tomorrow'&&view==='day'&&selectedDate===nextDay(today)))a.setAttribute('aria-current','page'); $('nav').append(a); });
|
||||
const schedule=el('a','▦ '+t('schedule'));schedule.href='/v/plan/tasks/schedule'+(projectID?'?project='+projectID:'');$('nav').append(schedule);
|
||||
const schedule=el('a','▦ '+t('schedule'));schedule.href='/v/plan/tasks/schedule'+(projectID?'?project='+projectID:'');$('nav').append(schedule);const workHistory=el('a',ja?'◷ 作業記録':'◷ Work history');workHistory.href='/v/plan/tasks/work';$('nav').append(workHistory);
|
||||
$('date').textContent = view==='day'?selectedDate:today; $('heading').textContent = t(view === 'project' ? 'project' : view === 'detail' || view === 'new' ? 'all' : view);
|
||||
$('help').textContent = t(view==='today'?'todayHelp':view==='review'?'reviewHelp':'private');
|
||||
$('search-label').textContent=t('search');$('quick-title').placeholder=t('quick');$('quick-title').setAttribute('aria-label',t('title'));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{ define "auth.gohtml" }}<!doctype html>
|
||||
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>{{ if .CLIAuth }}{{ T "auth.cli_title" }}{{ else if .Logout }}{{ T "auth.logout" }}{{ else if .MFA }}{{ T "auth.totp" }}{{ else if .Setup }}{{ T "auth.setup" }}{{ else }}{{ T "auth.login" }}{{ end }} · {{ .WikiName }}</title>
|
||||
<link rel="stylesheet" href="/static/css/theme/base.css"><link rel="stylesheet" href="/static/css/main.css"><link rel="stylesheet" href="/static/css/home.css?v=12"><link rel="stylesheet" href="/static/css/auth.css?v=1"><link rel="stylesheet" href="{{ .ThemeCSS }}"></head>
|
||||
<link rel="stylesheet" href="/static/css/theme/base.css"><link rel="stylesheet" href="/static/css/main.css"><link rel="stylesheet" href="/static/css/home.css?v=13"><link rel="stylesheet" href="/static/css/auth.css?v=1"><link rel="stylesheet" href="{{ .ThemeCSS }}"></head>
|
||||
<body class="auth-page" style="--home-glass-opacity:{{ .HomeGlassOpacity }}%">
|
||||
{{ if .HomeWallpaperURL }}<img class="home-wallpaper" src="{{ .HomeWallpaperURL }}" alt="" aria-hidden="true" decoding="async" fetchpriority="high" style="opacity:{{ .HomeWallpaperOpacity }}">{{ end }}
|
||||
<a class="auth-brand" href="/">{{ .WikiName }}</a>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<link rel="stylesheet" href="/static/css/theme/base.css">
|
||||
<link rel="stylesheet" href="{{ .ThemeCSS }}">
|
||||
<link rel="stylesheet" href="/static/css/config.css?v=external-resources-1">
|
||||
<link rel="stylesheet" href="/static/css/config.css?v=home-palette-1">
|
||||
</head>
|
||||
|
||||
<body class="mode-config">
|
||||
@@ -107,6 +107,7 @@
|
||||
<p class="muted wide">{{ T "home.wallpaper_help" }}</p>
|
||||
<label class="wide">{{ T "home.glass_transparency" }}<span class="config-range-control"><input name="home_glass_transparency" type="range" min="0" max="85" step="1" value="{{ .HomeGlassTransparency }}" data-range-output="home-glass-transparency-output"><output id="home-glass-transparency-output">{{ .HomeGlassTransparency }}%</output></span></label>
|
||||
<p class="muted wide">{{ T "home.glass_help" }}</p>
|
||||
{{ template "home-palette-controls" . }}
|
||||
<p class="muted wide">{{ T "home.layout_help" }}</p>
|
||||
<a class="wide" href="/-/sys/config?panel=bookmarks" data-config-panel="bookmarks">{{ T "config.manage_bookmarks" }} →</a>
|
||||
<label class="config-toggle wide" data-label="{{ T "config.virtual_folder_pages" }}"><input name="virtual_folder_pages" value="1" type="checkbox" role="switch" aria-label="{{ T "config.virtual_folder_pages" }}" {{ if .VirtualFolderPages }}checked{{ end }}></label>
|
||||
|
||||
@@ -0,0 +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=4"></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=4" defer></script></body></html>{{ end }}
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
<link rel="stylesheet" href="/static/css/theme/base.css">
|
||||
<link rel="stylesheet" href="/static/css/content-viewer.css">
|
||||
<link rel="stylesheet" href="/static/css/home.css?v=12">
|
||||
<link rel="stylesheet" href="/static/css/home.css?v=13">
|
||||
<link rel="stylesheet" href="{{ .ThemeCSS }}">
|
||||
<script defer src="/static/js/content-viewer.js"></script>
|
||||
<script defer src="/static/js/home-type-search.js?v=1"></script>
|
||||
@@ -83,6 +83,6 @@
|
||||
<button type="button" data-children-delete>{{ T "children.delete_selected" }}</button>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
{{ template "home-appearance" . }}{{ template "home-palette" . }}</body>
|
||||
</html>
|
||||
{{ end }}
|
||||
@@ -1,7 +1,7 @@
|
||||
{{ define "organizer_dashboard.gohtml" }}<!doctype html>
|
||||
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ T "organizer.dashboard" }} · {{ .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/task-productivity.css?v=2"><link rel="stylesheet" href="/static/css/organizer.css?v=1"></head>
|
||||
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ T "organizer.dashboard" }} · {{ .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/task-productivity.css?v=3"><link rel="stylesheet" href="/static/css/organizer.css?v=1"></head>
|
||||
<body class="mode-view organizer-page"><header class="topbar"><div class="brand"><a href="/">{{ .WikiName }}</a></div>{{ template "auth-menu" . }}</header>
|
||||
{{ template "organizer-nav" . }}
|
||||
<main id="organizer-dashboard" data-writable="{{ .TaskWritable }}" data-calendar="{{ .CalendarEnabled }}" data-today="{{ .Today }}" data-timezone="{{ .Timezone }}">
|
||||
<header class="dashboard-toolbar"><div><h1>{{ T "organizer.dashboard" }}</h1><small>{{ .Today }} · {{ .Timezone }}</small></div><div id="dashboard-controls"></div></header><p id="dashboard-status" role="status" aria-live="polite"></p><div id="dashboard-grid"></div>
|
||||
</main><script src="/static/js/organizer-dashboard.js?v=1" defer></script><script src="/static/js/task-productivity.js?v=4" defer></script></body></html>{{ end }}
|
||||
</main><script src="/static/js/organizer-dashboard.js?v=1" defer></script><script src="/static/js/task-productivity.js?v=6" defer></script></body></html>{{ end }}
|
||||
@@ -1,8 +1,9 @@
|
||||
{{ define "organizer_settings.gohtml" }}<!doctype html>
|
||||
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ T "organizer.settings" }} · {{ .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/config.css"><link rel="stylesheet" href="/static/css/task-productivity.css?v=2"><link rel="stylesheet" href="/static/css/organizer.css?v=1"></head>
|
||||
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ T "organizer.settings" }} · {{ .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/config.css"><link rel="stylesheet" href="/static/css/task-productivity.css?v=3"><link rel="stylesheet" href="/static/css/organizer.css?v=1"></head>
|
||||
<body class="mode-config organizer-page"><header class="topbar"><div class="brand"><a href="/">{{ .WikiName }}</a></div>{{ template "auth-menu" . }}</header>{{ template "organizer-nav" . }}
|
||||
<main class="config-main"><div class="config-layout"><aside class="config-sidebar"><nav class="sidebar-nav"><a href="/-/sys/config?panel=organizer" aria-current="page">{{ T "organizer.settings" }}</a>{{ if .TasksEnabled }}<a href="#task-productivity">{{ T "tasks.title" }}</a>{{ end }}{{ if .CalendarEnabled }}<a href="#organizer-calendar-defaults">{{ T "organizer.calendar_defaults" }}</a>{{ end }}{{ if .ContactsEnabled }}<a href="/v/plan/contacts">{{ T "organizer.contacts" }} ↗</a>{{ end }}{{ if .AuthIsAdmin }}<a href="/-/sys/config">{{ T "config.title" }} ↗</a>{{ end }}</nav></aside>
|
||||
<section class="organizer-settings-content"><h1>{{ T "organizer.settings" }}</h1><p>{{ T "organizer.private" }}</p>
|
||||
{{ if .TasksEnabled }}<section id="task-productivity" data-view="settings" data-writable="{{ .TaskWritable }}"><h2></h2><p id="productivity-status" role="status" aria-live="polite"></p><div id="productivity-content"></div></section>{{ end }}
|
||||
{{ if .FeedsEnabled }}<section><h2>{{ T "feeds.title" }}</h2><p>{{ T "feeds.help" }}</p><a href="/v/feeds?settings=1">⚙ {{ T "feeds.title" }}</a></section>{{ end }}
|
||||
{{ if .TasksEnabled }}<section id="task-productivity" data-view="settings" data-writable="{{ .TaskWritable }}"><h2></h2><p id="productivity-status" role="status" aria-live="polite"></p><div id="productivity-content"></div></section><section id="task-digest-history" data-writable="{{ .TaskWritable }}"></section>{{ end }}
|
||||
{{ if .CalendarEnabled }}<section id="organizer-calendar-defaults" data-writable="{{ .TaskWritable }}"><h2>{{ T "organizer.calendar_defaults" }}</h2><p role="status"></p><div data-calendar-defaults></div></section>{{ end }}
|
||||
</section></div></main><script src="/static/js/task-productivity.js?v=4" defer></script><script src="/static/js/organizer-settings.js?v=1" defer></script></body></html>{{ end }}
|
||||
</section></div></main><script src="/static/js/task-productivity.js?v=6" defer></script><script src="/static/js/task-digest-history.js?v=1" defer></script><script src="/static/js/organizer-settings.js?v=1" defer></script></body></html>{{ end }}
|
||||
@@ -13,7 +13,7 @@
|
||||
<link rel="stylesheet" href="/static/css/content-viewer.css">
|
||||
<link rel="stylesheet" href="/static/css/city-graph.css">
|
||||
<link rel="stylesheet" href="{{ .ThemeCSS }}">
|
||||
{{ if .IsHome }}<link rel="stylesheet" href="/static/css/home.css?v=12">{{ end }}
|
||||
{{ if .IsHome }}<link rel="stylesheet" href="/static/css/home.css?v=13">{{ end }}
|
||||
<script defer src="/static/js/content-viewer.js"></script>
|
||||
<script defer src="/static/js/viewer-shortcuts.js"></script>
|
||||
{{ if eq .ContentView.Kind "code" }}
|
||||
@@ -990,6 +990,6 @@ window.addEventListener("DOMContentLoaded", () => {
|
||||
</script>
|
||||
{{ end }}
|
||||
|
||||
</body>
|
||||
{{ template "home-appearance" . }}{{ template "home-palette" . }}</body>
|
||||
</html>
|
||||
{{ end }}
|
||||
@@ -1,9 +1,9 @@
|
||||
{{ define "periodical.gohtml" }}<!doctype html><html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ .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/home.css?v=12"><link rel="stylesheet" href="/static/css/periodicals.css?v=6"></head>
|
||||
<body class="{{ .Theme }} periodical-top">{{ if .HomeWallpaperURL }}<img class="home-wallpaper" src="{{ .HomeWallpaperURL }}" alt="" aria-hidden="true" decoding="async" fetchpriority="high" style="opacity:{{ .HomeWallpaperOpacity }}">{{ end }}<main class="periodical-shell" data-periodical-kind="{{ .Kind }}"><header class="topbar"><a href="/">{{ .WikiName }}</a>{{ if not .Public }}<nav><a href="/v/diary">{{ T "periodical.diary" }}</a><a href="/v/blog">{{ T "periodical.blog" }}</a></nav>{{ template "auth-menu" . }}{{ end }}</header><div class="periodical-heading"><h1>{{ .Title }}</h1><nav>{{ if .CanConfigure }}<a href="/-/sys/config?panel={{ .Kind }}" title="{{ T "extension.settings" }}">⚙</a>{{ end }}{{ if and .Projection (not .Public) }}<a href="{{ .SourceViewer }}">{{ T "periodical.source_viewer" }}</a>{{ else if and .Enabled (not .Public) }}<button type="button" data-periodical-compose aria-haspopup="dialog">+ {{ T "periodical.compose" }}</button><a href="/v/{{ .Kind }}/-/new" aria-label="{{ T "periodical.new_page" }}" title="{{ T "periodical.new_page" }}">↗</a><button type="button" data-periodical-new aria-haspopup="dialog">{{ T "periodical.plan" }}</button><button type="button" data-periodical-add aria-haspopup="dialog">+ {{ T "periodical.register" }}</button>{{ end }}</nav></div>{{ if not .Public }}<p class="muted">{{ T "periodical.scope_help" }}</p>{{ end }}
|
||||
{{ define "periodical.gohtml" }}<!doctype html><html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ .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/home.css?v=13"><link rel="stylesheet" href="/static/css/periodicals.css?v=6"></head>
|
||||
<body class="{{ .Theme }} periodical-top"{{ if .IsHome }} style="--home-glass-opacity:{{ .HomeGlassOpacity }}%"{{ end }}>{{ if .HomeWallpaperURL }}<img class="home-wallpaper" src="{{ .HomeWallpaperURL }}" alt="" aria-hidden="true" decoding="async" fetchpriority="high" style="opacity:{{ .HomeWallpaperOpacity }}">{{ end }}<main class="periodical-shell" data-periodical-kind="{{ .Kind }}"><header class="topbar"><a href="/">{{ .WikiName }}</a>{{ if not .Public }}<nav><a href="/v/diary">{{ T "periodical.diary" }}</a><a href="/v/blog">{{ T "periodical.blog" }}</a></nav>{{ template "auth-menu" . }}{{ end }}</header><div class="periodical-heading"><h1>{{ .Title }}</h1><nav>{{ if .CanConfigure }}<a href="/-/sys/config?panel={{ .Kind }}" title="{{ T "extension.settings" }}">⚙</a>{{ end }}{{ if and .Projection (not .Public) }}<a href="{{ .SourceViewer }}">{{ T "periodical.source_viewer" }}</a>{{ else if and .Enabled (not .Public) }}<button type="button" data-periodical-compose aria-haspopup="dialog">+ {{ T "periodical.compose" }}</button><a href="/v/{{ .Kind }}/-/new" aria-label="{{ T "periodical.new_page" }}" title="{{ T "periodical.new_page" }}">↗</a><button type="button" data-periodical-new aria-haspopup="dialog">{{ T "periodical.plan" }}</button><button type="button" data-periodical-add aria-haspopup="dialog">+ {{ T "periodical.register" }}</button>{{ end }}</nav></div>{{ if not .Public }}<p class="muted">{{ T "periodical.scope_help" }}</p>{{ end }}
|
||||
{{ if not .Enabled }}<p role="status">{{ T "periodical.disabled" }}</p>{{ else }}
|
||||
|
||||
<div class="periodical-layout"><section class="periodical-entries" aria-label="{{ .Title }}"><table class="periodical-index"><thead><tr><th scope="col">{{ T "periodical.date" }}</th><th scope="col">{{ T "periodical.title" }}</th><th scope="col" class="periodical-index-actions">{{ T "config.actions" }}</th></tr></thead><tbody>{{ range .Entries }}<tr data-periodical-entry data-page="{{ .PageUUID }}" data-path="{{ .Path }}" data-title="{{ .Title }}" data-date="{{ .Date }}" data-category="{{ .Category }}" data-version="{{ .Version }}"><td class="periodical-index-date"><time datetime="{{ .Date }}">{{ .Date }}</time></td><td class="periodical-index-title"><h2><a href="{{ .Href }}" title="{{ .Title }}">{{ .Title }}</a></h2></td><td class="periodical-index-actions">{{ if .CanEdit }}<nav><a href="{{ .EditHref }}" title="{{ T "periodical.edit_body" }}" aria-label="{{ T "periodical.edit_body" }}">✎</a><button type="button" data-periodical-edit aria-label="{{ T "periodical.edit_metadata" }}" title="{{ T "periodical.edit_metadata" }}">⚙</button><button type="button" data-periodical-remove data-confirm="{{ T "periodical.remove_confirm" }}" title="{{ T "periodical.remove" }}" aria-label="{{ T "periodical.remove" }}">×</button></nav>{{ end }}</td></tr>{{ else }}<tr><td colspan="3">{{ T "periodical.empty" }}</td></tr>{{ end }}</tbody></table><nav class="periodical-pagination">{{ if .Previous }}<a href="{{ .Previous }}">← {{ T "periodical.previous" }}</a>{{ end }}{{ if .Next }}<a href="{{ .Next }}">{{ T "periodical.next" }} →</a>{{ end }}</nav></section>
|
||||
<aside><div class="periodical-calendar-panel"><form method="get" action="{{ .FilterAction }}" class="periodical-filters" data-periodical-filters><div class="periodical-month-controls">{{ template "periodical-month-controls" . }}<a class="periodical-filter-icon" href="{{ .BasePath }}" title="{{ T "periodical.clear" }}" aria-label="{{ T "periodical.clear" }}">{{ template "periodical-reset-icon" . }}</a></div>{{ if not .Public }}<label>{{ T "periodical.category" }} <select name="category"><option value="">{{ T "periodical.all" }}</option>{{ range .Categories }}<option {{ if eq . $.Category }}selected{{ end }}>{{ . }}</option>{{ end }}</select></label><label><input type="checkbox" name="own" value="" {{ if .Mine }}checked{{ end }}> {{ T "periodical.mine" }}</label>{{ end }}</form><section class="periodical-calendar"><header><a href="{{ .PreviousMonth }}" aria-label="{{ T "periodical.previous_month" }}">‹</a><strong>{{ .Month }}</strong><a href="{{ .NextMonth }}" aria-label="{{ T "periodical.next_month" }}">›</a></header><div class="periodical-weekdays" aria-hidden="true">{{ if eq .Locale "ja" }}<span>日</span><span>月</span><span>火</span><span>水</span><span>木</span><span>金</span><span>土</span>{{ else }}<span>Su</span><span>Mo</span><span>Tu</span><span>We</span><span>Th</span><span>Fr</span><span>Sa</span>{{ end }}</div><div class="periodical-days">{{ range .Days }}{{ if .Number }}<a href="{{ .Href }}" class="{{ if .Count }}has-entries{{ end }}" {{ if .Selected }}aria-current="date"{{ end }}>{{ .Number }}{{ if .Count }}<small aria-label="{{ T "periodical.entries" }}">{{ .Count }}</small>{{ end }}</a>{{ else }}<span></span>{{ end }}{{ end }}</div></section></div><section class="periodical-recent"><h2>{{ T "periodical.recent" }}</h2>{{ range .Recent }}<a href="{{ .Href }}"><time>{{ .Date }}</time> {{ .Title }}</a>{{ else }}<p>{{ T "periodical.empty" }}</p>{{ end }}</section></aside></div>
|
||||
{{ if not .Public }}<dialog data-periodical-composer><form><header><h2>{{ T "periodical.compose" }}</h2><button type="button" data-composer-close aria-label="{{ T "city.close" }}">×</button></header><fieldset><label>{{ T "periodical.title" }}<input name="title" required maxlength="240"></label><label>{{ T "periodical.date" }}<input type="date" name="date" required value="{{ .Today }}"></label><label>{{ T "periodical.keyword" }}<input name="keyword" maxlength="240"></label><p>{{ T "periodical.prefix" }}: <code>{{ .Prefix }}</code></p><label>{{ T "periodical.category" }}<input name="category" maxlength="80"></label><label>{{ T "periodical.body" }}<textarea name="body" rows="12" required maxlength="131072"></textarea></label><p>{{ T "periodical.compose_help" }}</p><button type="submit">{{ T "periodical.save_article" }}</button></fieldset><p role="status" data-composer-status></p></form></dialog>
|
||||
<dialog data-periodical-planner><form><header><h2>{{ T "periodical.plan" }}</h2><button type="button" data-planner-close aria-label="{{ T "city.close" }}">×</button></header><p>{{ T "periodical.prefix" }}: <code>{{ .Prefix }}</code></p><label>{{ T "periodical.date" }}<input type="date" name="date" required value="{{ .Today }}"></label><label>{{ T "periodical.keyword" }}<input name="keyword" maxlength="240"></label><button type="submit">{{ T "periodical.plan" }}</button><p data-planner-status role="status"></p><div data-planner-result hidden><p><a data-planner-editor target="_blank" rel="noopener">{{ T "periodical.open_editor" }}</a></p><p>{{ T "periodical.registration_help" }}</p><button type="button" data-planner-register>{{ T "periodical.register" }}</button></div></form></dialog>
|
||||
<dialog data-periodical-dialog><form data-periodical-entry-form><header><h2>{{ T "periodical.register" }}</h2><button type="button" data-periodical-close aria-label="{{ T "city.close" }}">×</button></header><input type="hidden" name="page_uuid"><input type="hidden" name="version" value="0"><label>Path<input name="path" required placeholder="/diary/2026/09/16" maxlength="4096"></label><label>{{ T "periodical.title" }}<input name="title" required maxlength="240"></label><label>{{ T "periodical.date" }}<input type="date" name="date" required value="{{ .Today }}"></label><label>{{ T "periodical.category" }}<input name="category" maxlength="80"></label><p>{{ T "periodical.registration_help" }}</p><button type="submit">{{ T "config.save" }}</button><p data-periodical-status role="status"></p></form></dialog>{{ end }}{{ end }}</main><script src="/static/js/periodicals.js?v=8" defer></script></body></html>{{ end }}
|
||||
<dialog data-periodical-dialog><form data-periodical-entry-form><header><h2>{{ T "periodical.register" }}</h2><button type="button" data-periodical-close aria-label="{{ T "city.close" }}">×</button></header><input type="hidden" name="page_uuid"><input type="hidden" name="version" value="0"><label>Path<input name="path" required placeholder="/diary/2026/09/16" maxlength="4096"></label><label>{{ T "periodical.title" }}<input name="title" required maxlength="240"></label><label>{{ T "periodical.date" }}<input type="date" name="date" required value="{{ .Today }}"></label><label>{{ T "periodical.category" }}<input name="category" maxlength="80"></label><p>{{ T "periodical.registration_help" }}</p><button type="submit">{{ T "config.save" }}</button><p data-periodical-status role="status"></p></form></dialog>{{ end }}{{ end }}</main><script src="/static/js/periodicals.js?v=8" defer></script>{{ template "home-appearance" . }}{{ template "home-palette" . }}</body></html>{{ end }}
|
||||
@@ -8,7 +8,7 @@
|
||||
{{ template "social-metadata" . }}
|
||||
<link rel="stylesheet" href="/static/css/theme/base.css">
|
||||
<link rel="stylesheet" href="{{ .ThemeCSS }}">
|
||||
<link rel="stylesheet" href="/static/css/home.css?v=12">
|
||||
<link rel="stylesheet" href="/static/css/home.css?v=13">
|
||||
</head>
|
||||
<body class="home-landing home-layout-{{ .HomeLayout }}{{ if eq .HomeLayout "directory" }} home-paged{{ end }}" style="--home-glass-opacity:{{ .HomeGlassOpacity }}%">
|
||||
{{ if .HomeWallpaperURL }}<img class="home-wallpaper" src="{{ .HomeWallpaperURL }}" alt="" aria-hidden="true" decoding="async" fetchpriority="high" style="opacity:{{ .HomeWallpaperOpacity }}">{{ end }}
|
||||
@@ -47,19 +47,8 @@
|
||||
{{ template "home-bookmarks" . }}
|
||||
{{ end }}
|
||||
</main>
|
||||
{{ if .CanConfigureHome }}
|
||||
<button type="button" class="home-appearance-launch" data-home-appearance-open aria-label="{{ T "home.appearance" }}" title="{{ T "home.appearance" }}"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="m9 3-.5 3-2 .9L4 6l-2 4 2.5 1.8v2.4L2 16l2 4 2.5-.9 2 .9.5 3h6l.5-3 2-.9L20 20l2-4-2.5-1.8v-2.4L22 10l-2-4-2.5.9-2-.9-.5-3z"/><circle cx="12" cy="13" r="3"/></svg></button>
|
||||
<dialog class="home-appearance-dialog" data-home-appearance-dialog aria-labelledby="home-appearance-title">
|
||||
<form method="post" action="/-/sys/config" data-home-appearance-form data-saved="{{ T "config.saved" }}">
|
||||
<input type="hidden" name="section" value="home-appearance">
|
||||
<header><h2 id="home-appearance-title">{{ T "home.appearance" }}</h2><button type="button" data-home-appearance-close aria-label="{{ T "picker.cancel" }}">×</button></header>
|
||||
<label>{{ T "home.glass_transparency" }}<span class="home-appearance-range"><input name="home_glass_transparency" type="range" min="0" max="85" step="1" value="{{ .HomeGlassTransparency }}"><output>{{ .HomeGlassTransparency }}%</output></span></label>
|
||||
<p class="muted">{{ T "home.glass_help" }}</p>
|
||||
<footer><span data-home-appearance-status role="status"></span><button type="button" data-home-appearance-cancel>{{ T "picker.cancel" }}</button><button type="submit">{{ T "config.save" }}</button></footer>
|
||||
</form>
|
||||
</dialog>
|
||||
<script defer src="/static/js/home-appearance.js?v=1"></script>
|
||||
{{ end }}
|
||||
{{ template "home-appearance" . }}
|
||||
{{ template "home-palette" . }}
|
||||
{{ if eq .HomeLayout "directory" }}
|
||||
<nav class="home-page-indicator" data-home-page-indicator aria-label="{{ T "home.bookmarks" }}">
|
||||
<button type="button" data-home-page-target="search" aria-current="page" aria-label="{{ T "home.search" }}"></button>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{{ define "task_work_history.gohtml" }}<!doctype html>
|
||||
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ T "task.work_history" }} · {{ .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/organizer.css?v=1"><link rel="stylesheet" href="/static/css/task-work-history.css?v=1"></head>
|
||||
<body class="mode-view organizer-page"><header class="topbar"><div class="brand"><a href="/">{{ .WikiName }}</a></div>{{ template "auth-menu" . }}</header>{{ template "organizer-nav" . }}
|
||||
<main id="task-work-history" data-writable="{{ .TaskWritable }}" data-timezone="{{ .Timezone }}"><header><h1>{{ T "task.work_history" }}</h1><a href="/v/plan/dashboard#activity">{{ T "organizer.dashboard" }}</a></header><p id="work-history-status" role="status" aria-live="polite"></p><div id="work-history-controls"></div><div id="work-history-list"></div><div id="work-history-paging"></div></main>
|
||||
<script src="/static/js/task-work-history.js?v=1" defer></script></body></html>{{ end }}
|
||||
@@ -11,4 +11,4 @@
|
||||
<p id="tasks-status" role="status" aria-live="polite"></p><div class="tasks-list-scroll"><div id="tasks-list" role="list"></div></div><button type="button" id="tasks-more" hidden></button>
|
||||
</section>
|
||||
<dialog id="tasks-dialog" aria-labelledby="tasks-dialog-title"><form id="tasks-form"><header class="tasks-toolbar"><h2 id="tasks-dialog-title"></h2><button type="button" id="tasks-close">×</button></header><div id="tasks-fields"></div><p id="tasks-error" role="alert"></p><details id="tasks-history"><summary></summary><ol></ol></details><footer class="tasks-actions"><button type="button" id="tasks-archive"></button><a id="tasks-project-open" hidden></a><button type="submit" id="tasks-save"></button></footer></form></dialog>
|
||||
</main><link rel="stylesheet" href="/static/css/dav-settings.css?v=3"><script src="/static/js/task-inline.js?v=4" defer></script><script src="/static/js/task-today.js?v=1" defer></script><script src="/static/js/task-planning.js?v=3" defer></script><script src="/static/js/task-focus.js?v=2" defer></script><script src="/static/js/task-work.js?v=1" defer></script><script src="/static/js/tasks.js?v=9" defer></script><script src="/static/js/task-dav-settings.js?v=4" defer></script></body></html>{{ end }}
|
||||
</main><link rel="stylesheet" href="/static/css/dav-settings.css?v=3"><script src="/static/js/task-inline.js?v=4" defer></script><script src="/static/js/task-today.js?v=1" defer></script><script src="/static/js/task-planning.js?v=3" defer></script><script src="/static/js/task-focus.js?v=2" defer></script><script src="/static/js/task-work.js?v=1" defer></script><script src="/static/js/tasks.js?v=10" defer></script><script src="/static/js/task-dav-settings.js?v=4" defer></script></body></html>{{ end }}
|
||||
@@ -0,0 +1,33 @@
|
||||
{{ define "home-palette-controls" }}
|
||||
<div class="home-palette-controls wide">
|
||||
<label>{{ T "home.palette_mode" }}<select name="home_palette_mode"><option value="off" {{ if eq .HomePalette.Mode "off" }}selected{{ end }}>{{ T "home.palette_off" }}</option><option value="accent" {{ if eq .HomePalette.Mode "accent" }}selected{{ end }}>{{ T "home.palette_accent" }}</option><option value="surface" {{ if eq .HomePalette.Mode "surface" }}selected{{ end }}>{{ T "home.palette_surface" }}</option></select></label>
|
||||
<label>{{ T "home.palette_strength" }}<span class="home-appearance-range"><input name="home_palette_strength" data-range-output="home-palette-strength-output" type="range" min="0" max="100" step="5" value="{{ .HomePalette.Strength }}"><output id="home-palette-strength-output" data-palette-strength>{{ .HomePalette.Strength }}%</output></span></label>
|
||||
<label>{{ T "home.palette_brightness" }}<select name="home_palette_brightness"><option value="preserve" {{ if eq .HomePalette.Brightness "preserve" }}selected{{ end }}>{{ T "home.palette_preserve" }}</option><option value="auto" {{ if eq .HomePalette.Brightness "auto" }}selected{{ end }}>{{ T "home.palette_auto" }}</option></select></label>
|
||||
<p class="muted">{{ T "home.palette_help" }}</p>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ define "home-appearance" }}
|
||||
{{ if .IsHome }}
|
||||
{{ if .CanConfigureHome }}
|
||||
<button type="button" class="home-appearance-launch" data-home-appearance-open aria-label="{{ T "home.appearance" }}" title="{{ T "home.appearance" }}"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="m9 3-.5 3-2 .9L4 6l-2 4 2.5 1.8v2.4L2 16l2 4 2.5-.9 2 .9.5 3h6l.5-3 2-.9L20 20l2-4-2.5-1.8v-2.4L22 10l-2-4-2.5.9-2-.9-.5-3z"/><circle cx="12" cy="13" r="3"/></svg></button>
|
||||
<dialog class="home-appearance-dialog" data-home-appearance-dialog aria-labelledby="home-appearance-title">
|
||||
<form method="post" action="/-/sys/config" data-home-appearance-form data-saved="{{ T "config.saved" }}">
|
||||
<input type="hidden" name="section" value="home-appearance">
|
||||
<header><h2 id="home-appearance-title">{{ T "home.appearance" }}</h2><button type="button" data-home-appearance-close aria-label="{{ T "picker.cancel" }}">×</button></header>
|
||||
<label>{{ T "home.glass_transparency" }}<span class="home-appearance-range"><input name="home_glass_transparency" type="range" min="0" max="85" step="1" value="{{ .HomeGlassTransparency }}"><output>{{ .HomeGlassTransparency }}%</output></span></label>
|
||||
<p class="muted">{{ T "home.glass_help" }}</p>
|
||||
{{ template "home-palette-controls" . }}
|
||||
<footer><span data-home-appearance-status role="status"></span><button type="button" data-home-appearance-cancel>{{ T "picker.cancel" }}</button><button type="submit">{{ T "config.save" }}</button></footer>
|
||||
</form>
|
||||
</dialog>
|
||||
<script defer src="/static/js/home-appearance.js?v=2"></script>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ define "home-palette" }}
|
||||
{{ if and .IsHome .HomeWallpaperURL }}
|
||||
<div hidden data-home-palette data-mode="{{ .HomePalette.Mode }}" data-strength="{{ .HomePalette.Strength }}" data-brightness="{{ .HomePalette.Brightness }}" data-key="{{ .HomeWallpaperKey }}" data-domain="{{ .HomePaletteDomain }}"></div>
|
||||
<script defer src="/static/js/home-palette-core.js?v=1"></script>
|
||||
<script defer src="/static/js/home-palette.js?v=1"></script>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
@@ -1,12 +1,14 @@
|
||||
{{ 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 .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 }}
|
||||
{{ if .TasksEnabled }}<a href="/v/plan/dashboard" class="organizer-launch" data-home-shortcut="dashboard" title="{{ T "organizer.dashboard" }}" aria-label="{{ T "organizer.dashboard" }}"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 3h7v7H3zM14 3h7v11h-7zM3 14h7v7H3zM14 18h7v3h-7z"/></svg></a>{{ end }}
|
||||
{{ if .ContactsEnabled }}<a href="/v/plan/contacts" class="organizer-launch" data-home-shortcut="contacts" title="{{ T "organizer.contacts" }}" aria-label="{{ T "organizer.contacts" }}"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="4" y="3" width="15" height="18" rx="2"/><circle cx="12" cy="9" r="3"/><path d="M8 17c0-5 8-5 8 0M2 7h4M2 12h4M2 17h4"/></svg></a>{{ end }}
|
||||
{{ end }}
|
||||
Reference in new issue
Block a user