feat: 添加作品/草稿/AI配额等后端API
This commit is contained in:
@@ -121,4 +121,64 @@ router.get('/endings', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 获取我的作品
|
||||
router.get('/my-works', async (req, res) => {
|
||||
try {
|
||||
const { userId } = req.query;
|
||||
const works = await UserModel.getMyWorks(parseInt(userId));
|
||||
res.json({ code: 0, data: works });
|
||||
} catch (err) {
|
||||
console.error('获取作品失败:', err);
|
||||
res.status(500).json({ code: 500, message: '获取作品失败' });
|
||||
}
|
||||
});
|
||||
|
||||
// 获取草稿箱
|
||||
router.get('/drafts', async (req, res) => {
|
||||
try {
|
||||
const { userId } = req.query;
|
||||
const drafts = await UserModel.getDrafts(parseInt(userId));
|
||||
res.json({ code: 0, data: drafts });
|
||||
} catch (err) {
|
||||
console.error('获取草稿失败:', err);
|
||||
res.status(500).json({ code: 500, message: '获取草稿失败' });
|
||||
}
|
||||
});
|
||||
|
||||
// 获取最近游玩
|
||||
router.get('/recent-played', async (req, res) => {
|
||||
try {
|
||||
const { userId, limit } = req.query;
|
||||
const recent = await UserModel.getRecentPlayed(parseInt(userId), parseInt(limit) || 10);
|
||||
res.json({ code: 0, data: recent });
|
||||
} catch (err) {
|
||||
console.error('获取最近游玩失败:', err);
|
||||
res.status(500).json({ code: 500, message: '获取最近游玩失败' });
|
||||
}
|
||||
});
|
||||
|
||||
// 获取AI创作历史
|
||||
router.get('/ai-history', async (req, res) => {
|
||||
try {
|
||||
const { userId, limit } = req.query;
|
||||
const history = await UserModel.getAIHistory(parseInt(userId), parseInt(limit) || 20);
|
||||
res.json({ code: 0, data: history });
|
||||
} catch (err) {
|
||||
console.error('获取AI历史失败:', err);
|
||||
res.status(500).json({ code: 500, message: '获取AI历史失败' });
|
||||
}
|
||||
});
|
||||
|
||||
// 获取AI配额
|
||||
router.get('/ai-quota', async (req, res) => {
|
||||
try {
|
||||
const { userId } = req.query;
|
||||
const quota = await UserModel.getAIQuota(parseInt(userId));
|
||||
res.json({ code: 0, data: quota });
|
||||
} catch (err) {
|
||||
console.error('获取AI配额失败:', err);
|
||||
res.status(500).json({ code: 500, message: '获取AI配额失败' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user