Skip to content

Commit

Permalink
Merge branch 'master' into fix-deprecated-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Dec 9, 2024
2 parents eb2d1f1 + 454f771 commit ac6b965
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 33 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/publish-rolling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,12 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
395 changes: 394 additions & 1 deletion client/src/javascript/i18n/strings/he.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions server/services/qBittorrent/clientGatewayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
throw new Error();
}

const method = isApiVersionAtLeast(await this.clientRequestManager.apiVersion, '2.11.0') ? 'stopped' : 'paused';
await this.clientRequestManager
.torrentsAddFiles(fileBuffers, {
savepath: destination,
tags: tags.join(','),
[isApiVersionAtLeast(this.clientRequestManager.apiVersion, '2.11.0') ? 'stopped' : 'paused']: !start,
[method]: !start,
root_folder: !isBasePath,
contentLayout: isBasePath ? 'NoSubfolder' : undefined,
sequentialDownload: isSequential,
Expand Down Expand Up @@ -119,11 +120,12 @@ class QBittorrentClientGatewayService extends ClientGatewayService {
throw new Error();
}

const method = isApiVersionAtLeast(await this.clientRequestManager.apiVersion, '2.11.0') ? 'stopped' : 'paused';
await this.clientRequestManager
.torrentsAddURLs(urls, {
savepath: destination,
tags: tags.join(','),
[isApiVersionAtLeast(this.clientRequestManager.apiVersion, '2.11.0') ? 'stopped' : 'paused']: !start,
[method]: !start,
root_folder: !isBasePath,
contentLayout: isBasePath ? 'NoSubfolder' : undefined,
sequentialDownload: isSequential,
Expand Down Expand Up @@ -526,7 +528,7 @@ class QBittorrentClientGatewayService extends ClientGatewayService {

async testGateway(): Promise<void> {
return this.clientRequestManager
.updateAuthCookie()
.updateConnection()
.then(() => this.processClientRequestSuccess(undefined), this.processClientRequestError);
}
}
Expand Down
40 changes: 23 additions & 17 deletions server/services/qBittorrent/clientRequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const EMPTY_SERVER_STATE = {
class ClientRequestManager {
private connectionSettings: QBittorrentConnectionSettings;
private apiBase: string;
apiVersion: string | null = null;
apiVersion: Promise<string | undefined> = Promise.resolve(undefined);
private authCookie: Promise<string | undefined> = Promise.resolve(undefined);
private isMainDataPending = false;

Expand Down Expand Up @@ -80,17 +80,27 @@ class ClientRequestManager {
});
}

async updateAuthCookie(connectionSettings?: QBittorrentConnectionSettings): Promise<void> {
let authFailed = false;
async updateConnection(connectionSettings?: QBittorrentConnectionSettings): Promise<void> {
let failed = false;

this.authCookie = this.authenticate(connectionSettings).catch(() => {
authFailed = true;
failed = true;
return undefined;
});

this.apiVersion = this.authCookie
.then(() => {
return !failed ? this.getApiVersion() : Promise.resolve(undefined);
})
.catch(() => {
failed = true;
return undefined;
});

await this.authCookie;
await this.apiVersion;

if (authFailed) {
if (failed) {
throw new Error();
}
}
Expand Down Expand Up @@ -120,15 +130,12 @@ class ClientRequestManager {
});
}

async getApiVersion(): Promise<void> {
try {
const {data} = await axios.get(`${this.apiBase}/app/webapiVersion`, {
async getApiVersion(): Promise<string> {
return axios
.get<string>(`${this.apiBase}/app/webapiVersion`, {
headers: await this.getRequestHeaders(),
});
this.apiVersion = data;
} catch (error) {
this.apiVersion = null;
}
})
.then((res) => res.data);
}

async getTorrentInfos(): Promise<QBittorrentTorrentInfos> {
Expand Down Expand Up @@ -306,7 +313,7 @@ class ClientRequestManager {
}

async torrentsPause(hashes: Array<string>): Promise<void> {
const method = isApiVersionAtLeast(this.apiVersion, '2.11.0') ? 'stop' : 'pause';
const method = isApiVersionAtLeast(await this.apiVersion, '2.11.0') ? 'stop' : 'pause';
return axios
.post(
`${this.apiBase}/torrents/${method}`,
Expand All @@ -323,7 +330,7 @@ class ClientRequestManager {
}

async torrentsResume(hashes: Array<string>): Promise<void> {
const method = isApiVersionAtLeast(this.apiVersion, '2.11.0') ? 'start' : 'resume';
const method = isApiVersionAtLeast(await this.apiVersion, '2.11.0') ? 'start' : 'resume';
return axios
.post(
`${this.apiBase}/torrents/${method}`,
Expand Down Expand Up @@ -622,8 +629,7 @@ class ClientRequestManager {
constructor(connectionSettings: QBittorrentConnectionSettings) {
this.connectionSettings = connectionSettings;
this.apiBase = `${connectionSettings.url}/api/v2`;
this.updateAuthCookie().catch(() => undefined);
this.getApiVersion();
this.updateConnection().catch(() => undefined);
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/services/qBittorrent/util/apiVersionCheck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function isApiVersionAtLeast(currentVersion: string | null, targetVersion: string): boolean {
export function isApiVersionAtLeast(currentVersion: string | undefined, targetVersion: string): boolean {
if (!currentVersion) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions server/services/rTorrent/util/XMLRPCDeserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const closeTag = (elementName: string) => {
break;
case 'i4':
case 'i8':
case 'int':
case 'string':
case 'name':
dataStack.push(tagValue);
Expand Down
4 changes: 2 additions & 2 deletions server/services/rTorrent/util/XMLRPCSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const value = (value: XMLRPCValue): string => {
};

const data = (values: XMLRPCValue[]) => {
return `<data>${values.map(value)}</data>`;
return `<data>${values.map(value).join('')}</data>`;
};

const member = ([key, val]: [string, XMLRPCValue]) => {
Expand All @@ -64,7 +64,7 @@ const param = (param: XMLRPCValue) => {
const sParams = (params: XMLRPCValue[]) => {
if (!params?.length) return '';

return `<params>${params.map(param)}</params>`;
return `<params>${params.map(param).join('')}</params>`;
};

const serializeSync = (methodName: string, params: XMLRPCValue[]): string => {
Expand Down

0 comments on commit ac6b965

Please sign in to comment.