diff --git a/src/lib/AddFile.svelte b/src/lib/AddFile.svelte index 5ba780b3..bdd7851b 100644 --- a/src/lib/AddFile.svelte +++ b/src/lib/AddFile.svelte @@ -11,9 +11,13 @@ const dispatch = createEventDispatcher<{ 'shc-retrieved': SHCRetrieveEvent }>(); let submitting = false; let summaryUrl = EXAMPLE_IPS; + let uploadFiles: FileList | undefined; + let inputUrl: HTMLFormElement; let label = 'SHL from ' + new Date().toISOString().slice(0, 10); + let expiration: number | null; + let summaryUrlValidated: URL | undefined = undefined; $: { try { @@ -23,11 +27,20 @@ } } - async function fetchIps(url?: URL) { + async function fetchIps() { submitting = true; try { - const contentResponse = await fetch(url!, { headers: { accept: 'application/fhir+json' } }); - const content: any = await contentResponse.json(); + let content; + + if (uploadFiles?.[0] instanceof File) { + content = JSON.parse(new TextDecoder().decode(await uploadFiles[0].arrayBuffer())); + } else { + const contentResponse = await fetch(summaryUrlValidated!, { + headers: { accept: 'application/fhir+json' } + }); + content = await contentResponse.json(); + } + if (content.verifiableCredential) { return dispatch('shc-retrieved', { shc: content, @@ -42,7 +55,8 @@ verifiableCredential: [shc] }, content, - label + label, + exp: expiration ? new Date().getTime() / 1000 + expiration : undefined }); } catch (e) { console.log('Failed', e); @@ -66,6 +80,7 @@ } }) ); + const signed = new jose.CompactSign(body) .setProtectedHeader(fields) .sign(await exampleSigningKey); @@ -73,19 +88,30 @@ } -