feat: unify account environments and work collection

This commit is contained in:
2026-10-06 13:00:29 +08:00
parent b72727451d
commit 950b23da32
22 changed files with 935 additions and 93 deletions
@@ -237,9 +237,17 @@ func (c CreatorCollector) ListWorks(ctx context.Context, accountKey, cursor stri
maxCursor = cursor
}
query := douyinAPIQuery()
query.Set("channel", "channel_pc_web")
query.Set("sec_user_id", accountKey)
query.Set("count", "20")
query.Set("count", "18")
query.Set("max_cursor", maxCursor)
query.Set("locate_query", "false")
query.Set("show_live_replay_strategy", "1")
query.Set("need_time_list", "1")
query.Set("time_list_query", "0")
query.Set("cut_version", "1")
query.Set("publish_video_strategy_type", "2")
query.Set("from_user_page", "0")
response, err := c.Browser.Get(ctx, worksEndpoint+"?"+query.Encode())
if err != nil {
return creator.WorkPage{}, err
@@ -101,6 +101,40 @@ func TestCreatorCollectorGuardsAndCollection(t *testing.T) {
}
}
func TestListWorksUsesCurrentDouyinWebPaginationParameters(t *testing.T) {
browser := &collectorBrowser{response: Response{Status: 200, Body: []byte(`{"status_code":0,"has_more":false,"max_cursor":0,"aweme_list":[]}`)}}
collector := CreatorCollector{Browser: browser, AccountKey: "MS4wLjABAAAAkey"}
if _, err := collector.ListWorks(context.Background(), "ignored", "1746702477000"); err != nil {
t.Fatal(err)
}
parsed, err := url.Parse(browser.url)
if err != nil {
t.Fatal(err)
}
query := parsed.Query()
want := map[string]string{
"channel": "channel_pc_web",
"sec_user_id": "MS4wLjABAAAAkey",
"count": "18",
"max_cursor": "1746702477000",
"locate_query": "false",
"show_live_replay_strategy": "1",
"need_time_list": "1",
"time_list_query": "0",
"cut_version": "1",
"publish_video_strategy_type": "2",
"from_user_page": "0",
}
if parsed.Path != "/aweme/v1/web/aweme/post/" {
t.Fatalf("unexpected endpoint: %s", parsed.Path)
}
for key, value := range want {
if query.Get(key) != value {
t.Errorf("query %s = %q, want %q (full query: %s)", key, query.Get(key), value, query.Encode())
}
}
}
func TestParseCreatorCommentsPageAllowsEmptyComments(t *testing.T) {
page, err := parseCreatorCommentsPage([]byte(`{"status_code":0,"has_more":false,"cursor":20,"comments":null}`))
if err != nil {