Skip to content

Commit 0c4ebcc

Browse files
committed
Download files with more descriptive file name.
1 parent 9b0e59f commit 0c4ebcc

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ This generates react queries that you can use in your Components.
4545
#### Production
4646

4747
Make a PR to the `main` branch. Once merged, Vercel will deploy to https://comfyregistry.org
48+
49+
50+
### CORS
51+
52+
To enable CORS on the google cloud storage bucket, reference the `cors.json` file. More info [here](https://cloud.google.com/storage/docs/cross-origin#cors-components).
53+
54+
`gcloud storage buckets update gs://comfy-registry --cors-file=cors.json`

components/nodes/NodeDetails.tsx

+30-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Image from 'next/image'
22
import { useRouter } from 'next/router'
33
import React, { useState } from 'react'
4+
import axios from 'axios'
5+
import download from 'downloadjs'
6+
import fileDownload from 'js-file-download'
47
import { Button, Spinner } from 'flowbite-react'
58
import nodesLogo from '../../public/images/nodesLogo.svg'
69
import NodeVDrawer from './NodeVDrawer'
@@ -40,6 +43,17 @@ export function formatRelativeDate(dateString: string) {
4043
}
4144
}
4245

46+
const downloadFile = async (url: string, filename: string) => {
47+
try {
48+
console.log('downloading file from:', url)
49+
const response = await fetch(url)
50+
const blob = await response.blob()
51+
download(blob, filename, 'application/gzip')
52+
} catch (error) {
53+
console.error('Error downloading file:', error)
54+
}
55+
}
56+
4357
const NodeDetails = () => {
4458
const router = useRouter()
4559
const { publisherId, nodeId } = router.query
@@ -300,15 +314,26 @@ const NodeDetails = () => {
300314
{data.latest_version?.downloadUrl && (
301315
<Button
302316
className="flex-shrink-0 px-4 text-white bg-blue-500 rounded whitespace-nowrap text-[16px]"
303-
onClick={() =>
317+
onClick={(
318+
e: React.MouseEvent<HTMLButtonElement>
319+
) => {
320+
e.preventDefault()
321+
console.log('clicked download')
322+
if (
323+
data &&
324+
data.latest_version?.downloadUrl
325+
) {
326+
downloadFile(
327+
data.latest_version?.downloadUrl,
328+
`${data.name}_${data.latest_version.version}.zip`
329+
)
330+
}
304331
analytic.track(
305332
'Download Latest Node Version'
306333
)
307-
}
334+
}}
308335
>
309-
<Link href={data.latest_version?.downloadUrl}>
310-
Download Latest
311-
</Link>
336+
<a>Download Latest</a>
312337
</Button>
313338
)}
314339
</div>

cors.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"origin": ["*"],
4+
"method": ["GET", "HEAD"],
5+
"responseHeader": ["*"],
6+
"maxAgeSeconds": 3000
7+
}
8+
]

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@next/mdx": "12.3.1",
2222
"@tanstack/react-query": "^5.17.19",
2323
"axios": "^1.6.5",
24+
"downloadjs": "^1.4.7",
2425
"firebase": "^10.11.1",
2526
"flowbite": "^2.3.0",
2627
"flowbite-react": "0.7.5",
@@ -41,6 +42,7 @@
4142
"@babel/core": "7.19.3",
4243
"@mdx-js/react": "2.1.4",
4344
"@types/async-busboy": "^1.1.1",
45+
"@types/downloadjs": "^1.4.6",
4446
"@types/mixpanel-browser": "^2.49.0",
4547
"@types/node": "18.8.3",
4648
"@types/qs": "^6.9.15",

pnpm-lock.yaml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)