格式修复,增加收藏页面

This commit is contained in:
2025-08-25 07:45:43 +08:00
parent 4d8f11e5cd
commit 67333b5f01
18 changed files with 632 additions and 324 deletions
+85
View File
@@ -65,6 +65,46 @@ router.get('/search', async (req, res) => {
}
});
/**
* 获取用户收藏的作品列表
* GET /api/artwork/bookmarks
*/
router.get('/bookmarks', async (req, res) => {
try {
const {
type = 'all',
offset = 0,
limit = 30
} = req.query;
const artworkService = new ArtworkService(req.backend.getAuth());
const result = await artworkService.getBookmarks({
type,
offset: parseInt(offset),
limit: parseInt(limit)
});
if (result.success) {
res.json({
success: true,
data: result.data
});
} else {
res.status(400).json({
success: false,
error: result.error
});
}
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
/**
* 获取作品详情
* GET /api/artwork/:id
@@ -181,4 +221,49 @@ router.get('/:id/images', async (req, res) => {
}
});
/**
* 收藏/取消收藏作品
* POST /api/artwork/:id/bookmark
*/
router.post('/:id/bookmark', async (req, res) => {
try {
const { id } = req.params;
const { action = 'add' } = req.body; // 'add' 或 'remove'
if (!id || isNaN(parseInt(id))) {
return res.status(400).json({
success: false,
error: 'Invalid artwork ID'
});
}
if (!['add', 'remove'].includes(action)) {
return res.status(400).json({
success: false,
error: 'Invalid action. Must be "add" or "remove"'
});
}
const artworkService = new ArtworkService(req.backend.getAuth());
const result = await artworkService.toggleBookmark(parseInt(id), action);
if (result.success) {
res.json({
success: true,
data: result.data
});
} else {
res.status(400).json({
success: false,
error: result.error
});
}
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
module.exports = router;