feat(brand): 品牌检测建单可选本机/线上采集(V212),默认本机+排队相位可见
This commit is contained in:
@@ -102,13 +102,50 @@ export function expandBrandFolderRecursive(folder: string) {
|
||||
return requestPostJson<BrandExpandFolderResponse>(`${API_PREFIX}/api/brand/expand-folder-recursive`, { folder })
|
||||
}
|
||||
|
||||
export function runBrandNow(files: UploadedFileRef[], strategy: string) {
|
||||
export function runBrandNow(files: UploadedFileRef[], strategy: string, collectChannel?: 'LOCAL' | 'ONLINE') {
|
||||
return requestPostJson<BrandTaskMutationResponse>(
|
||||
`${API_PREFIX}/api/brand/run?userId=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
{ files, strategy, taskType: 1 },
|
||||
{ files, strategy, taskType: 1, ...(collectChannel ? { collect_channel: collectChannel } : {}) },
|
||||
)
|
||||
}
|
||||
|
||||
/** 本机采集要用到的桥能力;由页面把 `getPywebviewApi()` 传进来(本模块不引桥,见下) */
|
||||
export interface BrandLocalBridge {
|
||||
run_brand_task?: (payload: { files: UploadedFileRef[]; strategy: string; uid: number }) => Promise<{
|
||||
success?: boolean
|
||||
task_id?: number
|
||||
error?: string
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
* 本机采集(V212):把这一单交给桌面客户端本机 Flask 执行。
|
||||
*
|
||||
* 页面载入的是线上 Web,`/api/brand/*` 的相对地址一律打到线上 15126(服务端执行);
|
||||
* 本地这一档只能经 pywebview 桥显式送回 127.0.0.1:5123,所以这里不走 fetch 而走桥。
|
||||
* 老客户端没有 `run_brand_task` 方法 ⇒ 返回 available=false,由页面把选项置灰并提示升级。
|
||||
*
|
||||
* 桥由调用方传入而不在此 import:本模块被 `node --test` 直接加载(tests/modules-image-video
|
||||
* 等),而 bridges/pywebview.ts 用的是 vite 别名与省略扩展名的导入,Node ESM 解析不了。
|
||||
*/
|
||||
export function runBrandLocal(files: UploadedFileRef[], strategy: string, bridge?: BrandLocalBridge) {
|
||||
if (!bridge?.run_brand_task) {
|
||||
return Promise.resolve({ available: false as const })
|
||||
}
|
||||
return Promise.resolve(
|
||||
bridge.run_brand_task({
|
||||
files,
|
||||
strategy,
|
||||
uid: getCurrentUserId(),
|
||||
}),
|
||||
).then((res) => ({
|
||||
available: true as const,
|
||||
success: Boolean(res?.success),
|
||||
taskId: Number(res?.task_id) || 0,
|
||||
error: res?.error ? String(res.error) : '',
|
||||
}))
|
||||
}
|
||||
|
||||
export function createBrandTask(files: UploadedFileRef[], strategy: string) {
|
||||
return requestPostJson<BrandTaskMutationResponse>(
|
||||
`${API_PREFIX}/api/brand/tasks?userId=${encodeURIComponent(String(getCurrentUserId()))}`,
|
||||
|
||||
@@ -19,6 +19,8 @@ export type CollectChannel = 'LOCAL' | 'ONLINE';
|
||||
export interface CollectRoutingVo {
|
||||
appearancePatentLocal: boolean;
|
||||
similarAsinLocal: boolean;
|
||||
/** 品牌检测默认通道(2026-11-18,V212):true=桌面客户端本机执行;false=服务端 15126 执行。 */
|
||||
brandLocal: boolean;
|
||||
}
|
||||
|
||||
export function getCollectRouting() {
|
||||
|
||||
@@ -141,6 +141,13 @@ export interface PywebviewApi {
|
||||
expand_brand_folder?: (
|
||||
folder: string,
|
||||
) => Promise<{ success: boolean; items?: Array<{ absolutePath: string; relativePath: string }>; error?: string }>;
|
||||
/**
|
||||
* 品牌检测本机采集(V212):把这一单交给本机 Flask 执行并返回 task_id。
|
||||
* 老客户端没有这个方法 ⇒ 页面据此把「本机采集」置灰并要求升级。
|
||||
*/
|
||||
run_brand_task?: (
|
||||
payload: { files: unknown[]; strategy: string; uid: number },
|
||||
) => Promise<{ success: boolean; task_id?: number; collect_channel?: string; error?: string }>;
|
||||
upload_file_to_java?: (
|
||||
filePath: string,
|
||||
relativePath?: string,
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 品牌检测的阶段文案(唯一出处)。
|
||||
*
|
||||
* 背景(2026-11-18):品牌任务的服务端执行方(15126)跨账号最多并发 2 个
|
||||
* (`BRAND_MAX_CONCURRENT_TASKS` 默认 2),同账号串行;名额被大单占满时后到的
|
||||
* 任务要排队几十分钟。排队期心跳此前一律报 `crawling`,界面就把「排队 62 分钟」
|
||||
* 显示成「品牌查询中 0/N」——用户只能以为任务卡死。现在排队期单独报 `queued`。
|
||||
*
|
||||
* 这里的 key 必须与后端 `BrandTaskProgressCacheService` 的 phase 白名单同形:
|
||||
* 后端会把白名单外的 phase 归一成 `crawling`,漏加即界面重新退回「品牌查询中」。
|
||||
*/
|
||||
export const BRAND_PHASE_TEXT: Record<string, string> = {
|
||||
queued: '排队中',
|
||||
crawling: '品牌查询中',
|
||||
assembling: '结果生成中',
|
||||
uploading: '结果上传中',
|
||||
failed: '处理失败',
|
||||
}
|
||||
|
||||
/** 未知/缺省 phase 的统一兜底文案(保持改动前的显示口径)。 */
|
||||
export const BRAND_PHASE_FALLBACK = '品牌检测中'
|
||||
|
||||
export function brandPhaseText(phase?: string | null): string {
|
||||
const key = (phase ?? '').trim()
|
||||
if (!key) return BRAND_PHASE_FALLBACK
|
||||
return BRAND_PHASE_TEXT[key] || BRAND_PHASE_FALLBACK
|
||||
}
|
||||
Reference in New Issue
Block a user