7 Commits
Author SHA1 Message Date
Anya Tokugawa bd80ff6a0c docs: record v0.15.0 production deployment [skip ci] 2026-11-08 20:42:17 +09:00
Anya Tokugawa b90aef79d0 feat: add browser upload queue and trusted sessions with bounded projections
Build and publish container images / images (push) Successful in 11m37s
Release container images / release (push) Successful in 22s
2026-11-08 20:27:04 +09:00
Anya Tokugawa 84d52390f9 docs: record v0.14.1 production deployment [skip ci] 2026-11-08 19:43:43 +09:00
Anya Tokugawa 4049acf76e fix(tasks): recover deleted captures without reviving tombstones
Build and publish container images / images (push) Successful in 12m0s
Release container images / release (push) Successful in 19s
2026-11-08 19:26:50 +09:00
Anya Tokugawa 43a2d8c5a1 docs: record v0.14.0 production deployment [skip ci] 2026-11-08 18:21:06 +09:00
Anya Tokugawa 38a4fcf530 feat(tasks): add explicit deletion with DAV tombstones
Build and publish container images / images (push) Successful in 11m42s
Release container images / release (push) Successful in 27s
2026-11-08 18:04:54 +09:00
Anya Tokugawa dc978231e2 docs: record v0.13.0 production deployment [skip ci] 2026-11-08 16:32:53 +09:00
100 changed files with 3300 additions and 231 deletions

No files matched your search

+14 -2
View File
@@ -91,13 +91,25 @@ jobs:
org.opencontainers.image.revision=${{ github.sha }} org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
- name: Build Gecko relay
uses: https://github.com/docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: Dockerfile.gecko-relay
platforms: linux/amd64
load: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/pageswiki-gecko-relay:${{ env.IMAGE_TAG }}
labels: |
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
# Publish only after all builds succeed. Use the host daemon for registry # Publish only after all builds succeed. Use the host daemon for registry
# access; BuildKit does not inherit the runner's /etc/hosts entries. # access; BuildKit does not inherit the runner's /etc/hosts entries.
- name: Push images - name: Push images
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer; do for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer pageswiki-gecko-relay; do
docker push "$REGISTRY/$IMAGE_OWNER/$image:$IMAGE_TAG" docker push "$REGISTRY/$IMAGE_OWNER/$image:$IMAGE_TAG"
done done
@@ -105,7 +117,7 @@ jobs:
if: always() if: always()
shell: bash shell: bash
run: | run: |
for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer; do for image in pageswiki-app pageswiki-adaptor-gateway pageswiki-excalidraw-viewer pageswiki-gecko-relay; do
ref="$REGISTRY/$IMAGE_OWNER/$image:$IMAGE_TAG" ref="$REGISTRY/$IMAGE_OWNER/$image:$IMAGE_TAG"
if docker image inspect "$ref" >/dev/null 2>&1; then if docker image inspect "$ref" >/dev/null 2>&1; then
docker image rm "$ref" || echo "Could not remove local CI tag: $ref" >&2 docker image rm "$ref" || echo "Could not remove local CI tag: $ref" >&2
+5
View File
@@ -66,10 +66,15 @@ func main() {
if err := geckorelay.VerifyAssets(assets); err != nil { if err := geckorelay.VerifyAssets(assets); err != nil {
log.Fatal(err) log.Fatal(err)
} }
distribution, err := geckorelay.VerifyDistribution(assets)
if err != nil {
log.Fatal(err)
}
relay, err := geckorelay.New(secret, assets) relay, err := geckorelay.New(secret, assets)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
relay.Distribution = distribution
s := &http.Server{Addr: addr, Handler: relay, ReadHeaderTimeout: 5 * time.Second, IdleTimeout: 30 * time.Second, MaxHeaderBytes: 16 << 10} s := &http.Server{Addr: addr, Handler: relay, ReadHeaderTimeout: 5 * time.Second, IdleTimeout: 30 * time.Second, MaxHeaderBytes: 16 << 10}
log.Printf("Gecko relay listening; authenticated TCP 80/443 only") log.Printf("Gecko relay listening; authenticated TCP 80/443 only")
log.Fatal(s.ListenAndServe()) log.Fatal(s.ListenAndServe())
+2 -2
View File
@@ -14,12 +14,12 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile.gecko-relay dockerfile: Dockerfile.gecko-relay
image: pageswiki-gecko-relay:dev image: ${PAGESWIKI_GECKO_IMAGE:-pageswiki-gecko-relay:dev}
environment: environment:
PAGESWIKI_GECKO_KEY_FILE: /run/secrets/gecko-key PAGESWIKI_GECKO_KEY_FILE: /run/secrets/gecko-key
volumes: volumes:
- ${PAGESWIKI_GECKO_KEY_PATH:?Set absolute relay key path}:/run/secrets/gecko-key:ro - ${PAGESWIKI_GECKO_KEY_PATH:?Set absolute relay key path}:/run/secrets/gecko-key:ro
- ${PAGESWIKI_GECKO_ASSETS_DIR:?Set verified Gecko dist directory}:/gecko:ro - ${PAGESWIKI_GECKO_ASSETS_DIR:?Set verified complete Gecko bundle directory}:/gecko:ro
networks: networks:
gecko-front: {} gecko-front: {}
gecko-egress: {} gecko-egress: {}
+2
View File
@@ -48,6 +48,8 @@ IPアドレス管理(IPAM)、DNSゾーン/レコード管理、機器・
## CSV/表・スライド拡張(設計TODO) ## CSV/表・スライド拡張(設計TODO)
初期CSV macroは実装済みです。`{{csv:/data/items.csv range=A1:H200 header=true}}` を認証済みProjectionで展開し、`rev=` で同じObjectのRevisionへ固定できます。現在のPath閲覧権限を毎回検査し、外部URL、匿名公開、asset指定、共有キャッシュ、CSV編集はこの段階に含めません。入力256 KiB・UTF-8、表示200行×32列、走査2,000行・100列、セル16 KiB、Projection当たり4種類のCSVまでに制限します。引用符・改行・BOMに対応し、セルはHTML escapeしてmacroや数式を実行しません。処理不能時は内容を漏らさない警告に置き換えます。Authoringでは元のmacroを保持します。
CSVをPage本文へ複製せず、認可済みの別Documentをテーブルとして投影するmacroを用意します。候補構文は `{{csv:/data/items.csv range=A1:H200 header=true}}` とし、Path、Revision(またはasset hash)、列・行上限、表示モードを正規化してキャッシュキーに含めます。macroは表示時にboundedなProjectionを作るだけで、結果HTMLを正本へ逆流させません。CSV Editorは元Revisionを編集し、表投影とは別の操作・競合・権限として扱います。 CSVをPage本文へ複製せず、認可済みの別Documentをテーブルとして投影するmacroを用意します。候補構文は `{{csv:/data/items.csv range=A1:H200 header=true}}` とし、Path、Revision(またはasset hash)、列・行上限、表示モードを正規化してキャッシュキーに含めます。macroは表示時にboundedなProjectionを作るだけで、結果HTMLを正本へ逆流させません。CSV Editorは元Revisionを編集し、表投影とは別の操作・競合・権限として扱います。
交換形式はRFC 4180互換CSV(UTF-8、CRLF、引用符・改行を含むfield、BOMの扱いを明示)を第一正本とします。複数シート、型、数式、結合セル、書式が必要な場合はODSを別アダプタ/Assetとして扱い、CSVへの不可逆変換を黙って行いません。行数、列数、セル長、総バイト、ネストmacroを制限し、malformed inputは安全なテキスト表示へfallbackします。 交換形式はRFC 4180互換CSV(UTF-8、CRLF、引用符・改行を含むfield、BOMの扱いを明示)を第一正本とします。複数シート、型、数式、結合セル、書式が必要な場合はODSを別アダプタ/Assetとして扱い、CSVへの不可逆変換を黙って行いません。行数、列数、セル長、総バイト、ネストmacroを制限し、malformed inputは安全なテキスト表示へfallbackします。
+4 -2
View File
@@ -396,11 +396,13 @@ Wiki単独は親Path配下の `rss-{request UUID}` に新規作成します。
- [x] RSS-7c:Shift+j/kによるフォルダ選択。空・未分類・端・購読選択中・検索維持・入力/モーダル抑止・連打を合成試験。 - [x] RSS-7c:Shift+j/kによるフォルダ選択。空・未分類・端・購読選択中・検索維持・入力/モーダル抑止・連打を合成試験。
- [x] RSS-8a:Gecko端末描画+自前Wisp中継の方式決定。公開中継を使わず、独立・既定無効で導入する。 - [x] RSS-8a:Gecko端末描画+自前Wisp中継の方式決定。公開中継を使わず、独立・既定無効で導入する。
- [x] RSS-8b1:upstream v0.0.1/hash固定、最小埋め込みと親documentのisolation、Chromiumで合成記事の描画・遷移確認。 - [x] RSS-8b1:upstream v0.0.1/hash固定、最小埋め込みと親documentのisolation、Chromiumで合成記事の描画・遷移確認。
- [ ] RSS-8b2:Safari/iPhone SE実機、IME・コピー・find・証明書エラー・HTTPS互換性、配布license/notice整備。 - [ ] RSS-8b2:Safari/iPhone SE実機、IME・コピー・実サイト互換性。固定配布物のlicense/notice整備、HTTPSと証明書エラー、日本語findの合成試験は実施済み。
- [x] RSS-8c1:認証付きWisp TCP profile、公開IP/port制限、失効・資源上限・管理者/CLI無効化・内部status。 - [x] RSS-8c1:認証付きWisp TCP profile、公開IP/port制限、失効・資源上限・管理者/CLI無効化・内部status。
- [ ] RSS-8c2:運用ホストの外向きfirewall、設定UIへの中継監視統合、負荷時の長時間受入。 - [ ] RSS-8c2:運用ホストの外向きfirewall、設定UIへの中継監視統合、負荷時の長時間受入。
- [x] RSS-8d1:個人設定の選択、1ページのpopup閲覧、戻る/進む/再読込/別タブ/終了。 - [x] RSS-8d1:個人設定の選択、1ページのpopup閲覧、戻る/進む/再読込/別タブ/終了。
- [ ] RSS-8d2:初回/再表示・低メモリ端末の性能評価、失敗/切断・複数タブのUX、本番配備。 - [ ] RSS-8d2:初回/再表示・低メモリ端末の性能評価、実行中の切断・複数タブのUX、本番配備。起動上限と起動失敗時のiframe破棄・原文リンクへの退避は実装済み。
一覧には配信日と配信時刻(HH:mm)を分けて表示します。Domainの設定タイムゾーンを使い、tooltipには年・秒・タイムゾーンを含めます。配信日時不明は「—」とし、取得日時で補いません。モバイルでも時刻欄を残します。
隔離試験はRSS/Atom・FreshRSS login/read、欠落ID・巨大/不正feed、条件付きGET、失敗時cache保持、 隔離試験はRSS/Atom・FreshRSS login/read、欠落ID・巨大/不正feed、条件付きGET、失敗時cache保持、
本人分離・失効・readonly、二重送信・版競合・旧worker拒否、migration再実行/失敗rollback、 本人分離・失効・readonly、二重送信・版競合・旧worker拒否、migration再実行/失敗rollback、
+2 -2
View File
@@ -103,7 +103,7 @@ P0は認可・整合性・復旧の安全条件、P1は日常利用の回復性
| SHARE-01 / P2 | 未実装:委譲share URL、期限/失効/監査、説明可能な権限総覧 | AUTH-01、PUB-01。login/adapter/federation資格情報と別目的、単一Page投影、caveat・依存物の失効を検証 | [公開](publication.md)、[Schutzaria](schutzaria.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) | | 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) | | 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) | | CSV-01 / P2 | viewerと有界CSV macroを実装。残件:CSV editor、匿名投影、asset指定、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) | | 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) | | RECIPE-01 / P2 | 未実装:構造化レシピmetadataとPage投影の初期slice | 材料・数量・未知単位を保持、人数変更は派生値、Asset認可、版競合、出典・公開確認 | [料理レシピ](recipe-management.md) |
@@ -111,7 +111,7 @@ P0は認可・整合性・復旧の安全条件、P1は日常利用の回復性
| ID / 優先 | 状態・次の作業 | 着手ゲート・最初の検証 | 詳細 | | ID / 優先 | 状態・次の作業 | 着手ゲート・最初の検証 | 詳細 |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| RSS-01 / P2 | 一部実装:内蔵簡易正本、FreshRSS読取connector、3ペインUI・HTML本文、Wiki保存・タスク化・dashboard、OPML確認付き入出力 | 残件はFreshRSS既読/star書戻し、購読/カテゴリnavigation、実接続受入、公平性/backoff。managed schema feeds v3・隔離fixture。本番未反映。二重正本・停止時の自動切替なし | [RSS](feeds.md) | | RSS-01 / P2 | 一部実装:内蔵簡易正本、FreshRSS読取・既読/star書戻し、購読/カテゴリnavigation、3ペインUI・HTML本文、Wiki保存・タスク化・dashboard、OPML、配信時刻 | 残件は実接続受入、公平性/backoff、Gecko実機・運用受入。個別の実装/受入状況はRSS設計を参照。二重正本・停止時の自動切替なし | [RSS](feeds.md) |
| IMAP-01 / P3 | 未実装・選定待ち:IMAP読取同期 | provider/認証/保持を決める。UIDVALIDITY/UID、添付量、外部画像、失効をfixture化。neomutt captureは実装済みで別 | [メール](mail.md) | | IMAP-01 / P3 | 未実装・選定待ち:IMAP読取同期 | provider/認証/保持を決める。UIDVALIDITY/UID、添付量、外部画像、失効をfixture化。neomutt captureは実装済みで別 | [メール](mail.md) |
| TICKET-01 / P3 | 未実装:queue/番号/workflow/外部依頼者 | 共有範囲と状態遷移を定義、同時採番・失効・監査。既存個人タスクをticketと呼び替えない | [タスクとticket](tasks-tickets.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) | | EXT-01 / P3 | built-inのみ:第三者manifest/署名/隔離runtime、停止・rollback・観測 | capability・secret・host・予算・export契約。任意コードをGoプロセス内へ直接ロードしない | [拡張](extensions.md) |
+8
View File
@@ -14,6 +14,14 @@ childrenは現在Pathを既定にし、表示形式は本文macroの `view` 引
`/v/tree/{path}` は範囲を限定します。展開・全展開・全折りたたみ状態の保持、複数選択、rename・移動・削除はPath操作と一致させます。一般の子一覧から予約ユーザー領域を混入させません。再帰操作は事前の全対象確認と競合検出が必要です。 `/v/tree/{path}` は範囲を限定します。展開・全展開・全折りたたみ状態の保持、複数選択、rename・移動・削除はPath操作と一致させます。一般の子一覧から予約ユーザー領域を混入させません。再帰操作は事前の全対象確認と競合検出が必要です。
## Browserのアップロード
`/v/browser/{path}` の一覧へファイルをドロップすると、現在のPath配下へアップロードします。フォルダ行へのドロップではそのフォルダが宛先になります。既存の内部Path移動・選択操作とは区別します。
右下のフローティングカードに待機・送信中・完了・失敗・取消と進捗を表示します。追加ドロップは同じキューへ積み、送信は1件ずつ、最大100件・各256 MiBまで。待機中の取消、折りたたみ、終了分のクリアに対応します。終了後は一覧だけを再取得し、キューは残します。
既存の認可付き `/v/upload` を使用し、`If-None-Match: *` で同名Pathの上書きを防ぎます。通信断は保存結果不明として扱い、自動再送しません。キューはページ内のみで、ページ離脱・再起動後の再開やフォルダの再帰アップロードには未対応です。新規オブジェクト・Path・初回Revisionの一体的なトランザクション化は残課題です。
## ホームとブックマーク ## ホームとブックマーク
通常トップバー型、中央検索型、検索+セクションカード型を選びます。セクションは手動URL/Path、または指定親の子リンクを表示します。設定は歯車のポップアップで、閲覧画面を編集フォームで埋めません。カード列はviewportに適応します。 通常トップバー型、中央検索型、検索+セクションカード型を選びます。セクションは手動URL/Path、または指定親の子リンクを表示します。設定は歯車のポップアップで、閲覧画面を編集フォームで埋めません。カード列はviewportに適応します。
+6
View File
@@ -23,6 +23,12 @@
### 3. テーマ・アカウント・連絡先 ### 3. テーマ・アカウント・連絡先
- [x] 信頼できる端末の長期ログイン(2026-11-08ローカル実装、本番未反映):ログイン画面の明示選択で最大30日。Domain管理者は設定→セッションで0〜30日(0で無効)を指定する。通常ログインは既存の絶対期限を維持。パスワード/TOTP、LDAP、OIDC、SMTPマジックリンクに適用し、選択は認証challengeに固定する。CookieとBearerの期限はDBの発行期限と一致し、ログアウト・管理者失効・アカウント停止で無効になる。既存セッションの延長、TOTPの省略、アクセスによる期限延長は行わない。
- [x] 独立CLIの `pages login --remember` / `pages login --oidc --no-browser --remember`。S256 grantに選択を保存し、ブラウザ側のクエリで上書きできない。APIセッションは承認元ブラウザの残存期限を超えない。期限切れ後はlogoutなしで再認証でき、同一アカウントのcwdと未送信タスク下書きを保持する。別アカウントへの下書き移動は拒否する。旧サーバーは選択を無視する場合があるため、実際の期限は応答のexpires_inを正とする。
- [x] タスク編集フッターの関連ページ導線(2026-11-08ローカル実装、本番未反映):アーカイブ・削除・保存と同じ並びに関連ページリンクを表示。新規タブで開き、編集中の内容を保持する。保存済みの関連Pageがない場合、解除した場合、Path変更が未保存の場合は非表示。デスクトップ/モバイル4幅のブラウザテストを追加。
長期ログインのDB変更はmanaged component `cli-auth` v2の `remember` 列追加のみ。既存行はfalse、既存セッションと文書・タスクデータは変更しない。端末名・一覧・個別端末の信頼登録、refresh token rotationは別設計とし、今回は既存セッション管理から失効する。
- [x] 共通ナビの◐からプリセットを選択、リロードせず切替。host限定Cookieに保持し、Domain既定に戻せる。登録済みテーマのみ許可。Domain設定/アカウントの全端末設定ではなくブラウザ上書き。失敗時は現在テーマを保持する。 - [x] 共通ナビの◐からプリセットを選択、リロードせず切替。host限定Cookieに保持し、Domain既定に戻せる。登録済みテーマのみ許可。Domain設定/アカウントの全端末設定ではなくブラウザ上書き。失敗時は現在テーマを保持する。
- [x] 絶対セッション期限:設定→セッション、5〜43200分、既定1440分。Domain単位で新規ブラウザ/APIログイン(OIDC/LDAPを含む)に適用。発行時にDBの期限を固定し、Cookie/APIのexpires_inにも反映。既存セッションの期限とCalDAVアプリパスワードは変更しない。管理者認可とサーバ側失効をfixture検証。 - [x] 絶対セッション期限:設定→セッション、5〜43200分、既定1440分。Domain単位で新規ブラウザ/APIログイン(OIDC/LDAPを含む)に適用。発行時にDBの期限を固定し、Cookie/APIのexpires_inにも反映。既存セッションの期限とCalDAVアプリパスワードは変更しない。管理者認可とサーバ側失効をfixture検証。
- [ ] 無操作タイムアウトとアカウント別の短縮上書き:background pollingを人間の操作とみなさないactivity契約、再認証、既存セッションへの即時適用を別途設計する。 - [ ] 無操作タイムアウトとアカウント別の短縮上書き:background pollingを人間の操作とみなさないactivity契約、再認証、既存セッションへの即時適用を別途設計する。
+8
View File
@@ -26,6 +26,14 @@ v0.3.0のOIDCログインは利用者の動作確認済み。v0.4.0ではOIDC承
## 利用方法 ## 利用方法
### 信頼できる端末でのログイン継続
2026-11-08ローカル実装、未リリース。独立CLIと対応サーバーを更新すると、`pages login --remember` または `pages login --oidc --no-browser --remember` で最長30日のセッションを要求できる。管理者の `auth_trusted_session_days`(既定30、0で無効)に従い、応答の `expires_in` を期限として保存する。旧サーバーでは通常の期限になる場合がある。
パスワードログインは必要なTOTPを維持する。選択はTOTP challenge/OIDC grantへ固定し、認証完了時の追加パラメーターで変更できない。CLI grantはmanaged component `cli-auth` v2で `remember` 列を追加し、既存行をfalseとして保持する。承認済みgrantの交換とセッション発行は従来どおり単一トランザクションで処理し、期限は承認元ブラウザの期限を超えない。
ローカル期限切れ後は `logout` を挟まず再ログインできる。同一アカウントならcwdと未送信タスク下書きを保持し、認証失敗時は従来のローカル状態を変更しない。ログアウト・管理者による失効・アカウント停止は長期セッションにも適用する。共有端末では使用しない。
```sh ```sh
# 初回設定。パスワードはlogin時の非表示プロンプト、必要ならTOTPを続けて入力。 # 初回設定。パスワードはlogin時の非表示プロンプト、必要ならTOTPを続けて入力。
pages configure --origin https://pages.example.test --username anya pages configure --origin https://pages.example.test --username anya
+34 -1
View File
@@ -11,7 +11,7 @@
- 見直し:見直す日を迎えたもの、または30日間変更されていない未完了タスク。 - 見直し:見直す日を迎えたもの、または30日間変更されていない未完了タスク。
- プロジェクト:名前とメモ、関連Wiki、所属タスクの一覧。タスクは一つのプロジェクトへ所属、または未所属。 - プロジェクト:名前とメモ、関連Wiki、所属タスクの一覧。タスクは一つのプロジェクトへ所属、または未所属。
- タスク:件名、プレーンテキストのメモ、状態、優先度、分単位の見積もり、期限、取り組む日、見直す日、関連Wiki。 - タスク:件名、プレーンテキストのメモ、状態、優先度、分単位の見積もり、期限、取り組む日、見直す日、関連Wiki。
- 完了/再開、アーカイブ/復元。完了取消でも過去の版は残る。初版は物理削除を提供しない。 - 完了/再開、アーカイブ/復元。完了取消でも過去の版は残る。タスクの削除はアーカイブとは別の操作(下記)。
- タイトル絞り込みとカーソルページング、変更履歴の版番号・日時表示。 - タイトル絞り込みとカーソルページング、変更履歴の版番号・日時表示。
- 日本語/英語、既存テーマ、デスクトップの左ナビとモバイルの横ナビ・全画面編集モーダル。 - 日本語/英語、既存テーマ、デスクトップの左ナビとモバイルの横ナビ・全画面編集モーダル。
@@ -34,6 +34,39 @@
一覧GETは `kind=task|project`、`view`、`project`、`q`、`limit`、`before` を受け付けます。既定60件、上限100件。作成はPOST、更新はPUT、`If-Match: "{version}"` 必須。ヘッダーなしは428、古い版は412。UUIDをクライアントで生成し、同内容の作成再送は同じ版を返します。異内容の再送は競合です。成功時は `item` と現在読める `page_path`、ETagを返します。一覧はメモ本文を省略するため、編集やクイック完了前に必ず詳細を取得します。 一覧GETは `kind=task|project`、`view`、`project`、`q`、`limit`、`before` を受け付けます。既定60件、上限100件。作成はPOST、更新はPUT、`If-Match: "{version}"` 必須。ヘッダーなしは428、古い版は412。UUIDをクライアントで生成し、同内容の作成再送は同じ版を返します。異内容の再送は競合です。成功時は `item` と現在読める `page_path`、ETagを返します。一覧はメモ本文を省略するため、編集やクイック完了前に必ず詳細を取得します。
## タスクの削除
2026-11-08、v0.14.0で本番反映済み。[配備記録](../../operations/releases/2026-11-08-task-deletion.md)。
UUID検索は追加せず、既存のタスク編集画面で「アーカイブ/復元」の隣に「削除」を置きます。未保存の新規タスク、readonly、プロジェクト編集には表示しません。件名と削除範囲を確認してから実行し、削除失敗時は編集内容を保持します。アーカイブ済みタスクも同じ操作で削除できます。
- `DELETE /_/api/v1/extension/organizer.tasks/items/{uuid}`。PUTと同じ厳密な `If-Match: "{version}"` を要求し、成功204、未指定428、古い版412。成功応答を失った場合、同じ所有者・同じ削除前の版で再送できます。
- 所有者・Domain・active状態・システム拡張の有効状態を同一writer transactionで再検査。他人の対象/削除記録は404。プロジェクトの削除は提供しません。
- サブタスクがあれば409 `has_children`(アーカイブ済みも対象)。先に移動または削除します。実行中/一時停止中の集中セッション、実行中の作業記録があれば409 `working`。再帰削除・自動停止はしません。
- head・版参照・期限通知予約・達成度メトリクスを削除し、カレンダー時間枠との関連は解除します。Wiki本文、カレンダーの予定、記録済みの作業時間は独立した記録として残します。削除タスクは通常/アーカイブ一覧・詳細・変更履歴から取得できず、復元操作もありません。
- `organizer_task_deletions` にDomain、所有者、UUID、collectionで修飾したDAV名/UID、削除版、削除時刻だけを保持します。件名・本文は複写しません。DBとDocument Storeを一緒に保全する既存方針は変わりません。CASファイルや既存バックアップの安全消去を意味せず、保持期間・GCは別課題です。
- 削除記録・head除去・関連索引の更新・変更ジャーナル/共通outboxは原子的にコミット。履歴移行ジョブは削除記録から種類を解決し、head欠落で停止しません。
- DAVの一覧/REPORTから対象を除き、GETは404、multigetは対象ごとに404。旧ETagでのPUTは412。同じcollectionの同じUIDまたはhrefを使う新規/無条件PUTは既存の `no-uid-conflict` で拒否し、古い端末からの復活を防ぎます。削除済みUUIDへのJSON再作成は410。同名の件名を持つ**新しいUUID/DAV UID・href**のタスクは作成できます。DAV識別子の予約は索引再構築後も保持します。
- 従来の「DAV DELETEをアーカイブへ変換する」互換動作は変更しません。今回追加した不可逆操作はWeb/APIからの明示的な削除です。クライアント固有の同期/競合UIの挙動まで保証するものではありません。
`internal/server/task_delete_test.go` で条件付き削除・権限・再送・DBロールバック・通知取消・作業履歴保全・DAV索引再構築/再送拒否を検証します。既存のChromiumテストに、削除ボタンの位置、確認キャンセル、版競合、成功後の一覧更新を追加しています。本番データの削除は実施しません。
### 削除済みメール取り込みの再作成
PagesWiki v0.14.1/pages-cli v0.4.2で実装、2026-11-08 19:42 JSTに本番反映済み。[配備記録](../../operations/releases/2026-11-08-task-capture-recovery.md)。サーバーとCLIの両方の更新が必要です。DBスキーマ変更や既存データの削除はありません。
`POST /_/api/v1/extension/organizer.tasks/capture` は、受付記録に対応するタスクの状態を本文ハッシュより先に確認します。削除済みなら同じ内容・異なる内容とも410 `deleted`。タスクと削除記録が両方欠落していれば409 `capture_missing` とし、自動修復・再作成はしません。存続中のタスクへの異内容再送は従来どおり412です。
削除済み要求の保留下書きは `pages task retry REQUEST_UUID --recreate-deleted` で明示的に再取り込みできます。CLIは新しい要求を送る前に保存し、以降の再送用IDを表示します。通信失敗後は表示された新IDで通常の `task retry NEW_REQUEST_UUID` を使います。メール本文・Wiki suffixは保持し、以前のタスクの状態・作業時間・子タスクを復元する操作ではありません。
- APIには `replaces_deleted` に元のrequest UUIDを渡します。新しい `request_id` はURL名前空間のUUIDv5で、名前は `pages:task-recreate:` と元のrequest UUIDを連結したもの。任意の後継IDを拒否し、同じ再取り込みの二重作成を防ぎます。
- 同じDomain・所有者の受付記録と削除記録を要求し、元タスクが存続中なら412、他人の受付記録や不存在の要求は404。writer transaction内でも検査します。受付記録のない直接作成タスクには使えません。
- 新しいタスク・受付記録・変更履歴・通知予約を原子的に保存します。旧受付記録、削除記録、DAV識別子の予約は残し、旧端末の再送による復活を防ぎます。
- Wiki保存先にページが残っていれば、そのUUIDを新しいタスクに関連付けます。本文・リビジョンは上書きしません。存在しなければ保留本文から作成します。read/create/writeの現在権限と入力上限を検査し、ファイルなどページ以外との衝突は409です。保存先は保留要求と現在の既定値から解決するため、移動済みのWikiや既定Path変更を追跡して復元する機能ではありません。
- 再作成済み要求の再送は同じ新タスクを返します。そのタスクも削除済みなら410で停止し、さらに復活させません。元のメールを再入力しただけでは削除済み状態を解除しません。
`internal/server/task_capture_recreate_test.go` でライフサイクル・並行再送・所有者境界・ロールバック・Wiki保持を検証し、CLIの単体テストとHTTP結合テストでも再送IDの保持を検証します。
## 保存と復旧の境界 ## 保存と復旧の境界
`organizer_items` はDomain・所有者・UUID・種類・検索用メタデータ・現在版を保持します。本文を含む型付きJSONは既存Document StoreへSHA-256で保存し、同じJSONをDBにも保持します。`organizer_revisions` は版からDocumentへの参照、`organizer_changes` は後続処理用の小さな変更ジャーナルです。head更新・履歴・変更ジャーナルは同じSQLiteトランザクションです。 `organizer_items` はDomain・所有者・UUID・種類・検索用メタデータ・現在版を保持します。本文を含む型付きJSONは既存Document StoreへSHA-256で保存し、同じJSONをDBにも保持します。`organizer_revisions` は版からDocumentへの参照、`organizer_changes` は後続処理用の小さな変更ジャーナルです。head更新・履歴・変更ジャーナルは同じSQLiteトランザクションです。
+30 -6
View File
@@ -1,8 +1,9 @@
# Gecko連携の再配布条件 # Gecko連携の再配布条件
PagesWiki v0.13.0は、自作の連携コードと中継サービスのソースを配布し、Geckoエンジンは同梱しません。 PagesWiki v0.13.0ではGeckoエンジンの配布を保留しました。
実験機能`viewer.gecko`は既定無効のままです。既存3イメージのリリースにエンジンを追加せず、 現在は固定版のエンジン、対応ソース、第三者NOTICE、日本語フォントを含む配布bundleを生成できます。
専用relayも上流エンジンを含まないDockerfileとして提供します。 実験機能`viewer.gecko`は既定無効のままです。relayイメージとbundleは別物で、
起動時にbundle全体を検証してから資産を配信します。
本書は今回追加した部品の配布判断と残件を整理するもので、プロジェクト全体の法務監査ではありません。 本書は今回追加した部品の配布判断と残件を整理するもので、プロジェクト全体の法務監査ではありません。
## 部品と適用条件 ## 部品と適用条件
@@ -17,6 +18,8 @@ PagesWiki v0.13.0は、自作の連携コードと中継サービスのソース
| Emscripten runtime / WasmFS | 6.0.1と上流のpatch | Emscripten本体はMITまたはUIUC/NCSA。libc等のruntime依存には別noticeがあるため、ツールチェーンの最上位LICENSEだけでは棚卸し完了としない | | Emscripten runtime / WasmFS | 6.0.1と上流のpatch | Emscripten本体はMITまたはUIUC/NCSA。libc等のruntime依存には別noticeがあるため、ツールチェーンの最上位LICENSEだけでは棚卸し完了としない |
| zstddec | 0.2.0 | npm metadataは`MIT AND BSD-3-Clause`。JS wrapperと組み込まれたdecoderの両noticeを保持 | | zstddec | 0.2.0 | npm metadataは`MIT AND BSD-3-Clause`。JS wrapperと組み込まれたdecoderの両noticeを保持 |
| Liberation fonts | 上記Firefox commit内のPDF.js standard_fonts | SIL OFL 1.1。著作権表示・OFL本文・Reserved Font Namesを保持 | | Liberation fonts | 上記Firefox commit内のPDF.js standard_fonts | SIL OFL 1.1。著作権表示・OFL本文・Reserved Font Namesを保持 |
| Rust standard libraryと依存crate | 1.95.0と`library/Cargo.lock` | RustのMIT/Apache-2.0と各crateの個別条件。lockに記載された全registry crateのsource・noticeを保持 |
| Noto Sans CJK JP | Sans2.004、`523d033d6cb47f4a80c58a35753646f5c3608a78` | SIL OFL 1.1。未改変OTF、Adobeの埋込著作権表示、OFL本文を保持 |
relayのruntimeイメージは`FROM scratch`とし、Goバイナリとlicenseだけを含めます。 relayのruntimeイメージは`FROM scratch`とし、Goバイナリとlicenseだけを含めます。
Alpine/BusyBoxを新たに再配布する構成にはしません。`go list -deps`でrelayにリンクされる外部Go moduleは Alpine/BusyBoxを新たに再配布する構成にはしません。`go list -deps`でrelayにリンクされる外部Go moduleは
@@ -62,9 +65,28 @@ MPLはファイル単位の義務であり、別実装のWiki全体をMPLへ変
4. 提供するsourceとnoticeの可用性・保全、配布物とのhash対応を検査する。 4. 提供するsourceとnoticeの可用性・保全、配布物とのhash対応を検査する。
5. Mozillaの商標はコードlicenseとは別に扱い、Firefoxの公式配布であるとの表現やロゴの流用をしない。 5. Mozillaの商標はコードlicenseとは別に扱い、Firefoxの公式配布であるとの表現やロゴの流用をしない。
現時点では2・3・4の配布用bundleが未完成です。今回のrelease artifactにエンジンは載せず、 ### 配布bundle
本番では中継用鍵・資産mount・`viewer.gecko`の有効化を追加しません。
エンジン非同梱の連携コードと、通常のRSSフォルダショートカットはリリース対象です。 `tools/gecko/sources.lock.json`に取得元とSHA-256を固定し、`tools/gecko/bundle.py`で組み立てます。
生成物は98ファイル、合計1,196,102,561 bytes(manifest自身を除く)です。
manifestのSHA-256は`84953114f5e393dd97d9f948a5bc51c95b9355b58461dd3355e068a96cb2e381`。
同じ値をrelay側で固定し、列挙された全ファイルのサイズ・hash・通常ファイルであることを起動時に検査します。
不足、改変、symlink、別版混入を許可しません。
元のsource archiveを変更せず保存し、license/copying/copyright/notice/authorsファイルを別の閲覧用テキストにも集約します。
Mozillaの条件付きnoticeは**全分岐を含む保守的な上位集合**としてテキスト化し、元のHTMLはsource archiveに保持します。
Rustの追加依存はCargo.lockのチェックサムで検証します。crateから欠けていたFortanixのMPLヘッダと
vex-sdkのMIT本文も、元ソース・固定commitから補完しています。
Notoの未改変フォントには`© 2014-2021 Adobe (http://www.adobe.com/).`が埋め込まれ、READMEにも保持します。
閲覧画面のⓘは`/_/api/v1/extension/organizer.feeds/browser/distribution/v0.0.1/index.html`を開きます。
同じ入口からNOTICE、manifest、ソース一式を取得できます。認証は必要ですが、RSS・Geckoを無効化した後も、
認証済みの受領者はソースを取得できます。readonly利用者も取得可能です。
relay自体を撤去する場合は、先にbundleと取得先を保全・移設してください。無効化はソース提供の撤回を意味しません。
CIは中継バイナリの4番目のイメージを配布しますが、約1.2GBのbundleを通常イメージへ重複同梱しません。
検証済みbundleをread-onlyでmountする運用です。再配布条件の充足はこの固定版・未改変バイナリ・
保持したsource/noticeを前提とします。依存更新時はlockとnoticeを再確認し、公開済みbundleを上書きしません。
## 一次資料 ## 一次資料
@@ -75,3 +97,5 @@ MPLはファイル単位の義務であり、別実装のWiki全体をMPLへ変
- [zstddec 0.2.0 metadata](https://registry.npmjs.org/zstddec/0.2.0) - [zstddec 0.2.0 metadata](https://registry.npmjs.org/zstddec/0.2.0)
- [Go LICENSE](https://go.dev/LICENSE) - [Go LICENSE](https://go.dev/LICENSE)
- [golang.org/x/net v0.35.0 LICENSE](https://go.googlesource.com/net/+/refs/tags/v0.35.0/LICENSE) - [golang.org/x/net v0.35.0 LICENSE](https://go.googlesource.com/net/+/refs/tags/v0.35.0/LICENSE)
- [Noto CJK固定版OFL](https://github.com/notofonts/noto-cjk/blob/523d033d6cb47f4a80c58a35753646f5c3608a78/LICENSE)
- [vex-sdk固定版MIT](https://github.com/vexide/vex-sdk/blob/6c0b83d35b6fc31a7607efe456e387df45476314/LICENSE.md)
+34 -8
View File
@@ -28,7 +28,8 @@ WebSocketではOriginも検査し、grantは一回限りです。既存接続の
bac28056a00ef6e5fb4345117e73d3629e75aca00dac71389fabbce39c018a73 bac28056a00ef6e5fb4345117e73d3629e75aca00dac71389fabbce39c018a73
``` ```
展開後の`gecko.js/dist/`をread-onlyで`/gecko`へmountします。起動時に次の両ファイルのhashを確認し、 エンジン単体の`dist/`ではなく、後述するsource/notice付きbundleをread-onlyで`/gecko`へmountします。
起動時に次の両ファイルに加え、manifestに列挙された全ソース・NOTICE・フォントをhash検査し、
欠損・改変・異なる版の混在があれば中継は起動しません。 欠損・改変・異なる版の混在があれば中継は起動しません。
| ファイル | SHA-256 | | ファイル | SHA-256 |
@@ -37,13 +38,27 @@ bac28056a00ef6e5fb4345117e73d3629e75aca00dac71389fabbce39c018a73
| gecko.wasm.zst | ebd6c75179152624d9644865e11792ed25cadc714d9e0985f412baf9c637a086 | | gecko.wasm.zst | ebd6c75179152624d9644865e11792ed25cadc714d9e0985f412baf9c637a086 |
資産URLにも`assets/v0.0.1/`を含め、版をまたいだJS/WASMのcache混在を避けます。 資産URLにも`assets/v0.0.1/`を含め、版をまたいだJS/WASMのcache混在を避けます。
初回にはJSと圧縮WASMの合計38,175,359 bytes(約36.4MiB)の転送とWASMの展開・compileが必要です。 初回にはJS・圧縮WASM・日本語フォントの合計54,643,095 bytes(約52.1MiB)の転送とWASMの展開・compileが必要です。
約1.2GBの対応ソースは閲覧の起動時には取得せず、ⓘから明示的にダウンロードするときだけ配信します。
本体のDocker buildにFirefoxのソースビルドを加えません。 本体のDocker buildにFirefoxのソースビルドを加えません。
`Dockerfile.gecko-relay`は自前の中継バイナリだけを含みます。エンジンは同梱・再配布しません。 `Dockerfile.gecko-relay`は自前の中継バイナリだけを含みます。エンジンは同梱・再配布しません。
**エンジンをイメージへ同梱する場合だけでなく、mountした資産を利用者へ配信する前にもnoticeと対応sourceの提供が必要です。** **エンジンをイメージへ同梱する場合だけでなく、mountした資産を利用者へ配信する前にもnoticeと対応sourceの提供が必要です。**
固定版のMPL宣言、第三者依存物、今回の配布範囲は[再配布条件](gecko-redistribution.md)を参照してください。 固定版のMPL宣言、第三者依存物、今回の配布範囲は[再配布条件](gecko-redistribution.md)を参照してください。
v0.13.0の本番配備ではエンジンを配信せず、機能の有効化も行いません。 v0.13.0の本番配備ではエンジンを配信していません。新しいrelayは完成したbundleを必須とします。
### bundle生成
Python 3.11以降を使い、十分な空き容量のあるディスク上で実行します。ソースarchiveは展開せず保持します。
```sh
python tools/gecko/bundle.py --cache /srv/gecko-cache --output /srv/gecko/v0.0.1-bundle1
# 同一入力からの再生成。出力先はまだ存在しない新しいディレクトリを指定する。
python tools/gecko/bundle.py --cache /srv/gecko-cache --output /srv/gecko/rebuilt --offline
```
出力manifestのSHA-256が`84953114f5e393dd97d9f948a5bc51c95b9355b58461dd3355e068a96cb2e381`と一致することを確認します。
稼働中のmount先を上書きせず、source/noticeの提供を含めて不変の単位で保全します。
## 配置 ## 配置
@@ -55,7 +70,8 @@ v0.13.0の本番配備ではエンジンを配信せず、機能の有効化も
| 変数 | 内容 | | 変数 | 内容 |
| --- | --- | | --- | --- |
| PAGESWIKI_GECKO_KEY_PATH | 32文字以上の十分ランダムな共有鍵のファイル絶対Path。appとrelayへ同じread-only mount | | PAGESWIKI_GECKO_KEY_PATH | 32文字以上の十分ランダムな共有鍵のファイル絶対Path。appとrelayへ同じread-only mount |
| PAGESWIKI_GECKO_ASSETS_DIR | hash確認した`gecko.js/dist`の絶対Path | | PAGESWIKI_GECKO_ASSETS_DIR | 全ファイルを検証したbundleの絶対Path。engineだけのdistは禁止 |
| PAGESWIKI_GECKO_IMAGE | Giteaで配布した`pageswiki-gecko-relay:sha-...`またはrelease tag。省略時は開発用image |
| PAGESWIKI_GECKO_FRONT_SUBNET | 内部接続網。既定`172.24.0.0/27`。既存LANとの重複を避ける | | PAGESWIKI_GECKO_FRONT_SUBNET | 内部接続網。既定`172.24.0.0/27`。既存LANとの重複を避ける |
| PAGESWIKI_GECKO_EGRESS_SUBNET | 中継の外向き網。既定`172.24.0.32/27` | | PAGESWIKI_GECKO_EGRESS_SUBNET | 中継の外向き網。既定`172.24.0.32/27` |
@@ -100,7 +116,8 @@ UDP、80/443以外のTCP、単一ラベルのホスト名は拒否します。
| WebSocket受信idle | 90秒 | | WebSocket受信idle | 90秒 |
| 宛先接続 | 名前解決込み8秒、個別dial 2秒 | | 宛先接続 | 名前解決込み8秒、個別dial 2秒 |
| relayコンテナ | 256MiB、0.5 CPU、64 PIDs、read-only、capabilitiesなし | | relayコンテナ | 256MiB、0.5 CPU、64 PIDs、read-only、capabilitiesなし |
| 閲覧プロファイル | volatileな32MiB・2,048 entries、端末のOPFSへ永続化しない | | 閲覧プロファイル | 日本語フォントを含むvolatileな32MiB・2,048 entries、端末のOPFSへ永続化しない |
| source/noticeダウンロード | 全体2接続まで。ETag・Range対応。閲覧streamの枠とは分離 |
relayの稼働状態・接続数・送受信bytes・拒否数は、コンテナ内の次の操作でJSON取得できます。 relayの稼働状態・接続数・送受信bytes・拒否数は、コンテナ内の次の操作でJSON取得できます。
鍵はファイルから読み、標準出力には含めません。counterは再起動でリセットします。 鍵はファイルから読み、標準出力には含めません。counterは再起動でリセットします。
@@ -134,7 +151,10 @@ extension viewer.gecko off
```sh ```sh
go test -race ./internal/geckorelay ./internal/server -run 'TestGrant|TestDestinations|TestRelay|TestAssets|TestFeedGeckoAuthorization|TestFeedGeckoWebsocket' go test -race ./internal/geckorelay ./internal/server -run 'TestGrant|TestDestinations|TestRelay|TestAssets|TestFeedGeckoAuthorization|TestFeedGeckoWebsocket'
PAGESWIKI_BROWSER_TEST=1 PAGESWIKI_GECKO_TEST_ASSETS=/verified/gecko.js/dist go test ./internal/server -run '^TestFeedGeckoChromium$' -count=1 PAGESWIKI_BROWSER_TEST=1 PAGESWIKI_GECKO_TEST_ASSETS=/verified/bundle go test ./internal/server -run '^TestFeedGeckoChromium$' -count=1
PAGESWIKI_GECKO_TEST_BUNDLE=/verified/bundle go test ./internal/geckorelay -run TestDistribution
# 公開テストサイトへの実通信。実RSS・外部カレンダー・メールは使用しない。
PAGESWIKI_BROWSER_TEST=1 PAGESWIKI_GECKO_TEST_ASSETS=/verified/bundle PAGESWIKI_GECKO_PUBLIC_HTTPS_TEST=1 go test ./internal/server -run '^TestFeedGeckoChromium$' -count=1
node internal/server/testdata/feed-gecko-profile.mjs node internal/server/testdata/feed-gecko-profile.mjs
``` ```
@@ -144,6 +164,12 @@ node internal/server/testdata/feed-gecko-profile.mjs
標準のhistory.back()が失敗するため、フォーム内容やスクロール位置を復元する履歴ではありません。 標準のhistory.back()が失敗するため、フォーム内容やスクロール位置を復元する履歴ではありません。
画面のcanvasは最大1920×1080、experimental WASM JITとGPUは無効です。 画面のcanvasは最大1920×1080、experimental WASM JITとGPUは無効です。
本番の標準機能に昇格する前に、HTTPSサイトと証明書エラーの表示、Safari/iPhone SE、IME、コピー、 HTTPSの実描画と期限切れ証明書の拒否を確認しました。上流最小GREはエラーページの部品が不足するため、
find、実サイト互換性、複数タブ・起動失敗時のUX、低メモリ端末の測定、コンテナ外向きfirewallを検証します。 `about:neterror`/`about:certerror`を検知してcanvasを隠し、PagesWiki側で説明します。証明書の無視・例外追加は提供しません。
Noto CJKをメモリプロファイルのfontsに置き、エンジンを改変せず日本語描画も確認しています。
検索アイコンまたはCtrl/Cmd+Fからページ内検索できます。検索語は256文字まで、前後検索と一致なしの表示に対応し、合成記事で日本語検索を確認しています。起動失敗または120秒の起動上限到達時はiframeを破棄し、元記事を別タブで開く導線を残します。上流のdestroy呼出しだけではWASM資源の解放にならないため、親側のiframe破棄まで行います。`TestFeedGeckoStartupFailureChromium` はフォント取得失敗時の破棄と代替導線を検証します。
本番の標準機能に昇格する前に、Safari/iPhone SE、IME、コピー、実サイト互換性、
複数タブ・低メモリ端末の測定、コンテナ外向きfirewallを検証します。
外部ページのiframe拒否とは別の仕組みですが、すべてのサイトでの動作や軽さを保証するものではありません。 外部ページのiframe拒否とは別の仕組みですが、すべてのサイトでの動作や軽さを保証するものではありません。
+3
View File
@@ -11,6 +11,9 @@ runner の環境構築や Gitea の事前疎通診断は行わず、本番へ自
| `pageswiki-app`(app / app2 共通) | `Dockerfile` | | `pageswiki-app`(app / app2 共通) | `Dockerfile` |
| `pageswiki-adaptor-gateway` | `Dockerfile.adapter-gateway` | | `pageswiki-adaptor-gateway` | `Dockerfile.adapter-gateway` |
| `pageswiki-excalidraw-viewer` | `Dockerfile.excalidraw-viewer` | | `pageswiki-excalidraw-viewer` | `Dockerfile.excalidraw-viewer` |
| `pageswiki-gecko-relay`(任意) | `Dockerfile.gecko-relay` |
v0.15.0以降はGecko relayを含む4イメージをビルド・昇格します。以下の「3イメージ」は通常配備するapp・gateway・Excalidrawの組を指します。Gecko relayは別overlayで明示的に配備するもので、通常の本番更新では起動しません。
Kroki、Mermaid、code-server は upstream の配布イメージを使用する。 Kroki、Mermaid、code-server は upstream の配布イメージを使用する。
`main` / `mk_district` への push、手動実行でビルド・公開する。 `main` / `mk_district` への push、手動実行でビルド・公開する。
@@ -37,3 +37,56 @@ Safari、IME/copy/find、実HTTPSの互換性と証明書エラー、低メモ
本番の外向きfirewallは実験機能の昇格前の残件です。 本番の外向きfirewallは実験機能の昇格前の残件です。
構成・上限・切り戻しは[Gecko中継の試験導入](../gecko-relay.md)、機能の進捗は[RSS設計](../../design/ja/feeds.md)を参照してください。 構成・上限・切り戻しは[Gecko中継の試験導入](../gecko-relay.md)、機能の進捗は[RSS設計](../../design/ja/feeds.md)を参照してください。
## リリース・本番反映記録
対象commitは`5321d613b40db36238235ff68e256caa6d4e4cf1`。
2026-11-08 16:31:51 JSTに本番の外部HTTPS検証を完了しました。
- [ビルドCI run 66](https://git.anya.jp/anya/pages/actions/runs/66): success。
- [リリースCI run 67](https://git.anya.jp/anya/pages/actions/runs/67): success。
- [Gitea Release v0.13.0](https://git.anya.jp/anya/pages/releases/tag/v0.13.0)。
注釈付きGitタグ`v0.13.0`と同名の3イメージを公開しました。
SHAタグから再ビルドせず昇格し、両タグのmanifest digest一致を確認しています。
本番`.env.release`は`PAGESWIKI_IMAGE_TAG=v0.13.0`です。
app・app2・adaptor-gateway・excalidraw-viewerだけを切り替え、他サービスは変更していません。
### DBと復旧点
現在の両DBをSQLiteのオンラインバックアップで独立コピーし、`integrity_check`のokと、
新イメージをネットワーク遮断・読み取り専用で実行した`schema check`の成功を確認しました。
13管理コンポーネントはすべてcurrentで、feeds v6・task-productivity v4のままです。
この検査はlegacy領域の全移行を網羅するものではありません。今回のschema追加はありません。
最初に選んだ前回切替前バックアップにはfeeds v5が残っていたため、現在のDBのコピーへ検査対象を変更しました。
`/tmp`上の検査コピー作成はI/Oエラーで中断し、その一時コピーだけを除去して、
空き容量のあるディスク上でコピー・整合性検査を完了しています。本番DBへの検査用書き込みはしていません。
復旧点は`.deployment-backups/release-v0.13.0-20261108/`です。
`config/`に旧構成、`cutover/data`・`cutover/data2`に停止時点の全データを保存しました。
16:29:32 JSTに停止を開始し、16:31:01 JSTにchecksum同期・再走査の差分ゼロ・DB一致を確認しました。
稼働元とはinodeを共有せず、不変の旧バックアップとのみ未変更ファイルを共有しています。
旧3イメージは`rollback-before-v0.13.0-20261108`タグで保持しています。
旧版へ戻す場合も更新後の書き込みを失わないよう、データの自動巻き戻しは行いません。
### 配備後検証
- 4サービスのrevisionが対象commitと一致、再起動回数0。
- app・app2の`/health`と管理スキーマ検査が正常。
- 外部HTTPSでhealth・ログイン・カレンダーHTML枠は200、匿名のRSS・設定は303、RSS APIとGecko proxyは401。
カレンダーHTML枠の200は既存の仕様で、実予定データの取得・閲覧は検証していません。
- `feeds.js`・`task-productivity.js`・`feed-gecko.js`・`feed-gecko-profile.mjs`・`feed-gecko.css`の配信SHA-256がソースと一致。
- 起動直後のpanic/fatal・database locked・event job failed・schema errorは各0件。
- 本番へのGecko環境変数・asset mount追加なし、Gecko relayの起動なし。
手元ではGo全体テスト、go vet、関連race検査、CLI、配布ツール、ChromiumによるRSSと合成Gecko記事の試験を通しています。
ライセンス同梱を含め専用scratch relayのビルド・起動・statusも確認しましたが、配布イメージへの追加や本番起動はしていません。
### 配布イメージ
| イメージ(`git.anya.jp/anya/`、タグ`v0.13.0`) | manifest digest |
| --- | --- |
| pageswiki-app | `sha256:87e9a2761c136aff734761f296c9dbe34fc391ad5687eaf332d3c9ba15b03ab5` |
| pageswiki-adaptor-gateway | `sha256:b82bb2184d21ea692b63fa2f9a70f15392474719e444e8d2b7618723cc80c7f1` |
| pageswiki-excalidraw-viewer | `sha256:2fff1ac0191e2fc7d8ad21aba365c82e0500f81d78da3672c030e77cb6a418af` |
@@ -0,0 +1,77 @@
# PagesWiki v0.14.1とpages-cli v0.4.2
削除済みタスクの受付記録が残り、変更した下書きの再送で412になっていた問題を修正します。
削除済みなら410、受付記録に対応するタスクと削除記録が両方欠落していれば409 `capture_missing` で停止します。
存続中のタスクを異内容のcaptureで上書きすることは許可しません。
2026-11-08 19:42:51 JSTに本番配備後の確認を完了しました。
DBスキーマ変更・既存データの削除・実タスクの再取り込みは行っていません。
Gecko等の未コミット変更は含みません。
## 再取り込み
サーバーをv0.14.1、利用するCLIをv0.4.2に更新してから実行します。
別インスタンスへ接続している場合は、その接続先サーバーの更新も必要です。
```sh
pages --version
pages task retry REQUEST_UUID --recreate-deleted
```
保持した下書きから、新UUIDのタスクを作成します。旧UUIDの削除記録とDAV識別子予約を残し、
通常の再送で古いタスクが復活するのを防ぎます。再取り込み用IDは決定的で、応答消失や並行再送でも重複作成しません。
既存Wikiが保存先にあれば本文・リビジョンは変更せず、新タスクから関連付けます。
ページがなければ保留本文から作ります。移動済みページの自動探索や旧作業記録の復元ではありません。
通信失敗時はCLIが表示する新IDで `pages task retry NEW_REQUEST_UUID` を実行します。
セッションファイルや受付記録を手動で消さないでください。
詳細は[実装契約](../../design/ja/tasks-implementation.md#削除済みメール取り込みの再作成)と
[CLIのNeoMutt手順](https://git.anya.jp/anya/pages-cli/src/tag/v0.4.2/docs/neomutt.md)を参照してください。
## リリースと検証
| 対象 | タグ | commit | CI |
| --- | --- | --- | --- |
| PagesWiki | [v0.14.1](https://git.anya.jp/anya/pages/releases/tag/v0.14.1) | `4049acf76e36c12b8f3c506de5eaf1e920ac7e86` | [build 72](https://git.anya.jp/anya/pages/actions/runs/72)、[release 75](https://git.anya.jp/anya/pages/actions/runs/75) success |
| pages-cli | [v0.4.2](https://git.anya.jp/anya/pages-cli/releases/tag/v0.4.2) | `e27c023d66a61b73d3fe47e982daa6f34213c41f` | [build 73](https://git.anya.jp/anya/pages-cli/actions/runs/73)、[release 74](https://git.anya.jp/anya/pages-cli/actions/runs/74) success |
- 正確なリリースソースで `go test ./...`。server/storeのgo vet、削除・再取り込み・並行再送のrace検査が成功。
- CLIの52単体テスト、サーバーとCLIのHTTP結合テストが成功。Wiki本文・版の保全、他所有者拒否、readonly、kill switch、入力上限、保存途中のロールバックを検証。
- 公開されたCLIの4配布ファイルをSHA256SUMSで照合し、Pythonソースとcommitを照合。
- 配布Linux ELFでバージョン、メール取り込み、下書き差し替え、削除済み再取り込み、認証・ファイル権限のスモークテストとTLS関連6テストが成功。
- Linux ELFはglibc 2.36以降。macOS/Windowsの未検証バイナリは配布していません。
## 本番切り替えと復旧点
app・app2・adaptor-gateway・excalidraw-viewerを同じv0.14.1へ更新しました。
`.env.release` の選択は `PAGESWIKI_IMAGE_TAG=v0.14.1` です。
- 19:40:36 JSTに停止開始。
- 19:42:17 JSTに、停止時点のdata/data2についてchecksum同期、再走査の差分ゼロ、DBファイル一致を確認。
- 19:42:23 JSTに新版の起動と両アプリのhealth応答を確認。
- 設定と停止時データは `.deployment-backups/release-v0.14.1-20261108/` の `config/` と `cutover/data`、`cutover/data2` に保存。DBのinodeは稼働元と独立しています。
- 旧3イメージを `rollback-before-v0.14.1-20261108` タグで保持。旧バックアップも残しています。
v0.14.0への切り戻しはイメージ選択のみで行い、DBを過去へ戻しません。
その場合は再取り込みAPIが利用できなくなるため、CLIの再取り込み操作を止めてください。
v0.14.0より前への切り戻しは削除記録の扱いが異なり、[v0.14.0の注意点](2026-11-08-task-deletion.md#dbと切り戻し)が引き続き適用されます。
## 配備後確認
- 4サービスのrevisionが対象commitと一致、running、再起動回数0。
- app/app2のhealth正常。管理対象13スキーマはcurrent。これはlegacy領域を含む全移行検証ではありませんが、今回の変更にスキーマ移行はありません。
- 両DBの `quick_check` はok。
- 外部HTTPSのhealth・ログイン画面200。匿名のタスク/ダッシュボード/RSS画面303、タスクAPI401。匿名DELETEとcapture POSTも401。
- tasks.js、tasks.css、organizer-dashboard.js、feeds.js、feed-gecko.jsのSHA-256がリリースcommitと一致。
- 起動直後のfatal/panic、DB lock、schema/migration failure、event job failureは両アプリとも0件。
- 実際のメール本文・利用者の保留下書きを使った再取り込みは実施していません。
## 配布イメージ
SHAタグから再ビルドせず昇格。本番で取得したdigestとCI結果は一致しています。
| イメージ(`git.anya.jp/anya/`、タグ`v0.14.1`) | manifest digest |
| --- | --- |
| pageswiki-app | `sha256:11488fb958db12ec5a25aa265fc8179a31ab5728800f47605759822a44eb81e6` |
| pageswiki-adaptor-gateway | `sha256:ca17704eb5e88a4e73827ff2a5fafda7c4bb7d9be3987b5a83a3a5ae0c780098` |
| pageswiki-excalidraw-viewer | `sha256:a2b692c3864b8c4f13412e746fcea7cd9a2c03d49e0d5ead252432f37930c4c4` |
@@ -0,0 +1,70 @@
# PagesWiki v0.14.0
タスク編集画面に、アーカイブと独立した削除操作を追加するminor releaseです。
本日の達成率ウィジェットは説明文を除き、グラフと完了数/総数を表示します。
Geckoの追加整備やRSSの追加ショートカットなど、並行作業中の変更は含めません。
## 変更と削除範囲
- タスク編集画面の「アーカイブ/復元」の隣に「削除」。確認後に実行し、アーカイブ済みタスクにも対応。
- DELETE APIは所有者・Domain・active状態を検査し、If-Matchを要求。更新競合時は入力を保持。
- サブタスクが残る場合や作業/集中セッションが実行中の場合は削除を拒否。
- タスクhead、版参照、通知予約、達成度メトリクスを削除。カレンダー時間枠との関連は解除。
- Wikiメモ、カレンダー予定、記録済みの作業時間は保持。CASファイル・既存バックアップの安全消去ではありません。
- CalDAV一覧/REPORTから削除対象を除外。削除済みのUUIDとcollection内のDAV UID/hrefを予約し、古い端末からの再作成を拒否。
- 従来のDAV DELETEをアーカイブへ変換する動作は維持。
詳細は[タスクの実装契約](../../design/ja/tasks-implementation.md#タスクの削除)を参照してください。
## DBと切り戻し
`organizer_task_deletions` を追加します。起動時の移行は既存タスクを削除せず、
既存のタスクデータや版参照を変更しません。DAV索引再構築は削除記録の識別子予約にも対応します。
旧版は削除記録を認識しません。削除機能を使用した後の旧版への切り戻しでは、
クライアントの再送で同じDAVタスクが作成されるおそれがあります。
切り戻す場合は書き込み・DAV同期を停止してから判断し、DBを無断で過去へ戻さないでください。
## 検証と配備
対象commitは `38a4fcf5301e0c7c6cad12070e040dc62a03d41b`。
2026-11-08 18:20:25 JSTに配備後の検証を完了しました。
- [ビルドCI run 68](https://git.anya.jp/anya/pages/actions/runs/68)、[リリースCI run 69](https://git.anya.jp/anya/pages/actions/runs/69)はともにsuccess。
- [Gitea Release v0.14.0](https://git.anya.jp/anya/pages/releases/tag/v0.14.0)と注釈付きGitタグを公開。
- リリース対象だけの独立ソースで `go test -p 1 ./...`、server/storeのgo vet、配布ツール等15テスト、PC・モバイル幅のChromium回帰試験が成功。
- 両本番DBのオンラインバックアップを隔離し、`EnsureTasksSchema`を各2回実行。task head・版参照・DAV resource/collection識別子のdigestが移行前後で一致し、削除記録は0件、`integrity_check`はok。
- app・app2・adaptor-gateway・excalidraw-viewerを同じv0.14.0へ更新。他サービス・Gecko設定・利用者設定は変更なし。
本番のタスク削除や外部カレンダー本文を用いた検証は行っていません。
### 復旧点
`.deployment-backups/release-v0.14.0-20261108/` の `config/` に旧構成、
`cutover/data`・`cutover/data2`に停止時点のデータを保存しています。
18:18:53 JSTに停止を開始、18:19:57 JSTにchecksum同期・再走査の差分ゼロ・DB一致を確認しました。
稼働元とinodeを共有しません。旧バックアップは削除していません。
旧3イメージは `rollback-before-v0.14.0-20261108` タグで保持しています。
`.env.release` は `PAGESWIKI_IMAGE_TAG=v0.14.0`。
新版の4サービスは18:20:12〜18:20:18 JSTに起動しました。
### 配備後検証
- 4サービスのrevisionが対象commitと一致、running、再起動回数0。
- app・app2のhealthと管理スキーマ検査が正常。legacy task領域は上記の隔離コピー移行試験で別途確認。
- 両DBの `quick_check` がok、削除記録0件。
- 外部HTTPSのhealth・ログイン画面200。匿名のタスク/ダッシュボード/RSS画面は303、タスクAPIは401。
- 実在しないUUIDへの匿名DELETEを401で拒否。
- tasks.js、tasks.css、organizer-dashboard.js、feeds.js、feed-gecko.jsの配信SHA-256がリリースcommitと一致。未完了Gecko変更の混入なし。
- 起動直後のfatal/panic、DB lock、event job failed、schema/migration errorは両アプリとも各0件。
### 配布イメージ
SHAタグから再ビルドせず昇格し、本番ホストで取得したdigestとCIの昇格結果が一致しています。
| イメージ(`git.anya.jp/anya/`、タグ`v0.14.0`) | manifest digest |
| --- | --- |
| pageswiki-app | `sha256:46edb2640bfda3be73d8bed354bb1e014b050d68b6c17af8036d65d7732378af` |
| pageswiki-adaptor-gateway | `sha256:696f2d0bcdf1a3dce8821c061a78ad9f3d6fcaadda32cc1cb4e5d5a117028fc0` |
| pageswiki-excalidraw-viewer | `sha256:4d72abb4c1964553458af2b95e19722e18ae05fcfa2b02ff086407ad962ca62c` |
@@ -0,0 +1,48 @@
# PagesWiki v0.15.0とpages-cli v0.5.0
ブラウザアップロード、信頼端末ログイン、RSSの配信時刻、CSV投影とタスクの関連ページ導線を追加します。Geckoの整備コードと配布イメージも含みますが、専用relayの本番有効化は行いません。
## 変更内容
- `/v/browser` のファイルドロップと右下のキュー。逐次送信、待機取消、折りたたみ、同名保護、一覧だけの更新。ページを閉じた後の再開とフォルダ再帰アップロードは未対応。
- ログイン時の信頼端末選択。管理者指定の最大30日・絶対期限で、既存セッションは延長しません。パスワード/TOTP、OIDC、LDAP、マジックリンクに選択を引き継ぎます。
- CLIの `login --remember` と期限切れ再ログイン時の作業パス/保留下書き保持。
- RSS一覧の配信時刻とDomainタイムゾーン。本文の日付表示も同じタイムゾーンへ統一。
- 保存済みタスクの関連Wikiページを開くボタン。
- 認証済み閲覧者の権限を確認する有界CSV macro。`{{csv:/data/items.csv range=A1:H200 header=true}}` と同じObjectのRevision固定に対応。CSV編集・匿名投影・外部URL取得は含みません。
- Geckoの日本語ページ内検索、起動上限・失敗時のiframe破棄、固定ソース/notice付き配布物検査。Safari実機、IME・コピー、運用firewallと低メモリ受入は残件。
## リリースと検証
本体commitは `b90aef79d03c21332cd49a47aba015a30f6de1a0`。Gitea [build 76](https://git.anya.jp/anya/pages/actions/runs/76)、[release 79](https://git.anya.jp/anya/pages/actions/runs/79) が成功し、SHAイメージを再ビルドせず `v0.15.0` へ昇格しました。
CLI commitは `bee03094f3bf2fa0c2dab80313d2f4bd15452c3d`。[v0.5.0](https://git.anya.jp/anya/pages-cli/releases/tag/v0.5.0) のCIと55単体テストが成功。公開した4ファイルのSHA256SUMS照合、Pythonソース一致、取得したLinux ELFのバージョン・ログイン・タスク/メール取り込み・下書き回復等の合成スモークテストを確認しました。未検証のmacOS/Windowsバイナリは追加していません。
本体は `go test ./...`、`go vet ./...`、リリースツールと壁紙テスト、Gecko配布ツールのテストが成功。Chromiumで認証・タスク・RSS・Gecko・アップロードの合成試験を実施しました。アップロードキューは1280px/390px幅、逐次送信、同名保護、取消、一覧更新を検証しています。
## DBと復旧
`cli-auth` v1→v2で `auth_cli_requests.remember` を既定0・0/1制約付きで追加します。他の管理対象componentのversionは変わりません。両インスタンスの独立コピーで、ネットワークを遮断しworkerを停止して新イメージを起動し、schema checkとSQLite integrity_checkが成功しました。実外部カレンダーやメール内容は検証に使用していません。
保全先は `.deployment-backups/release-v0.15.0-20261108/`。`config/` に旧設定、`cutover/data` と `cutover/data2` に停止時点のデータを保存します。旧3イメージの `rollback-before-v0.15.0-20261108` タグと既存バックアップを保持します。
新しいmigration履歴を旧版が受け付けるとは限らないため、旧イメージだけのダウングレードは行いません。切戻しが必要ならwriterを止め、切替後データも保全し、停止時バックアップとの変更差分を扱ってからDB・ファイル・設定・イメージを同じ復旧点へ戻します。運用開始後の書き込みを黙って破棄しません。
## 本番反映
2026-11-08 20:41:33 JSTに配備後確認を完了しました。20:40:05に停止し、20:41:10に停止時バックアップを検証、20:41:16に新版の起動とhealthを確認しています。
- app・app2・adaptor-gateway・excalidraw-viewerはすべて対象commitと一致し、running・再起動回数0。
- 両DBのquick_checkはok、管理対象13componentはcurrent。legacy領域全体の検証を意味するものではありません。
- 外部HTTPSのhealth・ログイン画面200。匿名タスク/dashboard/RSS画面303、タスクAPI・DELETE・captureは401。
- tasks、RSS、Gecko、アップロードキュー、信頼端末UIの配信JS/CSSはリリースcommitとSHA-256一致。公開ログイン画面の信頼端末選択も確認。
- 起動直後のfatal/panic、DB/schema failure、event job failureは両アプリとも0件。
- `.env.release` は `PAGESWIKI_IMAGE_TAG=v0.15.0`。Gecko relayコンテナは起動せず、通常3イメージ・4サービスだけを更新。
配備イメージのmanifest digest:
| イメージ(`git.anya.jp/anya/`) | digest |
| --- | --- |
| pageswiki-app | `sha256:43c398f2c294c7802987aaae1bfdf27b3d0c7ea24fa73df912ac03ea312366b0` |
| pageswiki-adaptor-gateway | `sha256:aebc515c3b3e36b58b03ecab1646e6d95b0dd21074a1a863ca5806cb7fde4df1` |
| pageswiki-excalidraw-viewer | `sha256:4a80354aa4567abe52ff17e32a6f224e85d8cd2e0f1a466e5690b4b353d901cc` |
+8
View File
@@ -12,6 +12,14 @@ require (
modernc.org/sqlite v1.32.0 modernc.org/sqlite v1.32.0
) )
require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/nftables v0.3.0 // indirect
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 // indirect
github.com/mdlayher/socket v0.5.0 // indirect
golang.org/x/sync v0.11.0 // indirect
)
require ( require (
github.com/Azure/go-ntlmssp v0.1.1 // indirect github.com/Azure/go-ntlmssp v0.1.1 // indirect
github.com/SherClockHolmes/webpush-go v1.4.0 github.com/SherClockHolmes/webpush-go v1.4.0
+7
View File
@@ -27,7 +27,10 @@ github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17w
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df h1:Mwihr/o+v4L5h56rwHLOE20+hh7Okhwno5BHz3zDuao= github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df h1:Mwihr/o+v4L5h56rwHLOE20+hh7Okhwno5BHz3zDuao=
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/nftables v0.3.0 h1:bkyZ0cbpVeMHXOrtlFc8ISmfVqq5gPJukoYieyVmITg=
github.com/google/nftables v0.3.0/go.mod h1:BCp9FsrbF1Fn/Yu6CLUc9GGZFw/+hsxfluNXXmxBfRM=
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo= github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd h1:gbpYu9NMq8jhDVbvlGkMFWCjLFlqqEZjEmObmhUy6Vo=
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw= github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -55,6 +58,10 @@ github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZ
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4= github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 h1:A1Cq6Ysb0GM0tpKMbdCXCIfBclan4oHk1Jb+Hrejirg=
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42/go.mod h1:BB4YCPDOzfy7FniQ/lxuYQ3dgmM2cZumHbK8RpTjN2o=
github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI=
github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI=
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA= github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
+85
View File
@@ -0,0 +1,85 @@
package geckorelay
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
)
const DistributionPrefix = "/distribution/v0.0.1/"
// Updated only after the reproducible source/notice bundle has been reviewed.
const DistributionManifestSHA256 = "84953114f5e393dd97d9f948a5bc51c95b9355b58461dd3355e068a96cb2e381"
type DistributionFile struct {
File string `json:"file"`
SHA256 string `json:"sha256"`
Size int64 `json:"size"`
Kind string `json:"kind"`
}
var distributionName = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9._+-]{0,150}$`)
func VerifyDistribution(dir string) (map[string]DistributionFile, error) {
return verifyDistribution(dir, DistributionManifestSHA256)
}
func verifyDistribution(dir, expected string) (map[string]DistributionFile, error) {
path := filepath.Join(dir, "manifest.json")
info, err := os.Lstat(path)
if err != nil || !info.Mode().IsRegular() || info.Size() > 1<<20 {
return nil, fmt.Errorf("Gecko distribution manifest missing or invalid")
}
raw, err := os.ReadFile(path)
if err != nil {
return nil, err
}
sum := sha256.Sum256(raw)
if hex.EncodeToString(sum[:]) != expected {
return nil, fmt.Errorf("Gecko distribution manifest checksum mismatch")
}
var manifest struct {
Format string `json:"format"`
Version string `json:"version"`
Files []DistributionFile `json:"files"`
}
if json.Unmarshal(raw, &manifest) != nil || manifest.Format != "pageswiki.gecko-distribution.v1" || manifest.Version != "v0.0.1" || len(manifest.Files) > 512 {
return nil, fmt.Errorf("invalid Gecko distribution format")
}
files := map[string]DistributionFile{}
for _, entry := range manifest.Files {
if !distributionName.MatchString(entry.File) || entry.File == "manifest.json" || entry.Size < 1 || entry.Size > 2<<30 || len(entry.SHA256) != 64 {
return nil, fmt.Errorf("invalid distribution entry")
}
if _, exists := files[entry.File]; exists {
return nil, fmt.Errorf("duplicate distribution entry")
}
info, err := os.Lstat(filepath.Join(dir, entry.File))
if err != nil || !info.Mode().IsRegular() || info.Size() != entry.Size {
return nil, fmt.Errorf("distribution file missing or invalid: %s", entry.File)
}
file, err := os.Open(filepath.Join(dir, entry.File))
if err != nil {
return nil, err
}
hash := sha256.New()
_, err = io.Copy(hash, io.LimitReader(file, entry.Size+1))
file.Close()
if err != nil || hex.EncodeToString(hash.Sum(nil)) != entry.SHA256 {
return nil, fmt.Errorf("distribution file checksum mismatch: %s", entry.File)
}
files[entry.File] = entry
}
for _, name := range []string{"index.html", "README.txt", "gecko.js", "gecko.wasm.zst", "firefox.tar.gz", "firefox.tar.gz.notices.txt", "wrapper.tar.gz", "wrapper-MPL.txt", "emscripten.tar.gz", "emscripten.tar.gz.notices.txt", "rust-src.tar.xz", "rust-src.tar.xz.notices.txt", "zstddec.tgz", "zstddec.tgz.notices.txt", "NotoSansCJKjp-Regular.otf", "NotoSansCJK-LICENSE.txt"} {
if _, ok := files[name]; !ok {
return nil, fmt.Errorf("distribution incomplete: %s", name)
}
}
files["manifest.json"] = DistributionFile{File: "manifest.json", SHA256: expected, Size: int64(len(raw)), Kind: "manifest"}
return files, nil
}
+83
View File
@@ -0,0 +1,83 @@
package geckorelay
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"time"
)
func TestDistribution(t *testing.T) {
dir := t.TempDir()
if _, err := VerifyDistribution(dir); err == nil {
t.Fatal("missing distribution accepted")
}
names := []string{"index.html", "README.txt", "gecko.js", "gecko.wasm.zst", "firefox.tar.gz", "firefox.tar.gz.notices.txt", "wrapper.tar.gz", "wrapper-MPL.txt", "emscripten.tar.gz", "emscripten.tar.gz.notices.txt", "rust-src.tar.xz", "rust-src.tar.xz.notices.txt", "zstddec.tgz", "zstddec.tgz.notices.txt", "NotoSansCJKjp-Regular.otf", "NotoSansCJK-LICENSE.txt"}
content := []byte("synthetic source and notice")
hash := sha256.Sum256(content)
var entries []DistributionFile
for _, name := range names {
if err := os.WriteFile(filepath.Join(dir, name), content, 0600); err != nil {
t.Fatal(err)
}
entries = append(entries, DistributionFile{File: name, Size: int64(len(content)), SHA256: hex.EncodeToString(hash[:])})
}
raw, _ := json.Marshal(map[string]any{"format": "pageswiki.gecko-distribution.v1", "version": "v0.0.1", "files": entries})
if err := os.WriteFile(filepath.Join(dir, "manifest.json"), raw, 0600); err != nil {
t.Fatal(err)
}
sum := sha256.Sum256(raw)
want := hex.EncodeToString(sum[:])
files, err := verifyDistribution(dir, want)
if err != nil {
t.Fatal(err)
}
relay, _ := New(testKey, dir)
relay.Distribution = files
for _, name := range []string{"index.html", "firefox.tar.gz", "manifest.json", "unknown", "../manifest.json"} {
req := httptest.NewRequest("GET", DistributionPrefix+name, nil)
req.Header.Set(GrantHeader, Sign(testKey, Grant{Subject: "test:user", Nonce: "download-test-0123456789", Expires: time.Now().Add(30 * time.Second).Unix()}))
rec := httptest.NewRecorder()
relay.ServeHTTP(rec, req)
expected := 200
if strings.Contains(name, "unknown") || strings.Contains(name, "../") {
expected = 404
}
if rec.Code != expected {
t.Fatalf("%s: %d", name, rec.Code)
}
if expected == 200 && rec.Header().Get("ETag") == "" {
t.Fatal("no ETag")
}
}
if err := os.WriteFile(filepath.Join(dir, "README.txt"), []byte("tampered"), 0600); err != nil {
t.Fatal(err)
}
if _, err := verifyDistribution(dir, want); err == nil {
t.Fatal("tampered notice accepted")
}
if err := os.Remove(filepath.Join(dir, "README.txt")); err != nil {
t.Fatal(err)
}
if err := os.Symlink(filepath.Join(dir, "gecko.js"), filepath.Join(dir, "README.txt")); err != nil {
t.Fatal(err)
}
if _, err := verifyDistribution(dir, want); err == nil {
t.Fatal("symlink accepted")
}
}
func TestDistributionRealBundle(t *testing.T) {
dir := os.Getenv("PAGESWIKI_GECKO_TEST_BUNDLE")
if dir == "" {
t.Skip("opt-in complete distribution")
}
if _, err := VerifyDistribution(dir); err != nil {
t.Fatal(err)
}
}
+45 -1
View File
@@ -9,6 +9,7 @@ import (
"io" "io"
"net" "net"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
@@ -28,6 +29,8 @@ const (
type Relay struct { type Relay struct {
Key, Assets string Key, Assets string
Distribution map[string]DistributionFile
downloads chan struct{}
mu sync.Mutex mu sync.Mutex
active map[string]bool active map[string]bool
used map[string]int64 used map[string]int64
@@ -40,7 +43,7 @@ func New(key, assets string) (*Relay, error) {
if len(key) < 32 { if len(key) < 32 {
return nil, errors.New("relay key must contain at least 32 bytes") return nil, errors.New("relay key must contain at least 32 bytes")
} }
r := &Relay{Key: key, Assets: assets, active: map[string]bool{}, used: map[string]int64{}} r := &Relay{Key: key, Assets: assets, active: map[string]bool{}, used: map[string]int64{}, downloads: make(chan struct{}, 2)}
r.dial = func(ctx context.Context, host string, port uint16) (net.Conn, error) { r.dial = func(ctx context.Context, host string, port uint16) (net.Conn, error) {
ctx, cancel := context.WithTimeout(ctx, 8*time.Second) ctx, cancel := context.WithTimeout(ctx, 8*time.Second)
defer cancel() defer cancel()
@@ -72,6 +75,47 @@ func (r *Relay) ServeHTTP(w http.ResponseWriter, req *http.Request) {
json.NewEncoder(w).Encode(map[string]any{"active_sessions": active, "received_bytes": r.rx.Load(), "sent_bytes": r.tx.Load(), "rejected": r.rejected.Load(), "profile": "tcp-80-443", "max_sessions": 4, "max_streams": maxStreams, "bytes_per_second": bytesPerSecond, "max_session_bytes": maxBytes}) json.NewEncoder(w).Encode(map[string]any{"active_sessions": active, "received_bytes": r.rx.Load(), "sent_bytes": r.tx.Load(), "rejected": r.rejected.Load(), "profile": "tcp-80-443", "max_sessions": 4, "max_streams": maxStreams, "bytes_per_second": bytesPerSecond, "max_session_bytes": maxBytes})
return return
} }
if strings.HasPrefix(req.URL.Path, DistributionPrefix) {
name := strings.TrimPrefix(req.URL.Path, DistributionPrefix)
entry, ok := r.Distribution[name]
if !ok {
http.NotFound(w, req)
return
}
select {
case r.downloads <- struct{}{}:
defer func() { <-r.downloads }()
default:
http.Error(w, "download limit", 429)
return
}
w.Header().Set("ETag", `"`+entry.SHA256+`"`)
w.Header().Set("Cache-Control", "private, max-age=86400, immutable")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Content-Security-Policy", "default-src 'none'; base-uri 'none'; frame-ancestors 'self'")
w.Header().Set("Referrer-Policy", "no-referrer")
switch {
case name == "index.html":
w.Header().Set("Content-Type", "text/html; charset=utf-8")
case strings.HasSuffix(name, ".txt"):
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
case name == "manifest.json":
w.Header().Set("Content-Type", "application/json")
default:
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", `attachment; filename="`+name+`"`)
}
// ServeContent avoids ServeFile's /index.html -> ./ redirect, which
// would escape the explicit file allowlist at the proxy boundary.
file, err := os.Open(filepath.Join(r.Assets, name))
if err != nil {
http.NotFound(w, req)
return
}
defer file.Close()
http.ServeContent(w, req, name, time.Time{}, file)
return
}
if req.URL.Path == AssetsPrefix+"gecko.js" || req.URL.Path == AssetsPrefix+"gecko.wasm.zst" { if req.URL.Path == AssetsPrefix+"gecko.js" || req.URL.Path == AssetsPrefix+"gecko.wasm.zst" {
w.Header().Set("Cross-Origin-Resource-Policy", "same-origin") w.Header().Set("Cross-Origin-Resource-Policy", "same-origin")
w.Header().Set("Cache-Control", "private, max-age=86400, immutable") w.Header().Set("Cache-Control", "private, max-age=86400, immutable")
+11
View File
@@ -35,6 +35,17 @@ func (s *Server) handleAuthAdmin(w http.ResponseWriter, r *http.Request) {
} }
panel := "auth" panel := "auth"
switch r.FormValue("action") { switch r.FormValue("action") {
case "save_trusted_session_policy":
panel = "auth-sessions"
days, err := strconv.Atoi(r.PostForm.Get("trusted_session_days"))
if err != nil || days < 0 || days > 30 {
http.Error(w, "trusted session lifetime must be between 0 and 30 days", 400)
return
}
if err := s.store.SetConfigInDomain(domainUUID, "auth_trusted_session_days", strconv.Itoa(days)); err != nil {
http.Error(w, "could not save session policy", 500)
return
}
case "save_session_policy": case "save_session_policy":
panel = "auth-sessions" panel = "auth-sessions"
minutes, err := strconv.Atoi(r.FormValue("session_minutes")) minutes, err := strconv.Atoi(r.FormValue("session_minutes"))
+4
View File
@@ -51,4 +51,8 @@ func TestBrowserCookieLoginLogoutChromium(t *testing.T) {
if err := s.store.DB.QueryRow(`SELECT count(*) FROM auth_sessions WHERE revoked_at_ms>0`).Scan(&revoked); err != nil || revoked != 1 { if err := s.store.DB.QueryRow(`SELECT count(*) FROM auth_sessions WHERE revoked_at_ms>0`).Scan(&revoked); err != nil || revoked != 1 {
t.Fatalf("browser revocations=%d %v", revoked, err) t.Fatalf("browser revocations=%d %v", revoked, err)
} }
var lifetime int64
if err := s.store.DB.QueryRow(`SELECT expires_at_ms-auth_time_ms FROM auth_sessions WHERE revoked_at_ms>0`).Scan(&lifetime); err != nil || lifetime != (30*24*time.Hour).Milliseconds() {
t.Fatalf("trusted browser lifetime=%d %v", lifetime, err)
}
} }
+4 -1
View File
@@ -74,7 +74,7 @@ func (s *Server) handleCLIAuth(w http.ResponseWriter, r *http.Request, action st
writeEventJSON(w, 400, map[string]string{"error": "invalid_request"}) writeEventJSON(w, 400, map[string]string{"error": "invalid_request"})
return return
} }
id, device, code, err := s.store.StartCLIAuth(ctx, domain, cliOrigin(r), challenge) id, device, code, err := s.store.StartCLIAuthForLogin(ctx, domain, cliOrigin(r), challenge, r.PostForm.Get("remember") == "1")
if err != nil { if err != nil {
cliAuthError(w, err) cliAuthError(w, err)
return return
@@ -140,6 +140,9 @@ func (s *Server) verifyCLIAuth(w http.ResponseWriter, r *http.Request) {
return return
} }
data := map[string]any{"CLIAuth": true, "CLIOrigin": grant.Origin, "CLIRequest": id} data := map[string]any{"CLIAuth": true, "CLIOrigin": grant.Origin, "CLIRequest": id}
if grant.Remember {
data["CLIRememberDays"] = s.store.TrustedSessionDays(domain)
}
if grant.State != "pending" { if grant.State != "pending" {
data["CLIDone"] = true data["CLIDone"] = true
s.renderAuthPage(w, r, data) s.renderAuthPage(w, r, data)
+28 -2
View File
@@ -28,6 +28,14 @@ func cliForm(s *Server, path string, form url.Values, cookie, origin string) *ht
} }
func TestCLIAuthOIDCFlow(t *testing.T) { func TestCLIAuthOIDCFlow(t *testing.T) {
for _, remember := range []bool{false, true} {
t.Run(map[bool]string{false: "normal", true: "trusted"}[remember], func(t *testing.T) {
testCLIAuthOIDCFlow(t, remember)
})
}
}
func testCLIAuthOIDCFlow(t *testing.T, remember bool) {
s, api, domain := configFixture(t) s, api, domain := configFixture(t)
principal := s.mustCLIPrincipal(t, domain, api) principal := s.mustCLIPrincipal(t, domain, api)
// An enrolled local factor must not add a second challenge to OIDC consent. // An enrolled local factor must not add a second challenge to OIDC consent.
@@ -43,7 +51,13 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
} }
verifier := strings.Repeat("x", 43) verifier := strings.Repeat("x", 43)
sum := sha256.Sum256([]byte(verifier)) sum := sha256.Sum256([]byte(verifier))
start := cliForm(s, "/_/auth/cli/start", url.Values{"code_challenge": {base64.RawURLEncoding.EncodeToString(sum[:])}, "code_challenge_method": {"S256"}}, "", "") startForm := url.Values{"code_challenge": {base64.RawURLEncoding.EncodeToString(sum[:])}, "code_challenge_method": {"S256"}}
expectedSeconds := 24 * 60 * 60
if remember {
startForm.Set("remember", "1")
expectedSeconds *= 30
}
start := cliForm(s, "/_/auth/cli/start", startForm, "", "")
if start.Code != 200 { if start.Code != 200 {
t.Fatalf("start %d %s", start.Code, start.Body.String()) t.Fatalf("start %d %s", start.Code, start.Body.String())
} }
@@ -63,7 +77,12 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
t.Fatalf("verify landing: %d %s", verify.Code, verify.Body.String()) t.Fatalf("verify landing: %d %s", verify.Code, verify.Body.String())
} }
begin := httptest.NewRecorder() begin := httptest.NewRecorder()
s.beginOIDC(begin, httptest.NewRequest("GET", "https://localhost/_/auth/oidc?cli="+id, nil)) // The browser query must not override the CLI's persisted choice.
tamperedRemember := "1"
if remember {
tamperedRemember = "0"
}
s.beginOIDC(begin, httptest.NewRequest("GET", "https://localhost/_/auth/oidc?cli="+id+"&remember="+tamperedRemember, nil))
if begin.Code != 302 { if begin.Code != 302 {
t.Fatalf("oidc begin %d %s", begin.Code, begin.Body.String()) t.Fatalf("oidc begin %d %s", begin.Code, begin.Body.String())
} }
@@ -86,6 +105,9 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
for _, cookie := range complete.Result().Cookies() { for _, cookie := range complete.Result().Cookies() {
if cookie.Name == authCookieName { if cookie.Name == authCookieName {
browser = cookie.Value browser = cookie.Value
if cookie.MaxAge != expectedSeconds {
t.Fatalf("cookie lifetime %d, want %d", cookie.MaxAge, expectedSeconds)
}
} }
} }
if browser == "" { if browser == "" {
@@ -128,6 +150,7 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
var result struct { var result struct {
Token string `json:"access_token"` Token string `json:"access_token"`
Username string `json:"username"` Username string `json:"username"`
Expires int `json:"expires_in"`
} }
if err := json.Unmarshal(exchange.Body.Bytes(), &result); err != nil { if err := json.Unmarshal(exchange.Body.Bytes(), &result); err != nil {
t.Fatal(err) t.Fatal(err)
@@ -135,6 +158,9 @@ func TestCLIAuthOIDCFlow(t *testing.T) {
if !strings.HasPrefix(result.Token, "pw_api_") || result.Username != "admin" || result.Token == browser { if !strings.HasPrefix(result.Token, "pw_api_") || result.Username != "admin" || result.Token == browser {
t.Fatal("invalid delegated credential") t.Fatal("invalid delegated credential")
} }
if result.Expires > expectedSeconds || result.Expires < expectedSeconds-10 {
t.Fatalf("CLI lifetime %d, want approximately %d", result.Expires, expectedSeconds)
}
if _, err := s.store.PrincipalForSession(domain, result.Token); err != nil { if _, err := s.store.PrincipalForSession(domain, result.Token); err != nil {
t.Fatal(err) t.Fatal(err)
} }
+19 -7
View File
@@ -14,7 +14,10 @@ import (
"time" "time"
) )
type oidcChallenge struct{ Verifier, Nonce, Return, Issuer, ClientID, BrowserHash, CLIRequest string } type oidcChallenge struct {
Verifier, Nonce, Return, Issuer, ClientID, BrowserHash, CLIRequest string
Remember bool
}
func logOIDCFailure(stage, domainUUID, issuer string, err error) { func logOIDCFailure(stage, domainUUID, issuer string, err error) {
host := "invalid" host := "invalid"
@@ -57,6 +60,7 @@ func (s *Server) beginOIDC(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 8*time.Second) ctx, cancel := context.WithTimeout(r.Context(), 8*time.Second)
defer cancel() defer cancel()
cliRequest := r.URL.Query().Get("cli") cliRequest := r.URL.Query().Get("cli")
remember := r.URL.Query().Get("remember") == "1"
returnPath := safeReturnPath(r.URL.Query().Get("return")) returnPath := safeReturnPath(r.URL.Query().Get("return"))
if cliRequest != "" { if cliRequest != "" {
if !cliSecureTransport(r) || !cliProofPattern.MatchString(cliRequest) { if !cliSecureTransport(r) || !cliProofPattern.MatchString(cliRequest) {
@@ -68,6 +72,12 @@ func (s *Server) beginOIDC(w http.ResponseWriter, r *http.Request) {
return return
} }
returnPath = cliVerifyPath(cliRequest) returnPath = cliVerifyPath(cliRequest)
grant, err := s.store.CLIAuthRequest(ctx, domainUUID, cliOrigin(r), cliRequest)
if err != nil {
http.Error(w, "invalid CLI request", 400)
return
}
remember = grant.Remember
} }
metadata, err := fetchOIDCMetadata(ctx, config.Issuer) metadata, err := fetchOIDCMetadata(ctx, config.Issuer)
if err != nil { if err != nil {
@@ -77,7 +87,7 @@ func (s *Server) beginOIDC(w http.ResponseWriter, r *http.Request) {
} }
verifier, nonce, browser := randomURLToken(32), randomURLToken(24), randomURLToken(32) verifier, nonce, browser := randomURLToken(32), randomURLToken(24), randomURLToken(32)
browserDigest := sha256.Sum256([]byte(browser)) browserDigest := sha256.Sum256([]byte(browser))
state, err := s.store.CreateAuthChallenge(domainUUID, "", "oidc", oidcChallenge{Verifier: verifier, Nonce: nonce, Return: returnPath, Issuer: config.Issuer, ClientID: config.ClientID, BrowserHash: base64.RawURLEncoding.EncodeToString(browserDigest[:]), CLIRequest: cliRequest}, 5*time.Minute) state, err := s.store.CreateAuthChallenge(domainUUID, "", "oidc", oidcChallenge{Verifier: verifier, Nonce: nonce, Return: returnPath, Issuer: config.Issuer, ClientID: config.ClientID, BrowserHash: base64.RawURLEncoding.EncodeToString(browserDigest[:]), CLIRequest: cliRequest, Remember: remember}, 5*time.Minute)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
@@ -205,7 +215,7 @@ func (s *Server) completeOIDC(w http.ResponseWriter, r *http.Request) {
http.Error(w, "No local account matches the configured OIDC identity field", http.StatusForbidden) http.Error(w, "No local account matches the configured OIDC identity field", http.StatusForbidden)
return return
} }
token, err := s.store.CreateBrowserAuthSession(domainUUID, principal.UUID, 0) token, lifetime, err := s.store.CreateLoginSession(domainUUID, principal.UUID, 0, true, challenge.Remember)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
return return
@@ -217,7 +227,7 @@ func (s *Server) completeOIDC(w http.ResponseWriter, r *http.Request) {
return return
} }
} }
s.setAuthCookie(w, r, token) s.setAuthCookieForSeconds(w, r, token, int(lifetime.Seconds()))
http.Redirect(w, r, challenge.Return, http.StatusSeeOther) http.Redirect(w, r, challenge.Return, http.StatusSeeOther)
} }
@@ -244,7 +254,7 @@ func (s *Server) requestMagicLink(w http.ResponseWriter, r *http.Request) {
if principalErr == nil { if principalErr == nil {
select { select {
case s.smtpSlots <- struct{}{}: case s.smtpSlots <- struct{}{}:
token, err := s.store.CreateAuthChallenge(domainUUID, principal.UUID, "magic-link", magicLinkChallenge{Return: safeReturnPath(r.FormValue("return")), Email: principal.Email}, 15*time.Minute) token, err := s.store.CreateAuthChallenge(domainUUID, principal.UUID, "magic-link", magicLinkChallenge{Return: safeReturnPath(r.FormValue("return")), Email: principal.Email, Remember: r.PostForm.Get("remember") == "1"}, 15*time.Minute)
if err != nil { if err != nil {
<-s.smtpSlots <-s.smtpSlots
break break
@@ -282,12 +292,12 @@ func (s *Server) verifyMagicLink(w http.ResponseWriter, r *http.Request) {
http.Error(w, "This sign-in link is invalid or expired", http.StatusBadRequest) http.Error(w, "This sign-in link is invalid or expired", http.StatusBadRequest)
return return
} }
token, err := s.store.CreateBrowserAuthSession(domainUUID, principalUUID, 0) token, lifetime, err := s.store.CreateLoginSession(domainUUID, principalUUID, 0, true, payload.Remember)
if err != nil { if err != nil {
http.Error(w, "This sign-in link is invalid or expired", http.StatusBadRequest) http.Error(w, "This sign-in link is invalid or expired", http.StatusBadRequest)
return return
} }
s.setAuthCookie(w, r, token) s.setAuthCookieForSeconds(w, r, token, int(lifetime.Seconds()))
http.Redirect(w, r, safeReturnPath(payload.Return), http.StatusSeeOther) http.Redirect(w, r, safeReturnPath(payload.Return), http.StatusSeeOther)
} }
@@ -306,6 +316,8 @@ func (s *Server) renderAuthPage(w http.ResponseWriter, r *http.Request, data map
data["LDAPEnabled"] = config.Enabled data["LDAPEnabled"] = config.Enabled
} }
data["Locale"] = s.getLocale(domainUUID) data["Locale"] = s.getLocale(domainUUID)
data["TrustedSessionDays"] = s.store.TrustedSessionDays(domainUUID)
data["RememberRequested"] = r.PostForm.Get("remember") == "1"
transparency := s.homeGlassTransparency(domainUUID) transparency := s.homeGlassTransparency(domainUUID)
data["HomeGlassTransparency"] = transparency data["HomeGlassTransparency"] = transparency
data["HomeGlassOpacity"] = 100 - transparency data["HomeGlassOpacity"] = 100 - transparency
+12 -11
View File
@@ -62,7 +62,11 @@ func requestIsHTTPS(r *http.Request) bool {
} }
func (s *Server) setAuthCookie(w http.ResponseWriter, r *http.Request, token string) { func (s *Server) setAuthCookie(w http.ResponseWriter, r *http.Request, token string) {
http.SetCookie(w, &http.Cookie{Name: authCookieName, Value: token, Path: "/", HttpOnly: true, Secure: requestIsHTTPS(r), SameSite: http.SameSiteLaxMode, MaxAge: s.store.AuthSessionLifetimeMinutes(s.domainUUIDForRequest(r)) * 60}) s.setAuthCookieForSeconds(w, r, token, s.store.AuthSessionLifetimeMinutes(s.domainUUIDForRequest(r))*60)
}
func (s *Server) setAuthCookieForSeconds(w http.ResponseWriter, r *http.Request, token string, seconds int) {
http.SetCookie(w, &http.Cookie{Name: authCookieName, Value: token, Path: "/", HttpOnly: true, Secure: requestIsHTTPS(r), SameSite: http.SameSiteLaxMode, MaxAge: seconds})
} }
func (s *Server) authTokenFromRequest(r *http.Request) string { func (s *Server) authTokenFromRequest(r *http.Request) string {
@@ -160,6 +164,7 @@ func (s *Server) handleAuth(w http.ResponseWriter, r *http.Request) {
} }
var principal *store.Principal var principal *store.Principal
mfaLevel := 0 mfaLevel := 0
remember := r.PostForm.Get("remember") == "1"
if action == "setup" && setup && s.validBootstrapToken(domainUUID, r.FormValue("bootstrap_token")) { if action == "setup" && setup && s.validBootstrapToken(domainUUID, r.FormValue("bootstrap_token")) {
principal, err = s.store.BootstrapOwner(domainUUID, r.FormValue("username"), r.FormValue("password"), r.FormValue("display_name"), r.FormValue("email")) principal, err = s.store.BootstrapOwner(domainUUID, r.FormValue("username"), r.FormValue("password"), r.FormValue("display_name"), r.FormValue("email"))
if err == nil { if err == nil {
@@ -171,7 +176,7 @@ func (s *Server) handleAuth(w http.ResponseWriter, r *http.Request) {
} else if action == "login" && !setup { } else if action == "login" && !setup {
principal, err = s.store.AuthenticatePassword(r.FormValue("username"), r.FormValue("password")) principal, err = s.store.AuthenticatePassword(r.FormValue("username"), r.FormValue("password"))
if err == nil && s.store.HasTOTP(principal.UUID) { if err == nil && s.store.HasTOTP(principal.UUID) {
challenge, challengeErr := s.store.CreateTOTPLoginChallenge(domainUUID, principal.UUID) challenge, challengeErr := s.store.CreateTOTPLoginChallengeForLogin(domainUUID, principal.UUID, remember)
if challengeErr != nil { if challengeErr != nil {
err = challengeErr err = challengeErr
} else if strings.Contains(r.Header.Get("Accept"), "application/json") { } else if strings.Contains(r.Header.Get("Accept"), "application/json") {
@@ -191,7 +196,7 @@ func (s *Server) handleAuth(w http.ResponseWriter, r *http.Request) {
} }
} }
var principalUUID string var principalUUID string
principalUUID, err = s.store.CompleteTOTPLoginChallenge(domainUUID, challenge, r.FormValue("code")) principalUUID, remember, err = s.store.CompleteTOTPLoginChallengeForLogin(domainUUID, challenge, r.FormValue("code"))
if err == nil { if err == nil {
principal = &store.Principal{UUID: principalUUID} principal = &store.Principal{UUID: principalUUID}
mfaLevel = 1 mfaLevel = 1
@@ -201,18 +206,14 @@ func (s *Server) handleAuth(w http.ResponseWriter, r *http.Request) {
err = store.ErrAccessDenied err = store.ErrAccessDenied
} }
if err == nil { if err == nil {
var token string token, lifetime, issueErr := s.store.CreateLoginSession(domainUUID, principal.UUID, mfaLevel, !strings.Contains(r.Header.Get("Accept"), "application/json"), remember)
if strings.Contains(r.Header.Get("Accept"), "application/json") { err = issueErr
token, err = s.store.CreateAuthSessionWithMFA(domainUUID, principal.UUID, mfaLevel)
} else {
token, err = s.store.CreateBrowserAuthSession(domainUUID, principal.UUID, mfaLevel)
}
if err == nil { if err == nil {
if strings.Contains(r.Header.Get("Accept"), "application/json") { if strings.Contains(r.Header.Get("Accept"), "application/json") {
writeEventJSON(w, http.StatusOK, map[string]any{"access_token": token, "token_type": "Bearer", "expires_in": s.store.AuthSessionLifetimeMinutes(domainUUID) * 60}) writeEventJSON(w, http.StatusOK, map[string]any{"access_token": token, "token_type": "Bearer", "expires_in": int(lifetime.Seconds())})
return return
} }
s.setAuthCookie(w, r, token) s.setAuthCookieForSeconds(w, r, token, int(lifetime.Seconds()))
http.Redirect(w, r, safeReturnPath(r.FormValue("return")), http.StatusSeeOther) http.Redirect(w, r, safeReturnPath(r.FormValue("return")), http.StatusSeeOther)
return return
} }
+4 -9
View File
@@ -221,7 +221,7 @@ func (s *Server) handleLDAPLogin(w http.ResponseWriter, r *http.Request) {
return return
} }
if s.store.HasTOTP(principal.UUID) { if s.store.HasTOTP(principal.UUID) {
challenge, challengeErr := s.store.CreateTOTPLoginChallenge(domainUUID, principal.UUID) challenge, challengeErr := s.store.CreateTOTPLoginChallengeForLogin(domainUUID, principal.UUID, r.PostForm.Get("remember") == "1")
if challengeErr != nil { if challengeErr != nil {
http.Error(w, "authentication unavailable", http.StatusServiceUnavailable) http.Error(w, "authentication unavailable", http.StatusServiceUnavailable)
return return
@@ -234,20 +234,15 @@ func (s *Server) handleLDAPLogin(w http.ResponseWriter, r *http.Request) {
s.renderAuthPage(w, r, map[string]any{"MFA": true, "Return": returnPath}) s.renderAuthPage(w, r, map[string]any{"MFA": true, "Return": returnPath})
return return
} }
var token string token, lifetime, err := s.store.CreateLoginSession(domainUUID, principal.UUID, 0, !strings.Contains(r.Header.Get("Accept"), "application/json"), r.PostForm.Get("remember") == "1")
if strings.Contains(r.Header.Get("Accept"), "application/json") {
token, err = s.store.CreateAuthSession(domainUUID, principal.UUID)
} else {
token, err = s.store.CreateBrowserAuthSession(domainUUID, principal.UUID, 0)
}
if err != nil { if err != nil {
http.Error(w, "authentication unavailable", http.StatusServiceUnavailable) http.Error(w, "authentication unavailable", http.StatusServiceUnavailable)
return return
} }
if strings.Contains(r.Header.Get("Accept"), "application/json") { if strings.Contains(r.Header.Get("Accept"), "application/json") {
writeEventJSON(w, http.StatusOK, map[string]any{"access_token": token, "token_type": "Bearer", "expires_in": s.store.AuthSessionLifetimeMinutes(domainUUID) * 60}) writeEventJSON(w, http.StatusOK, map[string]any{"access_token": token, "token_type": "Bearer", "expires_in": int(lifetime.Seconds())})
return return
} }
s.setAuthCookie(w, r, token) s.setAuthCookieForSeconds(w, r, token, int(lifetime.Seconds()))
http.Redirect(w, r, returnPath, http.StatusSeeOther) http.Redirect(w, r, returnPath, http.StatusSeeOther)
} }
@@ -6,6 +6,7 @@ import (
"net/url" "net/url"
"strings" "strings"
"testing" "testing"
"time"
) )
func TestSessionPolicyAdminUIAndCookie(t *testing.T) { func TestSessionPolicyAdminUIAndCookie(t *testing.T) {
@@ -48,3 +49,99 @@ func TestSessionPolicyAdminUIAndCookie(t *testing.T) {
t.Fatalf("cookie policy %#v", cookies) t.Fatalf("cookie policy %#v", cookies)
} }
} }
func TestTrustedSessionPolicyAndRevocation(t *testing.T) {
s, admin, domain := configFixture(t)
p := s.mustCLIPrincipal(t, domain, admin)
for _, days := range []string{"30", "7", "0"} {
form := url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {days}}
w := configRequest(s, admin, "POST", "/-/sys/config/auth", form)
if w.Code != 303 {
t.Fatalf("policy %s: %d %s", days, w.Code, w.Body.String())
}
want := 24 * time.Hour
if days == "30" {
want *= 30
}
if days == "7" {
want *= 7
}
for _, browser := range []bool{false, true} {
token, lifetime, err := s.store.CreateLoginSession(domain, p, 0, browser, true)
if err != nil || lifetime != want {
t.Fatalf("duration %v %v", lifetime, err)
}
if _, err = s.store.PrincipalForSession(domain, token); err != nil {
t.Fatal(err)
}
if err = s.store.RevokeAuthSession(token); err != nil {
t.Fatal(err)
}
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
t.Fatal("revoked trusted session accepted")
}
}
w = httptest.NewRecorder()
s.handleAuth(w, httptest.NewRequest("GET", "https://localhost/_/auth/login", nil))
if strings.Contains(w.Body.String(), `id="auth-remember"`) != (days != "0") {
t.Fatal("login choice does not reflect policy")
}
}
for _, bad := range []string{"", "-1", "31", "abc"} {
w := configRequest(s, admin, "POST", "/-/sys/config/auth", url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {bad}})
if w.Code != 400 {
t.Fatalf("invalid policy %q accepted: %d", bad, w.Code)
}
}
user, err := s.store.CreatePasswordAccount(domain, "trusted-reader", "a long test password", "Reader", "")
if err != nil {
t.Fatal(err)
}
if err = s.store.SetConfigInDomain(domain, "auth_trusted_session_days", "30"); err != nil {
t.Fatal(err)
}
token, _, err := s.store.CreateLoginSession(domain, user.UUID, 0, false, true)
if err != nil {
t.Fatal(err)
}
w := configRequest(s, token, "POST", "/-/sys/config/auth", url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {"7"}})
if w.Code != 403 {
t.Fatalf("reader changed trusted policy: %d", w.Code)
}
if err = s.store.SetPrincipalState(domain, user.UUID, "suspended"); err != nil {
t.Fatal(err)
}
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
t.Fatal("suspended trusted session accepted")
}
}
func TestTrustedSessionExpiryIsFixed(t *testing.T) {
s, admin, domain := configFixture(t)
p := s.mustCLIPrincipal(t, domain, admin)
token, lifetime, err := s.store.CreateLoginSession(domain, p, 0, false, true)
if err != nil || lifetime != 30*24*time.Hour {
t.Fatalf("trusted default: %v %v", lifetime, err)
}
var id string
var expiry int64
if err = s.store.DB.QueryRow(`SELECT uuid,expires_at_ms FROM auth_sessions ORDER BY rowid DESC LIMIT 1`).Scan(&id, &expiry); err != nil {
t.Fatal(err)
}
if err = s.store.SetConfigInDomain(domain, "auth_trusted_session_days", "0"); err != nil {
t.Fatal(err)
}
if _, err = s.store.PrincipalForSession(domain, token); err != nil {
t.Fatal(err)
}
var after int64
if err = s.store.DB.QueryRow(`SELECT expires_at_ms FROM auth_sessions WHERE uuid=?`, id).Scan(&after); err != nil || after != expiry {
t.Fatalf("policy/read changed expiry: %d %d %v", expiry, after, err)
}
if _, err = s.store.DB.Exec(`UPDATE auth_sessions SET expires_at_ms=? WHERE uuid=?`, time.Now().Add(-time.Second).UnixMilli(), id); err != nil {
t.Fatal(err)
}
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
t.Fatal("expired trusted session accepted")
}
}
+12
View File
@@ -0,0 +1,12 @@
package server
func init() {
for lang, entries := range map[string]map[string]string{
"en": {"auth.remember": "Keep me signed in on this trusted device", "auth.days": "days", "auth.remember_cli": "Keep this CLI signed in for up to", "auth.trusted_days": "Trusted device session (days; 0 disables)"},
"ja": {"auth.remember": "信頼できる端末でログインを維持する", "auth.days": "日間", "auth.remember_cli": "CLIのログイン継続期間(最大)", "auth.trusted_days": "信頼できる端末の有効期間(日・0で無効)"},
} {
for key, value := range entries {
translations[lang][key] = value
}
}
}
+88
View File
@@ -0,0 +1,88 @@
package server
import (
"context"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"strings"
"sync/atomic"
"testing"
"time"
)
func TestBrowserUploadQueueChromium(t *testing.T) {
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" {
t.Skip("opt-in Chromium")
}
for _, width := range []string{"1280", "390"} {
t.Run(width, func(t *testing.T) { testBrowserUploadQueueChromium(t, width) })
}
}
func testBrowserUploadQueueChromium(t *testing.T, width string) {
s, token, domain := configFixture(t)
s.mux.HandleFunc("/v/browser/", s.handleBrowser)
s.mux.HandleFunc("/v/upload", s.handleUpload)
object, err := s.store.CreatePageAtPathInDomain(domain, "/drop/existing.txt")
if err != nil {
t.Fatal(err)
}
if _, err = s.store.SaveRevisionContent(object, []byte("original"), "", "und", "text/plain", "existing.txt"); err != nil {
t.Fatal(err)
}
if _, err = s.store.CreatePageAtPathInDomain(domain, "/drop/sub/seed"); err != nil {
t.Fatal(err)
}
script, err := os.ReadFile("internal/server/testdata/browser-upload.js")
if err != nil {
t.Fatal(err)
}
var active, peak atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Host = "localhost"
r.Header.Set("Authorization", "Bearer "+token)
if r.Method == "POST" && r.URL.Path == "/v/upload" {
n := active.Add(1)
defer active.Add(-1)
if n > peak.Load() {
peak.Store(n)
}
time.Sleep(100 * time.Millisecond)
}
if r.URL.Path == "/v/browser/drop" && r.URL.Query().Has("fixture") {
rec := httptest.NewRecorder()
s.withAuthorization(s.mux).ServeHTTP(rec, r)
for key, values := range rec.Header() {
w.Header()[key] = values
}
w.WriteHeader(rec.Code)
w.Write([]byte(strings.Replace(rec.Body.String(), "</body>", "<script>"+string(script)+"</script></body>", 1)))
return
}
s.withAuthorization(s.mux).ServeHTTP(w, r)
}))
defer server.Close()
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
defer cancel()
out, err := exec.CommandContext(ctx, "node", "internal/server/testdata/vim-browser-smoke.mjs", server.URL+"/v/browser/drop?fixture=1", t.TempDir(), "/tmp/pageswiki-browser-upload-"+width+".png", width, "850").CombinedOutput()
if err != nil {
t.Fatalf("browser: %v %s", err, out)
}
if peak.Load() != 1 {
t.Fatalf("parallel uploads: %d", peak.Load())
}
for _, path := range []string{"/drop/日本語 #1.txt", "/drop/sub/nested.txt"} {
if _, err = s.store.ResolvePathInDomain(domain, path); err != nil {
t.Fatal(path, err)
}
}
if _, err = s.store.ResolvePathInDomain(domain, "/drop/cancel.txt"); err == nil {
t.Fatal("cancelled file uploaded")
}
revs, err := s.store.ListRevisions(object)
if err != nil || len(revs) != 1 {
t.Fatal("existing file overwritten")
}
}
+1 -1
View File
@@ -45,7 +45,7 @@ func (s *Server) transpileMarkdownFromPath(r *http.Request, path string, mode ma
html := latest.Body html := latest.Body
if mode == markdownProjection { if mode == markdownProjection {
html = s.expandMacrosForRequest(r, html, path, s.domainUUIDForRequest(r)) html = s.safeHTMLProjection(r, html, path, true)
} else { } else {
return grammaratur.HTMLToMarkdownAuthoring(html) return grammaratur.HTMLToMarkdownAuthoring(html)
} }
+44 -43
View File
@@ -1078,49 +1078,50 @@ func (s *Server) handleConfig(
s.getSystemNavItems(s.domainUUIDForRequest(r)), s.getSystemNavItems(s.domainUUIDForRequest(r)),
NavContext{}, NavContext{},
), ),
"HomePath": homePath, "HomePath": homePath,
"HomeWallpaperPath": homeWallpaperPath, "HomeWallpaperPath": homeWallpaperPath,
"HomeWallpaperOpacity": homeWallpaperOpacity, "HomeWallpaperOpacity": homeWallpaperOpacity,
"HomeGlassTransparency": s.homeGlassTransparency(domainUUID), "HomeGlassTransparency": s.homeGlassTransparency(domainUUID),
"HomePalette": s.homePalette(domainUUID), "HomePalette": s.homePalette(domainUUID),
"HomeLayout": s.homeLayout(s.domainUUIDForRequest(r)), "HomeLayout": s.homeLayout(s.domainUUIDForRequest(r)),
"HomeBookmarks": s.homeBookmarksText(s.domainUUIDForRequest(r)), "HomeBookmarks": s.homeBookmarksText(s.domainUUIDForRequest(r)),
"VirtualFolderPages": s.getVirtualFolderPages(s.domainUUIDForRequest(r)), "VirtualFolderPages": s.getVirtualFolderPages(s.domainUUIDForRequest(r)),
"WikiName": wikiName, "WikiName": wikiName,
"Locale": s.getLocale(s.domainUUIDForRequest(r)), "Locale": s.getLocale(s.domainUUIDForRequest(r)),
"Timezone": s.getTimezoneName(s.domainUUIDForRequest(r)), "Timezone": s.getTimezoneName(s.domainUUIDForRequest(r)),
"Theme": s.getTheme(s.domainUUIDForRequest(r)), "Theme": s.getTheme(s.domainUUIDForRequest(r)),
"ThemeOptions": themeOptions(), "ThemeOptions": themeOptions(),
"EditorKeymap": s.getEditorKeymap(s.domainUUIDForRequest(r)), "EditorKeymap": s.getEditorKeymap(s.domainUUIDForRequest(r)),
"EditorFormat": s.getEditorFormat(s.domainUUIDForRequest(r)), "EditorFormat": s.getEditorFormat(s.domainUUIDForRequest(r)),
"EditorPreviewDefault": s.getEditorPreviewDefault(s.domainUUIDForRequest(r)), "EditorPreviewDefault": s.getEditorPreviewDefault(s.domainUUIDForRequest(r)),
"EditorSyntax": s.getEditorSyntaxHighlight(s.domainUUIDForRequest(r)), "EditorSyntax": s.getEditorSyntaxHighlight(s.domainUUIDForRequest(r)),
"EditorAutocomplete": s.getEditorAutocomplete(s.domainUUIDForRequest(r)), "EditorAutocomplete": s.getEditorAutocomplete(s.domainUUIDForRequest(r)),
"ZombieGraceHours": zombieGraceHours, "ZombieGraceHours": zombieGraceHours,
"Objects": recent, "Objects": recent,
"ZombieObjects": zombies, "ZombieObjects": zombies,
"Domains": domains, "Domains": domains,
"DomainEntries": domainEntries, "DomainEntries": domainEntries,
"PeriodicalProjections": projections, "PeriodicalProjections": projections,
"PeriodicalKinds": []string{"diary", "blog"}, "PeriodicalKinds": []string{"diary", "blog"},
"CampusLegacyPeers": legacyPeers, "CampusLegacyPeers": legacyPeers,
"Campuses": campuses, "Campuses": campuses,
"CampusManaged": campusManaged, "CampusManaged": campusManaged,
"CampusOnline": campusOnline, "CampusOnline": campusOnline,
"FederationInstances": federationInstances, "FederationInstances": federationInstances,
"CampusTokens": campusTokens, "CampusTokens": campusTokens,
"AuthPrincipals": authPrincipals, "AuthPrincipals": authPrincipals,
"AuthSessions": authSessions, "AuthSessions": authSessions,
"AuthSessionMinutes": s.store.AuthSessionLifetimeMinutes(s.domainUUIDForRequest(r)), "AuthSessionMinutes": s.store.AuthSessionLifetimeMinutes(s.domainUUIDForRequest(r)),
"OIDCConfig": oidcConfig, "AuthTrustedSessionDays": s.store.TrustedSessionDays(s.domainUUIDForRequest(r)),
"SMTPConfig": smtpConfig, "OIDCConfig": oidcConfig,
"LDAPConfig": ldapConfig, "SMTPConfig": smtpConfig,
"LDAPTest": r.URL.Query().Get("ldap_test"), "LDAPConfig": ldapConfig,
"ObjectsCampusUUID": selectedCampusUUID, "LDAPTest": r.URL.Query().Get("ldap_test"),
"ObjectsDomainUUID": selectedDomain.UUID, "ObjectsCampusUUID": selectedCampusUUID,
"ObjectsDomainHost": objectsDomainHost, "ObjectsDomainUUID": selectedDomain.UUID,
"HomeNavItemsConfig": s.getHomeNavItems(s.domainUUIDForRequest(r)), "ObjectsDomainHost": objectsDomainHost,
"SystemNavItemsConfig": s.getSystemNavItems(s.domainUUIDForRequest(r)), "HomeNavItemsConfig": s.getHomeNavItems(s.domainUUIDForRequest(r)),
"SystemNavItemsConfig": s.getSystemNavItems(s.domainUUIDForRequest(r)),
}, },
) )
} }
+169
View File
@@ -0,0 +1,169 @@
package server
import (
"encoding/csv"
"errors"
"html"
"io"
"net/http"
"net/url"
"path"
"regexp"
"strconv"
"strings"
"unicode/utf8"
"github.com/google/uuid"
)
// Projection only: no network fetch, shared rendered cache or write-back.
const maxCSVMacroBytes = 256 << 10
var csvMacroRE = regexp.MustCompile(`^\{\{csv:(?:"([^"]+)"|([^\s}]+))(.*?)\}\}$`)
var csvRangeRE = regexp.MustCompile(`^([A-Z]{1,2})([1-9][0-9]{0,3}):([A-Z]{1,2})([1-9][0-9]{0,3})$`)
type csvMacroOptions struct {
Path, Revision string
Row, EndRow, Column, EndColumn int
Header bool
}
func parseCSVMacro(raw string) (csvMacroOptions, error) {
o := csvMacroOptions{Row: 1, EndRow: 200, Column: 1, EndColumn: 32, Header: true}
m := csvMacroRE.FindStringSubmatch(raw)
bad := errors.New("invalid CSV macro")
if m == nil {
return o, bad
}
o.Path = m[1]
if o.Path == "" {
o.Path = m[2]
}
if !strings.HasPrefix(o.Path, "/") || strings.HasPrefix(o.Path, "//") || path.Clean(o.Path) != o.Path || strings.ContainsAny(o.Path, "\\\x00\r\n") || len(o.Path) > 2048 {
return o, bad
}
seen := map[string]bool{}
for _, field := range strings.Fields(m[3]) {
key, value, ok := strings.Cut(field, "=")
if !ok || seen[key] {
return o, bad
}
seen[key] = true
switch key {
case "header":
if value != "true" && value != "false" {
return o, bad
}
o.Header = value == "true"
case "rev":
if _, err := uuid.Parse(value); len(value) != 36 || err != nil {
return o, bad
}
o.Revision = value
case "range":
parts := csvRangeRE.FindStringSubmatch(strings.ToUpper(value))
if parts == nil {
return o, bad
}
col := func(s string) int {
n := 0
for _, c := range s {
n = n*26 + int(c-'A') + 1
}
return n
}
o.Column, o.EndColumn = col(parts[1]), col(parts[3])
o.Row, _ = strconv.Atoi(parts[2])
o.EndRow, _ = strconv.Atoi(parts[4])
if o.Column > o.EndColumn || o.EndColumn > 100 || o.EndColumn-o.Column >= 32 || o.Row > o.EndRow || o.EndRow > 2000 || o.EndRow-o.Row >= 200 {
return o, bad
}
default:
return o, bad
}
}
return o, nil
}
func csvMacroTable(body []byte, o csvMacroOptions) (string, error) {
if len(body) > maxCSVMacroBytes || !utf8.Valid(body) || strings.IndexByte(string(body), 0) >= 0 {
return "", errors.New("invalid CSV input")
}
reader := csv.NewReader(strings.NewReader(strings.TrimPrefix(string(body), "\ufeff")))
reader.FieldsPerRecord = -1
var out strings.Builder
out.WriteString(`<div class="csv-projection table-scroll"><table><caption><a href="` + html.EscapeString((&url.URL{Path: o.Path}).EscapedPath()) + `" title="Revision ` + html.EscapeString(o.Revision) + `">` + html.EscapeString(path.Base(o.Path)) + `</a></caption><tbody>`)
for row := 1; row <= o.EndRow; row++ {
record, err := reader.Read()
if err == io.EOF {
break
}
if err != nil {
return "", err
}
if len(record) > 100 {
return "", errors.New("too many CSV columns")
}
if row < o.Row {
continue
}
out.WriteString("<tr>")
cell := "td"
if o.Header && row == o.Row {
cell = "th"
}
for col := o.Column; col <= o.EndColumn && col <= len(record); col++ {
if len(record[col-1]) > 16<<10 {
return "", errors.New("CSV cell too large")
}
// Never expand macros, formulas or markup from CSV cells.
out.WriteString("<" + cell + ">" + html.EscapeString(record[col-1]) + "</" + cell + ">")
}
out.WriteString("</tr>")
}
out.WriteString("</tbody></table></div>")
return out.String(), nil
}
func (s *Server) expandCSVMacro(r *http.Request, macro string) string {
fallback := `<span class="projection-warning">` + html.EscapeString(translate(s.getLocale(s.domainUUIDForRequest(r)), "viewer.csv_unavailable")) + `</span>`
o, err := parseCSVMacro(macro)
if err != nil || r.Context().Err() != nil || s.store == nil || isAnonymousProjection(r) || !s.pathReadFilter(r)(o.Path) {
return fallback
}
domain := s.domainUUIDForRequest(r)
object, err := s.store.ResolvePathInDomainContext(r.Context(), domain, o.Path)
if err != nil {
return fallback
}
rev, err := s.store.GetLatestRevisionMetadataForLanguagesContext(r.Context(), object, s.revisionLanguageCandidates(r))
if o.Revision != "" {
rev, err = s.store.GetRevisionMetadataContext(r.Context(), o.Revision)
}
if err != nil || rev == nil || rev.UUID == "" || rev.ObjectUUID != object {
return fallback
}
media := strings.ToLower(strings.TrimSpace(strings.Split(rev.ContentType, ";")[0]))
if media != "text/csv" && media != "application/csv" {
return fallback
}
size, err := s.store.DocumentSizeContext(r.Context(), rev.DocumentHash)
if err != nil || size > maxCSVMacroBytes {
return fallback
}
window, err := s.store.ReadDocumentWindowContext(r.Context(), rev.DocumentHash, 0, maxCSVMacroBytes)
if err != nil || window.Truncated {
return fallback
}
o.Revision = rev.UUID
table, err := csvMacroTable(window.Data, o)
if err != nil || r.Context().Err() != nil {
return fallback
}
return table
}
func init() {
translations["en"]["viewer.csv_unavailable"] = "CSV unavailable (access, format or size limit)."
translations["ja"]["viewer.csv_unavailable"] = "CSVを表示できません(権限・形式・サイズ制限)。"
}
+111
View File
@@ -0,0 +1,111 @@
package server
import (
"context"
"net/http/httptest"
"strings"
"testing"
"pageswiki/internal/grammaratur"
)
func TestCSVMacroParsingAndBounds(t *testing.T) {
for _, raw := range []string{`{{csv:/data/a.csv}}`, `{{csv:"/data/日本語 table.csv" range=B2:D4 header=false}}`} {
if _, err := parseCSVMacro(raw); err != nil {
t.Fatal(raw, err)
}
}
for _, raw := range []string{`{{csv:https://example.org/a.csv}}`, `{{csv://evil/a.csv}}`, `{{csv:/a/../secret}}`, `{{csv:/a range=A1:C201}}`, `{{csv:/a range=A1:AG2}}`, `{{csv:/a range=A2001:B2002}}`, `{{csv:/a range=D2:A1}}`, `{{csv:/a header=yes}}`, `{{csv:/a header=true header=false}}`, `{{csv:/a unsupported=1}}`, `{{csv:/a rev=bad}}`} {
if _, err := parseCSVMacro(raw); err == nil {
t.Fatal("accepted", raw)
}
}
o, _ := parseCSVMacro(`{{csv:/data/a.csv range=A1:C3}}`)
body := "\ufeffname,description,formula\r\n日本語,\"a,b\r\nnext\",=1+1\r\n<script>,{{children:/private}},end\r\n"
got, err := csvMacroTable([]byte(body), o)
if err != nil || !strings.Contains(got, "<th>name</th>") || !strings.Contains(got, "a,b\nnext") || !strings.Contains(got, "&lt;script&gt;") || !strings.Contains(got, "{{children:/private}}") {
t.Fatalf("CSV: %s %v", got, err)
}
checkInertProjection(t, got)
for _, bad := range [][]byte{[]byte("a,\"unterminated"), {0xff}, []byte("a,\x00"), []byte(strings.Repeat("x", maxCSVMacroBytes+1)), []byte(strings.Repeat("x", (16<<10)+1)), []byte(strings.Repeat("a,", 101))} {
if _, err := csvMacroTable(bad, o); err == nil {
t.Fatal("invalid/large CSV accepted")
}
}
}
func TestCSVMacroProjectionAuthorizationAndRevision(t *testing.T) {
s, token, domain := configFixture(t)
object, err := s.store.CreatePageAtPathInDomain(domain, "/data/report.csv")
if err != nil {
t.Fatal(err)
}
first, err := s.store.SaveRevisionContent(object, []byte("name,value\r\noriginal,1\r\n"), "", "und", "text/csv", "report.csv")
if err != nil {
t.Fatal(err)
}
r := httptest.NewRequest("GET", "http://localhost/guide", nil)
r.Header.Set("Authorization", "Bearer "+token)
macro := `{{csv:/data/report.csv range=A1:B2}}`
got := s.safeHTMLProjection(r, "<p>"+macro+"</p><code>"+macro+"</code>", "/guide", true)
if strings.Count(got, `class="csv-projection table-scroll"`) != 1 || !strings.Contains(got, "original") || !strings.Contains(got, "<code>"+macro+"</code>") || !strings.Contains(got, first.UUID) {
t.Fatal(got)
}
second, err := s.store.SaveRevisionContent(object, []byte("name,value\nupdated,2\n"), "", "und", "text/csv", "report.csv")
if err != nil {
t.Fatal(err)
}
got = s.safeHTMLProjection(r, macro, "/guide", true)
if !strings.Contains(got, "updated") || !strings.Contains(got, second.UUID) || strings.Contains(got, "original") {
t.Fatal("stale projection", got)
}
got = s.safeHTMLProjection(r, `{{csv:/data/report.csv rev=`+first.UUID+`}}`, "/guide", true)
if !strings.Contains(got, "original") || strings.Contains(got, "updated") {
t.Fatal("pinned revision", got)
}
other, err := s.store.CreatePageAtPathInDomain(domain, "/data/other.csv")
if err != nil {
t.Fatal(err)
}
foreign, err := s.store.SaveRevisionContent(other, []byte("SECRET_DIFFERENT_OBJECT"), "", "und", "text/csv", "other.csv")
if err != nil {
t.Fatal(err)
}
got = s.safeHTMLProjection(r, `{{csv:/data/report.csv rev=`+foreign.UUID+`}}`, "/guide", true)
if strings.Contains(got, "SECRET") || strings.Contains(got, "<table") {
t.Fatal("foreign revision leaked", got)
}
// A fresh request with no credentials must not reuse another reader's table.
denied := httptest.NewRequest("GET", "http://localhost/guide", nil)
got = s.safeHTMLProjection(denied, macro, "/guide", true)
if strings.Contains(got, "updated") || strings.Contains(got, "<table") {
t.Fatal("unauthorized table", got)
}
public := r.WithContext(context.WithValue(r.Context(), anonymousProjectionKey{}, true))
if got = s.safeHTMLProjection(public, macro, "/guide", true); strings.Contains(got, "<table") {
t.Fatal("anonymous CSV expanded", got)
}
ctx, cancel := context.WithCancel(r.Context())
cancel()
if got = s.expandCSVMacro(r.WithContext(ctx), macro); strings.Contains(got, "<table") {
t.Fatal("cancelled projection ran")
}
// Authoring must preserve the macro, never bake projected rows into HTML.
source := "<p>" + macro + "</p>"
md, err := grammaratur.HTMLToMarkdownAuthoring(source)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(grammaratur.MarkdownAuthoringHTML(md), macro) || strings.Contains(md, "updated") {
t.Fatal("authoring expanded CSV", md)
}
// Four distinct CSV reads per projection, then leave authored syntax literal.
input := strings.Repeat(macro, 2)
for _, col := range []string{"A1:A2", "B1:B2", "A1:B1", "A2:B2"} {
input += `{{csv:/data/report.csv range=` + col + `}}`
}
got = s.safeHTMLProjection(r, input, "/guide", true)
if strings.Count(got, "<table>") != 5 || !strings.Contains(got, "{{csv:") {
t.Fatal("CSV budget not enforced", got)
}
}
+3 -2
View File
@@ -17,7 +17,8 @@ func feedRoute(p string) bool { return p == "/v/feeds" || strings.HasPrefix(p, f
func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) { func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "private, no-store") w.Header().Set("Cache-Control", "private, no-store")
domain := s.domainUUIDForRequest(r) domain := s.domainUUIDForRequest(r)
if !s.systemExtensionEnabled(domain, "organizer.feeds") { licenseDownload := strings.HasPrefix(r.URL.Path, geckoAPI+"distribution/v0.0.1/")
if !licenseDownload && !s.systemExtensionEnabled(domain, "organizer.feeds") {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
@@ -61,7 +62,7 @@ func (s *Server) handleFeeds(w http.ResponseWriter, r *http.Request) {
linkMode = "tab" linkMode = "tab"
} }
} }
s.renderWithContext(w, r, "feeds.gohtml", map[string]any{"Title": "RSS", "FeedWritable": active, "FeedWikiPrefix": prefix, "FeedLinkMode": linkMode, "FeedShareX": s.systemExtensionEnabled(domain, "sharing.x")}) s.renderWithContext(w, r, "feeds.gohtml", map[string]any{"Title": "RSS", "FeedTimezone": s.getTimezoneName(domain), "FeedWritable": active, "FeedWikiPrefix": prefix, "FeedLinkMode": linkMode, "FeedShareX": s.systemExtensionEnabled(domain, "sharing.x")})
return return
} }
key := strings.TrimPrefix(r.URL.Path, feedsAPI) key := strings.TrimPrefix(r.URL.Path, feedsAPI)
+9 -5
View File
@@ -48,7 +48,10 @@ func geckoIsolation(w http.ResponseWriter) {
} }
func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domain, actor string, active bool) { func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domain, actor string, active bool) {
if !active || !s.geckoAvailable(domain) { path := strings.TrimPrefix(r.URL.Path, geckoAPI)
// Recipients can still obtain sources after the viewer is disabled.
distribution := strings.HasPrefix(path, strings.TrimPrefix(geckorelay.DistributionPrefix, "/"))
if s.geckoConfig() == nil || (!distribution && (!active || !s.geckoAvailable(domain))) {
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
@@ -56,7 +59,6 @@ func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domai
http.Error(w, "invalid request", 400) http.Error(w, "invalid request", 400)
return return
} }
path := strings.TrimPrefix(r.URL.Path, geckoAPI)
switch path { switch path {
case "": case "":
geckoIsolation(w) geckoIsolation(w)
@@ -73,8 +75,10 @@ func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domai
return return
} }
default: default:
http.NotFound(w, r) if !distribution {
return http.NotFound(w, r)
return
}
} }
cfg := s.geckoConfig() cfg := s.geckoConfig()
ctx, cancel := context.WithCancel(r.Context()) ctx, cancel := context.WithCancel(r.Context())
@@ -129,7 +133,7 @@ func (s *Server) handleFeedBrowser(w http.ResponseWriter, r *http.Request, domai
proxy.ServeHTTP(w, r.WithContext(ctx)) proxy.ServeHTTP(w, r.WithContext(ctx))
} }
const geckoShell = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="/static/css/feed-gecko.css?v=1"><title>Gecko</title></head><body><p id="status" role="status"></p><canvas id="screen" tabindex="0" aria-label="Original article"></canvas><script type="module" src="/static/js/feed-gecko.js?v=1"></script></body></html>` const geckoShell = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="/static/css/feed-gecko.css?v=1"><title>Gecko</title></head><body><p id="status" role="status"></p><canvas id="screen" tabindex="0" aria-label="Original article"></canvas><script type="module" src="/static/js/feed-gecko.js?v=2"></script></body></html>`
func init() { func init() {
translations["en"]["feeds.gecko"] = "Gecko RSS browser (experimental)" translations["en"]["feeds.gecko"] = "Gecko RSS browser (experimental)"
+53 -4
View File
@@ -23,17 +23,44 @@ import (
// The real engine runs against a synthetic Wisp HTTP responder. This test never // The real engine runs against a synthetic Wisp HTTP responder. This test never
// dials an article server, production source, DNS name or external calendar. // dials an article server, production source, DNS name or external calendar.
func TestFeedGeckoChromium(t *testing.T) { func TestFeedGeckoChromium(t *testing.T) {
testFeedGeckoChromium(t, false)
}
func TestFeedGeckoStartupFailureChromium(t *testing.T) {
testFeedGeckoChromium(t, true)
}
func testFeedGeckoChromium(t *testing.T, failure bool) {
assets := os.Getenv("PAGESWIKI_GECKO_TEST_ASSETS") assets := os.Getenv("PAGESWIKI_GECKO_TEST_ASSETS")
if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" || assets == "" { if os.Getenv("PAGESWIKI_BROWSER_TEST") != "1" || assets == "" {
t.Skip("opt-in real Gecko assets") t.Skip("opt-in real Gecko assets")
} }
var connections atomic.Int64 var connections atomic.Int64
publicHTTPS := !failure && os.Getenv("PAGESWIKI_GECKO_PUBLIC_HTTPS_TEST") == "1"
realRelay, err := geckorelay.New(geckoTestKey, assets)
if err != nil {
t.Fatal(err)
}
if publicHTTPS {
realRelay.Distribution, err = geckorelay.VerifyDistribution(assets)
if err != nil {
t.Fatal(err)
}
}
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if failure && strings.HasSuffix(r.URL.Path, "/NotoSansCJKjp-Regular.otf") {
http.Error(w, "synthetic startup failure", 503)
return
}
if publicHTTPS {
realRelay.ServeHTTP(w, r)
return
}
if _, err := geckorelay.Verify(geckoTestKey, r.Header.Get(geckorelay.GrantHeader), time.Now()); err != nil { if _, err := geckorelay.Verify(geckoTestKey, r.Header.Get(geckorelay.GrantHeader), time.Now()); err != nil {
http.Error(w, "bad grant", 403) http.Error(w, "bad grant", 403)
return return
} }
if strings.HasPrefix(r.URL.Path, "/assets/") { if strings.HasPrefix(r.URL.Path, "/assets/") || strings.HasPrefix(r.URL.Path, geckorelay.DistributionPrefix) {
http.ServeFile(w, r, filepath.Join(assets, filepath.Base(r.URL.Path))) http.ServeFile(w, r, filepath.Join(assets, filepath.Base(r.URL.Path)))
return return
} }
@@ -67,7 +94,7 @@ func TestFeedGeckoChromium(t *testing.T) {
if !strings.Contains(requests[id], "\r\n\r\n") { if !strings.Contains(requests[id], "\r\n\r\n") {
continue continue
} }
body := `<!doctype html><body style="margin:0;background:rgb(255,0,0)"><a style="display:block;width:300px;height:100px;background:blue;color:white" href="http://fixture.invalid/next">Synthetic next page</a><h1>Private fixture</h1>` body := `<!doctype html><meta charset="utf-8"><body style="margin:0;background:rgb(255,0,0)"><a style="display:block;width:300px;height:100px;background:blue;color:white" href="http://fixture.invalid/next">Synthetic next page</a><h1>日本語の記事:学舎の園</h1>`
if strings.HasPrefix(requests[id], "GET /next ") { if strings.HasPrefix(requests[id], "GET /next ") {
body = `<!doctype html><body style="margin:0;background:rgb(0,255,0)"><h1>Second synthetic page</h1>` body = `<!doctype html><body style="margin:0;background:rgb(0,255,0)"><h1>Second synthetic page</h1>`
} }
@@ -96,11 +123,26 @@ func TestFeedGeckoChromium(t *testing.T) {
if e != nil { if e != nil {
t.Fatal(e) t.Fatal(e)
} }
if e = s.store.CompleteFeed(context.Background(), claim, []store.FeedItem{{ID: "synthetic", Title: "Gecko synthetic fixture", URL: "http://fixture.invalid/first", Body: "No external network access."}}, "", "", "", false); e != nil { articleURL := "http://fixture.invalid/first"
if publicHTTPS {
articleURL = "https://example.com/"
}
if e = s.store.CompleteFeed(context.Background(), claim, []store.FeedItem{{ID: "synthetic", Title: "Gecko synthetic fixture", URL: articleURL, Body: "Synthetic test fixture."}}, "", "", "", false); e != nil {
t.Fatal(e) t.Fatal(e)
} }
handler := s.handler() handler := s.handler()
web := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { web := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if publicHTTPS && r.URL.Path == "/static/js/feed-gecko.js" {
js, err := os.ReadFile("static/js/feed-gecko.js")
if err != nil {
t.Error(err)
http.Error(w, "fixture missing", 500)
return
}
w.Header().Set("Content-Type", "text/javascript")
io.WriteString(w, strings.Replace(string(js), "engine=new Gecko(", "globalThis.fixtureEngine=engine=new Gecko(", 1))
return
}
if r.Header.Get("Origin") == "http://"+r.Host { if r.Header.Get("Origin") == "http://"+r.Host {
r.Header.Set("Origin", "http://localhost") r.Header.Set("Origin", "http://localhost")
} }
@@ -111,7 +153,14 @@ func TestFeedGeckoChromium(t *testing.T) {
defer web.Close() defer web.Close()
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second)
defer cancel() defer cancel()
out, e := exec.CommandContext(ctx, "node", "internal/server/testdata/feed-gecko-browser.mjs", web.URL+"/v/feeds", t.TempDir(), "/tmp/pageswiki-feed-gecko.png").CombinedOutput() mode := "synthetic"
if failure {
mode = "startup-failure"
}
if publicHTTPS {
mode = "public-https"
}
out, e := exec.CommandContext(ctx, "node", "internal/server/testdata/feed-gecko-browser.mjs", web.URL+"/v/feeds", t.TempDir(), "/tmp/pageswiki-feed-gecko.png", mode).CombinedOutput()
if e != nil { if e != nil {
t.Fatalf("browser: %v\n%s", e, out) t.Fatalf("browser: %v\n%s", e, out)
} }
+16 -1
View File
@@ -57,7 +57,7 @@ func TestFeedGeckoAuthorizationAndHeaders(t *testing.T) {
t.Error("credential/header leaked", h) t.Error("credential/header leaked", h)
} }
} }
if r.URL.Path != "/assets/v0.0.1/gecko.js" { if r.URL.Path != "/assets/v0.0.1/gecko.js" && r.URL.Path != "/distribution/v0.0.1/manifest.json" {
t.Error("path", r.URL.Path) t.Error("path", r.URL.Path)
} }
w.Header().Set("Set-Cookie", "forbidden=1") w.Header().Set("Set-Cookie", "forbidden=1")
@@ -133,6 +133,18 @@ func TestFeedGeckoAuthorizationAndHeaders(t *testing.T) {
if w = feedRequestTest(s, token, "GET", "browser/", nil); w.Code != 404 { if w = feedRequestTest(s, token, "GET", "browser/", nil); w.Code != 404 {
t.Fatal("disabled shell", w.Code) t.Fatal("disabled shell", w.Code)
} }
if err = s.setSystemExtensionEnabled(domain, "organizer.feeds", false); err != nil {
t.Fatal(err)
}
if w = feedRequestTest(s, token, "GET", "browser/distribution/v0.0.1/manifest.json", nil); w.Code != 200 {
t.Fatal("sources lost after disabling extensions", w.Code)
}
if w = feedRequestTest(s, "", "GET", "browser/distribution/v0.0.1/manifest.json", nil); w.Code == 200 {
t.Fatal("anonymous source download")
}
if err = s.setSystemExtensionEnabled(domain, "organizer.feeds", true); err != nil {
t.Fatal(err)
}
if err = s.setSystemExtensionEnabled(domain, "viewer.gecko", true); err != nil { if err = s.setSystemExtensionEnabled(domain, "viewer.gecko", true); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -142,6 +154,9 @@ func TestFeedGeckoAuthorizationAndHeaders(t *testing.T) {
if w = feedRequestTest(s, token, "GET", "browser/", nil); w.Code != 404 { if w = feedRequestTest(s, token, "GET", "browser/", nil); w.Code != 404 {
t.Fatal("readonly browser", w.Code) t.Fatal("readonly browser", w.Code)
} }
if w = feedRequestTest(s, token, "GET", "browser/distribution/v0.0.1/manifest.json", nil); w.Code != 200 {
t.Fatal("readonly recipient lost source access", w.Code)
}
} }
func TestFeedGeckoWebsocketRevocation(t *testing.T) { func TestFeedGeckoWebsocketRevocation(t *testing.T) {
+3
View File
@@ -531,6 +531,9 @@ func TestFeedsChromium(t *testing.T) {
t.Skip("opt-in Chromium") t.Skip("opt-in Chromium")
} }
s, token, domain, actor, source := feedFixture(t) s, token, domain, actor, source := feedFixture(t)
if err := s.store.SetConfigInDomain(domain, "timezone", "Asia/Tokyo"); err != nil {
t.Fatal(err)
}
prefs, err := s.store.TaskPreferences(context.Background(), domain, actor) prefs, err := s.store.TaskPreferences(context.Background(), domain, actor)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
+15 -2
View File
@@ -20,11 +20,11 @@ import (
"golang.org/x/net/html/atom" "golang.org/x/net/html/atom"
) )
const htmlProjectionVersion = "controlled-v2" const htmlProjectionVersion = "controlled-v3"
const maxProjectionInput = 1 << 20 const maxProjectionInput = 1 << 20
const maxProjectionOutput = 4 << 20 const maxProjectionOutput = 4 << 20
var projectionMacroRE = regexp.MustCompile(`\{\{(?:children[^}]*|(?:city-breadcrumbs|spot-pages|quartier|street|spot|nearby|city)(?:\s+[^}]*)?)\}\}`) var projectionMacroRE = regexp.MustCompile(`\{\{(?:csv:[^}]*|children[^}]*|(?:city-breadcrumbs|spot-pages|quartier|street|spot|nearby|city)(?:\s+[^}]*)?)\}\}`)
var languageClassRE = regexp.MustCompile(`^language-[a-zA-Z0-9_+-]{1,40}$`) var languageClassRE = regexp.MustCompile(`^language-[a-zA-Z0-9_+-]{1,40}$`)
func projectionPolicy(generated bool) *bluemonday.Policy { func projectionPolicy(generated bool) *bluemonday.Policy {
@@ -199,6 +199,8 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
} }
var output strings.Builder var output strings.Builder
macros, count := 0, 0 macros, count := 0, 0
csvCount := 0
csvResults := map[string]string{}
var emit func(*html.Node, int, bool) bool var emit func(*html.Node, int, bool) bool
emit = func(n *html.Node, depth int, literal bool) bool { emit = func(n *html.Node, depth int, literal bool) bool {
count++ count++
@@ -226,6 +228,14 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
// be reparsed as a nested children request on its raw text. // be reparsed as a nested children request on its raw text.
if isAnonymousProjection(r) { if isAnonymousProjection(r) {
expanded = s.expandPublicMacro(r, macro, path) expanded = s.expandPublicMacro(r, macro, path)
} else if strings.HasPrefix(macro, "{{csv:") {
if cached, ok := csvResults[macro]; ok {
expanded = cached
} else if csvCount < 4 {
csvCount++
expanded = s.expandCSVMacro(r, macro)
csvResults[macro] = expanded
}
} else if strings.HasPrefix(macro, "{{children") { } else if strings.HasPrefix(macro, "{{children") {
expanded = s.expandChildrenMacros(macro, path) expanded = s.expandChildrenMacros(macro, path)
} else { } else {
@@ -236,6 +246,9 @@ func (s *Server) safeHTMLProjection(r *http.Request, body, path string, expand b
// promote decoded entities into trusted generated elements. // promote decoded entities into trusted generated elements.
output.WriteString(stdhtml.EscapeString(macro)) output.WriteString(stdhtml.EscapeString(macro))
} else { } else {
if output.Len()+len(expanded) > maxProjectionOutput {
return false
}
output.WriteString(expanded) output.WriteString(expanded)
} }
at = loc[1] at = loc[1]
+3 -2
View File
@@ -36,8 +36,9 @@ func (c *smtpLimitedConn) Read(buffer []byte) (int, error) {
} }
type magicLinkChallenge struct { type magicLinkChallenge struct {
Return string `json:"return"` Return string `json:"return"`
Email string `json:"email"` Email string `json:"email"`
Remember bool `json:"remember,omitempty"`
} }
func smtpMailbox(value string) (*mail.Address, error) { func smtpMailbox(value string) (*mail.Address, error) {
@@ -0,0 +1,226 @@
package server
import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
"testing"
"github.com/google/uuid"
"pageswiki/internal/store"
)
func TestTaskCaptureDeletedRecreation(t *testing.T) {
for _, wiki := range []bool{false, true} {
t.Run(fmt.Sprint(wiki), func(t *testing.T) {
s, token, domain, actor := taskFixture(t)
ctx := context.Background()
id := uuid.NewString()
input := map[string]any{"request_id": id, "title": "Original"}
if wiki {
input["wiki_body"], input["wiki_prefix"] = "Original private body", "/mail"
}
w := taskRequest(s, token, "POST", "capture", input, "")
if w.Code != 201 {
t.Fatal(w.Code, w.Body)
}
var result struct {
Item store.TaskRecord `json:"item"`
Path string `json:"page_path"`
}
if err := json.Unmarshal(w.Body.Bytes(), &result); err != nil {
t.Fatal(err)
}
page, path := result.Item.PageUUID, result.Path
var revision string
if wiki {
r, err := s.store.GetLatestRevision(page)
if err != nil {
t.Fatal(err)
}
revision = r.UUID
}
if w = taskRequest(s, token, "DELETE", "items/"+id, nil, `"1"`); w.Code != 204 {
t.Fatal(w.Code, w.Body)
}
if w = taskRequest(s, token, "GET", "items/"+id, nil, ""); w.Code != 404 {
t.Fatal(w.Code, w.Body)
}
for _, title := range []string{"Original", "Changed"} {
input["title"] = title
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 410 || !strings.Contains(w.Body.String(), `"deleted"`) {
t.Fatal(w.Code, w.Body)
}
}
input["replaces_deleted"], input["request_id"] = id, store.TaskRecreationID(id)
if wiki {
input["wiki_body"] = "Must not overwrite the retained page"
for _, invalidBody := range []string{"bad\x00body", strings.Repeat("x", 256<<10+1)} {
input["wiki_body"] = invalidBody
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 422 {
t.Fatal("reused page bypassed body validation", w.Code, w.Body)
}
}
input["wiki_body"] = "Must not overwrite the retained page"
}
// A lost successful response, including concurrent retries, creates one
// successor. It neither revives the original nor revises the Wiki.
var wg sync.WaitGroup
for i := 0; i < 4; i++ {
wg.Add(1)
go func() {
defer wg.Done()
v := taskRequest(s, token, "POST", "capture", input, "")
if v.Code != 201 {
t.Errorf("concurrent recreation: %d %s", v.Code, v.Body)
}
}()
}
wg.Wait()
w = taskRequest(s, token, "POST", "capture", input, "")
if w.Code != 201 {
t.Fatal(w.Code, w.Body)
}
if err := json.Unmarshal(w.Body.Bytes(), &result); err != nil {
t.Fatal(err)
}
if result.Item.UUID != store.TaskRecreationID(id) || result.Item.UUID == id || result.Item.Title != "Changed" || result.Item.Version != 1 || result.Item.PageUUID != page || result.Path != path {
t.Fatal(result)
}
if wiki {
r, err := s.store.GetLatestRevision(page)
if err != nil || r.UUID != revision || !strings.Contains(r.Body, "Original private body") {
t.Fatal("Wiki changed", r, err)
}
}
for table, expected := range map[string]int{"organizer_items": 1, "organizer_capture_receipts": 2, "organizer_task_deletions": 1, "organizer_revisions": 1} {
var count int
if err := s.store.DB.QueryRow("SELECT count(*) FROM " + table).Scan(&count); err != nil || count != expected {
t.Fatal(table, count, err)
}
}
if _, err := s.store.SaveTask(ctx, domain, actor, store.TaskRecord{UUID: id, Kind: "task", Title: "Offline resurrection", Status: "todo", Bucket: "inbox", Priority: 1}, 0); err != store.ErrTaskDeleted {
t.Fatal("old UUID revived", err)
}
input["title"] = "Different committed recovery"
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 412 {
t.Fatal(w.Code, w.Body)
}
// Deleting the successor cannot be undone by replaying the recovery.
if w = taskRequest(s, token, "DELETE", "items/"+result.Item.UUID, nil, `"1"`); w.Code != 204 {
t.Fatal(w.Code, w.Body)
}
if w = taskRequest(s, token, "POST", "capture", input, ""); w.Code != 410 {
t.Fatal(w.Code, w.Body)
}
})
}
}
func TestTaskCaptureRecreationGuards(t *testing.T) {
s, token, domain, actor := taskFixture(t)
id := uuid.NewString()
input := map[string]any{"request_id": id, "title": "Original"}
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 {
t.Fatal(w.Code, w.Body)
}
recreate := map[string]any{"request_id": store.TaskRecreationID(id), "replaces_deleted": id, "title": "New"}
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 412 {
t.Fatal("live capture replaced", w.Code, w.Body)
}
if w := taskRequest(s, token, "DELETE", "items/"+id, nil, `"1"`); w.Code != 204 {
t.Fatal(w.Code, w.Body)
}
other, err := s.store.CreatePasswordAccount(domain, "recreateother", "long fixture password", "Other", "")
if err != nil {
t.Fatal(err)
}
otherToken, err := s.store.CreateAuthSession(domain, other.UUID)
if err != nil {
t.Fatal(err)
}
if w := taskRequest(s, otherToken, "POST", "capture", recreate, ""); w.Code != 404 {
t.Fatal("other owner", w.Code, w.Body)
}
if _, err := s.store.RecreateCapturedTask(context.Background(), "other-domain", actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Wrong domain"), "", "", id); err != store.ErrAccessDenied {
t.Fatal("wrong domain", err)
}
if err := s.store.SetPrincipalState(domain, actor, "readonly"); err != nil {
t.Fatal(err)
}
if _, err := s.store.RecreateCapturedTask(context.Background(), domain, actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Readonly"), "", "", id); err != store.ErrAccessDenied {
t.Fatal("readonly", err)
}
if err := s.store.SetPrincipalState(domain, actor, "active"); err != nil {
t.Fatal(err)
}
token, err = s.store.CreateAuthSession(domain, actor)
if err != nil {
t.Fatal(err)
}
if err := s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":false}`); err != nil {
t.Fatal(err)
}
if _, err := s.store.RecreateCapturedTask(context.Background(), domain, actor, store.TaskRecreationID(id), "hash", newTaskRecord("task", "Disabled"), "", "", id); err != store.ErrAccessDenied {
t.Fatal("extension disabled", err)
}
if err := s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":true}`); err != nil {
t.Fatal(err)
}
for _, invalid := range []string{uuid.NewString(), id, "not-an-id"} {
recreate["request_id"] = invalid
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 422 {
t.Fatal("arbitrary recovery ID", w.Code, w.Body)
}
}
recreate["request_id"] = store.TaskRecreationID(id)
// Failure during receipt insertion rolls back the task, page and journals.
if _, err := s.store.DB.Exec(`CREATE TRIGGER reject_recreation BEFORE INSERT ON organizer_capture_receipts BEGIN SELECT RAISE(ABORT,'fixture rejection'); END`); err != nil {
t.Fatal(err)
}
recreate["wiki_body"], recreate["wiki_prefix"] = "New body", "/recreated"
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 500 {
t.Fatal(w.Code, w.Body)
}
var count int
if err := s.store.DB.QueryRow(`SELECT count(*) FROM organizer_items`).Scan(&count); err != nil || count != 0 {
t.Fatal("orphan task", count, err)
}
if err := s.store.DB.QueryRow(`SELECT count(*) FROM paths WHERE path LIKE '/recreated/%'`).Scan(&count); err != nil || count != 0 {
t.Fatal("orphan page", count, err)
}
if _, err := s.store.DB.Exec(`DROP TRIGGER reject_recreation`); err != nil {
t.Fatal(err)
}
if w := taskRequest(s, token, "POST", "capture", recreate, ""); w.Code != 201 {
t.Fatal(w.Code, w.Body)
}
if _, err := s.store.GetTask(context.Background(), domain, actor, store.TaskRecreationID(id)); err != nil {
t.Fatal(err)
}
}
func TestTaskCaptureOrphanReceipt(t *testing.T) {
s, token, domain, actor := taskFixture(t)
id := uuid.NewString()
input := map[string]any{"request_id": id, "title": "Original"}
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 201 {
t.Fatal(w.Code, w.Body)
}
// Simulate preexisting corruption, not a supported user deletion operation.
if _, err := s.store.DB.Exec(`DELETE FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=?`, domain, actor, id); err != nil {
t.Fatal(err)
}
for _, title := range []string{"Original", "Changed"} {
input["title"] = title
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 409 || !strings.Contains(w.Body.String(), "capture_missing") {
t.Fatal(w.Code, w.Body)
}
}
input["request_id"], input["replaces_deleted"] = store.TaskRecreationID(id), id
if w := taskRequest(s, token, "POST", "capture", input, ""); w.Code != 409 || !strings.Contains(w.Body.String(), "capture_missing") {
t.Fatal(w.Code, w.Body)
}
}
+272
View File
@@ -0,0 +1,272 @@
package server
import (
"context"
"database/sql"
"errors"
"strconv"
"strings"
"testing"
"time"
"github.com/google/uuid"
"pageswiki/internal/store"
)
func TestTaskDeleteAPIAndDAVTombstone(t *testing.T) {
s, token, domain, actor := taskFixture(t)
ctx := context.Background()
page, err := s.store.CreatePageAtPathInDomain(domain, "/delete-fixture-note")
if err != nil {
t.Fatal(err)
}
task := newTaskRecord("task", "Delete fixture")
task.PageUUID = page
task.NotifyDue, task.DueOn = true, "2099-01-01"
task, err = s.store.SaveTask(ctx, domain, actor, task, 0)
if err != nil {
t.Fatal(err)
}
url := "items/" + task.UUID
for _, test := range []struct {
tag string
status int
}{{"", 428}, {`W/"1"`, 422}, {`"2"`, 412}} {
w := taskRequest(s, token, "DELETE", url, nil, test.tag)
if w.Code != test.status {
t.Fatalf("precondition %s: %d %s", test.tag, w.Code, w.Body)
}
}
for i := 0; i < 2; i++ {
w := taskRequest(s, token, "DELETE", url, nil, `"1"`)
if w.Code != 204 {
t.Fatalf("delete/retry: %d %s", w.Code, w.Body)
}
}
for _, suffix := range []string{url, url + "/history"} {
if w := taskRequest(s, token, "GET", suffix, nil, ""); w.Code != 404 {
t.Fatalf("deleted read: %d %s", w.Code, w.Body)
}
}
for _, view := range []string{"all", "archived", "done", "today"} {
w := taskRequest(s, token, "GET", "items?view="+view, nil, "")
if w.Code != 200 || strings.Contains(w.Body.String(), task.UUID) {
t.Fatalf("deleted list %s: %d %s", view, w.Code, w.Body)
}
}
for _, table := range []string{"organizer_items", "organizer_revisions", "organizer_reminders", "organizer_task_metrics"} {
var count int
if err := s.store.DB.QueryRow(`SELECT count(*) FROM ` + table).Scan(&count); err != nil || count != 0 {
t.Fatalf("cleanup %s: %d %v", table, count, err)
}
}
if id, err := s.store.ResolvePathInDomain(domain, "/delete-fixture-note"); err != nil || id != page {
t.Fatal("Wiki note removed", id, err)
}
if _, err := s.store.SaveTask(ctx, domain, actor, task, 0); !errors.Is(err, store.ErrTaskDeleted) {
t.Fatal("UUID recreated", err)
}
if _, _, err := s.store.PublishTaskActivity(ctx, 100); err != nil {
t.Fatal("deleted head stalled outbox bridge", err)
}
for _, project := range []string{"", uuid.NewString()} {
if project != "" {
p := newTaskRecord("project", "Delete project fixture")
p.UUID = project
if _, err := s.store.SaveTask(ctx, domain, actor, p, 0); err != nil {
t.Fatal(err)
}
}
davTask := newTaskRecord("task", "DAV fixture")
davTask.ProjectUUID = project
data := &store.TaskDAVData{Name: "client-fixture.ics", UID: "client-fixture-uid", Data: "fixture"}
davTask, err = s.store.SaveTaskDAV(ctx, domain, actor, davTask, 0, data, "", project)
if err != nil {
t.Fatal(err)
}
if err = s.store.DeleteTask(ctx, domain, actor, davTask.UUID, davTask.Version); err != nil {
t.Fatal(err)
}
// Simulate reopening/rebuilding the derived DAV indexes.
if err = s.store.EnsureTasksSchema(); err != nil {
t.Fatal(err)
}
if _, err = s.store.TaskDAVByName(ctx, domain, actor, data.Name, project); !errors.Is(err, sql.ErrNoRows) {
t.Fatal("DAV deleted resource exposed", err)
}
items, err := s.store.TaskDAVList(ctx, domain, actor, project)
if err != nil || len(items) != 0 {
t.Fatal("DAV deleted resource listed", items, err)
}
for _, altered := range []string{"neither", "name", "uid"} {
candidate := newTaskRecord("task", "Stale client PUT")
candidate.ProjectUUID = project
d := *data
if altered == "name" {
d.Name = "other.ics"
}
if altered == "uid" {
d.UID = "other-uid"
}
if _, err := s.store.SaveTaskDAV(ctx, domain, actor, candidate, 0, &d, "", project); !errors.Is(err, store.ErrTaskDAVIdentity) {
t.Fatalf("resurrection %s: %v", altered, err)
}
}
}
}
func TestTaskDeleteGuardsAndAtomicity(t *testing.T) {
s, token, domain, actor := taskFixture(t)
ctx := context.Background()
task, err := s.store.SaveTask(ctx, domain, actor, newTaskRecord("task", "Guarded fixture"), 0)
if err != nil {
t.Fatal(err)
}
other, err := s.store.CreatePasswordAccount(domain, "deleteother", "long fixture password", "Other", "")
if err != nil {
t.Fatal(err)
}
if err := s.store.DeleteTask(ctx, domain, other.UUID, task.UUID, 1); !errors.Is(err, sql.ErrNoRows) {
t.Fatal("ownership", err)
}
if err := s.store.DeleteTask(ctx, "other-domain", actor, task.UUID, 1); !errors.Is(err, store.ErrAccessDenied) {
t.Fatal("domain", err)
}
if err := s.store.SetPrincipalState(domain, actor, "readonly"); err != nil {
t.Fatal(err)
}
if w := taskRequest(s, token, "DELETE", "items/"+task.UUID, nil, `"1"`); w.Code != 401 {
t.Fatal("readonly", w.Code, w.Body)
}
if err := s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); !errors.Is(err, store.ErrAccessDenied) {
t.Fatal("readonly store", err)
}
if err := s.store.SetPrincipalState(domain, actor, "active"); err != nil {
t.Fatal(err)
}
token, err = s.store.CreateAuthSession(domain, actor)
if err != nil {
t.Fatal(err)
}
if err := s.store.SetConfigInDomain(domain, "system_extension_states", `{"organizer.tasks":false}`); err != nil {
t.Fatal(err)
}
if err := s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); !errors.Is(err, store.ErrAccessDenied) {
t.Fatal("disabled", err)
}
if _, err := s.store.DB.Exec(`DELETE FROM config WHERE domain_uuid=? AND key='system_extension_states'`, domain); err != nil {
t.Fatal(err)
}
child := newTaskRecord("task", "Archived child")
child.ParentUUID = task.UUID
child.Archived = true
child, err = s.store.SaveTask(ctx, domain, actor, child, 0)
if err != nil {
t.Fatal(err)
}
if w := taskRequest(s, token, "DELETE", "items/"+task.UUID, nil, `"1"`); w.Code != 409 || !strings.Contains(w.Body.String(), "has_children") {
t.Fatal("children", w.Code, w.Body)
}
if err = s.store.DeleteTask(ctx, domain, actor, child.UUID, child.Version); err != nil {
t.Fatal(err)
}
focus, err := s.store.ChangeTaskFocus(ctx, domain, actor, "start", store.TaskFocus{UUID: uuid.NewString(), TaskUUID: task.UUID, Phase: "focus", DurationMS: 25 * 60 * 1000}, 0, time.Now())
if err != nil {
t.Fatal(err)
}
if err = s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); !errors.Is(err, store.ErrTaskWorking) {
t.Fatal("focus", err)
}
if _, err = s.store.ChangeTaskFocus(ctx, domain, actor, "cancel", focus, focus.Version, time.Now()); err != nil {
t.Fatal(err)
}
work, err := s.store.ChangeTaskWork(ctx, domain, actor, "start", store.TaskWork{UUID: uuid.NewString(), TaskUUID: task.UUID}, time.Now())
if err != nil {
t.Fatal(err)
}
if err = s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); !errors.Is(err, store.ErrTaskWorking) {
t.Fatal("running work", err)
}
if _, err = s.store.ChangeTaskWork(ctx, domain, actor, "stop", work, time.Now()); err != nil {
t.Fatal(err)
}
// Abort at the last delete step: neither a tombstone nor partial cleanup may remain.
if _, err = s.store.DB.Exec(`CREATE TRIGGER fail_fixture_delete BEFORE DELETE ON organizer_items BEGIN SELECT RAISE(ABORT,'fixture failure'); END`); err != nil {
t.Fatal(err)
}
if err = s.store.DeleteTask(ctx, domain, actor, task.UUID, 1); err == nil {
t.Fatal("injected failure ignored")
}
if _, err = s.store.GetTask(ctx, domain, actor, task.UUID); err != nil {
t.Fatal("head not rolled back", err)
}
var n int
if err = s.store.DB.QueryRow(`SELECT count(*) FROM organizer_task_deletions WHERE item_uuid=?`, task.UUID).Scan(&n); err != nil || n != 0 {
t.Fatal("partial tombstone", n, err)
}
if _, err = s.store.DB.Exec(`DROP TRIGGER fail_fixture_delete`); err != nil {
t.Fatal(err)
}
task.Archived = true
task, err = s.store.SaveTask(ctx, domain, actor, task, 1)
if err != nil {
t.Fatal(err)
}
if w := taskRequest(s, token, "DELETE", "items/"+task.UUID, nil, `"`+strconv.FormatInt(task.Version, 10)+`"`); w.Code != 204 {
t.Fatal("archived deletion", w.Code, w.Body)
}
if err := s.store.DeleteTask(ctx, domain, other.UUID, task.UUID, task.Version); !errors.Is(err, sql.ErrNoRows) {
t.Fatal("tombstone ownership", err)
}
if _, err := s.store.SaveTask(ctx, domain, other.UUID, task, 0); !errors.Is(err, sql.ErrNoRows) {
t.Fatal("tombstone creation privacy", err)
}
if err := s.store.DB.QueryRow(`SELECT count(*) FROM organizer_work_sessions WHERE uuid=? AND end_ms>0`, work.UUID).Scan(&n); err != nil || n != 1 {
t.Fatal("work history removed", n, err)
}
project, err := s.store.SaveTask(ctx, domain, actor, newTaskRecord("project", "Keep project"), 0)
if err != nil {
t.Fatal(err)
}
if err = s.store.DeleteTask(ctx, domain, actor, project.UUID, 1); !errors.Is(err, store.ErrTaskInvalid) {
t.Fatal("project unexpectedly deleted", err)
}
}
func TestTaskDeleteDAVHTTP(t *testing.T) {
s, token, domain, actor := taskFixture(t)
ctx := context.Background()
auth, name := "Bearer "+token, "delete-client.ics"
url := taskDAVCollection + name
if w := davTaskRequest(s, auth, "PUT", url, taskICALFixture, nil); w.Code != 201 {
t.Fatal(w.Code, w.Body)
}
item, err := s.store.TaskDAVByName(ctx, domain, actor, name)
if err != nil {
t.Fatal(err)
}
before := davTaskRequest(s, auth, "GET", url, "", nil)
if before.Code != 200 {
t.Fatal(before.Code, before.Body)
}
if err = s.store.DeleteTask(ctx, domain, actor, item.UUID, item.Version); err != nil {
t.Fatal(err)
}
if w := davTaskRequest(s, auth, "GET", url, "", nil); w.Code != 404 {
t.Fatal(w.Code, w.Body)
}
query := `<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"><d:prop><d:getetag/><c:calendar-data/></d:prop><c:filter><c:comp-filter name="VCALENDAR"><c:comp-filter name="VTODO"/></c:comp-filter></c:filter></c:calendar-query>`
if w := davTaskRequest(s, auth, "REPORT", taskDAVCollection, query, nil); w.Code != 207 || strings.Contains(w.Body.String(), name) {
t.Fatal("query", w.Code, w.Body)
}
multi := `<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"><d:prop><d:getetag/><c:calendar-data/></d:prop><d:href>` + url + `</d:href></c:calendar-multiget>`
if w := davTaskRequest(s, auth, "REPORT", taskDAVCollection, multi, nil); w.Code != 207 || !strings.Contains(w.Body.String(), "404 Not Found") {
t.Fatal("multiget", w.Code, w.Body)
}
if w := davTaskRequest(s, auth, "PUT", url, taskICALFixture, map[string]string{"If-Match": before.Header().Get("ETag")}); w.Code != 412 {
t.Fatal("stale conditional PUT", w.Code, w.Body)
}
if w := davTaskRequest(s, auth, "PUT", url, taskICALFixture, nil); w.Code != 403 || !strings.Contains(w.Body.String(), "no-uid-conflict") {
t.Fatal("stale unconditional PUT", w.Code, w.Body)
}
}
+32 -16
View File
@@ -56,20 +56,21 @@ func applyTaskReminderDefaults(item *store.TaskRecord, p store.TaskPreferences)
} }
type taskCaptureInput struct { type taskCaptureInput struct {
RequestID string `json:"request_id"` ReplacesDeleted string `json:"replaces_deleted,omitempty"`
Title string `json:"title"` RequestID string `json:"request_id"`
Notes string `json:"notes"` Title string `json:"title"`
ProjectUUID *string `json:"project_uuid"` Notes string `json:"notes"`
AssigneeUUID *string `json:"assignee_uuid"` ProjectUUID *string `json:"project_uuid"`
DueOn *string `json:"due_on"` AssigneeUUID *string `json:"assignee_uuid"`
StartOn *string `json:"start_on"` DueOn *string `json:"due_on"`
PlannedOn *string `json:"planned_on"` StartOn *string `json:"start_on"`
ReviewOn *string `json:"review_on"` PlannedOn *string `json:"planned_on"`
Estimate *int `json:"estimate_minutes"` ReviewOn *string `json:"review_on"`
Complexity *int `json:"complexity"` Estimate *int `json:"estimate_minutes"`
WikiBody *string `json:"wiki_body,omitempty"` Complexity *int `json:"complexity"`
WikiPrefix *string `json:"wiki_prefix,omitempty"` WikiBody *string `json:"wiki_body,omitempty"`
WikiSuffix *string `json:"wiki_suffix,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) { func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request, actor string, active bool, kind string) {
@@ -197,6 +198,13 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
taskError(w, store.ErrTaskInvalid) taskError(w, store.ErrTaskInvalid)
return return
} }
if input.ReplacesDeleted != "" {
id, err := uuid.Parse(input.ReplacesDeleted)
if err != nil || id.String() != input.ReplacesDeleted || input.RequestID != store.TaskRecreationID(input.ReplacesDeleted) {
taskError(w, store.ErrTaskInvalid)
return
}
}
raw, _ := json.Marshal(input) raw, _ := json.Marshal(input)
hash := sha256.Sum256(raw) hash := sha256.Sum256(raw)
requestHash := hex.EncodeToString(hash[:]) requestHash := hex.EncodeToString(hash[:])
@@ -261,7 +269,11 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
taskError(w, store.ErrTaskInvalid) taskError(w, store.ErrTaskInvalid)
return return
} }
target = store.TaskCaptureWikiPath(prefix, item.Title, input.RequestID) pathID := input.RequestID
if input.ReplacesDeleted != "" {
pathID = input.ReplacesDeleted
}
target = store.TaskCaptureWikiPath(prefix, item.Title, pathID)
if input.WikiSuffix != nil { if input.WikiSuffix != nil {
if !store.ValidTaskMailSuffix(*input.WikiSuffix) { if !store.ValidTaskMailSuffix(*input.WikiSuffix) {
taskError(w, store.ErrTaskInvalid) taskError(w, store.ErrTaskInvalid)
@@ -280,7 +292,11 @@ func (s *Server) handleTaskProductivity(w http.ResponseWriter, r *http.Request,
taskError(w, store.ErrTaskInvalid) taskError(w, store.ErrTaskInvalid)
return return
} }
item, err = s.store.CaptureTaskWithWiki(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body) if input.ReplacesDeleted != "" {
item, err = s.store.RecreateCapturedTask(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body, input.ReplacesDeleted)
} else {
item, err = s.store.CaptureTaskWithWiki(r.Context(), domain, actor, input.RequestID, requestHash, item, target, body)
}
if err != nil { if err != nil {
taskError(w, err) taskError(w, err)
return return
+31 -1
View File
@@ -62,6 +62,14 @@ func taskError(w http.ResponseWriter, err error) {
status, code = 422, "invalid" status, code = 422, "invalid"
case errors.Is(err, store.ErrTaskConflict): case errors.Is(err, store.ErrTaskConflict):
status, code = 412, "conflict" status, code = 412, "conflict"
case errors.Is(err, store.ErrTaskCaptureMissing):
status, code = 409, "capture_missing"
case errors.Is(err, store.ErrTaskDeleted):
status, code = 410, "deleted"
case errors.Is(err, store.ErrTaskHasChildren):
status, code = 409, "has_children"
case errors.Is(err, store.ErrTaskWorking):
status, code = 409, "working"
case errors.Is(err, store.ErrTaskDAVIdentity): case errors.Is(err, store.ErrTaskDAVIdentity):
status, code = 409, "uid_conflict" status, code = 409, "uid_conflict"
case errors.Is(err, store.ErrTaskDAVRelocated): case errors.Is(err, store.ErrTaskDAVRelocated):
@@ -323,8 +331,30 @@ func (s *Server) handleTasksAPI(w http.ResponseWriter, r *http.Request) {
writeEventJSON(w, 200, map[string]any{"items": items, "parents": parents, "next": next, "today": today}) writeEventJSON(w, 200, map[string]any{"items": items, "parents": parents, "next": next, "today": today})
return return
} }
if r.Method == "DELETE" && id != "" {
if !active {
taskError(w, store.ErrAccessDenied)
return
}
tag := r.Header.Get("If-Match")
if tag == "" {
writeEventJSON(w, 428, map[string]string{"error": "precondition"})
return
}
expected, _ := strconv.ParseInt(strings.Trim(tag, `"`), 10, 64)
if expected < 1 || tag != `"`+strconv.FormatInt(expected, 10)+`"` {
taskError(w, store.ErrTaskInvalid)
return
}
if err := s.store.DeleteTask(ctx, domain, actor, id, expected); err != nil {
taskError(w, err)
return
}
w.WriteHeader(http.StatusNoContent)
return
}
if (r.Method != "POST" || id != "") && (r.Method != "PUT" || id == "") { if (r.Method != "POST" || id != "") && (r.Method != "PUT" || id == "") {
w.Header().Set("Allow", "GET, POST, PUT") w.Header().Set("Allow", "GET, POST, PUT, DELETE")
w.WriteHeader(405) w.WriteHeader(405)
return return
} }
+4
View File
@@ -4,6 +4,10 @@
if (phase === 'login') { if (phase === 'login') {
const form = document.querySelector('form[action="/_/auth/login"]') const form = document.querySelector('form[action="/_/auth/login"]')
assert(form, 'Login form missing') assert(form, 'Login form missing')
const remember = form.elements.remember
assert(remember && !remember.checked, 'Trusted login must be opt-in')
remember.checked = true
remember.dispatchEvent(new Event('change', { bubbles: true }))
form.elements.username.value = 'admin' form.elements.username.value = 'admin'
form.elements.password.value = 'a long test password' form.elements.password.value = 'a long test password'
sessionStorage.setItem('auth-flow-phase', 'authenticated') sessionStorage.setItem('auth-flow-phase', 'authenticated')
+17
View File
@@ -0,0 +1,17 @@
(async()=>{
const wait=async fn=>{for(let i=0;i<200;i++){if(fn())return;await new Promise(r=>setTimeout(r,30));}throw Error('Timeout '+fn);};
const assert=(ok,msg)=>{if(!ok)throw Error(msg);};
await wait(()=>document.querySelector('.browser-upload-queue'));
const drop=(target,files)=>{const transfer=new DataTransfer();for(const [name,body]of files)transfer.items.add(new File([body],name,{type:'text/plain'}));const event=new DragEvent('drop',{bubbles:true,cancelable:true,dataTransfer:transfer});target.dispatchEvent(event);assert(event.defaultPrevented,'File drop did not prevent navigation');};
const main=document.querySelector('.browser-main');
drop(main,[['日本語 #1.txt','new file'],['existing.txt','must not replace'],['cancel.txt','not sent']]);
const queued=[...document.querySelectorAll('.browser-upload-queue li')];queued[2].querySelector('button').click();
drop(document.querySelector('.browser-row[data-path="/drop/sub"]'),[['nested.txt','nested']]);
await wait(()=>document.querySelectorAll('.browser-upload-queue [data-state=done]').length===2&&document.querySelectorAll('.browser-upload-queue [data-state=failed]').length===1);
await wait(()=>document.querySelector('.browser-row[data-path="/drop/日本語 #1.txt"]'));
assert(document.querySelectorAll('.browser-upload-queue [data-state=cancelled]').length===1,'Cancellation missing');
const card=document.querySelector('.browser-upload-queue'),rect=card.getBoundingClientRect();assert(getComputedStyle(card).position==='fixed'&&rect.right<=innerWidth&&rect.bottom<=innerHeight,'Queue not floating within viewport');
const toggle=card.querySelector('[aria-controls]');toggle.click();assert(getComputedStyle(card.querySelector('ol')).display==='none','Queue collapse failed');toggle.click();
assert(document.querySelectorAll('.browser-upload-queue progress[value="100"]').length===2,'Completion progress missing');
document.body.dataset.vimReady='true';
})().catch(e=>{const p=document.createElement('pre');p.id='error';p.textContent=e.stack;document.body.append(p);});
+30 -4
View File
@@ -1,7 +1,7 @@
import {spawn} from 'node:child_process'; import {spawn} from 'node:child_process';
import {writeFile} from 'node:fs/promises'; import {writeFile} from 'node:fs/promises';
import {setTimeout as delay} from 'node:timers/promises'; import {setTimeout as delay} from 'node:timers/promises';
const [url,profile,screenshot]=process.argv.slice(2); const [url,profile,screenshot,mode]=process.argv.slice(2);
const browser=spawn('chromium',['--headless','--no-sandbox','--disable-gpu','--disable-background-networking','--no-proxy-server','--remote-debugging-port=0',`--user-data-dir=${profile}`,'about:blank']); const browser=spawn('chromium',['--headless','--no-sandbox','--disable-gpu','--disable-background-networking','--no-proxy-server','--remote-debugging-port=0',`--user-data-dir=${profile}`,'about:blank']);
process.on('SIGTERM',()=>{browser.kill();process.exit(1);}); process.on('SIGTERM',()=>{browser.kill();process.exit(1);});
let socket,logs=[]; let socket,logs=[];
@@ -17,24 +17,50 @@ try {
const wait=async(expression,seconds=15)=>{for(let n=0;n<seconds*5;n++){if(await evaluate(expression))return;await delay(200);}if(screenshot){const {data}=await call('Page.captureScreenshot',{format:'png'});await writeFile(screenshot,Buffer.from(data,'base64'));}throw Error('Timeout: '+expression+'\n'+logs.slice(-30).join('\n'));}; const wait=async(expression,seconds=15)=>{for(let n=0;n<seconds*5;n++){if(await evaluate(expression))return;await delay(200);}if(screenshot){const {data}=await call('Page.captureScreenshot',{format:'png'});await writeFile(screenshot,Buffer.from(data,'base64'));}throw Error('Timeout: '+expression+'\n'+logs.slice(-30).join('\n'));};
await call('Runtime.enable');await call('Log.enable');await call('Page.enable'); await call('Runtime.enable');await call('Log.enable');await call('Page.enable');
// Only synthetic fixture diagnostics; production does not log article URLs. // Only synthetic fixture diagnostics; production does not log article URLs.
await call('Page.addScriptToEvaluateOnNewDocument',{source:`if(location.pathname.endsWith('/browser/'))import('/_/api/v1/extension/organizer.feeds/browser/assets/v0.0.1/gecko.js').then(({Gecko})=>{const init=Gecko.prototype.init;Gecko.prototype.init=function(){this.opts.printErr=console.warn;this.opts.print=console.log;return init.call(this);};});`}); await call('Page.addScriptToEvaluateOnNewDocument',{source:`if(location.pathname.endsWith('/browser/'))import('/_/api/v1/extension/organizer.feeds/browser/assets/v0.0.1/gecko.js').then(({Gecko})=>{const init=Gecko.prototype.init;Gecko.prototype.init=function(){window.fixtureEngine=this;this.opts.printErr=console.warn;this.opts.print=console.log;return init.call(this);};});`});
await call('Emulation.setDeviceMetricsOverride',{width:1280,height:850,deviceScaleFactor:1,mobile:false});await call('Page.navigate',{url}); await call('Emulation.setDeviceMetricsOverride',{width:1280,height:850,deviceScaleFactor:1,mobile:false});await call('Page.navigate',{url});
await wait(`document.querySelector('.feed-row')`); await wait(`document.querySelector('.feed-row')`);
if(!await evaluate('crossOriginIsolated'))throw Error('Parent not isolated'); if(!await evaluate('crossOriginIsolated'))throw Error('Parent not isolated');
await evaluate(`window.geckoReady=false;addEventListener('message',e=>{if(e.data?.type==='pageswiki-gecko'&&e.data.ready)geckoReady=true;});document.querySelector('.feed-row').click()`); await evaluate(`window.geckoReady=false;addEventListener('message',e=>{if(e.data?.type==='pageswiki-gecko'&&e.data.ready)geckoReady=true;});document.querySelector('.feed-row').click()`);
await wait(`document.querySelector('.feed-original')`);await evaluate(`document.querySelector('.feed-original').click()`); await wait(`document.querySelector('.feed-original')`);await evaluate(`document.querySelector('.feed-original').click()`);
await wait(`document.querySelector('.feed-external iframe')?.contentWindow.crossOriginIsolated`); await wait(`document.querySelector('.feed-external iframe')?.contentWindow.crossOriginIsolated`);
if(mode==='startup-failure'){
await wait(`document.querySelector('.feed-external [role=alert]')&&!document.querySelector('.feed-external iframe')`);
if(!await evaluate(`document.querySelector('.feed-external a[target=_blank]').href==='http://fixture.invalid/first'`))throw Error('Failure lost original fallback');
await evaluate(`document.querySelector('.feed-external').close()`);
console.log('Gecko startup failure discarded iframe and retained original fallback');
}else{
await wait(`geckoReady || document.querySelector('.feed-external iframe')?.contentDocument?.querySelector('#status')?.textContent.includes('Viewer failed')`,100); await wait(`geckoReady || document.querySelector('.feed-external iframe')?.contentDocument?.querySelector('#status')?.textContent.includes('Viewer failed')`,100);
if(!await evaluate('geckoReady'))throw Error('Gecko startup failed\n'+logs.slice(-8).join('\n')); if(!await evaluate('geckoReady'))throw Error('Gecko startup failed\n'+logs.slice(-8).join('\n'));
if(mode==='public-https'){
const engine=`document.querySelector('.feed-external iframe').contentWindow.fixtureEngine`;
await wait(`(async()=>/documentation examples/i.test(String(await ${engine}.evalChrome('document.body.textContent'))))()`,30);
await evaluate(`${engine}.load('https://expired.badssl.com/')`);
await wait(`(async()=>/^about:(neterror|certerror)/.test(String(await ${engine}.evalChrome('String(document.documentURI)'))))()`,30);
const location=await evaluate(`${engine}.evalChrome('String(document.documentURI)')`);
if(!String(location).startsWith('about:neterror')&&!String(location).startsWith('about:certerror'))throw Error('Expired certificate was not rejected: '+location);
await wait(`document.querySelector('.feed-external iframe').contentDocument.querySelector('canvas').hidden && document.querySelector('.feed-external iframe').contentDocument.querySelector('#status').textContent.length>20`);
await evaluate(`document.querySelector('.feed-external').close()`);
console.log('Public HTTPS example.com rendered; expired.badssl.com certificate rejected; closed');
}else{
const pixel=`(()=>{const c=document.querySelector('.feed-external iframe').contentDocument.querySelector('canvas');return Array.from(c.getContext('2d').getImageData(400,200,1,1).data)})()`; const pixel=`(()=>{const c=document.querySelector('.feed-external iframe').contentDocument.querySelector('canvas');return Array.from(c.getContext('2d').getImageData(400,200,1,1).data)})()`;
await wait(`${pixel}[0]===255 && ${pixel}[1]===0`); await wait(`${pixel}[0]===255 && ${pixel}[1]===0`);
await evaluate(`document.querySelector('.feed-external button[title*="Ctrl+F"]').click();document.querySelector('.feed-gecko-find input').value='学舎の園';document.querySelector('.feed-gecko-find').requestSubmit()`);
await wait(`(async()=>String(await document.querySelector('.feed-external iframe').contentWindow.fixtureEngine.evalChrome('String(window.getSelection())'))==='学舎の園')()`);
await wait(`getComputedStyle(document.querySelector('.feed-gecko-find')).display==='flex'`);
await evaluate(`document.querySelector('.feed-gecko-find input').value='missing-synthetic-word';document.querySelector('.feed-gecko-find').requestSubmit()`);
await wait(`document.querySelector('.feed-gecko-find output').textContent.length>0`);
await evaluate(`document.querySelector('.feed-gecko-find button:last-child').click()`);
await wait(`getComputedStyle(document.querySelector('.feed-gecko-find')).display==='none'`);
const rect=await evaluate(`(()=>{const r=document.querySelector('.feed-external iframe').getBoundingClientRect();return {x:r.x+100,y:r.y+50}})()`); const rect=await evaluate(`(()=>{const r=document.querySelector('.feed-external iframe').getBoundingClientRect();return {x:r.x+100,y:r.y+50}})()`);
await call('Input.dispatchMouseEvent',{type:'mousePressed',...rect,button:'left',buttons:1,clickCount:1});await call('Input.dispatchMouseEvent',{type:'mouseReleased',...rect,button:'left',buttons:0,clickCount:1}); await call('Input.dispatchMouseEvent',{type:'mousePressed',...rect,button:'left',buttons:1,clickCount:1});await call('Input.dispatchMouseEvent',{type:'mouseReleased',...rect,button:'left',buttons:0,clickCount:1});
await wait(`${pixel}[0]===0 && ${pixel}[1]===255`); await wait(`${pixel}[0]===0 && ${pixel}[1]===255`);
await wait(`document.querySelector('.feed-external a').href==='http://fixture.invalid/next'`); await wait(`document.querySelector('.feed-external a').href==='http://fixture.invalid/next'`);
await evaluate(`document.querySelector('.feed-external button').click()`); await evaluate(`[...document.querySelectorAll('.feed-external-bar button')].find(b=>b.textContent==='←').click()`);
await wait(`${pixel}[0]===255 && ${pixel}[1]===0`); await wait(`${pixel}[0]===255 && ${pixel}[1]===0`);
if(screenshot){const {data}=await call('Page.captureScreenshot',{format:'png'});await writeFile(screenshot,Buffer.from(data,'base64'));} if(screenshot){const {data}=await call('Page.captureScreenshot',{format:'png'});await writeFile(screenshot,Buffer.from(data,'base64'));}
await evaluate(`document.querySelector('.feed-external').close()`);await wait(`!document.querySelector('.feed-external')`); await evaluate(`document.querySelector('.feed-external').close()`);await wait(`!document.querySelector('.feed-external')`);
console.log('Real Gecko: isolation, Wisp article render, click navigation, viewer-local back and teardown passed'); console.log('Real Gecko: isolation, Japanese find/missing match, Wisp article render, click navigation, viewer-local back and teardown passed');
}
}
}finally{socket?.close();browser.kill();await new Promise(resolve=>browser.once('exit',resolve));await delay(300);} }finally{socket?.close();browser.kill();await new Promise(resolve=>browser.once('exit',resolve));await delay(300);}
+15 -2
View File
@@ -9,6 +9,7 @@
w.fetch=async(...args)=>{pendingRequests++;try{const response=await fetch(...args);await response.clone().arrayBuffer();return response;}finally{pendingRequests--;}}; w.fetch=async(...args)=>{pendingRequests++;try{const response=await fetch(...args);await response.clone().arrayBuffer();return response;}finally{pendingRequests--;}};
for(const key of Object.keys(w.localStorage))if(key.startsWith('pageswiki.feed-folders.v1:'))w.localStorage.removeItem(key); for(const key of Object.keys(w.localStorage))if(key.startsWith('pageswiki.feed-folders.v1:'))w.localStorage.removeItem(key);
await wait(()=>d.querySelectorAll('.feed-row').length===100); await wait(()=>d.querySelectorAll('.feed-row').length===100);
const published=d.querySelector('.feed-published-time');assert(/^\d{2}:\d{2}$/.test(published.textContent),'Publication time missing');assert(published.title.includes('2026')&&published.title.includes('JST'),'Publication timezone/full tooltip missing');assert(w.getComputedStyle(published).display!=='none','Publication time hidden on mobile');assert(d.querySelector('.feed-row').children.length===5,'Publication time column missing');
assert(d.documentElement.scrollWidth<=w.innerWidth,'Viewport overflow'); 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'); 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');} 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');}
@@ -62,6 +63,7 @@
tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('[data-feed="feed/1"]')); tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('[data-feed="feed/1"]'));
tech().querySelector('[data-feed="feed/1"]').click();await wait(()=>d.querySelector('.feed-row')?.textContent.includes('Catalog first')); tech().querySelector('[data-feed="feed/1"]').click();await wait(()=>d.querySelector('.feed-row')?.textContent.includes('Catalog first'));
const globalSearch=d.querySelector('#feed-toolbar input');globalSearch.value='Catalog';globalSearch.dispatchEvent(new w.Event('input',{bubbles:true}));await delay(220); const globalSearch=d.querySelector('#feed-toolbar input');globalSearch.value='Catalog';globalSearch.dispatchEvent(new w.Event('input',{bubbles:true}));await delay(220);
folderKey('H');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name'));
folderKey('K');await wait(()=>activeFolder()===folderNames()[1]&&d.querySelector('.feed-row')?.textContent.includes('Catalog second')); folderKey('K');await wait(()=>activeFolder()===folderNames()[1]&&d.querySelector('.feed-row')?.textContent.includes('Catalog second'));
assert(globalSearch.value==='Catalog'&&!d.querySelector('button[data-feed][aria-current="true"]'),'Folder navigation lost search or kept subscription filter'); assert(globalSearch.value==='Catalog'&&!d.querySelector('button[data-feed][aria-current="true"]'),'Folder navigation lost search or kept subscription filter');
d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body')); d.querySelector('.feed-row').click();await wait(()=>d.querySelector('#feed-reader .feed-body'));
@@ -71,14 +73,25 @@
d.querySelector('.feed-capture').close();await wait(()=>!d.querySelector('.feed-capture')); d.querySelector('.feed-capture').close();await wait(()=>!d.querySelector('.feed-capture'));
folderKey('J');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name')&&d.querySelector('.feed-row')?.textContent.includes('Catalog first')); folderKey('J');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name')&&d.querySelector('.feed-row')?.textContent.includes('Catalog first'));
assert(!d.querySelector('.feed-layout').classList.contains('reading')&&!d.querySelector('#feed-reader .feed-body'),'Folder navigation left old article open'); assert(!d.querySelector('.feed-layout').classList.contains('reading')&&!d.querySelector('#feed-reader .feed-body'),'Folder navigation left old article open');
catalogFind.value='Other';catalogFind.dispatchEvent(new w.Event('input',{bubbles:true}));assert(!activeFolder(),'Catalog filter setup'); const currentCatalogFind=d.querySelector('.feed-catalog input');currentCatalogFind.value='Other';currentCatalogFind.dispatchEvent(new w.Event('input',{bubbles:true}));assert(!activeFolder(),'Catalog filter setup');
folderKey('K');await wait(()=>activeFolder()===folderNames()[1]&&d.querySelector('.feed-row')?.textContent.includes('Catalog second')); folderKey('K');await wait(()=>activeFolder()===folderNames()[1]&&d.querySelector('.feed-row')?.textContent.includes('Catalog second'));
assert(d.querySelector('.feed-catalog input').value==='','Folder navigation left selected folder hidden by catalog filter'); assert(d.querySelector('.feed-catalog input').value==='','Folder navigation left selected folder hidden by catalog filter');
globalSearch.value='';globalSearch.dispatchEvent(new w.Event('input',{bubbles:true}));await delay(220); globalSearch.value='';globalSearch.dispatchEvent(new w.Event('input',{bubbles:true}));await delay(220);
// Rapid repeats must settle on the latest folder rather than an older request. // Rapid repeats must settle on the latest folder rather than an older request.
folderKey('J');folderKey('J');folderKey('K');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name')&&d.querySelector('.feed-row')?.textContent.includes('Catalog first'));await delay(100); folderKey('J');folderKey('J');folderKey('K');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name')&&d.querySelector('.feed-row')?.textContent.includes('Catalog first'));await delay(100);
assert(d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog first'),'Stale folder request won'); assert(d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog first'),'Stale folder request won');
tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false'); // Horizontal hierarchy navigation, with unchanged article filters and bounded siblings.
folderKey('L');await wait(()=>tech().querySelector('button[data-feed="feed/1"][aria-current="true"]'));
assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='true','L did not expand folder');
folderKey('L');folderKey('J');folderKey('K');await delay(80);
assert(tech().querySelector('button[data-feed="feed/1"][aria-current="true"]'),'Leaf keys escaped the current folder');
folderKey('H');await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name'));
folderKey('H');await wait(()=>d.querySelector('.feed-tree-all[aria-current="true"]'));
assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false','H did not collapse folder');
folderKey('H');await delay(80);assert(d.querySelector('.feed-tree-all[aria-current="true"]'),'H escaped catalog root');
folderKey('L');await wait(()=>activeFolder()===folderNames()[0]);
folderKey('L');await delay(80);assert(activeFolder()===folderNames()[0]&&!folderNames()[0].closest('.feed-folder').querySelector('button[data-feed]'),'L fabricated an empty-folder child');
tech().querySelector('.feed-folder-name').click();await wait(()=>activeFolder()===tech().querySelector('.feed-folder-name'));
tech().querySelector('.feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog first')); tech().querySelector('.feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===1&&d.querySelector('.feed-row').textContent.includes('Catalog first'));
assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false','Selecting folder expands it unexpectedly');tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('button[data-feed="feed/1"]')); assert(tech().querySelector('.feed-folder-toggle').getAttribute('aria-expanded')==='false','Selecting folder expands it unexpectedly');tech().querySelector('.feed-folder-toggle').click();await wait(()=>tech().querySelector('button[data-feed="feed/1"]'));
const empty=folder('user/-/label/Empty/Folder');assert(empty.querySelector('.feed-folder-name span').textContent==='Empty/Folder','Slash label split');empty.querySelector('.feed-folder-toggle').click();assert(!empty.querySelector('button[data-feed]'),'Empty folder fabricated a feed');empty.querySelector('.feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===0); const empty=folder('user/-/label/Empty/Folder');assert(empty.querySelector('.feed-folder-name span').textContent==='Empty/Folder','Slash label split');empty.querySelector('.feed-folder-toggle').click();assert(!empty.querySelector('button[data-feed]'),'Empty folder fabricated a feed');empty.querySelector('.feed-folder-name').click();await wait(()=>d.querySelectorAll('.feed-row').length===0);
+2
View File
@@ -40,6 +40,8 @@ window.addEventListener('load',async()=>{const wait=async(fn)=>{for(let i=0;i<12
}else if(path==='/v/plan/dashboard'){ }else if(path==='/v/plan/dashboard'){
await wait(()=>document.querySelectorAll('.productivity-day').length>300);if(!document.querySelector('.productivity-day[data-level="2"]'))throw Error('Seven-point completion missing'); await wait(()=>document.querySelectorAll('.productivity-day').length>300);if(!document.querySelector('.productivity-day[data-level="2"]'))throw Error('Seven-point completion missing');
if(document.querySelectorAll('[data-widget]').length!==6)throw Error('Widget registry missing'); if(document.querySelectorAll('[data-widget]').length!==6)throw Error('Widget registry missing');
await wait(()=>document.querySelector('[data-widget=progress] .dashboard-progress'));
if(document.querySelector('[data-widget=progress] .widget-body small'))throw Error('Completion widget explanation should not be displayed');
const tab=document.querySelector('[data-tab=done]');tab.click();await wait(()=>document.querySelector('#widget-panel-tasks').textContent.includes('Browser work task'));if(location.pathname!=='/v/plan/dashboard'||document.querySelector('#organizer-dashboard iframe'))throw Error('Tab navigation escaped widget'); const tab=document.querySelector('[data-tab=done]');tab.click();await wait(()=>document.querySelector('#widget-panel-tasks').textContent.includes('Browser work task'));if(location.pathname!=='/v/plan/dashboard'||document.querySelector('#organizer-dashboard iframe'))throw Error('Tab navigation escaped widget');
document.querySelector('#dashboard-controls button[aria-pressed]').click();const width=document.querySelector('[data-widget=tasks] [data-size=width]');width.value='6';width.dispatchEvent(new Event('change'));const height=document.querySelector('[data-widget=tasks] [data-size=height]');height.value='5';height.dispatchEvent(new Event('change')); document.querySelector('#dashboard-controls button[aria-pressed]').click();const width=document.querySelector('[data-widget=tasks] [data-size=width]');width.value='6';width.dispatchEvent(new Event('change'));const height=document.querySelector('[data-widget=tasks] [data-size=height]');height.value='5';height.dispatchEvent(new Event('change'));
document.querySelector('[data-widget=tasks] .widget-arrange button').click();document.querySelector('#dashboard-controls button:last-child').click();await wait(()=>document.querySelector('#dashboard-status').textContent.includes('保存しました'));const layout=await fetch('/_/api/v1/extension/organizer.tasks/dashboard').then(r=>r.json());if(layout.widgets[2].id!=='tasks'||layout.widgets[2].width!==6||layout.widgets[2].height!==5||layout.widgets[2].tab!=='done')throw Error('Layout did not persist'); document.querySelector('[data-widget=tasks] .widget-arrange button').click();document.querySelector('#dashboard-controls button:last-child').click();await wait(()=>document.querySelector('#dashboard-status').textContent.includes('保存しました'));const layout=await fetch('/_/api/v1/extension/organizer.tasks/dashboard').then(r=>r.json());if(layout.widgets[2].id!=='tasks'||layout.widgets[2].width!==6||layout.widgets[2].height!==5||layout.widgets[2].tab!=='done')throw Error('Layout did not persist');
+32
View File
@@ -130,6 +130,38 @@ window.addEventListener('load', async () => {
document.body.dataset.vimReady='true';return; document.body.dataset.vimReady='true';return;
} }
await wait(()=>$('status').textContent.includes('ありません')); await wait(()=>$('status').textContent.includes('ありません'));
// Deletion shares the archive footer, not a UUID-search workflow.
$('new').click();await wait(()=>document.querySelector('#tasks-form [name=title]'));
if(!$('delete').hidden)throw Error('Unsaved task must not offer deletion');if(!$('page-open').hidden||$('page-open').hasAttribute('href'))throw Error('New task leaked a related page');$('close').click();
$('quick-title').value='Disposable deletion fixture';$('capture').requestSubmit();
await wait(()=>$('list').querySelector('[data-action=detail]'));$('list').querySelector('[data-action=detail]').click();
await wait(()=>!$('delete').hidden);
if($('delete').parentElement!==$('archive').parentElement||$('delete').textContent!=='削除')throw Error('Delete action is not beside archive');
const deletionID=$('list').querySelector('[data-task-id]').dataset.taskId;
window.confirm=()=>false;$('delete').click();
if(!$('dialog').open)throw Error('Cancelled deletion closed the editor');
const deletionAPI='/_/api/v1/extension/organizer.tasks/items/'+deletionID;
const deletionItem=(await fetch(deletionAPI).then(r=>r.json())).item;
if(!$('page-open').hidden)throw Error('Unlinked task offered related page');
// The footer link uses the saved, authorized path, never unsaved input.
value('page_path','/projects/browser');$('form').requestSubmit();await wait(()=>!$('dialog').open);
$('list').querySelector('[data-action=detail]').click();await wait(()=>!$('page-open').hidden);
const link=$('page-open');if(link.parentElement!==$('save').parentElement||link.pathname!=='/projects/browser'||link.target!=='_blank'||!link.rel.includes('noopener'))throw Error('Unsafe or misplaced related page navigation');
value('title','Unsaved title kept');if(link.hidden||!$('dialog').open)throw Error('Editing task hid the saved page navigation');
if(innerWidth<761&&link.getBoundingClientRect().height<44)throw Error('Related page touch target too small');
document.querySelector('.task-editor-advanced').open=true;
value('page_path','//external.invalid/unsaved');if(!link.hidden||link.hasAttribute('href'))throw Error('Unsaved path exposed a link');
value('page_path','/projects/browser');if(link.hidden)throw Error('Restored path did not restore related link');
window.confirm=()=>true;$('close').click();$('list').querySelector('[data-action=detail]').click();await wait(()=>!$('page-open').hidden);
const freshDeletionItem=(await fetch(deletionAPI).then(r=>r.json())).item;
const changed=await fetch(deletionAPI,{method:'PUT',headers:{'Content-Type':'application/json','If-Match':'"'+freshDeletionItem.version+'"'},body:JSON.stringify({...freshDeletionItem,title:'Updated deletion fixture'})});
if(!changed.ok)throw Error('Deletion conflict fixture failed');
window.confirm=()=>true;$('delete').click();await wait(()=>$('error').textContent.includes('別の画面'));
if(!$('dialog').open||$('delete').disabled)throw Error('Deletion failure did not keep a usable editor');
$('close').click();$('refresh').click();await wait(()=>$('list').querySelector('input[name=title]')?.value==='Updated deletion fixture');
$('list').querySelector('[data-action=detail]').click();await wait(()=>!$('delete').hidden);$('delete').click();
await wait(()=>!$('dialog').open&&!$('list').querySelector('[data-task-id]'));
if((await fetch(deletionAPI)).status!==404)throw Error('Deleted task remains readable');
$('quick-title').value='Write the first task';$('capture').requestSubmit(); $('quick-title').value='Write the first task';$('capture').requestSubmit();
await wait(()=>$('list').querySelector('[data-action=detail]')); await wait(()=>$('list').querySelector('[data-action=detail]'));
$('list').querySelector('[data-action=detail]').click(); $('list').querySelector('[data-action=detail]').click();
+21 -2
View File
@@ -39,6 +39,7 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusRequestEntityTooLarge) http.Error(w, err.Error(), http.StatusRequestEntityTooLarge)
return return
} }
defer r.MultipartForm.RemoveAll()
file, header, err := r.FormFile("file") file, header, err := r.FormFile("file")
if err != nil { if err != nil {
http.Error(w, "file is required", http.StatusBadRequest) http.Error(w, "file is required", http.StatusBadRequest)
@@ -83,6 +84,11 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
} }
} }
objectUUID, err := s.store.ResolvePathInDomain(domainUUID, targetPath) objectUUID, err := s.store.ResolvePathInDomain(domainUUID, targetPath)
createOnly := r.Header.Get("If-None-Match") == "*"
if err == nil && createOnly {
http.Error(w, "file already exists", http.StatusPreconditionFailed)
return
}
if err == nil && mode == "enforcing" { if err == nil && mode == "enforcing" {
// upload and write-once grants never overwrite an existing object. // upload and write-once grants never overwrite an existing object.
if s.store.Authorize(store.AuthorizationRequest{DomainUUID: domainUUID, PrincipalUUID: principal.UUID, Capability: "write", TargetType: "path", TargetID: targetPath}) != nil { if s.store.Authorize(store.AuthorizationRequest{DomainUUID: domainUUID, PrincipalUUID: principal.UUID, Capability: "write", TargetType: "path", TargetID: targetPath}) != nil {
@@ -92,6 +98,13 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
} }
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
objectUUID, err = s.store.CreatePageAtPathInDomain(domainUUID, targetPath) objectUUID, err = s.store.CreatePageAtPathInDomain(domainUUID, targetPath)
if err != nil && createOnly {
// A concurrent creator wins; never turn this into an overwrite.
if _, resolveErr := s.store.ResolvePathInDomain(domainUUID, targetPath); resolveErr == nil {
http.Error(w, "file already exists", http.StatusPreconditionFailed)
return
}
}
} }
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)
@@ -113,17 +126,23 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
if strings.TrimSpace(language) == "" { if strings.TrimSpace(language) == "" {
language = "und" language = "und"
} }
if _, err := s.store.SaveRevisionContent( revision, err := s.store.SaveRevisionContent(
objectUUID, objectUUID,
payload, payload,
"web upload: "+originalName, "web upload: "+originalName,
language, language,
contentType, contentType,
originalName, originalName,
); err != nil { )
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
if strings.Contains(r.Header.Get("Accept"), "application/json") {
w.Header().Set("Cache-Control", "private, no-store")
writeEventJSON(w, http.StatusCreated, map[string]string{"path": targetPath, "object_uuid": objectUUID, "revision_uuid": revision.UUID})
return
}
http.Redirect(w, r, targetPath, http.StatusSeeOther) http.Redirect(w, r, targetPath, http.StatusSeeOther)
} }
+46
View File
@@ -2,6 +2,7 @@ package server
import ( import (
"bytes" "bytes"
"encoding/json"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@@ -85,6 +86,51 @@ func TestWebUploadCreatesAndRevisesSpecifiedPath(t *testing.T) {
} }
} }
func TestWebUploadCreateOnlyJSON(t *testing.T) {
s, token, domain := configFixture(t)
upload := func(payload string, authenticated bool) *httptest.ResponseRecorder {
var body bytes.Buffer
writer := multipart.NewWriter(&body)
writer.WriteField("path", "/uploads/日本語 #1.txt")
file, _ := writer.CreateFormFile("file", "日本語 #1.txt")
file.Write([]byte(payload))
writer.Close()
r := httptest.NewRequest("POST", "http://localhost/v/upload", &body)
r.Header.Set("Content-Type", writer.FormDataContentType())
r.Header.Set("Accept", "application/json")
r.Header.Set("If-None-Match", "*")
if authenticated {
r.Header.Set("Authorization", "Bearer "+token)
}
w := httptest.NewRecorder()
s.handleUpload(w, r)
return w
}
if w := upload("denied", false); w.Code != 403 {
t.Fatalf("unauthorized: %d", w.Code)
}
w := upload("original", true)
var result map[string]string
if w.Code != 201 || json.Unmarshal(w.Body.Bytes(), &result) != nil || result["path"] != "/uploads/日本語 #1.txt" || result["revision_uuid"] == "" {
t.Fatalf("JSON upload %d %s", w.Code, w.Body.String())
}
if w = upload("overwrite", true); w.Code != 412 {
t.Fatalf("duplicate: %d %s", w.Code, w.Body.String())
}
object, err := s.store.ResolvePathInDomain(domain, result["path"])
if err != nil {
t.Fatal(err)
}
revisions, err := s.store.ListRevisions(object)
if err != nil || len(revisions) != 1 {
t.Fatalf("unexpected revisions %d %v", len(revisions), err)
}
rev, err := s.store.GetRevision(revisions[0].UUID)
if err != nil || rev.Body != "original" {
t.Fatal("overwritten", err)
}
}
func mustServerDomainUUID(t *testing.T, st *store.Store) string { func mustServerDomainUUID(t *testing.T, st *store.Store) string {
t.Helper() t.Helper()
domain, err := st.GetDefaultDomain() domain, err := st.GetDefaultDomain()
+5 -1
View File
@@ -164,6 +164,10 @@ func (s *Store) CreateBrowserAuthSession(domainUUID, principalUUID string, mfaLe
} }
func (s *Store) createTypedAuthSession(domainUUID, principalUUID string, mfaLevel int, prefix string) (string, error) { func (s *Store) createTypedAuthSession(domainUUID, principalUUID string, mfaLevel int, prefix string) (string, error) {
return s.createTypedAuthSessionForLifetime(domainUUID, principalUUID, mfaLevel, prefix, s.AuthSessionLifetime(domainUUID))
}
func (s *Store) createTypedAuthSessionForLifetime(domainUUID, principalUUID string, mfaLevel int, prefix string, lifetime time.Duration) (string, error) {
raw, _, err := authToken() raw, _, err := authToken()
if err != nil { if err != nil {
return "", err return "", err
@@ -177,7 +181,7 @@ func (s *Store) createTypedAuthSession(domainUUID, principalUUID string, mfaLeve
result, err := s.DB.Exec(`INSERT INTO auth_sessions(uuid,token_hash,principal_uuid,domain_uuid,auth_time_ms,expires_at_ms,last_seen_at_ms,mfa_level) result, err := s.DB.Exec(`INSERT INTO auth_sessions(uuid,token_hash,principal_uuid,domain_uuid,auth_time_ms,expires_at_ms,last_seen_at_ms,mfa_level)
SELECT ?,?,p.uuid,m.domain_uuid,?,?,?,? FROM principals p JOIN domain_memberships m ON m.principal_uuid=p.uuid SELECT ?,?,p.uuid,m.domain_uuid,?,?,?,? FROM principals p JOIN domain_memberships m ON m.principal_uuid=p.uuid
WHERE p.uuid=? AND p.state IN ('active','readonly') AND m.domain_uuid=? AND m.state='active'`, WHERE p.uuid=? AND p.state IN ('active','readonly') AND m.domain_uuid=? AND m.state='active'`,
uuid.NewString(), hash, now, now+s.AuthSessionLifetime(domainUUID).Milliseconds(), now, mfaLevel, principalUUID, domainUUID) uuid.NewString(), hash, now, now+lifetime.Milliseconds(), now, mfaLevel, principalUUID, domainUUID)
if err != nil { if err != nil {
return "", err return "", err
} }
+18 -6
View File
@@ -27,7 +27,9 @@ var cliAuthMigrations = []db.SQLMigration{{Version: 1, Name: "cli_oidc_handoff",
schemaUnique("auth_cli_requests", "id"), schemaUnique("auth_cli_requests", "device_hash"), schemaUnique("auth_cli_requests", "id"), schemaUnique("auth_cli_requests", "device_hash"),
schemaIndex("auth_cli_requests", "auth_cli_domain_created", "domain_uuid,created_ms"), schemaIndex("auth_cli_requests", "auth_cli_domain_created", "domain_uuid,created_ms"),
schemaIndex("auth_cli_requests", "auth_cli_expiry", "expires_ms"), schemaIndex("auth_cli_requests", "auth_cli_expiry", "expires_ms"),
}}} }}, {Version: 2, Name: "cli_trusted_session_choice", Statements: []string{
`ALTER TABLE auth_cli_requests ADD COLUMN remember INTEGER NOT NULL DEFAULT 0 CHECK(remember IN (0,1))`,
}, Assertions: []string{schemaColumns("auth_cli_requests", "remember")}}}
var ( var (
ErrCLIPending = errors.New("authorization_pending") ErrCLIPending = errors.New("authorization_pending")
@@ -39,11 +41,16 @@ var (
type CLIAuthRequest struct { type CLIAuthRequest struct {
ID, Origin, State, BrowserHash, PrincipalUUID string ID, Origin, State, BrowserHash, PrincipalUUID string
ExpiresMS int64 ExpiresMS int64
Remember bool
} }
// Admission is one write statement; concurrent unauthenticated requests cannot // Admission is one write statement; concurrent unauthenticated requests cannot
// race the caps. Requests are retained for ten minutes for issuance accounting. // race the caps. Requests are retained for ten minutes for issuance accounting.
func (s *Store) StartCLIAuth(ctx context.Context, domain, origin, challenge string) (id, device, code string, err error) { func (s *Store) StartCLIAuth(ctx context.Context, domain, origin, challenge string) (id, device, code string, err error) {
return s.StartCLIAuthForLogin(ctx, domain, origin, challenge, false)
}
func (s *Store) StartCLIAuthForLogin(ctx context.Context, domain, origin, challenge string, remember bool) (id, device, code string, err error) {
if s.ReadOnly { if s.ReadOnly {
return "", "", "", ErrReadOnly return "", "", "", ErrReadOnly
} }
@@ -66,10 +73,10 @@ func (s *Store) StartCLIAuth(ctx context.Context, domain, origin, challenge stri
return return
} }
var result sql.Result var result sql.Result
result, err = s.DB.ExecContext(ctx, `INSERT INTO auth_cli_requests(id,domain_uuid,origin,device_hash,challenge,code_hash,created_ms,expires_ms) result, err = s.DB.ExecContext(ctx, `INSERT INTO auth_cli_requests(id,domain_uuid,origin,device_hash,challenge,code_hash,created_ms,expires_ms,remember)
SELECT ?,?,?,?,?,?,?,? WHERE (SELECT count(*) FROM auth_cli_requests)<4096 SELECT ?,?,?,?,?,?,?,?,? WHERE (SELECT count(*) FROM auth_cli_requests)<4096
AND (SELECT count(*) FROM auth_cli_requests WHERE domain_uuid=? AND created_ms>?)<64`, AND (SELECT count(*) FROM auth_cli_requests WHERE domain_uuid=? AND created_ms>?)<64`,
id, domain, origin, hashAuthToken(device), challenge, hashAuthToken(code), now, now+300000, domain, now-300000) id, domain, origin, hashAuthToken(device), challenge, hashAuthToken(code), now, now+300000, remember, domain, now-300000)
if err == nil { if err == nil {
if n, e := result.RowsAffected(); e != nil { if n, e := result.RowsAffected(); e != nil {
err = e err = e
@@ -82,7 +89,7 @@ func (s *Store) StartCLIAuth(ctx context.Context, domain, origin, challenge stri
func (s *Store) CLIAuthRequest(ctx context.Context, domain, origin, id string) (*CLIAuthRequest, error) { func (s *Store) CLIAuthRequest(ctx context.Context, domain, origin, id string) (*CLIAuthRequest, error) {
var grant CLIAuthRequest var grant CLIAuthRequest
err := s.DB.QueryRowContext(ctx, `SELECT id,origin,state,browser_hash,principal_uuid,expires_ms FROM auth_cli_requests WHERE id=? AND domain_uuid=? AND origin=? AND expires_ms>?`, id, domain, origin, time.Now().UnixMilli()).Scan(&grant.ID, &grant.Origin, &grant.State, &grant.BrowserHash, &grant.PrincipalUUID, &grant.ExpiresMS) err := s.DB.QueryRowContext(ctx, `SELECT id,origin,state,browser_hash,principal_uuid,expires_ms,remember FROM auth_cli_requests WHERE id=? AND domain_uuid=? AND origin=? AND expires_ms>?`, id, domain, origin, time.Now().UnixMilli()).Scan(&grant.ID, &grant.Origin, &grant.State, &grant.BrowserHash, &grant.PrincipalUUID, &grant.ExpiresMS, &grant.Remember)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
return nil, ErrCLIExpired return nil, ErrCLIExpired
} }
@@ -168,15 +175,17 @@ func (s *Store) ExchangeCLIAuth(ctx context.Context, domain, origin, device, ver
} }
now := time.Now().UnixMilli() now := time.Now().UnixMilli()
lifetime := s.AuthSessionLifetime(domain).Milliseconds() lifetime := s.AuthSessionLifetime(domain).Milliseconds()
trustedLifetime := s.LoginSessionLifetime(domain, true).Milliseconds()
tx, err := s.DB.BeginTx(ctx, nil) tx, err := s.DB.BeginTx(ctx, nil)
if err != nil { if err != nil {
return return
} }
defer tx.Rollback() defer tx.Rollback()
var id, state, browser string var id, state, browser string
var remember bool
err = tx.QueryRowContext(ctx, `UPDATE auth_cli_requests SET next_poll_ms=?,state=CASE WHEN state='approved' THEN 'consumed' ELSE state END err = tx.QueryRowContext(ctx, `UPDATE auth_cli_requests SET next_poll_ms=?,state=CASE WHEN state='approved' THEN 'consumed' ELSE state END
WHERE device_hash=? AND challenge=? AND domain_uuid=? AND origin=? AND expires_ms>? AND next_poll_ms<=? AND state IN ('pending','approved','denied') WHERE device_hash=? AND challenge=? AND domain_uuid=? AND origin=? AND expires_ms>? AND next_poll_ms<=? AND state IN ('pending','approved','denied')
RETURNING id,state,browser_hash`, now+5000, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now, now).Scan(&id, &state, &browser) RETURNING id,state,browser_hash,remember`, now+5000, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now, now).Scan(&id, &state, &browser, &remember)
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
var exists int var exists int
e := tx.QueryRowContext(ctx, `SELECT count(*) FROM auth_cli_requests WHERE device_hash=? AND challenge=? AND domain_uuid=? AND origin=? AND expires_ms>? AND state IN ('pending','approved','denied')`, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now).Scan(&exists) e := tx.QueryRowContext(ctx, `SELECT count(*) FROM auth_cli_requests WHERE device_hash=? AND challenge=? AND domain_uuid=? AND origin=? AND expires_ms>? AND state IN ('pending','approved','denied')`, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now).Scan(&exists)
@@ -204,6 +213,9 @@ func (s *Store) ExchangeCLIAuth(ctx context.Context, domain, origin, device, ver
return return
} }
var raw string var raw string
if remember {
lifetime = trustedLifetime
}
raw, _, err = authToken() raw, _, err = authToken()
if err != nil { if err != nil {
return return
+58
View File
@@ -8,10 +8,68 @@ import (
"sync/atomic" "sync/atomic"
"testing" "testing"
"time" "time"
"pageswiki/internal/db"
) )
const cliTestOrigin = "https://wiki.example" const cliTestOrigin = "https://wiki.example"
func TestCLIAuthTrustedMigrationPreservesExistingRequests(t *testing.T) {
s := newSchemaTestStore(t)
ctx := context.Background()
if err := db.ApplySQLiteMigrations(ctx, s.DB, "cli-auth", cliAuthMigrations[:1]); err != nil {
t.Fatal(err)
}
if _, err := s.DB.Exec(`INSERT INTO auth_cli_requests(id,domain_uuid,origin,device_hash,challenge,code_hash,created_ms,expires_ms) VALUES('old','domain','https://wiki.example','device','challenge','code',1,2)`); err != nil {
t.Fatal(err)
}
for i := 0; i < 2; i++ {
if err := db.ApplySQLiteMigrations(ctx, s.DB, "cli-auth", cliAuthMigrations); err != nil {
t.Fatal(err)
}
}
var remember int
var challenge string
if err := s.DB.QueryRow(`SELECT remember,challenge FROM auth_cli_requests WHERE id='old'`).Scan(&remember, &challenge); err != nil || remember != 0 || challenge != "challenge" {
t.Fatalf("old grant changed: %d %q %v", remember, challenge, err)
}
if _, err := s.DB.Exec(`UPDATE auth_cli_requests SET remember=2`); err == nil {
t.Fatal("invalid remember flag accepted")
}
}
func TestTOTPLoginBindsTrustedChoice(t *testing.T) {
for _, remember := range []bool{false, true} {
s, p, _ := cliAuthFixture(t)
secret, err := s.BeginTOTPEnrollment(p)
if err != nil {
t.Fatal(err)
}
code, err := totpCode(secret, time.Now().Unix()/30)
if err != nil {
t.Fatal(err)
}
if err = s.ConfirmTOTPEnrollment(p, code); err != nil {
t.Fatal(err)
}
// Synthetic fixture: permit this time step once for login after enrollment.
if _, err = s.DB.Exec(`UPDATE auth_credentials SET parameters_json='{"last_counter":0}' WHERE principal_uuid=? AND kind='totp'`, p); err != nil {
t.Fatal(err)
}
challenge, err := s.CreateTOTPLoginChallengeForLogin("domain", p, remember)
if err != nil {
t.Fatal(err)
}
got, choice, err := s.CompleteTOTPLoginChallengeForLogin("domain", challenge, code)
if err != nil || got != p || choice != remember {
t.Fatalf("bound choice: %q %v %v", got, choice, err)
}
if _, _, err = s.CompleteTOTPLoginChallengeForLogin("domain", challenge, code); err == nil {
t.Fatal("challenge replay accepted")
}
}
}
func cliAuthFixture(t *testing.T) (*Store, string, string) { func cliAuthFixture(t *testing.T) (*Store, string, string) {
t.Helper() t.Helper()
s := newSchemaTestStore(t) s := newSchemaTestStore(t)
+34
View File
@@ -30,3 +30,37 @@ func (s *Store) SetAuthSessionLifetimeMinutes(domain string, minutes int) error
func (s *Store) AuthSessionLifetime(domain string) time.Duration { func (s *Store) AuthSessionLifetime(domain string) time.Duration {
return time.Duration(s.AuthSessionLifetimeMinutes(domain)) * time.Minute return time.Duration(s.AuthSessionLifetimeMinutes(domain)) * time.Minute
} }
// Opt-in persistent sessions have a separate, administrator-controlled ceiling.
// Zero disables the option. Existing sessions retain their original expiry.
func (s *Store) TrustedSessionDays(domain string) int {
raw, err := s.GetConfigInDomain(domain, "auth_trusted_session_days")
if err != nil {
return 0
}
if raw == "" {
return 30
}
days, err := strconv.Atoi(raw)
if err != nil || days < 0 || days > 30 {
return 0
}
return days
}
func (s *Store) LoginSessionLifetime(domain string, remember bool) time.Duration {
if days := s.TrustedSessionDays(domain); remember && days > 0 {
return time.Duration(days) * 24 * time.Hour
}
return s.AuthSessionLifetime(domain)
}
func (s *Store) CreateLoginSession(domain, principal string, mfa int, browser, remember bool) (string, time.Duration, error) {
lifetime := s.LoginSessionLifetime(domain, remember)
prefix := "pw_api_"
if browser {
prefix = "pw_browser_"
}
token, err := s.createTypedAuthSessionForLifetime(domain, principal, mfa, prefix, lifetime)
return token, lifetime, err
}
+23 -8
View File
@@ -176,36 +176,51 @@ func TOTPURI(secret, account, issuer string) string {
} }
func (s *Store) CreateTOTPLoginChallenge(domainUUID, principalUUID string) (string, error) { func (s *Store) CreateTOTPLoginChallenge(domainUUID, principalUUID string) (string, error) {
return s.CreateTOTPLoginChallengeForLogin(domainUUID, principalUUID, false)
}
func (s *Store) CreateTOTPLoginChallengeForLogin(domainUUID, principalUUID string, remember bool) (string, error) {
token, hash, err := authToken() token, hash, err := authToken()
if err != nil { if err != nil {
return "", err return "", err
} }
now := time.Now().UnixMilli() now := time.Now().UnixMilli()
payload, _ := json.Marshal(map[string]string{"principal_uuid": principalUUID}) payload, _ := json.Marshal(map[string]any{"principal_uuid": principalUUID, "remember": remember})
_, err = s.DB.Exec(`INSERT INTO auth_challenges(uuid,domain_uuid,principal_uuid,kind,token_hash,payload_json,expires_at_ms,created_at_ms) VALUES(?,?,?,?,?,?,?,?)`, uuid.NewString(), domainUUID, principalUUID, "totp-login", hash, string(payload), now+5*60*1000, now) _, err = s.DB.Exec(`INSERT INTO auth_challenges(uuid,domain_uuid,principal_uuid,kind,token_hash,payload_json,expires_at_ms,created_at_ms) VALUES(?,?,?,?,?,?,?,?)`, uuid.NewString(), domainUUID, principalUUID, "totp-login", hash, string(payload), now+5*60*1000, now)
return token, err return token, err
} }
func (s *Store) CompleteTOTPLoginChallenge(domainUUID, token, code string) (string, error) { func (s *Store) CompleteTOTPLoginChallenge(domainUUID, token, code string) (string, error) {
id, _, err := s.CompleteTOTPLoginChallengeForLogin(domainUUID, token, code)
return id, err
}
func (s *Store) CompleteTOTPLoginChallengeForLogin(domainUUID, token, code string) (string, bool, error) {
sum := sha256.Sum256([]byte(token)) sum := sha256.Sum256([]byte(token))
hash := base64.RawURLEncoding.EncodeToString(sum[:]) hash := base64.RawURLEncoding.EncodeToString(sum[:])
var challengeUUID, principalUUID string var challengeUUID, principalUUID, payload string
var expires int64 var expires int64
var attempts int var attempts int
err := s.DB.QueryRow(`SELECT uuid,principal_uuid,expires_at_ms,attempt_count FROM auth_challenges WHERE domain_uuid=? AND kind='totp-login' AND token_hash=? AND consumed_at_ms=0`, domainUUID, hash).Scan(&challengeUUID, &principalUUID, &expires, &attempts) err := s.DB.QueryRow(`SELECT uuid,principal_uuid,expires_at_ms,attempt_count,payload_json FROM auth_challenges WHERE domain_uuid=? AND kind='totp-login' AND token_hash=? AND consumed_at_ms=0`, domainUUID, hash).Scan(&challengeUUID, &principalUUID, &expires, &attempts, &payload)
if err != nil || expires < time.Now().UnixMilli() || attempts >= 5 { if err != nil || expires < time.Now().UnixMilli() || attempts >= 5 {
return "", ErrAccessDenied return "", false, ErrAccessDenied
}
var options struct {
Remember bool `json:"remember"`
}
if json.Unmarshal([]byte(payload), &options) != nil {
return "", false, ErrAccessDenied
} }
if err = s.VerifyTOTP(principalUUID, code); err != nil { if err = s.VerifyTOTP(principalUUID, code); err != nil {
_, _ = s.DB.Exec(`UPDATE auth_challenges SET attempt_count=attempt_count+1,consumed_at_ms=CASE WHEN attempt_count+1>=5 THEN ? ELSE consumed_at_ms END WHERE uuid=? AND consumed_at_ms=0`, time.Now().UnixMilli(), challengeUUID) _, _ = s.DB.Exec(`UPDATE auth_challenges SET attempt_count=attempt_count+1,consumed_at_ms=CASE WHEN attempt_count+1>=5 THEN ? ELSE consumed_at_ms END WHERE uuid=? AND consumed_at_ms=0`, time.Now().UnixMilli(), challengeUUID)
return "", err return "", false, err
} }
result, err := s.DB.Exec(`UPDATE auth_challenges SET consumed_at_ms=? WHERE uuid=? AND consumed_at_ms=0`, time.Now().UnixMilli(), challengeUUID) result, err := s.DB.Exec(`UPDATE auth_challenges SET consumed_at_ms=? WHERE uuid=? AND consumed_at_ms=0`, time.Now().UnixMilli(), challengeUUID)
if err != nil { if err != nil {
return "", err return "", false, err
} }
changed, _ := result.RowsAffected() changed, _ := result.RowsAffected()
if changed != 1 { if changed != 1 {
return "", ErrAccessDenied return "", false, ErrAccessDenied
} }
return principalUUID, nil return principalUUID, options.Remember, nil
} }
+5 -1
View File
@@ -81,7 +81,11 @@ func minInt64(a, b int64) int64 {
} }
func (s *Store) GetRevisionMetadata(revisionUUID string) (*Revision, error) { func (s *Store) GetRevisionMetadata(revisionUUID string) (*Revision, error) {
row := s.DB.QueryRow(`SELECT uuid,object_uuid,COALESCE(document_hash,''),COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),'',COALESCE(message,''),COALESCE(created_at,0),COALESCE(created_at_ms,COALESCE(created_at,0)*1000) FROM revisions WHERE uuid=?`, revisionUUID) return s.GetRevisionMetadataContext(context.Background(), revisionUUID)
}
func (s *Store) GetRevisionMetadataContext(ctx context.Context, revisionUUID string) (*Revision, error) {
row := s.DB.QueryRowContext(ctx, `SELECT uuid,object_uuid,COALESCE(document_hash,''),COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),'',COALESCE(message,''),COALESCE(created_at,0),COALESCE(created_at_ms,COALESCE(created_at,0)*1000) FROM revisions WHERE uuid=?`, revisionUUID)
return scanRevision(row) return scanRevision(row)
} }
+6 -1
View File
@@ -1,6 +1,7 @@
package store package store
import ( import (
"context"
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"strings" "strings"
@@ -69,6 +70,10 @@ func (s *Store) ResolvePathInDomain(
domainUUID string, domainUUID string,
path string, path string,
) (string, error) { ) (string, error) {
return s.ResolvePathInDomainContext(context.Background(), domainUUID, path)
}
func (s *Store) ResolvePathInDomainContext(ctx context.Context, domainUUID, path string) (string, error) {
path = normalizePath(path) path = normalizePath(path)
if err := s.ensureLocalDomain(domainUUID); err != nil { if err := s.ensureLocalDomain(domainUUID); err != nil {
return "", err return "", err
@@ -76,7 +81,7 @@ func (s *Store) ResolvePathInDomain(
var objectUUID string var objectUUID string
err := s.DB.QueryRow(` err := s.DB.QueryRowContext(ctx, `
SELECT object_uuid SELECT object_uuid
FROM paths FROM paths
WHERE domain_uuid = ? WHERE domain_uuid = ?
+6 -1
View File
@@ -1,6 +1,7 @@
package store package store
import ( import (
"context"
"crypto/sha256" "crypto/sha256"
"database/sql" "database/sql"
"encoding/hex" "encoding/hex"
@@ -324,6 +325,10 @@ func (s *Store) GetRevision(
} }
func (s *Store) GetLatestRevisionMetadataForLanguages(objectUUID string, rawLanguages []string) (*Revision, error) { func (s *Store) GetLatestRevisionMetadataForLanguages(objectUUID string, rawLanguages []string) (*Revision, error) {
return s.GetLatestRevisionMetadataForLanguagesContext(context.Background(), objectUUID, rawLanguages)
}
func (s *Store) GetLatestRevisionMetadataForLanguagesContext(ctx context.Context, objectUUID string, rawLanguages []string) (*Revision, error) {
candidates := make([]string, 0, len(rawLanguages)+1) candidates := make([]string, 0, len(rawLanguages)+1)
seen := map[string]bool{} seen := map[string]bool{}
for _, rawLanguage := range rawLanguages { for _, rawLanguage := range rawLanguages {
@@ -336,7 +341,7 @@ func (s *Store) GetLatestRevisionMetadataForLanguages(objectUUID string, rawLang
candidates = append(candidates, "und") candidates = append(candidates, "und")
} }
for _, lang := range candidates { for _, lang := range candidates {
row := s.DB.QueryRow(`SELECT uuid,object_uuid,COALESCE(document_hash,''),COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),'',COALESCE(message,''),COALESCE(created_at,0),COALESCE(created_at_ms,COALESCE(created_at,0)*1000) FROM revisions WHERE object_uuid=? AND COALESCE(NULLIF(lang,''),'und')=? ORDER BY COALESCE(created_at_ms,created_at*1000) DESC,rowid DESC LIMIT 1`, objectUUID, lang) row := s.DB.QueryRowContext(ctx, `SELECT uuid,object_uuid,COALESCE(document_hash,''),COALESCE(NULLIF(lang,''),'und'),COALESCE(NULLIF(content_type,''),'text/html; charset=utf-8'),COALESCE(filename,''),'',COALESCE(message,''),COALESCE(created_at,0),COALESCE(created_at_ms,COALESCE(created_at,0)*1000) FROM revisions WHERE object_uuid=? AND COALESCE(NULLIF(lang,''),'und')=? ORDER BY COALESCE(created_at_ms,created_at*1000) DESC,rowid DESC LIMIT 1`, objectUUID, lang)
revision, err := scanRevision(row) revision, err := scanRevision(row)
if err == nil { if err == nil {
return revision, nil return revision, nil
+54
View File
@@ -0,0 +1,54 @@
package store
import (
"context"
"database/sql"
"errors"
"github.com/google/uuid"
)
// A receipt without a live task or a deletion marker needs repair, not an
// implicit create that could silently revive an inconsistent record.
var ErrTaskCaptureMissing = errors.New("captured task is missing without a deletion record")
func TaskRecreationID(request string) string {
return uuid.NewSHA1(uuid.NameSpaceURL, []byte("pages:task-recreate:"+request)).String()
}
func deletedCapture(ctx context.Context, q interface {
QueryRowContext(context.Context, string, ...any) *sql.Row
}, domain, actor, request string) error {
var id string
if err := q.QueryRowContext(ctx, `SELECT item_uuid FROM organizer_capture_receipts WHERE domain_uuid=? AND owner_uuid=? AND request_uuid=?`, domain, actor, request).Scan(&id); err != nil {
return err
}
var live, deleted bool
if err := q.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_items WHERE domain_uuid=? AND uuid=?), EXISTS(SELECT 1 FROM organizer_task_deletions WHERE domain_uuid=? AND owner_uuid=? AND item_uuid=?)`, domain, id, domain, actor, id).Scan(&live, &deleted); err != nil {
return err
}
if live {
return ErrTaskConflict
}
if !deleted {
return ErrTaskCaptureMissing
}
return nil
}
// RecreateCapturedTask never removes old receipts, tombstones or DAV identity
// reservations. A deterministic successor ID makes a lost response retry safe.
// The caller authorizes read/create/write for target, including retained pages.
func (s *Store) RecreateCapturedTask(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body, replaces string) (TaskRecord, error) {
id, err := uuid.Parse(replaces)
if err != nil || id.String() != replaces || request != TaskRecreationID(replaces) {
return TaskRecord{}, ErrTaskInvalid
}
if err = taskActor(ctx, s.DB, domain, actor, true); err != nil {
return TaskRecord{}, err
}
if err = deletedCapture(ctx, s.DB, domain, actor, replaces); err != nil {
return TaskRecord{}, err
}
return s.captureTaskWithWiki(ctx, domain, actor, request, hash, item, target, body, replaces)
}
+5 -1
View File
@@ -77,8 +77,12 @@ func ValidTaskMailSuffix(s string) bool {
return mailListSuffix.MatchString(s) || (mailMonthSuffix.MatchString(s) && !strings.HasPrefix(s, "0000/")) return mailListSuffix.MatchString(s) || (mailMonthSuffix.MatchString(s) && !strings.HasPrefix(s, "0000/"))
} }
func validCapturedTaskWiki(target, body string) bool {
return target != "" && ValidTaskWikiPrefix(path.Dir(target)) && path.Clean(target) == target && len(body) <= 256<<10 && utf8.ValidString(body) && strings.IndexByte(body, 0) < 0
}
func (s *Store) createCapturedTaskWiki(ctx context.Context, tx *sql.Tx, domain, actor string, item *TaskRecord, target, body string) error { func (s *Store) createCapturedTaskWiki(ctx context.Context, tx *sql.Tx, domain, actor string, item *TaskRecord, target, body string) error {
if target == "" || !ValidTaskWikiPrefix(path.Dir(target)) || path.Clean(target) != target || item.PageUUID != "" || len(body) > 256<<10 || !utf8.ValidString(body) || strings.IndexByte(body, 0) >= 0 { if !validCapturedTaskWiki(target, body) || item.PageUUID != "" {
return ErrTaskInvalid return ErrTaskInvalid
} }
var exists bool var exists bool
+3
View File
@@ -54,6 +54,9 @@ func (s *Store) ensureTaskDAVSchema() error {
`DELETE FROM organizer_dav_collections`, `DELETE FROM organizer_dav_collections`,
`INSERT INTO organizer_dav_collections(domain_uuid,path,owner_uuid,project_uuid) SELECT domain_uuid,COALESCE(NULLIF(json_extract(data,'$.dav_collection'),''),'tasks/projects/'||uuid),owner_uuid,uuid FROM organizer_items WHERE kind='project'`, `INSERT INTO organizer_dav_collections(domain_uuid,path,owner_uuid,project_uuid) SELECT domain_uuid,COALESCE(NULLIF(json_extract(data,'$.dav_collection'),''),'tasks/projects/'||uuid),owner_uuid,uuid FROM organizer_items WHERE kind='project'`,
`INSERT INTO organizer_dav_resources(domain_uuid,owner_uuid,item_uuid,name,uid) SELECT domain_uuid,owner_uuid,uuid,CASE WHEN project_uuid='' THEN '' ELSE char(0)||project_uuid||char(0) END||COALESCE(json_extract(data,'$.caldav.name'),uuid||'.ics'),CASE WHEN project_uuid='' THEN '' ELSE char(0)||project_uuid||char(0) END||COALESCE(json_extract(data,'$.caldav.uid'),uuid) FROM organizer_items WHERE kind='task'`, `INSERT INTO organizer_dav_resources(domain_uuid,owner_uuid,item_uuid,name,uid) SELECT domain_uuid,owner_uuid,uuid,CASE WHEN project_uuid='' THEN '' ELSE char(0)||project_uuid||char(0) END||COALESCE(json_extract(data,'$.caldav.name'),uuid||'.ics'),CASE WHEN project_uuid='' THEN '' ELSE char(0)||project_uuid||char(0) END||COALESCE(json_extract(data,'$.caldav.uid'),uuid) FROM organizer_items WHERE kind='task'`,
// Deleted identities remain reserved after an index rebuild. A stale
// client PUT must not silently resurrect a deliberately removed task.
`INSERT INTO organizer_dav_resources(domain_uuid,owner_uuid,item_uuid,name,uid) SELECT domain_uuid,owner_uuid,item_uuid,dav_name,dav_uid FROM organizer_task_deletions`,
} { } {
if _, err = tx.Exec(q); err != nil { if _, err = tx.Exec(q); err != nil {
return err return err
+117
View File
@@ -0,0 +1,117 @@
package store
import (
"context"
"database/sql"
"encoding/json"
"errors"
"time"
"github.com/google/uuid"
)
var ErrTaskDeleted = errors.New("task has been deleted")
var ErrTaskHasChildren = errors.New("move or delete subtasks first")
var ErrTaskWorking = errors.New("stop task work and focus sessions first")
// DeleteTask is deliberately separate from reversible archiving. The head and
// revision references are removed; minimal identity tombstones prevent offline
// clients from resurrecting the same task. Wiki documents, calendar events and
// completed work records are independent resources and are not deleted here.
// CAS blobs/backups are not securely erased by this operation.
func (s *Store) DeleteTask(ctx context.Context, domain, actor, id string, expected int64) error {
if s.ReadOnly {
return ErrReadOnly
}
u, err := uuid.Parse(id)
if err != nil || u.String() != id || expected < 1 {
return ErrTaskInvalid
}
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
tx, err := s.DB.BeginTx(ctx, nil)
if err != nil {
return err
}
defer tx.Rollback()
if _, err = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=? AND principal_uuid=?`, domain, actor); err != nil {
return err
}
if err = taskActor(ctx, tx, domain, actor, true); err != nil {
return err
}
enabled, err := taskReminderExtensionEnabled(ctx, tx, domain)
if err != nil {
return err
}
if !enabled {
return ErrAccessDenied
}
var raw string
err = tx.QueryRowContext(ctx, `SELECT data FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=?`, domain, actor, id).Scan(&raw)
if errors.Is(err, sql.ErrNoRows) {
// A lost successful DELETE response can be retried with its original
// precondition, without disclosing another owner's tombstone.
var version int64
if e := tx.QueryRowContext(ctx, `SELECT version FROM organizer_task_deletions WHERE domain_uuid=? AND owner_uuid=? AND item_uuid=?`, domain, actor, id).Scan(&version); e != nil {
return e
}
if version-1 != expected {
return ErrTaskConflict
}
return nil
}
if err != nil {
return err
}
var item TaskRecord
if err = json.Unmarshal([]byte(raw), &item); err != nil {
return err
}
if item.Kind != "task" {
return ErrTaskInvalid
}
if item.Version != expected {
return ErrTaskConflict
}
var children, working bool
if err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND parent_uuid=?)`, domain, actor, id).Scan(&children); err != nil {
return err
}
if children {
return ErrTaskHasChildren
}
if err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_focus WHERE domain_uuid=? AND owner_uuid=? AND task_uuid=? AND state IN ('running','paused')) OR EXISTS(SELECT 1 FROM organizer_work_sessions WHERE domain_uuid=? AND owner_uuid=? AND task_uuid=? AND end_ms=0 AND cancelled_ms=0)`, domain, actor, id, domain, actor, id).Scan(&working); err != nil {
return err
}
if working {
return ErrTaskWorking
}
name, uid := id+".ics", id
if item.CalDAV != nil {
name, uid = item.CalDAV.Name, item.CalDAV.UID
}
now := time.Now().UnixMilli()
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_task_deletions(domain_uuid,owner_uuid,item_uuid,dav_name,dav_uid,version,deleted_at_ms) VALUES(?,?,?,?,?,?,?)`, domain, actor, id, taskDAVIndexKey(item.ProjectUUID, name), taskDAVIndexKey(item.ProjectUUID, uid), item.Version+1, now)
if err != nil {
return err
}
for _, q := range []string{
`DELETE FROM organizer_reminders WHERE domain_uuid=? AND item_uuid=?`,
`DELETE FROM organizer_task_metrics WHERE domain_uuid=? AND task_uuid=?`,
`UPDATE organizer_time_blocks SET state='unlinked' WHERE domain_uuid=? AND task_uuid=?`,
`DELETE FROM organizer_revisions WHERE domain_uuid=? AND item_uuid=?`,
`DELETE FROM organizer_items WHERE domain_uuid=? AND uuid=?`,
} {
if _, err = tx.ExecContext(ctx, q, domain, id); err != nil {
return err
}
}
if _, err = tx.ExecContext(ctx, `INSERT INTO organizer_changes(domain_uuid,item_uuid,version,actor_uuid,created_at_ms) VALUES(?,?,?,?,?)`, domain, id, item.Version+1, actor, now); err != nil {
return err
}
if _, err = s.appendTaskActivityTx(tx, domain, actor, id, "task", item.Version+1, now); err != nil {
return err
}
return tx.Commit()
}
+39 -3
View File
@@ -227,10 +227,22 @@ func (s *Store) CapturedTask(ctx context.Context, domain, actor, request, hash s
if err != nil { if err != nil {
return TaskRecord{}, err return TaskRecord{}, err
} }
// Check lifecycle before payload equality. A retained receipt must not
// disguise a deleted task as an editable version conflict.
item, err := s.GetTask(ctx, domain, actor, id)
if errors.Is(err, sql.ErrNoRows) {
if err = deletedCapture(ctx, s.DB, domain, actor, request); err != nil {
return TaskRecord{}, err
}
return TaskRecord{}, ErrTaskDeleted
}
if err != nil {
return TaskRecord{}, err
}
if stored != hash { if stored != hash {
return TaskRecord{}, ErrTaskConflict return TaskRecord{}, ErrTaskConflict
} }
return s.GetTask(ctx, domain, actor, id) return item, nil
} }
func (s *Store) CaptureTask(ctx context.Context, domain, actor, request, hash string, item TaskRecord) (TaskRecord, error) { func (s *Store) CaptureTask(ctx context.Context, domain, actor, request, hash string, item TaskRecord) (TaskRecord, error) {
@@ -240,6 +252,10 @@ func (s *Store) CaptureTask(ctx context.Context, domain, actor, request, hash st
// CaptureTaskWithWiki commits the task, receipt and optional Wiki page together. // CaptureTaskWithWiki commits the task, receipt and optional Wiki page together.
// The HTTP caller must authorize read/create/write for the exact target path. // The HTTP caller must authorize read/create/write for the exact target path.
func (s *Store) CaptureTaskWithWiki(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body string) (TaskRecord, error) { func (s *Store) CaptureTaskWithWiki(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body string) (TaskRecord, error) {
return s.captureTaskWithWiki(ctx, domain, actor, request, hash, item, target, body, "")
}
func (s *Store) captureTaskWithWiki(ctx context.Context, domain, actor, request, hash string, item TaskRecord, target, body, replaces string) (TaskRecord, error) {
if _, err := uuid.Parse(request); err != nil { if _, err := uuid.Parse(request); err != nil {
return TaskRecord{}, ErrTaskInvalid return TaskRecord{}, ErrTaskInvalid
} }
@@ -252,11 +268,31 @@ func (s *Store) CaptureTaskWithWiki(ctx context.Context, domain, actor, request,
} }
item.UUID = request item.UUID = request
out, err := s.saveTask(ctx, domain, actor, item, 0, func(tx *sql.Tx, current *TaskRecord, _ TaskRecord) error { out, err := s.saveTask(ctx, domain, actor, item, 0, func(tx *sql.Tx, current *TaskRecord, _ TaskRecord) error {
if target != "" { if replaces != "" {
if e := s.createCapturedTaskWiki(ctx, tx, domain, actor, current, target, body); e != nil { if e := deletedCapture(ctx, tx, domain, actor, replaces); e != nil {
return e return e
} }
} }
if target != "" {
if !validCapturedTaskWiki(target, body) || current.PageUUID != "" {
return ErrTaskInvalid
}
// Explicit recreation may reuse a surviving Wiki page. Its content
// and revisions are independent of task deletion and never replaced.
reused := false
if replaces != "" {
e := tx.QueryRowContext(ctx, `SELECT p.object_uuid FROM paths p JOIN objects o ON o.uuid=p.object_uuid WHERE p.domain_uuid=? AND p.path=? AND o.kind='page'`, domain, target).Scan(&current.PageUUID)
if e != nil && !errors.Is(e, sql.ErrNoRows) {
return e
}
reused = e == nil
}
if !reused {
if e := s.createCapturedTaskWiki(ctx, tx, domain, actor, current, target, body); e != nil {
return e
}
}
}
_, e := tx.ExecContext(ctx, `INSERT INTO organizer_capture_receipts VALUES(?,?,?,?,?)`, domain, actor, request, hash, item.UUID) _, e := tx.ExecContext(ctx, `INSERT INTO organizer_capture_receipts VALUES(?,?,?,?,?)`, domain, actor, request, hash, item.UUID)
return e return e
}) })
+15
View File
@@ -81,6 +81,10 @@ func (s *Store) EnsureTasksSchema() error {
UNIQUE(domain_uuid,item_uuid,version))`, UNIQUE(domain_uuid,item_uuid,version))`,
`CREATE TABLE IF NOT EXISTS organizer_activity_bridge(id INTEGER PRIMARY KEY CHECK(id=1),last_sequence INTEGER NOT NULL DEFAULT 0)`, `CREATE TABLE IF NOT EXISTS organizer_activity_bridge(id INTEGER PRIMARY KEY CHECK(id=1),last_sequence INTEGER NOT NULL DEFAULT 0)`,
`INSERT OR IGNORE INTO organizer_activity_bridge(id,last_sequence) VALUES(1,0)`, `INSERT OR IGNORE INTO organizer_activity_bridge(id,last_sequence) VALUES(1,0)`,
`CREATE TABLE IF NOT EXISTS organizer_task_deletions (
domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,item_uuid TEXT NOT NULL,
dav_name TEXT NOT NULL,dav_uid TEXT NOT NULL,version INTEGER NOT NULL,deleted_at_ms INTEGER NOT NULL,
PRIMARY KEY(domain_uuid,item_uuid))`,
} { } {
if _, err := s.DB.Exec(q); err != nil { if _, err := s.DB.Exec(q); err != nil {
return err return err
@@ -227,6 +231,17 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
if enabled, exists := states["organizer.tasks"]; exists && !enabled { if enabled, exists := states["organizer.tasks"]; exists && !enabled {
return TaskRecord{}, ErrAccessDenied return TaskRecord{}, ErrAccessDenied
} }
var deletedOwner string
err = tx.QueryRowContext(ctx, `SELECT owner_uuid FROM organizer_task_deletions WHERE domain_uuid=? AND item_uuid=?`, domain, item.UUID).Scan(&deletedOwner)
if err == nil {
if deletedOwner != actor {
return TaskRecord{}, sql.ErrNoRows
}
return TaskRecord{}, ErrTaskDeleted
}
if !errors.Is(err, sql.ErrNoRows) {
return TaskRecord{}, err
}
if item.NotifyDue || item.NotifyPlanned { if item.NotifyDue || item.NotifyPlanned {
item.ReminderTimezone = "UTC" item.ReminderTimezone = "UTC"
err = tx.QueryRowContext(ctx, `SELECT value FROM config WHERE domain_uuid=? AND key='timezone'`, domain).Scan(&item.ReminderTimezone) err = tx.QueryRowContext(ctx, `SELECT value FROM config WHERE domain_uuid=? AND key='timezone'`, domain).Scan(&item.ReminderTimezone)
+1 -1
View File
@@ -44,7 +44,7 @@ func (s *Store) PublishTaskActivity(ctx context.Context, limit int) (int, int, e
if _, err = tx.ExecContext(ctx, `UPDATE organizer_activity_bridge SET last_sequence=last_sequence WHERE id=1`); err != nil { if _, err = tx.ExecContext(ctx, `UPDATE organizer_activity_bridge SET last_sequence=last_sequence WHERE id=1`); err != nil {
return 0, 0, err return 0, 0, err
} }
rows, err := tx.QueryContext(ctx, `SELECT c.sequence,c.domain_uuid,c.item_uuid,c.version,c.actor_uuid,c.created_at_ms,COALESCE(i.kind,'') FROM organizer_changes c LEFT JOIN organizer_items i ON i.domain_uuid=c.domain_uuid AND i.uuid=c.item_uuid WHERE c.sequence>(SELECT last_sequence FROM organizer_activity_bridge WHERE id=1) ORDER BY c.sequence LIMIT ?`, limit) rows, err := tx.QueryContext(ctx, `SELECT c.sequence,c.domain_uuid,c.item_uuid,c.version,c.actor_uuid,c.created_at_ms,COALESCE(i.kind,CASE WHEN d.item_uuid IS NOT NULL THEN 'task' ELSE '' END) FROM organizer_changes c LEFT JOIN organizer_items i ON i.domain_uuid=c.domain_uuid AND i.uuid=c.item_uuid LEFT JOIN organizer_task_deletions d ON d.domain_uuid=c.domain_uuid AND d.item_uuid=c.item_uuid WHERE c.sequence>(SELECT last_sequence FROM organizer_activity_bridge WHERE id=1) ORDER BY c.sequence LIMIT ?`, limit)
if err != nil { if err != nil {
return 0, 0, err return 0, 0, err
} }
+38 -12
View File
@@ -32,7 +32,7 @@ import urllib.parse as url
import urllib.request as http import urllib.request as http
import webbrowser import webbrowser
VERSION = '0.4.0' VERSION = '0.4.2'
class Failure(Exception): class Failure(Exception):
def __init__(self, message, status=0, payload=None): def __init__(self, message, status=0, payload=None):
@@ -144,9 +144,11 @@ class Client:
except (ValueError, UnicodeError): except (ValueError, UnicodeError):
raise Failure('Invalid JSON response.') from None raise Failure('Invalid JSON response.') from None
def login(self, username, password, otp=getpass.getpass): def login(self, username, password, otp=getpass.getpass, *, remember=False):
form={'username':username,'password':password}
if remember:form['remember']='1'
try: try:
result = self.json('/_/auth/login', method='POST', form={'username': username, 'password': password}) result = self.json('/_/auth/login', method='POST', form=form)
except Failure as e: except Failure as e:
if e.status != 401 or not e.payload.get('mfa_required') or not e.payload.get('challenge_token'): if e.status != 401 or not e.payload.get('mfa_required') or not e.payload.get('challenge_token'):
raise raise
@@ -164,12 +166,13 @@ class Client:
self.token = token self.token = token
return time.time() + duration return time.time() + duration
def login_oidc(self, no_browser=False, expected_username='', *, sleep=time.sleep, clock=time.monotonic): def login_oidc(self, no_browser=False, expected_username='', *, remember=False, sleep=time.sleep, clock=time.monotonic):
verifier = secrets.token_urlsafe(32) verifier = secrets.token_urlsafe(32)
challenge = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).decode().rstrip('=') challenge = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).decode().rstrip('=')
try: try:
started = self.json('/_/auth/cli/start', method='POST', form={ form={'code_challenge':challenge,'code_challenge_method':'S256'}
'code_challenge': challenge, 'code_challenge_method': 'S256'}) if remember:form['remember']='1'
started = self.json('/_/auth/cli/start', method='POST', form=form)
except Failure as e: except Failure as e:
if e.status in (404, 405, 501): if e.status in (404, 405, 501):
raise Failure('CLI OIDC login is unavailable on this server. Check the configured server URL and deploy a server version supporting /_/auth/cli/start.', e.status) from None raise Failure('CLI OIDC login is unavailable on this server. Check the configured server URL and deploy a server version supporting /_/auth/cli/start.', e.status) from None
@@ -569,7 +572,7 @@ def tasks(client, profile, words):
for name in ('done','reopen','archive','start'): for name in ('done','reopen','archive','start'):
p=sub.add_parser(name);p.add_argument('uuid',type=task_uuid) p=sub.add_parser(name);p.add_argument('uuid',type=task_uuid)
sub.add_parser('stop');sub.add_parser('status') sub.add_parser('stop');sub.add_parser('status')
p=sub.add_parser('retry');p.add_argument('request_id',type=task_uuid) p=sub.add_parser('retry');p.add_argument('request_id',type=task_uuid);p.add_argument('--recreate-deleted',action='store_true',help='Explicitly recreate a deleted capture with a new UUID; preserve and relink any existing Wiki page')
p=sub.add_parser('report');p.add_argument('--from',dest='start');p.add_argument('--to',dest='end') p=sub.add_parser('report');p.add_argument('--from',dest='start');p.add_argument('--to',dest='end')
p=sub.add_parser('preferences');p.add_argument('--wiki-prefix');p.add_argument('--project');p.add_argument('--assignee');p.add_argument('--due-days',type=int);p.add_argument('--start-days',type=int);p.add_argument('--planned-days',type=int);p.add_argument('--review-days',type=int);p.add_argument('--estimate',type=int);p.add_argument('--complexity',type=int);p.add_argument('--digest',choices=['on','off']);p.add_argument('--at');p.add_argument('--timezone') p=sub.add_parser('preferences');p.add_argument('--wiki-prefix');p.add_argument('--project');p.add_argument('--assignee');p.add_argument('--due-days',type=int);p.add_argument('--start-days',type=int);p.add_argument('--planned-days',type=int);p.add_argument('--review-days',type=int);p.add_argument('--estimate',type=int);p.add_argument('--complexity',type=int);p.add_argument('--digest',choices=['on','off']);p.add_argument('--at');p.add_argument('--timezone')
for child in sub.choices.values():child.add_argument('--json',action='store_true') for child in sub.choices.values():child.add_argument('--json',action='store_true')
@@ -578,10 +581,19 @@ def tasks(client, profile, words):
def capture(payload): def capture(payload):
pending=profile.data.setdefault('task_outbox',{}) 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 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']) replaced=payload['request_id'] in pending and pending[payload['request_id']] != payload
pending[payload['request_id']]=payload;profile.save() pending[payload['request_id']]=payload;profile.save()
if replaced:print('Replaced the retained draft with the current input.',file=sys.stderr)
try: result=client.json(TASK_API+'capture',method='POST',data=payload) try: result=client.json(TASK_API+'capture',method='POST',data=payload)
except Failure as e: except Failure as e:
if e.status==410 and e.payload.get('error')=='deleted':
raise Failure('Draft retained. This task was deleted; normal retry will not restore it. To explicitly create a new task (preserving any existing Wiki body), use: pages task retry '+payload['request_id']+' --recreate-deleted',e.status,e.payload) from e
if e.status==409 and e.payload.get('error')=='capture_missing':
raise Failure('Draft retained. The server has a capture receipt but no task or deletion record. Server-side consistency repair is required; retry will not fix it.',e.status,e.payload) from e
if e.status==412:
raise Failure('Draft retained. This request ID conflicts with a server capture or task. An unchanged retry will not resolve it; inspect with: pages task show '+payload['request_id'],e.status,e.payload) from e
if e.status==409 and e.payload.get('error')=='note_exists':
raise Failure('Draft retained. A Wiki page already occupies the destination; it was not overwritten.',e.status,e.payload) from e
print('Draft retained; retry with: pages task retry '+payload['request_id'],file=sys.stderr) print('Draft retained; retry with: pages task retry '+payload['request_id'],file=sys.stderr)
if e.payload.get('error') == 'wiki_prefix_required': raise Failure('Set a private Wiki destination first: pages task preferences --wiki-prefix /YOUR/MAIL/PATH',e.status) from e if e.payload.get('error') == 'wiki_prefix_required': raise Failure('Set a private Wiki destination first: pages task preferences --wiki-prefix /YOUR/MAIL/PATH',e.status) from e
raise raise
@@ -606,6 +618,19 @@ def tasks(client, profile, words):
if action=='retry': if action=='retry':
payload=profile.data.get('task_outbox',{}).get(a.request_id) payload=profile.data.get('task_outbox',{}).get(a.request_id)
if not payload:raise Failure('No retained task capture with this request ID.') if not payload:raise Failure('No retained task capture with this request ID.')
if a.recreate_deleted:
pending=profile.data['task_outbox']
replacement=str(uuid.uuid5(uuid.NAMESPACE_URL,'pages:task-recreate:'+a.request_id))
payload=dict(payload,request_id=replacement,replaces_deleted=a.request_id)
if replacement in pending and pending[replacement]!=payload:
raise Failure('A different recreation draft already exists; inspect or retry it first: '+replacement)
previous=pending.copy()
pending[replacement]=payload;del pending[a.request_id]
try:profile.save()
except Exception:
profile.data['task_outbox']=previous
raise
print('Recreation draft saved. Existing Wiki content will be preserved. Retry ID: '+replacement,file=sys.stderr)
emit(capture(payload));return emit(capture(payload));return
if action in ('add','from-mail'): if action in ('add','from-mail'):
payload={'request_id':getattr(a,'request_id',None) or str(uuid.uuid4()),'title':a.title,'notes':a.notes or ''} payload={'request_id':getattr(a,'request_id',None) or str(uuid.uuid4()),'title':a.title,'notes':a.notes or ''}
@@ -622,7 +647,7 @@ def tasks(client, profile, words):
value=getattr(a,attr) value=getattr(a,attr)
if value is not None:payload[key]=task_project(client,value) if attr=='project' else value 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 # A retry of the same pending mail must not drift across a month boundary
# when Date was missing. Other changed options still fail closed. # when Date was missing. Changed input replaces the pending draft below.
old=profile.data.get('task_outbox',{}).get(payload['request_id']) 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'}: 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() payload=old.copy()
@@ -834,6 +859,7 @@ def main(argv=None):
login = argparse.ArgumentParser(prog='pages login', description='Log into the configured connection. Password and TOTP are prompted privately.') login = argparse.ArgumentParser(prog='pages login', description='Log into the configured connection. Password and TOTP are prompted privately.')
login.add_argument('--oidc', action='store_true', help='Authenticate and approve in a browser; no local password required') login.add_argument('--oidc', action='store_true', help='Authenticate and approve in a browser; no local password required')
login.add_argument('--no-browser', action='store_true', help='Print the browser login URL without opening it (requires --oidc)') login.add_argument('--no-browser', action='store_true', help='Print the browser login URL without opening it (requires --oidc)')
login.add_argument('--remember', action='store_true', help='Keep this trusted device signed in for up to 30 days, subject to server policy')
login_args = login.parse_args(args.args) login_args = login.parse_args(args.args)
if login_args.no_browser and not login_args.oidc: login.error('--no-browser requires --oidc') if login_args.no_browser and not login_args.oidc: login.error('--no-browser requires --oidc')
elif '--help' in args.args: elif '--help' in args.args:
@@ -852,13 +878,13 @@ def main(argv=None):
print('WARNING: --insecure disables TLS certificate and hostname verification for this invocation. Credentials and data can be intercepted; this option is not saved.', file=sys.stderr) print('WARNING: --insecure disables TLS certificate and hostname verification for this invocation. Credentials and data can be intercepted; this option is not saved.', file=sys.stderr)
if args.command == 'login': if args.command == 'login':
if not login_args.oidc and not spec.get('username'): raise Failure('Set your account with pages configure --username NAME, or use pages login --oidc.') if not login_args.oidc and not spec.get('username'): raise Failure('Set your account with pages configure --username NAME, or use pages login --oidc.')
if profile.data.get('token'): raise Failure('Log out this profile before replacing its session.') if profile.data.get('token') and profile.data.get('expires',0)>time.time(): raise Failure('Log out this profile before replacing its active session.')
client = Client(spec['origin'], lang=lang, insecure=args.insecure) client = Client(spec['origin'], lang=lang, insecure=args.insecure)
if login_args.oidc: if login_args.oidc:
expires, username = client.login_oidc(login_args.no_browser, spec.get('username', '')) expires, username = client.login_oidc(login_args.no_browser, spec.get('username', ''), remember=login_args.remember)
else: else:
username = spec['username'] username = spec['username']
expires = client.login(username, getpass.getpass('Password: ')) expires = client.login(username, getpass.getpass('Password: '), remember=login_args.remember)
same_identity = profile.data.get('origin') == client.base and profile.data.get('username') == username same_identity = profile.data.get('origin') == client.base and profile.data.get('username') == username
pending = profile.data.get('task_outbox', {}) pending = profile.data.get('task_outbox', {})
if pending and not same_identity: if pending and not same_identity:
+148 -4
View File
@@ -9,6 +9,74 @@ import unittest
m=runpy.run_path(str(Path(__file__).with_name('pages'))) m=runpy.run_path(str(Path(__file__).with_name('pages')))
class ProductivityTests(unittest.TestCase): class ProductivityTests(unittest.TestCase):
def test_deleted_capture_message_retains_draft_without_retry_loop(self):
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
original={'request_id':ident,'title':'Private title','notes':'Private notes'}
for status,code,message in [(410,'deleted','--recreate-deleted'),(409,'capture_missing','consistency repair'),(412,'conflict','unchanged retry'),(409,'note_exists','not overwritten')]:
profile=SimpleNamespace(data={'task_outbox':{ident:original.copy()}},save=lambda:None)
calls=[]
def send(*args,**kw):
calls.append(kw)
raise m['Failure']('old generic message',status,{'error':code})
output=io.StringIO()
with contextlib.redirect_stderr(output),self.assertRaises(m['Failure']) as error:
m['tasks'](SimpleNamespace(json=send),profile,['retry',ident])
self.assertIn(message,str(error.exception))
self.assertNotIn('Private',str(error.exception)+output.getvalue())
self.assertNotIn('retry with:',output.getvalue())
self.assertEqual(profile.data['task_outbox'][ident],original)
self.assertEqual(len(calls),1)
def test_recreate_deleted_persists_successor_and_retries_same_id(self):
import uuid
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
replacement=str(uuid.uuid5(uuid.NAMESPACE_URL,'pages:task-recreate:'+ident))
payload={'request_id':ident,'title':'Private title','wiki_body':'Private body','wiki_suffix':'2030/01/'+ident}
saved,calls=[],[]
profile=SimpleNamespace(data={'task_outbox':{ident:payload.copy()}})
profile.save=lambda:saved.append(json.loads(json.dumps(profile.data)))
def send(route,**kw):
calls.append(kw['data'].copy())
self.assertEqual(saved[-1]['task_outbox'][replacement],kw['data'])
self.assertNotIn(ident,saved[-1]['task_outbox'])
if len(calls)==1:raise m['Failure']('Connection lost')
return {'item':{'uuid':replacement}}
output,error=io.StringIO(),io.StringIO()
with contextlib.redirect_stdout(output),contextlib.redirect_stderr(error):
with self.assertRaises(m['Failure']):m['tasks'](SimpleNamespace(json=send),profile,['retry',ident,'--recreate-deleted'])
self.assertEqual(len(profile.data['task_outbox']),1)
m['tasks'](SimpleNamespace(json=send),profile,['retry',replacement])
self.assertEqual(calls[0],calls[1])
self.assertEqual(calls[0]['request_id'],replacement)
self.assertEqual(calls[0]['replaces_deleted'],ident)
self.assertEqual(calls[0]['wiki_suffix'],payload['wiki_suffix'])
self.assertEqual(calls[0]['wiki_body'],payload['wiki_body'])
self.assertEqual(profile.data['task_outbox'],{})
self.assertIn(replacement,error.getvalue())
self.assertNotIn('Private',error.getvalue())
def test_recreate_deleted_save_failure_keeps_original_and_sends_nothing(self):
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
payload={'request_id':ident,'title':'Draft'}
def fail():raise m['Failure']('disk full')
profile=SimpleNamespace(data={'task_outbox':{ident:payload.copy()}},save=fail)
calls=[]
with self.assertRaises(m['Failure']):m['tasks'](SimpleNamespace(json=lambda *a,**kw:calls.append(kw)),profile,['retry',ident,'--recreate-deleted'])
self.assertEqual(calls,[])
self.assertEqual(profile.data['task_outbox'],{ident:payload})
def test_recreate_deleted_never_clobbers_different_successor_draft(self):
import uuid
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
replacement=str(uuid.uuid5(uuid.NAMESPACE_URL,'pages:task-recreate:'+ident))
pending={ident:{'request_id':ident,'title':'Original'},replacement:{'request_id':replacement,'title':'Different'}}
before=json.loads(json.dumps(pending))
calls=[]
profile=SimpleNamespace(data={'task_outbox':pending},save=lambda:calls.append('save'))
with self.assertRaises(m['Failure']):m['tasks'](SimpleNamespace(json=lambda *a,**kw:calls.append('send')),profile,['retry',ident,'--recreate-deleted'])
self.assertEqual(calls,[])
self.assertEqual(pending,before)
def test_mail_path_priority_and_dates(self): def test_mail_path_priority_and_dates(self):
import datetime,hashlib import datetime,hashlib
ident='06cb3a24-61f8-4a9f-a0bf-89eea9632f25' ident='06cb3a24-61f8-4a9f-a0bf-89eea9632f25'
@@ -24,7 +92,7 @@ class ProductivityTests(unittest.TestCase):
raw=b'Subject: [../unsafe 123] Title\r\n'+date+b'\r\nbody' raw=b'Subject: [../unsafe 123] Title\r\n'+date+b'\r\nbody'
self.assertEqual(suffix(raw,ident,now),'2030/02/'+hashlib.sha256(raw).hexdigest()) self.assertEqual(suffix(raw,ident,now),'2030/02/'+hashlib.sha256(raw).hexdigest())
def test_pending_mail_month_and_options_are_preserved(self): def test_pending_mail_keeps_month_but_replaces_changed_options(self):
from unittest.mock import patch from unittest.mock import patch
raw=b'Subject: Test\r\nMessage-ID: <same@example.invalid>\r\n\r\nbody' raw=b'Subject: Test\r\nMessage-ID: <same@example.invalid>\r\n\r\nbody'
calls=[] calls=[]
@@ -37,10 +105,86 @@ class ProductivityTests(unittest.TestCase):
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']): 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']) m['tasks'](client,profile,['from-mail'])
self.assertEqual(calls[0],calls[1]) self.assertEqual(calls[0],calls[1])
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),self.assertRaises(m['Failure']): with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
m['tasks'](client,profile,['from-mail','--wiki-prefix','/changed']) m['tasks'](client,profile,['from-mail','--wiki-prefix','/changed'])
self.assertEqual(len(calls),2) self.assertEqual(len(calls),3)
self.assertEqual(next(iter(profile.data['task_outbox'].values())),calls[0]) self.assertEqual(calls[2]['request_id'],calls[0]['request_id'])
self.assertEqual(calls[2]['wiki_prefix'],'/changed')
self.assertEqual(next(iter(profile.data['task_outbox'].values())),calls[2])
def test_changed_capture_is_saved_before_send_and_retained_on_conflict(self):
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
saved,calls=[],[]
old={'request_id':ident,'title':'Old draft','notes':'Old private notes'}
profile=SimpleNamespace(data={'task_outbox':{ident:old}})
profile.save=lambda:saved.append(json.loads(json.dumps(profile.data)))
def send(route,**kw):
payload=kw['data'].copy();calls.append(payload)
self.assertEqual(saved[-1]['task_outbox'][ident],payload)
if len(calls)==1:raise m['Failure']('conflict',412,{'error':'conflict'})
return {'item':{'uuid':ident}}
client=SimpleNamespace(json=send)
out,err=io.StringIO(),io.StringIO()
with contextlib.redirect_stdout(out),contextlib.redirect_stderr(err):
with self.assertRaises(m['Failure']) as failure:
m['tasks'](client,profile,['add','New draft','--request-id',ident,'--notes','New private notes'])
self.assertEqual(failure.exception.status,412)
self.assertEqual(profile.data['task_outbox'][ident],calls[0])
self.assertEqual(len(calls),1) # No automatic server overwrite/retry.
m['tasks'](client,profile,['retry',ident])
self.assertEqual(calls[0],calls[1])
self.assertEqual(calls[0]['title'],'New draft')
self.assertEqual(profile.data['task_outbox'],{})
self.assertIn('Replaced the retained draft',err.getvalue())
self.assertNotIn('private notes',err.getvalue())
self.assertEqual(json.loads(out.getvalue())['item']['uuid'],ident)
def test_replacing_draft_does_not_send_when_local_save_fails(self):
ident='b5550cab-22d4-54eb-b06d-3b432d3f5101'
def fail_save():raise m['Failure']('local write failed')
profile=SimpleNamespace(data={'task_outbox':{ident:{'request_id':ident,'title':'Old','notes':''}}},save=fail_save)
calls=[]
client=SimpleNamespace(json=lambda *a,**kw:calls.append(kw))
with self.assertRaises(m['Failure']):m['tasks'](client,profile,['add','New','--request-id',ident])
self.assertEqual(calls,[])
def test_full_outbox_allows_replacement_but_not_new_id(self):
import uuid
pending={str(uuid.uuid4()):{'title':'Old'} for _ in range(20)}
ident=next(iter(pending))
profile=SimpleNamespace(data={'task_outbox':pending},save=lambda:None)
calls=[]
def send(route,**kw):
calls.append(kw['data'].copy())
raise m['Failure']('offline')
client=SimpleNamespace(json=send)
with contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
m['tasks'](client,profile,['add','Replacement','--request-id',ident])
self.assertEqual(len(calls),1)
self.assertEqual(pending[ident]['title'],'Replacement')
with self.assertRaises(m['Failure']):m['tasks'](client,profile,['add','Another'])
self.assertEqual(len(calls),1)
self.assertEqual(len(pending),20)
def test_reimported_mail_replaces_body_and_removes_obsolete_options(self):
from unittest.mock import patch
raw=b'Subject: Old\r\nMessage-ID: <same@example.invalid>\r\n\r\nOLD BODY'
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)
changed=raw.replace(b'Subject: Old',b'Subject: New').replace(b'OLD BODY',b'NEW BODY')
for mail,args in [(raw,['--wiki-prefix','/old']),(changed,['--wiki-prefix','/new']),(changed,['--metadata-only'])]:
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(mail))),contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
m['tasks'](client,profile,['from-mail',*args])
self.assertEqual(len({c['request_id'] for c in calls}),1)
self.assertEqual(calls[1]['title'],'New')
self.assertIn('NEW BODY',calls[1]['wiki_body'])
self.assertNotIn('OLD BODY',calls[1]['wiki_body'])
for key in ('wiki_body','wiki_prefix','wiki_suffix'):self.assertNotIn(key,calls[2])
self.assertEqual(next(iter(profile.data['task_outbox'].values())),calls[2])
def test_mail_privacy_and_long_subject_override(self): 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' 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'
+55
View File
@@ -0,0 +1,55 @@
import contextlib
import io
import os
from pathlib import Path
import runpy
import time
import tempfile
import unittest
from unittest.mock import patch
m = runpy.run_path(str(Path(__file__).with_name('pages')))
class RememberTests(unittest.TestCase):
def test_expired_login_retains_same_account_drafts_and_path(self):
with tempfile.TemporaryDirectory() as root, patch.dict(os.environ, {'XDG_CONFIG_HOME': root}), contextlib.redirect_stdout(io.StringIO()):
with m['Configuration']().locked() as config:
config.data = {'version': 1, 'default_profile': 'default', 'profiles': {'default': {'origin': 'https://wiki.example', 'username': 'anya', 'lang': 'auto'}}}
config.save()
with m['Profile']('default').locked() as profile:
profile.data = {'origin': 'https://wiki.example', 'username': 'anya', 'token': 'expired', 'expires': 1,
'cwd': '/projects/demo', 'task_outbox': {'request': {'title': 'synthetic draft'}}}
profile.save()
def login(client, username, password, *, remember=False):
self.assertTrue(remember)
client.token = 'pw_api_'+'x'*43
return time.time()+2592000
with patch.object(m['Client'], 'login', login), patch.object(m['getpass'], 'getpass', return_value='synthetic'):
m['main'](['login', '--remember'])
with m['Profile']('default').locked() as profile:
self.assertEqual(profile.data['cwd'], '/projects/demo')
self.assertEqual(profile.data['task_outbox']['request']['title'], 'synthetic draft')
self.assertTrue(profile.data['token'].startswith('pw_api_'))
def test_password_choice_is_explicit_and_bound_before_totp(self):
for remember in (False, True):
client = m['Client']('https://wiki.example')
challenge = m['Failure']('MFA', 401, {'mfa_required': True, 'challenge_token': 'challenge'})
result = {'access_token': 'pw_api_' + 'x'*43, 'token_type': 'Bearer', 'expires_in': 2592000}
with patch.object(client, 'json', side_effect=[challenge, result]) as api:
expiry = client.login('anya', 'synthetic-password', lambda _: '123456', remember=remember)
self.assertEqual(api.call_args_list[0].kwargs['form'].get('remember'), '1' if remember else None)
self.assertNotIn('remember', api.call_args_list[1].kwargs['form'])
self.assertAlmostEqual(expiry - time.time(), 2592000, delta=2)
def test_oidc_choice_is_bound_at_start(self):
for remember in (False, True):
client = m['Client']('https://wiki.example')
start = {'device_code': 'd'*43, 'verification_uri': '/_/auth/cli/verify?request='+'r'*43,
'user_code': 'ABCD-1234', 'expires_in': 300, 'interval': 5}
result = {'access_token': 'pw_api_'+'x'*43, 'token_type': 'Bearer', 'expires_in': 2592000, 'username': 'anya'}
with patch.object(client, 'json', side_effect=[start, result]) as api, contextlib.redirect_stdout(io.StringIO()):
client.login_oidc(True, remember=remember, sleep=lambda _: None, clock=lambda: 0)
self.assertEqual(api.call_args_list[0].kwargs['form'].get('remember'), '1' if remember else None)
self.assertNotIn('remember', api.call_args_list[1].kwargs['form'])
+46
View File
@@ -5,6 +5,7 @@ import json
from pathlib import Path from pathlib import Path
import runpy import runpy
import sys import sys
import uuid
from types import SimpleNamespace from types import SimpleNamespace
from unittest.mock import patch from unittest.mock import patch
from email.message import EmailMessage from email.message import EmailMessage
@@ -61,5 +62,50 @@ def run():
output=io.StringIO() output=io.StringIO()
with contextlib.redirect_stdout(output):m['contacts'](client,['export',contact['uuid']]) with contextlib.redirect_stdout(output):m['contacts'](client,['export',contact['uuid']])
assert 'UID:urn:test:cli' in output.getvalue() assert 'UID:urn:test:cli' in output.getvalue()
# Failed captures can be replaced locally; committed receipts remain protected.
request_id=str(uuid.uuid4())
with contextlib.redirect_stderr(io.StringIO()):
try:task('add','Rejected draft','--request-id',request_id,'--estimate','-1')
except m['Failure'] as error:assert error.status==422
else:raise AssertionError('Invalid estimate accepted')
assert profile.data['task_outbox'][request_id]['estimate_minutes']==-1
corrected=task('add','Corrected draft','--request-id',request_id,'--estimate','15')['item']
assert corrected['uuid']==request_id and corrected['title']=='Corrected draft'
assert request_id not in profile.data['task_outbox']
try:task('add','Changed after commit','--request-id',request_id,'--estimate','30')
except m['Failure'] as error:assert error.status==412
else:raise AssertionError('Committed capture silently overwritten')
assert profile.data['task_outbox'][request_id]['title']=='Changed after commit'
stored=task('show',request_id)['item']
assert stored['title']=='Corrected draft' and stored['estimate_minutes']==15
# Deleted receipts must not be mistaken for editable conflicts. An
# explicit recreation preserves the old tombstone and changes identity.
client.request(m['TASK_API']+'items/'+request_id,method='DELETE',etag='"'+str(stored['version'])+'"')
with contextlib.redirect_stderr(io.StringIO()):
try:task('retry',request_id)
except m['Failure'] as error:
assert error.status==410 and '--recreate-deleted' in str(error)
else:raise AssertionError('Deleted task implicitly recreated')
recreated=task('retry',request_id,'--recreate-deleted')['item']
replacement=str(uuid.uuid5(uuid.NAMESPACE_URL,'pages:task-recreate:'+request_id))
assert recreated['uuid']==replacement and recreated['title']=='Changed after commit'
assert recreated['estimate_minutes']==30 and not profile.data.get('task_outbox')
try:task('show',request_id)
except m['Failure'] as error:assert error.status==404
else:raise AssertionError('Deleted UUID resurrected')
# Reimport a deleted mail with a changed body: reconnect the surviving
# Wiki note, without overwriting its independent content or revision.
mail_id=captured['item']['uuid']
client.request(m['TASK_API']+'items/'+mail_id,method='DELETE',etag='"1"')
changed_mail=mail.replace(b'Private mail body',b'Changed private body')
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(changed_mail))),contextlib.redirect_stderr(io.StringIO()):
try:task('from-mail')
except m['Failure'] as error:assert error.status==410
else:raise AssertionError('Deleted mail task recreated implicitly')
with contextlib.redirect_stderr(io.StringIO()):recreated_mail=task('retry',mail_id,'--recreate-deleted')
assert recreated_mail['item']['page_uuid']==captured['item']['page_uuid']
assert recreated_mail['page_path']==captured['page_path']
body,_=client.raw('path:'+recreated_mail['page_path'])
assert 'Private mail body' in body.decode() and 'Changed private body' not in body.decode()
if __name__=='__main__':run() if __name__=='__main__':run()
+3
View File
@@ -191,3 +191,6 @@
backdrop-filter: none; backdrop-filter: none;
} }
} }
/* Keep the persistent-session control compact and touchable in all themes. */
.auth-form label.auth-remember{display:flex;flex-direction:row;align-items:center;gap:.65rem;min-height:44px;font-size:.85rem;cursor:pointer}
.auth-form label.auth-remember input{width:1.15rem;height:1.15rem;min-height:0;flex:0 0 auto;padding:0;margin:0;accent-color:var(--accent)}
+13
View File
@@ -0,0 +1,13 @@
.browser-upload-target{outline:2px dashed var(--accent,var(--link));outline-offset:-4px;background:color-mix(in srgb,var(--accent,var(--link)) 8%,var(--bg))}
.browser-upload-queue{position:fixed;right:1rem;bottom:1rem;z-index:950;width:min(27rem,calc(100vw - 2rem));box-sizing:border-box;background:var(--bg);color:var(--fg);border:1px solid var(--border,var(--border-soft));border-radius:.6rem;box-shadow:0 .5rem 2rem #0005;padding:.5rem}
.browser-upload-queue[hidden],.browser-upload-queue [hidden]{display:none}
.browser-upload-queue header,.browser-upload-queue footer{display:flex;align-items:center;gap:.5rem}
.browser-upload-queue header strong{flex:1}.browser-upload-queue footer{justify-content:flex-end}
.browser-upload-queue button{font:inherit;color:inherit;background:transparent;border:1px solid var(--border-soft);border-radius:.3rem;min-width:2rem;min-height:2rem;cursor:pointer}
.browser-upload-queue button:disabled{opacity:.4;cursor:default}
.browser-upload-queue ol{list-style:none;margin:.4rem 0;padding:0;max-height:40dvh;overflow:auto;overscroll-behavior:contain}
.browser-upload-queue li{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:.2rem .5rem;padding:.4rem 0;border-top:1px solid var(--border-soft)}
.browser-upload-queue .upload-name{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.browser-upload-queue .upload-state{font-size:.8rem;grid-column:1/-1;overflow-wrap:anywhere}
.browser-upload-queue progress{width:100%;height:.35rem;grid-column:1/-1;accent-color:var(--accent,var(--link))}.browser-upload-queue [data-state=failed] .upload-state{color:var(--danger,#e77373)}
.browser-upload-queue .upload-notice{margin:.3rem 0;font-size:.85rem}.browser-upload-queue .upload-notice:empty{display:none}
@media(max-width:600px){.browser-upload-queue{right:.5rem;bottom:.5rem;width:calc(100vw - 1rem)}.browser-upload-queue button{min-height:44px;min-width:44px}.browser-upload-queue ol{max-height:35dvh}}
+1 -1
View File
@@ -1 +1 @@
:root{color-scheme:light dark}html,body{margin:0;width:100%;height:100%;overflow:hidden;background:#fff;color:#222;font:14px system-ui}canvas{display:block;width:100%;height:100%;outline:none}#status{position:absolute;inset:1rem auto auto 1rem;max-width:calc(100% - 4rem);margin:0;padding:.75rem 1rem;border-radius:.4rem;background:#222;color:#fff;z-index:1}#status[hidden]{display:none} :root{color-scheme:light dark}html,body{margin:0;width:100%;height:100%;overflow:hidden;background:#fff;color:#222;font:14px system-ui}canvas{display:block;width:100%;height:100%;outline:none}#status{position:absolute;inset:1rem auto auto 1rem;max-width:calc(100% - 4rem);margin:0;padding:.75rem 1rem;border-radius:.4rem;background:#222;color:#fff;z-index:1}#status[hidden],canvas[hidden]{display:none}
+7 -4
View File
@@ -1,5 +1,8 @@
.feeds-page{height:100dvh;overflow:hidden;display:flex;flex-direction:column;background:var(--bg);color:var(--fg)} .feeds-page{height:100dvh;overflow:hidden;display:flex;flex-direction:column;background:var(--bg);color:var(--fg)}
.feed-external{width:calc(100vw - 1.5rem);height:calc(100dvh - 1.5rem);max-width:none;max-height:none;box-sizing:border-box;margin:auto;padding:0;background:var(--bg,#111);color:var(--fg);border:1px solid var(--border,#8885);border-radius:.5rem;overflow:hidden}.feed-external[open]{display:flex;flex-direction:column}.feed-external::backdrop{background:#0009}.feed-external-bar{display:flex;align-items:center;gap:.5rem;padding:.3rem .5rem;flex-shrink:0}.feed-external-bar span{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.feed-external-bar a{padding:.3rem;text-decoration:none;font-size:1.2rem}.feed-external iframe{flex:1;width:100%;min-height:0;border:0;background:#fff}@media(max-width:600px){.feed-external{width:100vw;height:100dvh;border:0;border-radius:0}} .feed-external{width:calc(100vw - 1.5rem);height:calc(100dvh - 1.5rem);max-width:none;max-height:none;box-sizing:border-box;margin:auto;padding:0;background:var(--bg,#111);color:var(--fg);border:1px solid var(--border,#8885);border-radius:.5rem;overflow:hidden}.feed-external[open]{display:flex;flex-direction:column}.feed-external::backdrop{background:#0009}.feed-external-bar{display:flex;align-items:center;gap:.5rem;padding:.3rem .5rem;flex-shrink:0}.feed-external-bar span{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.feed-external-bar a{padding:.3rem;text-decoration:none;font-size:1.2rem}.feed-external iframe{flex:1;width:100%;min-height:0;border:0;background:#fff}.feed-gecko-find{display:flex;align-items:center;gap:.3rem;padding:.3rem .5rem;flex-shrink:0}.feed-gecko-find[hidden]{display:none}.feed-gecko-find input{flex:1;min-width:0;max-width:30rem}.feed-gecko-find output{font-size:.85rem}.feed-gecko-find button{min-width:2rem}@media(max-width:600px){.feed-external{width:100vw;height:100dvh;border:0;border-radius:0}.feed-external-bar{gap:.15rem}.feed-external-bar button,.feed-gecko-find button{min-height:44px}}
#feeds-app form.feed-gecko-find{display:flex;gap:.3rem}
#feeds-app form.feed-gecko-find[hidden]{display:none}
#feed-columns>span{white-space:nowrap}
.feed-help{display:flex;align-items:center;gap:.5rem;padding:.25rem 0;font-size:.78rem;flex-shrink:0}.feed-help[hidden]{display:none}.feed-help span{flex:1;min-width:0;overflow-wrap:anywhere}.feed-help button{flex-shrink:0} .feed-help{display:flex;align-items:center;gap:.5rem;padding:.25rem 0;font-size:.78rem;flex-shrink:0}.feed-help[hidden]{display:none}.feed-help span{flex:1;min-width:0;overflow-wrap:anywhere}.feed-help button{flex-shrink:0}
.feed-capture{width:min(42rem,calc(100vw - 2rem));max-height:calc(100dvh - 2rem);box-sizing:border-box;overflow:auto;background:var(--bg,#111);color:var(--fg);border:1px solid var(--border,#8885);border-radius:.6rem;padding:1rem;box-shadow:0 1rem 4rem #0007}.feed-capture::backdrop{background:#0008}.feed-capture-heading{display:flex;align-items:center;justify-content:space-between;gap:.5rem}.feed-capture h2{font-size:1.05rem;margin:0}.feed-capture-heading,.feed-capture-field,.feed-capture-tokens,.feed-capture-destination,.feed-capture-actions,.feed-capture .feed-warning{grid-column:1/-1}#feeds-app .feed-capture form{grid-template-columns:1fr 1fr;gap:.65rem}#feeds-app .feed-capture .feed-capture-check{display:flex;align-items:center;gap:.4rem}#feeds-app .feed-capture input[type=checkbox]{width:1rem;min-height:1rem;flex-shrink:0}.feed-capture-check:has([name=confirm]){grid-column:1/-1}.feed-capture-tokens,.feed-capture-actions{display:flex;gap:.35rem;flex-wrap:wrap}.feed-capture-actions{justify-content:flex-end}.feed-capture-destination{font-size:.75rem;overflow-wrap:anywhere;opacity:.8}.feed-capture .feed-warning:empty{display:none}.feed-capture-field:has([name=prefix]){position:relative}.feed-capture-field:has([name=prefix]) a{position:absolute;right:.1rem;top:0;text-decoration:none}@media(max-width:600px){#feeds-app .feed-capture form{grid-template-columns:1fr}.feed-capture{padding:.75rem}} .feed-capture{width:min(42rem,calc(100vw - 2rem));max-height:calc(100dvh - 2rem);box-sizing:border-box;overflow:auto;background:var(--bg,#111);color:var(--fg);border:1px solid var(--border,#8885);border-radius:.6rem;padding:1rem;box-shadow:0 1rem 4rem #0007}.feed-capture::backdrop{background:#0008}.feed-capture-heading{display:flex;align-items:center;justify-content:space-between;gap:.5rem}.feed-capture h2{font-size:1.05rem;margin:0}.feed-capture-heading,.feed-capture-field,.feed-capture-tokens,.feed-capture-destination,.feed-capture-actions,.feed-capture .feed-warning{grid-column:1/-1}#feeds-app .feed-capture form{grid-template-columns:1fr 1fr;gap:.65rem}#feeds-app .feed-capture .feed-capture-check{display:flex;align-items:center;gap:.4rem}#feeds-app .feed-capture input[type=checkbox]{width:1rem;min-height:1rem;flex-shrink:0}.feed-capture-check:has([name=confirm]){grid-column:1/-1}.feed-capture-tokens,.feed-capture-actions{display:flex;gap:.35rem;flex-wrap:wrap}.feed-capture-actions{justify-content:flex-end}.feed-capture-destination{font-size:.75rem;overflow-wrap:anywhere;opacity:.8}.feed-capture .feed-warning:empty{display:none}.feed-capture-field:has([name=prefix]){position:relative}.feed-capture-field:has([name=prefix]) a{position:absolute;right:.1rem;top:0;text-decoration:none}@media(max-width:600px){#feeds-app .feed-capture form{grid-template-columns:1fr}.feed-capture{padding:.75rem}}
.feed-folder-row{display:flex;align-items:center;min-width:0}#feeds-app .feed-folder-toggle{flex:0 0 1.7rem;border:0;padding:.15rem;min-width:1.7rem}#feeds-app .feed-folder-name{display:flex;align-items:center;gap:.3rem;flex:1;min-width:0;text-align:left;border:0;font-size:.78rem;padding:.2rem}.feed-folder-name span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.feed-folder-name svg{width:1rem;height:1rem;flex-shrink:0;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linejoin:round}.feed-folder>.feed-subscriptions{padding-left:1.1rem;border-left:1px solid var(--border,#8885);margin-left:.8rem}.feed-catalog .feed-subscriptions[hidden]{display:none}.feed-folder small{font-size:.7rem;opacity:.7;padding:.3rem}.feed-catalog button[aria-current=true]{background:color-mix(in srgb,var(--accent,#659de4) 22%,transparent)!important}.feed-tree-all{width:100%;text-align:left}.feed-folders{min-width:0} .feed-folder-row{display:flex;align-items:center;min-width:0}#feeds-app .feed-folder-toggle{flex:0 0 1.7rem;border:0;padding:.15rem;min-width:1.7rem}#feeds-app .feed-folder-name{display:flex;align-items:center;gap:.3rem;flex:1;min-width:0;text-align:left;border:0;font-size:.78rem;padding:.2rem}.feed-folder-name span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.feed-folder-name svg{width:1rem;height:1rem;flex-shrink:0;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linejoin:round}.feed-folder>.feed-subscriptions{padding-left:1.1rem;border-left:1px solid var(--border,#8885);margin-left:.8rem}.feed-catalog .feed-subscriptions[hidden]{display:none}.feed-folder small{font-size:.7rem;opacity:.7;padding:.3rem}.feed-catalog button[aria-current=true]{background:color-mix(in srgb,var(--accent,#659de4) 22%,transparent)!important}.feed-tree-all{width:100%;text-align:left}.feed-folders{min-width:0}
@@ -11,6 +14,6 @@
#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} #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} .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-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)} .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 3.3rem 3.4rem 7rem 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: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 3.3rem 3.4rem 6rem 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}} @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.2rem 3.1rem 3.2rem minmax(0,1fr);font-size:.85rem}.feed-row{min-height:2.75rem}#feed-columns>span:nth-child(4),.feed-row>span:nth-child(4){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}}
+6
View File
@@ -5,6 +5,12 @@ body {
margin: 0; margin: 0;
} }
.csv-projection { max-width:100%; overflow:auto; }
.csv-projection table { border-collapse:collapse; font-size:.9rem; }
.csv-projection th,.csv-projection td { padding:.25rem .5rem; border:1px solid var(--border-soft); white-space:pre-wrap; overflow-wrap:anywhere; min-width:3rem; max-width:30rem; }
.csv-projection th { background:var(--row-hover,var(--bg)); text-align:left; }
.csv-projection caption { text-align:left; font-size:.8rem; padding:.2rem 0; }
a { a {
color: var(--link); color: var(--link);
} }
+4
View File
@@ -19,6 +19,10 @@ body:has(#tasks-app)>.topbar{min-width:0}#tasks-app{box-sizing:border-box}
#tasks-app button{font:inherit;color:var(--fg);border:1px solid var(--border,#8885);background:var(--panel,var(--bg));border-radius:.45rem;padding:.5rem .7rem;cursor:pointer}#tasks-app button:hover{border-color:var(--accent)}#tasks-app :focus-visible{outline:2px solid var(--accent);outline-offset:2px}#tasks-app button:disabled{opacity:.5;cursor:default} #tasks-app button{font:inherit;color:var(--fg);border:1px solid var(--border,#8885);background:var(--panel,var(--bg));border-radius:.45rem;padding:.5rem .7rem;cursor:pointer}#tasks-app button:hover{border-color:var(--accent)}#tasks-app :focus-visible{outline:2px solid var(--accent);outline-offset:2px}#tasks-app button:disabled{opacity:.5;cursor:default}
#tasks-capture{display:flex;gap:.5rem;margin:1rem 0}#tasks-quick-title{flex:1}.tasks-search{display:flex;align-items:center;gap:.6rem;margin:1rem 0}.tasks-search input{flex:1}#tasks-status:empty{display:none} #tasks-capture{display:flex;gap:.5rem;margin:1rem 0}#tasks-quick-title{flex:1}.tasks-search{display:flex;align-items:center;gap:.6rem;margin:1rem 0}.tasks-search input{flex:1}#tasks-status:empty{display:none}
#tasks-list{border-top:1px solid var(--border,#8885)}.task-row{display:flex;align-items:center;gap:.8rem;padding:.6rem .2rem;border-bottom:1px solid var(--border,#8885);content-visibility:auto;contain-intrinsic-size:auto 62px}.task-row-main{min-width:0;flex:1;display:flex;flex-direction:column;gap:.2rem}.task-row-main>a{color:var(--fg);text-decoration:none;overflow-wrap:anywhere}.task-row-main>a:hover{color:var(--accent)}.task-row[data-done=true] .task-row-main>a{text-decoration:line-through;opacity:.65}.task-row-meta{display:flex;gap:.7rem;flex-wrap:wrap}.task-row-meta .task-overdue{color:var(--danger,#da6161);opacity:1}#tasks-more{margin:1rem 0;width:100%} #tasks-list{border-top:1px solid var(--border,#8885)}.task-row{display:flex;align-items:center;gap:.8rem;padding:.6rem .2rem;border-bottom:1px solid var(--border,#8885);content-visibility:auto;contain-intrinsic-size:auto 62px}.task-row-main{min-width:0;flex:1;display:flex;flex-direction:column;gap:.2rem}.task-row-main>a{color:var(--fg);text-decoration:none;overflow-wrap:anywhere}.task-row-main>a:hover{color:var(--accent)}.task-row[data-done=true] .task-row-main>a{text-decoration:line-through;opacity:.65}.task-row-meta{display:flex;gap:.7rem;flex-wrap:wrap}.task-row-meta .task-overdue{color:var(--danger,#da6161);opacity:1}#tasks-more{margin:1rem 0;width:100%}
#tasks-app #tasks-delete{color:var(--danger,#da6161);border-color:currentColor}
#tasks-app a.task-footer-link{display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;font:inherit;line-height:normal;color:var(--fg);background:var(--panel,var(--bg));border:1px solid var(--border,#8885);border-radius:.45rem;padding:.5rem .7rem;text-decoration:none}
#tasks-app a.task-footer-link:hover{border-color:var(--accent);color:var(--accent)}
@media(max-width:760px){#tasks-form>footer>button,#tasks-form>footer>a.task-footer-link{min-height:44px}}
#tasks-dialog{box-sizing:border-box;color:var(--fg);background:var(--panel,var(--bg));border:1px solid var(--border,#8885);border-radius:1rem;width:min(680px,95vw);max-height:92dvh;padding:1.5rem;box-shadow:0 1rem 4rem #0005;overflow:auto}#tasks-dialog::backdrop{background:#0007;backdrop-filter:blur(3px)}#tasks-fields{display:grid;grid-template-columns:1fr 1fr;gap:.8rem;margin:1rem 0}#tasks-fields label{display:flex;flex-direction:column;gap:.3rem;font-size:.9rem}#tasks-fields label.task-full{grid-column:1/-1}#tasks-fields input,#tasks-fields select,#tasks-fields textarea{width:100%}#tasks-fields textarea{min-height:7rem;resize:vertical}#tasks-fields a{overflow-wrap:anywhere;color:var(--accent)}#tasks-form footer{justify-content:flex-end;margin-top:1rem}#tasks-error{color:var(--danger,#d55)}#tasks-history{font-size:.8rem}#tasks-app [hidden]{display:none!important} #tasks-dialog{box-sizing:border-box;color:var(--fg);background:var(--panel,var(--bg));border:1px solid var(--border,#8885);border-radius:1rem;width:min(680px,95vw);max-height:92dvh;padding:1.5rem;box-shadow:0 1rem 4rem #0005;overflow:auto}#tasks-dialog::backdrop{background:#0007;backdrop-filter:blur(3px)}#tasks-fields{display:grid;grid-template-columns:1fr 1fr;gap:.8rem;margin:1rem 0}#tasks-fields label{display:flex;flex-direction:column;gap:.3rem;font-size:.9rem}#tasks-fields label.task-full{grid-column:1/-1}#tasks-fields input,#tasks-fields select,#tasks-fields textarea{width:100%}#tasks-fields textarea{min-height:7rem;resize:vertical}#tasks-fields a{overflow-wrap:anywhere;color:var(--accent)}#tasks-form footer{justify-content:flex-end;margin-top:1rem}#tasks-error{color:var(--danger,#d55)}#tasks-history{font-size:.8rem}#tasks-app [hidden]{display:none!important}
@media(max-width:760px){#tasks-app{display:block;padding:.75rem}#tasks-nav{flex-direction:row;overflow:auto;padding:0 0 .7rem;gap:.1rem;white-space:nowrap}#tasks-nav a{padding:.5rem}.tasks-toolbar h1{font-size:1.3rem}#tasks-dialog{width:100%;height:100dvh;max-height:100dvh;margin:0;border-radius:0;padding:1rem}#tasks-fields{gap:.7rem}.task-row{gap:.5rem}} @media(max-width:760px){#tasks-app{display:block;padding:.75rem}#tasks-nav{flex-direction:row;overflow:auto;padding:0 0 .7rem;gap:.1rem;white-space:nowrap}#tasks-nav a{padding:.5rem}.tasks-toolbar h1{font-size:1.3rem}#tasks-dialog{width:100%;height:100dvh;max-height:100dvh;margin:0;border-radius:0;padding:1rem}#tasks-fields{gap:.7rem}.task-row{gap:.5rem}}
@media(max-width:760px){body:has(#tasks-app)>.topbar{flex-wrap:wrap;padding:.65rem;gap:.5rem}body:has(#tasks-app)>.topbar>.brand{flex:1;min-width:0}body:has(#tasks-app)>.topbar>.brand>a{display:block;overflow:hidden;text-overflow:ellipsis}body:has(#tasks-app)>.topbar>nav{order:2;width:100%}body:has(#tasks-app)>.topbar>.city-map-launch{margin-inline:0;flex-shrink:0}#tasks-fields{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}} @media(max-width:760px){body:has(#tasks-app)>.topbar{flex-wrap:wrap;padding:.65rem;gap:.5rem}body:has(#tasks-app)>.topbar>.brand{flex:1;min-width:0}body:has(#tasks-app)>.topbar>.brand>a{display:block;overflow:hidden;text-overflow:ellipsis}body:has(#tasks-app)>.topbar>nav{order:2;width:100%}body:has(#tasks-app)>.topbar>.city-map-launch{margin-inline:0;flex-shrink:0}#tasks-fields{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}}
+24
View File
@@ -0,0 +1,24 @@
(() => {
'use strict';
const choice=document.getElementById('auth-remember');
if(!choice)return;
const sync=()=>{
for(const form of document.querySelectorAll('.auth-form')){
if(form===choice.form)continue;
const path=new URL(form.action,location.href).pathname;
if(!['/_/auth/ldap','/_/auth/magic-link'].includes(path))continue;
let input=form.querySelector('input[name=remember]');
if(!input){input=document.createElement('input');input.type='hidden';input.name='remember';form.append(input);}
input.value=choice.checked?'1':'0';
}
for(const link of document.querySelectorAll('a.auth-provider-button')){
const url=new URL(link.href,location.href);
if(url.origin!==location.origin||url.pathname!=='/_/auth/oidc')continue;
if(choice.checked)url.searchParams.set('remember','1');else url.searchParams.delete('remember');
link.href=url.pathname+url.search;
}
};
choice.addEventListener('change',sync);
window.addEventListener('pageshow',sync);
sync();
})();
+5 -3
View File
@@ -56,15 +56,17 @@
drain(); drain();
}, {rootMargin: '240px 0px'}); }, {rootMargin: '240px 0px'});
document.querySelectorAll('.browser-thumbnail [data-preview-src]').forEach(image => { const observeImages = () => { document.querySelectorAll('.browser-thumbnail [data-preview-src]').forEach(image => {
if(image.dataset.previewQueued || image.dataset.previewLoaded)return;
observer.observe(image); observer.observe(image);
const rect = image.getBoundingClientRect(); const rect = image.getBoundingClientRect();
if (rect.bottom >= -240 && rect.top <= innerHeight + 240) { if (rect.bottom >= -240 && rect.top <= innerHeight + 240) {
observer.unobserve(image); observer.unobserve(image);
enqueue(image); enqueue(image);
} }
}); });drain(); };
drain(); observeImages();
document.addEventListener('pageswiki:browser-list-updated',observeImages);
document.addEventListener('visibilitychange', drain); document.addEventListener('visibilitychange', drain);
window.addEventListener('pagehide', () => { window.addEventListener('pagehide', () => {
stopped = true; stopped = true;
+82
View File
@@ -0,0 +1,82 @@
(() => {
'use strict';
const main=document.querySelector('[data-upload-directory]');if(!main)return;
const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en;
const maxFiles=100,maxBytes=256*1024*1024,queue=[];
let running=false,dragDepth=0,dirty=false,refreshGeneration=0;
const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
const button=(text,label,action)=>{const b=el('button',text);b.type='button';b.title=b.ariaLabel=label;b.onclick=action;return b;};
const card=el('aside',undefined,'browser-upload-queue');card.hidden=true;card.ariaLabel=t('Uploads','アップロード');
const header=el('header'),title=el('strong',t('Uploads','アップロード')),summary=el('span'),list=el('ol'),notice=el('p',undefined,'upload-notice'),footer=el('footer');
notice.role='status';summary.setAttribute('aria-live','polite');list.id='browser-upload-items';
const toggle=button('−',t('Collapse queue','キューを折りたたむ'),()=>{list.hidden=!list.hidden;toggle.textContent=list.hidden?'+':'−';toggle.setAttribute('aria-expanded',String(!list.hidden));});toggle.setAttribute('aria-expanded','true');toggle.setAttribute('aria-controls',list.id);
const clear=button('✓',t('Clear finished entries','完了・失敗を一覧から除く'),()=>{for(let i=queue.length-1;i>=0;i--)if(queue[i].state!=='queued'&&queue[i].state!=='uploading'){queue[i].row.remove();queue.splice(i,1);}update();});
const refresh=button('⟳',t('Refresh file list','ファイル一覧を更新'),()=>{if(!running)refreshList();});
const close=button('×',t('Close queue','キューを閉じる'),()=>{if(!running)card.hidden=true;});
header.append(title,summary,toggle,close);footer.append(clear,refresh);card.append(header,notice,list,footer);document.body.append(card);
const labels={queued:t('Queued','待機'),uploading:t('Uploading','送信中'),done:t('Complete','完了'),failed:t('Failed','失敗'),cancelled:t('Cancelled','取消')};
function update(){
const completed=queue.filter(x=>x.state==='done').length,pending=queue.filter(x=>x.state==='queued'||x.state==='uploading').length;
summary.textContent=`${completed} / ${queue.length}`;summary.title=t('Completed / total','完了 / 全件');
close.disabled=refresh.disabled=running||pending>0;refresh.hidden=!dirty;
clear.disabled=!queue.some(x=>!['queued','uploading'].includes(x.state));
}
function state(item,value,message){item.state=value;item.row.dataset.state=value;item.status.textContent=message||labels[value];item.cancel.disabled=value!=='queued';if(value==='done')item.progress.value=100;update();}
function send(item){return new Promise(resolve=>{
const xhr=new XMLHttpRequest();let settled=false;
const finish=(ok,message)=>{if(settled)return;settled=true;item.file=null;dirty=true;state(item,ok?'done':'failed',message);resolve();};
xhr.open('POST','/v/upload');xhr.timeout=10*60*1000;xhr.setRequestHeader('Accept','application/json');xhr.setRequestHeader('If-None-Match','*');
xhr.upload.onprogress=e=>{if(e.lengthComputable){item.progress.value=Math.min(99,e.loaded/e.total*100);item.progress.setAttribute('aria-valuetext',`${Math.round(item.progress.value)}%`);}};
xhr.onload=()=>{let result;try{result=JSON.parse(xhr.responseText);}catch{}
if(xhr.status===201&&result?.path)finish(true);
else finish(false,xhr.status===412?t('Already exists — not overwritten','同名あり・上書きしません'):xhr.status===401||xhr.status===403||xhr.responseURL.includes('/_/auth/')?t('Sign in / permission required','ログインまたは権限が必要'):t('Upload failed; check file list','送信失敗・一覧を確認してください'));
};
xhr.onerror=xhr.ontimeout=()=>finish(false,t('Connection lost; check result before retrying','通信断・再送前に保存結果を確認してください'));
const form=new FormData();form.append('path',item.path);form.append('file',item.file,item.name);
try{xhr.send(form);}catch{finish(false,t('Could not send file','ファイルを送信できません'));}
});}
async function refreshList(){
const generation=++refreshGeneration;
refresh.disabled=true;
try{
const response=await fetch(location.href,{credentials:'same-origin',cache:'no-store'});
if(!response.ok||response.redirected)throw Error('refresh');
const page=new DOMParser().parseFromString(await response.text(),'text/html'),grid=page.getElementById('browser-grid'),current=document.getElementById('browser-grid');
if(generation!==refreshGeneration)return;
if(!grid||page.querySelector('[data-upload-directory]')?.dataset.uploadDirectory!==main.dataset.uploadDirectory)throw Error('refresh');
window.clearBrowserSelection?.();current.replaceChildren(...Array.from(grid.children).map(row=>document.importNode(row,true)));
main.querySelector('.browser-empty')?.remove();const empty=page.querySelector('.browser-empty');if(empty)current.before(document.importNode(empty,true));
document.dispatchEvent(new Event('pageswiki:browser-list-updated'));
}catch{if(generation===refreshGeneration)notice.textContent=t('Could not refresh list. Reload after checking the queue.','一覧を更新できません。キューを確認してから再読み込みしてください。');}
finally{update();}
}
async function pump(){if(running)return;running=true;update();try{let item;while((item=queue.find(x=>x.state==='queued'))){state(item,'uploading');await send(item);}}finally{running=false;update();if(dirty)refreshList();}}
function add(files,directory){
++refreshGeneration;
card.hidden=false;notice.textContent='';
for(const file of files){
if(queue.length>=maxFiles){notice.textContent=t('Queue limit: 100 files. Clear finished entries.','キューは100件までです。完了分を一覧から除いてください。');break;}
const name=file.name,target=directory.replace(/\/+$/,'')+'/'+name;
if(!name||name==='.'||name==='..'||/[\\/\x00-\x1f]/.test(name)){notice.textContent=t('Invalid file name','無効なファイル名です');continue;}
const row=el('li'),label=el('span',name,'upload-name'),status=el('span',labels.queued,'upload-state'),progress=el('progress');row.dataset.state='queued';progress.max=100;progress.value=0;progress.ariaLabel=name;label.title=target;
const item={file,name,path:target,state:'queued',row,status,progress};item.cancel=button('×',t('Cancel queued file','待機中のファイルを取り消す'),()=>{if(item.state==='queued'){item.file=null;state(item,'cancelled');}});
row.append(label,item.cancel,status,progress);list.append(row);queue.push(item);
if(file.size>maxBytes){item.file=null;state(item,'failed',t('Maximum 256 MiB per file','1ファイル256 MiBまで'));}
else if(queue.some(x=>x!==item&&x.path===target&&['queued','uploading'].includes(x.state))){item.file=null;state(item,'failed',t('Already queued','すでにキューにあります'));}
}
update();pump();
}
const external=e=>Array.from(e.dataTransfer?.types||[]).includes('Files');
document.addEventListener('dragenter',e=>{if(!external(e))return;e.preventDefault();if(++dragDepth===1)main.classList.add('browser-upload-target');},true);
document.addEventListener('dragover',e=>{if(!external(e))return;e.preventDefault();e.stopImmediatePropagation();e.dataTransfer.dropEffect=e.target.closest?.('.browser-main')?'copy':'none';},true);
document.addEventListener('dragleave',e=>{if(!external(e))return;if(--dragDepth<=0){dragDepth=0;main.classList.remove('browser-upload-target');}},true);
document.addEventListener('drop',e=>{
if(!external(e))return;e.preventDefault();e.stopImmediatePropagation();dragDepth=0;main.classList.remove('browser-upload-target');
if(!e.target.closest?.('.browser-main'))return;
// Folder traversal is deliberately not guessed from zero-byte File objects.
const items=Array.from(e.dataTransfer.items||[]);if(items.some(x=>x.webkitGetAsEntry?.()?.isDirectory)){card.hidden=false;notice.textContent=t('Drop files, not folders','フォルダではなくファイルをドロップしてください');return;}
const folder=e.target.closest?.('.browser-row[data-is-dir="true"]');
add(Array.from(e.dataTransfer.files||[]),folder?.dataset.path||main.dataset.uploadDirectory||'/');
},true);
addEventListener('beforeunload',e=>{if(running||queue.some(x=>x.state==='queued')){e.preventDefault();e.returnValue='';}});
})();
+42 -7
View File
@@ -3,12 +3,23 @@ const api = '/_/api/v1/extension/organizer.feeds/browser/';
const status = document.getElementById('status'), canvas = document.getElementById('screen'); const status = document.getElementById('status'), canvas = document.getElementById('screen');
let engine, started = false, ready = false, stopped = false, navigating = false, poll, resizeTimer; let engine, started = false, ready = false, stopped = false, navigating = false, poll, resizeTimer;
let history = [], position = 0; let history = [], position = 0;
const startup = new AbortController();
let deadline, finding=false;
const ja = parent.document.documentElement.lang.startsWith('ja'); const ja = parent.document.documentElement.lang.startsWith('ja');
const text = (en,jp) => ja ? jp : en; const text = (en,jp) => ja ? jp : en;
function report(message) { status.textContent=message; status.hidden=!message; } function report(message) { status.textContent=message; status.hidden=!message; }
function url(value) { try { const u=new URL(value); return ['https:','http:'].includes(u.protocol)&&!u.username&&!u.password&&u.href.length<=8192 ? u.href : ''; } catch {return '';} } function url(value) { try { const u=new URL(value); return ['https:','http:'].includes(u.protocol)&&!u.username&&!u.password&&u.href.length<=8192 ? u.href : ''; } catch {return '';} }
function send(data) { parent.postMessage({type:'pageswiki-gecko',...data},location.origin); } function send(data) { parent.postMessage({type:'pageswiki-gecko',...data},location.origin); }
function navigationState() { send({href:history[position],back:position>0,forward:position<history.length-1}); } function navigationState() { send({href:history[position],back:position>0,forward:position<history.length-1}); }
async function pageState() {
const uri=String(await engine.evalChrome('String(document.documentURI)'));
const failed=/^about:(neterror|certerror)(?:\?|$)/.test(uri);
// The minimal upstream GRE omits error-page localization/modules. Never
// expose a broken certificate override UI; use our own inert explanation.
canvas.hidden=failed;
report(failed?text('The page could not be loaded securely or the connection failed. Certificate errors cannot be bypassed here. Use ↗ to inspect it in your browser.','安全な接続を確立できないか、通信に失敗しました。証明書エラーはここでは無視できません。↗からブラウザで確認してください。'):'');
return !failed;
}
async function navigate(command) { async function navigate(command) {
if(!ready||stopped||navigating)return; if(!ready||stopped||navigating)return;
const next=position+(command==='back'?-1:command==='forward'?1:0); const next=position+(command==='back'?-1:command==='forward'?1:0);
@@ -18,37 +29,61 @@ async function navigate(command) {
// Minimal upstream GRE omits SessionStoreFunctions: native history.back() // Minimal upstream GRE omits SessionStoreFunctions: native history.back()
// fails. Keep a bounded viewer-local URL history and re-load the chosen URL. // fails. Keep a bounded viewer-local URL history and re-load the chosen URL.
await engine.load(history[position]); await engine.load(history[position]);
await pageState();
const current=url(await engine.evalChrome('String(location.href)')); const current=url(await engine.evalChrome('String(location.href)'));
if(current)history[position]=current; if(current)history[position]=current;
navigationState(); navigationState();
} catch { report(text('Navigation failed. Use ↗ to open the original.','移動できませんでした。↗から原文を開いてください。')); } } catch { report(text('Navigation failed. Use ↗ to open the original.','移動できませんでした。↗から原文を開いてください。')); }
finally {navigating=false;} finally {navigating=false;}
} }
function stop() { stopped=true;clearTimeout(poll);clearTimeout(resizeTimer);engine?.destroy(); } function stop() { stopped=true;ready=false;startup.abort();clearTimeout(deadline);clearTimeout(poll);clearTimeout(resizeTimer);engine?.destroy(); }
function fail() {
if(stopped)return;
stop();
// Upstream destroy() only detaches input; the parent must discard the iframe
// to release the WASM heap, workers and socket, including a stuck init().
send({failed:true});
}
async function find(query, backwards) {
if(!ready||stopped||finding||navigating||typeof query!=='string'||!query.trim()||query.length>256)return;
finding=true;
try {
const found=await engine.evalChrome(`String(window.find(${JSON.stringify(query)},false,${backwards===true},true,false,false,false))`);
if(!stopped)send({findResult:found==='true',query});
} catch {if(!stopped)send({findError:true});}
finally {finding=false;}
}
async function start(href) { async function start(href) {
started=true; started=true;
if(!crossOriginIsolated || typeof SharedArrayBuffer==='undefined') { report(text('This browser cannot run the isolated viewer. Use ↗ to open the original.','このブラウザでは分離ビューアを実行できません。↗から原文を開いてください。'));return; } if(!crossOriginIsolated || typeof SharedArrayBuffer==='undefined') {fail();return;}
report(text('Starting Gecko…','Geckoを起動中…')); report(text('Starting Gecko…','Geckoを起動中…'));
const timer=setTimeout(()=>{if(!ready&&!stopped)report(text('Startup is taking longer than expected. Close the viewer to stop, or use ↗.','起動に時間がかかっています。閉じると停止します。↗から原文も開けます。'));},45000); const timer=setTimeout(()=>{if(!ready&&!stopped)report(text('Startup is taking longer than expected. Close the viewer to stop, or use ↗.','起動に時間がかかっています。閉じると停止します。↗から原文も開けます。'));},45000);
deadline=setTimeout(fail,120000);
try { try {
const {Gecko}=await import(api+'assets/v0.0.1/gecko.js'); if(stopped)return; const {Gecko}=await import(api+'assets/v0.0.1/gecko.js'); if(stopped)return;
const font=await fetch(api+'distribution/v0.0.1/NotoSansCJKjp-Regular.otf',{credentials:'same-origin',signal:startup.signal});
if(!font.ok)throw Error('Bundled font unavailable');
const data=new Uint8Array(await font.arrayBuffer());if(stopped)return;
if(data.byteLength!==16467736)throw Error('Bundled font size mismatch');
const profile=memoryProfile();await profile.mkdir('fonts');await profile.writeFile('fonts/NotoSansCJKjp-Regular.otf',data);
const socket=new URL(api+'wisp/',location.href);socket.protocol=location.protocol==='https:'?'wss:':'ws:'; const socket=new URL(api+'wisp/',location.href);socket.protocol=location.protocol==='https:'?'wss:':'ws:';
engine=new Gecko({canvas,wasm:{url:api+'assets/v0.0.1/gecko.wasm.zst',compressed:true},wispUrl:socket.href,profile:memoryProfile(),width:Math.min(innerWidth,1920),height:Math.min(innerHeight,1080),env:{GECKO_NOWASMJIT:'1'},print:()=>{},printErr:()=>{}}); engine=new Gecko({canvas,wasm:{url:api+'assets/v0.0.1/gecko.wasm.zst',compressed:true},wispUrl:socket.href,profile,width:Math.min(innerWidth,1920),height:Math.min(innerHeight,1080),env:{GECKO_NOWASMJIT:'1'},print:()=>{},printErr:()=>{}});
await engine.init();if(stopped)return; await engine.init();if(stopped)return;
await engine.load(href);if(stopped)return; await engine.load(href);if(stopped)return;
history=[url(await engine.evalChrome('String(location.href)'))||href];position=0; history=[url(await engine.evalChrome('String(location.href)'))||href];position=0;
ready=true;report('');canvas.focus();send({ready:true}); ready=true;clearTimeout(deadline);await pageState();canvas.focus();send({ready:true});
navigationState(); navigationState();
const update=async()=>{if(stopped)return;try{if(!navigating){const href=url(await engine.evalChrome('String(location.href)'));if(href&&!navigating&&href!==history[position]){history=history.slice(0,position+1);history.push(href);if(history.length>64)history.shift();position=history.length-1;navigationState();}}}catch{/* Keep the last validated URL. */}if(!stopped)poll=setTimeout(update,2000);};update(); const update=async()=>{if(stopped)return;try{if(!navigating){await pageState();const href=url(await engine.evalChrome('String(location.href)'));if(href&&!navigating&&href!==history[position]){history=history.slice(0,position+1);history.push(href);if(history.length>64)history.shift();position=history.length-1;navigationState();}}}catch{/* Keep the last validated URL. */}if(!stopped)poll=setTimeout(update,2000);};update();
} catch { report(text('Viewer failed. Close it and retry, or use ↗ to open the original.','ビューアを開始できませんでした。閉じて再試行するか、↗から原文を開いてください。')); } } catch {fail();}
finally {clearTimeout(timer);} finally {clearTimeout(timer);}
} }
addEventListener('message',event=>{ addEventListener('message',event=>{
if(event.source!==parent||event.origin!==location.origin||event.data?.type!=='pageswiki-gecko')return; if(event.source!==parent||event.origin!==location.origin||event.data?.type!=='pageswiki-gecko')return;
if(!started){const href=url(event.data.href);if(href)start(href);return;} if(!started){const href=url(event.data.href);if(href)start(href);return;}
if(['back','forward','reload'].includes(event.data.command))navigate(event.data.command); if(['back','forward','reload'].includes(event.data.command))navigate(event.data.command);
if(event.data.command==='find')find(event.data.query,event.data.backwards);
}); });
addEventListener('resize',()=>{clearTimeout(resizeTimer);resizeTimer=setTimeout(()=>{if(ready&&!stopped)engine.resize(Math.min(innerWidth,1920),Math.min(innerHeight,1080)).catch(()=>{});},150);}); addEventListener('resize',()=>{clearTimeout(resizeTimer);resizeTimer=setTimeout(()=>{if(ready&&!stopped)engine.resize(Math.min(innerWidth,1920),Math.min(innerHeight,1080)).catch(()=>{});},150);});
addEventListener('keydown',e=>{if(e.key==='Escape'){e.preventDefault();send({close:true});}},true); addEventListener('keydown',e=>{if(e.key==='Escape'){e.preventDefault();send({close:true});}if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='f'){e.preventDefault();e.stopImmediatePropagation();send({find:true});}},true);
addEventListener('pagehide',stop); addEventListener('pagehide',stop);
send({listening:true}); send({listening:true});
+54 -16
View File
@@ -28,12 +28,14 @@
const transfer=button('⇄','OPML',opmlForm);transfer.id='feed-opml';toolbar.append(transfer); const transfer=button('⇄','OPML',opmlForm);transfer.id='feed-opml';toolbar.append(transfer);
const history=button('◷',t('Operation history','操作履歴'),actionHistory);history.id='feed-history';toolbar.append(history); const history=button('◷',t('Operation history','操作履歴'),actionHistory);history.id='feed-history';toolbar.append(history);
const helpButton=button('?',t('Keyboard shortcuts','キー操作'),showHelp),help=el('div',undefined,'feed-help');help.id='feed-help';help.hidden=true;helpButton.setAttribute('aria-controls',help.id);helpButton.setAttribute('aria-expanded','false'); const helpButton=button('?',t('Keyboard shortcuts','キー操作'),showHelp),help=el('div',undefined,'feed-help');help.id='feed-help';help.hidden=true;helpButton.setAttribute('aria-controls',help.id);helpButton.setAttribute('aria-expanded','false');
help.append(el('span',t('j/k articles · Shift+j/k folders · Enter read · Esc index · / search · n unread · m read/unread · * star · r refresh · ? / Esc close help','j/k 記事移動 · Shift+j/k フォルダ移動 · Enter 本文 · Esc 一覧 · / 検索 · n 次の未読 · m 既読/未読 · * star · r 更新 · ? / Esc ヘルプを閉じる')),button('×',t('Close help','ヘルプを閉じる'),hideHelp));status.before(help);toolbar.append(helpButton); help.append(el('span',t('j/k articles · Shift+j/k folders / subscriptions · Shift+h parent · Shift+l enter · Enter read · Esc index · / search · n unread · m read/unread · * star · r refresh · ? / Esc close help','j/k 記事移動 · Shift+j/k フォルダ・購読元移動 · Shift+h 親へ · Shift+l 配下へ · Enter 本文 · Esc 一覧 · / 検索 · n 次の未読 · m 既読/未読 · * star · r 更新 · ? / Esc ヘルプを閉じる')),button('×',t('Close help','ヘルプを閉じる'),hideHelp));status.before(help);toolbar.append(helpButton);
let debounce;searchbox.addEventListener('input',()=>{clearTimeout(debounce);debounce=setTimeout(()=>{search=searchbox.value.trim();load(false).catch(report);},180);}); 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)); const columns=document.getElementById('feed-columns');for(const s of ['',t('Date','日付'),t('Time','時刻'),t('Feed','配信元'),t('Subject','件名')])columns.append(el('span',s));
function hideHelp(){if(help.contains(document.activeElement))helpButton.focus();help.hidden=true;helpButton.setAttribute('aria-expanded','false');} function hideHelp(){if(help.contains(document.activeElement))helpButton.focus();help.hidden=true;helpButton.setAttribute('aria-expanded','false');}
function showHelp(){if(!help.hidden){hideHelp();return;}help.hidden=false;helpButton.setAttribute('aria-expanded','true');} function showHelp(){if(!help.hidden){hideHelp();return;}help.hidden=false;helpButton.setAttribute('aria-expanded','true');}
function date(ms){return ms?new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{month:'2-digit',day:'2-digit'}).format(new Date(ms)):'—';} const dateOptions={timeZone:root.dataset.timezone||undefined},dateFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{...dateOptions,month:'2-digit',day:'2-digit'}),timeFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{...dateOptions,hour:'2-digit',minute:'2-digit',hourCycle:'h23'}),fullDateFormat=new Intl.DateTimeFormat(ja?'ja-JP':'en-GB',{...dateOptions,year:'numeric',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit',hourCycle:'h23',timeZoneName:'short'});
function validDate(ms){return typeof ms==='number'&&ms>0&&Number.isFinite(new Date(ms).getTime());}
function date(ms){return validDate(ms)?dateFormat.format(new Date(ms)):'—';}
function closeReader(){editing=false;detailSeq++;detailController?.abort();layout.classList.remove('reading','action-history');rows.focus();} function closeReader(){editing=false;detailSeq++;detailController?.abort();layout.classList.remove('reading','action-history');rows.focus();}
function drawSources(){sourcesView.replaceChildren();const all=button(t('All sources','すべての購読元'),'',()=>chooseSource(''));sourcesView.append(all);let folder=null; 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)); 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));
@@ -54,16 +56,36 @@
remoteCategory=id;categoryMode=mode;remoteFeed=feed;markCatalog();layout.classList.remove('sources-open','reading','action-history'); remoteCategory=id;categoryMode=mode;remoteFeed=feed;markCatalog();layout.classList.remove('sources-open','reading','action-history');
detailSeq++;detailController?.abort();clearTimeout(actionTimer);selected=-1;editing=false;reader.replaceChildren();await load(false); detailSeq++;detailController?.abort();clearTimeout(actionTimer);selected=-1;editing=false;reader.replaceChildren();await load(false);
} }
const sortedSubscriptions=subs=>[...subs].sort((a,b)=>a.title.localeCompare(b.title)||a.id.localeCompare(b.id));
function moveFolder(delta){ function moveFolder(delta){
if(!catalogLoaded||sources.find(s=>s.uuid===currentSource)?.provider!=='freshrss')return; if(!catalogLoaded||sources.find(s=>s.uuid===currentSource)?.provider!=='freshrss')return;
const groups=catalogGroups();if(!groups.length)return; const groups=catalogGroups();if(!groups.length)return;
const current=groups.findIndex(g=>g.id===remoteCategory&&g.mode===categoryMode); const current=groups.findIndex(g=>g.id===remoteCategory&&g.mode===categoryMode);
if(remoteFeed){const g=groups[current],subs=sortedSubscriptions(g?g.subs:catalog),index=subs.findIndex(s=>s.id===remoteFeed)+delta;if(index<0||index>=subs.length)return;return navigateCatalog(g?.id||'',g?.mode||'',subs[index].id);}
const index=current<0?(delta>0?0:groups.length-1):current+delta;if(index<0||index>=groups.length)return; const index=current<0?(delta>0?0:groups.length-1):current+delta;if(index<0||index>=groups.length)return;
// Folder search must not leave the newly selected folder invisible. const group=groups[index];return navigateCatalog(group.id,group.mode);
if(catalogSearch){catalogSearch='';drawSources();} }
const group=groups[index],result=chooseCatalog(group.id,group.mode); function navigateCatalog(id,mode,feed=''){
const selectedFolder=sourcesView.querySelector('.feed-folder-name[aria-current="true"]'); // Clear only the tree filter, never article search or unread/star filters.
selectedFolder?.scrollIntoView({block:'nearest'});rows.focus({preventScroll:true});return result; catalogSearch='';
const result=chooseCatalog(id,mode,feed);drawSources();
sourcesView.querySelector('.feed-catalog button[aria-current="true"]')?.scrollIntoView({block:'nearest'});rows.focus({preventScroll:true});return result;
}
function enterFolder(enter){
if(!catalogLoaded||sources.find(s=>s.uuid===currentSource)?.provider!=='freshrss')return;
const groups=catalogGroups(),group=groups.find(g=>g.id===remoteCategory&&g.mode===categoryMode),state=folderState(currentSource);
if(enter){
if(remoteFeed)return;
if(!group){if(groups.length)return navigateCatalog(groups[0].id,groups[0].mode);return;}
state.add(JSON.stringify([group.mode,group.id]));
}else{
if(remoteFeed)return navigateCatalog(group?.id||'',group?.mode||'');
if(!group)return;
state.delete(JSON.stringify([group.mode,group.id]));
}
try{localStorage.setItem('pageswiki.feed-folders.v1:'+currentSource,JSON.stringify([...state]));}catch{}
if(!enter)return navigateCatalog('','');
const sub=sortedSubscriptions(group.subs)[0];return navigateCatalog(group.id,group.mode,sub?.id||'');
} }
function drawCatalog(parent){ function drawCatalog(parent){
if(!catalogLoaded)return; if(!catalogLoaded)return;
@@ -74,8 +96,8 @@
const all=select(t('All subscriptions','すべての購読'),{id:'',mode:''});all.className='feed-tree-all';nav.append(all); const all=select(t('All subscriptions','すべての購読'),{id:'',mode:''});all.className='feed-tree-all';nav.append(all);
const find=el('input');find.type='search';find.placeholder=find.ariaLabel=t('Find subscription / folder','購読・フォルダを検索');find.value=catalogSearch;nav.append(find); const find=el('input');find.type='search';find.placeholder=find.ariaLabel=t('Find subscription / folder','購読・フォルダを検索');find.value=catalogSearch;nav.append(find);
const list=el('div',undefined,'feed-folders');nav.append(list);parent.append(nav); const list=el('div',undefined,'feed-folders');nav.append(list);parent.append(nav);
function subscriptions(target,subs,g){let count=0;const sorted=[...subs].sort((a,b)=>a.title.localeCompare(b.title)||a.id.localeCompare(b.id));const more=button('↓',t('More subscriptions','購読元をさらに表示'),append); function subscriptions(target,subs,g){const sorted=sortedSubscriptions(subs);let count=0;const more=button('↓',t('More subscriptions','購読元をさらに表示'),append);
function append(){more.remove();for(const sub of sorted.slice(count,count+50)){const group=g||{id:'',mode:''},b=select(sub.title||sub.id,group,sub.id);b.title=(sub.title||sub.id)+(sub.categories.length?' · '+sub.categories.map(c=>c.label).join(' / '):'');target.append(b);}count+=50;if(count<sorted.length)target.append(more);}append(); function append(){more.remove();const end=Math.max(count+50,sorted.findIndex(s=>s.id===remoteFeed)+1);for(const sub of sorted.slice(count,end)){const group=g||{id:'',mode:''},b=select(sub.title||sub.id,group,sub.id);b.title=(sub.title||sub.id)+(sub.categories.length?' · '+sub.categories.map(c=>c.label).join(' / '):'');target.append(b);}count=end;if(count<sorted.length)target.append(more);}append();
} }
const draw=()=>{list.replaceChildren();const query=find.value.trim().toLocaleLowerCase();catalogSearch=find.value; const draw=()=>{list.replaceChildren();const query=find.value.trim().toLocaleLowerCase();catalogSearch=find.value;
if(query){const matches=catalog.filter(s=>s.title.toLocaleLowerCase().includes(query)||s.categories.some(c=>c.label.toLocaleLowerCase().includes(query)));const results=el('div',undefined,'feed-subscriptions');list.append(results);subscriptions(results,matches,null);if(!matches.length)results.append(el('small',t('No subscriptions','購読なし')));return;} if(query){const matches=catalog.filter(s=>s.title.toLocaleLowerCase().includes(query)||s.categories.some(c=>c.label.toLocaleLowerCase().includes(query)));const results=el('div',undefined,'feed-subscriptions');list.append(results);subscriptions(results,matches,null);if(!matches.length)results.append(el('small',t('No subscriptions','購読なし')));return;}
@@ -92,7 +114,15 @@
const data=await request('catalog?'+new URLSearchParams({source:currentSource}),{signal:catalogController.signal});if(version!==catalogSeq)return;catalog=data.subscriptions;catalogFolders=data.folders||[];catalogLoaded=true;drawSources(); const data=await request('catalog?'+new URLSearchParams({source:currentSource}),{signal:catalogController.signal});if(version!==catalogSeq)return;catalog=data.subscriptions;catalogFolders=data.folders||[];catalogLoaded=true;drawSources();
} }
async function chooseSource(id){currentSource=id;remoteFeed=remoteCategory=categoryMode=catalogSearch='';catalog=[];catalogFolders=[];catalogLoaded=false;drawSources();layout.classList.remove('reading');editing=false;await Promise.all([loadCatalog(),load(false)]);if(sources.find(s=>s.uuid===id)?.provider!=='freshrss')layout.classList.remove('sources-open');} async function chooseSource(id){currentSource=id;remoteFeed=remoteCategory=categoryMode=catalogSearch='';catalog=[];catalogFolders=[];catalogLoaded=false;drawSources();layout.classList.remove('reading');editing=false;await Promise.all([loadCatalog(),load(false)]);if(sources.find(s=>s.uuid===id)?.provider!=='freshrss')layout.classList.remove('sources-open');}
function rowNode(item,index){const row=el('div',undefined,'feed-row'+(item.read?'':' unread'));row.id='feed-row-'+index;row.setAttribute('role','option');row.setAttribute('aria-selected',String(index===selected));for(const text of [(item.starred?'★':item.read?' ':'●'),date(item.published_ms),item.feed||sources.find(s=>s.uuid===item.source)?.title||'',item.title||t('(Untitled)','(無題)')])row.append(el('span',text));row.title=item.title;row.onclick=()=>open(index).catch(report);return row;} function 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));
const known=validDate(item.published_ms),published=el('span',known?timeFormat.format(new Date(item.published_ms)):'—','feed-published-time');
published.title=published.ariaLabel=t('Published: ','配信日時: ')+(known?fullDateFormat.format(new Date(item.published_ms)):t('Unknown','不明'));
row.append(el('span',item.starred?'★':item.read?' ':'●'),el('span',date(item.published_ms)),published,
el('span',item.feed||sources.find(s=>s.uuid===item.source)?.title||''),el('span',item.title||t('(Untitled)','(無題)')));
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'));} 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; 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,category_mode:categoryMode});if(append){q.set('before',next.ms);q.set('key',next.key);}const data=await request('items?'+q,{signal:controller.signal});if(version!==seq)return; try{const q=new URLSearchParams({source:currentSource,filter,q:search,feed:remoteFeed,category:remoteCategory,category_mode:categoryMode});if(append){q.set('before',next.ms);q.set('key',next.key);}const data=await request('items?'+q,{signal:controller.signal});if(version!==seq)return;
@@ -115,13 +145,21 @@
const gecko=root.dataset.linkMode==='gecko', controller=new AbortController(); const gecko=root.dataset.linkMode==='gecko', controller=new AbortController();
const close=button('×',t('Close preview','プレビューを閉じる'),()=>dialog.close());bar.append(name,external,close);frame.title=dialog.ariaLabel;frame.referrerPolicy='no-referrer'; const close=button('×',t('Close preview','プレビューを閉じる'),()=>dialog.close());bar.append(name,external,close);frame.title=dialog.ariaLabel;frame.referrerPolicy='no-referrer';
if(gecko){ if(gecko){
const licenses=el('a','ⓘ');licenses.href=api+'browser/distribution/v0.0.1/index.html';licenses.target='_blank';licenses.rel='noopener noreferrer';licenses.title=licenses.ariaLabel=t('Engine sources and licenses','エンジンのソースとライセンス');bar.insertBefore(licenses,close);
frame.src=api+'browser/';frame.allow='cross-origin-isolated'; frame.src=api+'browser/';frame.allow='cross-origin-isolated';
const send=command=>frame.contentWindow?.postMessage({type:'pageswiki-gecko',command},location.origin); const send=(command,options={})=>frame.contentWindow?.postMessage({type:'pageswiki-gecko',command,...options},location.origin);
const findbar=el('form',undefined,'feed-gecko-find'),query=el('input'),findStatus=el('output');findbar.hidden=true;query.type='search';query.maxLength=256;query.placeholder=query.ariaLabel=t('Find in article','記事内を検索');findStatus.role='status';
const findButton=button('⌕',t('Find in article (Ctrl+F)','記事内検索 (Ctrl+F)'),()=>{findbar.hidden=!findbar.hidden;if(!findbar.hidden)query.focus();});findButton.disabled=true;bar.insertBefore(findButton,name);
const search=backwards=>{if(query.value.trim())send('find',{query:query.value,backwards});};
findbar.append(query,button('↑',t('Previous match','前の一致'),()=>search(true)),button('↓',t('Next match','次の一致'),()=>search(false)),findStatus,button('×',t('Close search','検索を閉じる'),()=>{findbar.hidden=true;findButton.focus();}));
findbar.onsubmit=e=>{e.preventDefault();search(false);};query.oninput=()=>findStatus.textContent='';query.addEventListener('keydown',e=>{if(e.key==='Escape'){e.preventDefault();findbar.hidden=true;findButton.focus();}else if(e.key==='Enter'&&e.shiftKey){e.preventDefault();search(true);}});
dialog.addEventListener('keydown',e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='f'&&!findButton.disabled){e.preventDefault();findbar.hidden=false;query.focus();}});
dialog.append(findbar);
const nav={};for(const [icon,label,command]of [['←',t('Back','戻る'),'back'],['→',t('Forward','進む'),'forward'],['⟳',t('Reload','再読込'),'reload']]){const b=button(icon,label,()=>send(command));b.disabled=true;nav[command]=b;bar.insertBefore(b,name);} const nav={};for(const [icon,label,command]of [['←',t('Back','戻る'),'back'],['→',t('Forward','進む'),'forward'],['⟳',t('Reload','再読込'),'reload']]){const b=button(icon,label,()=>send(command));b.disabled=true;nav[command]=b;bar.insertBefore(b,name);}
addEventListener('message',e=>{if(e.origin!==location.origin||e.source!==frame.contentWindow||e.data?.type!=='pageswiki-gecko')return;if(e.data.listening)frame.contentWindow.postMessage({type:'pageswiki-gecko',href:url.href},location.origin);if(e.data.close)dialog.close();if(e.data.ready)nav.reload.disabled=false;if(typeof e.data.back==='boolean')nav.back.disabled=!e.data.back;if(typeof e.data.forward==='boolean')nav.forward.disabled=!e.data.forward;if(e.data.href){try{const u=new URL(e.data.href);if(['http:','https:'].includes(u.protocol)&&!u.username&&!u.password){name.textContent=u.hostname;name.title=external.href=u.href;}}catch{}}},{signal:controller.signal}); addEventListener('message',e=>{if(e.origin!==location.origin||e.source!==frame.contentWindow||e.data?.type!=='pageswiki-gecko')return;if(e.data.listening)frame.contentWindow.postMessage({type:'pageswiki-gecko',href:url.href},location.origin);if(e.data.close)dialog.close();if(e.data.ready)nav.reload.disabled=findButton.disabled=false;if(e.data.find&&!findButton.disabled){findbar.hidden=false;query.focus();}if(typeof e.data.findResult==='boolean'&&e.data.query===query.value)findStatus.textContent=e.data.findResult?'':t('No match','一致なし');if(e.data.findError)findStatus.textContent=t('Search unavailable','検索できません');if(e.data.failed){for(const b of Object.values(nav))b.disabled=true;findButton.disabled=true;findbar.hidden=true;const error=el('p',t('Viewer unavailable. Close and retry, or open the original with ↗.','ビューアを開始できません。閉じて再試行するか、↗から原文を開いてください。'),'feed-warning');error.role='alert';frame.src='about:blank';frame.replaceWith(error);return;}if(typeof e.data.back==='boolean')nav.back.disabled=!e.data.back;if(typeof e.data.forward==='boolean')nav.forward.disabled=!e.data.forward;if(e.data.href){try{const u=new URL(e.data.href);if(['http:','https:'].includes(u.protocol)&&!u.username&&!u.password){name.textContent=u.hostname;name.title=external.href=u.href;}}catch{}}},{signal:controller.signal});
let hiddenTimer;document.addEventListener('visibilitychange',()=>{clearTimeout(hiddenTimer);if(document.hidden)hiddenTimer=setTimeout(()=>dialog.close(),60000);},{signal:controller.signal});dialog.addEventListener('close',()=>clearTimeout(hiddenTimer),{once:true}); let hiddenTimer;document.addEventListener('visibilitychange',()=>{clearTimeout(hiddenTimer);if(document.hidden)hiddenTimer=setTimeout(()=>dialog.close(),60000);},{signal:controller.signal});dialog.addEventListener('close',()=>clearTimeout(hiddenTimer),{once:true});
}else{frame.setAttribute('sandbox','allow-scripts');frame.src=url.href;} }else{frame.setAttribute('sandbox','allow-scripts');frame.src=url.href;}
dialog.append(bar,frame);root.append(dialog); dialog.prepend(bar);dialog.append(frame);root.append(dialog);
dialog.addEventListener('keydown',e=>e.stopPropagation());dialog.addEventListener('close',()=>{controller.abort();frame.src='about:blank';dialog.remove();editing=wasEditing;const item=items[selected];if(item&&!editing)pollAction(item);});dialog.showModal();close.focus(); dialog.addEventListener('keydown',e=>e.stopPropagation());dialog.addEventListener('close',()=>{controller.abort();frame.src='about:blank';dialog.remove();editing=wasEditing;const item=items[selected];if(item&&!editing)pollAction(item);});dialog.showModal();close.focus();
} }
function renderItem(item){reader.replaceChildren();const actions=el('div',undefined,'feed-actions');actions.append(button('←',t('Back to list','一覧へ戻る'),closeReader)); function renderItem(item){reader.replaceChildren();const actions=el('div',undefined,'feed-actions');actions.append(button('←',t('Back to list','一覧へ戻る'),closeReader));
@@ -133,7 +171,7 @@
const original=actions.querySelector('.feed-original');if(original)original.addEventListener('click',e=>openArticleLink(e,original.href)); const original=actions.querySelector('.feed-original');if(original)original.addEventListener('click',e=>openArticleLink(e,original.href));
if(item.url&&root.dataset.shareX==='true'){const share=el('a',undefined,'feed-share-x feed-original');share.title=share.ariaLabel=t('Share original article on X','原文の記事をXでシェア');share.href='https://twitter.com/intent/tweet?'+new URLSearchParams({text:item.title||'',url:item.url});share.target='_blank';share.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','M18 3h3l-7 8 8 10h-6l-5-7-6 7H2l7-9L2 3h6l5 6z');svg.append(path);share.append(svg);actions.append(share);} if(item.url&&root.dataset.shareX==='true'){const share=el('a',undefined,'feed-share-x feed-original');share.title=share.ariaLabel=t('Share original article on X','原文の記事をXでシェア');share.href='https://twitter.com/intent/tweet?'+new URLSearchParams({text:item.title||'',url:item.url});share.target='_blank';share.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','M18 3h3l-7 8 8 10h-6l-5-7-6 7H2l7-9L2 3h6l5 6z');svg.append(path);share.append(svg);actions.append(share);}
if(writable)actions.append(button(t('+ Wiki / Task','+ Wiki・タスク'),t('Capture with attribution','出典付きで取り込む'),()=>captureForm(item))); 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')); reader.append(actions,el('h1',item.title||t('(Untitled)','(無題)')),el('p',(item.feed||'')+' · '+(validDate(item.published_ms)?fullDateFormat.format(new Date(item.published_ms)):t('Date unknown','日付不明')),'feed-meta'));
if(item.provider==='freshrss'&&!canWrite)read.title=star.title=t('FreshRSS · read only','FreshRSS · 読取専用'); if(item.provider==='freshrss'&&!canWrite)read.title=star.title=t('FreshRSS · read only','FreshRSS · 読取専用');
const body=el('div',undefined,'feed-body'); 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);} 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);}
@@ -240,7 +278,7 @@
}; };
} }
document.addEventListener('keydown',event=>{if(event.defaultPrevented||event.isComposing||event.ctrlKey||event.altKey||event.metaKey||document.querySelector('dialog[open]'))return;if(event.key==='Escape'&&!help.hidden){hideHelp();event.preventDefault();return;}const input=event.target.closest?.('input,textarea,select,[contenteditable]:not([contenteditable=false]),[role=textbox]');if(input||event.target.isContentEditable){if(event.key==='Escape'){event.target.blur();event.preventDefault();}return;}if(event.key==='?'&&!help.hidden){hideHelp();event.preventDefault();return;}if(event.key==='Enter'&&event.target.closest?.('button,a'))return;if(editing){if(event.key==='Escape'){closeReader();event.preventDefault();}return;} document.addEventListener('keydown',event=>{if(event.defaultPrevented||event.isComposing||event.ctrlKey||event.altKey||event.metaKey||document.querySelector('dialog[open]'))return;if(event.key==='Escape'&&!help.hidden){hideHelp();event.preventDefault();return;}const input=event.target.closest?.('input,textarea,select,[contenteditable]:not([contenteditable=false]),[role=textbox]');if(input||event.target.isContentEditable){if(event.key==='Escape'){event.target.blur();event.preventDefault();}return;}if(event.key==='?'&&!help.hidden){hideHelp();event.preventDefault();return;}if(event.key==='Enter'&&event.target.closest?.('button,a'))return;if(editing){if(event.key==='Escape'){closeReader();event.preventDefault();}return;}
if(event.shiftKey&&['j','k'].includes(event.key.toLowerCase())){event.preventDefault();Promise.resolve().then(()=>moveFolder(event.key.toLowerCase()==='j'?1:-1)).catch(report);return;} if(event.shiftKey&&['h','j','k','l'].includes(event.key.toLowerCase())){event.preventDefault();const key=event.key.toLowerCase();Promise.resolve().then(()=>key==='h'||key==='l'?enterFolder(key==='l'):moveFolder(key==='j'?1:-1)).catch(report);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);} 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')&&currentSource){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); (async()=>{const q=new URLSearchParams(location.search);currentSource=q.get('source')||'';await reload();if(q.has('settings')&&writable){sourceForm();return;}if(q.has('id')&&currentSource){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);
+1 -1
View File
@@ -92,7 +92,7 @@
if(item.id==='progress'){ if(item.id==='progress'){
const data=await request(api+'progress',{signal});if(controller.signal.aborted)return;body.replaceChildren();const percentage=data.total?Math.round(data.done*100/data.total):null; const data=await request(api+'progress',{signal});if(controller.signal.aborted)return;body.replaceChildren();const percentage=data.total?Math.round(data.done*100/data.total):null;
const ring=el('div',percentage===null?'—':percentage+'%','dashboard-progress');ring.style.setProperty('--progress',(percentage||0)+'%'); const ring=el('div',percentage===null?'—':percentage+'%','dashboard-progress');ring.style.setProperty('--progress',(percentage||0)+'%');
body.append(ring,el('p',data.done+' / '+data.total),el('small',t('Completed / tasks planned for today. Cancelled and archived tasks are excluded.','今日に計画したタスクの完了数/総数。取りやめ・アーカイブは除きます。')));return; body.append(ring,el('p',data.done+' / '+data.total));return;
} }
if(item.id==='schedule'){ if(item.id==='schedule'){
if(root.dataset.calendar!=='true'){body.replaceChildren(el('p',t('Calendar extension is disabled.','カレンダー拡張は無効です。')));return;} if(root.dataset.calendar!=='true'){body.replaceChildren(el('p',t('Calendar extension is disabled.','カレンダー拡張は無効です。')));return;}
+22 -5
View File
@@ -3,6 +3,7 @@
const app = document.getElementById('tasks-app'); if (!app) return; const app = document.getElementById('tasks-app'); if (!app) return;
const ja = document.documentElement.lang.startsWith('ja'); const ja = document.documentElement.lang.startsWith('ja');
const words = { const words = {
delete:['Delete','削除'],deleted:['This task has been deleted.','このタスクは削除されています。'],has_children:['Move or delete the subtasks first, including archived subtasks.','先にサブタスクを移動または削除してください(アーカイブ済みも含みます)。'],working:['Stop the running work timer or focus session before deleting this task.','作業時間の記録・集中セッションを停止してから削除してください。'],deleteConfirm:['Delete this task? This cannot be undone. Wiki notes, calendar events and recorded work time will remain. Unsaved changes will be discarded.','このタスクを削除しますか?復元できません。Wikiメモ、カレンダーの予定、記録済みの作業時間は残ります。未保存の変更は破棄されます。'],
carryover:['Carryover','持ち越し'],tomorrow:['Tomorrow','明日'],day:['Daily plan','日別の計画'],notes_subpath:['Wiki note subfolder (relative to the project Wiki page)','Wikiメモのサブ階層(プロジェクトの関連Wiki配下)'], carryover:['Carryover','持ち越し'],tomorrow:['Tomorrow','明日'],day:['Daily plan','日別の計画'],notes_subpath:['Wiki note subfolder (relative to the project Wiki page)','Wikiメモのサブ階層(プロジェクトの関連Wiki配下)'],
start_on:['Work starts','工程開始'],end_on:['Work ends','工程終了'],schedule:['Day schedule','日割り工程表'], start_on:['Work starts','工程開始'],end_on:['Work ends','工程終了'],schedule:['Day schedule','日割り工程表'],
notify_due:['Notify on due date','期限日にInboxへ通知'],notify_planned:['Notify on planned date','取り組む日にInboxへ通知'],reminder_time:['Notification time','通知時刻'],reminder_help:['Inbox only. Saved using the Domain timezone. Missed reminders from earlier days are skipped.','Inbox通知のみ。保存時のドメインのタイムゾーンを使用します。前日以前の未配信分は送りません。'],reminder_zone:['Timezone on save','保存時のタイムゾーン'], notify_due:['Notify on due date','期限日にInboxへ通知'],notify_planned:['Notify on planned date','取り組む日にInboxへ通知'],reminder_time:['Notification time','通知時刻'],reminder_help:['Inbox only. Saved using the Domain timezone. Missed reminders from earlier days are skipped.','Inbox通知のみ。保存時のドメインのタイムゾーンを使用します。前日以前の未配信分は送りません。'],reminder_zone:['Timezone on save','保存時のタイムゾーン'],
@@ -120,7 +121,8 @@
} }
async function open(id,kind='task') { async function open(id,kind='task') {
if($('dialog').open&&!closeDialog())return; if($('dialog').open&&!closeDialog())return;
const ticket=++detailGeneration;dialogController?.abort();dialogController=new AbortController();$('error').textContent='';editing=null;dirty=false;$('fields').replaceChildren();Object.keys(fields).forEach(k=>delete fields[k]);$('history').open=false;$('history').querySelector('ol').replaceChildren();$('dialog-title').textContent=t('loading');$('save').disabled=true;$('archive').hidden=true;$('history').hidden=true;$('project-open').hidden=true;$('dialog').showModal(); $('page-open').hidden=true;$('page-open').removeAttribute('href');
const ticket=++detailGeneration;dialogController?.abort();dialogController=new AbortController();$('error').textContent='';editing=null;dirty=false;$('fields').replaceChildren();Object.keys(fields).forEach(k=>delete fields[k]);$('history').open=false;$('history').querySelector('ol').replaceChildren();$('dialog-title').textContent=t('loading');$('save').disabled=true;$('archive').hidden=$('delete').hidden=true;$('history').hidden=true;$('project-open').hidden=true;$('dialog').showModal();
try { try {
if(!id&&kind==='task')await refreshDefaults(); if(!id&&kind==='task')await refreshDefaults();
const data=id?await request(api+'/'+id,{signal:dialogController.signal}):{item:blank(kind),page_path:''};if(ticket!==detailGeneration)return;editing=data.item; const data=id?await request(api+'/'+id,{signal:dialogController.signal}):{item:blank(kind),page_path:''};if(ticket!==detailGeneration)return;editing=data.item;
@@ -146,15 +148,18 @@
} }
if(editing.kind==='project'){const folder=field('notes_subpath',t('notes_subpath'),'text',editing.notes_subpath||'tasks',true);folder.maxLength=500;folder.placeholder='tasks';$('fields').append(el('small',ja?'例:関連Wikiが /projects/app、サブ階層が tasks → /projects/app/tasks/件名。Wikiの公開範囲に従います。':'Example: project Wiki /projects/app + subfolder tasks → /projects/app/tasks/title. Wiki permissions apply.','task-full'));} if(editing.kind==='project'){const folder=field('notes_subpath',t('notes_subpath'),'text',editing.notes_subpath||'tasks',true);folder.maxLength=500;folder.placeholder='tasks';$('fields').append(el('small',ja?'例:関連Wikiが /projects/app、サブ階層が tasks → /projects/app/tasks/件名。Wikiの公開範囲に従います。':'Example: project Wiki /projects/app + subfolder tasks → /projects/app/tasks/title. Wiki permissions apply.','task-full'));}
field('page_path',t('page'),'text',data.page_path,true).placeholder='/lab/project'; field('page_path',t('page'),'text',data.page_path,true).placeholder='/lab/project';
if(data.page_path){const a=el('a',t('linked')+' ↗');a.href='/'+data.page_path.replace(/^\/+/, '').split('/').map(encodeURIComponent).join('/');$('fields').append(a);}else if(editing.page_uuid)$('fields').append(el('small',t('hiddenLink'))); const updatePageLink=()=>{const a=$('page-open');a.hidden=!data.page_path||!editing.page_uuid||fields.page_path.value!==data.page_path;a.removeAttribute('href');if(!a.hidden)a.href='/'+data.page_path.replace(/^\/+/, '').split('/').map(encodeURIComponent).join('/');};
if(editing.page_uuid){const unlink=el('button',t('unlink'));unlink.type='button';unlink.disabled=!writable;unlink.addEventListener('click',()=>{editing.page_uuid='';fields.page_path.value='';fields.page_path.dataset.changed='true';dirty=true;unlink.disabled=true;});$('fields').append(unlink);} $('page-open').textContent=t('linked')+' ↗';$('page-open').title=ja?'関連ページを新しいタブで開く':'Open related page in a new tab';updatePageLink();
fields.page_path.addEventListener('input',()=>{fields.page_path.dataset.changed='true';}); if(!data.page_path&&editing.page_uuid)$('fields').append(el('small',t('hiddenLink')));
if(editing.page_uuid){const unlink=el('button',t('unlink'));unlink.type='button';unlink.disabled=!writable;unlink.addEventListener('click',()=>{editing.page_uuid='';fields.page_path.value='';fields.page_path.dataset.changed='true';dirty=true;unlink.disabled=true;updatePageLink();});$('fields').append(unlink);}
fields.page_path.addEventListener('input',()=>{fields.page_path.dataset.changed='true';updatePageLink();});
if(id&&editing.kind==='task'){ if(id&&editing.kind==='task'){
if(writable&&!editing.archived&&!['done','cancelled'].includes(editing.status)){const focus=el('button',ja?'◷ このタスクに集中':'◷ Focus on this task','task-full');focus.type='button';focus.addEventListener('click',()=>{if(dirty){$('error').textContent=ja?'先にタスクの変更を保存してください。':'Save your task changes first.';return;}const task={...editing};if(closeDialog())app.dispatchEvent(new CustomEvent('task-focus',{detail:task}));});$('fields').append(focus);} if(writable&&!editing.archived&&!['done','cancelled'].includes(editing.status)){const focus=el('button',ja?'◷ このタスクに集中':'◷ Focus on this task','task-full');focus.type='button';focus.addEventListener('click',()=>{if(dirty){$('error').textContent=ja?'先にタスクの変更を保存してください。':'Save your task changes first.';return;}const task={...editing};if(closeDialog())app.dispatchEvent(new CustomEvent('task-focus',{detail:task}));});$('fields').append(focus);}
const plan=el('button',ja?'▦ 時間枠をカレンダーへ':'▦ Calendar time blocks','task-full');plan.type='button';plan.id='tasks-plan-open'; const plan=el('button',ja?'▦ 時間枠をカレンダーへ':'▦ Calendar time blocks','task-full');plan.type='button';plan.id='tasks-plan-open';
plan.addEventListener('click',()=>{if(dirty){$('error').textContent=ja?'先にタスクの変更を保存してください。':'Save your task changes first.';return;}app.dispatchEvent(new CustomEvent('task-plan',{detail:{...editing}}));});$('fields').append(plan); plan.addEventListener('click',()=>{if(dirty){$('error').textContent=ja?'先にタスクの変更を保存してください。':'Save your task changes first.';return;}app.dispatchEvent(new CustomEvent('task-plan',{detail:{...editing}}));});$('fields').append(plan);
} }
$('archive').hidden=!id||!writable;$('archive').textContent=t(editing.archived?'restore':'archive');$('save').hidden=!writable;$('save').disabled=false;$('history').hidden=!id; $('archive').hidden=!id||!writable;$('archive').textContent=t(editing.archived?'restore':'archive');$('save').hidden=!writable;$('save').disabled=false;$('history').hidden=!id;
$('delete').hidden=!id||!writable||editing.kind!=='task';$('delete').textContent=t('delete');
if(editing.kind==='project'&&id){$('project-open').hidden=false;$('project-open').href=href(editing);$('project-open').textContent=t('openProject');} if(editing.kind==='project'&&id){$('project-open').hidden=false;$('project-open').href=href(editing);$('project-open').textContent=t('openProject');}
arrangeEditor();title.focus(); arrangeEditor();title.focus();
}catch(e){if(e.name!=='AbortError'&&ticket===detailGeneration)$('error').textContent=e.message;} }catch(e){if(e.name!=='AbortError'&&ticket===detailGeneration)$('error').textContent=e.message;}
@@ -165,7 +170,19 @@
$('form').addEventListener('invalid',event=>{const details=event.target.closest('details');if(details)details.open=true;},true); $('form').addEventListener('invalid',event=>{const details=event.target.closest('details');if(details)details.open=true;},true);
function readForm(){const item={...editing};['title','notes','notes_subpath','status','bucket','project_uuid','assignee_uuid','due_on','planned_on','review_on','start_on','end_on','reminder_time'].forEach(k=>{if(fields[k])item[k]=fields[k].value;});['notify_due','notify_planned'].forEach(k=>{if(fields[k])item[k]=fields[k].checked;});['priority','estimate_minutes','complexity'].forEach(k=>{if(fields[k])item[k]=Number(fields[k].value);});if(fields.page_path?.dataset.changed||(!item.page_uuid&&fields.page_path?.value))item.page_path=fields.page_path.value;return item;} function readForm(){const item={...editing};['title','notes','notes_subpath','status','bucket','project_uuid','assignee_uuid','due_on','planned_on','review_on','start_on','end_on','reminder_time'].forEach(k=>{if(fields[k])item[k]=fields[k].value;});['notify_due','notify_planned'].forEach(k=>{if(fields[k])item[k]=fields[k].checked;});['priority','estimate_minutes','complexity'].forEach(k=>{if(fields[k])item[k]=Number(fields[k].value);});if(fields.page_path?.dataset.changed||(!item.page_uuid&&fields.page_path?.value))item.page_path=fields.page_path.value;return item;}
async function saveItem(item){const data=await request(api+(item.version?'/'+item.uuid:''),{method:item.version?'PUT':'POST',headers:item.version?{'If-Match':'"'+item.version+'"'}:{},body:JSON.stringify(item)});app.dispatchEvent(new Event('task-today-refresh'));return data;} async function saveItem(item){const data=await request(api+(item.version?'/'+item.uuid:''),{method:item.version?'PUT':'POST',headers:item.version?{'If-Match':'"'+item.version+'"'}:{},body:JSON.stringify(item)});app.dispatchEvent(new Event('task-today-refresh'));return data;}
async function submit(archive=false){if(!editing||saving||!writable)return;if(!$('form').reportValidity())return;const item=readForm();if(archive)item.archived=!item.archived;saving=true;Object.values(fields).forEach(f=>f.disabled=true);$('save').disabled=$('archive').disabled=true;$('error').textContent='';try{await saveItem(item);saving=false;closeDialog(true);await load();if(projectID)await loadProject();}catch(e){$('error').textContent=e.message;}finally{saving=false;Object.values(fields).forEach(f=>f.disabled=!writable);$('save').disabled=$('archive').disabled=false;}} async function submit(archive=false){if(!editing||saving||!writable)return;if(!$('form').reportValidity())return;const item=readForm();if(archive)item.archived=!item.archived;saving=true;Object.values(fields).forEach(f=>f.disabled=true);$('save').disabled=$('archive').disabled=$('delete').disabled=true;$('error').textContent='';try{await saveItem(item);saving=false;closeDialog(true);await load();if(projectID)await loadProject();}catch(e){$('error').textContent=e.message;}finally{saving=false;Object.values(fields).forEach(f=>f.disabled=!writable);$('save').disabled=$('archive').disabled=$('delete').disabled=false;}}
$('delete').addEventListener('click',async()=>{
if(!editing?.version||editing.kind!=='task'||saving||!writable)return;
if(!confirm(editing.title+'\n\n'+t('deleteConfirm')))return;
saving=true;Object.values(fields).forEach(f=>f.disabled=true);$('save').disabled=$('archive').disabled=$('delete').disabled=true;$('error').textContent='';
try{
await request(api+'/'+editing.uuid,{method:'DELETE',headers:{'If-Match':'"'+editing.version+'"'}});
saving=false;closeDialog(true);app.dispatchEvent(new Event('task-today-refresh'));
if(view==='detail'){location.replace('/v/plan/tasks');return;}
await load();
}catch(e){$('error').textContent=e.message;}
finally{saving=false;Object.values(fields).forEach(f=>f.disabled=!writable);$('save').disabled=$('archive').disabled=$('delete').disabled=false;}
});
$('form').addEventListener('submit',e=>{e.preventDefault();submit();});$('archive').addEventListener('click',()=>submit(true)); $('form').addEventListener('submit',e=>{e.preventDefault();submit();});$('archive').addEventListener('click',()=>submit(true));
$('history').addEventListener('toggle',async()=>{if(!$('history').open||!editing?.version)return;const id=editing.uuid;try{const data=await request(api+'/'+id+'/history');if(editing?.uuid!==id)return;const ol=$('history').querySelector('ol');ol.replaceChildren();data.items.forEach(v=>ol.append(el('li','#'+v.version+' · '+new Date(v.created_at_ms).toLocaleString())));}catch(e){$('error').textContent=e.message;}}); $('history').addEventListener('toggle',async()=>{if(!$('history').open||!editing?.version)return;const id=editing.uuid;try{const data=await request(api+'/'+id+'/history');if(editing?.uuid!==id)return;const ol=$('history').querySelector('ol');ol.replaceChildren();data.items.forEach(v=>ol.append(el('li','#'+v.version+' · '+new Date(v.created_at_ms).toLocaleString())));}catch(e){$('error').textContent=e.message;}});
$('new').addEventListener('click',()=>open('',view==='projects'?'project':'task')); $('new').addEventListener('click',()=>open('',view==='projects'?'project':'task'));
+2 -1
View File
@@ -11,8 +11,9 @@
{{ if .Setup }}<label>{{ T "auth.bootstrap_token" }}<input name="bootstrap_token" autocomplete="off" required></label><label>{{ T "auth.display_name" }}<input name="display_name" autocomplete="name"></label><label>{{ T "auth.email" }}<input name="email" type="email" autocomplete="email"></label>{{ end }} {{ if .Setup }}<label>{{ T "auth.bootstrap_token" }}<input name="bootstrap_token" autocomplete="off" required></label><label>{{ T "auth.display_name" }}<input name="display_name" autocomplete="name"></label><label>{{ T "auth.email" }}<input name="email" type="email" autocomplete="email"></label>{{ end }}
<label>{{ T "auth.username" }}<input name="username" autocomplete="username" required autofocus></label> <label>{{ T "auth.username" }}<input name="username" autocomplete="username" required autofocus></label>
<label>{{ T "auth.password" }}<input name="password" type="password" autocomplete="{{ if .Setup }}new-password{{ else }}current-password{{ end }}" minlength="12" required></label> <label>{{ T "auth.password" }}<input name="password" type="password" autocomplete="{{ if .Setup }}new-password{{ else }}current-password{{ end }}" minlength="12" required></label>
{{ if and (not .Setup) .TrustedSessionDays }}<label class="auth-remember"><input id="auth-remember" type="checkbox" name="remember" value="1" {{ if .RememberRequested }}checked{{ end }}><span>{{ T "auth.remember" }}({{ .TrustedSessionDays }} {{ T "auth.days" }})</span></label>{{ end }}
<button class="auth-primary" type="submit">{{ if .Setup }}{{ T "auth.create_owner" }}{{ else }}{{ T "auth.login" }}{{ end }}</button></form> <button class="auth-primary" type="submit">{{ if .Setup }}{{ T "auth.create_owner" }}{{ else }}{{ T "auth.login" }}{{ end }}</button></form>
{{ if and (not .Setup) (not .MFA) .OIDCEnabled }}<div class="auth-separator"><span>{{ T "auth.or" }}</span></div><a class="auth-provider-button" href="/_/auth/oidc?return={{ .Return }}"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="8"/><path d="M12 4v16M8 8.5A5 5 0 0 1 16 12a5 5 0 0 1-8 3.5"/></svg><span>{{ T "auth.login_oidc" }}</span></a>{{ end }} {{ if and (not .Setup) (not .MFA) .OIDCEnabled }}<div class="auth-separator"><span>{{ T "auth.or" }}</span></div><a class="auth-provider-button" href="/_/auth/oidc?return={{ .Return }}"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="8"/><path d="M12 4v16M8 8.5A5 5 0 0 1 16 12a5 5 0 0 1-8 3.5"/></svg><span>{{ T "auth.login_oidc" }}</span></a>{{ end }}
{{ if and (not .Setup) (not .MFA) .LDAPEnabled }}<div class="auth-separator"><span>{{ T "auth.or" }}</span></div><form class="auth-form" method="post" action="/_/auth/ldap"><input type="hidden" name="return" value="{{ .Return }}"><label>{{ T "auth.ldap_username" }}<input name="username" autocomplete="username" required></label><label>{{ T "auth.password" }}<input name="password" type="password" autocomplete="current-password" required></label><button class="auth-provider-button" type="submit">{{ T "auth.login_ldap" }}</button></form>{{ end }} {{ if and (not .Setup) (not .MFA) .LDAPEnabled }}<div class="auth-separator"><span>{{ T "auth.or" }}</span></div><form class="auth-form" method="post" action="/_/auth/ldap"><input type="hidden" name="return" value="{{ .Return }}"><label>{{ T "auth.ldap_username" }}<input name="username" autocomplete="username" required></label><label>{{ T "auth.password" }}<input name="password" type="password" autocomplete="current-password" required></label><button class="auth-provider-button" type="submit">{{ T "auth.login_ldap" }}</button></form>{{ end }}
{{ if and (not .Setup) (not .MFA) .MagicEnabled }}{{ if .MagicSent }}<p>{{ T "auth.magic_sent" }}</p>{{ else }}<form class="auth-form auth-magic-form" method="post" action="/_/auth/magic-link"><input type="hidden" name="return" value="{{ .Return }}"><label>{{ T "auth.email" }}<input name="email" type="email" autocomplete="email" required></label><button class="auth-secondary">{{ T "auth.send_magic_link" }}</button></form>{{ end }}{{ end }} {{ if and (not .Setup) (not .MFA) .MagicEnabled }}{{ if .MagicSent }}<p>{{ T "auth.magic_sent" }}</p>{{ else }}<form class="auth-form auth-magic-form" method="post" action="/_/auth/magic-link"><input type="hidden" name="return" value="{{ .Return }}"><label>{{ T "auth.email" }}<input name="email" type="email" autocomplete="email" required></label><button class="auth-secondary">{{ T "auth.send_magic_link" }}</button></form>{{ end }}{{ end }}
{{ end }}</section></main></body></html>{{ end }} {{ end }}</section></main><script src="/static/js/auth-remember.js" defer></script></body></html>{{ end }}
+3 -1
View File
@@ -455,7 +455,7 @@
onmousedown="startResize(event, 'sidebar')" onmousedown="startResize(event, 'sidebar')"
></div> ></div>
<section class="browser-main"> <section class="browser-main" data-upload-directory="{{ .Path }}">
<div class="browser-toolbar"> <div class="browser-toolbar">
@@ -1112,6 +1112,8 @@ restoreViewMode()
restorePanes() restorePanes()
</script> </script>
<script src="/static/js/browser-interactions.js?v=1"></script> <script src="/static/js/browser-interactions.js?v=1"></script>
<script src="/static/js/browser-upload.js?v=1" defer></script>
<link rel="stylesheet" href="/static/css/browser-upload.css?v=1">
<dialog class="browser-create-dialog" data-browser-create-dialog aria-labelledby="browser-create-title"> <dialog class="browser-create-dialog" data-browser-create-dialog aria-labelledby="browser-create-title">
<form> <form>
<h2 id="browser-create-title">{{ T "browser.new" }}</h2> <h2 id="browser-create-title">{{ T "browser.new" }}</h2>
+1
View File
@@ -1169,6 +1169,7 @@ Vim
<section id="panel-auth-sessions" class="config-section config-panel"><h1>{{ T "auth.sessions" }}</h1> <section id="panel-auth-sessions" class="config-section config-panel"><h1>{{ T "auth.sessions" }}</h1>
<form method="post" action="/-/sys/config/auth" class="auth-account-form"><input type="hidden" name="action" value="save_session_policy"><label>{{ T "auth.session_minutes" }}<input type="number" name="session_minutes" value="{{ .AuthSessionMinutes }}" min="5" max="43200" step="1" required aria-describedby="session-policy-help"></label><button>{{ T "config.save" }}</button></form> <form method="post" action="/-/sys/config/auth" class="auth-account-form"><input type="hidden" name="action" value="save_session_policy"><label>{{ T "auth.session_minutes" }}<input type="number" name="session_minutes" value="{{ .AuthSessionMinutes }}" min="5" max="43200" step="1" required aria-describedby="session-policy-help"></label><button>{{ T "config.save" }}</button></form>
<p id="session-policy-help" class="muted">{{ T "auth.session_policy_help" }}</p> <p id="session-policy-help" class="muted">{{ T "auth.session_policy_help" }}</p>
<form method="post" action="/-/sys/config/auth" class="auth-account-form"><input type="hidden" name="action" value="save_trusted_session_policy"><label>{{ T "auth.trusted_days" }}<input type="number" name="trusted_session_days" value="{{ .AuthTrustedSessionDays }}" min="0" max="30" step="1" required></label><button>{{ T "config.save" }}</button></form>
<div class="table-scroll"><table class="recent-table"><thead><tr><th>{{ T "auth.account" }}</th><th>{{ T "auth.auth_time" }}</th><th>{{ T "auth.last_seen" }}</th><th>{{ T "auth.expires" }}</th><th>MFA</th><th></th></tr></thead><tbody>{{ range .AuthSessions }}<tr><td>{{ .DisplayName }}</td><td>{{ formatUnixMS .AuthTimeMS }}</td><td>{{ formatUnixMS .LastSeenAtMS }}</td><td>{{ formatUnixMS .ExpiresAtMS }}</td><td>{{ .MFALevel }}</td><td><form method="post" action="/-/sys/config/auth"><input type="hidden" name="action" value="revoke_session"><input type="hidden" name="session_uuid" value="{{ .UUID }}"><button>{{ T "auth.revoke" }}</button></form></td></tr>{{ else }}<tr><td colspan="6">—</td></tr>{{ end }}</tbody></table></div> <div class="table-scroll"><table class="recent-table"><thead><tr><th>{{ T "auth.account" }}</th><th>{{ T "auth.auth_time" }}</th><th>{{ T "auth.last_seen" }}</th><th>{{ T "auth.expires" }}</th><th>MFA</th><th></th></tr></thead><tbody>{{ range .AuthSessions }}<tr><td>{{ .DisplayName }}</td><td>{{ formatUnixMS .AuthTimeMS }}</td><td>{{ formatUnixMS .LastSeenAtMS }}</td><td>{{ formatUnixMS .ExpiresAtMS }}</td><td>{{ .MFALevel }}</td><td><form method="post" action="/-/sys/config/auth"><input type="hidden" name="action" value="revoke_session"><input type="hidden" name="session_uuid" value="{{ .UUID }}"><button>{{ T "auth.revoke" }}</button></form></td></tr>{{ else }}<tr><td colspan="6">—</td></tr>{{ end }}</tbody></table></div>
</section> </section>
<section id="panel-events" class="config-section config-panel"><h1>{{ T "config.event_definitions" }}</h1> <section id="panel-events" class="config-section config-panel"><h1>{{ T "config.event_definitions" }}</h1>
+3 -3
View File
@@ -1,9 +1,9 @@
{{ define "feeds.gohtml" }}<!doctype html> {{ define "feeds.gohtml" }}<!doctype html>
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> <html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>{{ T "feeds.title" }} · {{ .WikiName }}</title> <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=8"></head> <link rel="stylesheet" href="/static/css/main.css"><link rel="stylesheet" href="/static/css/theme/base.css"><link rel="stylesheet" href="{{ .ThemeCSS }}"><link rel="stylesheet" href="/static/css/feeds.css?v=9"></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" . }} <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 }}" data-wiki-prefix="{{ .FeedWikiPrefix }}" data-share-x="{{ .FeedShareX }}" data-link-mode="{{ .FeedLinkMode }}"> <main id="feeds-app" data-timezone="{{ .FeedTimezone }}" data-writable="{{ .FeedWritable }}" data-tasks="{{ .TasksEnabled }}" data-wiki-prefix="{{ .FeedWikiPrefix }}" data-share-x="{{ .FeedShareX }}" data-link-mode="{{ .FeedLinkMode }}">
<div id="feed-toolbar"></div><p id="feed-status" role="status" aria-live="polite"></p> <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> <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=10" defer></script></body></html>{{ end }} </main><script src="/static/js/feeds.js?v=11" defer></script></body></html>{{ end }}
+1 -1
View File
@@ -4,4 +4,4 @@
{{ template "organizer-nav" . }} {{ template "organizer-nav" . }}
<main id="organizer-dashboard" data-writable="{{ .TaskWritable }}" data-calendar="{{ .CalendarEnabled }}" data-today="{{ .Today }}" data-timezone="{{ .Timezone }}"> <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> <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=8" defer></script></body></html>{{ end }} </main><script src="/static/js/organizer-dashboard.js?v=2" defer></script><script src="/static/js/task-productivity.js?v=8" defer></script></body></html>{{ end }}
+3 -3
View File
@@ -1,6 +1,6 @@
{{ define "tasks.gohtml" }}<!doctype html> {{ define "tasks.gohtml" }}<!doctype html>
<html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ T "tasks.title" }} · {{ .WikiName }}</title> <html lang="{{ .Locale }}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{ T "tasks.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/tasks.css?v=10"></head> <link rel="stylesheet" href="/static/css/main.css"><link rel="stylesheet" href="/static/css/theme/base.css"><link rel="stylesheet" href="{{ .ThemeCSS }}"><link rel="stylesheet" href="/static/css/tasks.css?v=11"></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" . }} <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="tasks-app" data-view="{{ .TaskView }}" data-id="{{ .TaskID }}" data-today="{{ .TaskToday }}" data-selected-date="{{ .TaskSelectedDate }}" data-timezone="{{ .TaskTimezone }}" data-writable="{{ .TaskWritable }}"> <main id="tasks-app" data-view="{{ .TaskView }}" data-id="{{ .TaskID }}" data-today="{{ .TaskToday }}" data-selected-date="{{ .TaskSelectedDate }}" data-timezone="{{ .TaskTimezone }}" data-writable="{{ .TaskWritable }}">
<nav id="tasks-nav" aria-label="Tasks"></nav><section class="tasks-workspace"> <nav id="tasks-nav" aria-label="Tasks"></nav><section class="tasks-workspace">
@@ -10,5 +10,5 @@
<label id="tasks-kind-control" class="tasks-search" hidden><span></span><select id="tasks-kind"></select></label><a id="tasks-project-archive" href="/v/plan/tasks/archived?kind=project" hidden></a> <label id="tasks-kind-control" class="tasks-search" hidden><span></span><select id="tasks-kind"></select></label><a id="tasks-project-archive" href="/v/plan/tasks/archived?kind=project" hidden></a>
<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> <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> </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> <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><button type="button" id="tasks-delete" class="danger" hidden></button><a id="tasks-page-open" class="task-footer-link" target="_blank" rel="noopener noreferrer" hidden></a><a id="tasks-project-open" class="task-footer-link" 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=10" 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=11" defer></script><script src="/static/js/task-dav-settings.js?v=4" defer></script></body></html>{{ end }}
+1
View File
@@ -4,6 +4,7 @@
{{ else }} {{ else }}
<p>{{ T "auth.cli_warning" }}</p> <p>{{ T "auth.cli_warning" }}</p>
<p><strong>{{ .CLIOrigin }}</strong></p> <p><strong>{{ .CLIOrigin }}</strong></p>
{{ if .CLIRememberDays }}<p>{{ T "auth.remember_cli" }}: {{ .CLIRememberDays }} {{ T "auth.days" }}</p>{{ end }}
{{ if .CLILogin }} {{ if .CLILogin }}
<a class="auth-provider-button" href="{{ .CLILogin }}">{{ T "auth.login_oidc" }}</a> <a class="auth-provider-button" href="{{ .CLILogin }}">{{ T "auth.login_oidc" }}</a>
{{ else }} {{ else }}
+1 -1
View File
@@ -1,7 +1,7 @@
import {spawnSync} from 'node:child_process'; import {spawnSync} from 'node:child_process';
import {pathToFileURL} from 'node:url'; import {pathToFileURL} from 'node:url';
export const images = ['pageswiki-app', 'pageswiki-adaptor-gateway', 'pageswiki-excalidraw-viewer']; export const images = ['pageswiki-app', 'pageswiki-adaptor-gateway', 'pageswiki-excalidraw-viewer', 'pageswiki-gecko-relay'];
// SemVer 2.0.0: numeric prerelease identifiers cannot have leading zeroes. // SemVer 2.0.0: numeric prerelease identifiers cannot have leading zeroes.
const number = '(0|[1-9][0-9]*)'; const number = '(0|[1-9][0-9]*)';
const identifier = '(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)'; const identifier = '(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)';
+6 -6
View File
@@ -37,19 +37,19 @@ function registry() {
return {client, entries, copies}; return {client, entries, copies};
} }
test('promotes three sources by digest and retry does not rewrite', () => { test('promotes all sources by digest and retry does not rewrite', () => {
const {client, copies} = registry(); const {client, copies} = registry();
const plan = promote(options, client, () => {}); const plan = promote(options, client, () => {});
assert.equal(copies.length, 3); assert.equal(copies.length, images.length);
for (const item of plan) assert.ok(item.source.endsWith(`@${item.digest}`)); for (const item of plan) assert.ok(item.source.endsWith(`@${item.digest}`));
promote(options, client, () => {}); promote(options, client, () => {});
assert.equal(copies.length, 3); assert.equal(copies.length, images.length);
}); });
test('missing source, wrong revision or existing release conflict prevents all writes', () => { test('missing source, wrong revision or existing release conflict prevents all writes', () => {
for (const failure of ['missing', 'revision', 'conflict']) { for (const failure of ['missing', 'revision', 'conflict']) {
const {client, entries, copies} = registry(); const {client, entries, copies} = registry();
const last = `${options.prefix}/${images[2]}`; const last = `${options.prefix}/${images.at(-1)}`;
if (failure === 'missing') entries.delete(`${last}:sha-${revision}`); if (failure === 'missing') entries.delete(`${last}:sha-${revision}`);
if (failure === 'revision') client.revision = () => 'b'.repeat(40); if (failure === 'revision') client.revision = () => 'b'.repeat(40);
if (failure === 'conflict') entries.set(`${last}:v0.1.0`, `sha256:${'f'.repeat(64)}`); if (failure === 'conflict') entries.set(`${last}:v0.1.0`, `sha256:${'f'.repeat(64)}`);
@@ -68,7 +68,7 @@ test('partial promotion is safely resumable', () => {
assert.throws(() => promote(options, client, () => {}), /unavailable/); assert.throws(() => promote(options, client, () => {}), /unavailable/);
client.copy = copy; client.copy = copy;
promote(options, client, () => {}); promote(options, client, () => {});
assert.equal(copies.length, 3); assert.equal(copies.length, images.length);
}); });
test('destination digest mismatch and concurrent overwrite are failures', () => { test('destination digest mismatch and concurrent overwrite are failures', () => {
@@ -79,7 +79,7 @@ test('destination digest mismatch and concurrent overwrite are failures', () =>
const get = other.client.digest; const get = other.client.digest;
let reads = 0; let reads = 0;
other.client.digest = (ref, optional) => { other.client.digest = (ref, optional) => {
if (ref.endsWith(':v0.1.0') && ++reads > 3) return `sha256:${'f'.repeat(64)}`; if (ref.endsWith(':v0.1.0') && ++reads > images.length) return `sha256:${'f'.repeat(64)}`;
return get(ref, optional); return get(ref, optional);
}; };
assert.throws(() => promote(options, other.client), /concurrently/); assert.throws(() => promote(options, other.client), /concurrently/);
+46
View File
@@ -0,0 +1,46 @@
Gecko WASM v0.0.1 distribution for PagesWiki
The gecko.js and gecko.wasm.zst binaries are unmodified upstream release files.
PagesWiki's relay and UI are separate software. This is not an official Mozilla
Firefox distribution and no Mozilla trademarks or logos are licensed here.
Corresponding source and build recipe:
wrapper.tar.gz: HeyPuter/firefox-wasm eadcb5fa828d7e8b54ae2df13b6b3208f6553944
firefox.tar.gz: MercuryWorkshop/firefox 2e1e835a5da5907e5ceef19aade58a7493f1e34d
emscripten.tar.gz: Emscripten 6.0.1 (runtime and bundled libc sources/notices)
rust-src.tar.xz: Rust 1.95.0 standard library; .crate files are all registry
dependencies of library/Cargo.lock, checked against that lock's checksums.
zstddec.tgz: zstddec 0.2.0, MIT and BSD-3-Clause notices.
wrapper-MPL.txt: MPL-2.0 declaration added by upstream at
ac40f56c85060bd49dfc36ca60490f97dd270c50. The wrapper's core source and
Emscripten patches were unchanged between these commits.
vex-sdk-LICENSE.txt: MIT notice from the crate's source commit, omitted from
the published crate. Fortanix's in-source copyright/MPL header is retained.
NotoSansCJKjp-Regular.otf: unmodified Noto Sans CJK JP Sans2.004, commit
523d033d6cb47f4a80c58a35753646f5c3608a78. Embedded copyright notice:
© 2014-2021 Adobe (http://www.adobe.com/).
SIL Open Font License 1.1, reproduced in NotoSansCJK-LICENSE.txt. No font
names or embedded notices are modified. Source repository: notofonts/noto-cjk.
Extract wrapper.tar.gz into a working directory, put the extracted Firefox
source at firefox/, and follow the included README and Makefile. Use the fixed
Firefox revision above, Emscripten 6.0.1, Rust 1.95.0 and its rust-src, and the
included pnpm-lock.yaml. make emsdk applies the included WasmFS patches;
vendor-std-deps.py verifies the standard library crates. The upstream Makefile,
mozconfig and build scripts describe the release build. Building is
not performed by the PagesWiki runtime. The upstream build timestamp is not
fixed; byte-for-byte reproducibility is not claimed.
The source archives preserve their original licenses, copyrights and patches.
The *.notices.txt files collect license, copying, copyright, notice and author
files from those archives. Mozilla's license.html is converted to inert readable
text with ALL conditional sections included, a conservative superset. Original
HTML and build conditionals remain in firefox.tar.gz. Liberation fonts (SIL OFL
1.1, reserved names retained) are covered by that archive's PDF.js font notice.
Gecko's source archive includes its vendored third-party/Rust source and notices.
Upstream source URLs and exact hashes/sizes are recorded in manifest.json.
Keep this complete bundle available to recipients whenever the engine is served,
and preserve the source offer after disabling the feature. Do not deploy a pair
of engine files alone. Do not remove notices because a component is believed
unused without reviewing the actual build. No additional warranty is provided.
+163
View File
@@ -0,0 +1,163 @@
#!/usr/bin/env python3
"""Build an offline, hash-locked Gecko distribution without extracting source trees.
Python 3.11+. Sources and notices remain available alongside the engine. The
output is a new directory: never replace a bundle mounted by a running relay.
"""
import argparse
import hashlib
import html
from html.parser import HTMLParser
import json
from pathlib import Path, PurePosixPath
import re
import shutil
import tarfile
import tomllib
import urllib.request
ROOT = Path(__file__).resolve().parent
def digest(path):
with path.open('rb') as stream:
return hashlib.file_digest(stream, 'sha256').hexdigest()
def obtain(cache, name, url, expected, offline=False):
path = cache / name
if not path.exists():
if offline:
raise ValueError('missing offline input: ' + name)
temporary = path.with_suffix(path.suffix + '.part')
with urllib.request.urlopen(url, timeout=60) as response, temporary.open('wb') as target:
shutil.copyfileobj(response, target, 1 << 20)
if digest(temporary) != expected:
temporary.unlink()
raise ValueError('download checksum mismatch: ' + name)
temporary.rename(path)
if digest(path) != expected:
raise ValueError('cached checksum mismatch: ' + name)
return path
class NoticeText(HTMLParser):
"""Readable superset of Mozilla's conditional notice, without active HTML."""
def __init__(self):
super().__init__(convert_charrefs=True)
self.parts = []
self.skip = 0
def handle_starttag(self, tag, attrs):
if tag in ('script', 'style'):
self.skip += 1
if not self.skip and tag in ('p', 'li', 'pre', 'h1', 'h2', 'h3', 'br', 'div'):
self.parts.append('\n')
if not self.skip and tag == 'a':
href = dict(attrs).get('href', '')
if href.startswith(('https://', 'http://')):
self.parts.append(' [' + href + '] ')
def handle_endtag(self, tag):
if tag in ('script', 'style') and self.skip:
self.skip -= 1
def handle_data(self, value):
if not self.skip:
self.parts.append(value)
def notices(archive):
chunks = []
with tarfile.open(archive) as source:
for member in source:
name = PurePosixPath(member.name).name
if not member.isfile() or not re.match(r'(?i)^(licen[cs]e|copying|copyright|notice|authors)([._-].*|$)', name):
continue
if member.size > 8 << 20:
raise ValueError('oversized notice: ' + member.name)
raw = source.extractfile(member).read().decode('utf-8', errors='replace')
if name == 'license.html':
parser = NoticeText()
# Include ALL conditional branches (a conservative superset).
parser.feed(re.sub(r'^#.*$', '', raw, flags=re.M))
raw = ''.join(parser.parts)
chunks.append('\n\n===== ' + member.name + ' =====\n\n' + raw)
if not chunks:
if archive.name == 'fortanix-sgx-abi-0.6.1.crate':
raw = member_bytes(archive, 'src/lib.rs').decode()
return raw.split('*/', 1)[0] + '*/\nFull MPL-2.0 text: wrapper-MPL.txt\n'
if archive.name == 'vex-sdk-0.27.1.crate':
return 'MIT license and copyright notice: vex-sdk-LICENSE.txt\nOriginal metadata:\n' + member_bytes(archive, 'Cargo.toml').decode()
raise ValueError('no notices found: ' + archive.name)
return ''.join(chunks)
def member_bytes(archive, suffix):
with tarfile.open(archive) as source:
matches = [m for m in source if m.isfile() and m.name.endswith('/' + suffix)]
if len(matches) != 1 or matches[0].size > 64 << 20:
raise ValueError('ambiguous/missing member: ' + suffix)
return source.extractfile(matches[0]).read()
def build(cache, output, offline=False):
if output.exists():
raise ValueError('output already exists; choose a new immutable directory')
lock = json.loads((ROOT / 'sources.lock.json').read_text())
cache.mkdir(parents=True, exist_ok=True)
inputs = {entry['file']: obtain(cache, entry['file'], entry['url'], entry['sha256'], offline) for entry in lock['inputs']}
# Rust build-std vendors its own Cargo.lock packages, not just Gecko crates.
cargo = tomllib.loads(member_bytes(inputs['rust-src.tar.xz'], 'library/Cargo.lock').decode())
crates = []
for package in cargo['package']:
if 'source' not in package:
continue
if package['source'] != 'registry+https://github.com/rust-lang/crates.io-index':
raise ValueError('unsupported Rust dependency source')
name = package['name'] + '-' + package['version'] + '.crate'
url = 'https://static.crates.io/crates/' + package['name'] + '/' + name
crates.append((name, obtain(cache, name, url, package['checksum'], offline), url))
output.mkdir(parents=True)
records = []
def record(name, origin, kind):
records.append(dict(file=name, sha256=digest(output / name), size=(output / name).stat().st_size, origin=origin, kind=kind))
for entry in lock['inputs']:
name = entry['file']
shutil.copyfile(inputs[name], output / name)
record(name, entry['url'], 'notice' if name.endswith('.txt') else 'source' if name != 'engine.tar.gz' else 'upstream-binary')
if name.endswith(('.tar.gz', '.tar.xz', '.tgz')) and name not in ('engine.tar.gz', 'wrapper.tar.gz'):
target = name + '.notices.txt'
(output / target).write_text(notices(inputs[name]), encoding='utf-8')
record(target, name, 'notice')
for name, source, url in crates:
shutil.copyfile(source, output / name)
record(name, url, 'source')
target = name + '.notices.txt'
(output / target).write_text(notices(source), encoding='utf-8')
record(target, name, 'notice')
for name in ('gecko.js', 'gecko.wasm.zst'):
(output / name).write_bytes(member_bytes(inputs['engine.tar.gz'], 'dist/' + name))
record(name, 'engine.tar.gz', 'engine')
if records[-1]['sha256'] != lock['engine'][name]:
raise ValueError('engine payload mismatch: ' + name)
# This file describes preservation of originals and source/build relationships.
shutil.copyfile(ROOT / 'README.txt', output / 'README.txt')
record('README.txt', 'PagesWiki tools/gecko/README.txt', 'notice')
rows = ''.join('<tr><td><a href="' + html.escape(r['file'], quote=True) + '">' + html.escape(r['file']) + '</a></td><td>' + r['kind'] + '</td><td>' + str(r['size']) + '</td><td><code>' + r['sha256'] + '</code></td></tr>' for r in records)
(output / 'index.html').write_text('<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Gecko sources and licenses</title><h1>Gecko sources and licenses</h1><p>Unmodified upstream Gecko WASM v0.0.1. Not an official Mozilla Firefox distribution. <a href="README.txt">Source and build instructions</a>. <a href="manifest.json">SHA-256 manifest</a>.</p><p>Notices include all build-conditional sections and vendored source notices; some components may not be linked. Originals remain in the source archives. License texts and copyright notices are not replaced by this index.</p><table><thead><tr><th>File</th><th>Kind</th><th>Bytes</th><th>SHA-256</th></tr></thead><tbody>' + rows + '</tbody></table></html>', encoding='utf-8')
record('index.html', 'generated index', 'index')
(output / 'manifest.json').write_text(json.dumps(dict(format='pageswiki.gecko-distribution.v1', version='v0.0.1', files=records), indent=2, sort_keys=True) + '\n')
print('manifest SHA-256:', digest(output / 'manifest.json'), flush=True)
print('files:', len(records), 'bytes:', sum(r['size'] for r in records), flush=True)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--cache', type=Path, required=True)
parser.add_argument('--output', type=Path, required=True)
parser.add_argument('--offline', action='store_true')
args = parser.parse_args()
build(args.cache, args.output, args.offline)
+18
View File
@@ -0,0 +1,18 @@
{
"engine": {
"gecko.js": "e5aeebffd21106eccf23b1219316221add5e95085bc5a1bfb941117cfcd75ef7",
"gecko.wasm.zst": "ebd6c75179152624d9644865e11792ed25cadc714d9e0985f412baf9c637a086"
},
"inputs": [
{"file":"engine.tar.gz","url":"https://github.com/HeyPuter/firefox-wasm/releases/download/v0.0.1/gecko.js-v0.0.1.tar.gz","sha256":"bac28056a00ef6e5fb4345117e73d3629e75aca00dac71389fabbce39c018a73"},
{"file":"wrapper.tar.gz","url":"https://codeload.github.com/HeyPuter/firefox-wasm/tar.gz/eadcb5fa828d7e8b54ae2df13b6b3208f6553944","sha256":"60078bb4c68ed97e95b5720b9833a9454aac0668fb069aa53393e96628e845e1"},
{"file":"firefox.tar.gz","url":"https://codeload.github.com/MercuryWorkshop/firefox/tar.gz/2e1e835a5da5907e5ceef19aade58a7493f1e34d","sha256":"d3d3907c34e498e2a1ef2ada1d11797a4e8075b49ab45b1968aa49d5cddc3096"},
{"file":"emscripten.tar.gz","url":"https://codeload.github.com/emscripten-core/emscripten/tar.gz/refs/tags/6.0.1","sha256":"0187d75d8ff8c5345fcf37deb92c24b7ebd2eb1fe04339c21ea2bcd9d81cc681"},
{"file":"rust-src.tar.xz","url":"https://static.rust-lang.org/dist/rust-src-1.95.0.tar.xz","sha256":"67b09138c8db96afc4bbfc69ea771ac9a091fd777698acb43f6dfd9fb7dea363"},
{"file":"zstddec.tgz","url":"https://registry.npmjs.org/zstddec/-/zstddec-0.2.0.tgz","sha256":"4708fc2e97b5ae6e8c2545ceabdd965bfe8858a5064fce30380eeb4c6ba3f41d"},
{"file":"wrapper-MPL.txt","url":"https://raw.githubusercontent.com/HeyPuter/firefox-wasm/ac40f56c85060bd49dfc36ca60490f97dd270c50/LICENSE","sha256":"3f3d9e0024b1921b067d6f7f88deb4a60cbe7a78e76c64e3f1d7fc3b779b9d04"},
{"file":"vex-sdk-LICENSE.txt","url":"https://raw.githubusercontent.com/vexide/vex-sdk/6c0b83d35b6fc31a7607efe456e387df45476314/LICENSE.md","sha256":"7bc7d5de2a0b793d4e1adb7ffcb99387776adc1f15f055bc3b667ea449249e6a"},
{"file":"NotoSansCJKjp-Regular.otf","url":"https://raw.githubusercontent.com/notofonts/noto-cjk/523d033d6cb47f4a80c58a35753646f5c3608a78/Sans/OTF/Japanese/NotoSansCJKjp-Regular.otf","sha256":"68a3fc98800b2a27b371f2fb79991daf3633bd89309d4ffaa6946fd587f375b5"},
{"file":"NotoSansCJK-LICENSE.txt","url":"https://raw.githubusercontent.com/notofonts/noto-cjk/523d033d6cb47f4a80c58a35753646f5c3608a78/LICENSE","sha256":"6a73f9541c2de74158c0e7cf6b0a58ef774f5a780bf191f2d7ec9cc53efe2bf2"}
]
}
+50
View File
@@ -0,0 +1,50 @@
import hashlib
import io
from pathlib import Path
import tarfile
import tempfile
import unittest
import bundle
class BundleTest(unittest.TestCase):
def test_notice_superset_is_inert(self):
p = bundle.NoticeText()
p.feed('<style>hidden</style><h1>Licenses</h1><p>Copyright &amp; authors</p><script>bad()</script><a href="https://example.org/license">Terms</a>')
result = ''.join(p.parts)
self.assertIn('Copyright & authors', result)
self.assertIn('https://example.org/license', result)
self.assertNotIn('bad()', result)
self.assertNotIn('hidden', result)
def test_hash_rejects_changed_cached_source(self):
with tempfile.TemporaryDirectory() as name:
cache = Path(name)
(cache / 'source').write_bytes(b'changed')
with self.assertRaisesRegex(ValueError, 'checksum'):
bundle.obtain(cache, 'source', 'https://invalid.test', '0' * 64, True)
self.assertEqual(bundle.obtain(cache, 'source', '', hashlib.sha256(b'changed').hexdigest(), True), cache / 'source')
def test_archive_is_read_not_extracted(self):
with tempfile.TemporaryDirectory() as name:
path = Path(name) / 'source.tar.gz'
with tarfile.open(path, 'w:gz') as archive:
member = tarfile.TarInfo('../../LICENSE')
data = b'Copyright owner. Permission notice.'
member.size = len(data)
archive.addfile(member, io.BytesIO(data))
member = tarfile.TarInfo('src/license.html')
data = b'#ifdef OPTIONAL\n<p>Optional terms</p>\n#else\n<p>Other terms</p>\n#endif'
member.size = len(data)
archive.addfile(member, io.BytesIO(data))
notice = bundle.notices(path)
self.assertIn('Copyright owner', notice)
self.assertIn('Optional terms', notice)
self.assertIn('Other terms', notice)
self.assertNotIn('#ifdef', notice)
self.assertEqual(list(Path(name).iterdir()), [path])
if __name__ == '__main__':
unittest.main()