47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
import express from 'express'
|
|
import cors from 'cors'
|
|
import { ensureDataFiles, readCache, readStatus } from './lib/cache.js'
|
|
|
|
const app = express()
|
|
app.use(cors())
|
|
app.use(express.json())
|
|
|
|
ensureDataFiles()
|
|
|
|
app.get('/api/qishier/all', (_req, res) => {
|
|
try {
|
|
const cache = readCache()
|
|
res.json({
|
|
updatedAt: cache.updatedAt,
|
|
name: cache.name || '七十二家房客',
|
|
coverUrl: cache.coverUrl || '',
|
|
displayType: cache.displayType || 0,
|
|
total: cache.items?.length || 0,
|
|
beginScoreMap: cache.beginScoreMap || {},
|
|
pages: cache.pages || {},
|
|
list: cache.items || []
|
|
})
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: '读取缓存失败',
|
|
error: error.message
|
|
})
|
|
}
|
|
})
|
|
|
|
app.get('/api/qishier/status', (_req, res) => {
|
|
try {
|
|
const status = readStatus()
|
|
res.json(status)
|
|
} catch (error) {
|
|
res.status(500).json({
|
|
message: '读取状态失败',
|
|
error: error.message
|
|
})
|
|
}
|
|
})
|
|
|
|
app.listen(3000, () => {
|
|
console.log('Node 服务已启动: http://localhost:3000')
|
|
})
|