feat: refine audience profile csv columns

This commit is contained in:
2026-05-18 17:25:58 +08:00
parent 66bc49d498
commit 26ae3bb4b6
7 changed files with 229 additions and 171 deletions
+12 -4
View File
@@ -1,6 +1,7 @@
import type { MarketRecord } from "./types";
import type {
AudienceProfileDistributionItem,
AudienceProfileKind,
AudienceProfileResult,
AudienceProfileSuccess
} from "./audience-profile-types";
@@ -18,7 +19,6 @@ type FetchLike = (
interface AudienceProfileClientOptions {
baseUrl?: string;
fetchImpl?: FetchLike;
linkType?: number;
timeoutMs?: number;
}
@@ -49,16 +49,24 @@ 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 function createAudienceProfileClient(
options: AudienceProfileClientOptions = {}
) {
const baseUrl = options.baseUrl ?? resolveBaseUrl();
const fetchImpl = options.fetchImpl ?? defaultFetch;
const timeoutMs = options.timeoutMs ?? 8000;
const linkType = options.linkType ?? 1;
return {
async loadAudienceProfile(record: MarketRecord): Promise<AudienceProfileResult> {
async loadAudienceProfile(
record: MarketRecord,
linkType: number
): Promise<AudienceProfileResult> {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
@@ -98,7 +106,7 @@ export function createAudienceProfileClient(
export function buildAudienceProfileUrl(
authorId: string,
baseUrl: string,
linkType = 1
linkType = 3
): string {
const url = new URL("/gw/api/data_sp/author_audience_distribution", baseUrl);
url.searchParams.set("o_author_id", authorId);