fix: m4mini deployment issues - duplicate script setup, auth redirect, Tauri bypass

This commit is contained in:
2026-06-26 20:33:35 +08:00
parent f915aaf794
commit 691b38fe96
14 changed files with 5185 additions and 219 deletions

View File

@@ -1,6 +1,6 @@
export const isTauri = typeof window !== 'undefined' && !!(window as any).__TAURI__
export function getApiBase(): string {
if (isTauri) return ''
if (isTauri) return 'http://localhost:8888'
return localStorage.getItem('proxy_url') || window.location.origin
}

View File

@@ -32,7 +32,16 @@ export async function apiCall(cmd: string, args: Record<string, any>): Promise<a
return httpCall('update_identity', { uuid: args.uuid, metadataJson: JSON.stringify(metadata) })
}
if (isTauri) {
return invoke(cmd, args)
try {
const data = await invoke(cmd, args)
return transformResponse(cmd, data)
} catch (e: any) {
console.error('[apiCall] invoke error:', typeof e, e)
const errMsg = typeof e === 'string' ? e : (e?.message || String(e))
console.error('[apiCall] falling back to HTTP for', cmd, '- error:', errMsg)
const data = await httpCall(cmd, args)
return transformResponse(cmd, data)
}
}
const data = await httpCall(cmd, args)
return transformResponse(cmd, data)
@@ -117,6 +126,14 @@ function buildHttpRequest(cmd: string, args: Record<string, any>): { url: string
case 'get_face_candidates': {
return { url: `/api/v1/faces/candidates?page=${a.page || 1}&page_size=${a.perPage || 100}`, method: 'GET' }
}
case 'get_unassigned_traces': {
let url = `/api/v1/traces/unassigned?page=${a.page || 1}&per_page=${a.perPage || 20}`
if (a.fileUuid) url += `&file_uuid=${a.fileUuid}`
return { url, method: 'GET' }
}
case 'get_pending_persons': {
return { url: `/api/v1/file/${a.fileUuid}/pending-persons`, method: 'GET' }
}
case 'get_identity': {
return { url: `/api/v1/identity/${a.uuid}`, method: 'GET' }
}
@@ -326,8 +343,6 @@ function buildHttpRequest(cmd: string, args: Record<string, any>): { url: string
// Transform HTTP response to match Tauri invoke format
// Some endpoints need data reshaping to match what the Rust commands return
export function transformResponse(cmd: string, data: any): any {
if (isTauri) return data
switch (cmd) {
case 'get_files': {
const files = data.files || data.data || data || []
@@ -337,7 +352,7 @@ export function transformResponse(cmd: string, data: any): any {
file_path: f.file_path || '',
file_size: f.file_size || 0,
modified_time: f.modified_time || '',
isRegistered: f.is_registered ?? false,
isRegistered: f.isRegistered ?? f.is_registered ?? false,
status: f.status || '',
registrationTime: f.registration_time || null,
ingested: f.ingested ?? (f.status === 'completed'),
@@ -349,8 +364,9 @@ export function transformResponse(cmd: string, data: any): any {
identity_uuid: p.identity_uuid || '',
name: p.name || '',
starred: p.metadata?.starred ?? p.starred ?? false,
status: p.metadata?.status ?? p.status ?? 'pending',
status: p.status || p.metadata?.status || 'pending',
metadata: p.metadata || {},
file_uuids: p.file_uuids || [],
}))
}
case 'get_faces': {
@@ -393,6 +409,32 @@ export function transformResponse(cmd: string, data: any): any {
bbox: c.bbox ? { x: c.bbox.x, y: c.bbox.y, width: c.bbox.width, height: c.bbox.height } : null,
}))
}
case 'get_unassigned_traces': {
const traces = data.traces || data.data || []
return {
total: data.total || traces.length || 0,
traces: traces.map((t: any) => ({
trace_id: t.trace_id,
file_uuid: t.file_uuid || '',
frame_count: t.frame_count || 0,
start_frame: t.start_frame || 0,
end_frame: t.end_frame || 1,
best_face_id: t.best_face_id,
best_face_frame: t.best_face_frame || 1,
best_face_confidence: t.best_face_confidence || 1,
best_face_bbox: t.best_face_bbox ? { x: t.best_face_bbox.x, y: t.best_face_bbox.y, width: t.best_face_bbox.width, height: t.best_face_bbox.height } : null,
})),
}
}
case 'get_pending_persons': {
return {
pending_persons: (data.pending_persons || data.data || []).map((p: any) => ({
identity_uuid: p.identity_uuid || '',
name: p.name || '',
trace_count: p.trace_count || 0,
})),
}
}
case 'search_llm_smart': {
const results = data.results || data.data || data || []
return results.map((r: any) => ({