mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui: do not reconnect if triggered PermissionError or PrivilegeError
This commit is contained in:
1 parent
f13cad070f
commit
dbf54650b9
2 files changed
+7
-2
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.31.2",
|
||||
"version": "4.31.3",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -18,6 +18,10 @@ type RequestPayload = RequestInitSharedConnPayload | RequestSendMessagePayload;
|
||||
function broadcastMsg(ports: MessagePort[], message: any) {
|
||||
for (const p of ports) p.postMessage(message);
|
||||
}
|
||||
function closeSharedConn(path: string) {
|
||||
sharedConnections[path][0].close();
|
||||
delete sharedConnections[path];
|
||||
}
|
||||
function initSharedConn(path: string, port: MessagePort, cookie: any) {
|
||||
if (!sharedConnections[path]) {
|
||||
console.log('Init connection for', path);
|
||||
@@ -32,6 +36,7 @@ function initSharedConn(path: string, port: MessagePort, cookie: any) {
|
||||
if (payload.event === 'auth') {
|
||||
if (['PermissionError', 'PrivilegeError'].includes(payload.error)) {
|
||||
broadcastMsg(ports, { type: 'close', path, error: payload.error });
|
||||
closeSharedConn(path);
|
||||
} else {
|
||||
console.log('Connected to', path);
|
||||
broadcastMsg(ports, { type: 'open', path });
|
||||
@@ -47,7 +52,7 @@ function initSharedConn(path: string, port: MessagePort, cookie: any) {
|
||||
|
||||
// @ts-ignore
|
||||
onconnect = function (e) { // eslint-disable-line no-undef
|
||||
const port = e.ports[0];
|
||||
const port: MessagePort = e.ports[0];
|
||||
|
||||
port.addEventListener('message', (msg: { data: RequestPayload }) => {
|
||||
if (msg.data.type === 'sharedConn') initSharedConn(msg.data.path, port, msg.data.cookie);
|
||||
|
||||
Reference in new issue
Block a user