From e7d2c85de99c51fd52abae0cb83d0bb6dbd8b485 Mon Sep 17 00:00:00 2001 From: shuaiplus <2327005759@qq.com> Date: Sat, 7 Mar 2026 06:36:41 +0800 Subject: [PATCH] chore: remove obsolete workflows and update sync process in sync-upstream.yml --- .../import-kv-id-from-nodewarden2.yml | 59 -------------- .github/workflows/switch-to-kv-mode.yml | 80 ------------------- .github/workflows/switch-to-r2-mode.yml | 80 ------------------- .github/workflows/sync-upstream.yml | 33 +------- README.md | 68 ++++------------ README_EN.md | 64 ++++----------- package-lock.json | 4 +- package.json | 2 +- wrangler.kv.toml | 8 +- 9 files changed, 42 insertions(+), 356 deletions(-) delete mode 100644 .github/workflows/import-kv-id-from-nodewarden2.yml delete mode 100644 .github/workflows/switch-to-kv-mode.yml delete mode 100644 .github/workflows/switch-to-r2-mode.yml diff --git a/.github/workflows/import-kv-id-from-nodewarden2.yml b/.github/workflows/import-kv-id-from-nodewarden2.yml deleted file mode 100644 index 0884ad4..0000000 --- a/.github/workflows/import-kv-id-from-nodewarden2.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Import KV ID from NodeWarden2 - -on: - workflow_dispatch: - -permissions: - contents: write - -jobs: - patch: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Configure git - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - - name: Import KV namespace id from NodeWarden2 - env: - REPO_OWNER: ${{ github.repository_owner }} - run: | - python - <<'PY' - import os - import re - from pathlib import Path - from urllib.request import urlopen - - owner = os.environ["REPO_OWNER"] - source_url = f"https://raw.githubusercontent.com/{owner}/nodewarden2/main/wrangler.toml" - with urlopen(source_url) as response: - source_text = response.read().decode("utf-8") - - source_match = re.search(r'id\s*=\s*"([^"]+)"', source_text) - if not source_match: - raise SystemExit('No `id = "..."` found in nodewarden2/wrangler.toml') - - kv_id = source_match.group(1) - - target_path = Path("wrangler.toml") - target_text = target_path.read_text(encoding="utf-8") - target_text, count = re.subn(r'id\s*=\s*"[^"]+"', f'id = "{kv_id}"', target_text, count=1) - - if count == 0: - raise SystemExit('No `id = "..."` found in current wrangler.toml') - - target_path.write_text(target_text, encoding="utf-8") - PY - - - name: Commit imported KV id - run: | - git add wrangler.toml - git diff --cached --quiet && exit 0 - git commit -m "chore: import kv id from nodewarden2" - git push origin main diff --git a/.github/workflows/switch-to-kv-mode.yml b/.github/workflows/switch-to-kv-mode.yml deleted file mode 100644 index b2b1eed..0000000 --- a/.github/workflows/switch-to-kv-mode.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Switch to KV mode - -on: - workflow_dispatch: - -permissions: - contents: write - -jobs: - patch: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Configure git - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - - name: Switch wrangler.toml to KV mode - run: | - python - <<'PY' - import re - from pathlib import Path - - path = Path("wrangler.toml") - text = path.read_text(encoding="utf-8") - - pattern = ( - r"\[\[r2_buckets\]\]\s*" - r'binding\s*=\s*"ATTACHMENTS"\s*' - r'bucket_name\s*=\s*"nodewarden-attachments"\s*' - ) - replacement = ( - '[[kv_namespaces]]\n' - 'binding = "ATTACHMENTS_KV"\n' - 'id = "placeholder"\n' - ) - - new_text, count = re.subn(pattern, replacement, text, count=1) - if count == 0 and 'binding = "ATTACHMENTS_KV"' not in text: - raise SystemExit("Expected R2 block not found in wrangler.toml") - - if count > 0: - path.write_text(new_text, encoding="utf-8") - PY - - - name: Update deploy button link in README files - env: - REPO_SLUG: ${{ github.repository }} - run: | - python - <<'PY' - import os - import re - from pathlib import Path - - repo_slug = os.environ["REPO_SLUG"] - deploy_url = f"https://deploy.workers.cloudflare.com/?url=https://github.com/{repo_slug}" - - pattern = re.compile( - r'https://deploy\.workers\.cloudflare\.com/\?url=https://github\.com/[^)\s]+' - ) - - for file_name in ("README.md", "README_EN.md"): - path = Path(file_name) - text = path.read_text(encoding="utf-8") - new_text, count = pattern.subn(deploy_url, text, count=2) - if count > 0: - path.write_text(new_text, encoding="utf-8") - PY - - - name: Commit KV mode change - run: | - git add wrangler.toml README.md README_EN.md - git diff --cached --quiet && exit 0 - git commit -m "chore: switch wrangler.toml to KV mode" - git push origin main diff --git a/.github/workflows/switch-to-r2-mode.yml b/.github/workflows/switch-to-r2-mode.yml deleted file mode 100644 index 3e7eb0e..0000000 --- a/.github/workflows/switch-to-r2-mode.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Switch to R2 mode - -on: - workflow_dispatch: - -permissions: - contents: write - -jobs: - patch: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Configure git - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - - name: Switch wrangler.toml to R2 mode - run: | - python - <<'PY' - import re - from pathlib import Path - - path = Path("wrangler.toml") - text = path.read_text(encoding="utf-8") - - pattern = ( - r"\[\[kv_namespaces\]\]\s*" - r'binding\s*=\s*"ATTACHMENTS_KV"\s*' - r'id\s*=\s*"placeholder"\s*' - ) - replacement = ( - '[[r2_buckets]]\n' - 'binding = "ATTACHMENTS"\n' - 'bucket_name = "nodewarden-attachments"\n' - ) - - new_text, count = re.subn(pattern, replacement, text, count=1) - if count == 0 and 'binding = "ATTACHMENTS"' not in text: - raise SystemExit("Expected KV block not found in wrangler.toml") - - if count > 0: - path.write_text(new_text, encoding="utf-8") - PY - - - name: Update deploy button link in README files - env: - REPO_SLUG: ${{ github.repository }} - run: | - python - <<'PY' - import os - import re - from pathlib import Path - - repo_slug = os.environ["REPO_SLUG"] - deploy_url = f"https://deploy.workers.cloudflare.com/?url=https://github.com/{repo_slug}" - - pattern = re.compile( - r'https://deploy\.workers\.cloudflare\.com/\?url=https://github\.com/[^)\s]+' - ) - - for file_name in ("README.md", "README_EN.md"): - path = Path(file_name) - text = path.read_text(encoding="utf-8") - new_text, count = pattern.subn(deploy_url, text, count=2) - if count > 0: - path.write_text(new_text, encoding="utf-8") - PY - - - name: Commit R2 mode change - run: | - git add wrangler.toml README.md README_EN.md - git diff --cached --quiet && exit 0 - git commit -m "chore: switch wrangler.toml to R2 mode" - git push origin main diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml index 316dbac..76e2953 100644 --- a/.github/workflows/sync-upstream.yml +++ b/.github/workflows/sync-upstream.yml @@ -22,40 +22,13 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - - name: Sync main from upstream but keep local wrangler.toml + - name: Sync main from upstream run: | - cp wrangler.toml /tmp/nodewarden-wrangler.toml git remote add upstream https://github.com/shuaiplus/NodeWarden.git || true git fetch upstream git checkout main - git reset --hard upstream/main - cp /tmp/nodewarden-wrangler.toml wrangler.toml - - - name: Update deploy button links in README files - env: - REPO_SLUG: ${{ github.repository }} - run: | - python - <<'PY' - import os - import re - from pathlib import Path - - repo_slug = os.environ["REPO_SLUG"] - deploy_url = f"https://deploy.workers.cloudflare.com/?url=https://github.com/{repo_slug}" - pattern = re.compile( - r'https://deploy\.workers\.cloudflare\.com/\?url=https://github\.com/[^)\s]+' - ) - - for file_name in ("README.md", "README_EN.md"): - path = Path(file_name) - text = path.read_text(encoding="utf-8") - new_text, _ = pattern.subn(deploy_url, text) - path.write_text(new_text, encoding="utf-8") - PY + git merge upstream/main - name: Push synced main run: | - git add wrangler.toml README.md README_EN.md - git diff --cached --quiet && exit 0 - git commit -m "chore: sync upstream while keeping local deploy config" - git push origin main --force + git push origin main diff --git a/README.md b/README.md index 57c5f4a..877157b 100644 --- a/README.md +++ b/README.md @@ -50,51 +50,26 @@ English:[`README_EN.md`](./README_EN.md) - ⬜ macOS 客户端(未测试) --- -# 快速开始 -### 一键部署 +## 网页部署 -> **若你只是想快速体验,直接点击第 2 步的一键部署按钮即可;以下步骤主要为了后续长期更新。** +1. Fork 本仓库。若本项目对你有帮助,欢迎点个 Star。 +2. 打开 [Workers](https://deploy.workers.cloudflare.com/) ➜ 点击 `取消` ➜ `Continue with GitHub` ➜ 选择你 Fork 后的仓库(`NodeWarden`)➜ 下一步 ➜ (默认使用 R2 存储;若未开通,可切换为 KV,并将部署命令改为 `npm run deploy:kv`)➜ 部署 ➜ 打开生成的链接 - -1. 先 Fork 本仓库,并命名为 **NodeWarden**。 -2. 点击下面的按钮,在打开的页面中将项目名称改为 **NodeWarden2**,并将 **JWT_SECRET** 设置为 32 位随机字符串。 - - [![Deploy (R2)](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/shuaiplus/NodeWarden) - -3. 部署完成后,在同一页面打开 Workers 设置,将 `Git 存储库` 断开连接。 -4. 在同一位置重新连接到第 1 步 Fork 的仓库,并在页面底部将`名称` 改回 **NodeWarden**。 -5. GitHub 仓库 **NodeWarden2** 可以删除。 - -
-📦 若未绑定银行卡、无法启用 R2 对象存储,可改用 KV 模式 - -
- ->- **R2**:需绑定银行卡;**单个附件 / Send 文件上限 100 MB**(代码限制,可自行修改);**总量 10 GB 免费** ->- **KV**:无需绑卡;**单个附件 / Send 文件上限 25 MiB**(Cloudflare 限制,不可修改);**总量 1 GB 免费** -> ->1. 先 Fork 本仓库,并命名为 **NodeWarden**(默认自动填写) ->2. 进入新仓库,进入 `Actions` 页面,点击 `I understand my workflows, go ahead and enable them`,点击 `Switch to KV mode`,点击`Run Workflow` ->3. 成功后**在你自己的仓库中**点击下面的按钮,在打开的页面中将项目名称改为 **NodeWarden2**,并将 **JWT_SECRET** 设置为 32 位随机字符串。(不能选`创建专用 Git 存储库`) -> -> [![Deploy (R2)](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/shuaiplus/NodeWarden) -> ->4. 在同一页面打开 Workers 设置,将 `Git 存储库` 断开连接。 ->5. 返回Github进入Fork后的仓库(NodeWarden),进入 `Actions` 页面,运行`Import KV ID from NodeWarden2` ->6. 返回cloudflare,`Git 存储库`连接到Fork后的仓库(NodeWarden),并在页面底部将`名称`改回 **NodeWarden**。 ->7. GitHub 仓库 **NodeWarden2** 可以删除了。 - -
+ | 储存 | 是否需绑卡 | 单个附件/Send文件上限 | 免费额度 | + |---|---|---|---| + | R2 | 需要 | 100 MB(软限制可更改) | 10 GB | + | KV | 不需要 | 25 MiB(Cloudflare限制) | 1 GB | > [!TIP] > 同步方法(更新仓库): ->- 手动:打开你 Fork 的 GitHub 仓库,看到顶部同步提示后,点击 `Sync fork`,点击`Update branch` ->- 自动:进入你的 Fork 仓库 -> `Actions`->`Sync upstream`->`Enable workflow`,会在每天凌晨 3 点自动同步上游。 +>- 手动:打开你 Fork 的 GitHub 仓库,看到顶部同步提示后,点击 `Sync fork` ➜ `Update branch` +>- 自动:进入你的 Fork 仓库 ➜ `Actions` ➜ `Sync upstream` ➜ `Enable workflow`,会在每天凌晨 3 点自动同步上游。 -### CLI 部署 + +## CLI 部署 ```powershell # 先把仓库拉到本地 @@ -107,34 +82,23 @@ npm install # Cloudflare CLI 登录 npx wrangler login -# 创建云资源(D1 + R2) -npx wrangler d1 create nodewarden-db -npx wrangler r2 bucket create nodewarden-attachments - -# 部署 +# 部署到 Cloudflare npm run deploy # (可选)KV 模式(无 R2 / 无信用卡) -npx wrangler kv namespace create ATTACHMENTS_KV -# 将返回的 namespace id 替换 wrangler.kv.toml 中 `id = "placeholder"` 里的 placeholder(保留双引号) npm run deploy:kv +# 本地开发 +npm run dev +npm run dev:kv + # 后续更新时重新拉取仓库并重新部署即可,无需重复创建云资源 git clone https://github.com/shuaiplus/NodeWarden.git cd NodeWarden npm run deploy ``` ---- -## 本地开发 - -这是一个 Cloudflare Workers 的 TypeScript 项目(Wrangler)。 - -```bash -npm install -npm run dev -``` --- ## 常见问题 diff --git a/README_EN.md b/README_EN.md index 6cc2475..43ad084 100644 --- a/README_EN.md +++ b/README_EN.md @@ -51,46 +51,22 @@ --- -# Quick start +## Web deploy -### One-click deploy +1. Fork this repository. If you find this project helpful, please consider giving it a Star. +2. Open [Workers](https://deploy.workers.cloudflare.com/) -> click `Cancel` -> `Continue with GitHub` -> select your forked repository (`NodeWarden`) -> `Next` -> (R2 storage is used by default; if R2 is unavailable for your account, switch to KV and change the deploy command to `npm run deploy:kv`) -> deploy -> open the generated URL. -> **If you only want a quick trial, simply click the one-click deploy button in step 2. The remaining steps are mainly for long-term maintenance.** - -1. Fork this repository and name it **NodeWarden**. -2. Click the button below. On the page that opens, rename the project to **NodeWarden2** and set **JWT_SECRET** to a random 32-character string. - - [![Deploy](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/shuaiplus/NodeWarden) -3. After deployment, open the Worker settings on the same page and disconnect the **Git repository**. -4. Reconnect the **Git repository** to the fork from step 1, then change the **Name** field at the bottom to **NodeWarden**. -5. The temporary **NodeWarden2** repository can be deleted. - -
-📦 If you do not have a payment method attached and cannot enable R2 object storage, you can use KV mode instead - -
- ->- **R2**: requires a payment method; **single attachment / Send file limit is 100 MB** (project-level limit, editable in code); **10 GB free storage** ->- **KV**: no card required; **single attachment / Send file limit is 25 MiB** (Cloudflare limit, not editable); **1 GB free storage** -> ->1. Fork this repository and name it **NodeWarden**. ->2. Open the new repository, go to `Actions`, click `I understand my workflows, go ahead and enable them`, then run `Switch to KV mode`. ->3. After that, **in your own repository**, click the button below. On the page that opens, rename the project to **NodeWarden2** and set **JWT_SECRET** to a random 32-character string. Do not select `Create dedicated Git repository`. -> -> [![Deploy](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/shuaiplus/NodeWarden) -> ->4. On the same page, open Worker settings and disconnect the `Git repository`. ->5. Go back to your forked repository (**NodeWarden**) on GitHub, open `Actions`, and run `Import KV ID from NodeWarden2`. ->6. Return to Cloudflare, reconnect the `Git repository` to your forked repository (**NodeWarden**), and change the `Name` field at the bottom back to **NodeWarden**. ->7. The GitHub repository **NodeWarden2** can then be deleted. -
+| Storage | Card required | Single attachment / Send file limit | Free tier | +|---|---|---|---| +| R2 | Yes | 100 MB (soft limit, can be changed) | 10 GB | +| KV | No | 25 MiB (Cloudflare limit, cannot be changed) | 1 GB | > [!TIP] > Sync upstream (keep your fork updated): >- Manual: open your fork on GitHub, click `Sync fork`, then click `Update branch`. >- Automatic: in your fork, go to `Actions` -> `Sync upstream` -> `Enable workflow`. It will automatically sync from upstream every day at 3 AM. -### CLI deploy +## CLI deploy ```powershell # Clone repository @@ -103,33 +79,21 @@ npm install # Cloudflare CLI login npx wrangler login -# Create cloud resources (D1 + R2) -npx wrangler d1 create nodewarden-db -npx wrangler r2 bucket create nodewarden-attachments - -# Deploy +# Deploy to Cloudflare npm run deploy # (Optional) KV mode (no R2 / no credit card) -npx wrangler kv namespace create ATTACHMENTS_KV -# Replace placeholder inside `id = "placeholder"` in wrangler.kv.toml with the returned namespace id (keep the quotes) npm run deploy:kv -# To update later: re-clone and re-deploy — no need to recreate cloud resources +# Local development +npm run dev +npm run dev:kv + +# To update later, pull the repository again and redeploy git clone https://github.com/shuaiplus/NodeWarden.git cd NodeWarden npm run deploy ``` - ---- -## Local development - -This repo is a Cloudflare Workers TypeScript project (Wrangler). - -```bash -npm install -npm run dev -``` --- ## FAQ diff --git a/package-lock.json b/package-lock.json index 4711475..8528c46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nodewarden", - "version": "1.1.0", + "version": "1.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nodewarden", - "version": "1.1.0", + "version": "1.3.0", "license": "LGPL-3.0", "dependencies": { "@noble/hashes": "^2.0.1", diff --git a/package.json b/package.json index ade3ea5..968410c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodewarden", - "version": "1.1.0", + "version": "1.3.0", "description": "Minimal Bitwarden-compatible server running on Cloudflare Workers", "author": "shuaiplus", "license": "LGPL-3.0", diff --git a/wrangler.kv.toml b/wrangler.kv.toml index 5509bb4..2152fdd 100644 --- a/wrangler.kv.toml +++ b/wrangler.kv.toml @@ -1,7 +1,11 @@ name = "nodewarden" main = "src/index.ts" compatibility_date = "2024-01-01" -assets = { directory = "./dist", not_found_handling = "single-page-application", run_worker_first = ["/api/*", "/identity/*", "/icons/*", "/setup/*", "/config", "/notifications/*", "/.well-known/*"] } + +[assets] +directory = "./dist" +not_found_handling = "single-page-application" +run_worker_first = [ "/api/*", "/identity/*", "/icons/*", "/setup/*", "/config", "/notifications/*", "/.well-known/*" ] [build] command = "npm run build" @@ -12,4 +16,4 @@ database_name = "nodewarden-db" [[kv_namespaces]] binding = "ATTACHMENTS_KV" -id = "placeholder" +id = "5441c718d39e49229fc9c0e5ca0eff8f"