Assessor_2.0/server/gpo/gpo-source-availability.ts

19 lines
1.1 KiB
TypeScript

import type { ImportArtifact } from '../../src/domain/ingestion-persistence';
import { ImportError } from '../../src/shared/errors';
import type { BackendArtifactStore } from '../artifacts/backend-artifact-store';
export async function gpoSourceAvailability(artifact: ImportArtifact, store?: BackendArtifactStore) {
if (artifact.storage.kind !== 'backend-controlled') return 'missing' as const;
return store ? store.availability(artifact.storage.storageKey) : 'unavailable' as const;
}
export async function requireGpoSource(artifact: ImportArtifact, store: BackendArtifactStore): Promise<void> {
const availability = await gpoSourceAvailability(artifact, store);
if (availability === 'available') return;
const code = availability === 'missing' ? 'artifact-store-object-missing' : 'artifact-store-read-failed';
const message = availability === 'missing'
? 'Stored GPO source is missing. Upload the unchanged original backup again. Saved results remain available.'
: 'The artifact store cannot be accessed. Check the backend storage connection and permissions.';
throw new ImportError(message, [{ severity: 'error', code, message }]);
}