mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
dashboard: make log display more resilient
This commit is contained in:
parent
e967d9ed45
commit
696d1e686a
@ -14,10 +14,10 @@ import {
|
||||
type DeleteInstanceResult,
|
||||
type InstanceFields,
|
||||
type InstanceId,
|
||||
type InstanceLogFields,
|
||||
PocketBase,
|
||||
RestCommands,
|
||||
RestMethods,
|
||||
type UntrustedInstanceLogFields,
|
||||
type UpdateInstancePayload,
|
||||
UpdateInstancePayloadSchema,
|
||||
type UpdateInstanceResult,
|
||||
@ -245,7 +245,7 @@ export const createPocketbaseClient = (config: PocketbaseClientConfig) => {
|
||||
|
||||
const watchInstanceLog = (
|
||||
instance: InstanceFields,
|
||||
update: (log: InstanceLogFields) => void,
|
||||
update: (log: UntrustedInstanceLogFields) => void,
|
||||
nInitial = 100,
|
||||
): (() => void) => {
|
||||
const auth = client.authStore.exportToCookie()
|
||||
@ -269,7 +269,7 @@ export const createPocketbaseClient = (config: PocketbaseClientConfig) => {
|
||||
}),
|
||||
onmessage: (event) => {
|
||||
const {} = event
|
||||
const log = JSON.parse(event.data) as InstanceLogFields
|
||||
const log = JSON.parse(event.data) as UntrustedInstanceLogFields
|
||||
|
||||
update(log)
|
||||
},
|
||||
|
@ -30,9 +30,11 @@
|
||||
// This will take in the log message and return either the message or a string
|
||||
const logText = (log: any) => {
|
||||
try {
|
||||
return JSON.parse(log.message)
|
||||
const parsed = JSON.parse(log.message)
|
||||
// Split on newlines and join with <br> tags
|
||||
return parsed.split('\n').join('<br>')
|
||||
} catch (e) {
|
||||
return log.message
|
||||
return log.message.split('\n').join('<br>')
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +82,15 @@
|
||||
logs.set([])
|
||||
unwatch = client().watchInstanceLog($instance, (newLog) => {
|
||||
logs.update((currentLogs) => {
|
||||
return [...currentLogs, newLog]
|
||||
return [
|
||||
...currentLogs,
|
||||
{
|
||||
time: `<no time>`,
|
||||
stream: StreamNames.StdOut,
|
||||
message: `<no message>`,
|
||||
...newLog,
|
||||
},
|
||||
]
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -119,7 +129,7 @@
|
||||
<div>
|
||||
<span class="mr-1 text-accent">{log.time}</span>
|
||||
<span class="mr-1 text-base-content {logColor(log.stream)}"
|
||||
>{logText(log)}</span
|
||||
>{@html logText(log)}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
@ -149,7 +159,7 @@
|
||||
<span class="mr-1 text-accent">{log.time}</span>
|
||||
|
||||
<span class="mr-1 text-base-content {logColor(log.stream)}"
|
||||
>{logText(log)}</span
|
||||
>{@html logText(log)}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user