@samitouri / QOSami-HFS / commits / cccea510

admin/logs: avoid harmless 404 requests

Massimo Melina committed Oct 5, 2024 at 10:52 UTC cccea510053f698aae59d3ef6115bcdaaecea4c4
2 files changed +5 -2
admin/src/LogsPage.ts
+3 -1
@@ -95,6 +95,8 @@ export default function LogsPage() {
95 }
96 }
97
98 +const LOGS_ON_FILE: string[] = [CFG.log, CFG.error_log]
99 +
100 function LogFile({ file, addToFooter, hidden }: { hidden?: boolean, file: string, addToFooter?: ReactNode }) {
101 const [showCountry, setShowCountry] = useState(false)
102 const [showAgent, setShowAgent] = useState(false)
@@ -111,7 +113,7 @@ function LogFile({ file, addToFooter, hidden }: { hidden?: boolean, file: string
113 const invert = true
114 const [firstSight, setFirstSight] = useState(!hidden)
115 useEffect(() => setFirstSight(x => x || !hidden), [hidden])
114 - useApi(firstSight && 'get_log_file', { file, range: limited || !skipped ? -MAX : `0-${skipped}` }, {
116 + useApi(firstSight && LOGS_ON_FILE.includes(file) && 'get_log_file', { file, range: limited || !skipped ? -MAX : `0-${skipped}` }, {
117 skipParse: true, skipLog: true,
118 onResponse(res, body) {
119 const lines = body.split('\n')
src/api.log.ts
+2 -1
@@ -9,7 +9,7 @@ import { serveFile } from './serveFile'
9 import { ips } from './ips'
10
11 export default {
12 - async get_log_file({ file = 'log', range = '' }, ctx) {
12 + async get_log_file({ file = 'log', range = '' }, ctx) { // this is limited to logs on file, and serves the file instead of a list of records
13 const log = _.find(loggers, { name: file })
14 if (!log)
15 throw HTTP_NOT_FOUND
@@ -44,6 +44,7 @@ export default {
44 ctx.res.once('close', events.on('console', x => list.add(x)))
45 return
46 }
47 + // for other logs we only provide updates. Use get_log_file to download past content
48 if (!_.find(loggers, { name: file }))
49 return list.error(HTTP_NOT_FOUND, true)
50 list.ready()