-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include preview.png in zip download #55
Include preview.png in zip download #55
Conversation
@fulopkovacs is attempting to deploy a commit to the polyhaven Team on Vercel. A member of the Team first needs to authorize it. |
@gregzaal : this PR needs an intervention from you. Right now the CORS-headers of the preview images are not configured to allow requests from
Could you fix the CORS-headers? Or is there a reason why As always, sorry for the inconvenience, and take your time with the answer, it's not urgent. |
I've added the CORS headers to all image files on cdn.polyhaven.com. There might be some stale caches around so let me know if there are any issues. It would be better to use the thumbnail images instead of the preview, which would be The |
/> | ||
// TODO: should we make it possible to download the bundle | ||
// without the preview in it? | ||
m !== 'preview' ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this addition does - making the change here locally doesn't seem to do anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this error if I remove this condition:
The value of the data
attribute of DownloadMap
in this case is undefined
, because it's supposed to be files[m][res]
(see here), but files["preview"]
has only these keys: "url"
, "path"
, "size"
, no resolutions.
if (files.preview) dlFiles.push({ | ||
url: files.preview, | ||
path: `${assetID}_preview.png` | ||
// TODO: is the size of this image stored in the db? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's not. I believe it might be necessary to have the final bundle size known before downloading so this might be a roadblock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so it's gonna be a tough one. For now, I hardcoded 0
for the size of the preview images, which is obviously a lie, but it's good for testing.
From what I see we have two problems here:
- we need to get the file sizes of all the thumbnail images
- we need to get that data into Firebase (if that's what you're still using)
For issue 1 I can use https://api.polyhaven.com/assets
to get the list of all the assets, and then write a bash script that downloads them and uses exiftool
to get their sizes. I can save this data to a csv
/json
.
As for issue 2, I don't have experience specifically with Firebase, but I believe we can write another script (that relies on firebase-tools
(https://www.npmjs.com/package/firebase-tools)) to save the data in the db. This second script would have to run on your computer, because I have no access to Firebase. If you're using windows, then we might have to use Node.js instead of bash for this second script.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I realized that there's another, bit hacky way to solve this problem: https://github.com/Poly-Haven/polyhaven.com/pull/55/files#r1018417712. I don't recommend it, but we could use it if we don't have another option.
Okay, the CORS-headers seem to be fixed. The thumbnail images were included in the zip files in all my tests, so the only problem that we have now is that we don't know the size of the preview images (right now we lie about it, and say that it's |
components/AssetPage/AssetPage.tsx
Outdated
// Set preview image size | ||
fetch(`https://cdn.polyhaven.com/asset_img/thumbs/${assetID}.png?format=png`).then( | ||
res => res.blob() | ||
).then((res) => { | ||
setPreviewImageSize(res.size) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I came up with this hacky way of getting the size of the preview images in the browser. I'd much rather fetch this data from the db, but I thought I should present this idea too.
Somewhat related, I noticed something strange: the size of the blob is the same as the size of the image if I download it manually (with wget
), but the displayed size of the zip file is less than the size of the downloaded zip (8.2MB
vs 7.78MB
). A similar difference is present when I view the same file on the website (https://polyhaven.com/a/wood_cabinet_worn_long) too: 6.69MB
vs 7.00MB
. Maybe we don't add the size of a file to the sum that we display?
OK I think we can kill a few birds with one stone if we store the thumbnail images on our download server (where assets live, dl.polyhaven.org) as well as on the image server (cdn.polyhaven.com) and include those files in the database like the rest of them. This way we solve Poly-Haven/Public-API#8, #57, and #14 (this issue) with known file size and no jank with bunny.net's webp conversion. To actually achieve this requires some changes on our backend for future assets. and a script to retroactively upload existing asset thumbs, which is not something you can help with :( nor do I really know when I can make time for it. Thanks for attempting this but it looks like it's not solvable in a nice way right now. |
9035818
to
0b65ea7
Compare
That's okay, I'll pick up something else. I don't think we'll ever use the last commit (that calculates the size of the image in the browser), so I removed it. You can close this PR If you want, we can always reference it in the future. |
Notes
preview.png
file is the image that we fetch fromhttps://cdn.polyhaven.com/asset_img/primary/${assetID}.png