Skip to content

Commit 8391116

Browse files
authored
feat(ui): run the dashboard console as a web repl (#1341)
The dashboard console carried commands over an HTTP request and read the log from an event stream, and a browser signed in with the session cookie never got the socket at all. Every command, the log, the completion and the confirmation now run over the one version 1 websocket. A cookie session sends a hello without a token and the browser attaches the session cookie. The input is disabled while the socket is down, a refusal shows the sign-in state, and the data of a result is drawn as a table. The legacy endpoints stay on the server. The unused event stream package is removed. Signed-off-by: TheMeinerLP <github@themeinerlp.dev>
1 parent 88ee03d commit 8391116

8 files changed

Lines changed: 379 additions & 325 deletions

File tree

‎reposilite-frontend/fake-api/fake-ingot-backend.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,30 @@ application
907907
})
908908
.ws("/api/console/sock", (connection) => {
909909
let authenticated = false
910+
// Set by a first message that is a version 1 hello. The legacy text protocol below stays as it was.
911+
let version1 = false
912+
let sequence = 0
913+
914+
const send = (frame: object) => connection.send(JSON.stringify(frame))
910915

911916
connection.on("message", (data) => {
912917
const message = String(data)
918+
if (version1 || message.startsWith('{"type":"hello"')) {
919+
const frame = JSON.parse(message) as { type: string; id?: string; command?: string; line?: string }
920+
if (frame.type === "hello") {
921+
version1 = true
922+
send({ type: "welcome", protocol: 1, boot: "fake-boot", node: "fake-node", seq: sequence, replay: null })
923+
send({ type: "log", seq: ++sequence, node: "fake-node", level: "INFO", text: "Console connected", dropped: 0 })
924+
} else if (frame.type === "execute") {
925+
send({
926+
type: "result", id: frame.id, status: "SUCCEEDED", exitCode: 0, data: null, node: "fake-node", confirmed: false,
927+
output: [{ stream: "stdout", text: "Response: " + frame.command }]
928+
})
929+
} else if (frame.type === "complete") {
930+
send({ type: "complete", id: frame.id, replace: { start: 0, end: frame.line?.length ?? 0 }, candidates: [] })
931+
}
932+
return
933+
}
913934
if (message == "Authorization:name:secret") {
914935
sendMessage(connection, "DEBUG | Authorized")
915936
authenticated = true

‎reposilite-frontend/package-lock.json‎

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎reposilite-frontend/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"axios": "^1.18.0",
4141
"downloadjs": "^1.4.7",
4242
"echarts": "^6.1.0",
43-
"extended-eventsource": "^2.1.0",
4443
"mime-types": "^3.0.2",
4544
"pretty-bytes": "^7.1.0",
4645
"simple-icons": "^16.35.0",

0 commit comments

Comments
 (0)