|
@@ -15,13 +15,11 @@ const TEST_USER_ID = '1';
|
|
|
const router = new Router();
|
|
const router = new Router();
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * GET /api/book-generator/books
|
|
|
|
|
- * 获取专辑列表
|
|
|
|
|
|
|
+ * 获取专辑列表 handler
|
|
|
*/
|
|
*/
|
|
|
-router.get('/books', async (ctx: Context) => {
|
|
|
|
|
|
|
+async function getAlbums(ctx: Context) {
|
|
|
try {
|
|
try {
|
|
|
const books = await bookStore.getAllByUser();
|
|
const books = await bookStore.getAllByUser();
|
|
|
- // 只返回基本信息
|
|
|
|
|
const albums = books.map(book => ({
|
|
const albums = books.map(book => ({
|
|
|
id: book.id,
|
|
id: book.id,
|
|
|
title: book.title,
|
|
title: book.title,
|
|
@@ -37,7 +35,11 @@ router.get('/books', async (ctx: Context) => {
|
|
|
ctx.status = 500;
|
|
ctx.status = 500;
|
|
|
ctx.body = { code: 1, message: error instanceof Error ? error.message : '查询失败' };
|
|
ctx.body = { code: 1, message: error instanceof Error ? error.message : '查询失败' };
|
|
|
}
|
|
}
|
|
|
-});
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// GET /api/book-generator/books 和 /albums
|
|
|
|
|
+router.get('/books', getAlbums);
|
|
|
|
|
+router.get('/albums', getAlbums);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* GET /api/book-generator/list
|
|
* GET /api/book-generator/list
|
|
@@ -104,10 +106,9 @@ router.get('/list', optionalAuth, async (ctx: Context) => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * POST /api/book-generator/books
|
|
|
|
|
- * 创建专辑
|
|
|
|
|
|
|
+ * 创建专辑 handler
|
|
|
*/
|
|
*/
|
|
|
-router.post('/books', async (ctx: Context) => {
|
|
|
|
|
|
|
+async function createAlbum(ctx: Context) {
|
|
|
try {
|
|
try {
|
|
|
const body = ctx.request.body as {
|
|
const body = ctx.request.body as {
|
|
|
title: string;
|
|
title: string;
|
|
@@ -123,7 +124,7 @@ router.post('/books', async (ctx: Context) => {
|
|
|
const book = await bookStore.create({
|
|
const book = await bookStore.create({
|
|
|
title: body.title.trim(),
|
|
title: body.title.trim(),
|
|
|
description: body.description || '',
|
|
description: body.description || '',
|
|
|
- totalChapters: 0, // 初始为 0,等待添加章节
|
|
|
|
|
|
|
+ totalChapters: 0,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
ctx.body = {
|
|
ctx.body = {
|
|
@@ -140,7 +141,11 @@ router.post('/books', async (ctx: Context) => {
|
|
|
ctx.status = 500;
|
|
ctx.status = 500;
|
|
|
ctx.body = { code: 1, message: error instanceof Error ? error.message : '创建失败' };
|
|
ctx.body = { code: 1, message: error instanceof Error ? error.message : '创建失败' };
|
|
|
}
|
|
}
|
|
|
-});
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// POST /api/book-generator/books 和 /albums
|
|
|
|
|
+router.post('/books', createAlbum);
|
|
|
|
|
+router.post('/albums', createAlbum);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* GET /api/book-generator/books/:id
|
|
* GET /api/book-generator/books/:id
|