XNSim/XNSimHtml/routes/planes.js

21 lines
706 B
JavaScript
Raw Normal View History

const express = require('express');
const router = express.Router();
const { getPlanes } = require('../utils/db-utils');
// 获取所有飞机列表
router.get('/planes', (req, res) => {
try {
const planes = getPlanes();
2025-05-16 15:30:54 +08:00
// 将BLOB数据转换为base64
const planesWithBase64 = planes.map(plane => ({
...plane,
Icon: plane.Icon ? `data:image/png;base64,${plane.Icon.toString('base64')}` : null
}));
res.json(planesWithBase64);
} catch (error) {
console.error('获取飞机列表失败:', error);
res.status(500).json({ error: '获取飞机列表失败', details: error.message });
}
});
module.exports = router;