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

fix(synologyDownloadStation) 修正DSM版本大于7.1.1无法使用DownloadStations #1340

Merged
merged 5 commits into from
Feb 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions resource/clients/synologyDownloadStation/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
init(options) {
this.options = options;
this.sessionId = "";
this.synoToken = "";
if (this.options.address.substr(-1) == "/") {
this.options.address = this.options.address.substr(0, this.options.address.length - 1);
}
Expand All @@ -18,7 +19,7 @@
*/
getSessionId() {
return new Promise((resolve, reject) => {
let url = `${this.options.address}/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=login&account=${encodeURIComponent(this.options.loginName)}&passwd=${encodeURIComponent(this.options.loginPwd)}&session=DownloadStation&format=sid`;
let url = `${this.options.address}/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=login&account=${encodeURIComponent(this.options.loginName)}&passwd=${encodeURIComponent(this.options.loginPwd)}&session=DownloadStation&format=sid&enable_syno_token=yes`;
$.ajax({
url,
timeout: PTBackgroundService.options.connectClientTimeout,
Expand All @@ -27,6 +28,7 @@
console.log(result)
if (result && result.success) {
this.sessionId = result.data.sid;
this.synoToken = result.data.synotoken
resolve(this.sessionId)
} else {
reject({
Expand Down Expand Up @@ -111,6 +113,10 @@
_sid: this.sessionId // fxxk, _sid 参数不能放在第一位,不然会直接 101 报错
}

let headers = {
'X-SYNO-TOKEN': this.synoToken
}

// fxxk, 没有 destination 参数也会直接报错
let savePath = (options.savePath || "") + "";
if (savePath.substr(-1) === "/") { // 去除路径最后的 / ,以确保可以正常添加目录信息
Expand Down Expand Up @@ -146,7 +152,7 @@
.then((result) => {
formData.append("torrent", result, "file.torrent")

this.addTorrent(formData, options, callback);
this.addTorrent(formData, headers, options, callback);
})
.catch((result) => {
callback && callback(result);
Expand All @@ -155,9 +161,10 @@
}
}

addTorrent(formData, options, callback) {
addTorrent(formData, headers, options, callback) {
$.ajax({
url: `${this.options.address}/webapi/entry.cgi`,
headers,
timeout: PTBackgroundService.options.connectClientTimeout,
type: "POST",
processData: false,
Expand Down