重构用户和笔记相关的数据库模式,更新字段名称;优化路由描述,添加新搜索功能;调整浏览器启动参数,简化调试信息

This commit is contained in:
2026-01-07 01:49:49 +08:00
parent 2621d0229f
commit e5ddd01fd2
7 changed files with 98 additions and 138 deletions

View File

@@ -6,7 +6,12 @@ app.route({
path: 'xhs-users',
key: 'list',
middleware: ['auth'],
description: '获取小红书用户列表',
description: `获取小红书用户列表, 参数说明:
page: 页码默认1
pageSize: 每页数量默认20
search: 搜索关键词,模糊匹配昵称、用户名和描述
sort: 排序方式ASC或DESC默认DESC按更新时间降序
`,
metadata: {
tags: ['小红书', '用户'],
}
@@ -66,11 +71,11 @@ app.route({
tags: ['小红书', '用户'],
}
}).define(async (ctx) => {
const { user_id, createdAt, updatedAt, ...rest } = ctx.query.data || {};
const { id, createdAt, updatedAt, ...rest } = ctx.query.data || {};
let user;
if (!user_id) {
if (!id) {
user = await db.insert(xhsUser).values({
user_id: rest.user_id || `user_${Date.now()}`,
id: rest.id || `user_${Date.now()}`,
nickname: rest.nickname || '',
username: rest.username || '',
avatar: rest.avatar || '',
@@ -85,7 +90,7 @@ app.route({
updatedAt: Date.now(),
}).returning();
} else {
const existing = await db.select().from(xhsUser).where(eq(xhsUser.user_id, user_id)).limit(1);
const existing = await db.select().from(xhsUser).where(eq(xhsUser.id, id)).limit(1);
if (existing.length === 0) {
ctx.throw(404, '没有找到对应的用户');
}
@@ -99,7 +104,7 @@ app.route({
link: rest.link,
data: rest.data ? JSON.stringify(rest.data) : undefined,
updatedAt: Date.now(),
}).where(eq(xhsUser.user_id, user_id)).returning();
}).where(eq(xhsUser.id, id)).returning();
}
ctx.body = user;
}).addTo(app);
@@ -109,20 +114,20 @@ app.route({
path: 'xhs-users',
key: 'delete',
middleware: ['auth'],
description: '删除小红书用户, 参数: data.user_id 用户ID',
description: '删除小红书用户, 参数: data.id 用户ID',
metadata: {
tags: ['小红书', '用户'],
}
}).define(async (ctx) => {
const { user_id } = ctx.query.data || {};
if (!user_id) {
ctx.throw(400, 'user_id 参数缺失');
const { id } = ctx.query.data || {};
if (!id) {
ctx.throw(400, 'id 参数缺失');
}
const existing = await db.select().from(xhsUser).where(eq(xhsUser.user_id, user_id)).limit(1);
const existing = await db.select().from(xhsUser).where(eq(xhsUser.id, id)).limit(1);
if (existing.length === 0) {
ctx.throw(404, '没有找到对应的用户');
}
await db.delete(xhsUser).where(eq(xhsUser.user_id, user_id));
await db.delete(xhsUser).where(eq(xhsUser.id, id));
ctx.body = { success: true };
}).addTo(app);
@@ -130,16 +135,16 @@ app.route({
path: 'xhs-users',
key: 'get',
middleware: ['auth'],
description: '获取单个小红书用户, 参数: data.user_id 用户ID',
description: '获取单个小红书用户, 参数: data.id 用户ID',
metadata: {
tags: ['小红书', '用户'],
}
}).define(async (ctx) => {
const { user_id } = ctx.query.data || {};
if (!user_id) {
ctx.throw(400, 'user_id 参数缺失');
const { id } = ctx.query.data || {};
if (!id) {
ctx.throw(400, 'id 参数缺失');
}
const existing = await db.select().from(xhsUser).where(eq(xhsUser.user_id, user_id)).limit(1);
const existing = await db.select().from(xhsUser).where(eq(xhsUser.id, id)).limit(1);
if (existing.length === 0) {
ctx.throw(404, '没有找到对应的用户');
}