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();
|
await integrationInstance.pauseQueueAsync();
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
downloadClientRequestHandler.invalidateCache();
|
||||||
}),
|
}),
|
||||||
pauseItem: protectedProcedure
|
pauseItem: protectedProcedure
|
||||||
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
||||||
@@ -60,6 +61,7 @@ export const downloadsRouter = createTRPCRouter({
|
|||||||
await integrationInstance.pauseItemAsync(input.item);
|
await integrationInstance.pauseItemAsync(input.item);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
downloadClientRequestHandler.invalidateCache();
|
||||||
}),
|
}),
|
||||||
resume: protectedProcedure
|
resume: protectedProcedure
|
||||||
.meta({
|
.meta({
|
||||||
@@ -77,6 +79,7 @@ export const downloadsRouter = createTRPCRouter({
|
|||||||
await integrationInstance.resumeQueueAsync();
|
await integrationInstance.resumeQueueAsync();
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
downloadClientRequestHandler.invalidateCache();
|
||||||
}),
|
}),
|
||||||
resumeItem: protectedProcedure
|
resumeItem: protectedProcedure
|
||||||
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
||||||
@@ -88,6 +91,7 @@ export const downloadsRouter = createTRPCRouter({
|
|||||||
await integrationInstance.resumeItemAsync(input.item);
|
await integrationInstance.resumeItemAsync(input.item);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
downloadClientRequestHandler.invalidateCache();
|
||||||
}),
|
}),
|
||||||
deleteItem: protectedProcedure
|
deleteItem: protectedProcedure
|
||||||
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
.concat(createDownloadClientIntegrationMiddleware("interact"))
|
||||||
@@ -99,5 +103,6 @@ export const downloadsRouter = createTRPCRouter({
|
|||||||
await integrationInstance.deleteItemAsync(input.item, input.fromDisk);
|
await integrationInstance.deleteItemAsync(input.item, input.fromDisk);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
downloadClientRequestHandler.invalidateCache();
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -99,11 +99,14 @@ export class QBitTorrentIntegration extends Integration implements IDownloadClie
|
|||||||
password: this.getSecretValue("password"),
|
password: this.getSecretValue("password"),
|
||||||
};
|
};
|
||||||
|
|
||||||
return new QBittorrent({
|
const client = new QBittorrent({
|
||||||
...credentials,
|
...credentials,
|
||||||
baseUrl: this.url("/").toString(),
|
baseUrl: this.url("/").toString(),
|
||||||
dispatcher: dispatcher ?? (await createCertificateAgentAsync()),
|
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"] {
|
private static getTorrentState(state: string): DownloadClientItem["state"] {
|
||||||
@@ -125,6 +128,8 @@ export class QBitTorrentIntegration extends Integration implements IDownloadClie
|
|||||||
return "seeding";
|
return "seeding";
|
||||||
case "pausedDL":
|
case "pausedDL":
|
||||||
case "pausedUP":
|
case "pausedUP":
|
||||||
|
case "stoppedDL":
|
||||||
|
case "stoppedUP":
|
||||||
return "paused";
|
return "paused";
|
||||||
case "stalledDL":
|
case "stalledDL":
|
||||||
return "stalled";
|
return "stalled";
|
||||||
|
|||||||
@@ -20,11 +20,23 @@ export const createIntegrationRequestHandler = <
|
|||||||
TInput extends Record<string, unknown>,
|
TInput extends Record<string, unknown>,
|
||||||
>(
|
>(
|
||||||
options: Options<TData, TKind, TInput>,
|
options: Options<TData, TKind, TInput>,
|
||||||
) => ({
|
) => {
|
||||||
handler: (integration: IntegrationOfKind<TKind>, itemOptions: TInput) => {
|
const integrationMap = new Map<string, IntegrationOfKind<TKind>>();
|
||||||
const inner = createRequestHandler<TData, { integrationId: string; options: TInput }>({
|
const inner = createRequestHandler<TData, { integrationId: string; options: TInput }>({
|
||||||
requestAsync: async (input) => options.requestAsync(integration, input.options),
|
requestAsync: async (input) => {
|
||||||
});
|
const integration = integrationMap.get(input.integrationId);
|
||||||
return inner.handler({ integrationId: integration.id, options: itemOptions });
|
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>>>();
|
const inflight = new Map<string, Promise<CacheEntry<TData>>>();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
invalidateCache: () => {
|
||||||
|
cache.clear();
|
||||||
|
inflight.clear();
|
||||||
|
},
|
||||||
handler: (input: TInput) => ({
|
handler: (input: TInput) => ({
|
||||||
async getDataAsync(): Promise<{ data: TData; timestamp: Date }> {
|
async getDataAsync(): Promise<{ data: TData; timestamp: Date }> {
|
||||||
const ttl = options.cacheTtlMs ?? DEFAULT_TTL_MS;
|
const ttl = options.cacheTtlMs ?? DEFAULT_TTL_MS;
|
||||||
|
|||||||
Reference in new issue
Block a user