fix: add asset id validation, type getImportJob, document resumePendingJobs limitation
This commit is contained in:
@@ -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));
|
||||
};
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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" })
|
||||
|
||||
Reference in New Issue
Block a user