Spaces:
Running
Running
Deploy d347cc7 từ GitHub Actions
Browse filesFiles changed (5)
254 unmodified lines25525625725825825926026116 unmodified lines278279280281281282283284254 unmodified lines}));
api.get('/batches/:bid', h(async (req, res) => { res.json({ batch: await batchOr404(String(req.params.bid)), live: liveStatus(String(req.params.bid)) }); res.json({ batch: await batchOr404(String(req.params.bid)), live: liveStatus(String(req.params.bid), req.user!.role === 'admin') });}));
// Upload ảnh / zip (multipart). Có thể gọi nhiều lần cho cùng 1 lô.16 unmodified lines const since = Number(req.query.since ?? 0) || 0; const now = Date.now(); // trả kèm mốc thời gian server để client hỏi tiếp từ đó (trừ lùi 2s phòng lệch giờ ghi) res.json({ items: await listItems(String(req.params.bid), since), next: now - 2000, live: liveStatus(String(req.params.bid)) }); res.json({ items: await listItems(String(req.params.bid), since), next: now - 2000, live: liveStatus(String(req.params.bid), req.user!.role === 'admin') });}));
async function itemOr404(bid: string, iid: string) {95 unmodified lines969798991001011021031041059910010610710810911095 unmodified lines await patchBatch(batchId, { status: 'done' }).catch(() => undefined);}
/** Mã bước gửi cho user thường (không lộ chi tiết nội bộ): 1 = lưu Storage, 2 = chuẩn bị, 3 = đợi Gemini/xử lý */function stepCode(step: string): number { if (step === 'Lưu lên Telegram') return 1; if (step === 'Chuẩn bị') return 2; return 3;}
export function liveStatus(batchId: string) { const processing = [...live.entries()].filter(([, v]) => v.batchId === batchId).map(([id, v]) => ({ id, step: v.step }));export function liveStatus(batchId: string, admin: boolean) { const processing = [...live.entries()].filter(([, v]) => v.batchId === batchId).map(([id, v]) => ({ id, step: admin ? v.step : stepCode(v.step) })); return { processing, waitingTelegram: tgQueue.filter((t) => t.batchId === batchId).length,1234456753 unmodified lines616263646465666728 unmodified lines9697989999100101102'use client';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { passportValidity, type Batch } from '@pc/core';import { deleteItem, getBatch, listItems, rerunItem, saveItem, updateBatch, type Live } from '../lib/api';import { deleteItem, stepLabel, getBatch, listItems, rerunItem, saveItem, updateBatch, type Live } from '../lib/api';import { startUpload, type UploadJob } from '../lib/uploader';import { useRouter } from 'next/navigation';import { exportCsv, exportXlsx } from '../lib/export';53 unmodified lines }, [refresh, active]);
const list = useMemo(() => [...items.values()].sort((a, b) => a.createdAt - b.createdAt || a.name.localeCompare(b.name)), [items]); const steps = useMemo(() => new Map(live.processing.map((p) => [p.id, p.step])), [live]); const steps = useMemo(() => new Map(live.processing.map((p) => [p.id, stepLabel(p.step)!])), [live]);
const counts = useMemo(() => { const c: Record<Filter, number> = { all: list.length, review: 0, HIGH: 0, MEDIUM: 0, LOW: 0, pending: 0, under180: 0 };28 unmodified lines }; const onRerun = async (id: string, mode: 'ocr' | 'llm') => { await rerunItem(batchId, id, mode); setLive((l) => ({ ...l, processing: [...l.processing, { id, step: 'Chờ xử lý lại' }] })); setLive((l) => ({ ...l, processing: [...l.processing, { id, step: isAdmin ? 'Chờ xử lý lại' : 3 }] })); setBatch((b) => (b ? { ...b, status: 'running' } : b)); }; const onDelete = async (id: string) => {1234456711 unmodified lines1920212222232425'use client';import { useCallback, useEffect, useState } from 'react';import type { Batch } from '@pc/core';import { getBatch, getItem, rerunItem, saveItem } from '../lib/api';import { getBatch, stepLabel, getItem, rerunItem, saveItem } from '../lib/api';import { useRouter } from 'next/navigation';import type { Item } from '../lib/types';import { ReviewPanel } from './ReviewPanel';11 unmodified lines const [it, b] = await Promise.all([getItem(batchId, itemId), getBatch(batchId)]); setItem(it); setBatch(b.batch); setStep(b.live.processing.find((p) => p.id === itemId)?.step); setStep(stepLabel(b.live.processing.find((p) => p.id === itemId)?.step)); } catch (e) { setErr((e as Error).message); }9 unmodified lines1011121314151613171819209 unmodified lines createdAt: number; updatedAt: number; createdBy?: string; lastLoginAt?: number;}
/** Admin nhận tên bước (chuỗi); user thường chỉ nhận mã số -> đổi sang nhãn đơn giản */const USER_STEPS: Record<number, string> = { 1: 'Lưu lên Storage', 2: 'Chuẩn bị', 3: 'Đợi phản hồi từ gemini' };export const stepLabel = (s: string | number | undefined) => (typeof s === 'number' ? USER_STEPS[s] ?? USER_STEPS[3] : s);
export interface Live { processing: { id: string; step: string }[]; waitingTelegram: number; waitingOcr: number; waitingLlm?: number }export interface Live { processing: { id: string; step: string | number }[]; waitingTelegram: number; waitingOcr: number; waitingLlm?: number }
export class ApiError extends Error { constructor(public status: number, message: string, public code?: string) { super(message); }passport-check/apps/server/src/index.ts+2-2
passport-check/apps/server/src/jobs.ts+9-2
passport-check/apps/web/src/components/BatchView.tsx+3-3
passport-check/apps/web/src/components/ItemPage.tsx+2-2
passport-check/apps/web/src/lib/api.ts+5-1