mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.31.2",
|
"version": "4.31.3",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "hydro.js",
|
"main": "hydro.js",
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ type RequestPayload = RequestInitSharedConnPayload | RequestSendMessagePayload;
|
|||||||
function broadcastMsg(ports: MessagePort[], message: any) {
|
function broadcastMsg(ports: MessagePort[], message: any) {
|
||||||
for (const p of ports) p.postMessage(message);
|
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) {
|
function initSharedConn(path: string, port: MessagePort, cookie: any) {
|
||||||
if (!sharedConnections[path]) {
|
if (!sharedConnections[path]) {
|
||||||
console.log('Init connection for', path);
|
console.log('Init connection for', path);
|
||||||
@@ -32,6 +36,7 @@ function initSharedConn(path: string, port: MessagePort, cookie: any) {
|
|||||||
if (payload.event === 'auth') {
|
if (payload.event === 'auth') {
|
||||||
if (['PermissionError', 'PrivilegeError'].includes(payload.error)) {
|
if (['PermissionError', 'PrivilegeError'].includes(payload.error)) {
|
||||||
broadcastMsg(ports, { type: 'close', path, error: payload.error });
|
broadcastMsg(ports, { type: 'close', path, error: payload.error });
|
||||||
|
closeSharedConn(path);
|
||||||
} else {
|
} else {
|
||||||
console.log('Connected to', path);
|
console.log('Connected to', path);
|
||||||
broadcastMsg(ports, { type: 'open', path });
|
broadcastMsg(ports, { type: 'open', path });
|
||||||
@@ -47,7 +52,7 @@ function initSharedConn(path: string, port: MessagePort, cookie: any) {
|
|||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
onconnect = function (e) { // eslint-disable-line no-undef
|
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 }) => {
|
port.addEventListener('message', (msg: { data: RequestPayload }) => {
|
||||||
if (msg.data.type === 'sharedConn') initSharedConn(msg.data.path, port, msg.data.cookie);
|
if (msg.data.type === 'sharedConn') initSharedConn(msg.data.path, port, msg.data.cookie);
|
||||||
|
|||||||
Reference in new issue
Block a user