Upload updates

This commit is contained in:
2026-09-21 09:01:01 -05:00
parent 98025e9e6d
commit 474403ffe2
18 changed files with 2539 additions and 796 deletions
+33 -5
View File
@@ -355,12 +355,17 @@ export interface TempUpload {
status: "pending" | "visual_match" | "completed" | "error";
resolution: "" | "auto_md5" | "duplicate" | "linked" | "custom";
e621_post_id: number | null;
e621_data: E621StoredPost | null;
/** Full post payload: only present on the detail endpoint. */
e621_data?: E621StoredPost | null;
custom_rating: Rating;
custom_tags: string[];
custom_notes: string;
iqdb_data: E621IqdbCandidate[] | null;
visual_matches:
/** Only present on the detail endpoint. */
custom_tags?: string[];
/** Only present on the detail endpoint. */
custom_notes?: string;
/** Only present on the detail endpoint. */
iqdb_data?: E621IqdbCandidate[] | null;
/** Only present on the detail endpoint. */
visual_matches?:
| {
j_id: string;
filename: string;
@@ -371,10 +376,33 @@ export interface TempUpload {
library_j_id: string | null;
file_url: string | null;
preview_url: string | null;
/** Background pipeline state (see the UploadRun status endpoint). */
pipeline_error: string;
attempts: number;
md5_checked?: boolean;
visual_checked?: boolean;
iqdb_checked?: boolean;
processing?: boolean;
similar_count?: number;
created_at: string;
updated_at: string;
}
/** Progress of the server-side staged-upload pipeline. */
export interface UploadStatus {
status: "idle" | "running" | "paused" | "error";
active: boolean;
phase: "" | "md5" | "visual" | "iqdb";
total: number;
processed: number;
matched: number;
failed: number;
error: string;
outstanding: number;
waiting: { md5: number; visual: number; iqdb: number };
updated_at: string | null;
}
export interface StatJob {
kind: "download" | "match";
id: string;
+30
View File
@@ -0,0 +1,30 @@
import { useQuery } from "@tanstack/react-query";
import { api } from "@/lib/api";
import { hasBackend } from "@/lib/backend";
import type { UploadStatus } from "@/lib/types";
import { useAuth } from "@/store/auth";
export const uploadStatusQueryKey = ["upload-status"] as const;
/**
* Poll the server-side upload pipeline while it has work and stop once it is
* idle. Shared by the Upload page and the shell indicator so both show the
* same state without extra requests.
*/
export function useUploadStatus(enabled = true) {
const user = useAuth((state) => state.user);
return useQuery({
queryKey: uploadStatusQueryKey,
queryFn: () => api<UploadStatus>("/api/uploads/status/"),
enabled: enabled && hasBackend() && Boolean(user?.can_upload),
// TanStack takes the smallest interval across the observers, so the
// Upload page and the shell pill can safely share this query.
refetchInterval: (query) => (query.state.data?.active ? 2_000 : false),
});
}
/** Ask the server to (re)start processing the caller's staged uploads. */
export function postProcessUploads(): Promise<UploadStatus> {
return api<UploadStatus>("/api/uploads/process/", { method: "POST" });
}