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
This commit is contained in:
@@ -15,6 +15,7 @@ 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";
|
||||
|
||||
@@ -1668,204 +1669,6 @@ export function deleteWithdrawHistory(resultId: number) {
|
||||
);
|
||||
}
|
||||
|
||||
// ========== 外观专利检测 ==========
|
||||
|
||||
export interface AppearancePatentParsedRow {
|
||||
rowIndex: number;
|
||||
sourceFileKey?: string;
|
||||
sourceFilename?: string;
|
||||
sourceId: string;
|
||||
displayId: string;
|
||||
rowToken?: string;
|
||||
groupKey?: string;
|
||||
asin: string;
|
||||
country: string;
|
||||
price?: string;
|
||||
sku?: string;
|
||||
url?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export interface AppearancePatentParsedGroup {
|
||||
sourceFileKey?: string;
|
||||
sourceFilename?: string;
|
||||
groupKey?: string;
|
||||
baseId?: string;
|
||||
displayId?: string;
|
||||
itemCount?: number;
|
||||
items: AppearancePatentParsedRow[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentParseVo {
|
||||
taskId: number;
|
||||
sourceFilename?: string;
|
||||
sourceFileCount?: number;
|
||||
totalRows: number;
|
||||
acceptedRows: number;
|
||||
droppedRows: number;
|
||||
groupCount?: number;
|
||||
aiPrompt?: string;
|
||||
items: AppearancePatentParsedRow[];
|
||||
groups?: AppearancePatentParsedGroup[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentParsedPayloadDto {
|
||||
aiPrompt?: string;
|
||||
apiKey?: string;
|
||||
patentToken?: string;
|
||||
sourceFiles?: UploadedFileRef[];
|
||||
headers?: string[];
|
||||
items?: AppearancePatentParsedRow[];
|
||||
groups?: AppearancePatentParsedGroup[];
|
||||
allItems?: AppearancePatentParsedRow[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentDashboardVo {
|
||||
pendingTaskCount: number;
|
||||
processedTaskCount: number;
|
||||
successTaskCount: number;
|
||||
failedTaskCount: number;
|
||||
}
|
||||
|
||||
export interface AppearancePatentHistoryItem {
|
||||
resultId?: number;
|
||||
taskId?: number;
|
||||
sourceFilename?: string;
|
||||
resultFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
fileProgressPercent?: number;
|
||||
fileProgressCurrent?: number;
|
||||
fileProgressTotal?: number;
|
||||
fileProgressMessage?: string;
|
||||
taskStatus?: string;
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
rowCount?: number;
|
||||
createdAt?: string;
|
||||
startedAt?: string;
|
||||
finishedAt?: string;
|
||||
}
|
||||
|
||||
export interface AppearancePatentHistoryVo {
|
||||
items: AppearancePatentHistoryItem[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentTaskSummary {
|
||||
id?: number;
|
||||
taskNo?: string;
|
||||
status?: string;
|
||||
errorMessage?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
finishedAt?: string;
|
||||
}
|
||||
|
||||
export interface AppearancePatentTaskDetailVo {
|
||||
task?: AppearancePatentTaskSummary;
|
||||
items?: AppearancePatentHistoryItem[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentTaskBatchVo {
|
||||
items: AppearancePatentTaskDetailVo[];
|
||||
missingTaskIds?: number[];
|
||||
}
|
||||
|
||||
export function parseAppearancePatent(files: UploadedFileRef[], aiPrompt: string, apiKey?: string, patentToken?: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<AppearancePatentParseVo>,
|
||||
{ user_id: number; files: UploadedFileRef[]; ai_prompt: string; api_key?: string; patent_token?: string }
|
||||
>(`${JAVA_API_PREFIX}/appearance-patent/parse`, {
|
||||
user_id: getCurrentUserId(),
|
||||
files,
|
||||
ai_prompt: aiPrompt,
|
||||
api_key: apiKey,
|
||||
patent_token: patentToken,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentParsedPayload(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<AppearancePatentParsedPayloadDto>>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/tasks/${taskId}/parsed-payload`,
|
||||
{ params: { user_id: getCurrentUserId() } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentQueuePayload(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<AppearancePatentParsedPayloadDto>>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/tasks/${taskId}/queue-payload`,
|
||||
{ params: { user_id: getCurrentUserId() } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<AppearancePatentDashboardVo>>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/dashboard`,
|
||||
{ params: { user_id: getCurrentUserId() } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<AppearancePatentHistoryVo>>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/history`,
|
||||
{ params: { user_id: getCurrentUserId(), limit: 50 } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentTaskProgressBatch(
|
||||
taskIds: number[],
|
||||
options: TaskProgressBatchOptions = {},
|
||||
) {
|
||||
return postTaskProgressBatch<AppearancePatentTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/tasks/progress/batch`,
|
||||
taskIds,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
export function activateAppearancePatentTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, undefined>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/tasks/${taskId}/activate?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteAppearancePatentTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/appearance-patent/tasks/${taskId}`, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteAppearancePatentHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/history/${resultId}`,
|
||||
{ params: { user_id: getCurrentUserId() } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(`/appearance-patent/results/${resultId}/download`);
|
||||
}
|
||||
|
||||
// ========== 跟价 ==========
|
||||
|
||||
export interface PriceTrackCandidateVo {
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
import { get, post, del, type JavaApiResponse, unwrapJavaResponse } from '../../http.ts'
|
||||
import { buildJavaUrl, JAVA_API_PREFIX } from '../../url.ts'
|
||||
import { getCurrentUserId } from '../../user.ts'
|
||||
import { getJavaDownloadUrl } from '../../download-url.ts'
|
||||
import { getTaskProgressCacheTtlMs, getTaskProgressTimeoutMs } from '../../../task-progress-config.ts'
|
||||
import { createTaskProgressRequestCache } from '../../../task-progress-request-cache.ts'
|
||||
import type { UploadedFileRef } from '../upload.ts'
|
||||
import { API_ENDPOINTS } from '../../endpoints.ts'
|
||||
|
||||
export interface AppearancePatentParsedRow {
|
||||
rowIndex: number;
|
||||
sourceFileKey?: string;
|
||||
sourceFilename?: string;
|
||||
sourceId: string;
|
||||
displayId: string;
|
||||
rowToken?: string;
|
||||
groupKey?: string;
|
||||
asin: string;
|
||||
country: string;
|
||||
price?: string;
|
||||
sku?: string;
|
||||
url?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export interface AppearancePatentParsedGroup {
|
||||
sourceFileKey?: string;
|
||||
sourceFilename?: string;
|
||||
groupKey?: string;
|
||||
baseId?: string;
|
||||
displayId?: string;
|
||||
itemCount?: number;
|
||||
items: AppearancePatentParsedRow[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentParseVo {
|
||||
taskId: number;
|
||||
sourceFilename?: string;
|
||||
sourceFileCount?: number;
|
||||
totalRows: number;
|
||||
acceptedRows: number;
|
||||
droppedRows: number;
|
||||
groupCount?: number;
|
||||
aiPrompt?: string;
|
||||
items: AppearancePatentParsedRow[];
|
||||
groups?: AppearancePatentParsedGroup[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentParsedPayloadDto {
|
||||
aiPrompt?: string;
|
||||
apiKey?: string;
|
||||
patentToken?: string;
|
||||
sourceFiles?: UploadedFileRef[];
|
||||
headers?: string[];
|
||||
items?: AppearancePatentParsedRow[];
|
||||
groups?: AppearancePatentParsedGroup[];
|
||||
allItems?: AppearancePatentParsedRow[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentDashboardVo {
|
||||
pendingTaskCount: number;
|
||||
processedTaskCount: number;
|
||||
successTaskCount: number;
|
||||
failedTaskCount: number;
|
||||
}
|
||||
|
||||
export interface AppearancePatentHistoryItem {
|
||||
resultId?: number;
|
||||
taskId?: number;
|
||||
sourceFilename?: string;
|
||||
resultFilename?: string;
|
||||
downloadUrl?: string;
|
||||
fileJobId?: number;
|
||||
fileStatus?: string;
|
||||
fileError?: string;
|
||||
fileReady?: boolean;
|
||||
fileProgressPercent?: number;
|
||||
fileProgressCurrent?: number;
|
||||
fileProgressTotal?: number;
|
||||
fileProgressMessage?: string;
|
||||
taskStatus?: string;
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
rowCount?: number;
|
||||
createdAt?: string;
|
||||
startedAt?: string;
|
||||
finishedAt?: string;
|
||||
}
|
||||
|
||||
export interface AppearancePatentHistoryVo {
|
||||
items: AppearancePatentHistoryItem[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentTaskSummary {
|
||||
id?: number;
|
||||
taskNo?: string;
|
||||
status?: string;
|
||||
errorMessage?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
finishedAt?: string;
|
||||
}
|
||||
|
||||
export interface AppearancePatentTaskDetailVo {
|
||||
task?: AppearancePatentTaskSummary;
|
||||
items?: AppearancePatentHistoryItem[];
|
||||
}
|
||||
|
||||
export interface AppearancePatentTaskBatchVo {
|
||||
items: AppearancePatentTaskDetailVo[];
|
||||
missingTaskIds?: number[];
|
||||
}
|
||||
|
||||
interface TaskProgressBatchOptions {
|
||||
force?: boolean;
|
||||
}
|
||||
|
||||
const taskProgressResponseCache = createTaskProgressRequestCache<unknown>({
|
||||
ttlMs: () => getTaskProgressCacheTtlMs(),
|
||||
maxEntries: 100,
|
||||
maxInflight: 16,
|
||||
});
|
||||
|
||||
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 function parseAppearancePatent(files: UploadedFileRef[], aiPrompt: string, apiKey?: string, patentToken?: string) {
|
||||
return unwrapJavaResponse(
|
||||
post<
|
||||
JavaApiResponse<AppearancePatentParseVo>,
|
||||
{ user_id: number; files: UploadedFileRef[]; ai_prompt: string; api_key?: string; patent_token?: string }
|
||||
>(buildJavaUrl(API_ENDPOINTS.appearancePatent.parse), {
|
||||
user_id: getCurrentUserId(),
|
||||
files,
|
||||
ai_prompt: aiPrompt,
|
||||
api_key: apiKey,
|
||||
patent_token: patentToken,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentParsedPayload(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<AppearancePatentParsedPayloadDto>>(
|
||||
buildJavaUrl(API_ENDPOINTS.appearancePatent.parsedPayload.replace('{taskId}', String(taskId))),
|
||||
{ params: { user_id: getCurrentUserId() } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentQueuePayload(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<AppearancePatentParsedPayloadDto>>(
|
||||
buildJavaUrl(API_ENDPOINTS.appearancePatent.queuePayload.replace('{taskId}', String(taskId))),
|
||||
{ params: { user_id: getCurrentUserId() } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentDashboard() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<AppearancePatentDashboardVo>>(
|
||||
buildJavaUrl(API_ENDPOINTS.appearancePatent.dashboard),
|
||||
{ params: { user_id: getCurrentUserId() } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentHistory() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<AppearancePatentHistoryVo>>(
|
||||
buildJavaUrl(API_ENDPOINTS.appearancePatent.history),
|
||||
{ params: { user_id: getCurrentUserId(), limit: 50 } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentTaskProgressBatch(
|
||||
taskIds: number[],
|
||||
options: TaskProgressBatchOptions = {},
|
||||
) {
|
||||
return postTaskProgressBatch<AppearancePatentTaskBatchVo>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/tasks/progress/batch`,
|
||||
taskIds,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
export function activateAppearancePatentTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, undefined>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/tasks/${taskId}/activate?user_id=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
undefined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteAppearancePatentTask(taskId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(`${JAVA_API_PREFIX}/appearance-patent/tasks/${taskId}`, {
|
||||
params: { user_id: getCurrentUserId() },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteAppearancePatentHistory(resultId: number) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<null>>(
|
||||
`${JAVA_API_PREFIX}/appearance-patent/history/${resultId}`,
|
||||
{ params: { user_id: getCurrentUserId() } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getAppearancePatentResultDownloadUrl(resultId: number) {
|
||||
return getJavaDownloadUrl(
|
||||
API_ENDPOINTS.appearancePatent.resultDownload.replace('{resultId}', String(resultId)),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user