fix(account): guard download record user races

This commit is contained in:
2026-05-19 01:10:17 +08:00
parent b839e0770c
commit f280039874
2 changed files with 162 additions and 30 deletions
+13 -4
View File
@@ -1249,9 +1249,16 @@ const onDetailRemove = (app: App) => {
};
const onDetailInstall = async (app: App) => {
const initiatingUserId = currentUser.value?.id ?? null;
const download = await handleInstall(app);
const initiatingUserId = currentUser.value?.id;
if (!download || !isLoggedIn.value || initiatingUserId === undefined) return;
if (
!download ||
initiatingUserId === null ||
!isLoggedIn.value ||
currentUser.value?.id !== initiatingUserId
) {
return;
}
pendingDownloadRecords.set(download.id, {
userId: initiatingUserId,
@@ -1272,6 +1279,10 @@ const handleInstallCompleteForDownloadRecord = async (
const pendingRecord = pendingDownloadRecords.get(result.id);
if (!pendingRecord) return;
if (result.success) {
pendingDownloadRecords.delete(result.id);
}
if (
!result.success ||
!isLoggedIn.value ||
@@ -1294,8 +1305,6 @@ const handleInstallCompleteForDownloadRecord = async (
await recordDownloadedApp(downloadRecord);
} catch (error: unknown) {
logger.warn({ err: error }, "记录下载应用失败");
} finally {
pendingDownloadRecords.delete(result.id);
}
};