fix: wait for config load

This commit is contained in:
Innei
2021-09-16 17:36:26 +08:00
parent 35343756f4
commit d786bf9619
5 changed files with 15 additions and 5 deletions

View File

@@ -1,6 +1,5 @@
import type { AxiosRequestConfig } from 'axios'
import { argv } from 'yargs'
import { isDev } from './utils/index.util'
console.log(argv)

View File

@@ -66,7 +66,7 @@ export class ConfigsService {
protected async configInit() {
const configs = await this.optionModel.find().lean()
configs.map((field) => {
configs.forEach((field) => {
const name = field.name as keyof IConfig
const value = field.value
this.config[name] = value

View File

@@ -197,7 +197,10 @@ export class MarkdownController {
return `/${(document as PageModel).slug}`
}
})()
const url = new URL(relativePath, this.configs.get('url').webUrl)
const {
url: { webUrl },
} = await this.configs.waitForConfigReady()
const url = new URL(relativePath, webUrl)
const html = minify(
`

View File

@@ -109,6 +109,7 @@ export class CronService {
return
}
const backupOptions = this.configs.get('backupOptions')
if (
!backupOptions.Bucket ||
!backupOptions.Region ||
@@ -140,7 +141,7 @@ export class CronService {
if (!err) {
this.logger.log('--> 上传成功')
} else {
this.logger.error('--> 上传失败了' + err.message)
this.logger.error('--> 上传失败了')
}
},
)

View File

@@ -1,3 +1,10 @@
export function getFolderSize(folderPath: string) {
return $`du -shc ${folderPath} | head -n 1 | cut -f1`
try {
return $`du -shc ${folderPath} | head -n 1 | cut -f1`
} catch (e: any) {
if (e.exitCode == 141) {
return e.stdout.trim()
}
return 'N/A'
}
}