feat: add import processor interface and registry
This commit is contained in:
1 parent
619b2e1785
commit
fbcff5f380
2 files changed
+37
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import type { ImportProcessor } from "./types";
|
||||
|
||||
const processors = new Map<string, ImportProcessor>();
|
||||
|
||||
export function registerProcessor(platform: string, processor: ImportProcessor) {
|
||||
processors.set(platform, processor);
|
||||
}
|
||||
|
||||
export function getProcessor(platform: string): ImportProcessor {
|
||||
const processor = processors.get(platform);
|
||||
if (!processor) {
|
||||
throw new Error(`No import processor registered for platform: ${platform}`);
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { importJobs, importJobItems } from "@/db/schema";
|
||||
|
||||
export type ImportJob = typeof importJobs.$inferSelect;
|
||||
export type ImportJobItem = typeof importJobItems.$inferSelect;
|
||||
|
||||
export interface ProcessorContext {
|
||||
headers: Record<string, string>; // user auth headers for Immich API calls
|
||||
albumId?: string; // resolved after setup()
|
||||
}
|
||||
|
||||
export interface SetupResult {
|
||||
skipAssetIds: string[]; // source asset IDs already in Immich → mark skipped
|
||||
albumId?: string; // created or resolved album ID
|
||||
importDataPatch?: Record<string, unknown>; // merged into job.importData in db
|
||||
}
|
||||
|
||||
export interface ImportProcessor {
|
||||
/** Called once per job before items are processed. Dedup + album creation. */
|
||||
setup(job: ImportJob, context: ProcessorContext): Promise<SetupResult>;
|
||||
/** Called once per item. Returns the Immich asset ID on success, throws on failure. */
|
||||
processItem(job: ImportJob, item: ImportJobItem, context: ProcessorContext): Promise<{ immichId: string }>;
|
||||
}
|
||||
Reference in new issue
Block a user