fix(scan): Fix-mode scanner + dialog suppression + cancel/timer + importer revive
Build backend images / build content-svc (push) Failing after 1m25s
Build backend images / build file-svc (push) Failing after 1m10s
Build backend images / build gateway (push) Failing after 56s
Build backend images / build identity-svc (push) Failing after 53s
Build backend images / build notification-svc (push) Failing after 57s
Build backend images / build render-svc (push) Failing after 48s
Build backend images / build studio-svc (push) Failing after 1m5s
Build backend images / build content-svc (push) Failing after 1m25s
Build backend images / build file-svc (push) Failing after 1m10s
Build backend images / build gateway (push) Failing after 56s
Build backend images / build identity-svc (push) Failing after 53s
Build backend images / build notification-svc (push) Failing after 57s
Build backend images / build render-svc (push) Failing after 48s
Build backend images / build studio-svc (push) Failing after 1m5s
- scan.jsx: app.beginSuppressDialogs() + clean quit (no AE hang on font/footage dialogs); FIX-mode branch parses frl_c(x)t/m(y) layer names → scenes by c(x); flexible/mockup keep comp-based walk; FR_SCAN_MODE selects. - render-svc: scan job carries project mode; cancel endpoint + node watchdog that kills AE on cancel; parseObjectURL handles minio:// (bucket in host); scan with no template fails cleanly; status guards so late results can't un-cancel. - content importer: revive soft-deleted scenes instead of duplicate-inserting (fixes scenes_project_id_key unique violation); orphan diff ignores deleted. - admin: scan dialog gets project-type picker + elapsed timer + Cancel button. - node-agent: AE-2026 wiring (host port 5010, host-reachable presign endpoint), FR_SCAN_MODE plumbing. docs/aep-template-convention.md: per-type naming + bundles. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -157,6 +157,7 @@ func main() {
|
||||
v1.POST("/template-scans/:project_id/quick", auth, admin, scanH.QuickScan) // headless Go quick-scan
|
||||
v1.POST("/template-scans/:project_id/jobs", auth, admin, scanH.CreateJob) // queue an AE full scan
|
||||
v1.GET("/template-scan-jobs/:id", auth, admin, scanH.GetJob)
|
||||
v1.POST("/template-scan-jobs/:id/cancel", auth, admin, scanH.Cancel)
|
||||
|
||||
// ── Exports management (admin: all users' rendered videos) ────────────────
|
||||
adminExports := v1.Group("/admin-exports", auth, admin)
|
||||
@@ -185,6 +186,7 @@ func main() {
|
||||
|
||||
// AE scan jobs (node claims, runs scan.jsx, posts the ScanResult back)
|
||||
internal.POST("/scan/claim", scanH.Claim)
|
||||
internal.GET("/scan/:id/status", scanH.Status) // node watchdog (cancel detection)
|
||||
internal.POST("/scan/:id/result", scanH.Result)
|
||||
internal.POST("/scan/:id/fail", scanH.Fail)
|
||||
}
|
||||
|
||||
@@ -22,13 +22,17 @@ type ScanJob struct {
|
||||
type ScanClaim struct {
|
||||
ID uuid.UUID
|
||||
ProjectID uuid.UUID
|
||||
Mode string // fix | flexible | mockup | musicvisualizer → drives scan.jsx parsing
|
||||
}
|
||||
|
||||
func (s *Store) CreateScanJob(ctx context.Context, projectID uuid.UUID, engine string) (uuid.UUID, error) {
|
||||
func (s *Store) CreateScanJob(ctx context.Context, projectID uuid.UUID, engine, mode string) (uuid.UUID, error) {
|
||||
if mode == "" {
|
||||
mode = "flexible"
|
||||
}
|
||||
var id uuid.UUID
|
||||
err := s.pool.QueryRow(ctx,
|
||||
`INSERT INTO render.scan_jobs (project_id, engine, status) VALUES ($1, $2, 'queued') RETURNING id`,
|
||||
projectID, engine).Scan(&id)
|
||||
`INSERT INTO render.scan_jobs (project_id, engine, status, mode) VALUES ($1, $2, 'queued', $3) RETURNING id`,
|
||||
projectID, engine, mode).Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
@@ -44,7 +48,7 @@ func (s *Store) ClaimScanJob(ctx context.Context, nodeID uuid.UUID) (*ScanClaim,
|
||||
ORDER BY created_at
|
||||
LIMIT 1 FOR UPDATE SKIP LOCKED
|
||||
)
|
||||
RETURNING id, project_id`, nodeID).Scan(&c.ID, &c.ProjectID)
|
||||
RETURNING id, project_id, mode`, nodeID).Scan(&c.ID, &c.ProjectID, &c.Mode)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -54,19 +58,42 @@ func (s *Store) ClaimScanJob(ctx context.Context, nodeID uuid.UUID) (*ScanClaim,
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
// SetScanResult / SetScanError only act on a 'running' job, so a result that
|
||||
// arrives after the user cancelled doesn't un-cancel it.
|
||||
func (s *Store) SetScanResult(ctx context.Context, id uuid.UUID, resultJSON string) error {
|
||||
_, err := s.pool.Exec(ctx,
|
||||
`UPDATE render.scan_jobs SET status = 'done', result = $2::jsonb, error = NULL, updated_at = NOW() WHERE id = $1`,
|
||||
`UPDATE render.scan_jobs SET status = 'done', result = $2::jsonb, error = NULL, updated_at = NOW() WHERE id = $1 AND status = 'running'`,
|
||||
id, resultJSON)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Store) SetScanError(ctx context.Context, id uuid.UUID, msg string) error {
|
||||
_, err := s.pool.Exec(ctx,
|
||||
`UPDATE render.scan_jobs SET status = 'error', error = $2, updated_at = NOW() WHERE id = $1`, id, msg)
|
||||
`UPDATE render.scan_jobs SET status = 'error', error = $2, updated_at = NOW() WHERE id = $1 AND status = 'running'`, id, msg)
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelScanJob marks a queued/running scan as cancelled (user-requested). The
|
||||
// node's watchdog sees this and kills the AE process.
|
||||
func (s *Store) CancelScanJob(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := s.pool.Exec(ctx,
|
||||
`UPDATE render.scan_jobs SET status = 'cancelled', error = 'cancelled by user', updated_at = NOW() WHERE id = $1 AND status IN ('queued','running')`, id)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetScanStatus returns just the status string (lightweight, for the node watchdog).
|
||||
func (s *Store) GetScanStatus(ctx context.Context, id uuid.UUID) (string, error) {
|
||||
var st string
|
||||
err := s.pool.QueryRow(ctx, `SELECT status FROM render.scan_jobs WHERE id = $1`, id).Scan(&st)
|
||||
if err != nil {
|
||||
if err == pgx.ErrNoRows {
|
||||
return "", nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return st, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetScanJob(ctx context.Context, id uuid.UUID) (*ScanJob, error) {
|
||||
var j ScanJob
|
||||
err := s.pool.QueryRow(ctx,
|
||||
|
||||
@@ -173,19 +173,27 @@ func extractAepFromZip(zb []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
// ── AE scan jobs (async, full fidelity) ───────────────────────────────────────
|
||||
// POST /v1/template-scans/:project_id/jobs (admin)
|
||||
// POST /v1/template-scans/:project_id/jobs (admin) body: {"mode":"fix|flexible|mockup|musicvisualizer"}
|
||||
func (h *ScanHandler) CreateJob(c *gin.Context) {
|
||||
pid, err := uuid.Parse(c.Param("project_id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.APIError{Code: "bad_request", Message: "invalid project_id"})
|
||||
return
|
||||
}
|
||||
id, err := h.store.CreateScanJob(c.Request.Context(), pid, "ae-jsx")
|
||||
var req struct {
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
_ = c.ShouldBindJSON(&req)
|
||||
mode := strings.ToLower(strings.TrimSpace(req.Mode))
|
||||
if mode == "" {
|
||||
mode = "flexible"
|
||||
}
|
||||
id, err := h.store.CreateScanJob(c.Request.Context(), pid, "ae-jsx", mode)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.APIError{Code: "internal_error", Message: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"id": id, "status": "queued"})
|
||||
c.JSON(http.StatusOK, gin.H{"id": id, "status": "queued", "mode": mode})
|
||||
}
|
||||
|
||||
// GET /v1/template-scan-jobs/:id (admin)
|
||||
@@ -223,9 +231,18 @@ func (h *ScanHandler) Claim(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
url, isBundle, md5 := resolveTemplateObject(h.minio, h.templatesBucket, claim.ProjectID)
|
||||
if url == "" {
|
||||
// No template object stored for this project — fail the job with a clear
|
||||
// message instead of handing the node an empty URL.
|
||||
_ = h.store.SetScanError(c.Request.Context(), claim.ID,
|
||||
"no template stored for this project — upload the .aep from «فایلها» first")
|
||||
c.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"scan_job_id": claim.ID,
|
||||
"project_id": claim.ProjectID,
|
||||
"mode": claim.Mode,
|
||||
"aep_download_url": url,
|
||||
"is_bundle": isBundle,
|
||||
"bundle_md5": md5,
|
||||
@@ -272,6 +289,35 @@ func (h *ScanHandler) Fail(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// POST /v1/template-scan-jobs/:id/cancel (admin)
|
||||
func (h *ScanHandler) Cancel(c *gin.Context) {
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.APIError{Code: "bad_request", Message: "invalid id"})
|
||||
return
|
||||
}
|
||||
if err := h.store.CancelScanJob(c.Request.Context(), id); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.APIError{Code: "internal_error", Message: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "cancelled"})
|
||||
}
|
||||
|
||||
// GET /v1/internal/scan/:id/status (node watchdog, HMAC) → {"status": "..."}
|
||||
func (h *ScanHandler) Status(c *gin.Context) {
|
||||
id, err := uuid.Parse(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.APIError{Code: "bad_request", Message: "invalid id"})
|
||||
return
|
||||
}
|
||||
st, err := h.store.GetScanStatus(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.APIError{Code: "internal_error", Message: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": st})
|
||||
}
|
||||
|
||||
// resolveTemplateObject presigns the canonical template object for a project,
|
||||
// probing bundle.zip → template.aep → template.aepx (same order as render claim).
|
||||
func resolveTemplateObject(mc *minio.Client, bucket string, projectID uuid.UUID) (url string, isBundle bool, md5 string) {
|
||||
|
||||
@@ -128,13 +128,30 @@ func (h *TemplateBundleHandler) Set(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// parseObjectURL extracts the bucket and object key from a path-style storage URL
|
||||
// such as http://host:9000/<bucket>/<key...>. Query/fragment are ignored.
|
||||
// parseObjectURL extracts the bucket and object key from a storage URL. Handles
|
||||
// two forms:
|
||||
// - minio://<bucket>/<key...> (file-svc FileAddress — bucket is the HOST)
|
||||
// - http(s)://host[:port]/<bucket>/<key> (public path-style — bucket is the 1st path seg)
|
||||
// Query/fragment are ignored.
|
||||
func parseObjectURL(raw string) (bucket, key string, err error) {
|
||||
u, perr := url.Parse(strings.TrimSpace(raw))
|
||||
if perr != nil {
|
||||
return "", "", fmt.Errorf("parse url: %w", perr)
|
||||
}
|
||||
|
||||
// minio://<bucket>/<key> — the bucket lives in the host component.
|
||||
if u.Scheme == "minio" {
|
||||
k := strings.TrimPrefix(u.Path, "/")
|
||||
if u.Host == "" || k == "" {
|
||||
return "", "", fmt.Errorf("cannot derive bucket/key from %q", raw)
|
||||
}
|
||||
if dec, derr := url.PathUnescape(k); derr == nil {
|
||||
k = dec
|
||||
}
|
||||
return u.Host, k, nil
|
||||
}
|
||||
|
||||
// http(s)://host[:port]/<bucket>/<key...>
|
||||
p := strings.TrimPrefix(u.Path, "/")
|
||||
if p == "" {
|
||||
return "", "", fmt.Errorf("url has no path: %q", raw)
|
||||
|
||||
Reference in New Issue
Block a user