fix: match Xingtu profile endpoints
This commit is contained in:
@@ -16,6 +16,16 @@ type FetchLike = (
|
||||
init?: RequestInit
|
||||
) => Promise<FetchResponseLike>;
|
||||
|
||||
export type AudienceProfileRequestTarget =
|
||||
| {
|
||||
linkType: number;
|
||||
source: "audienceDistribution";
|
||||
}
|
||||
| {
|
||||
authorType: number;
|
||||
source: "fansDistribution";
|
||||
};
|
||||
|
||||
interface AudienceProfileClientOptions {
|
||||
baseUrl?: string;
|
||||
fetchImpl?: FetchLike;
|
||||
@@ -49,10 +59,13 @@ const GENDER_LABELS: Record<string, string> = {
|
||||
const AGE_ORDER = ["18-23", "24-30", "31-40", "41-50", "50+"];
|
||||
const CITY_TIER_ORDER = ["一线", "新一线", "二线", "三线", "四线", "五线"];
|
||||
|
||||
export const AUDIENCE_PROFILE_LINK_TYPES: Record<AudienceProfileKind, number> = {
|
||||
audience: 3,
|
||||
fans: 1,
|
||||
longtimeFans: 4
|
||||
export const AUDIENCE_PROFILE_TARGETS: Record<
|
||||
AudienceProfileKind,
|
||||
AudienceProfileRequestTarget
|
||||
> = {
|
||||
audience: { linkType: 5, source: "audienceDistribution" },
|
||||
fans: { authorType: 1, source: "fansDistribution" },
|
||||
longtimeFans: { authorType: 5, source: "fansDistribution" }
|
||||
};
|
||||
|
||||
export function createAudienceProfileClient(
|
||||
@@ -65,14 +78,14 @@ export function createAudienceProfileClient(
|
||||
return {
|
||||
async loadAudienceProfile(
|
||||
record: MarketRecord,
|
||||
linkType: number
|
||||
target: AudienceProfileRequestTarget
|
||||
): Promise<AudienceProfileResult> {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
|
||||
try {
|
||||
const response = await fetchImpl(
|
||||
buildAudienceProfileUrl(record.authorId, baseUrl, linkType),
|
||||
buildAudienceProfileUrl(record.authorId, baseUrl, target),
|
||||
{
|
||||
credentials: "include",
|
||||
method: "GET",
|
||||
@@ -106,13 +119,22 @@ export function createAudienceProfileClient(
|
||||
export function buildAudienceProfileUrl(
|
||||
authorId: string,
|
||||
baseUrl: string,
|
||||
linkType = 3
|
||||
target: AudienceProfileRequestTarget
|
||||
): string {
|
||||
const url = new URL("/gw/api/data_sp/author_audience_distribution", baseUrl);
|
||||
const url = new URL(
|
||||
target.source === "audienceDistribution"
|
||||
? "/gw/api/data_sp/author_audience_distribution"
|
||||
: "/gw/api/data_sp/get_author_fans_distribution",
|
||||
baseUrl
|
||||
);
|
||||
url.searchParams.set("o_author_id", authorId);
|
||||
url.searchParams.set("platform_source", "1");
|
||||
url.searchParams.set("platform_channel", "1");
|
||||
url.searchParams.set("link_type", String(linkType));
|
||||
if (target.source === "audienceDistribution") {
|
||||
url.searchParams.set("platform_channel", "1");
|
||||
url.searchParams.set("link_type", String(target.linkType));
|
||||
} else {
|
||||
url.searchParams.set("author_type", String(target.authorType));
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { buildMarketCsv } from "./csv-exporter";
|
||||
import { buildAudienceProfileCsv } from "./audience-profile-csv";
|
||||
import {
|
||||
AUDIENCE_PROFILE_LINK_TYPES,
|
||||
createAudienceProfileClient
|
||||
AUDIENCE_PROFILE_TARGETS,
|
||||
createAudienceProfileClient,
|
||||
type AudienceProfileRequestTarget
|
||||
} from "./audience-profile-client";
|
||||
import { promptForBatchName } from "./batch-name-dialog";
|
||||
import { createBatchPayload, type BatchPayload } from "./batch-payload";
|
||||
@@ -58,7 +59,7 @@ export interface CreateMarketControllerOptions {
|
||||
getAuthState?: () => Promise<AuthStateValue>;
|
||||
loadAudienceProfile?: (
|
||||
record: MarketRecord,
|
||||
linkType: number
|
||||
target: AudienceProfileRequestTarget
|
||||
) => Promise<AudienceProfileResult>;
|
||||
loadAuthorMetrics?: (authorId: string) => Promise<MarketApiResult>;
|
||||
searchBackendMetrics?: (starIds: string[]) => Promise<
|
||||
@@ -101,13 +102,13 @@ export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
readBatchSubmitAck(sendRuntimeMessage, payload));
|
||||
const audienceProfileTargets: Array<{
|
||||
kind: AudienceProfileKind;
|
||||
linkType: number;
|
||||
target: AudienceProfileRequestTarget;
|
||||
}> = [
|
||||
{ kind: "audience", linkType: AUDIENCE_PROFILE_LINK_TYPES.audience },
|
||||
{ kind: "fans", linkType: AUDIENCE_PROFILE_LINK_TYPES.fans },
|
||||
{ kind: "audience", target: AUDIENCE_PROFILE_TARGETS.audience },
|
||||
{ kind: "fans", target: AUDIENCE_PROFILE_TARGETS.fans },
|
||||
{
|
||||
kind: "longtimeFans",
|
||||
linkType: AUDIENCE_PROFILE_LINK_TYPES.longtimeFans
|
||||
target: AUDIENCE_PROFILE_TARGETS.longtimeFans
|
||||
}
|
||||
];
|
||||
let activeProgressLabel = "导出中";
|
||||
@@ -664,9 +665,9 @@ export function createMarketController(options: CreateMarketControllerOptions) {
|
||||
): Promise<AudienceProfileExportRow["profiles"]> {
|
||||
const profiles = {} as AudienceProfileExportRow["profiles"];
|
||||
|
||||
for (const { kind, linkType } of audienceProfileTargets) {
|
||||
for (const { kind, target } of audienceProfileTargets) {
|
||||
try {
|
||||
profiles[kind] = await loadAudienceProfile(record, linkType);
|
||||
profiles[kind] = await loadAudienceProfile(record, target);
|
||||
} catch (error) {
|
||||
profiles[kind] = {
|
||||
failureReason:
|
||||
|
||||
Reference in New Issue
Block a user