fix: add asset id validation, type getImportJob, document resumePendingJobs limitation

This commit is contained in:
Varun
2026-04-03 20:19:20 +05:30
parent 93a4cabb01
commit ae9fd45f0a
3 changed files with 29 additions and 1 deletions
+21 -1
View File
@@ -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<ImportJobStatus> => {
return API.get(IMPORT_JOB_PATH(jobId));
};
+4
View File
@@ -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({
+4
View File
@@ -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" })