Files
crawler-plugin/frontend-vue/src/shared/api/java-modules.ts
T
huangzd1997 b27a686998 task-16: 拆分 appearance-patent 模块 API 至 types/modules/appearance-patent.ts,java-modules.ts re-export
- parseAppearancePatent/getAppearancePatentParsedPayload/getAppearancePatentQueuePayload/getAppearancePatentDashboard/getAppearancePatentHistory/getAppearancePatentTaskProgressBatch/activateAppearancePatentTask/deleteAppearancePatentTask/deleteAppearancePatentHistory/getAppearancePatentResultDownloadUrl
- appearance-patent 全套类型随模块迁移;progressBatch 内联缓存+超时实现
- 9 个测试:parse/parsedPayload/queuePayload/progressBatch/activate/dashboard/history/delete/download/export compat
2026-08-31 19:35:59 +08:00

2663 lines
69 KiB
TypeScript

import {
del,
get,
http,
post,
put,
type JavaApiResponse,
unwrapJavaResponse,
} from "./http.ts";
import { getTaskProgressCacheTtlMs, getTaskProgressTimeoutMs } from "../task-progress-config.ts";
import { createTaskProgressRequestCache } from "../task-progress-request-cache.ts";
export * from "./types/modules/dedupe.ts";
export * from "./types/modules/split.ts";
export * from "./types/modules/convert.ts";
export * from "./types/modules/publish.ts";
export * from "./types/modules/similar-asin.ts";
export * from "./types/modules/appearance-patent.ts";
const JAVA_API_PREFIX = "/newApi/api";
interface TaskProgressBatchOptions {
force?: boolean;
}
/** 进度批量接口的响应缓存与并发合并:TTL 过期、有界条目、in-flight 去重 */
const taskProgressResponseCache = createTaskProgressRequestCache<unknown>({
ttlMs: () => getTaskProgressCacheTtlMs(),
maxEntries: 100,
maxInflight: 16,
});
function getCurrentUserId() {
const raw =
typeof window === "undefined"
? ""
: window.localStorage.getItem("uid") || "";
const value = Number(raw);
if (!Number.isFinite(value) || value <= 0) {
throw new Error("未获取到用户ID");
}
return value;
}
function normalizeTaskIds(taskIds: number[]) {
return Array.from(
new Set(
(taskIds || [])
.map((taskId) => Number(taskId))
.filter((taskId) => Number.isFinite(taskId) && taskId > 0),
),
).sort((left, right) => left - right);
}
function buildTaskProgressRequestKey(path: string, taskIds: number[]) {
return `${path}::${taskIds.join(",")}`;
}
async function postTaskProgressBatch<T>(
path: string,
taskIds: number[],
options: TaskProgressBatchOptions = {},
) {
const normalizedTaskIds = normalizeTaskIds(taskIds);
if (!normalizedTaskIds.length) {
return { items: [], missingTaskIds: [] } as T;
}
const cacheKey = buildTaskProgressRequestKey(path, normalizedTaskIds);
const cached = taskProgressResponseCache.get(cacheKey);
if (!options.force && cached !== undefined) {
return cached as T;
}
const inflight = taskProgressResponseCache.getInflight(cacheKey);
if (!options.force && inflight) {
return (await inflight) as T;
}
const requestPromise = unwrapJavaResponse(
post<JavaApiResponse<T>, { taskIds: number[] }>(path, { taskIds: normalizedTaskIds }, {
timeout: getTaskProgressTimeoutMs(),
}),
)
.then((data) => {
taskProgressResponseCache.set(cacheKey, data);
return data;
})
.finally(() => {
taskProgressResponseCache.endInflight(cacheKey);
});
taskProgressResponseCache.startInflight(cacheKey, requestPromise);
return requestPromise;
}
export interface UploadedFileRef {
fileKey: string;
originalFilename?: string;
relativePath?: string;
}
export interface UploadFileVo {
fileKey: string;
originalFilename: string;
localPath: string;
size: number;
relativePath?: string;
objectKey?: string;
url?: string;
mediaType?: "image" | "video" | "audio" | "file" | string;
}
export interface UploadTempFileOptions {
relativePath?: string;
uploadToOss?: boolean;
moduleType?: string;
}
export async function uploadTempFileToJava(
file: File,
relativePathOrOptions?: string | UploadTempFileOptions,
) {
const options =
typeof relativePathOrOptions === 'string'
? { relativePath: relativePathOrOptions }
: relativePathOrOptions || {}
const formData = new FormData()
formData.append('file', file)
if (options.relativePath) {
formData.append('relativePath', options.relativePath)
}
if (options.uploadToOss) {
formData.append('uploadToOss', 'true')
}
if (options.moduleType) {
formData.append('moduleType', options.moduleType)
}
const response = await http.post<JavaApiResponse<UploadFileVo>>(
`${JAVA_API_PREFIX}/files/upload`,
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
},
timeout: 120000,
},
)
return response.data
}
export interface DeleteBrandPreviewRow {
rowIndex: number;
country: string;
asin: string;
status: string;
}
export interface DeleteBrandCountryAsinItem {
rowIndex: number;
asin: string;
status: string;
}
export interface DeleteBrandCountryGroup {
country: string;
asinCount: number;
items: DeleteBrandCountryAsinItem[];
}
export interface DeleteBrandCountryResultItem {
asin: string;
status?: string;
}
export interface DeleteBrandProcessedCountry {
country: string;
items: DeleteBrandCountryResultItem[];
}
export interface DeleteBrandResultFile {
fileKey?: string;
sourceFilename: string;
fileIndex?: number;
fileTotal?: number;
chunkIndex?: number;
chunkTotal?: number;
processedRows?: number;
totalRows?: number;
currentCountry?: string;
currentAsin?: string;
countries: DeleteBrandProcessedCountry[];
}
export interface DeleteBrandSubmitResultRequest {
submissionId?: string;
files: DeleteBrandResultFile[];
}
export interface DeleteBrandLineProgressInfo {
file_index?: number;
file_total?: number;
file_name?: string;
current_line?: number;
total_lines?: number;
current_country?: string;
current_asin?: string;
finished_files?: number;
phase?: string;
}
export interface DeleteBrandLineProgress {
has_progress: boolean;
info?: DeleteBrandLineProgressInfo;
}
export interface DeleteBrandTaskItem {
id: number;
taskNo?: string;
status?: string;
sourceFileCount?: number;
successFileCount?: number;
failedFileCount?: number;
errorMessage?: string;
createdAt?: string;
updatedAt?: string;
finishedAt?: string;
downloadUrl?: string;
downloadFilename?: string;
}
export interface DeleteBrandTaskFileProgress {
fileKey?: string;
sourceFilename?: string;
processedRows?: number;
totalRows?: number;
percent?: number;
status?: "PENDING" | "RUNNING" | "COMPLETED" | "FAILED";
}
export interface DeleteBrandTaskDetailVo {
task: DeleteBrandTaskItem;
line_progress: DeleteBrandLineProgress;
items?: DeleteBrandResultItem[];
fileProgress?: DeleteBrandTaskFileProgress[];
}
export interface DeleteBrandTaskBatchVo {
items: DeleteBrandTaskDetailVo[];
missingTaskIds: number[];
}
export type DeleteBrandMatchStatus =
| "MATCHED"
| "PENDING"
| "CONFLICT"
| "INDEX_STALE";
export interface DeleteBrandResultItem {
resultId?: number;
fileKey?: string;
sourceFilename: string;
shopName?: string;
companyName?: string;
matched?: boolean;
matchStatus?: DeleteBrandMatchStatus;
matchMessage?: string;
shopId?: string;
platform?: string;
openStoreUrl?: string;
outputFilename?: string;
downloadUrl?: string;
fileJobId?: number;
fileStatus?: string;
fileError?: string;
fileReady?: boolean;
taskId?: number;
countryCount?: number;
countries?: DeleteBrandCountryGroup[];
totalRows?: number;
truncated?: boolean;
previewRows?: DeleteBrandPreviewRow[];
success: boolean;
error?: string;
taskStatus?: string;
}
export interface DeleteBrandRunVo {
total: number;
successCount: number;
failedCount: number;
items: DeleteBrandResultItem[];
}
export interface DeleteBrandHistoryVo {
items: DeleteBrandResultItem[];
}
export interface DeleteBrandRunRequest {
files: UploadedFileRef[];
user_id: number;
}
export function runDeleteBrand(
request: Omit<DeleteBrandRunRequest, "user_id"> | DeleteBrandRunRequest,
) {
return unwrapJavaResponse(
post<JavaApiResponse<DeleteBrandRunVo>, DeleteBrandRunRequest>(
`${JAVA_API_PREFIX}/delete-brand/run`,
{
...request,
user_id: getCurrentUserId(),
},
{ timeout: 180000 },
),
);
}
export function getDeleteBrandHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<DeleteBrandHistoryVo>>(
`${JAVA_API_PREFIX}/delete-brand/history`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function deleteDeleteBrandHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/delete-brand/history/${resultId}`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function getDeleteBrandTaskDetail(taskId: number) {
return unwrapJavaResponse(
get<JavaApiResponse<DeleteBrandTaskDetailVo>>(
`${JAVA_API_PREFIX}/delete-brand/tasks/${taskId}`,
),
);
}
export function getDeleteBrandTaskDetails(taskIds: number[]) {
return unwrapJavaResponse(
post<JavaApiResponse<DeleteBrandTaskBatchVo>, { taskIds: number[] }>(
`${JAVA_API_PREFIX}/delete-brand/tasks/batch`,
{ taskIds },
),
);
}
export function getDeleteBrandTaskDownloadUrl(taskId: number) {
return getJavaDownloadUrl(`/delete-brand/tasks/${taskId}/download`);
}
export function getDeleteBrandResultDownloadUrl(resultId: number) {
return getJavaDownloadUrl(`/delete-brand/results/${resultId}/download`);
}
export function submitDeleteBrandResult(
taskId: number,
request: DeleteBrandSubmitResultRequest,
) {
return unwrapJavaResponse(
post<JavaApiResponse<null>, DeleteBrandSubmitResultRequest>(
`${JAVA_API_PREFIX}/delete-brand/tasks/${taskId}/result`,
request,
),
);
}
/** 商品风险处理:备选店铺与匹配相关数据结构。 */
export interface ProductRiskCandidateVo {
id: number;
shop_name: string;
created_at?: string;
}
export interface ProductRiskShopQueueItem {
shopName: string;
matched: boolean;
shopId?: string;
platform?: string;
companyName?: string;
openStoreUrl?: string;
matchedUserId?: number;
matchStatus?: string;
matchMessage?: string;
queryAsins?: QueryAsinCountryAsins[];
skipAsinsByCountry?: Record<string, string[]>;
skip_asins_by_country?: Record<string, string[]>;
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
}
export interface ShopMatchResultRow {
asin?: string;
minimumPrice?: string;
minimum_price?: string;
status?: string;
done?: boolean;
}
export interface ShopMatchSubmitShopPayload {
shopName?: string;
error?: string;
countries?: Record<string, ShopMatchResultRow[]>;
skipAsinsByCountry?: Record<string, string[]>;
skip_asins_by_country?: Record<string, string[]>;
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
}
export interface ProductRiskMatchShopsVo {
items: ProductRiskShopQueueItem[];
}
export function listProductRiskCandidates() {
return unwrapJavaResponse(
get<JavaApiResponse<ProductRiskCandidateVo[]>>(
`${JAVA_API_PREFIX}/product-risk-resolve/candidates`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function addProductRiskCandidate(shopName: string) {
return unwrapJavaResponse(
post<
JavaApiResponse<ProductRiskCandidateVo>,
{ user_id: number; shop_name: string }
>(`${JAVA_API_PREFIX}/product-risk-resolve/candidates`, {
user_id: getCurrentUserId(),
shop_name: shopName,
}),
);
}
export function deleteProductRiskCandidate(id: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/product-risk-resolve/candidates/${id}`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export interface ProductRiskCountryPreferenceVo {
country_codes: string[];
}
export function getProductRiskCountryPreference() {
return unwrapJavaResponse(
get<JavaApiResponse<ProductRiskCountryPreferenceVo>>(
`${JAVA_API_PREFIX}/product-risk-resolve/country-preference`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function putProductRiskCountryPreference(countryCodes: string[]) {
return unwrapJavaResponse(
put<
JavaApiResponse<ProductRiskCountryPreferenceVo>,
{ user_id: number; country_codes: string[] }
>(`${JAVA_API_PREFIX}/product-risk-resolve/country-preference`, {
user_id: getCurrentUserId(),
country_codes: countryCodes,
}),
);
}
export function matchProductRiskShops(shopNames: string[]) {
return unwrapJavaResponse(
post<
JavaApiResponse<ProductRiskMatchShopsVo>,
{ user_id: number; shop_names: string[] }
>(`${JAVA_API_PREFIX}/product-risk-resolve/match-shops`, {
user_id: getCurrentUserId(),
shop_names: shopNames,
}),
);
}
export interface ProductRiskDashboardVo {
candidateCount: number;
processedTaskCount: number;
successTaskCount: number;
failedTaskCount: number;
}
export interface ProductRiskHistoryItem {
resultId?: number;
taskId?: number;
shopName?: string;
shopId?: string;
platform?: string;
companyName?: string;
matched?: boolean;
matchStatus?: string;
matchMessage?: string;
taskStatus?: string;
success?: boolean;
error?: string;
outputFilename?: string;
downloadUrl?: string;
fileJobId?: number;
fileStatus?: string;
fileError?: string;
fileReady?: boolean;
scheduledAt?: string;
skipAsinsByCountry?: Record<string, string[]>;
skip_asins_by_country?: Record<string, string[]>;
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
}
export interface ProductRiskHistoryVo {
items: ProductRiskHistoryItem[];
}
export interface ProductRiskTaskSummary {
id?: number;
taskNo?: string;
status?: string;
errorMessage?: string;
createdAt?: string;
updatedAt?: string;
finishedAt?: string;
scheduledAt?: string;
countryCodes?: string[];
currentStageIndex?: number;
activeStageIndex?: number;
scheduleStages?: ShopMatchTaskStage[];
}
export interface ProductRiskTaskDetailVo {
task?: ProductRiskTaskSummary;
items?: ProductRiskHistoryItem[];
}
export interface ProductRiskTaskBatchVo {
items: ProductRiskTaskDetailVo[];
missingTaskIds?: number[];
}
export interface ProductRiskPendingDeleteVo {
removed: boolean;
}
export interface ProductRiskCreateTaskVo {
taskId: number;
items: ProductRiskHistoryItem[];
}
export type ShopMatchCandidateVo = ProductRiskCandidateVo;
export type ShopMatchCountryPreferenceVo = ProductRiskCountryPreferenceVo;
export type ShopMatchShopQueueItem = ProductRiskShopQueueItem;
export type ShopMatchDashboardVo = ProductRiskDashboardVo;
export type ShopMatchHistoryItem = ProductRiskHistoryItem;
export type ShopMatchHistoryVo = ProductRiskHistoryVo;
export type ShopMatchTaskDetailVo = ProductRiskTaskDetailVo;
export type ShopMatchTaskBatchVo = ProductRiskTaskBatchVo;
export interface ShopMatchCreateTaskItem {
shopName: string;
matched: boolean;
shopId?: string;
platform?: string;
companyName?: string;
openStoreUrl?: string;
matchedUserId?: number;
matchStatus?: string;
matchMessage?: string;
}
export interface ShopMatchCreateTaskResultItem {
resultId?: number;
taskId?: number;
shopName?: string;
shopId?: string;
platform?: string;
companyName?: string;
matched?: boolean;
matchStatus?: string;
matchMessage?: string;
taskStatus?: string;
success?: boolean;
error?: string;
outputFilename?: string;
downloadUrl?: string;
fileJobId?: number;
fileStatus?: string;
fileError?: string;
fileReady?: boolean;
scheduledAt?: string;
}
export interface ShopMatchCreateTaskVo {
taskId: number;
items: ShopMatchCreateTaskResultItem[];
}
export interface ShopMatchTaskStage {
stageIndex?: number;
scheduledAt?: string;
status?: string;
}
export function getProductRiskDashboard() {
return unwrapJavaResponse(
get<JavaApiResponse<ProductRiskDashboardVo>>(
`${JAVA_API_PREFIX}/product-risk-resolve/dashboard`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function getProductRiskHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<ProductRiskHistoryVo>>(
`${JAVA_API_PREFIX}/product-risk-resolve/history`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function deleteProductRiskHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/product-risk-resolve/history/${resultId}`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function createProductRiskTask(items: ProductRiskShopQueueItem[]) {
return unwrapJavaResponse(
post<
JavaApiResponse<ProductRiskCreateTaskVo>,
{ user_id: number; items: ProductRiskShopQueueItem[] }
>(`${JAVA_API_PREFIX}/product-risk-resolve/tasks`, {
user_id: getCurrentUserId(),
items,
}),
);
}
export function deleteProductRiskTask(taskId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/${taskId}`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function deletePendingProductRiskShopResult(shopName: string) {
return unwrapJavaResponse(
del<JavaApiResponse<ProductRiskPendingDeleteVo>>(
`${JAVA_API_PREFIX}/product-risk-resolve/pending-shop-result`,
{
params: { user_id: getCurrentUserId(), shop_name: shopName },
},
),
);
}
export function getProductRiskTasksBatch(taskIds: number[]) {
return unwrapJavaResponse(
post<JavaApiResponse<ProductRiskTaskBatchVo>, { taskIds: number[] }>(
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/batch`,
{ taskIds },
),
);
}
export function getProductRiskResultDownloadUrl(resultId: number) {
return getJavaDownloadUrl(
`/product-risk-resolve/results/${resultId}/download`,
);
}
export function listShopMatchCandidates() {
return unwrapJavaResponse(
get<JavaApiResponse<ShopMatchCandidateVo[]>>(
`${JAVA_API_PREFIX}/shop-match/candidates`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function addShopMatchCandidate(shopName: string) {
return unwrapJavaResponse(
post<
JavaApiResponse<ShopMatchCandidateVo>,
{ user_id: number; shop_name: string }
>(`${JAVA_API_PREFIX}/shop-match/candidates`, {
user_id: getCurrentUserId(),
shop_name: shopName,
}),
);
}
export function deleteShopMatchCandidate(id: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/candidates/${id}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function getShopMatchCountryPreference() {
return unwrapJavaResponse(
get<JavaApiResponse<ShopMatchCountryPreferenceVo>>(
`${JAVA_API_PREFIX}/shop-match/country-preference`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function putShopMatchCountryPreference(countryCodes: string[]) {
return unwrapJavaResponse(
put<
JavaApiResponse<ShopMatchCountryPreferenceVo>,
{ user_id: number; country_codes: string[] }
>(`${JAVA_API_PREFIX}/shop-match/country-preference`, {
user_id: getCurrentUserId(),
country_codes: countryCodes,
}),
);
}
export function matchShopMatchShops(shopNames: string[]) {
return unwrapJavaResponse(
post<
JavaApiResponse<ProductRiskMatchShopsVo>,
{ user_id: number; shop_names: string[] }
>(`${JAVA_API_PREFIX}/shop-match/match-shops`, {
user_id: getCurrentUserId(),
shop_names: shopNames,
}),
);
}
export function getShopMatchDashboard() {
return unwrapJavaResponse(
get<JavaApiResponse<ShopMatchDashboardVo>>(
`${JAVA_API_PREFIX}/shop-match/dashboard`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function getShopMatchHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<ShopMatchHistoryVo>>(
`${JAVA_API_PREFIX}/shop-match/history`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function deleteShopMatchHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/history/${resultId}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function createShopMatchTask(
items: ShopMatchCreateTaskItem[],
countryCodes: string[],
scheduleTimes?: string[],
) {
return unwrapJavaResponse(
post<
JavaApiResponse<ShopMatchCreateTaskVo>,
{ user_id: number; items: ShopMatchCreateTaskItem[]; country_codes: string[]; schedule_times?: string[] }
>(`${JAVA_API_PREFIX}/shop-match/tasks`, {
user_id: getCurrentUserId(),
items,
country_codes: countryCodes,
schedule_times: scheduleTimes,
}),
);
}
export function deleteShopMatchTask(taskId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function activateShopMatchTask(taskId: number, stageIndex: number) {
return unwrapJavaResponse(
post<JavaApiResponse<null>, undefined>(
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/activate?user_id=${encodeURIComponent(String(getCurrentUserId()))}&stage_index=${encodeURIComponent(String(stageIndex))}`,
undefined,
),
);
}
export function completeShopMatchTaskStage(taskId: number, stageIndex: number) {
return unwrapJavaResponse(
post<JavaApiResponse<null>, { stage_index: number }>(
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/stage-finished?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
{ stage_index: stageIndex },
),
);
}
export function getShopMatchTasksBatch(taskIds: number[]) {
return unwrapJavaResponse(
post<JavaApiResponse<ShopMatchTaskBatchVo>, { taskIds: number[] }>(
`${JAVA_API_PREFIX}/shop-match/tasks/batch`,
{ taskIds },
),
);
}
export function getShopMatchResultDownloadUrl(resultId: number) {
return getJavaDownloadUrl(`/shop-match/results/${resultId}/download`);
}
export function getShopMatchTaskSkipAsinsPaginated(
taskId: number,
page: number = 1,
pageSize: number = 1000,
options: {
shopName?: string | string[];
countryCode?: string | string[];
} = {},
) {
return unwrapJavaResponse(
get<JavaApiResponse<ShopMatchSkipAsinPageVo>>(
`${JAVA_API_PREFIX}/shop-match/tasks/${taskId}/skip-asins/paginated`,
{
params: {
page,
page_size: pageSize,
...(options.shopName ? { shop_name: options.shopName } : {}),
...(options.countryCode ? { country_code: options.countryCode } : {}),
},
},
),
);
}
export type PatrolDeleteCandidateVo = ProductRiskCandidateVo;
export type PatrolDeleteDashboardVo = ProductRiskDashboardVo;
export type PatrolDeleteShopQueueItem = ProductRiskShopQueueItem;
export interface PatrolDeleteConditionVo {
id: number;
conditionText: string;
createdAt?: string;
}
export interface PatrolDeleteCountryMetricRow {
status: string;
quantity: string;
deleteQuantity: string;
processStatus: string;
}
export interface PatrolDeleteCountrySection {
country: string;
rows: PatrolDeleteCountryMetricRow[];
}
export interface PatrolDeleteCartRatio {
country: string;
ratio: string;
}
export interface PatrolDeleteTaskItem {
shopName?: string;
matched?: boolean;
shopId?: string;
platform?: string;
companyName?: string;
matchStatus?: string;
matchMessage?: string;
countrySections: PatrolDeleteCountrySection[];
cartRatios: PatrolDeleteCartRatio[];
}
export interface PatrolDeleteHistoryItem {
resultId?: number;
taskId?: number;
shopName?: string;
shopId?: string;
platform?: string;
companyName?: string;
matched?: boolean;
matchStatus?: string;
matchMessage?: string;
taskStatus?: string;
success?: boolean;
error?: string;
createdAt?: string;
finishedAt?: string;
outputFilename?: string;
downloadUrl?: string;
fileJobId?: number;
fileStatus?: string;
fileError?: string;
fileReady?: boolean;
countrySections: PatrolDeleteCountrySection[];
cartRatios: PatrolDeleteCartRatio[];
}
export interface PatrolDeleteHistoryVo {
items: PatrolDeleteHistoryItem[];
}
export interface PatrolDeleteTaskBatchVo {
items: PatrolDeleteHistoryItem[];
missingTaskIds: number[];
}
export interface PatrolDeleteCreateTaskVo {
taskId: number;
items: PatrolDeleteHistoryItem[];
}
export function listPatrolDeleteCandidates() {
return unwrapJavaResponse(
get<JavaApiResponse<PatrolDeleteCandidateVo[]>>(
`${JAVA_API_PREFIX}/patrol-delete/candidates`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function addPatrolDeleteCandidate(shopName: string) {
return unwrapJavaResponse(
post<
JavaApiResponse<PatrolDeleteCandidateVo>,
{ user_id: number; shop_name: string }
>(`${JAVA_API_PREFIX}/patrol-delete/candidates`, {
user_id: getCurrentUserId(),
shop_name: shopName,
}),
);
}
export function deletePatrolDeleteCandidate(id: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/patrol-delete/candidates/${id}`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function listPatrolDeleteConditions() {
return unwrapJavaResponse(
get<JavaApiResponse<PatrolDeleteConditionVo[]>>(
`${JAVA_API_PREFIX}/patrol-delete/conditions`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function addPatrolDeleteCondition(conditionText: string) {
return unwrapJavaResponse(
post<
JavaApiResponse<PatrolDeleteConditionVo>,
{ user_id: number; condition_text: string }
>(`${JAVA_API_PREFIX}/patrol-delete/conditions`, {
user_id: getCurrentUserId(),
condition_text: conditionText,
}),
);
}
export function deletePatrolDeleteCondition(id: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/patrol-delete/conditions/${id}`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function matchPatrolDeleteShops(shopNames: string[]) {
return unwrapJavaResponse(
post<
JavaApiResponse<ProductRiskMatchShopsVo>,
{ user_id: number; shop_names: string[] }
>(`${JAVA_API_PREFIX}/patrol-delete/match-shops`, {
user_id: getCurrentUserId(),
shop_names: shopNames,
}),
);
}
export function getPatrolDeleteDashboard() {
return unwrapJavaResponse(
get<JavaApiResponse<PatrolDeleteDashboardVo>>(
`${JAVA_API_PREFIX}/patrol-delete/dashboard`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function getPatrolDeleteHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<PatrolDeleteHistoryVo>>(
`${JAVA_API_PREFIX}/patrol-delete/history`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function getPatrolDeleteTaskProgressBatch(taskIds: number[]) {
return postTaskProgressBatch<PatrolDeleteTaskBatchVo>(
`${JAVA_API_PREFIX}/patrol-delete/tasks/progress/batch`,
taskIds,
);
}
export function createPatrolDeleteTask(items: PatrolDeleteTaskItem[]) {
return unwrapJavaResponse(
post<
JavaApiResponse<PatrolDeleteCreateTaskVo>,
{ user_id: number; items: PatrolDeleteTaskItem[] }
>(`${JAVA_API_PREFIX}/patrol-delete/tasks`, {
user_id: getCurrentUserId(),
items,
}),
);
}
export function submitPatrolDeleteTaskResult(
taskId: number,
payload: {
shops: Array<{
shopName: string;
error?: string;
countrySections: PatrolDeleteCountrySection[];
cartRatios: PatrolDeleteCartRatio[];
shopDone?: boolean;
submissionId?: string;
chunkIndex?: number;
chunkTotal?: number;
}>;
},
) {
return unwrapJavaResponse(
post<
JavaApiResponse<null>,
{
shops: Array<{
shopName: string;
error?: string;
countrySections: PatrolDeleteCountrySection[];
cartRatios: PatrolDeleteCartRatio[];
shopDone?: boolean;
submissionId?: string;
chunkIndex?: number;
chunkTotal?: number;
}>;
}
>(`${JAVA_API_PREFIX}/patrol-delete/tasks/${taskId}/result`, payload),
);
}
export function getPatrolDeleteResultDownloadUrl(resultId: number) {
return getJavaDownloadUrl(`/patrol-delete/results/${resultId}/download`);
}
export function deletePatrolDeleteTask(taskId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/patrol-delete/tasks/${taskId}`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export function deletePatrolDeleteHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/patrol-delete/history/${resultId}`,
{
params: { user_id: getCurrentUserId() },
},
),
);
}
export type QueryAsinCandidateVo = ProductRiskCandidateVo;
export type QueryAsinDashboardVo = ProductRiskDashboardVo;
export type QueryAsinShopQueueItem = ProductRiskShopQueueItem;
export interface QueryAsinCountryAsins {
country: string;
asins: string[];
}
export interface QueryAsinStatusItem {
asin?: string;
status?: string;
}
export interface QueryAsinCountryResult {
country: string;
items: QueryAsinStatusItem[];
}
export interface QueryAsinTaskItem {
shopName?: string;
matched?: boolean;
shopId?: string;
platform?: string;
companyName?: string;
matchStatus?: string;
matchMessage?: string;
queryAsins: QueryAsinCountryAsins[];
}
export interface QueryAsinHistoryItem {
resultId?: number;
taskId?: number;
shopName?: string;
shopId?: string;
platform?: string;
companyName?: string;
matched?: boolean;
matchStatus?: string;
matchMessage?: string;
taskStatus?: string;
success?: boolean;
error?: string;
createdAt?: string;
finishedAt?: string;
outputFilename?: string;
downloadUrl?: string;
fileJobId?: number;
fileStatus?: string;
fileError?: string;
fileReady?: boolean;
queryAsins: QueryAsinCountryAsins[];
countryResults?: QueryAsinCountryResult[];
}
export interface QueryAsinHistoryVo {
items: QueryAsinHistoryItem[];
}
export interface QueryAsinTaskBatchVo {
items: QueryAsinHistoryItem[];
missingTaskIds: number[];
}
export interface QueryAsinCreateTaskVo {
taskId: number;
items: QueryAsinHistoryItem[];
}
export function listQueryAsinCandidates() {
return unwrapJavaResponse(
get<JavaApiResponse<QueryAsinCandidateVo[]>>(`${JAVA_API_PREFIX}/query-asin/candidates`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function addQueryAsinCandidate(shopName: string) {
return unwrapJavaResponse(
post<JavaApiResponse<QueryAsinCandidateVo>, { user_id: number; shop_name: string }>(
`${JAVA_API_PREFIX}/query-asin/candidates`,
{ user_id: getCurrentUserId(), shop_name: shopName },
),
);
}
export function deleteQueryAsinCandidate(id: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/query-asin/candidates/${id}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function matchQueryAsinShops(shopNames: string[]) {
return unwrapJavaResponse(
post<JavaApiResponse<ProductRiskMatchShopsVo>, { user_id: number; shop_names: string[] }>(
`${JAVA_API_PREFIX}/query-asin/match-shops`,
{ user_id: getCurrentUserId(), shop_names: shopNames },
),
);
}
export function getQueryAsinDashboard() {
return unwrapJavaResponse(
get<JavaApiResponse<QueryAsinDashboardVo>>(`${JAVA_API_PREFIX}/query-asin/dashboard`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function getQueryAsinHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<QueryAsinHistoryVo>>(`${JAVA_API_PREFIX}/query-asin/history`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function getQueryAsinTaskProgressBatch(taskIds: number[]) {
return postTaskProgressBatch<QueryAsinTaskBatchVo>(
`${JAVA_API_PREFIX}/query-asin/tasks/progress/batch`,
taskIds,
);
}
export function createQueryAsinTask(items: QueryAsinTaskItem[]) {
return unwrapJavaResponse(
post<JavaApiResponse<QueryAsinCreateTaskVo>, { user_id: number; items: QueryAsinTaskItem[] }>(
`${JAVA_API_PREFIX}/query-asin/tasks`,
{ user_id: getCurrentUserId(), items },
),
);
}
export function submitQueryAsinTaskResult(
taskId: number,
payload: {
shops: Array<{
shopName: string;
error?: string;
countryResults?: QueryAsinCountryResult[];
shopDone?: boolean;
submissionId?: string;
}>;
},
) {
return unwrapJavaResponse(
post<JavaApiResponse<null>, typeof payload>(`${JAVA_API_PREFIX}/query-asin/tasks/${taskId}/result`, payload),
);
}
export function getQueryAsinResultDownloadUrl(resultId: number) {
return getJavaDownloadUrl(`/query-asin/results/${resultId}/download`);
}
export function deleteQueryAsinTask(taskId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/query-asin/tasks/${taskId}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function deleteQueryAsinHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/query-asin/history/${resultId}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
// ========== 店铺数据抓取 ==========
export interface ShopDataCrawlCandidateVo {
id: number;
shop_name: string;
created_at?: string;
}
export interface ShopDataCrawlCountryPreferenceVo {
country_codes: string[];
}
export interface ShopDataCrawlShopItem {
shopName: string;
matched: boolean;
shopId?: string;
platform?: string;
companyName?: string;
openStoreUrl?: string;
matchedUserId?: number;
matchStatus?: string;
matchMessage?: string;
}
export interface ShopDataCrawlMatchVo {
items: ShopDataCrawlShopItem[];
}
export interface ShopDataCrawlDashboardVo {
candidateCount: number;
processedTaskCount: number;
successTaskCount: number;
failedTaskCount: number;
}
export interface ShopDataCrawlHistoryItem extends ShopDataCrawlShopItem {
resultId?: number;
taskId?: number;
taskStatus?: string;
success?: boolean;
error?: string;
fileReady?: boolean;
fileStatus?: string;
downloadUrl?: string;
outputFilename?: string;
createdAt?: string;
finishedAt?: string;
}
export interface ShopDataCrawlHistoryVo {
items: ShopDataCrawlHistoryItem[];
}
export interface ShopDataCrawlTaskSummary {
id?: number;
status?: string;
errorMessage?: string;
createdAt?: string;
finishedAt?: string;
countryCodes?: string[];
}
export interface ShopDataCrawlTaskDetailVo {
task?: ShopDataCrawlTaskSummary;
items?: ShopDataCrawlHistoryItem[];
}
export interface ShopDataCrawlTaskBatchVo {
items: Array<ShopDataCrawlTaskDetailVo | ShopDataCrawlHistoryItem>;
missingTaskIds?: number[];
}
export interface ShopDataCrawlCreateTaskVo {
taskId: number;
items: ShopDataCrawlHistoryItem[];
}
export function listShopDataCrawlCandidates() {
return unwrapJavaResponse(
get<JavaApiResponse<ShopDataCrawlCandidateVo[]>>(`${JAVA_API_PREFIX}/shop-data-crawl/candidates`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function addShopDataCrawlCandidate(shopName: string) {
return unwrapJavaResponse(
post<JavaApiResponse<ShopDataCrawlCandidateVo>, { user_id: number; shop_name: string }>(
`${JAVA_API_PREFIX}/shop-data-crawl/candidates`,
{ user_id: getCurrentUserId(), shop_name: shopName },
),
);
}
export function deleteShopDataCrawlCandidate(id: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-data-crawl/candidates/${id}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function getShopDataCrawlCountryPreference() {
return unwrapJavaResponse(
get<JavaApiResponse<ShopDataCrawlCountryPreferenceVo>>(
`${JAVA_API_PREFIX}/shop-data-crawl/country-preference`,
{ params: { user_id: getCurrentUserId() } },
),
);
}
export function putShopDataCrawlCountryPreference(countryCodes: string[]) {
return unwrapJavaResponse(
put<JavaApiResponse<ShopDataCrawlCountryPreferenceVo>, { user_id: number; country_codes: string[] }>(
`${JAVA_API_PREFIX}/shop-data-crawl/country-preference`,
{ user_id: getCurrentUserId(), country_codes: countryCodes },
),
);
}
export function matchShopDataCrawlShops(shopNames: string[]) {
return unwrapJavaResponse(
post<JavaApiResponse<ShopDataCrawlMatchVo>, { user_id: number; shop_names: string[] }>(
`${JAVA_API_PREFIX}/shop-data-crawl/match-shops`,
{ user_id: getCurrentUserId(), shop_names: shopNames },
),
);
}
export function getShopDataCrawlDashboard() {
return unwrapJavaResponse(
get<JavaApiResponse<ShopDataCrawlDashboardVo>>(`${JAVA_API_PREFIX}/shop-data-crawl/dashboard`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function getShopDataCrawlHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<ShopDataCrawlHistoryVo>>(`${JAVA_API_PREFIX}/shop-data-crawl/history`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function createShopDataCrawlTask(items: ShopDataCrawlShopItem[], countryCodes: string[]) {
return unwrapJavaResponse(
post<
JavaApiResponse<ShopDataCrawlCreateTaskVo>,
{ user_id: number; items: ShopDataCrawlShopItem[]; country_codes: string[] }
>(`${JAVA_API_PREFIX}/shop-data-crawl/tasks`, {
user_id: getCurrentUserId(),
items,
country_codes: countryCodes,
}),
);
}
export function getShopDataCrawlTaskProgressBatch(taskIds: number[]) {
return postTaskProgressBatch<ShopDataCrawlTaskBatchVo>(
`${JAVA_API_PREFIX}/shop-data-crawl/tasks/progress/batch`,
taskIds,
);
}
export function getShopDataCrawlResultDownloadUrl(resultId: number) {
return getJavaDownloadUrl(`/shop-data-crawl/results/${resultId}/download`);
}
export function deleteShopDataCrawlTask(taskId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-data-crawl/tasks/${taskId}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function deleteShopDataCrawlHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/shop-data-crawl/history/${resultId}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
// ========== 取款 ==========
export type WithdrawCandidateVo = QueryAsinCandidateVo;
export type WithdrawDashboardVo = QueryAsinDashboardVo;
export type WithdrawShopQueueItem = ProductRiskShopQueueItem;
export type WithdrawStatusCode =
| "ZERO_AVAILABLE"
| "SUCCESS"
| "BALANCE_FORBIDDEN"
| "NEGATIVE_WITHDRAW_BLANK";
export interface WithdrawRow {
country?: string;
shopAmount?: number | string | null;
withdrawAmount?: number | string | null;
status?: WithdrawStatusCode | string;
}
export interface WithdrawTaskItem {
shopName: string;
matched: boolean;
shopId?: string;
platform?: string;
companyName?: string;
matchStatus?: string;
matchMessage?: string;
}
export interface WithdrawHistoryItem extends WithdrawTaskItem {
resultId?: number;
taskId?: number;
taskStatus?: string;
reservedAmount?: number | string | null;
success?: boolean;
error?: string;
outputFilename?: string;
downloadUrl?: string;
fileJobId?: number;
fileStatus?: string;
fileError?: string;
fileReady?: boolean;
createdAt?: string;
finishedAt?: string;
rows?: WithdrawRow[];
shops?: WithdrawHistoryItem[];
}
export interface WithdrawHistoryVo {
items: WithdrawHistoryItem[];
}
export interface WithdrawTaskBatchVo {
items: WithdrawHistoryItem[];
missingTaskIds: number[];
}
export interface WithdrawCreateTaskVo {
taskId: number;
items: WithdrawHistoryItem[];
}
export function listWithdrawCandidates() {
return unwrapJavaResponse(
get<JavaApiResponse<WithdrawCandidateVo[]>>(`${JAVA_API_PREFIX}/withdraw/candidates`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function addWithdrawCandidate(shopName: string) {
return unwrapJavaResponse(
post<JavaApiResponse<WithdrawCandidateVo>, { user_id: number; shop_name: string }>(
`${JAVA_API_PREFIX}/withdraw/candidates`,
{ user_id: getCurrentUserId(), shop_name: shopName },
),
);
}
export function deleteWithdrawCandidate(id: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/withdraw/candidates/${id}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function clearWithdrawCandidates(shopNames: string[]) {
return unwrapJavaResponse(
post<JavaApiResponse<null>, { user_id: number; shop_names: string[] }>(
`${JAVA_API_PREFIX}/withdraw/candidates/clear`,
{ user_id: getCurrentUserId(), shop_names: shopNames },
),
);
}
export function matchWithdrawShops(shopNames: string[]) {
return unwrapJavaResponse(
post<JavaApiResponse<ProductRiskMatchShopsVo>, { user_id: number; shop_names: string[] }>(
`${JAVA_API_PREFIX}/withdraw/match-shops`,
{ user_id: getCurrentUserId(), shop_names: shopNames },
),
);
}
export function getWithdrawDashboard() {
return unwrapJavaResponse(
get<JavaApiResponse<WithdrawDashboardVo>>(`${JAVA_API_PREFIX}/withdraw/dashboard`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function getWithdrawHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<WithdrawHistoryVo>>(`${JAVA_API_PREFIX}/withdraw/history`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function getWithdrawTaskProgressBatch(taskIds: number[]) {
return postTaskProgressBatch<WithdrawTaskBatchVo>(
`${JAVA_API_PREFIX}/withdraw/tasks/progress/batch`,
taskIds,
);
}
export function createWithdrawTask(items: WithdrawTaskItem[], reservedAmount: number | string | null) {
return unwrapJavaResponse(
post<JavaApiResponse<WithdrawCreateTaskVo>, { user_id: number; reserved_amount: number | string | null; items: WithdrawTaskItem[] }>(
`${JAVA_API_PREFIX}/withdraw/tasks`,
{ user_id: getCurrentUserId(), reserved_amount: reservedAmount, items },
),
);
}
export function submitWithdrawTaskResult(
taskId: number,
payload: {
shops: Array<{
shopName: string;
error?: string;
rows?: WithdrawRow[];
shopDone?: boolean;
submissionId?: string;
}>;
},
) {
return unwrapJavaResponse(
post<JavaApiResponse<null>, typeof payload>(`${JAVA_API_PREFIX}/withdraw/tasks/${taskId}/result`, payload),
);
}
export function getWithdrawResultDownloadUrl(resultId: number) {
return getJavaDownloadUrl(`/withdraw/results/${resultId}/download`);
}
export function deleteWithdrawTask(taskId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/withdraw/tasks/${taskId}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
export function deleteWithdrawHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/withdraw/history/${resultId}`, {
params: { user_id: getCurrentUserId() },
}),
);
}
// ========== 跟价 ==========
export interface PriceTrackCandidateVo {
id: number;
shopName: string;
}
export interface PriceTrackShopQueueItem {
shopName?: string;
shopMallName?: string;
shopId?: number | string | null;
matched?: boolean;
matchStatus?: string;
matchMessage?: string;
platform?: string;
companyName?: string;
skipAsins?: Record<string, string[]>;
}
export interface PriceTrackMatchShopsVo {
items: PriceTrackShopQueueItem[];
skipAsinsByCountry?: Record<string, string[]>;
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
asinRowsByCountry?: Record<string, PriceTrackAsinParsedRow[]>;
minimumPriceByCountryAndAsin?: Record<string, Record<string, string>>;
}
export interface PriceTrackCountryPreferenceVo {
userId: number;
countryCodes: string[];
}
export interface PriceTrackDashboardVo {
candidateCount: number;
processedTaskCount: number;
successTaskCount: number;
failedTaskCount: number;
}
export interface PriceTrackHistoryItem {
resultId?: number;
taskId?: number;
loopRunId?: number;
roundIndex?: number;
shopName?: string;
shopMallName?: string;
shopId?: number | string | null;
platform?: string;
companyName?: string;
matched?: boolean;
matchStatus?: string;
matchMessage?: string;
taskStatus?: string;
outputFilename?: string;
downloadUrl?: string;
fileJobId?: number;
fileStatus?: string;
fileError?: string;
fileReady?: boolean;
error?: string;
success?: boolean;
}
export interface PriceTrackHistoryVo {
items: PriceTrackHistoryItem[];
}
export interface PriceTrackAsinParsedRow {
shopMallName?: string;
asin?: string;
price?: string;
recommendedPrice?: string;
shippingFee?: string;
minimumPrice?: string;
firstPlace?: string;
firstShop?: string;
secondPlace?: string;
secondShop?: string;
cartShopName?: string;
priceChangeStatus?: string;
modifyCount?: string;
status?: string;
}
export interface PriceTrackCreateTaskVo {
taskId: number;
items: PriceTrackHistoryItem[];
skipAsinsByCountry?: Record<string, string[]>;
skipAsinDetailsByCountry?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
asinRowsByCountry?: Record<string, PriceTrackAsinParsedRow[]>;
minimumPriceByCountryAndAsin?: Record<string, Record<string, string>>;
}
export interface PriceTrackTaskSummary {
id?: number;
taskNo?: string;
status?: string;
loopRunId?: number;
roundIndex?: number;
errorMessage?: string;
createdAt?: string;
updatedAt?: string;
finishedAt?: string;
}
export interface PriceTrackTaskDetailVo {
task?: PriceTrackTaskSummary;
items?: PriceTrackHistoryItem[];
}
export interface PriceTrackTaskBatchVo {
items: PriceTrackTaskDetailVo[];
missingTaskIds?: number[];
}
export interface PriceTrackPendingDeleteVo {
removed: boolean;
}
export type PriceTrackCreateTaskPayload = Omit<
PriceTrackCreateTaskRequest,
"userId"
>;
export function listPriceTrackCandidates() {
return unwrapJavaResponse(
get<JavaApiResponse<PriceTrackCandidateVo[]>>(
`${JAVA_API_PREFIX}/price-track/candidates?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
),
);
}
export function addPriceTrackCandidate(shopName: string) {
return unwrapJavaResponse(
post<JavaApiResponse<PriceTrackCandidateVo>, { userId: number; shopName: string }>(
`${JAVA_API_PREFIX}/price-track/candidates`,
{ userId: getCurrentUserId(), shopName },
),
);
}
export function deletePriceTrackCandidate(id: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/price-track/candidates/${id}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
),
);
}
export function getPriceTrackCountryPreference() {
return unwrapJavaResponse(
get<JavaApiResponse<PriceTrackCountryPreferenceVo>>(
`${JAVA_API_PREFIX}/price-track/country-preference?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
),
);
}
export function putPriceTrackCountryPreference(countryCodes: string[]) {
return unwrapJavaResponse(
put<JavaApiResponse<PriceTrackCountryPreferenceVo>, { userId: number; countryCodes: string[] }>(
`${JAVA_API_PREFIX}/price-track/country-preference`,
{ userId: getCurrentUserId(), countryCodes },
),
);
}
export function matchPriceTrackShops(
shopNames: string[],
options?: {
asinFiles?: string[];
countryCodes?: string[];
},
) {
return unwrapJavaResponse(
post<
JavaApiResponse<PriceTrackMatchShopsVo>,
{ userId: number; shopNames: string[]; asinFiles?: string[]; countryCodes?: string[] }
>(
`${JAVA_API_PREFIX}/price-track/match-shops`,
{
userId: getCurrentUserId(),
shopNames,
asinFiles: options?.asinFiles || [],
countryCodes: options?.countryCodes || [],
},
),
);
}
export function getShopMatchTaskProgressBatch(taskIds: number[]) {
return postTaskProgressBatch<ShopMatchTaskBatchVo>(
`${JAVA_API_PREFIX}/shop-match/tasks/progress/batch`,
taskIds,
);
}
export function getProductRiskTaskProgressBatch(taskIds: number[]) {
return postTaskProgressBatch<ProductRiskTaskBatchVo>(
`${JAVA_API_PREFIX}/product-risk-resolve/tasks/progress/batch`,
taskIds,
);
}
export function getDeleteBrandTaskProgress(taskIds: number[]) {
return postTaskProgressBatch<DeleteBrandTaskBatchVo>(
`${JAVA_API_PREFIX}/delete-brand/tasks/progress/batch`,
taskIds,
);
}
export function getPriceTrackDashboard() {
return unwrapJavaResponse(
get<JavaApiResponse<PriceTrackDashboardVo>>(
`${JAVA_API_PREFIX}/price-track/dashboard?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
),
);
}
export function getPriceTrackHistory() {
return unwrapJavaResponse(
get<JavaApiResponse<PriceTrackHistoryVo>>(
`${JAVA_API_PREFIX}/price-track/history?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
),
);
}
export function deletePriceTrackHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/price-track/history/${resultId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
),
);
}
export interface PriceTrackCreateTaskRequest {
userId: number;
statusMode: boolean;
asinMode: boolean;
items: PriceTrackShopQueueItem[];
asinFiles: string[];
countryCodes: string[];
loopRunId?: number;
roundIndex?: number;
shopIndex?: number;
}
export type PriceTrackExecutionMode = "FINITE" | "INFINITE";
export interface PriceTrackLoopRunCreateRequest {
userId: number;
statusMode: boolean;
asinMode: boolean;
items: PriceTrackShopQueueItem[];
asinFiles: string[];
countryCodes: string[];
executionMode: PriceTrackExecutionMode;
targetRounds?: number;
}
export interface PriceTrackLoopRunVo {
id: number;
status?: string;
executionMode?: PriceTrackExecutionMode;
targetRounds?: number;
currentRound?: number;
currentShopIndex?: number;
totalShopCount?: number;
activeTaskId?: number;
activeTaskStatus?: string;
stopRequested?: boolean;
errorMessage?: string;
statusMode?: boolean;
asinMode?: boolean;
asinFiles?: string[];
countryCodes?: string[];
}
export interface PriceTrackLoopRunDispatchVo {
loopRun?: PriceTrackLoopRunVo;
childTaskRequest?: PriceTrackCreateTaskRequest;
}
export function createPriceTrackTask(
request: PriceTrackCreateTaskPayload | PriceTrackCreateTaskRequest,
) {
return unwrapJavaResponse(
post<JavaApiResponse<PriceTrackCreateTaskVo>, PriceTrackCreateTaskRequest>(
`${JAVA_API_PREFIX}/price-track/tasks`,
{ ...request, userId: getCurrentUserId() },
),
);
}
export function deletePriceTrackTask(taskId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
),
);
}
export function getPriceTrackTasksBatch(taskIds: number[]) {
return unwrapJavaResponse(
post<JavaApiResponse<PriceTrackTaskBatchVo>, { taskIds: number[] }>(
`${JAVA_API_PREFIX}/price-track/tasks/batch`,
{ taskIds },
),
);
}
export function createPriceTrackLoopRun(
request: Omit<PriceTrackLoopRunCreateRequest, "userId"> | PriceTrackLoopRunCreateRequest,
) {
return unwrapJavaResponse(
post<JavaApiResponse<PriceTrackLoopRunVo>, PriceTrackLoopRunCreateRequest>(
`${JAVA_API_PREFIX}/price-track/loop-runs`,
{ ...request, userId: getCurrentUserId() },
),
);
}
export function getPriceTrackLoopRun(loopRunId: number) {
return unwrapJavaResponse(
get<JavaApiResponse<PriceTrackLoopRunVo>>(
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
),
);
}
export function dispatchNextPriceTrackLoopRun(loopRunId: number) {
return unwrapJavaResponse(
post<JavaApiResponse<PriceTrackLoopRunDispatchVo>, undefined>(
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/dispatch-next?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
undefined,
),
);
}
export function completePriceTrackLoopChild(loopRunId: number, childTaskId: number) {
return unwrapJavaResponse(
post<JavaApiResponse<PriceTrackLoopRunVo>, { childTaskId: number }>(
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/child-finished?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
{ childTaskId },
),
);
}
export function stopPriceTrackLoopRun(loopRunId: number) {
return unwrapJavaResponse(
post<JavaApiResponse<PriceTrackLoopRunVo>, undefined>(
`${JAVA_API_PREFIX}/price-track/loop-runs/${loopRunId}/stop?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
undefined,
),
);
}
export function getPriceTrackTaskProgressBatch(taskIds: number[]) {
return postTaskProgressBatch<PriceTrackTaskBatchVo>(
`${JAVA_API_PREFIX}/price-track/tasks/progress/batch`,
taskIds,
);
}
export function getPriceTrackResultDownloadUrl(resultId: number) {
return getJavaDownloadUrl(`/price-track/results/${resultId}/download`);
}
export function getTaskSkipPriceAsinsPaginated(
taskId: number,
page: number = 1,
pageSize: number = 1000,
options: {
shopName?: string | string[];
countryCode?: string | string[];
} = {},
) {
return unwrapJavaResponse(
get<JavaApiResponse<SkipPriceAsinPageVo>>(
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/skip-asins/paginated`,
{
params: {
page,
page_size: pageSize,
...(options.shopName ? { shop_name: options.shopName } : {}),
...(options.countryCode ? { country_code: options.countryCode } : {}),
},
},
),
);
}
export function markPriceTrackDispatchFailed(taskId: number, errorMessage: string) {
return unwrapJavaResponse(
post<JavaApiResponse<null>, { errorMessage: string }>(
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/dispatch-failed?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
{ errorMessage },
),
);
}
export function checkTaskSkipPriceAsin(taskId: number, country: string, asin: string) {
return unwrapJavaResponse(
get<JavaApiResponse<SkipPriceAsinCheckVo>>(
`${JAVA_API_PREFIX}/price-track/tasks/${taskId}/skip-asin/check`,
{
params: {
country,
asin,
},
},
),
);
}
export interface SkipPriceAsinCheckVo {
country: string;
asin: string;
exists: boolean;
minimumPrice?: string;
}
export interface SkipPriceAsinPageVo {
page: number;
pageSize: number;
total: number;
totalPages: number;
skipAsinsByCountry: Record<string, string[]>;
skipAsinDetailsByCountry: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
skip_asins?: Record<string, string[]>;
skip_asins_by_country?: Record<string, string[]>;
skip_asin_details_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
asin_rows_by_country?: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
minimum_price_by_country_and_asin?: Record<string, Record<string, string>>;
}
export interface ShopMatchSkipAsinPageVo {
page: number;
pageSize: number;
total: number;
totalPages: number;
queryAsins: QueryAsinCountryAsins[];
skipAsinsByCountry: Record<string, string[]>;
skipAsinDetailsByCountry: Record<string, Array<{ asin?: string; minimumPrice?: string }>>;
}
export function deletePendingPriceTrackShopResult(shopName: string) {
return unwrapJavaResponse(
del<JavaApiResponse<PriceTrackPendingDeleteVo>>(
`${JAVA_API_PREFIX}/price-track/pending-shop-result?user_id=${encodeURIComponent(String(getCurrentUserId()))}&shop_name=${encodeURIComponent(shopName)}`,
),
);
}
// ========== 视频复刻 / 图生视频 ==========
export interface ImageVideoDouyinCopyVo {
recognizedContent?: string;
scriptDraft?: string;
executeId?: string;
debugUrl?: string;
}
export interface ImageVideoDouyinCopyPayload {
url: string;
api_key?: string;
t8_key?: string;
duration?: number;
proc_info?: {
type: string;
name: string;
proc_image: string[];
properties: string;
};
}
export interface ImageVideoSecretStatusVo {
userId?: number;
configured?: boolean;
valid?: boolean;
expired?: boolean;
hasCopyApiKey?: boolean;
hasT8Key?: boolean;
hasT8VideoKey?: boolean;
hasVoiceApiKey?: boolean;
hasVoiceGroupId?: boolean;
copyApiKeyMasked?: string;
t8KeyMasked?: string;
t8VideoKeyMasked?: string;
voiceApiKeyMasked?: string;
voiceGroupIdMasked?: string;
expireDays?: number;
expiresAt?: string;
}
export interface ImageVideoSecretSavePayload {
copyApiKey?: string;
t8Key?: string;
t8VideoKey?: string;
voiceApiKey?: string;
voiceGroupId?: string;
expireDays: number;
}
export interface ImageVideoWorkflowParameters {
api_key_info: {
t8star_key: string;
t8_video_key: string;
ai_conductor_key: string;
};
bg_info: {
type: number;
prompt: string;
bg_image: string;
};
face_info: {
type: number;
model_figure: string;
model_image: string[];
};
proc_info: {
type: string;
name: string;
proc_image: string[];
properties: string;
};
text_info: {
type: number;
language: string;
text: string;
file_url: string;
};
audio_info: {
audio_url: string;
type: number;
bgm_url: string;
mode: number;
voice_name: string;
};
video_info: {
video_url: string;
share_url: string;
ref_video_mode: string;
mode: string;
draft: boolean;
model: string;
prompt: string;
ratio: string;
resolution: string;
duration: number;
};
}
export interface ImageVideoWorkflowResponse {
code?: number;
msg?: string;
data?: string;
execute_id?: string;
debug_url?: string;
[key: string]: unknown;
}
export type ImageVideoAsyncTaskStatus = 'PENDING' | 'RUNNING' | 'WAITING' | 'POLLING' | 'SUCCESS' | 'FAILED'
export interface ImageVideoAsyncTaskVo {
taskId: number;
taskType: string;
status: ImageVideoAsyncTaskStatus;
cozeExecuteId?: string;
cozeStatus?: string;
debugUrl?: string;
result?: unknown;
errorMessage?: string;
submittedAt?: string;
completedAt?: string;
}
export interface ImageVideoMediaUploadVo {
url: string;
objectKey: string;
originalFilename: string;
mediaType: "image" | "video" | "audio" | string;
}
export interface ImageVideoVoiceWorkflowResponse {
code?: number;
msg?: string;
data?: unknown;
execute_id?: string;
debug_url?: string;
[key: string]: unknown;
}
export interface ImageVideoWorkflowRunRequest {
userId: number;
parameters: ImageVideoWorkflowParameters;
}
export interface ImageVideoWorkflowResultRequest {
userId: number;
executeId: string;
}
export function getImageVideoSecretStatus() {
return unwrapJavaResponse(
get<JavaApiResponse<ImageVideoSecretStatusVo>>(
`${JAVA_API_PREFIX}/image-video/secrets`,
{ params: { user_id: getCurrentUserId() } },
),
);
}
export function saveImageVideoSecrets(payload: ImageVideoSecretSavePayload) {
return unwrapJavaResponse(
put<JavaApiResponse<ImageVideoSecretStatusVo>, ImageVideoSecretSavePayload & { userId: number }>(
`${JAVA_API_PREFIX}/image-video/secrets`,
{ ...payload, userId: getCurrentUserId() },
),
);
}
export function runImageVideoDouyinCopy(payload: ImageVideoDouyinCopyPayload) {
return unwrapJavaResponse(
post<JavaApiResponse<ImageVideoAsyncTaskVo>, ImageVideoDouyinCopyPayload & { userId: number }>(
`${JAVA_API_PREFIX}/image-video/douyin-copy`,
{ userId: getCurrentUserId(), ...payload },
),
);
}
export function runImageVideoWorkflow(parameters: ImageVideoWorkflowParameters) {
return unwrapJavaResponse(
post<JavaApiResponse<ImageVideoAsyncTaskVo>, ImageVideoWorkflowRunRequest>(
`${JAVA_API_PREFIX}/image-video/workflow/run`,
{ userId: getCurrentUserId(), parameters },
),
);
}
export function getImageVideoWorkflowResult(executeId: string) {
return unwrapJavaResponse(
post<JavaApiResponse<ImageVideoAsyncTaskVo>, ImageVideoWorkflowResultRequest>(
`${JAVA_API_PREFIX}/image-video/workflow/result`,
{ userId: getCurrentUserId(), executeId },
),
);
}
export function getImageVideoAsyncTask(taskId: number) {
return unwrapJavaResponse(
get<JavaApiResponse<ImageVideoAsyncTaskVo>>(
`${JAVA_API_PREFIX}/image-video/tasks/${taskId}`,
{ params: { user_id: getCurrentUserId() } },
),
);
}
export async function uploadImageVideoMedia(file: File) {
const response = await uploadTempFileToJava(file, {
uploadToOss: true,
moduleType: "IMAGE_VIDEO",
});
if (!response.success) {
throw new Error(response.message || "请求失败");
}
const data = response.data;
if (!data?.url || !data.objectKey) {
throw new Error("OSS 上传未返回有效 URL");
}
return {
url: data.url,
objectKey: data.objectKey,
originalFilename: data.originalFilename || file.name,
mediaType: data.mediaType || resolveImageVideoMediaType(file),
} as ImageVideoMediaUploadVo;
}
function resolveImageVideoMediaType(file: File) {
const type = (file.type || "").toLowerCase();
const name = (file.name || "").toLowerCase();
if (type.startsWith("image/") || /\.(png|jpe?g|webp|gif|bmp|svg)$/.test(name)) return "image";
if (type.startsWith("video/") || /\.(mp4|mov|webm|m4v|ogg|avi|mkv)$/.test(name)) return "video";
if (type.startsWith("audio/") || /\.(mp3|wav|m4a|aac|flac)$/.test(name)) return "audio";
return "file";
}
export function listImageVideoVoices(name = "") {
return unwrapJavaResponse(
post<JavaApiResponse<ImageVideoAsyncTaskVo>, { userId: number; name: string }>(
`${JAVA_API_PREFIX}/image-video/voice/list`,
{ userId: getCurrentUserId(), name },
),
);
}
export function deleteImageVideoVoice(voiceId: string) {
return unwrapJavaResponse(
post<JavaApiResponse<ImageVideoAsyncTaskVo>, { userId: number; voiceId: string }>(
`${JAVA_API_PREFIX}/image-video/voice/delete`,
{ userId: getCurrentUserId(), voiceId },
),
);
}
export function cloneImageVideoVoice(payload: { name?: string; audioUrl?: string; videoUrl?: string }) {
return unwrapJavaResponse(
post<JavaApiResponse<ImageVideoAsyncTaskVo>, { userId: number; name?: string; audioUrl?: string; videoUrl?: string }>(
`${JAVA_API_PREFIX}/image-video/voice/clone`,
{ userId: getCurrentUserId(), ...payload },
),
);
}
export function synthesizeImageVideoVoice(payload: { text: string; voiceId: string }) {
return unwrapJavaResponse(
post<JavaApiResponse<ImageVideoAsyncTaskVo>, { userId: number; text: string; voiceId: string }>(
`${JAVA_API_PREFIX}/image-video/voice/synthesis`,
{ userId: getCurrentUserId(), ...payload },
),
);
}
// ========== 采集数据 ==========
export interface CollectDataSourceFile {
fileKey: string;
originalFilename?: string;
relativePath?: string;
}
export interface CollectDataFilters {
amount?: number | string | null;
minAmount?: number | string | null;
maxAmount?: number | string | null;
min_amount?: number | string | null;
max_amount?: number | string | null;
rank?: boolean | null;
fba?: boolean | null;
fbm?: boolean | null;
countryCodes?: string[];
countryCode?: string | null;
country_code?: string | null;
}
export interface CollectDataParseRequest {
user_id: number;
files: CollectDataSourceFile[];
task_type?: string;
filters?: CollectDataFilters;
}
export interface CollectDataParseVo {
taskId: number;
taskNo?: string;
sourceFilename?: string;
sourceFileCount?: number;
totalRows?: number;
acceptedRows?: number;
droppedRows?: number;
pageSize?: number;
}
export interface CollectDataDashboardVo {
pendingTaskCount: number;
processedTaskCount: number;
successTaskCount: number;
failedTaskCount: number;
}
export interface CollectDataHistoryItem {
resultId?: number;
taskId?: number;
taskNo?: string;
sourceFilename?: string;
resultFilename?: string;
downloadUrl?: string;
taskStatus?: string;
success?: boolean;
error?: string;
rowCount?: number;
dedupeFilteredCount?: number;
invalidFilteredCount?: number;
brandRejectedCount?: number;
finalRowCount?: number;
totalRows?: number;
receivedRows?: number;
processedRows?: number;
collectStage?: string;
currentKeyword?: string;
searchCurrentPage?: number;
searchTotalPages?: number;
detailProcessedAsins?: number;
detailTotalAsins?: number;
progressPercent?: number;
createdAt?: string;
startedAt?: string;
finishedAt?: string;
taskType?: string;
filters?: CollectDataFilters;
}
export interface CollectDataHistoryVo {
items: CollectDataHistoryItem[];
}
export interface CollectDataTaskSummary {
id?: number;
taskNo?: string;
status?: string;
errorMessage?: string;
createdAt?: string;
updatedAt?: string;
startedAt?: string;
finishedAt?: string;
taskType?: string;
}
export interface CollectDataTaskDetailVo {
task?: CollectDataTaskSummary;
items?: CollectDataHistoryItem[];
}
export interface CollectDataTaskBatchVo {
items: CollectDataTaskDetailVo[];
missingTaskIds?: number[];
}
export interface CollectDataItemVo {
id?: number;
rowIndex?: number;
sourceFileKey?: string;
sourceFilename?: string;
keyword?: string;
statusValue?: string;
extra?: Record<string, string>;
}
export interface CollectDataItemsPageVo {
taskId?: number;
taskNo?: string;
taskType?: string;
taskStatus?: string;
page?: number;
pageSize?: number;
count?: number;
total?: number;
totalPages?: number;
filters?: CollectDataFilters;
items: CollectDataItemVo[];
}
export function parseCollectData(
request: Omit<CollectDataParseRequest, "user_id"> | CollectDataParseRequest,
) {
return unwrapJavaResponse(
post<JavaApiResponse<CollectDataParseVo>, CollectDataParseRequest>(
`${JAVA_API_PREFIX}/collect-data/parse`,
{ ...request, user_id: getCurrentUserId() },
),
);
}
export function activateCollectDataTask(taskId: number) {
return unwrapJavaResponse(
post<JavaApiResponse<null>, undefined>(
`${JAVA_API_PREFIX}/collect-data/tasks/${taskId}/activate?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
undefined,
),
);
}
export function getCollectDataItemsPage(
taskId: number,
page: number = 1,
pageSize: number = 50,
) {
return unwrapJavaResponse(
get<JavaApiResponse<CollectDataItemsPageVo>>(
`${JAVA_API_PREFIX}/collect-data/tasks/${taskId}/items`,
{
params: {
user_id: getCurrentUserId(),
page,
page_size: pageSize,
},
},
),
);
}
export function getCollectDataDashboard() {
return unwrapJavaResponse(
get<JavaApiResponse<CollectDataDashboardVo>>(
`${JAVA_API_PREFIX}/collect-data/dashboard`,
{ params: { user_id: getCurrentUserId() } },
),
);
}
export function getCollectDataHistory(limit: number = 50) {
return unwrapJavaResponse(
get<JavaApiResponse<CollectDataHistoryVo>>(
`${JAVA_API_PREFIX}/collect-data/history`,
{ params: { user_id: getCurrentUserId(), limit } },
),
);
}
export function getCollectDataTaskProgressBatch(
taskIds: number[],
options: TaskProgressBatchOptions = {},
) {
return postTaskProgressBatch<CollectDataTaskBatchVo>(
`${JAVA_API_PREFIX}/collect-data/tasks/progress/batch`,
taskIds,
options,
);
}
export function deleteCollectDataTask(taskId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/collect-data/tasks/${taskId}`,
{ params: { user_id: getCurrentUserId() } },
),
);
}
export function deleteCollectDataHistory(resultId: number) {
return unwrapJavaResponse(
del<JavaApiResponse<null>>(
`${JAVA_API_PREFIX}/collect-data/history/${resultId}`,
{ params: { user_id: getCurrentUserId() } },
),
);
}
export interface CollectDataCountryPreferenceVo {
country_codes: string[];
}
export function getCollectDataCountryPreference() {
return unwrapJavaResponse(
get<JavaApiResponse<CollectDataCountryPreferenceVo>>(
`${JAVA_API_PREFIX}/collect-data/country-preference`,
{ params: { user_id: getCurrentUserId() } },
),
);
}
export function putCollectDataCountryPreference(countryCodes: string[]) {
return unwrapJavaResponse(
put<
JavaApiResponse<CollectDataCountryPreferenceVo>,
{ user_id: number; country_codes: string[] }
>(`${JAVA_API_PREFIX}/collect-data/country-preference`, {
user_id: getCurrentUserId(),
country_codes: countryCodes,
}),
);
}
export function failCollectDataTask(taskId: number, error?: string) {
const params = new URLSearchParams({ user_id: String(getCurrentUserId()) });
if (error) params.set('error', error);
return unwrapJavaResponse(
post<JavaApiResponse<null>, undefined>(
`${JAVA_API_PREFIX}/collect-data/tasks/${taskId}/fail?${params.toString()}`,
undefined,
),
);
}
export function getJavaDownloadUrl(path: string) {
let raw =
path.startsWith("http://") || path.startsWith("https://")
? path
: `${JAVA_API_PREFIX}${path}`;
// pywebview 的 save_file_from_url_new 需要完整且带 schema 的 URL
if (
!raw.startsWith("http://") &&
!raw.startsWith("https://") &&
typeof window !== "undefined"
) {
raw = `${window.location.origin}${raw}`;
}
const separator = raw.includes("?") ? "&" : "?";
return `${raw}${separator}user_id=${encodeURIComponent(String(getCurrentUserId()))}`;
}
export { JAVA_API_PREFIX, http };