import { HttpError } from '../services/HttpService'; /** Why the server keeps a stored file closed until its malware scan clears it. */ export type ScanHold = 'held' | 'blocked' | 'unscannable'; /** The scan state a refusal carries, or undefined when the refusal is about something else. */ export const scanHoldOf = (error: unknown): ScanHold | undefined => { if (!(error instanceof HttpError) || error.status !== 409) return undefined; const document = (error.body as { document?: unknown } | null | undefined)?.document; return document === 'held' || document === 'blocked' || document === 'unscannable' ? document : undefined; }; /** Said in place of a file that will not open yet, or at all. */ export const SCAN_HOLD_WORDS: Record = { held: 'This file is still being checked for viruses. Try again in a minute.', blocked: 'This file failed its virus check, so it stays closed.', unscannable: 'This file could not be checked for viruses, so it stays closed.', }; /** Said in place of a file that was put inside a record before files were checked, so it is never opened. */ export const PRE_SCAN_FILE_WORDS = 'This file was sent before files were checked for viruses, so it stays closed. Ask for it to be sent again.'; /** Said when a submission cannot be attached because one of its files will not open. */ export const SUBMISSION_SCAN_HOLD_WORDS: Record = { held: 'A file on this submission is still being checked for viruses. Try again in a minute. Nothing was written to the record.', blocked: 'A file on this submission failed its virus check, so the submission cannot be attached. Nothing was written to the record.', unscannable: 'A file on this submission could not be checked for viruses, so the submission cannot be attached. Nothing was written to the record.', };