feat: 添加构建时间信息和相关功能

This commit is contained in:
2026-03-20 22:40:11 +08:00
parent d8d323e293
commit d5dc47fc07
5 changed files with 50 additions and 6 deletions

2
back-end/dist/.env vendored
View File

@@ -12,7 +12,7 @@ APP_BASE_URL=https://bai-api.blv-oa.com
# Database Configuration (Pocketbase)
POCKETBASE_API_URL=https://bai-api.blv-oa.com/pb/
POCKETBASE_AUTH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2xsZWN0aW9uSWQiOiJfcGJfdXNlcnNfYXV0aF8iLCJleHAiOjE3NzQzNjEzMzIsImlkIjoiazQ0aHI5MW90bnBydG10IiwicmVmcmVzaGFibGUiOmZhbHNlLCJ0eXBlIjoiYXV0aCJ9.qm4E6xYrDbEpAfdxZnHHRZs_EqiwHgDIIwSBz2k90Nk
POCKETBASE_AUTH_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2xsZWN0aW9uSWQiOiJwYmNfMzE0MjYzNTgyMyIsImV4cCI6MTc3NDEwMTc4NiwiaWQiOiJmcnl2dG1qNnlwcHlmMXAiLCJyZWZyZXNoYWJsZSI6ZmFsc2UsInR5cGUiOiJhdXRoIn0.67DCKhqRQYF3ClPU_9mBgON_9ZDEy-NzqTeS50rGGZo
# WeChat Configuration
WECHAT_APPID=wx3bd7a7b19679da7a

3
back-end/dist/build-info.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"buildTime": "2026-03-20T14:36:26.964Z"
}

View File

@@ -57,6 +57,11 @@ components:
status:
type: string
example: success
build_time:
type: string
nullable: true
description: 最近一次构建时间;开发模式下若未执行构建则可能为空
format: date-time
WechatProfileRequest:
type: object
required: [users_name, users_phone_code, users_picture]
@@ -197,7 +202,7 @@ paths:
post:
tags: [系统]
summary: Test endpoint
description: Returns a hello world message
description: Returns a hello world message and build time
responses:
'200':
description: Successful response

View File

@@ -1,23 +1,29 @@
const express = require('express')
const { success } = require('../utils/response')
const { getBuildTimestamp } = require('../utils/buildInfo')
const wechatRoutes = require('./wechatRoutes')
const router = express.Router()
router.post('/test-helloworld', (req, res) => {
function respondHelloWorld(req, res) {
return success(res, '请求成功', {
message: 'Hello, World!',
timestamp: new Date().toISOString(),
status: 'success',
build_time: getBuildTimestamp(),
})
})
}
router.post('/health', (req, res) => {
function respondHealth(req, res) {
return success(res, '服务运行正常', {
status: 'healthy',
timestamp: new Date().toISOString(),
})
})
}
router.post('/test-helloworld', respondHelloWorld)
router.post('/health', respondHealth)
router.use('/wechat', wechatRoutes)

30
back-end/dist/src/utils/buildInfo.js vendored Normal file
View File

@@ -0,0 +1,30 @@
const fs = require('fs')
const path = require('path')
function getBuildInfoFilePath() {
return path.resolve(__dirname, '..', '..', 'build-info.json')
}
function getBuildTimestamp() {
if (process.env.BUILD_TIME) {
return process.env.BUILD_TIME
}
const filePath = getBuildInfoFilePath()
if (!fs.existsSync(filePath)) {
return null
}
try {
const content = fs.readFileSync(filePath, 'utf8')
const payload = JSON.parse(content)
return payload.buildTime || null
} catch {
return null
}
}
module.exports = {
getBuildTimestamp,
}