diff --git a/src/handlers/api/import-jobs.handler.ts b/src/handlers/api/import-jobs.handler.ts index bff95d9..f2c2690 100644 --- a/src/handlers/api/import-jobs.handler.ts +++ b/src/handlers/api/import-jobs.handler.ts @@ -13,6 +13,26 @@ export const createImportJob = async (params: CreateImportJobParams): Promise<{ return API.post(IMPORT_JOBS_PATH, params); }; -export const getImportJob = async (jobId: string) => { +export interface ImportJobStatus { + job: { + id: string; + status: string; + platform: string; + totalCount: number; + uploadedCount: number; + skippedCount: number; + failedCount: number; + importData: string; + }; + items: { + id: string; + assetId: string; + status: string; + immichId: string | null; + error: string | null; + }[]; +} + +export const getImportJob = async (jobId: string): Promise => { return API.get(IMPORT_JOB_PATH(jobId)); }; diff --git a/src/pages/api/import-jobs/index.ts b/src/pages/api/import-jobs/index.ts index 3638dfa..10084bf 100644 --- a/src/pages/api/import-jobs/index.ts +++ b/src/pages/api/import-jobs/index.ts @@ -20,6 +20,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) return res.status(400).json({ error: "platform, url, and assets are required" }); } + if (assets.some((a: unknown) => typeof (a as any).id !== "string")) { + return res.status(400).json({ error: "Each asset must have a string id" }); + } + const [job] = await appDb .insert(importJobs) .values({ diff --git a/src/workers/import/runner.ts b/src/workers/import/runner.ts index eaa1d52..3cd9a98 100644 --- a/src/workers/import/runner.ts +++ b/src/workers/import/runner.ts @@ -21,6 +21,10 @@ export async function getJobItems(jobId: string) { } export async function resumePendingJobs() { + // Reset jobs that were mid-flight when the server last crashed. + // We cannot restart workers here — no auth headers are available at boot. + // Workers restart automatically when the polling endpoint (GET /api/import-jobs/[jobId]) + // detects a pending job with no active worker. await appDb .update(importJobs) .set({ status: "pending" })