Skip to content

Commit

Permalink
refactor: update JSON validation
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRohlf committed Oct 7, 2024
1 parent 0ed7eb3 commit b606a9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/@utils/downloadJSON.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function isValidJSON(json: any): boolean {
export function isValidJSON(json: string): boolean {
try {
JSON.parse(json)
return true
Expand All @@ -8,11 +8,11 @@ export function isValidJSON(json: any): boolean {
}

// Download JSON file
export function downloadJSON(json: any, filename: string): void {
export function downloadJSON(json: string, filename: string): void {
// check if the json is valid
if (isValidJSON(JSON.stringify(json))) {
if (isValidJSON(json)) {
const element = document.createElement('a') // create an <a> tag
const file = new Blob([JSON.stringify(json)], {
const file = new Blob([json], {
type: 'application/json'
}) // create a file
element.href = URL.createObjectURL(file) // create a URL for the file
Expand Down
4 changes: 3 additions & 1 deletion src/components/@shared/DDODownloadButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export default function DDODownloadButton({
}): ReactElement {
return (
<Button
onClick={() => downloadJSON(asset, `${asset.metadata.name}_metadata`)}
onClick={() =>
downloadJSON(JSON.stringify(asset), `${asset.metadata.name}_metadata`)
}
size="small"
>
Download DDO
Expand Down

0 comments on commit b606a9c

Please sign in to comment.