Browse Source

fix: 前端统一用 /books 替代 /albums,后端移除冗余别名

数据库表名为 book,API 路径应与之一致。7处前端调用
和4条后端别名全部修正。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
MyFramework User 3 months ago
parent
commit
b924a85c1c

+ 2 - 2
my-uniapp-vue3/src/pages/album/index.vue

@@ -279,7 +279,7 @@ async function fetchBookDetail() {
   loading.value = true;
   loading.value = true;
   try {
   try {
     // 调用专辑章节接口,返回章(level=1)列表,每个章包含小节音频
     // 调用专辑章节接口,返回章(level=1)列表,每个章包含小节音频
-    const data = await get(`/book-generator/albums/${bookId.value}/chapters`);
+    const data = await get(`/book-generator/books/${bookId.value}/chapters`);
     chapters.value = data?.chapters || [];
     chapters.value = data?.chapters || [];
     // 如果需要书籍基本信息,再调用getBook
     // 如果需要书籍基本信息,再调用getBook
     if (chapters.value.length > 0) {
     if (chapters.value.length > 0) {
@@ -296,7 +296,7 @@ async function fetchBookDetail() {
 // 加载专辑列表(用于移动章节)
 // 加载专辑列表(用于移动章节)
 async function fetchAlbumList() {
 async function fetchAlbumList() {
   try {
   try {
-    const data = await get('/book-generator/albums');
+    const data = await get('/book-generator/books');
     albumList.value = data?.albums?.filter((a: any) => a.id !== parseInt(bookId.value)) || [];
     albumList.value = data?.albums?.filter((a: any) => a.id !== parseInt(bookId.value)) || [];
   } catch (error) {
   } catch (error) {
     console.error('获取专辑列表失败:', error);
     console.error('获取专辑列表失败:', error);

+ 1 - 1
my-uniapp-vue3/src/pages/albums/index.vue

@@ -111,7 +111,7 @@ async function fetchAlbumList(isLoadMore = false) {
   loading.value = true;
   loading.value = true;
   try {
   try {
     // 调用专辑列表 API
     // 调用专辑列表 API
-    const result = await get<{ albums: any[] }>('/book-generator/albums');
+    const result = await get<{ albums: any[] }>('/book-generator/books');
     const books = result.albums || [];
     const books = result.albums || [];
 
 
     // 转换为 Album 格式
     // 转换为 Album 格式

+ 2 - 2
my-uniapp-vue3/src/pages/create/index.vue

@@ -377,7 +377,7 @@ const canGenerate = computed(() => {
 // 专辑相关函数
 // 专辑相关函数
 async function fetchAlbums() {
 async function fetchAlbums() {
   try {
   try {
-    const result = await get<{ albums: any[] }>('/book-generator/albums');
+    const result = await get<{ albums: any[] }>('/book-generator/books');
     albums.value = result.albums || [];
     albums.value = result.albums || [];
   } catch (error) {
   } catch (error) {
     console.error('获取专辑列表失败:', error);
     console.error('获取专辑列表失败:', error);
@@ -393,7 +393,7 @@ async function createAlbum() {
   if (!newAlbumTitle.value.trim()) return;
   if (!newAlbumTitle.value.trim()) return;
 
 
   try {
   try {
-    const result = await post<{ id: number | string; title: string; description?: string }>('/book-generator/albums', {
+    const result = await post<{ id: number | string; title: string; description?: string }>('/book-generator/books', {
       title: newAlbumTitle.value.trim(),
       title: newAlbumTitle.value.trim(),
       description: newAlbumDescription.value.trim(),
       description: newAlbumDescription.value.trim(),
     });
     });

+ 2 - 2
my-uniapp-vue3/src/pages/player/index.vue

@@ -461,7 +461,7 @@ async function fetchAlbumPlaylist(currentAudio: AudioItem) {
       // 由于 we're using chapter ID as audioId, try to get album info from chapters API
       // 由于 we're using chapter ID as audioId, try to get album info from chapters API
       // We'll use the current audioId to get chapter details and then album ID
       // We'll use the current audioId to get chapter details and then album ID
       try {
       try {
-        const chapterDetail = await get<any>(`/book-generator/albums/chapters/${audioId.value}`);
+        const chapterDetail = await get<any>(`/book-generator/books/chapters/${audioId.value}`);
         albumId = chapterDetail?.bookId; // The chapter detail now includes bookId
         albumId = chapterDetail?.bookId; // The chapter detail now includes bookId
       } catch (err) {
       } catch (err) {
         console.warn('无法通过章节ID获取专辑信息:', err);
         console.warn('无法通过章节ID获取专辑信息:', err);
@@ -475,7 +475,7 @@ async function fetchAlbumPlaylist(currentAudio: AudioItem) {
     }
     }
 
 
     // 获取专辑章节列表
     // 获取专辑章节列表
-    const data = await get<{ chapters: any[] }>(`/book-generator/albums/${albumId}/chapters`);
+    const data = await get<{ chapters: any[] }>(`/book-generator/books/${albumId}/chapters`);
     const chapters = data?.chapters || [];
     const chapters = data?.chapters || [];
 
 
     // 转换为播放列表格式
     // 转换为播放列表格式

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

@@ -37,9 +37,8 @@ async function getAlbums(ctx: Context) {
   }
   }
 }
 }
 
 
-// GET /api/book-generator/books 和 /albums
+// GET /api/book-generator/books
 router.get('/books', getAlbums);
 router.get('/books', getAlbums);
-router.get('/albums', getAlbums);
 
 
 /**
 /**
  * GET /api/book-generator/list
  * GET /api/book-generator/list
@@ -143,9 +142,8 @@ async function createAlbum(ctx: Context) {
   }
   }
 }
 }
 
 
-// POST /api/book-generator/books 和 /albums
+// POST /api/book-generator/books
 router.post('/books', createAlbum);
 router.post('/books', createAlbum);
-router.post('/albums', createAlbum);
 
 
 /**
 /**
  * GET /api/book-generator/books/:id
  * GET /api/book-generator/books/:id
@@ -366,9 +364,8 @@ async function getChapters(ctx: Context) {
   }
   }
 }
 }
 
 
-// GET /api/book-generator/books/:id/chapters 和 /albums/:id/chapters
+// GET /api/book-generator/books/:id/chapters
 router.get('/books/:id/chapters', optionalAuth, getChapters);
 router.get('/books/:id/chapters', optionalAuth, getChapters);
-router.get('/albums/:id/chapters', optionalAuth, getChapters);
 
 
 /**
 /**
  * POST /api/book-generator/books/:id/chapters/:chapterId/merge-audio
  * POST /api/book-generator/books/:id/chapters/:chapterId/merge-audio
@@ -500,8 +497,7 @@ async function getChapterDetail(ctx: Context) {
   }
   }
 }
 }
 
 
-// GET /api/book-generator/books/chapters/:id 和 /albums/chapters/:id
+// GET /api/book-generator/books/chapters/:id
 router.get('/books/chapters/:id', optionalAuth, getChapterDetail);
 router.get('/books/chapters/:id', optionalAuth, getChapterDetail);
-router.get('/albums/chapters/:id', optionalAuth, getChapterDetail);
 
 
 export default router;
 export default router;