commit melhorias1
This commit is contained in:
@@ -14,3 +14,12 @@ export const fiscalMapDownload=args=>verifiedCsvDownload({...args,pathForId:id=>
|
||||
export const remunerationDownload=args=>verifiedCsvDownload({...args,pathForId:id=>'/api/remunerations/exports/'+id});
|
||||
|
||||
export const personnelDownload=args=>verifiedCsvDownload({...args,pathForId:id=>'/api/hr-personnel/exports/'+id});
|
||||
/** Readable view is derived; the original artifact SHA and render format are checked separately. */
|
||||
export async function personnelReadableDownload({id,token,sourceSha256,isCurrent,fetcher=fetch}){
|
||||
if(!Number.isSafeInteger(Number(id))||Number(id)<1||!token||!/^[a-f0-9]{64}$/.test(sourceSha256))throw Error('Versão ou fonte indisponível. Consulte novamente.');
|
||||
const check=()=>{if(!isCurrent())throw Error('O contexto mudou. O resumo anterior foi ignorado.');};check();
|
||||
const r=await fetcher('/api/hr-personnel/readable/'+Number(id),{credentials:'same-origin',headers:{Accept:'text/csv','X-SGF-Context':token}});check();
|
||||
if(!r.ok){const problem=await r.json().catch(()=>({})),e=Error(problem.message||'Não foi possível consultar o resumo desta versão.');e.status=r.status;throw e;}
|
||||
const expected=r.headers.get('x-content-sha256');if(!/^text\/csv(?:;|$)/i.test(r.headers.get('content-type')??'')||r.headers.get('x-source-sha256')!==sourceSha256||r.headers.get('x-sgf-read-format')!=='SGF-HR-READABLE-CSV-v1'||!/^[a-f0-9]{64}$/.test(expected??''))throw Error('O resumo não corresponde à versão conservada.');
|
||||
const bytes=await r.arrayBuffer();check();const digest=await crypto.subtle.digest('SHA-256',bytes);check();const actual=[...new Uint8Array(digest)].map(v=>v.toString(16).padStart(2,'0')).join('');if(actual!==expected)throw Error('O resumo não confere com o SHA da resposta.');return{bytes,sha256:actual,sourceSha256};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user