XNSim/XNSimHtml/routes/model-dev.js

82 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const express = require('express');
const router = express.Router();
const {
getATAChapters,
getModelsByChapterId,
getModelVersionsByClassName,
saveModelVersion
} = require('../utils/db-utils');
// 获取所有ATA章节
router.get('/ata-chapters', (req, res) => {
try {
const chapters = getATAChapters();
res.json(chapters);
} catch (error) {
console.error('处理ATA章节请求时出错:', error);
res.status(500).json({ error: '获取ATA章节数据失败', details: error.message });
}
});
// 获取指定章节ID的模型
router.get('/chapter-models/:chapterId', (req, res) => {
try {
const { chapterId } = req.params;
const { productName } = req.query;
if (!chapterId) {
return res.status(400).json({ error: '缺少章节ID参数' });
}
const models = getModelsByChapterId(chapterId, productName);
res.json(models);
} catch (error) {
console.error('处理章节模型请求时出错:', error);
res.status(500).json({ error: '获取章节模型数据失败', details: error.message });
}
});
// 获取指定ClassName的模型版本
router.get('/model-versions/:className', (req, res) => {
try {
const className = req.params.className;
const { productName } = req.query;
if (!className) {
return res.status(400).json({ error: '模型类名不能为空' });
}
const versions = getModelVersionsByClassName(className, productName);
res.json(versions);
} catch (error) {
console.error(`获取模型版本失败: ${error.message}`);
res.status(500).json({ error: '获取模型版本失败', details: error.message });
}
});
// 保存模型版本信息
router.post('/model-versions', (req, res) => {
try {
const versionData = req.body;
const { productName } = req.query;
if (!versionData || !versionData.ClassName) {
return res.status(400).json({ error: '缺少必要的模型版本数据' });
}
// 如果请求中没有productName则使用versionData中的ProductName
if (!productName && versionData.ProductName) {
versionData.ProductName = versionData.ProductName;
} else if (productName) {
versionData.ProductName = productName;
}
const result = saveModelVersion(versionData);
res.json(result);
} catch (error) {
console.error(`保存模型版本失败: ${error.message}`);
res.status(500).json({ error: '保存模型版本失败', details: error.message });
}
});
module.exports = router;