fix: trailing slash integration url issues (#1571)

This commit is contained in:
Meier Lukas
2024-11-30 10:54:50 +01:00
committed by GitHub
parent d5f76218cd
commit b277f444b2
19 changed files with 126 additions and 129 deletions

View File

@@ -89,9 +89,8 @@ export class DelugeIntegration extends DownloadClientIntegration {
}
private getClient() {
const baseUrl = new URL(this.integration.url).href;
return new Deluge({
baseUrl,
baseUrl: this.url("/").toString(),
password: this.getSecretValue("password"),
});
}

View File

@@ -92,9 +92,9 @@ export class NzbGetIntegration extends DownloadClientIntegration {
method: CallType,
...params: Parameters<NzbGetClient[CallType]>
): Promise<ReturnType<NzbGetClient[CallType]>> {
const url = new URL(this.integration.url);
url.pathname += `${this.getSecretValue("username")}:${this.getSecretValue("password")}`;
url.pathname += url.pathname.endsWith("/") ? "jsonrpc" : "/jsonrpc";
const username = this.getSecretValue("username");
const password = this.getSecretValue("password");
const url = this.url(`/${username}:${password}/jsonrpc`);
const body = JSON.stringify({ method, params });
return await fetch(url, { method: "POST", body })
.then(async (response) => {

View File

@@ -70,9 +70,8 @@ export class QBitTorrentIntegration extends DownloadClientIntegration {
}
private getClient() {
const baseUrl = new URL(this.integration.url).href;
return new QBittorrent({
baseUrl,
baseUrl: this.url("/").toString(),
username: this.getSecretValue("username"),
password: this.getSecretValue("password"),
});

View File

@@ -12,7 +12,7 @@ dayjs.extend(duration);
export class SabnzbdIntegration extends DownloadClientIntegration {
public async testConnectionAsync(): Promise<void> {
//This is the one call that uses the least amount of data while requiring the api key
await this.sabNzbApiCallAsync("translate", new URLSearchParams({ value: "ping" }));
await this.sabNzbApiCallAsync("translate", { value: "ping" });
}
public async getClientJobsAndStatusAsync(): Promise<DownloadClientJobsAndStatus> {
@@ -75,7 +75,7 @@ export class SabnzbdIntegration extends DownloadClientIntegration {
}
public async pauseItemAsync({ id }: DownloadClientItem) {
await this.sabNzbApiCallAsync("queue", new URLSearchParams({ name: "pause", value: id }));
await this.sabNzbApiCallAsync("queue", { name: "pause", value: id });
}
public async resumeQueueAsync() {
@@ -83,32 +83,29 @@ export class SabnzbdIntegration extends DownloadClientIntegration {
}
public async resumeItemAsync({ id }: DownloadClientItem): Promise<void> {
await this.sabNzbApiCallAsync("queue", new URLSearchParams({ name: "resume", value: id }));
await this.sabNzbApiCallAsync("queue", { name: "resume", value: id });
}
//Delete files prevented on completed files. https://github.com/sabnzbd/sabnzbd/issues/2754
//Works on all other in downloading and post-processing.
//Will stop working as soon as the finished files is moved to completed folder.
public async deleteItemAsync({ id, progress }: DownloadClientItem, fromDisk: boolean): Promise<void> {
await this.sabNzbApiCallAsync(
progress !== 1 ? "queue" : "history",
new URLSearchParams({
name: "delete",
archive: fromDisk ? "0" : "1",
value: id,
del_files: fromDisk ? "1" : "0",
}),
);
await this.sabNzbApiCallAsync(progress !== 1 ? "queue" : "history", {
name: "delete",
archive: fromDisk ? "0" : "1",
value: id,
del_files: fromDisk ? "1" : "0",
});
}
private async sabNzbApiCallAsync(mode: string, searchParams?: URLSearchParams): Promise<unknown> {
const url = new URL("api", this.integration.url);
url.searchParams.append("output", "json");
url.searchParams.append("mode", mode);
searchParams?.forEach((value, key) => {
url.searchParams.append(key, value);
private async sabNzbApiCallAsync(mode: string, searchParams?: Record<string, string>): Promise<unknown> {
const url = this.url("/api", {
...searchParams,
output: "json",
mode,
apikey: this.getSecretValue("apiKey"),
});
url.searchParams.append("apikey", this.getSecretValue("apiKey"));
return await fetch(url)
.then((response) => {
if (!response.ok) {

View File

@@ -71,9 +71,8 @@ export class TransmissionIntegration extends DownloadClientIntegration {
}
private getClient() {
const baseUrl = new URL(this.integration.url).href;
return new Transmission({
baseUrl,
baseUrl: this.url("/").toString(),
username: this.getSecretValue("username"),
password: this.getSecretValue("password"),
});