This commit is contained in:
@@ -149,23 +149,42 @@ class DownloadClientRegistry {
|
||||
const clients = this.getAllClients();
|
||||
const result = {};
|
||||
|
||||
// Group by client type
|
||||
if (clients.length === 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Reset fallback flags for qBittorrent clients
|
||||
for (const client of clients) {
|
||||
if (client.resetFallbackFlag) {
|
||||
client.resetFallbackFlag();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch downloads from all clients in parallel
|
||||
const results = await Promise.allSettled(
|
||||
clients.map(async (client) => {
|
||||
const downloads = await client.getActiveDownloads();
|
||||
return {
|
||||
type: client.getClientType(),
|
||||
downloads
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
// Group by client type
|
||||
for (let i = 0; i < clients.length; i++) {
|
||||
const client = clients[i];
|
||||
const type = client.getClientType();
|
||||
if (!result[type]) {
|
||||
result[type] = [];
|
||||
}
|
||||
|
||||
// Reset fallback flags for qBittorrent clients
|
||||
if (client.resetFallbackFlag) {
|
||||
client.resetFallbackFlag();
|
||||
}
|
||||
|
||||
try {
|
||||
const downloads = await client.getActiveDownloads();
|
||||
result[type].push(...downloads);
|
||||
} catch (error) {
|
||||
logToFile(`[DownloadClientRegistry] Error fetching from ${client.name}: ${error.message}`);
|
||||
const res = results[i];
|
||||
if (res.status === 'fulfilled' && res.value) {
|
||||
result[type].push(...res.value.downloads);
|
||||
} else {
|
||||
const errorMsg = res.status === 'rejected' ? res.reason?.message : 'Unknown error';
|
||||
logToFile(`[DownloadClientRegistry] Error fetching from ${client.name}: ${errorMsg}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user