Skip to content

Commit 984b5d2

Browse files
committed
fix: 修复之前被搞坏的限流功能,更正活跃任务所需状态
1 parent 13b0f72 commit 984b5d2

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/composables/useDownloadManager.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@ const TERMINAL_DOWNLOAD_STATUS_SET = new Set<DownloadStatus>([
132132
'verify_failed',
133133
]);
134134
const PRESERVED_DOWNLOAD_STATUS_SET = new Set<DownloadStatus>(['active', 'pausing', 'paused']);
135-
const ACTIVE_PRESENCE_DOWNLOAD_STATUS_SET = new Set<DownloadStatus>([
136-
'active',
137-
'waiting',
138-
'paused',
139-
'pausing',
140-
]);
141135
const FOLDER_COLLECTION_ABORTED = 'folder-collection-aborted';
142136

143137
/** 统一的下载 command 调用入口。 */
@@ -650,11 +644,10 @@ export const useDownloadManager = createSharedComposable(() => {
650644
return { activeCount, totalSpeed, completed, failed, paused, waiting, total };
651645
});
652646

653-
/** 是否有活跃的下载任务(对齐旧版 db/downloads.ts hasActiveDownloads SQL 语义) */
647+
/** 是否有活跃的下载任务(仅统计正在下载、排队等待、或正在收集文件夹文件的任务) */
654648
const hasActiveDownloads = computed(() =>
655649
displayList.value.some(
656-
(d) =>
657-
(d.status != null && ACTIVE_PRESENCE_DOWNLOAD_STATUS_SET.has(d.status)) || d.isCollecting,
650+
(d) => d.status === 'active' || d.status === 'waiting' || d.isCollecting,
658651
),
659652
);
660653

src/composables/useUploadManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,9 @@ export const useUploadManager = createSharedComposable(() => {
617617
};
618618
});
619619

620-
// 与下载管理器保持一致,布局层和更新器都直接消费这个布尔值。
620+
/** 是否有活跃的上传任务(仅统计正在上传或正在计算哈希的任务) */
621621
const hasActiveUploads = computed(() =>
622-
displayList.value.some((item) => ACTIVE_UPLOAD_STATUS_SET.has(item.status)),
622+
displayList.value.some((item) => item.status === 'uploading' || item.status === 'hashing'),
623623
);
624624

625625
// `init` 设计成幂等入口,页面重复调用只会复用同一个初始化 promise。

src/utils/http/alova.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,27 @@ const { onAuthRequired, onResponseRefreshToken } = createServerTokenAuthenticati
6161
},
6262
});
6363

64+
// 全局单例速率限制器 — 惰性初始化,避免模块加载时访问尚未初始化的 Pinia store
65+
let globalApiLimiter: ReturnType<typeof createRateLimiter> | null = null;
66+
67+
const getApiLimiter = () => {
68+
if (!globalApiLimiter) {
69+
globalApiLimiter = createRateLimiter(() => {
70+
const settingStore = useSettingStoreWithOut();
71+
return settingStore.generalSetting.apiRateLimit;
72+
});
73+
}
74+
return globalApiLimiter;
75+
};
76+
6477
export const alovaInst = createAlova({
6578
requestAdapter: adapterTauriFetch(),
6679
timeout: 40000,
6780
beforeRequest: onAuthRequired(async (method) => {
68-
const settingStore = useSettingStoreWithOut();
69-
const apiLimiter = createRateLimiter(() => settingStore.generalSetting.apiRateLimit);
70-
7181
// 对非认证请求进行令牌桶限流
7282
const authRole = method.meta?.authRole;
7383
if (authRole === undefined) {
74-
await apiLimiter.acquire();
84+
await getApiLimiter().acquire();
7585
}
7686
console.log(method);
7787
}),

0 commit comments

Comments
 (0)