fix:修复SSE消息推送导致请求堵塞(谷歌浏览器并发请求不能超过6个)

This commit is contained in:
czhqwer
2025-03-30 11:49:03 +08:00
parent ece3ae6c2c
commit 1982a450a0
3 changed files with 28 additions and 20 deletions

View File

@@ -83,6 +83,7 @@ export default {
this.showPasswordDialog = true; this.showPasswordDialog = true;
} }
localStorage.setItem('password', password);
this.$emit('main-user', mainUser); this.$emit('main-user', mainUser);
} catch (error) { } catch (error) {
console.error('获取密码失败:', error); console.error('获取密码失败:', error);

View File

@@ -80,14 +80,34 @@ export default {
fileList: [], fileList: [],
enableShare: false, enableShare: false,
isAdmin: false, isAdmin: false,
sharedFilesEventSource: null,
systemEventSource: null,
}; };
}, },
mounted() { mounted() {
this.fetchFiles(); this.fetchFiles();
this.getShareStatus(); this.getShareStatus();
this.getShareAddress(); this.getShareAddress();
this.subscribeSharedFiles();
this.subscribeSystemEvent(); this.sharedFilesEventSource = subscribeSharedFiles(() => {
this.fetchFiles();
});
this.systemEventSource = subscribeSystemEvent((event) => {
if (event.type === 'enableShare') {
this.fileList = [];
this.enableShare = event.data.enable;
this.fetchFiles();
}
});
},
beforeDestroy() {
if (this.sharedFilesEventSource) {
this.sharedFilesEventSource.close();
}
if (this.systemEventSource) {
this.systemEventSource.close();
}
}, },
methods: { methods: {
async getShareAddress() { async getShareAddress() {
@@ -112,21 +132,6 @@ export default {
this.fileList = res.data; this.fileList = res.data;
} }
}, },
subscribeSharedFiles() {
subscribeSharedFiles(() => {
this.fetchFiles();
});
},
subscribeSystemEvent() {
subscribeSystemEvent((event) => {
if (event.type === 'enableShare') {
this.fileList = [];
this.enableShare = event.data.enable;
this.fetchFiles();
}
});
},
async downloadFile(file) { async downloadFile(file) {
try { try {
const adjusteUrl = this.replaceLocalhost(file.accessUrl) const adjusteUrl = this.replaceLocalhost(file.accessUrl)
@@ -154,7 +159,7 @@ export default {
if (!this.shareAddress || !url) return url; if (!this.shareAddress || !url) return url;
const shareIp = new URL(this.shareAddress).hostname; const shareIp = new URL(this.shareAddress).hostname;
return url.replace(/localhost/g, shareIp); return url.replace(/localhost/g, shareIp);
}, },
copyLink(accessUrl) { copyLink(accessUrl) {
const adjusteUrl = this.replaceLocalhost(accessUrl) const adjusteUrl = this.replaceLocalhost(accessUrl)
if (navigator.clipboard && navigator.clipboard.writeText) { if (navigator.clipboard && navigator.clipboard.writeText) {
@@ -196,8 +201,8 @@ export default {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(async() => { }).then(async () => {
const res = await unShareFile(fileIdentifier); const res = await unShareFile(fileIdentifier);
if (res.code === 200) { if (res.code === 200) {
this.fetchFiles(); this.fetchFiles();

View File

@@ -320,6 +320,8 @@ const subscribeSystemEvent = (callback) => {
console.log("连接已关闭"); console.log("连接已关闭");
} }
}; };
return eventSource;
} }