Skip to content

Commit 9c64ec7

Browse files
committed
feat: supports using "eid" to retrieve feed details
1 parent de5b261 commit 9c64ec7

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
lines changed

internal/api/handler.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ func (c *APIClient) handleFetchFeedProfile(ctx *gin.Context) {
194194
oid := ctx.Query("oid")
195195
uid := ctx.Query("nid")
196196
url := ctx.Query("url")
197-
resp, err := c.channels.FetchChannelsFeedProfile(oid, uid, url)
197+
eid := ctx.Query("eid")
198+
resp, err := c.channels.FetchChannelsFeedProfile(oid, uid, url, eid)
198199
if err != nil {
199200
result.Err(ctx, 400, err.Error())
200201
return
@@ -553,7 +554,8 @@ func buildBatchCreateTask(c *APIClient, existing_task_map map[string]int, feeds
553554
func (c *APIClient) handleCreateChannelsTask(ctx *gin.Context) {
554555
var body struct {
555556
Oid string `json:"oid"`
556-
Nid string `json:"Nid"`
557+
Nid string `json:"nid"`
558+
Eid string `json:"eid"`
557559
URL string `json:"url"`
558560
MP3 bool `json:"mp3"` // 是否下载为 mp3
559561
Cover bool `json:"cover"` // 是否下载封面
@@ -562,11 +564,11 @@ func (c *APIClient) handleCreateChannelsTask(ctx *gin.Context) {
562564
result.Err(ctx, 400, "不合法的参数")
563565
return
564566
}
565-
if body.Oid == "" && body.Nid == "" && body.URL == "" {
567+
if body.Oid == "" && body.Nid == "" && body.URL == "" && body.Eid == "" {
566568
result.Err(ctx, 400, "缺少参数")
567569
return
568570
}
569-
r, err := c.channels.FetchChannelsFeedProfile(body.Oid, body.Nid, body.URL)
571+
r, err := c.channels.FetchChannelsFeedProfile(body.Oid, body.Nid, body.URL, body.Eid)
570572
if err != nil {
571573
result.Err(ctx, 500, "获取详情失败: "+err.Error())
572574
return

internal/api/types/types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,10 @@ type ChannelsInteractionedFeedListBody struct {
291291
NextMarker string `json:"next_marker"`
292292
}
293293
type ChannelsFeedProfileBody struct {
294-
URL string `json:"url"`
295-
ObjectId string `json:"oid"`
296-
NonceId string `json:"nid"`
294+
URL string `json:"url"`
295+
ObjectId string `json:"oid"`
296+
NonceId string `json:"nid"`
297+
EncryptedObjectId string `json:"eid"`
297298
}
298299
type ChannelsFeedList struct {
299300
List []ChannelsFeedProfile `json:"list"`

internal/channels/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,16 @@ func (c *ChannelsClient) FetchChannelsInteractionedFeedList(flag, next_marker st
276276
return &r, nil
277277
}
278278

279-
func (c *ChannelsClient) FetchChannelsFeedProfile(oid, uid, url string) (*types.ChannelsFeedProfileResp, error) {
279+
func (c *ChannelsClient) FetchChannelsFeedProfile(oid, uid, url, eid string) (*types.ChannelsFeedProfileResp, error) {
280280
// fmt.Println("[API]fetch feed profile", oid, uid)
281-
kk := fmt.Sprintf("%s:%s:%s", oid, uid, url)
281+
kk := fmt.Sprintf("%s:%s:%s:%s", oid, uid, url, eid)
282282
cache_key := "channels:feed_profile:" + kk
283283
if val, found := c.cache.Get(cache_key); found {
284284
if resp, ok := val.(*types.ChannelsFeedProfileResp); ok {
285285
return resp, nil
286286
}
287287
}
288-
resp, err := c.RequestFrontend("key:channels:feed_profile", types.ChannelsFeedProfileBody{ObjectId: oid, NonceId: uid, URL: url}, 10*time.Second)
288+
resp, err := c.RequestFrontend("key:channels:feed_profile", types.ChannelsFeedProfileBody{ObjectId: oid, NonceId: uid, URL: url, EncryptedObjectId: eid}, 10*time.Second)
289289
if err != nil {
290290
return nil, err
291291
}

internal/interceptor/inject/src/downloader.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ var isWin = /Windows|Win/i.test(ua);
3434
})(),
3535
});
3636
}
37+
function connect_local_ws() {
38+
const protocol = "wss://";
39+
const ws = new WebSocket(
40+
protocol + FakeLocalAPIServerAddr + "/ws/channels",
41+
);
42+
ws.onclose = () => {
43+
WXU.error({ msg: "本地ws连接已关闭" });
44+
};
45+
ws.onerror = (e) => {
46+
WXU.error({ msg: "本地ws连接发生错误" });
47+
};
48+
ws.onmessage = (ev) => {
49+
const [err, msg] = WXU.parseJSON(ev.data);
50+
if (err) {
51+
return;
52+
}
53+
if (msg.type === "api_call") {
54+
__wx_handle_api_call(msg.data, ws);
55+
}
56+
};
57+
}
3758
function connect(selector) {
3859
console.log(
3960
"[]download connect websocket",
@@ -118,24 +139,7 @@ var isWin = /Windows|Win/i.test(ua);
118139
};
119140
if (WXU.config.remoteServerEnabled) {
120141
// 额外再连接本地ws用于API调用
121-
const lws = new WebSocket(
122-
protocol + FakeLocalAPIServerAddr + "/ws/channels",
123-
);
124-
lws.onclose = () => {
125-
WXU.error({ msg: "本地ws连接已关闭" });
126-
};
127-
lws.onerror = (e) => {
128-
WXU.error({ msg: "本地ws连接发生错误" });
129-
};
130-
lws.onmessage = (ev) => {
131-
const [err, msg] = WXU.parseJSON(ev.data);
132-
if (err) {
133-
return;
134-
}
135-
if (msg.type === "api_call") {
136-
__wx_handle_api_call(msg.data, lws);
137-
}
138-
};
142+
connect_local_ws();
139143
}
140144
});
141145
}
@@ -346,6 +350,10 @@ var isWin = /Windows|Win/i.test(ua);
346350
WXU.observe_node(".home-header", () => {
347351
insert_downloader();
348352
});
353+
// console.log("[]check is wxwork", window.ua.includes("wxwork"), window.ua);
354+
if (window.ua.includes("wxwork")) {
355+
connect_local_ws();
356+
}
349357

350358
// document.addEventListener(
351359
// "scroll",
@@ -451,7 +459,7 @@ async function __wx_handle_api_call(msg, socket) {
451459
return;
452460
}
453461
if (key === "key:channels:feed_profile") {
454-
console.log("before finderGetCommentProfile", data.oid, data.nid);
462+
console.log("before finderGetCommentProfile", data.oid, data.nid, data.eid);
455463
try {
456464
if (data.url) {
457465
var u = new URL(decodeURIComponent(data.url));
@@ -465,19 +473,25 @@ async function __wx_handle_api_call(msg, socket) {
465473
var payload = {
466474
needObject: 1,
467475
lastBuffer: "",
468-
scene: 146,
476+
scene: data.eid ? 141 : 146,
469477
direction: 2,
470478
identityScene: 2,
471479
pullScene: 6,
472480
objectid: (() => {
481+
if (data.eid) {
482+
return undefined;
483+
}
473484
if (data.oid.includes("_")) {
474485
return data.oid.split("_")[0];
475486
}
476487
return data.oid;
477488
})(),
478-
objectNonceId: data.nid,
479-
encrypted_objectid: "",
489+
objectNonceId: data.eid ? undefined : data.nid,
490+
encrypted_objectid: data.eid || "",
480491
};
492+
if (data.eid) {
493+
payload.traceBuffer = undefined;
494+
}
481495
var r = await WXU.API.finderGetCommentDetail(payload);
482496
/** @type {MediaProfileResp} */
483497
var { object } = r.data;

0 commit comments

Comments
 (0)