增加搜索推荐
This commit is contained in:
@@ -51,6 +51,8 @@ backend/
|
||||
- `GET /api/artwork/:id/preview` - 获取作品预览
|
||||
- `GET /api/artwork/:id/images` - 获取作品图片URL
|
||||
- 参数: `size` (small/medium/large/original)
|
||||
- `GET /api/artwork/:id/related` - 获取相关推荐作品
|
||||
- 参数: `offset`, `limit`
|
||||
|
||||
### 排行榜相关
|
||||
|
||||
|
||||
@@ -266,4 +266,45 @@ router.post('/:id/bookmark', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取相关推荐作品
|
||||
* GET /api/artwork/:id/related
|
||||
*/
|
||||
router.get('/:id/related', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { offset = 0, limit = 30 } = req.query;
|
||||
|
||||
if (!id || isNaN(parseInt(id))) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: 'Invalid artwork ID'
|
||||
});
|
||||
}
|
||||
|
||||
const artworkService = new ArtworkService(req.backend.getAuth());
|
||||
const result = await artworkService.getRelatedArtworks(parseInt(id), {
|
||||
offset: parseInt(offset),
|
||||
limit: parseInt(limit)
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
res.json({
|
||||
success: true,
|
||||
data: result.data
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
error: result.error
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -366,6 +366,48 @@ class ArtworkService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关推荐作品
|
||||
*/
|
||||
async getRelatedArtworks(artworkId, options = {}) {
|
||||
try {
|
||||
const { offset = 0, limit = 30 } = options;
|
||||
|
||||
if (!artworkId || isNaN(parseInt(artworkId))) {
|
||||
return {
|
||||
success: false,
|
||||
error: 'Invalid artwork ID'
|
||||
};
|
||||
}
|
||||
|
||||
const params = {
|
||||
illust_id: parseInt(artworkId),
|
||||
offset: parseInt(offset),
|
||||
filter: 'for_ios'
|
||||
};
|
||||
|
||||
const response = await this.makeRequest('GET', '/v2/illust/related', params);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: {
|
||||
artworks: response.illusts || [],
|
||||
next_url: response.next_url,
|
||||
total: response.illusts ? response.illusts.length : 0,
|
||||
source_artwork_id: artworkId
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error('Get related artworks error:', error.message);
|
||||
logger.error('Get related artworks error details:', error.response?.data);
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: error.message || 'Failed to get related artworks'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送API请求
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user