qbittorrent / qBittorrent

qBittorrent BitTorrent client
https://www.qbittorrent.org
Other
28.36k stars 3.99k forks source link

SequentailDownload: true and toggleSequentialDownload not working #21054

Open alexyProjet opened 4 months ago

alexyProjet commented 4 months ago

qBittorrent & operating system versions

qBitorrent version : 4.6.4 Qbitorrent API : 2.9.3 Operating system : Disk Station manager 7.2.1 running inside docker on a synology NAS

What is the problem?

I wrote some code to add torrent using the api in a nuxt3 project. Torrent is added with success, but even I set the sequentialDownload flag to "true", it stays at "false"

    const uploadResponse = await axios.post(`${qbittorrentNasIp}/api/v2/torrents/add`, torrentFormData, {
      headers: {
        ...torrentFormData.getHeaders(),
        Cookie: cookies.join("; "), // Include cookies in the request
      },
      params: {
        savepath: "/downloads",
        skip_checking: "true",
        root_folder: "true",
        upLimit: "0",
        sequentialDownload: "true",
        firstLastPiecePrio: "true",
      },
    });

I also tried using the toggleSequentialDownload via POST

const formData = new FormData();
    formData.append("hashes", "all");

    const response = await axios.post(`${qbittorrentNasIp}/api/v2/torrents/toggleSequentialDownload`, formData, {
      headers: {
        "Content-Type": "multipart/form-data",
        Cookie: cookies.join("; "),
      },
    });

but same result, even if I got a 200, the sequential download stay to false no matter how many time I change the toggle.

However if I change it using the WEB UI interface, it works

Log(s) & preferences file(s)

There is no log

glassez commented 4 months ago

It should be of type Boolean, not String:

// sequentialDownload: "true", // incorrect!
sequentialDownload: true,
alexyProjet commented 4 months ago

Thank you for your reply, but the doc say the following : sequentialDownload optional string Enable sequential download. Possible values are true, false (default)

I also tested with a bool, this is still the same

glassez commented 4 months ago

I'm sorry, I can't help you any more. I have no idea what this nuxt3 is, and how I could reproduce it to see under the debugger what exactly is happening in qBittorrent.

alexyProjet commented 4 months ago

Nuxt 3 is simply a web development framework built on Vue.js, vue3 in this case For anyone who wants to reproduce here is the main code :)

login cookie

const formData = new URLSearchParams();
  formData.append("username", username);
  formData.append("password", password);

  const loginResponse = await axios.post(`${qbittorrentNasIp}/api/v2/auth/login`, formData, {
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      Referer: qbittorrentNasIp,
    },
  });

  if (loginResponse.data !== "Ok.") {
    throw new Error("Login failed");
  }

  return loginResponse.headers["set-cookie"];

and then a function to call the API to uplaod the torrent and set the sequentialdownload flag

    const torrentFormData = new FormData();
    torrentFormData.append("torrents", torrentData, {
      filename: "upload.torrent",
      contentType: "application/x-bittorrent",
    });

    const uploadResponse = await axios.post(`${qbittorrentNasIp}/api/v2/torrents/add`, torrentFormData, {
      headers: {
        ...torrentFormData.getHeaders(),
        Cookie: cookies.join("; "), // Include cookies in the request
      },
      params: {
        savepath: "/downloads",
        skip_checking: "true",
        root_folder: "true",
        upLimit: "0",
        sequentialDownload: true,
        firstLastPiecePrio: "true",
      },
    });

    console.log("Torrent uploaded successfully");
for the toggle sequentialdownload flag, here is the code : 
// Créez un objet FormData
    const formData = new FormData();
    formData.append("hashes", "all");

    const response = await axios.post(`${qbittorrentNasIp}/api/v2/torrents/toggleSequentialDownload`, formData, {
      headers: {
        "Content-Type": "multipart/form-data",
        Cookie: cookies.join("; "),
      },
    });

    return {
      success: response.status === 200,
    };