fix: 完成 B-1, B-2, B-4(proxy 硬编码移除 + re-scan 端点)
B-1: 移除 proxy 硬编码路径 - 移除 API_KEY 常量,改为 get_api_key() 从环境变量读取 - 移除 PROFILE_DIRS,改为 get_output_dir() 从环境变量读取 - 移除 output_bases (identity_matches, trace_profile),改为环境变量驱动 - 移除 ADMIN_CONFIG_PATH,改为 get_admin_config_path() 从环境变量读取 - 添加 dev fallback 支持开发环境 B-2: API key 改为环境变量 - MOMENTRY_API_KEY 环境变量必须设置 - 未设置时会明确报错启动 B-4: 改用 re-scan 端点 - 简化 doReprocess 函数从 92 行减少到 32 行 - 改用单一 POST /api/v1/re-scan API - 显式传 auto_pipeline: true - 移除 unregister → register → process 手动串接 - 原子性操作,避免中间失败留下不一致状态 环境变量: - MOMENTRY_API_KEY (必需) - MOMENTRY_OUTPUT_DIR (可选,默认 /Users/accusys/momentry/output) - MOMENTRY_DATA_DIR (可选,默认 /Users/accusys/momentry/data) - MOMENTRY_ADMIN_CONFIG (可选,默认 /Users/accusys/momentry/config/admin_config.json)
This commit is contained in:
@@ -536,6 +536,9 @@ case 'search_keyword': {
|
||||
case 'process_file': {
|
||||
return { url: `/api/v1/file/${a.fileUuid}/process`, method: 'POST', body: { processors: a.processors } }
|
||||
}
|
||||
case 're_scan_file': {
|
||||
return { url: `/api/v1/re-scan`, method: 'POST', body: { file_uuid: a.fileUuid, auto_pipeline: a.autoPipeline ?? true } }
|
||||
}
|
||||
case 'get_identity_matches': {
|
||||
return { url: `/api/v1/identity-matches?file_hash=${a.fileHash}`, method: 'GET' }
|
||||
}
|
||||
|
||||
@@ -1962,93 +1962,34 @@ async function doReprocess(f: any) {
|
||||
if (reprocessing.value) return
|
||||
if (!f.isRegistered) { actionMsg.value = 'File not registered'; return }
|
||||
reprocessing.value = true
|
||||
const oldUuid = f.file_uuid
|
||||
actionMsg.value = '🔄 Unregistering...'
|
||||
|
||||
try {
|
||||
const unregResult: any = await apiCall('unregister_file', { fileUuid: oldUuid, deleteOutputFiles: true })
|
||||
if (!unregResult.success) {
|
||||
actionMsg.value = `Unregister failed: ${unregResult.message}`
|
||||
reprocessing.value = false
|
||||
setTimeout(() => { actionMsg.value = '' }, 8000)
|
||||
return
|
||||
}
|
||||
actionMsg.value = '🔄 Re-scanning...'
|
||||
|
||||
if (unregResult.command_id) {
|
||||
actionMsg.value = '🔄 Waiting for unregister...'
|
||||
await pollCommandStatus(unregResult.command_id)
|
||||
}
|
||||
|
||||
// Clear all cached state for this file
|
||||
delete fileProgressCache.value[oldUuid]
|
||||
delete processorCountsCache.value[oldUuid]
|
||||
|
||||
actionMsg.value = '⏳ Waiting for unregister to stabilize...'
|
||||
await waitForStable(async () => {
|
||||
await invalidateFiles()
|
||||
await ensureFiles()
|
||||
return !filesCache.value.some((x: any) => x.file_uuid === oldUuid && x.isRegistered)
|
||||
// Use single re-scan API with auto_pipeline: true
|
||||
const result = await apiCall('re_scan_file', {
|
||||
fileUuid: f.file_uuid,
|
||||
autoPipeline: true
|
||||
})
|
||||
|
||||
actionMsg.value = '📥 Registering...'
|
||||
const filePath = f.file_path || f.relative_path || f.file_name
|
||||
if (!filePath) { actionMsg.value = 'Missing file path'; reprocessing.value = false; return }
|
||||
const regResult: any = await apiCall('register_file', { filePath })
|
||||
if (!regResult.success) {
|
||||
actionMsg.value = `Register failed: ${regResult.message}`
|
||||
reprocessing.value = false
|
||||
setTimeout(() => { actionMsg.value = '' }, 8000)
|
||||
return
|
||||
}
|
||||
|
||||
let newUuid = regResult.file_uuid
|
||||
if (regResult.command_id && !newUuid) {
|
||||
actionMsg.value = '📥 Waiting for registration...'
|
||||
const finalStatus = await pollCommandStatus(regResult.command_id)
|
||||
newUuid = finalStatus.file_uuid
|
||||
}
|
||||
|
||||
if (!newUuid) {
|
||||
actionMsg.value = `Registration completed but no file_uuid`
|
||||
reprocessing.value = false
|
||||
return
|
||||
}
|
||||
|
||||
f.file_uuid = newUuid
|
||||
f.isRegistered = true
|
||||
|
||||
actionMsg.value = '⏳ Waiting for registration to stabilize...'
|
||||
await waitForStable(async () => {
|
||||
await invalidateFiles()
|
||||
await ensureFiles()
|
||||
const found = filesCache.value.find((x: any) => x.file_uuid === f.file_uuid)
|
||||
return found && found.isRegistered && found.status === 'registered'
|
||||
})
|
||||
|
||||
actionMsg.value = '🔍 Scanning...'
|
||||
const procs = selectedProcessors()
|
||||
if (!procs.length) { actionMsg.value = 'Please select at least one processor'; reprocessing.value = false; return }
|
||||
|
||||
// Immediately update status to show user the action started
|
||||
f.status = 'scanning'
|
||||
fileStatusCache.value[f.file_uuid] = 'scanning'
|
||||
|
||||
const procResult: any = await apiCall('process_file', { fileUuid: f.file_uuid, processors: procs })
|
||||
if (procResult.success) {
|
||||
actionMsg.value = `Re-scan started: ${f.file_name}`
|
||||
syncFileStatus(f.file_uuid)
|
||||
if (result.success) {
|
||||
actionMsg.value = '✅ Re-scan started'
|
||||
// Update status to scanning
|
||||
f.status = 'scanning'
|
||||
fileStatusCache.value[f.file_uuid] = 'scanning'
|
||||
// Sync status from Core API
|
||||
await syncFileStatus(f.file_uuid)
|
||||
} else {
|
||||
actionMsg.value = `Scan failed: ${procResult.message}`
|
||||
// Revert status on failure
|
||||
f.status = 'registered'
|
||||
fileStatusCache.value[f.file_uuid] = 'registered'
|
||||
actionMsg.value = `Failed: ${result.message || result.error}`
|
||||
}
|
||||
} catch (e: any) {
|
||||
actionMsg.value = `Reprocess error: ${e}`
|
||||
console.error('[reprocess]', e)
|
||||
actionMsg.value = `Error: ${e.message}`
|
||||
console.error('[re-scan]', e)
|
||||
} finally {
|
||||
reprocessing.value = false
|
||||
await loadFiles()
|
||||
setTimeout(() => { actionMsg.value = '' }, 5000)
|
||||
}
|
||||
reprocessing.value = false
|
||||
await loadFiles()
|
||||
setTimeout(() => { actionMsg.value = '' }, 8000)
|
||||
}
|
||||
|
||||
async function ctxUnregister(f: any) {
|
||||
|
||||
Reference in New Issue
Block a user