Skip to content
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

Download as zip #907

Open
a-camacho opened this issue Nov 3, 2022 · 9 comments
Open

Download as zip #907

a-camacho opened this issue Nov 3, 2022 · 9 comments

Comments

@a-camacho
Copy link

Hello guys,

Your product is incredible, and it works differently to others what is very useful : when uploading various files, you can get a single link for all those files.

Is there any plan to get the feature "download as .zip" back ?

That would be the last thing missing for me, to make it perfect.

Thanks a lot !

@eikek
Copy link
Owner

eikek commented Nov 3, 2022

Yes the zip download is missing (issue is #48) - the reason is that it is not trivial to add given that sharry wants to support large files. I want it then to create the zip file in the background and possibly cache for some time since it may be an expensive operation. I would really like to add it, but unfortunately time is a bit tight this year.

@louwers
Copy link

louwers commented Mar 4, 2023

Someone wrote a script to extract the files from the chunks: https://www.codeslikeaduck.com/posts/sharryfilerebuilder/

Downside is that the filenames are gone.

I was hoping the 'filesystem' store would just store uploaded files as files.

Edit: just found the discussion over at #1006

@hugosxm
Copy link

hugosxm commented Nov 14, 2023

I was hoping for a "download all" feature but i assume it is kind of the same than this one ?

@eikek
Copy link
Owner

eikek commented Nov 15, 2023

I was hoping for a "download all" feature but i assume it is kind of the same than this one ?

Correct :) it's currently missing. But you can download all files to a share using some script, which is not much effort. I can dig out such a script if you want. It would involve a curl to the share to get the list of files and then downloading each.

@hugosxm
Copy link

hugosxm commented Nov 15, 2023

Thanks for you answer, I plan to use this product with "regular users", the kind of person that are afraid of a black window lauching text commands ^^. This is why I'm looking for a graphical button that does everything ^^ !

@alexmaret
Copy link

I also would love to see this feature.

@albertbern
Copy link

My users also would love to see "download as .zip"

@Jeroen-45
Copy link

Jeroen-45 commented Dec 16, 2024

Since I was also really missing a "Download all" function to this otherwise perfect application for my needs, I decided to try and implement a solution myself. However, I quickly found out that elm is too confusing for me and would take me too much time to learn, so I went for a 'dirty/hacky' workaround instead, which I'm sharing here in case it's of use to anyone else:

<style>
    /* Title right padding to make space for download all button */
    h1 {
        padding-right: 60px;
    }

    @media (min-width: 640px) {
        h1 {
            padding-right: 160px;
        }
    }
</style>

<script>
    function placeDownloadButton() {
        // Remove existing button
        preexisting_button_div_el = document.getElementById('download-all-div')
        if (preexisting_button_div_el) {
            preexisting_button_div_el.remove()
        }

        // Check if we are on a download page
        if (!window.location.href.includes('/app/open/') && !window.location.href.includes('/app/upload/')) {
            return
        }

        // Create download all button
        const button_div_el = document.createElement('div')
        button_div_el.id = 'download-all-div'
        button_div_el.className = "container px-2 py-3"
        button_div_el.setAttribute("style", "position: absolute; top: 60px; left: 50%; transform: translateX(-50%); text-align: end;")

        const button_el = document.createElement('a')
        button_el.id = 'download-all-button'
        button_el.className = 'rounded border px-4 py-2 my-auto whitespace-nowrap border-gray-500 dark:border-stone-500 text-gray-500 ' +
            'dark:text-stone-400 text-center shadow-none focus:outline-none focus:ring focus:ring-opacity-75 ' +
            'hover:bg-gray-600 hover:text-white dark:hover:text-white dark:hover:bg-stone-500 dark:hover:text-stone-100'
        button_el.innerHTML = '<i class="fa fa-download"></i><span class="ml-2 hidden sm:inline">Download all</span>'
        button_el.setAttribute("style", "cursor: pointer;")

        button_div_el.appendChild(button_el)
        document.body.appendChild(button_div_el)

        document.getElementById("download-all-button").addEventListener("click", downloadAll)
    }


    function downloadAll() {
        // Click all download urls on page
        a_elems = document.querySelectorAll("td > a, .inline > a")
        for (const a_elem of a_elems) {
            if (!a_elem.getAttribute("href").includes('/api/')) {
                continue
            }
            a_elem.click()
        }
    }

    // Run button place once, then watch for window href changes
    const observeUrlChange = () => {
        let oldHref = document.location.href
        const body = document.querySelector('body')
        const observer = new MutationObserver(mutations => {
            if (oldHref !== document.location.href) {
                oldHref = document.location.href
                placeDownloadButton()
            }
        });
        observer.observe(body, { childList: true, subtree: true })
    };

    window.onload = () => {
        placeDownloadButton()
        observeUrlChange()
    }
</script>

Adding this html in a file and setting that file as webapp.custom-head in the Sharry config adds a "Download all" button to the private and public share viewing pages, which will simply cause every download link on the page to be clicked. This could be further expanded to also zip the files client-side, but just being able to download everything at once is already good enough for me. If anyone manages to get client-side zipping working, please tag me.

image

I hope this workaround is useful for others!

Finally, I think it goes without saying, but use at your own risk, things might break with future updates of Sharry or I might have made mistakes. This script has been working fine for me, but YMMV.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@eikek
Copy link
Owner

eikek commented Dec 17, 2024

hello @Jeroen-45 that is really nice! Thank you! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants