-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Junk
committed
Oct 2, 2023
1 parent
a2d1d6e
commit 4a4233d
Showing
4 changed files
with
89 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!-- | ||
This file is Free Software under the MIT License | ||
without warranty, see README.md and LICENSES/MIT.txt for details. | ||
SPDX-License-Identifier: MIT | ||
SPDX-FileCopyrightText: 2023 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de> | ||
Software-Engineering: 2023 Intevation GmbH <https://intevation.de | ||
--> | ||
|
||
<script lang="ts"> | ||
import { appStore } from "$lib/store"; | ||
import { loadSingleCSAF } from "$lib/urlloader"; | ||
let URL = ""; | ||
const load = () => { | ||
window.location.hash = `#/single?q=${URL}`; | ||
loadSingleCSAF(URL); | ||
}; | ||
const keydown = (e: KeyboardEvent) => { | ||
if (e.key === "Enter") { | ||
load(); | ||
} | ||
}; | ||
</script> | ||
|
||
<div class="row"> | ||
<div class="col"> | ||
<div style="display:flex"> | ||
<button class="loadbutton" on:click={load}><i class="bx bx-book-open" />URL</button> | ||
<input class="url" type="text" bind:value={URL} on:keydown={keydown} /> | ||
</div> | ||
</div> | ||
</div> | ||
{#if $appStore.ui.errorMsg} | ||
<div class="row"> | ||
<div class="col"><div class="errors text-error">{$appStore.ui.errorMsg}</div></div> | ||
</div> | ||
{/if} | ||
|
||
<style> | ||
.errors { | ||
margin-left: 200px; | ||
font-size: x-large; | ||
font-weight: bold; | ||
} | ||
.loadbutton { | ||
width: 200px; | ||
height: 50px; | ||
font-size: large; | ||
} | ||
.bx-book-open { | ||
margin-right: 1rem; | ||
} | ||
.url { | ||
margin-left: 1rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { appStore } from "$lib/store"; | ||
import { convertToDocModel } from "$lib/singleview/docmodel/docmodel"; | ||
|
||
async function loadSingleCSAF(url: string) { | ||
appStore.setErrorMsg(""); | ||
appStore.reset(); | ||
try { | ||
const response = await fetch(`${url}`); | ||
if (response.ok) { | ||
const csafDoc = await response.json(); | ||
appStore.clearUploadedFile(); | ||
const docModel = convertToDocModel(csafDoc); | ||
appStore.setDocument(docModel); | ||
} | ||
if (response.status === 404) { | ||
appStore.setErrorMsg("The resource you requested was not found on the server."); | ||
} | ||
} catch (error) { | ||
appStore.setErrorMsg( | ||
"Failed to load from URL. The server may be unreachable or the resource cannot be accessed due to CORS restrictions." | ||
); | ||
} | ||
} | ||
|
||
export { loadSingleCSAF }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters