@chainlesschain/personal-data-hub 0.4.6 → 0.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/adapters/doc-baidu-netdisk.test.js +102 -0
- package/__tests__/adapters/doc-platforms.test.js +177 -0
- package/__tests__/adapters/music-kugou.test.js +187 -0
- package/__tests__/adapters/recruit-boss.test.js +180 -0
- package/__tests__/adapters/shopping-dianping.test.js +239 -0
- package/__tests__/adapters/social-csdn.test.js +175 -0
- package/__tests__/adapters/social-zhihu.test.js +246 -0
- package/__tests__/adapters/travel-12306.test.js +234 -1
- package/__tests__/adapters/travel-ctrip.test.js +175 -1
- package/__tests__/adapters/travel-didi.test.js +204 -0
- package/__tests__/adapters/travel-tongcheng.test.js +289 -0
- package/__tests__/adapters/video-platforms.test.js +152 -0
- package/lib/adapter-guide.js +13 -1
- package/lib/adapters/_document-base.js +370 -0
- package/lib/adapters/_video-base.js +331 -0
- package/lib/adapters/doc-baidu-netdisk/index.js +91 -0
- package/lib/adapters/doc-tencent-docs/index.js +94 -0
- package/lib/adapters/doc-wps/index.js +77 -0
- package/lib/adapters/music-kugou/index.js +418 -0
- package/lib/adapters/recruit-boss/index.js +442 -0
- package/lib/adapters/shopping-dianping/index.js +473 -0
- package/lib/adapters/social-csdn/index.js +444 -0
- package/lib/adapters/social-zhihu/index.js +488 -0
- package/lib/adapters/travel-12306/index.js +279 -5
- package/lib/adapters/travel-ctrip/index.js +255 -40
- package/lib/adapters/travel-didi/index.js +327 -0
- package/lib/adapters/travel-tongcheng/index.js +393 -0
- package/lib/adapters/video-iqiyi/index.js +75 -0
- package/lib/adapters/video-tencent/index.js +78 -0
- package/lib/index.js +24 -0
- package/package.json +1 -1
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const os = require("node:os");
|
|
7
|
+
const crypto = require("node:crypto");
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
TongchengAdapter,
|
|
11
|
+
parseRecords,
|
|
12
|
+
orderToRecord,
|
|
13
|
+
extractOrders,
|
|
14
|
+
TYPE_MAP,
|
|
15
|
+
NAME,
|
|
16
|
+
VERSION,
|
|
17
|
+
} = require("../../lib/adapters/travel-tongcheng");
|
|
18
|
+
|
|
19
|
+
function writeTmp(content) {
|
|
20
|
+
const p = path.join(os.tmpdir(), `cc-tc-${crypto.randomUUID()}.json`);
|
|
21
|
+
fs.writeFileSync(p, content, "utf-8");
|
|
22
|
+
return p;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function collect(gen) {
|
|
26
|
+
const out = [];
|
|
27
|
+
for await (const x of gen) out.push(x);
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const FLIGHT_ORDER = {
|
|
32
|
+
orderId: "TC1",
|
|
33
|
+
projectType: "flight",
|
|
34
|
+
departureCity: "上海",
|
|
35
|
+
arrivalCity: "北京",
|
|
36
|
+
departureDate: 1716383021000,
|
|
37
|
+
airlineName: "东方航空",
|
|
38
|
+
flightNumber: "MU5101",
|
|
39
|
+
amount: "1180.00",
|
|
40
|
+
passengerName: "张三",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const COOKIES = "clientId=abc; tc_token=xyz; memberId=m1";
|
|
44
|
+
|
|
45
|
+
describe("constants + TYPE_MAP", () => {
|
|
46
|
+
it("exposes name/version", () => {
|
|
47
|
+
expect(NAME).toBe("travel-tongcheng");
|
|
48
|
+
expect(VERSION).toBe("0.1.0");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("maps tongcheng order types (incl. Chinese + scenery→attraction)", () => {
|
|
52
|
+
expect(TYPE_MAP.flight).toBe("flight");
|
|
53
|
+
expect(TYPE_MAP["机票"]).toBe("flight");
|
|
54
|
+
expect(TYPE_MAP["酒店"]).toBe("hotel");
|
|
55
|
+
expect(TYPE_MAP["火车票"]).toBe("train");
|
|
56
|
+
expect(TYPE_MAP["门票"]).toBe("attraction");
|
|
57
|
+
expect(TYPE_MAP["汽车票"]).toBe("bus");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("parseRecords / orderToRecord", () => {
|
|
62
|
+
it("parses flight order (projectType/amount/departureCity aliases)", () => {
|
|
63
|
+
const recs = parseRecords(JSON.stringify([FLIGHT_ORDER]));
|
|
64
|
+
expect(recs).toHaveLength(1);
|
|
65
|
+
expect(recs[0]).toMatchObject({
|
|
66
|
+
vendorId: "tongcheng",
|
|
67
|
+
recordId: "TC1",
|
|
68
|
+
vehicleType: "flight",
|
|
69
|
+
from: { city: "上海" },
|
|
70
|
+
to: { city: "北京" },
|
|
71
|
+
departureMs: 1716383021000,
|
|
72
|
+
carrier: "东方航空",
|
|
73
|
+
vehicleNumber: "MU5101",
|
|
74
|
+
traveler: "张三",
|
|
75
|
+
});
|
|
76
|
+
expect(recs[0].totalCost).toEqual({ value: 1180, currency: "CNY" });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("hotel order: hotelCity→to, hotelName→carrier, checkIn→time", () => {
|
|
80
|
+
const recs = parseRecords(
|
|
81
|
+
JSON.stringify([
|
|
82
|
+
{
|
|
83
|
+
orderId: "H1",
|
|
84
|
+
projectType: "hotel",
|
|
85
|
+
hotelCity: "杭州",
|
|
86
|
+
hotelName: "西湖国宾馆",
|
|
87
|
+
checkIn: "2026年5月1日",
|
|
88
|
+
linkName: "李四",
|
|
89
|
+
nights: 2,
|
|
90
|
+
},
|
|
91
|
+
]),
|
|
92
|
+
);
|
|
93
|
+
expect(recs[0]).toMatchObject({
|
|
94
|
+
recordId: "H1",
|
|
95
|
+
vehicleType: "hotel",
|
|
96
|
+
to: { city: "杭州" },
|
|
97
|
+
carrier: "西湖国宾馆",
|
|
98
|
+
traveler: "李四",
|
|
99
|
+
});
|
|
100
|
+
expect(recs[0].from).toBe(null);
|
|
101
|
+
expect(recs[0].extras.nights).toBe(2);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("scenery/门票 order maps to attraction; sceneryName→carrier/to", () => {
|
|
105
|
+
const rec = orderToRecord({ orderId: "S1", projectType: "门票", sceneryName: "黄山风景区", amount: 230 });
|
|
106
|
+
expect(rec.vehicleType).toBe("attraction");
|
|
107
|
+
expect(rec.carrier).toBe("黄山风景区");
|
|
108
|
+
expect(rec.totalCost.value).toBe(230);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("unknown type → trip + default carrier 同程; drops id-less rows", () => {
|
|
112
|
+
expect(orderToRecord({ order_no: "X1" }).vehicleType).toBe("trip");
|
|
113
|
+
expect(orderToRecord({ order_no: "X1" }).carrier).toBe("同程");
|
|
114
|
+
expect(orderToRecord({ projectType: "flight" })).toBe(null);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("accepts {orders:[...]} envelope + JSONL fallback", () => {
|
|
118
|
+
expect(parseRecords(JSON.stringify({ orders: [FLIGHT_ORDER] }))).toHaveLength(1);
|
|
119
|
+
const jsonl = `${JSON.stringify(FLIGHT_ORDER)}\ngarbage\n${JSON.stringify({ ...FLIGHT_ORDER, orderId: "TC2" })}`;
|
|
120
|
+
expect(parseRecords(jsonl).map((r) => r.recordId)).toEqual(["TC1", "TC2"]);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe("extractOrders", () => {
|
|
125
|
+
it("pulls list from common shapes", () => {
|
|
126
|
+
expect(extractOrders({ orders: [{ orderId: "A" }] })).toHaveLength(1);
|
|
127
|
+
expect(extractOrders({ data: { orderList: [{ orderId: "B" }] } })).toHaveLength(1);
|
|
128
|
+
expect(extractOrders({ data: { records: [{ orderId: "C" }] } })).toHaveLength(1);
|
|
129
|
+
expect(extractOrders({})).toEqual([]);
|
|
130
|
+
expect(extractOrders(null)).toEqual([]);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("TongchengAdapter file/snapshot mode", () => {
|
|
135
|
+
it("authenticate ready mode without account", async () => {
|
|
136
|
+
const a = new TongchengAdapter();
|
|
137
|
+
expect(await a.authenticate({})).toEqual({ ok: true, account: null, mode: "ready" });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("authenticate validates inputPath readability", async () => {
|
|
141
|
+
const p = writeTmp("[]");
|
|
142
|
+
try {
|
|
143
|
+
const a = new TongchengAdapter();
|
|
144
|
+
expect((await a.authenticate({ inputPath: p })).mode).toBe("snapshot-file");
|
|
145
|
+
const bad = await a.authenticate({ inputPath: path.join(os.tmpdir(), "nope-tc.json") });
|
|
146
|
+
expect(bad.ok).toBe(false);
|
|
147
|
+
expect(bad.reason).toBe("INPUT_PATH_UNREADABLE");
|
|
148
|
+
} finally {
|
|
149
|
+
fs.unlinkSync(p);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("sync yields orders from file + normalize end-to-end", async () => {
|
|
154
|
+
const p = writeTmp(JSON.stringify([FLIGHT_ORDER]));
|
|
155
|
+
try {
|
|
156
|
+
const a = new TongchengAdapter();
|
|
157
|
+
const items = await collect(a.sync({ inputPath: p }));
|
|
158
|
+
expect(items).toHaveLength(1);
|
|
159
|
+
expect(items[0]).toMatchObject({ adapter: NAME, originalId: "TC1" });
|
|
160
|
+
const batch = a.normalize(items[0]);
|
|
161
|
+
expect(batch.events[0].content.title).toBe("flight: 上海 → 北京");
|
|
162
|
+
expect(batch.events[0].content.amount).toEqual({ value: 1180, currency: "CNY", direction: "out" });
|
|
163
|
+
expect(batch.persons.find((x) => x.subtype === "merchant").names).toEqual(["东方航空"]);
|
|
164
|
+
} finally {
|
|
165
|
+
fs.unlinkSync(p);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("sync returns silently when no path / missing file", async () => {
|
|
170
|
+
const a = new TongchengAdapter();
|
|
171
|
+
expect(await collect(a.sync({}))).toEqual([]);
|
|
172
|
+
expect(await collect(a.sync({ inputPath: path.join(os.tmpdir(), "nope-tc2.json") }))).toEqual([]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("normalize throws on missing record", () => {
|
|
176
|
+
const a = new TongchengAdapter();
|
|
177
|
+
expect(() => a.normalize({ payload: {} })).toThrow(/payload\.record missing/);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("TongchengAdapter cookie-api mode", () => {
|
|
182
|
+
it("authenticate cookie mode (account OPTIONAL)", async () => {
|
|
183
|
+
const a = new TongchengAdapter({ account: { cookies: COOKIES } });
|
|
184
|
+
expect(await a.authenticate()).toEqual({ ok: true, account: null, mode: "cookie" });
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("empty cookies → ready (not cookie mode)", async () => {
|
|
188
|
+
const a = new TongchengAdapter({ account: { cookies: "" } });
|
|
189
|
+
expect((await a.authenticate()).mode).toBe("ready");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("sync fetches, paginates, maps + normalizes", async () => {
|
|
193
|
+
const pages = [
|
|
194
|
+
{
|
|
195
|
+
orderList: [
|
|
196
|
+
{ orderId: "CK1", projectType: "train", departureCity: "广州", arrivalCity: "深圳", amount: "75", orderDate: 1716383021000, trainNo: "G6501" },
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
{ orderList: [] },
|
|
200
|
+
];
|
|
201
|
+
const calls = [];
|
|
202
|
+
const fetchFn = async ({ url, cookies, query, sign }) => {
|
|
203
|
+
calls.push({ url, cookies, pageIndex: query.pageIndex, sign });
|
|
204
|
+
return pages[query.pageIndex - 1] || { orderList: [] };
|
|
205
|
+
};
|
|
206
|
+
const a = new TongchengAdapter({ account: { cookies: COOKIES }, fetchFn });
|
|
207
|
+
const items = await collect(a.sync({ sinceWatermark: 0 }));
|
|
208
|
+
expect(items).toHaveLength(1);
|
|
209
|
+
expect(items[0]).toMatchObject({ adapter: NAME, originalId: "CK1" });
|
|
210
|
+
expect(calls[0].cookies).toBe(COOKIES);
|
|
211
|
+
expect(calls[0].sign).toBe(null);
|
|
212
|
+
const batch = a.normalize(items[0]);
|
|
213
|
+
expect(batch.events[0].content.title).toBe("train: 广州 → 深圳");
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("invokes signProvider when configured", async () => {
|
|
217
|
+
const signCalls = [];
|
|
218
|
+
const a = new TongchengAdapter({
|
|
219
|
+
account: { cookies: COOKIES },
|
|
220
|
+
fetchFn: async ({ query }) =>
|
|
221
|
+
query.pageIndex === 1 ? { orders: [{ orderId: "S1", projectType: "hotel" }] } : { orders: [] },
|
|
222
|
+
signProvider: async (ctx) => {
|
|
223
|
+
signCalls.push(ctx);
|
|
224
|
+
return "TC-SIGN";
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
const items = await collect(a.sync({ sinceWatermark: 0 }));
|
|
228
|
+
expect(items).toHaveLength(1);
|
|
229
|
+
expect(signCalls).toHaveLength(1);
|
|
230
|
+
expect(signCalls[0].cookies).toBe(COOKIES);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("stops at sinceWatermark", async () => {
|
|
234
|
+
const a = new TongchengAdapter({
|
|
235
|
+
account: { cookies: COOKIES },
|
|
236
|
+
fetchFn: async () => ({
|
|
237
|
+
orderList: [
|
|
238
|
+
{ orderId: "NEW", projectType: "flight", orderDate: 2_000_000_000_000 },
|
|
239
|
+
{ orderId: "OLD", projectType: "flight", orderDate: 1_000_000_000_000 },
|
|
240
|
+
],
|
|
241
|
+
}),
|
|
242
|
+
});
|
|
243
|
+
const items = await collect(a.sync({ sinceWatermark: 1_500_000_000_000, maxPages: 1 }));
|
|
244
|
+
expect(items.map((x) => x.originalId)).toEqual(["NEW"]);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("respects opts.limit", async () => {
|
|
248
|
+
const a = new TongchengAdapter({
|
|
249
|
+
account: { cookies: COOKIES },
|
|
250
|
+
fetchFn: async () => ({
|
|
251
|
+
orderList: [
|
|
252
|
+
{ orderId: "L1", projectType: "flight", orderDate: 2_000_000_000_000 },
|
|
253
|
+
{ orderId: "L2", projectType: "flight", orderDate: 2_000_000_000_001 },
|
|
254
|
+
],
|
|
255
|
+
}),
|
|
256
|
+
});
|
|
257
|
+
const items = await collect(a.sync({ sinceWatermark: 0, limit: 1, maxPages: 1 }));
|
|
258
|
+
expect(items).toHaveLength(1);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("empty/login-redirect response yields zero (no crash)", async () => {
|
|
262
|
+
const a = new TongchengAdapter({
|
|
263
|
+
account: { cookies: COOKIES },
|
|
264
|
+
fetchFn: async () => "<html>login</html>",
|
|
265
|
+
});
|
|
266
|
+
expect(await collect(a.sync({ sinceWatermark: 0 }))).toEqual([]);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("default fetch throws when no fetchFn", async () => {
|
|
270
|
+
const a = new TongchengAdapter({ account: { cookies: COOKIES } });
|
|
271
|
+
await expect(collect(a.sync({ sinceWatermark: 0 }))).rejects.toThrow(/no fetchFn configured/);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("file path takes priority over cookie mode", async () => {
|
|
275
|
+
const p = writeTmp(JSON.stringify([FLIGHT_ORDER]));
|
|
276
|
+
try {
|
|
277
|
+
const a = new TongchengAdapter({
|
|
278
|
+
account: { cookies: COOKIES },
|
|
279
|
+
fetchFn: async () => {
|
|
280
|
+
throw new Error("fetchFn should NOT be called in file mode");
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
const items = await collect(a.sync({ inputPath: p }));
|
|
284
|
+
expect(items.map((x) => x.originalId)).toEqual(["TC1"]);
|
|
285
|
+
} finally {
|
|
286
|
+
fs.unlinkSync(p);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const os = require("node:os");
|
|
7
|
+
const crypto = require("node:crypto");
|
|
8
|
+
|
|
9
|
+
const iqiyi = require("../../lib/adapters/video-iqiyi");
|
|
10
|
+
const tv = require("../../lib/adapters/video-tencent");
|
|
11
|
+
|
|
12
|
+
function writeTmp(content) {
|
|
13
|
+
const p = path.join(os.tmpdir(), `cc-vid-${crypto.randomUUID()}.json`);
|
|
14
|
+
fs.writeFileSync(p, content, "utf-8");
|
|
15
|
+
return p;
|
|
16
|
+
}
|
|
17
|
+
async function collect(gen) {
|
|
18
|
+
const out = [];
|
|
19
|
+
for await (const x of gen) out.push(x);
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const COOKIES = "P00001=abc; QC005=xyz";
|
|
24
|
+
|
|
25
|
+
describe("video-iqiyi mappers", () => {
|
|
26
|
+
it("name/version + mapItem (channel code → category)", () => {
|
|
27
|
+
expect(iqiyi.NAME).toBe("video-iqiyi");
|
|
28
|
+
const rec = iqiyi.mapItem({ tvId: "100", albumName: "庆余年", channelId: 2, videoName: "庆余年", addtime: 1716300000, videoDuration: 2700 });
|
|
29
|
+
expect(rec).toMatchObject({ videoId: "100", title: "庆余年", category: "tv", durationSec: 2700 });
|
|
30
|
+
expect(rec.occurredAt).toBe(1716300000000);
|
|
31
|
+
expect(rec.url).toContain("iqiyi.com");
|
|
32
|
+
expect(iqiyi.mapItem({ albumName: "noid" })).toBe(null);
|
|
33
|
+
});
|
|
34
|
+
it("extractItems tolerant", () => {
|
|
35
|
+
expect(iqiyi.extractItems({ data: [{ tvId: 1 }] })).toHaveLength(1);
|
|
36
|
+
expect(iqiyi.extractItems({ data: { rc: [{ tvId: 1 }] } })).toHaveLength(1);
|
|
37
|
+
expect(iqiyi.extractItems({})).toEqual([]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("video-tencent mappers", () => {
|
|
42
|
+
it("name/version + mapItem (typeId → category)", () => {
|
|
43
|
+
expect(tv.NAME).toBe("video-tencent");
|
|
44
|
+
const rec = tv.mapItem({ cid: "C9", cTitle: "三体", cTypeId: 4, viewTime: 1716310000, duration: 3000 });
|
|
45
|
+
expect(rec).toMatchObject({ videoId: "C9", title: "三体", category: "anime", durationSec: 3000 });
|
|
46
|
+
expect(rec.url).toContain("v.qq.com");
|
|
47
|
+
expect(tv.mapItem({ cTitle: "noid" })).toBe(null);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("IqiyiVideoAdapter (via _video-base)", () => {
|
|
52
|
+
const SNAP = JSON.stringify({
|
|
53
|
+
schemaVersion: 1,
|
|
54
|
+
snapshottedAt: 1716383000000,
|
|
55
|
+
account: { userId: "u1" },
|
|
56
|
+
events: [
|
|
57
|
+
{ kind: "watch", id: "w1", videoId: "V1", title: "狂飙", category: "tv", episode: "第5集", durationSec: 2600, capturedAt: 1716300000000 },
|
|
58
|
+
{ kind: "favourite", id: "fa1", videoId: "V2", title: "流浪地球2", category: "movie" },
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("snapshot sync 2 kinds + normalize watch→media / favourite→like + media item", async () => {
|
|
63
|
+
const p = writeTmp(SNAP);
|
|
64
|
+
try {
|
|
65
|
+
const a = new iqiyi.IqiyiVideoAdapter();
|
|
66
|
+
const items = await collect(a.sync({ inputPath: p }));
|
|
67
|
+
expect(items.map((x) => x.kind)).toEqual(["watch", "favourite"]);
|
|
68
|
+
|
|
69
|
+
const watch = a.normalize(items[0]);
|
|
70
|
+
expect(watch.events[0].subtype).toBe("media");
|
|
71
|
+
expect(watch.events[0].content.title).toBe("观看: 狂飙 第5集");
|
|
72
|
+
expect(watch.items[0].subtype).toBe("media");
|
|
73
|
+
expect(watch.items[0].extra.platform).toBe("iqiyi");
|
|
74
|
+
expect(watch.events[0].extra.itemRef).toBe(watch.items[0].id);
|
|
75
|
+
|
|
76
|
+
const fav = a.normalize(items[1]);
|
|
77
|
+
expect(fav.events[0].subtype).toBe("like");
|
|
78
|
+
expect(fav.events[0].content.title).toBe("收藏: 流浪地球2");
|
|
79
|
+
} finally {
|
|
80
|
+
fs.unlinkSync(p);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("schema mismatch + unknown kind + include + limit", async () => {
|
|
85
|
+
const p = writeTmp(SNAP);
|
|
86
|
+
try {
|
|
87
|
+
const a = new iqiyi.IqiyiVideoAdapter();
|
|
88
|
+
expect((await collect(a.sync({ inputPath: p, include: { watch: false } }))).map((x) => x.kind)).toEqual(["favourite"]);
|
|
89
|
+
expect(await collect(a.sync({ inputPath: p, limit: 1 }))).toHaveLength(1);
|
|
90
|
+
expect(() => a.normalize({ payload: {} })).toThrow(/payload.record missing/);
|
|
91
|
+
} finally {
|
|
92
|
+
fs.unlinkSync(p);
|
|
93
|
+
}
|
|
94
|
+
const bad = writeTmp(JSON.stringify({ schemaVersion: 9, events: [] }));
|
|
95
|
+
try {
|
|
96
|
+
const a = new iqiyi.IqiyiVideoAdapter();
|
|
97
|
+
await expect(collect(a.sync({ inputPath: bad }))).rejects.toThrow(/schemaVersion mismatch/);
|
|
98
|
+
} finally {
|
|
99
|
+
fs.unlinkSync(bad);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("TencentVideoAdapter cookie-api mode", () => {
|
|
105
|
+
it("authenticate cookie (userId optional)", async () => {
|
|
106
|
+
const a = new tv.TencentVideoAdapter({ account: { cookies: COOKIES } });
|
|
107
|
+
expect(await a.authenticate()).toEqual({ ok: true, account: null, mode: "cookie" });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("sync fetches watch+favourite, paginates, normalizes", async () => {
|
|
111
|
+
const byUrl = (u) => (u.includes("History") ? "watch" : "favourite");
|
|
112
|
+
const data = {
|
|
113
|
+
watch: [{ cid: "C1", cTitle: "漫长的季节", cTypeId: 1, viewTime: 1716300000 }],
|
|
114
|
+
favourite: [{ cid: "C2", cTitle: "繁花", cTypeId: 1 }],
|
|
115
|
+
};
|
|
116
|
+
const calls = [];
|
|
117
|
+
const a = new tv.TencentVideoAdapter({
|
|
118
|
+
account: { cookies: COOKIES, userId: "u1" },
|
|
119
|
+
fetchFn: async ({ url, cookies, query, sign }) => {
|
|
120
|
+
const k = byUrl(url);
|
|
121
|
+
calls.push({ k, cookies, page: query.page, sign });
|
|
122
|
+
return { data: { list: query.page === 1 ? data[k] : [] } };
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
const items = await collect(a.sync({}));
|
|
126
|
+
expect(items.map((x) => x.kind).sort()).toEqual(["favourite", "watch"]);
|
|
127
|
+
expect(calls.every((c) => c.cookies === COOKIES && c.sign === null)).toBe(true);
|
|
128
|
+
const watch = a.normalize(items.find((x) => x.kind === "watch"));
|
|
129
|
+
expect(watch.events[0].content.title).toBe("观看: 漫长的季节");
|
|
130
|
+
expect(watch.items[0].extra.platform).toBe("tencent-video");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("invokes signProvider + limit + empty + default fetch + no input", async () => {
|
|
134
|
+
const signCalls = [];
|
|
135
|
+
const a = new tv.TencentVideoAdapter({
|
|
136
|
+
account: { cookies: COOKIES },
|
|
137
|
+
fetchFn: async ({ query }) => ({ list: query.page === 1 ? [{ cid: "C1", cTitle: "x" }, { cid: "C2", cTitle: "y" }] : [] }),
|
|
138
|
+
signProvider: async (ctx) => { signCalls.push(ctx); return "sig"; },
|
|
139
|
+
});
|
|
140
|
+
expect(await collect(a.sync({ limit: 1, include: { favourite: false } }))).toHaveLength(1);
|
|
141
|
+
expect(signCalls.length).toBeGreaterThan(0);
|
|
142
|
+
|
|
143
|
+
const a2 = new tv.TencentVideoAdapter({ account: { cookies: COOKIES }, fetchFn: async () => "<html>login</html>" });
|
|
144
|
+
expect(await collect(a2.sync({}))).toEqual([]);
|
|
145
|
+
|
|
146
|
+
const a3 = new tv.TencentVideoAdapter({ account: { cookies: COOKIES } });
|
|
147
|
+
await expect(collect(a3.sync({}))).rejects.toThrow(/no fetchFn configured/);
|
|
148
|
+
|
|
149
|
+
const a4 = new tv.TencentVideoAdapter();
|
|
150
|
+
await expect(collect(a4.sync({}))).rejects.toThrow(/needs opts.inputPath/);
|
|
151
|
+
});
|
|
152
|
+
});
|
package/lib/adapter-guide.js
CHANGED
|
@@ -32,6 +32,9 @@ const { READINESS_CATEGORY } = require("./adapter-readiness");
|
|
|
32
32
|
const DISPLAY_NAMES = Object.freeze({
|
|
33
33
|
"social-bilibili": "哔哩哔哩",
|
|
34
34
|
"social-weibo": "微博",
|
|
35
|
+
"social-zhihu": "知乎",
|
|
36
|
+
"recruit-boss": "BOSS 直聘",
|
|
37
|
+
"social-csdn": "CSDN",
|
|
35
38
|
"social-douyin": "抖音",
|
|
36
39
|
"social-xiaohongshu": "小红书",
|
|
37
40
|
"social-toutiao": "今日头条",
|
|
@@ -51,8 +54,11 @@ const DISPLAY_NAMES = Object.freeze({
|
|
|
51
54
|
"shopping-jd": "京东",
|
|
52
55
|
"shopping-meituan": "美团",
|
|
53
56
|
"shopping-pinduoduo": "拼多多",
|
|
57
|
+
"shopping-dianping": "大众点评",
|
|
54
58
|
"travel-12306": "12306 铁路",
|
|
55
59
|
"travel-ctrip": "携程",
|
|
60
|
+
"travel-tongcheng": "同程旅行",
|
|
61
|
+
"travel-didi": "滴滴企业版",
|
|
56
62
|
"travel-amap": "高德地图",
|
|
57
63
|
"travel-baidu-map": "百度地图",
|
|
58
64
|
"travel-tencent-map": "腾讯地图",
|
|
@@ -63,7 +69,13 @@ const DISPLAY_NAMES = Object.freeze({
|
|
|
63
69
|
"ai-chat-history": "AI 对话历史",
|
|
64
70
|
"apple-health": "Apple 健康",
|
|
65
71
|
"netease-music": "网易云音乐",
|
|
72
|
+
"music-kugou": "酷狗音乐",
|
|
73
|
+
"video-iqiyi": "爱奇艺",
|
|
74
|
+
"video-tencent": "腾讯视频",
|
|
66
75
|
"weread": "微信读书",
|
|
76
|
+
"doc-wps": "WPS 云文档",
|
|
77
|
+
"doc-tencent-docs": "腾讯文档",
|
|
78
|
+
"doc-baidu-netdisk": "百度网盘",
|
|
67
79
|
"browser-history-chrome": "Chrome 浏览历史",
|
|
68
80
|
"browser-history-edge": "Edge 浏览历史",
|
|
69
81
|
"vscode": "VS Code",
|
|
@@ -533,7 +545,7 @@ function getAdapterGuide(name, category) {
|
|
|
533
545
|
// usable standalone, e.g. CLI without a live readiness probe).
|
|
534
546
|
function _inferCategory(name) {
|
|
535
547
|
if (ADAPTER_OVERRIDES[name] && name === "wechat") return READINESS_CATEGORY.DEVICE;
|
|
536
|
-
if (/^(email-imap|finance-alipay|alipay-bill|ai-chat-history|weread)$/.test(name))
|
|
548
|
+
if (/^(email-imap|finance-alipay|alipay-bill|ai-chat-history|weread|doc-wps|doc-tencent-docs|doc-baidu-netdisk|recruit-boss|social-csdn)$/.test(name))
|
|
537
549
|
return READINESS_CATEGORY.CREDENTIAL;
|
|
538
550
|
if (/^(messaging-(telegram|whatsapp)|wechat|wechat-pc|messaging-qq|qq-pc|dingtalk-pc|feishu-pc|travel-amap)$/.test(name))
|
|
539
551
|
return READINESS_CATEGORY.DEVICE;
|