socket: Explicitly communicate success
This commit updates the socket process to explicitly communicate the process (and any potential error) on the server using a binary message.
This commit is contained in:
parent
53f63d4efd
commit
746ebcd9e3
12 changed files with 111 additions and 31 deletions
|
|
@ -317,6 +317,32 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
|
||||
-----
|
||||
|
||||
The following software may be included in this product: async-mutex. A copy of the source code may be downloaded from https://github.com/DirtyHairy/async-mutex. This software contains the following license and notice below:
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Christian Speckner <cnspeckn@googlemail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
-----
|
||||
|
||||
The following software may be included in this product: base-x. A copy of the source code may be downloaded from https://github.com/cryptocoinjs/base-x.git. This software contains the following license and notice below:
|
||||
|
||||
The MIT License (MIT)
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ var AssetsUser = Assets{
|
|||
|
||||
// AssetsAdmin contains assets for the 'Admin' entrypoint.
|
||||
var AssetsAdmin = Assets{
|
||||
Scripts: `<script nomodule="" defer src="/this-is-fine/User.b2f9a57c.js"></script><script type="module" src="/this-is-fine/User.e0367d79.js"></script><script type="module" src="/this-is-fine/Default.38d394c2.js"></script><script src="/this-is-fine/Default.38d394c2.js" nomodule="" defer></script><script type="module" src="/this-is-fine/Admin.620228db.js"></script><script src="/this-is-fine/Admin.939dcd95.js" nomodule="" defer></script>`,
|
||||
Scripts: `<script nomodule="" defer src="/this-is-fine/User.b2f9a57c.js"></script><script type="module" src="/this-is-fine/User.e0367d79.js"></script><script type="module" src="/this-is-fine/Default.38d394c2.js"></script><script src="/this-is-fine/Default.38d394c2.js" nomodule="" defer></script><script type="module" src="/this-is-fine/Admin.15462d3d.js"></script><script src="/this-is-fine/Admin.2889b18a.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/this-is-fine/Default.938b4407.css"><link rel="stylesheet" href="/this-is-fine/Admin.a1e05c23.css"><link rel="stylesheet" href="/this-is-fine/User.840de3b4.css"><link rel="stylesheet" href="/this-is-fine/User.68febbf8.css"><link rel="stylesheet" href="/this-is-fine/Admin.6d2ae968.css">`,
|
||||
}
|
||||
|
||||
// AssetsAdminProvision contains assets for the 'AdminProvision' entrypoint.
|
||||
var AssetsAdminProvision = Assets{
|
||||
Scripts: `<script nomodule="" defer src="/this-is-fine/User.b2f9a57c.js"></script><script nomodule="" defer src="/this-is-fine/Admin.939dcd95.js"></script><script type="module" src="/this-is-fine/User.e0367d79.js"></script><script type="module" src="/this-is-fine/Admin.620228db.js"></script><script type="module" src="/this-is-fine/Default.38d394c2.js"></script><script src="/this-is-fine/Default.38d394c2.js" nomodule="" defer></script><script type="module" src="/this-is-fine/AdminProvision.3cf9e19e.js"></script><script src="/this-is-fine/AdminProvision.d195fd59.js" nomodule="" defer></script>`,
|
||||
Scripts: `<script nomodule="" defer src="/this-is-fine/User.b2f9a57c.js"></script><script nomodule="" defer src="/this-is-fine/Admin.2889b18a.js"></script><script type="module" src="/this-is-fine/User.e0367d79.js"></script><script type="module" src="/this-is-fine/Admin.15462d3d.js"></script><script type="module" src="/this-is-fine/Default.38d394c2.js"></script><script src="/this-is-fine/Default.38d394c2.js" nomodule="" defer></script><script type="module" src="/this-is-fine/AdminProvision.3cf9e19e.js"></script><script src="/this-is-fine/AdminProvision.d195fd59.js" nomodule="" defer></script>`,
|
||||
Styles: `<link rel="stylesheet" href="/this-is-fine/Default.938b4407.css"><link rel="stylesheet" href="/this-is-fine/Admin.a1e05c23.css"><link rel="stylesheet" href="/this-is-fine/User.840de3b4.css"><link rel="stylesheet" href="/this-is-fine/User.68febbf8.css"><link rel="stylesheet" href="/this-is-fine/Admin.6d2ae968.css"><link rel="stylesheet" href="/this-is-fine/AdminProvision.38d394c2.css">`,
|
||||
}
|
||||
|
|
|
|||
1
internal/dis/component/server/assets/dist/Admin.15462d3d.js
vendored
Normal file
1
internal/dis/component/server/assets/dist/Admin.15462d3d.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
internal/dis/component/server/assets/dist/Admin.2889b18a.js
vendored
Normal file
1
internal/dis/component/server/assets/dist/Admin.2889b18a.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -4,6 +4,7 @@
|
|||
"license": "AGPL-3.0-only",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"async-mutex": "^0.4.0",
|
||||
"dayjs": "^1.11.5",
|
||||
"highlight.js": "^11.7.0",
|
||||
"latex.css": "^1.8.0",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import "./index.css"
|
||||
import connectSocket from './socket';
|
||||
import connectSocket from './socket'
|
||||
import { Mutex } from 'async-mutex'
|
||||
|
||||
type Println = ((line: string, flush?: boolean) => void) & {
|
||||
paintedFrames: number;
|
||||
|
|
@ -122,14 +123,14 @@ export function createModal(action: string, params: string[], opts: Partial<Moda
|
|||
const button = document.createElement("button")
|
||||
button.className = "pure-button pure-button-success"
|
||||
button.append(typeof opts?.onClose === 'function' ? "Close & Finish" : "Close")
|
||||
let success = false;
|
||||
let result = {success: false, error: "unknown error"};
|
||||
button.addEventListener('click', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (typeof opts?.onClose === 'function') {
|
||||
button.setAttribute('disabled', 'disabled')
|
||||
target.innerHTML = 'Finishing up ...'
|
||||
opts.onClose(success)
|
||||
opts.onClose(result.success)
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -154,20 +155,38 @@ export function createModal(action: string, params: string[], opts: Partial<Moda
|
|||
|
||||
println("Connecting ...", true)
|
||||
|
||||
const mutex = new Mutex();
|
||||
|
||||
// connect to the socket and send the action
|
||||
connectSocket((socket) => {
|
||||
println("Connected", true)
|
||||
socket.send(action)
|
||||
params.forEach(p => socket.send(p))
|
||||
}, (data) => {
|
||||
println(data);
|
||||
mutex.runExclusive(async () => {
|
||||
if (data instanceof Blob) {
|
||||
result = JSON.parse(await data.text());
|
||||
return
|
||||
}
|
||||
|
||||
println(data);
|
||||
})
|
||||
}).then(() => {
|
||||
success = true
|
||||
println("Connection closed.", true)
|
||||
close();
|
||||
mutex.runExclusive(async () => {
|
||||
if(result.success) {
|
||||
println("Process finished successfully. ")
|
||||
} else {
|
||||
println("Process failed: " + result.error)
|
||||
}
|
||||
println("Connection closed. ", true)
|
||||
close();
|
||||
})
|
||||
}).catch(() => {
|
||||
success = false
|
||||
println("Connection errored.", true)
|
||||
close();
|
||||
mutex.runExclusive(async () => {
|
||||
println("Connection errored. ", true)
|
||||
result = { success: false, error: "connection errored" }
|
||||
|
||||
close();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
@ -751,6 +751,13 @@ ansi-styles@^4.1.0:
|
|||
dependencies:
|
||||
color-convert "^2.0.1"
|
||||
|
||||
async-mutex@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.4.0.tgz#ae8048cd4d04ace94347507504b3cf15e631c25f"
|
||||
integrity sha512-eJFZ1YhRR8UN8eBLoNzcDPcy/jqjsg6I1AP+KvWQX80BqOSW1oJPJXDylPUEeMr2ZQvHgnQ//Lp6f3RQ1zI7HA==
|
||||
dependencies:
|
||||
tslib "^2.4.0"
|
||||
|
||||
base-x@^3.0.8:
|
||||
version "3.0.9"
|
||||
resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.9.tgz#6349aaabb58526332de9f60995e548a53fe21320"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue