playcanvas / editor

Issue tracker for the PlayCanvas Editor
https://playcanvas.com/
161 stars 28 forks source link

Download multiple files from the Editor #19

Open mvaligursky opened 4 years ago

mvaligursky commented 4 years ago

If I select multiple files in Editor's Library, right click and do Download, only one file gets downloaded. Ideally all of them get downloaded (in zip?).

willeastcott commented 4 years ago

So this isn't super simple. Some asset types have a download option, some don't. Some download a single file (textures), some download multiple files in zips (models). Needs a bit of thought, but in principle, yeah, I agree with you. I've literally done a multi-select in the asset panel before and expected to be able to download all. Actually, in my case, I just wanted multiple separate downloads to kick off.

Mentos- commented 4 years ago

The lack of a way to download multiple files is at the top of my wish list for the editor so here is my first pass at implementing it.

Select a bunch of assets in your Playcanvas project, copy/paste the downloadSelected.txt code into your dev console and then call the 'downloadSelected()' function in the console.

If the number of selected files is <= 10 then each file is downloaded individually with a 1 second sleep between each attempt to throttle the list, otherwise the blobs for each file are downloaded using fetch(url) and when all are downloaded they are saved to a zip using the JSZip and FileSaver libraries which are pasted in with the attached code.

I am still learning the PCUI framework so I could use some help aligning the text in the list so that there isn't so much space between the checkbox and file name as well as the footer at the bottom. A stretch goal would be to include asset icons and types.

downloadSelectedFiles

I found an odd issue where using fetch(url) would sometimes give a "net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)" error and the resulting blob was empty. Oddly this does not trigger an error so I found a workaround where I check if the blob.size is valid which throws an undefined error I can catch and retry the download (right now the allowance is for 5 consecutive retries in practice only 2 have been necessary from my testing).

I think with a little more polish this download method could be integrated into the official editor code?

Let me know what you guys think! Happy to make any changes feel free to tear my code apart, I spent the last 6 years in UE4 C++ so my Javascript is rusty!

mvaligursky commented 4 years ago

Just some relevant comments here for current / soon to be released options to do something similar - which might be all is needed for many specific uses:

adding @vkalpias for visibility.

LeXXik commented 1 year ago

Bumping! Was about to write one. Please, allow to download multiple selected assets or a folder. Probably downloaded as a zip archive.

willeastcott commented 1 year ago

Well, if you do write one, perhaps I can integrate it into the Editor UI codebase. 😄

LeXXik commented 1 year ago

I meant to say I was about to write one issue about it :D

But yeah, Editor needs an ability to create zip files, for example using https://stuk.github.io/jszip/. Not sure we can do it on the client side without it.