From 99141a926e6d81906b1ce2ead4964e59be5bbc23 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Thu, 12 Mar 2026 00:55:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20flowme-channel=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8C=85=E6=8B=AC=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E3=80=81=E5=88=9B=E5=BB=BA=E3=80=81=E6=9B=B4=E6=96=B0=E5=92=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8E=A5=E5=8F=A3=EF=BC=9B=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20flowme=20=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4=E5=92=8C?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/schemas/life-schema.ts | 2 +- .../{flowme => }/flowme-channel/list.ts | 0 src/routes/flowme/index.ts | 2 +- src/routes/flowme/list.ts | 54 +++++++++++++------ 4 files changed, 41 insertions(+), 17 deletions(-) rename src/routes/{flowme => }/flowme-channel/list.ts (100%) diff --git a/src/db/schemas/life-schema.ts b/src/db/schemas/life-schema.ts index 428d171..22a5e00 100644 --- a/src/db/schemas/life-schema.ts +++ b/src/db/schemas/life-schema.ts @@ -45,7 +45,7 @@ export const flowme = pgTable("flowme", { data: jsonb().default({}), channelId: uuid().references(() => flowmeChannels.id, { onDelete: 'set null' }), - type: text('type').default(''), + type: text('type').default(''), // muse, source: text('source').default(''), importance: integer('importance').default(0), // 重要性等级 isArchived: boolean('isArchived').default(false), // 是否归档 diff --git a/src/routes/flowme/flowme-channel/list.ts b/src/routes/flowme-channel/list.ts similarity index 100% rename from src/routes/flowme/flowme-channel/list.ts rename to src/routes/flowme-channel/list.ts diff --git a/src/routes/flowme/index.ts b/src/routes/flowme/index.ts index 4550f9f..792e70d 100644 --- a/src/routes/flowme/index.ts +++ b/src/routes/flowme/index.ts @@ -2,4 +2,4 @@ import './list.ts' // flowme channel 相关路由 -import './flowme-channel/list.ts' \ No newline at end of file +import '../flowme-channel/list.ts' \ No newline at end of file diff --git a/src/routes/flowme/list.ts b/src/routes/flowme/list.ts index bfc3d02..763e075 100644 --- a/src/routes/flowme/list.ts +++ b/src/routes/flowme/list.ts @@ -1,4 +1,4 @@ -import { desc, eq, count, or, like, and } from 'drizzle-orm'; +import { desc, eq, or, like, and, gte, lte } from 'drizzle-orm'; import { schema, app, db } from '@/app.ts' import z from 'zod'; @@ -11,16 +11,21 @@ app.route({ metadata: { args: { page: z.number().describe('页码, 默认为 1').optional(), - pageSize: z.number().describe('每页数量, 默认为 20').optional(), + pageSize: z.number().describe('每页数量, 默认为 100').optional(), search: z.string().describe('搜索关键词').optional(), channelId: z.string().describe('频道ID').optional(), + type: z.string().describe('类型').optional(), sort: z.enum(['ASC', 'DESC']).describe('排序方式,ASC 或 DESC,默认为 DESC').optional(), + timeRange: z.object({ + from: z.string().describe('开始时间,ISO 格式').optional(), + to: z.string().describe('结束时间,ISO 格式').optional(), + }).describe('时间范围过滤').optional(), } } }).define(async (ctx) => { const tokenUser = ctx.state.tokenUser; const uid = tokenUser.id; - const { page = 1, pageSize = 20, search, channelId, sort = 'DESC' } = ctx.query || {}; + const { page = 1, pageSize = 100, search, channelId, type, sort = 'DESC', timeRange } = ctx.query || {}; const offset = (page - 1) * pageSize; const orderByField = sort === 'ASC' ? schema.flowme.updatedAt : desc(schema.flowme.updatedAt); @@ -41,18 +46,37 @@ app.route({ eq(schema.flowme.channelId, channelId) ); } + if (type) { + whereCondition = and( + whereCondition, + eq(schema.flowme.type, type) + ); + } + if (timeRange) { + const { from, to } = timeRange; + if (from) { + whereCondition = and( + whereCondition, + gte(schema.flowme.updatedAt, new Date(from)) + ); + } + if (to) { + whereCondition = and( + whereCondition, + lte(schema.flowme.updatedAt, new Date(to)) + ); + } + } - const [list, totalCount] = await Promise.all([ - db.select() - .from(schema.flowme) - .where(whereCondition) - .limit(pageSize) - .offset(offset) - .orderBy(orderByField), - db.select({ count: count() }) - .from(schema.flowme) - .where(whereCondition) - ]); + const rows = await db.select() + .from(schema.flowme) + .where(whereCondition) + .limit(pageSize + 1) + .offset(offset) + .orderBy(orderByField); + + const hasMore = rows.length > pageSize; + const list = hasMore ? rows.slice(0, pageSize) : rows; ctx.body = { list, @@ -60,7 +84,7 @@ app.route({ page, current: page, pageSize, - total: totalCount[0]?.count || 0, + hasMore, }, }; return ctx;