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

Directory sharing via link with one click #1287

Open
lyd405121 opened this issue Apr 24, 2024 · 1 comment
Open

Directory sharing via link with one click #1287

lyd405121 opened this issue Apr 24, 2024 · 1 comment

Comments

@lyd405121
Copy link

Is your feature request related to a problem? Please describe.

  • When using Directory sharing via link

  • I need a button to download them all
    solution

  • It will enhanceuser's user experience

Describe the solution you'd like

Directory sharing with web link mode

  • When sharing a directoty with 1000 files using web link mode
    sharelink

  • I have to click one by one to download
    onebyone

  • It is better to have a button to download them all

Describe alternatives you've considered

No response

Additional context

No response

@lyd405121
Copy link
Author

Try to add this feature

  • But Failed TAT
  • Only few files downloaded successfully!

ss

async function download_one(fileurl, file_name) {

    console.log("downloading " + file_name);

    fetch(fileurl).then((res) =>
    res.blob().then((blob) => {  
       var a = document.createElement('a');
       var url = window.URL.createObjectURL(blob);
       a.href = url;
       a.download = file_name; // 下载名称
       a.click();
       window.URL.revokeObjectURL(url);
     })
    );
}

async function download_all() {

  document.getElementById('status-text').innerText = i18n.waiting;
  const response = await fetch(
    `${BASE_URL}/prepare-download?sessionId=${sessionId}`,
    {
      method: 'POST',
    },
  );

  if (response.status === 403) {
    document.getElementById('status-text').innerText = i18n.rejected;
    return;
  } else if (response.status !== 200) {
    document.getElementById('status-text').innerText = `Error: ${response.status}`;
    return;
  }

  const data = await response.json();
  const files = data.files;
  sessionId = data.sessionId;
  sessionStorage.setItem('sessionId', sessionId);
  //ui
  var button = document.createElement("button");
  button.type = "button";
  button.textContent = "download all";

  
  button.onclick = function() {
    file_num = Object.keys(files).length;
    console.log("file number:" + file_num);
    for (let i = 0; i < file_num; i++) 
    {
      const file = files[Object.keys(files)[i]];
      const index = file.fileName.lastIndexOf("/");
      var file_name = file.fileName.substring(index+1, file.fileName.length);
      var file_dir  = file.fileName.substring(0, index+1);
      const fileurl = "api/localsend/v2/download?" + "sessionId=" + sessionId + "&fileId=" + file.id;
      download_one(fileurl, file_name);
    }
} ;

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

1 participant