Undo refactor

This commit is contained in:
Dillon Shook
2025-01-05 09:59:23 -05:00
parent 3ffcd8edd9
commit 22e8074bfc

View File

@@ -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'
@@ -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 {
domainName,
name: fileName,
lastModifiedTime: d.time,
url: baseUrl + `${appName}/files/${d.name}`,
}
return Promise.resolve()
.then(function () {
// Ensure a valid appName parameter
return dataStore.getAppsDataStore().getAppDefinition(appName)
})
// 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}`,
.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,
}
})
})
)
})
.then(function (linkData) {
const baseUrl = `/user/system/goaccess/`
linkList.sort(
(a, b) =>
b.lastModifiedTime.getTime() - a.lastModifiedTime.getTime()
)
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}`,
}
})
baseApi.data = linkList
// 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}`,
})
}
res.send(baseApi)
} catch (e) {
ApiStatusCodes.createCatcher(res)(e)
}
linkList.sort(
(a, b) =>
b.lastModifiedTime.getTime() - a.lastModifiedTime.getTime()
)
baseApi.data = linkList
res.send(baseApi)
})
.catch((e) => ApiStatusCodes.createCatcher(res)(e))
})
router.get('/goaccess/:appName/files/:file', async function (req, res, next) {