From 3006f342c8d78ea9c992c0960723a420f198c235 Mon Sep 17 00:00:00 2001 From: ggyy <34892002@qq.com> Date: Fri, 7 Aug 2026 09:21:09 +0800 Subject: [PATCH] v 1.5.4 --- .github/workflows/update-edgekey.yml | 50 ++++++++++++++++++++++++++++ CHANGELOG.md | 11 ++++++ modules/payment/hashpay.ts | 22 ++++++++++-- package.json | 2 +- wrangler.jsonc | 2 +- 5 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/update-edgekey.yml diff --git a/.github/workflows/update-edgekey.yml b/.github/workflows/update-edgekey.yml new file mode 100644 index 0000000..381db6a --- /dev/null +++ b/.github/workflows/update-edgekey.yml @@ -0,0 +1,50 @@ +name: Update EdgeKey + +on: + workflow_dispatch: + workflow_call: + +permissions: + contents: write + +concurrency: + group: update-edgekey + cancel-in-progress: false + +jobs: + update: + runs-on: ubuntu-latest + steps: + - name: Checkout instance repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Sync from upstream + shell: bash + run: | + set -euo pipefail + + # Keep instance-specific Cloudflare bindings and compatibility flags. + if [ -f wrangler.jsonc ]; then + cp wrangler.jsonc "$RUNNER_TEMP/wrangler.current.jsonc" + fi + + git fetch https://github.com/34892002/edgeKey.git main + git reset --hard FETCH_HEAD + + if [ -f "$RUNNER_TEMP/wrangler.current.jsonc" ]; then + cp "$RUNNER_TEMP/wrangler.current.jsonc" wrangler.jsonc + fi + + git config user.name "EdgeKey Updater" + git config user.email "actions@github.com" + + if git diff --quiet; then + echo "EdgeKey is already up to date." + else + git add -A + git commit -m "Update EdgeKey from upstream" + fi + + git push --force-with-lease origin "HEAD:${GITHUB_REF_NAME}" diff --git a/CHANGELOG.md b/CHANGELOG.md index 08059f4..1168b14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Change Log +## v1.5.4 (2026-08-07) + +### Bug Fixes + +- **payment:** 修复 EdgeKey 与同一 Cloudflare 账号下的 HashPay Worker 通信时被 `error code: 1042` 拦截的问题。 +- **payment:** HashPay 网关返回非 JSON 响应时,记录 HTTP 状态、响应类型与响应摘要,便于排查上游或网络错误。 + +### Improvements + +- **ci:** 新增可手动触发的 EdgeKey 上游同步工作流;升级时保留实例的 `wrangler.jsonc` 配置。 + ## v1.5.3 (2026-07-22) ### Improvements diff --git a/modules/payment/hashpay.ts b/modules/payment/hashpay.ts index 2c4b5c6..04cdfa6 100644 --- a/modules/payment/hashpay.ts +++ b/modules/payment/hashpay.ts @@ -1,4 +1,4 @@ -import { externalServiceError } from "../../lib/app-error"; +import { externalServiceError, isAppError } from "../../lib/app-error"; import { logger } from "../../lib/logger"; import type { PaymentProviderAdapter, CreatePaymentInput, CreatePaymentResult, VerifyNotifyResult } from "./provider"; @@ -187,8 +187,26 @@ export function createHashpayAdapter(config: HashpayConfig): PaymentProviderAdap }, body: requestBody, }); - json = (await response.json()) as HashpayResponse; + const responseText = await response.text(); + + try { + json = JSON.parse(responseText) as HashpayResponse; + } catch { + const responsePreview = responseText.replace(/\s+/g, " ").trim().slice(0, 300); + logger.warn("hashpay.invalid_response", { + status: response.status, + contentType: response.headers.get("content-type"), + responsePreview, + }); + throw externalServiceError( + `HashPay 网关返回非 JSON 响应(HTTP ${response.status}):${responsePreview || "空响应"}`, + "HASHPAY_INVALID_RESPONSE" + ); + } } catch (err) { + if (isAppError(err)) { + throw err; + } throw externalServiceError( `HashPay 请求失败: ${err instanceof Error ? err.message : String(err)}`, "HASHPAY_INVALID_RESPONSE" diff --git a/package.json b/package.json index 42a5daa..e2689b2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.5.3", + "version": "1.5.4", "scripts": { "dev": "vike dev", "build": "bun run db:generate && vike build", diff --git a/wrangler.jsonc b/wrangler.jsonc index 41bfebc..ebbe634 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -3,7 +3,7 @@ "name": "edge-key", "compatibility_date": "2026-03-12", "main": "virtual:photon:cloudflare:server-entry", - "compatibility_flags": ["nodejs_compat"], + "compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"], "observability": { "enabled": true, "head_sampling_rate": 0.1