fix(qbittorrent): handle v5 stopped torrent states for pause functionality (#6211)
This commit is contained in:
1 parent
af89423f66
commit
2ada1aa249
4 files changed
+35
-9
No files matched your search
@@ -49,6 +49,7 @@ export const downloadsRouter = createTRPCRouter({
|
||||
await integrationInstance.pauseQueueAsync();
|
||||
}),
|
||||
);
|
||||
downloadClientRequestHandler.invalidateCache();
|
||||
}),
|
||||
pauseItem: protectedProcedure
|
||||
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
||||
@@ -60,6 +61,7 @@ export const downloadsRouter = createTRPCRouter({
|
||||
await integrationInstance.pauseItemAsync(input.item);
|
||||
}),
|
||||
);
|
||||
downloadClientRequestHandler.invalidateCache();
|
||||
}),
|
||||
resume: protectedProcedure
|
||||
.meta({
|
||||
@@ -77,6 +79,7 @@ export const downloadsRouter = createTRPCRouter({
|
||||
await integrationInstance.resumeQueueAsync();
|
||||
}),
|
||||
);
|
||||
downloadClientRequestHandler.invalidateCache();
|
||||
}),
|
||||
resumeItem: protectedProcedure
|
||||
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
||||
@@ -88,6 +91,7 @@ export const downloadsRouter = createTRPCRouter({
|
||||
await integrationInstance.resumeItemAsync(input.item);
|
||||
}),
|
||||
);
|
||||
downloadClientRequestHandler.invalidateCache();
|
||||
}),
|
||||
deleteItem: protectedProcedure
|
||||
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
||||
@@ -99,5 +103,6 @@ export const downloadsRouter = createTRPCRouter({
|
||||
await integrationInstance.deleteItemAsync(input.item, input.fromDisk);
|
||||
}),
|
||||
);
|
||||
downloadClientRequestHandler.invalidateCache();
|
||||
}),
|
||||
});
|
||||
@@ -99,11 +99,14 @@ export class QBitTorrentIntegration extends Integration implements IDownloadClie
|
||||
password: this.getSecretValue("password"),
|
||||
};
|
||||
|
||||
return new QBittorrent({
|
||||
const client = new QBittorrent({
|
||||
...credentials,
|
||||
baseUrl: this.url("/").toString(),
|
||||
dispatcher: dispatcher ?? (await createCertificateAgentAsync()),
|
||||
});
|
||||
// Populate version state so the library uses correct v5 endpoints (stop/start vs pause/resume)
|
||||
await client.getAppVersion();
|
||||
return client;
|
||||
}
|
||||
|
||||
private static getTorrentState(state: string): DownloadClientItem["state"] {
|
||||
@@ -125,6 +128,8 @@ export class QBitTorrentIntegration extends Integration implements IDownloadClie
|
||||
return "seeding";
|
||||
case "pausedDL":
|
||||
case "pausedUP":
|
||||
case "stoppedDL":
|
||||
case "stoppedUP":
|
||||
return "paused";
|
||||
case "stalledDL":
|
||||
return "stalled";
|
||||
|
||||
@@ -20,11 +20,23 @@ export const createIntegrationRequestHandler = <
|
||||
TInput extends Record<string, unknown>,
|
||||
>(
|
||||
options: Options<TData, TKind, TInput>,
|
||||
) => ({
|
||||
handler: (integration: IntegrationOfKind<TKind>, itemOptions: TInput) => {
|
||||
const inner = createRequestHandler<TData, { integrationId: string; options: TInput }>({
|
||||
requestAsync: async (input) => options.requestAsync(integration, input.options),
|
||||
});
|
||||
return inner.handler({ integrationId: integration.id, options: itemOptions });
|
||||
},
|
||||
});
|
||||
) => {
|
||||
const integrationMap = new Map<string, IntegrationOfKind<TKind>>();
|
||||
const inner = createRequestHandler<TData, { integrationId: string; options: TInput }>({
|
||||
requestAsync: async (input) => {
|
||||
const integration = integrationMap.get(input.integrationId);
|
||||
if (!integration) {
|
||||
throw new Error(`Integration ${input.integrationId} not found in cache`);
|
||||
}
|
||||
return options.requestAsync(integration, input.options);
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
invalidateCache: inner.invalidateCache,
|
||||
handler: (integration: IntegrationOfKind<TKind>, itemOptions: TInput) => {
|
||||
integrationMap.set(integration.id, integration);
|
||||
return inner.handler({ integrationId: integration.id, options: itemOptions });
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -22,6 +22,10 @@ export const createRequestHandler = <TData, TInput extends Record<string, unknow
|
||||
const inflight = new Map<string, Promise<CacheEntry<TData>>>();
|
||||
|
||||
return {
|
||||
invalidateCache: () => {
|
||||
cache.clear();
|
||||
inflight.clear();
|
||||
},
|
||||
handler: (input: TInput) => ({
|
||||
async getDataAsync(): Promise<{ data: TData; timestamp: Date }> {
|
||||
const ttl = options.cacheTtlMs ?? DEFAULT_TTL_MS;
|
||||
|
||||
Reference in new issue
Block a user