فهرست منبع

refactor: 路由 /albums 重命名为 /books,与数据库表名一致

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
MyFramework User 3 ماه پیش
والد
کامیت
2eabf7764f

+ 1 - 1
my-uniapp-vue3/src/pages/book-generator/chapter-detail.vue

@@ -748,7 +748,7 @@ async function loadChapterWithParams(id: string, chapterIdParam: number) {
     }
 
     // 直接获取章节详情(只返回当前章节,不返回整书内容)
-    const chapterData = await get<any>(`/book-generator/albums/chapters/${chapterIdParam}`);
+    const chapterData = await get<any>(`/book-generator/books/chapters/${chapterIdParam}`);
     console.log('[ChapterDetail] chapter loaded via API:', chapterData);
 
     if (!chapterData) {

+ 3 - 3
my-uniapp-vue3/src/utils/book-generator-api.ts

@@ -173,7 +173,7 @@ export async function getBook(id: string): Promise<Book> {
  * 获取单个章节详情(从专辑控制器获取,只返回单章节内容)
  */
 export async function getChapter(chapterId: string): Promise<any> {
-  return await request<any>(`/book-generator/albums/chapters/${chapterId}`);
+  return await request<any>(`/book-generator/books/chapters/${chapterId}`);
 }
 
 /**
@@ -656,7 +656,7 @@ export function isBookFullyCompleted(genStage?: string): boolean {
  * 获取书籍完整信息(用于编辑)
  */
 export async function getBookForEdit(id: string): Promise<any> {
-  return await request<any>(`/book-generator/albums/${id}`);
+  return await request<any>(`/book-generator/books/${id}`);
 }
 
 /**
@@ -670,5 +670,5 @@ export async function updateBook(id: string, data: {
   style?: string;
   bookScale?: string;
 }): Promise<{ id: number; title: string }> {
-  return post(`/book-generator/albums/${id}`, data);
+  return post(`/book-generator/books/${id}`, data);
 }

+ 14 - 14
server/src/modules/book-generator/album-controller.ts

@@ -15,10 +15,10 @@ const TEST_USER_ID = '1';
 const router = new Router();
 
 /**
- * GET /api/book-generator/albums
+ * GET /api/book-generator/books
  * 获取专辑列表
  */
-router.get('/albums', async (ctx: Context) => {
+router.get('/books', async (ctx: Context) => {
   try {
     const books = await bookStore.getAllByUser();
     // 只返回基本信息
@@ -104,10 +104,10 @@ router.get('/list', optionalAuth, async (ctx: Context) => {
 });
 
 /**
- * POST /api/book-generator/albums
+ * POST /api/book-generator/books
  * 创建专辑
  */
-router.post('/albums', async (ctx: Context) => {
+router.post('/books', async (ctx: Context) => {
   try {
     const body = ctx.request.body as {
       title: string;
@@ -143,10 +143,10 @@ router.post('/albums', async (ctx: Context) => {
 });
 
 /**
- * GET /api/book-generator/albums/:id
+ * GET /api/book-generator/books/:id
  * 获取单个书籍详情(用于编辑页面回填)
  */
-router.get('/albums/:id', optionalAuth, async (ctx: Context) => {
+router.get('/books/:id', optionalAuth, async (ctx: Context) => {
   try {
     const bookId = parseInt(ctx.params.id as string);
     const book = await prisma.book.findUnique({
@@ -189,10 +189,10 @@ router.get('/albums/:id', optionalAuth, async (ctx: Context) => {
 });
 
 /**
- * PUT /api/book-generator/albums/:id
+ * PUT /api/book-generator/books/:id
  * 更新书籍(书名、描述等)
  */
-router.put('/albums/:id', optionalAuth, async (ctx: Context) => {
+router.put('/books/:id', optionalAuth, async (ctx: Context) => {
   try {
     const bookId = parseInt(ctx.params.id as string);
     const body = ctx.request.body as {
@@ -233,12 +233,12 @@ router.put('/albums/:id', optionalAuth, async (ctx: Context) => {
 });
 
 /**
- * GET /api/book-generator/albums/:id/chapters
+ * GET /api/book-generator/books/:id/chapters
  * 获取专辑章节列表
  * 返回章(level=1)的列表,每个章包含其下所有小节的合并音频
  * 过滤规则:公开的音频 + 当前用户自己的音频
  */
-router.get('/albums/:id/chapters', optionalAuth, async (ctx: Context) => {
+router.get('/books/:id/chapters', optionalAuth, async (ctx: Context) => {
   try {
     const bookId = ctx.params.id as string;
     const userId = ctx.state.user?.userId || TEST_USER_ID;
@@ -391,10 +391,10 @@ router.get('/albums/:id/chapters', optionalAuth, async (ctx: Context) => {
 });
 
 /**
- * POST /api/book-generator/albums/:id/chapters/:chapterId/merge-audio
+ * POST /api/book-generator/books/:id/chapters/:chapterId/merge-audio
  * 合并章下所有小节音频为单个文件
  */
-router.post('/albums/:id/chapters/:chapterId/merge-audio', optionalAuth, async (ctx: Context) => {
+router.post('/books/:id/chapters/:chapterId/merge-audio', optionalAuth, async (ctx: Context) => {
   try {
     const bookId = ctx.params.id as string;
     const chapterId = parseInt(ctx.params.chapterId as string);
@@ -478,10 +478,10 @@ router.post('/albums/:id/chapters/:chapterId/merge-audio', optionalAuth, async (
 });
 
 /**
- * GET /api/book-generator/albums/chapters/:id
+ * GET /api/book-generator/books/chapters/:id
  * 获取单个章节详情
  */
-router.get('/albums/chapters/:id', optionalAuth, async (ctx: Context) => {
+router.get('/books/chapters/:id', optionalAuth, async (ctx: Context) => {
   try {
     const chapterId = parseInt(ctx.params.id as string);