Skip to content

Commit

Permalink
Undo refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dshook committed Jan 5, 2025
1 parent 3ffcd8e commit 22e8074
Showing 1 changed file with 72 additions and 67 deletions.
139 changes: 72 additions & 67 deletions src/routes/user/system/SystemRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import BaseApi from '../../../api/BaseApi'
import DockerApi from '../../../docker/DockerApi'
import DockerUtils from '../../../docker/DockerUtils'
import InjectionExtractor from '../../../injection/InjectionExtractor'
import { IAppDef } from '../../../models/AppDefinition'
import { AutomatedCleanupConfigsCleaner } from '../../../models/AutomatedCleanupConfigs'
import CaptainManager from '../../../user/system/CaptainManager'
import VersionManager from '../../../user/system/VersionManager'
Expand Down Expand Up @@ -359,81 +360,85 @@ router.get('/goaccess/:appName/files', async function (req, res, next) {
appName
)

try {
const appDefinition = await dataStore
.getAppsDataStore()
.getAppDefinition(appName)
let appDefinition: IAppDef | undefined = undefined

let files: string[] = []

try {
files = await fs.readdir(directoryPath)
} catch {
Logger.d('No goaccess logs found')
}

const linkData = await Promise.all(
files
// Make sure to only return the generated reports and not folders or the live report
// That will be added back later
.filter((f) => f.endsWith('.html') && !f.endsWith('Live.html'))
.map((file) => {
return fs
.stat(path.join(directoryPath, file))
.then(function (fileStats) {
return {
name: file,
time: fileStats.mtime,
}
})
})
)

const baseUrl = `/user/system/goaccess/`

const baseApi = new BaseApi(
ApiStatusCodes.STATUS_OK,
'GoAccess info retrieved'
)
const linkList = linkData.map((d) => {
const { domainName, fileName } = loadBalanceManager.parseLogPath(
d.name
return Promise.resolve()
.then(function () {
// Ensure a valid appName parameter
return dataStore.getAppsDataStore().getAppDefinition(appName)
})
.then(function (data) {
appDefinition = data
return fs.readdir(directoryPath).catch((e) => {
Logger.d('No goaccess logs found')
return []
})
})
.then(function (files) {
return Promise.all(
files
// Make sure to only return the generated reports and not folders or the live report
// That will be added back later
.filter(
(f) => f.endsWith('.html') && !f.endsWith('Live.html')
)
.map((file) => {
return fs
.stat(path.join(directoryPath, file))
.then(function (fileStats) {
return {
name: file,
time: fileStats.mtime,
}
})
})
)
return {
domainName,
name: fileName,
lastModifiedTime: d.time,
url: baseUrl + `${appName}/files/${d.name}`,
}
})
.then(function (linkData) {
const baseUrl = `/user/system/goaccess/`

// Add in the live report for all sites even if it might not exist yet since they're dynamic
const allDomains = [
`${appName}.${dataStore.getRootDomain()}`,
...appDefinition!.customDomain.map((d) => d.publicDomain),
]
for (const domain of allDomains) {
const name =
loadBalanceManager.getLogName(appName, domain) + '--Live.html'
linkList.push({
domainName: domain,
name,
lastModifiedTime: new Date(),
url: baseUrl + `${appName}/files/${name}`,
const baseApi = new BaseApi(
ApiStatusCodes.STATUS_OK,
'GoAccess info retrieved'
)
const linkList = linkData.map((d) => {
const { domainName, fileName } =
loadBalanceManager.parseLogPath(d.name)
return {
domainName,
name: fileName,
lastModifiedTime: d.time,
url: baseUrl + `${appName}/files/${d.name}`,
}
})
}

linkList.sort(
(a, b) =>
b.lastModifiedTime.getTime() - a.lastModifiedTime.getTime()
)
// Add in the live report for all sites even if it might not exist yet since they're dynamic
const allDomains = [
`${appName}.${dataStore.getRootDomain()}`,
...appDefinition!.customDomain.map((d) => d.publicDomain),
]
for (const domain of allDomains) {
const name =
loadBalanceManager.getLogName(appName, domain) +
'--Live.html'
linkList.push({
domainName: domain,
name,
lastModifiedTime: new Date(),
url: baseUrl + `${appName}/files/${name}`,
})
}

baseApi.data = linkList
linkList.sort(
(a, b) =>
b.lastModifiedTime.getTime() - a.lastModifiedTime.getTime()
)

res.send(baseApi)
} catch (e) {
ApiStatusCodes.createCatcher(res)(e)
}
baseApi.data = linkList

res.send(baseApi)
})
.catch((e) => ApiStatusCodes.createCatcher(res)(e))
})

router.get('/goaccess/:appName/files/:file', async function (req, res, next) {
Expand Down

0 comments on commit 22e8074

Please sign in to comment.