From c0a531fd1d5abff866b5aec9d9bd5810bb5ddf27 Mon Sep 17 00:00:00 2001 From: wxs Date: Mon, 16 Mar 2026 12:15:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=BA=E5=A4=B1=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pugongying/xhs-pgy-export.user.js | 10 +++---- pugongying/xhs-pgy-export.user.test.js | 40 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 pugongying/xhs-pgy-export.user.test.js diff --git a/pugongying/xhs-pgy-export.user.js b/pugongying/xhs-pgy-export.user.js index 8f491f8..f308d29 100644 --- a/pugongying/xhs-pgy-export.user.js +++ b/pugongying/xhs-pgy-export.user.js @@ -51,7 +51,7 @@ { namespace: "dataSummary", buildUrl: (userId) => - `${PROXY_API_BASE}/v1/pugongying/data_summary?userId=${encodeURIComponent(userId)}`, + `${PROXY_API_BASE}/v1/pugongying/data_summary?userId=${encodeURIComponent(userId)}&business=1`, extraHeaders: () => ({ "X-Cookie": root.document.cookie, "Authorization": "Bearer PsjpalaBZF2EVIyU5M7V9KHzUstOIN82LyMn9nqLekExyxIBnjjURlMKMDBSZwrG", @@ -80,7 +80,10 @@ "dataSummary.estimateVideoCpm": "预估CPM(视频)", "dataSummary.picReadCost": "预估阅读单价(图文)", "dataSummary.videoReadCost": "预估阅读单价(视频)", - "dataSummary.fans30GrowthRate": "粉丝量变化幅度", + "dataSummary.fans30GrowthRate": "粉丝量变化幅度(%)", + "dataSummary.mAccumImpNum": "曝光中位数", + "dataSummary.mEngagementNum": "互动中位数", + "dataSummary.readMedian": "阅读中位数", fansSummary: "粉丝概览", "fansSummary.activeFansRate": "活跃粉丝占比(%)", "fansSummary.readFansRate": "阅读粉丝占比(%)", @@ -107,9 +110,6 @@ lowerPrice: "最低报价", userType: "用户类型", tradeType: "合作行业", - clickMidNum: "阅读中位数", - accumCoopImpMedinNum30d: "近30天合作曝光中位数", - mEngagementNum: "互动中位数", }; const SELECTABLE_FIELD_PATHS = Object.keys(FIELD_LABEL_MAP).filter( (path) => !(path in NAMESPACE_LABEL_MAP), diff --git a/pugongying/xhs-pgy-export.user.test.js b/pugongying/xhs-pgy-export.user.test.js new file mode 100644 index 0000000..26bcb00 --- /dev/null +++ b/pugongying/xhs-pgy-export.user.test.js @@ -0,0 +1,40 @@ +const test = require("node:test"); +const assert = require("node:assert/strict"); + +// The userscript exports some helpers in a shorthand object; in Node that means any +// undeclared identifiers referenced there must exist on `global`. +global.buildSpreadsheetXml = () => ""; +global.document = { cookie: "x=y" }; + +const api = require("./xhs-pgy-export.user.js"); + +function okJson(payload) { + return { + ok: true, + status: 200, + async json() { + return payload; + }, + }; +} + +test("data_summary request includes business=1", async () => { + const urls = []; + + async function fetchImpl(url) { + urls.push(url); + if (String(url).startsWith(api.API_BASE)) { + return okJson({ data: { userId: "u-123" } }); + } + return okJson({ data: {} }); + } + + await api.fetchMergedBloggerRecord("any-id", fetchImpl); + + const target = urls.find((u) => String(u).includes("/v1/pugongying/data_summary")); + assert.ok(target, "expected a call to /v1/pugongying/data_summary"); + + const parsed = new URL(target); + assert.equal(parsed.searchParams.get("business"), "1"); + assert.equal(parsed.searchParams.get("userId"), "u-123"); +});