fix: (regression beta) admin/plugins/installed: past log was inverted (with last on bottom)
Massimo Melina committed
Apr 4, 2025 at 00:01 UTC
9116b654745707ece28db6a3f10f1328a7b4d194
2 files changed
+18
-17
admin/src/InstalledPlugins.ts
+11
-13
@@ -151,7 +151,6 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
151
),
152
Wrapper({ children }: any) {
153
const { list } = useApiList('get_plugin_log', { id }, {
154
- invert: true,
154
map(x) { x.ts = new Date(x.ts) }
155
})
156
let lastDate: any
@@ -167,19 +166,18 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
166
}
167
}, list.map(x => {
168
formatDate(x.ts)
170
- const thisDate = formatDate(x.ts)
171
- return h(Fragment, { key: x.id },
172
- thisDate !== lastDate && (lastDate = thisDate),
173
- h(Box, {},
174
- h(Box, { title: thisDate, display: 'inline', color: 'text.secondary', mr: 1 }, formatTime(x.ts)),
175
- replaceStringToReact(x.msg, /https?:\/\/\S+/, m => h(Link, {
176
- href: m[0],
177
- target: '_blank'
178
- }, m[0])) // make links clickable
179
- )
169
+ const thisDate = formatDate(x.ts)
170
+ return h(Fragment, { key: x.id },
171
+ thisDate !== lastDate && (lastDate = thisDate),
172
+ h(Box, {},
173
+ h(Box, { title: thisDate, display: 'inline', color: 'text.secondary', mr: 1 }, formatTime(x.ts)),
174
+ replaceStringToReact(x.msg, /https?:\/\/\S+/, m => h(Link, {
175
+ href: m[0],
176
+ target: '_blank'
177
+ }, m[0])) // make links clickable
178
)
181
- }
182
- ))
179
+ )
180
+ }))
181
)
182
) : showOptions ? null : h(Box, { p: '1em', pt: 0 }, "Log is empty")
183
)
src/plugins.ts
+7
-4
@@ -507,6 +507,7 @@ function watchPlugin(id: string, path: string) {
507
const openDbs: KvStorage[] = []
508
const subbedConfigs: Callback[] = []
509
const pluginReady = pendingPromise()
510
+ const MAX_LOG = 100
511
await initPlugin(pluginData, { // following properties are not available in server_code
512
id,
513
srcDir: __dirname,
@@ -522,10 +523,12 @@ function watchPlugin(id: string, path: string) {
523
console.log('plugin', id+':', ...args)
524
pluginReady.then(() => { // log() maybe invoked during init(), while plugin is undefined
525
if (!plugin) return
525
- plugin.log.unshift({ ts: new Date, msg: args.map(x => x && typeof x === 'object' ? JSON.stringify(x) : String(x)).join(' ') })
526
- plugin.log.length = Math.min(100, plugin.log.length) // truncate
527
- events.emit('pluginLog:' + id, plugin.log[0])
528
- events.emit('pluginLog', id, plugin.log[0])
526
+ const msg = { ts: new Date, msg: args.map(x => x && typeof x === 'object' ? JSON.stringify(x) : String(x)).join(' ') }
527
+ plugin.log.push(msg)
528
+ if (plugin.log.length > MAX_LOG)
529
+ plugin.log.splice(0, 10) // truncate
530
+ events.emit('pluginLog:' + id, msg)
531
+ events.emit('pluginLog', id, msg)
532
})
533
},
534
getConfig(cfgKey?: string) {