Skip to content

Commit

Permalink
Merge pull request #2776 from mitre/export-sources
Browse files Browse the repository at this point in the history
Add capability to download fact sources from sources page
  • Loading branch information
elegantmoose committed Jun 23, 2023
2 parents f2ddfa5 + e807f04 commit 6507725
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions templates/sources.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ <h2>Fact Sources</h2>
<span class="icon"><em class="fas fa-copy"></em></span>
<span>Duplicate Source</span>
</button>
<button class="button is-primary is-small mb-2" @click="downloadSource()"
x-bind:disabled="!selectedSourceId">
<span class="icon"><em class="fas fa-arrow-down"></em></span>
<span>Download Source</span>
</button>
<div class="hr"></div>
<button class="button is-small mb-2 is-danger is-outlined"
@click="openModal = { isOpen: true, name: 'Delete Source' }">
Expand Down Expand Up @@ -1260,6 +1265,22 @@ <h2>Fact Sources</h2>
});
},

downloadSource() {
apiV2('GET', `/api/v2/sources/${this.selectedSourceId}`)
.then((res) => {
const dataURL = `data:text/json;charset=utf-8,${encodeURIComponent(JSON.stringify(res, null, 2))}`
const fileName = `${this.selectedSource.name}.json`
const elem = document.createElement('a');
elem.setAttribute('href', dataURL);
elem.setAttribute('download', fileName);
elem.click();
elem.remove();
}).catch((error) => {
toast('Error downloading source');
console.error(error)
});
},

resetSearch() {
this.abilitySearch = {
query: '',
Expand Down

0 comments on commit 6507725

Please sign in to comment.