fix:优化docker p配置
This commit is contained in:
12
server/db.js
12
server/db.js
@@ -162,4 +162,16 @@ try {
|
||||
`)
|
||||
} catch (_) {}
|
||||
|
||||
// 后台留言:供开发者收集用户反馈
|
||||
try {
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS feedback (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
content TEXT NOT NULL,
|
||||
ip TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
)
|
||||
`)
|
||||
} catch (_) {}
|
||||
|
||||
module.exports = db
|
||||
|
||||
@@ -8,6 +8,7 @@ const router = express.Router()
|
||||
router.get('/db/dashboard', (req, res) => {
|
||||
try {
|
||||
const tables = [
|
||||
'feedback',
|
||||
'situation',
|
||||
'force_summary',
|
||||
'power_index',
|
||||
@@ -23,6 +24,7 @@ router.get('/db/dashboard', (req, res) => {
|
||||
]
|
||||
const data = {}
|
||||
const timeSort = {
|
||||
feedback: 'created_at DESC',
|
||||
situation: 'updated_at DESC',
|
||||
situation_update: 'timestamp DESC',
|
||||
gdelt_events: 'event_time DESC',
|
||||
@@ -89,6 +91,23 @@ router.post('/visit', (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/feedback', (req, res) => {
|
||||
try {
|
||||
const content = (req.body?.content ?? '').toString().trim()
|
||||
if (!content || content.length > 2000) {
|
||||
return res.status(400).json({ ok: false, error: '留言内容 1–2000 字' })
|
||||
}
|
||||
const ip = getClientIp(req)
|
||||
db.prepare(
|
||||
'INSERT INTO feedback (content, ip) VALUES (?, ?)'
|
||||
).run(content.slice(0, 2000), ip)
|
||||
res.json({ ok: true })
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
res.status(500).json({ ok: false, error: err.message })
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/stats', (req, res) => {
|
||||
try {
|
||||
const viewers = db.prepare(
|
||||
|
||||
Reference in New Issue
Block a user