remove old apps

This commit is contained in:
2026-01-26 03:01:29 +08:00
parent a9d725eb29
commit 4bc58460b4
15 changed files with 152 additions and 1155 deletions

View File

@@ -10,6 +10,7 @@ import './config/index.ts';
// import './file-listener/index.ts';
import './light-code/index.ts';
import './ai/index.ts';

View File

@@ -0,0 +1,151 @@
import { eq, desc, and, like, or } from 'drizzle-orm';
import { CustomError } from '@kevisual/router';
import { app, db, schema } from '../../app.ts';
app
.route({
path: 'light-code',
key: 'list',
description: `获取轻代码列表,参数
type: 代码类型light-code, ts`,
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const { type, search } = ctx.query || {};
const conditions = [eq(schema.kvContainer.uid, tokenUser.id)];
if (type) {
conditions.push(eq(schema.kvContainer.type, type as string));
}
if (search) {
const searchTerm = `%${search}%`;
conditions.push(
or(
like(schema.kvContainer.title, searchTerm),
like(schema.kvContainer.description, searchTerm),
),
);
}
const list = await db
.select({
id: schema.kvContainer.id,
title: schema.kvContainer.title,
description: schema.kvContainer.description,
type: schema.kvContainer.type,
tags: schema.kvContainer.tags,
data: schema.kvContainer.data,
uid: schema.kvContainer.uid,
createdAt: schema.kvContainer.createdAt,
updatedAt: schema.kvContainer.updatedAt,
hash: schema.kvContainer.hash,
})
.from(schema.kvContainer)
.where(and(...conditions))
.orderBy(desc(schema.kvContainer.updatedAt));
ctx.body = list;
return ctx;
})
.addTo(app);
app
.route({
path: 'light-code',
key: 'get',
description: '获取轻代码详情',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const id = ctx.query.id;
if (!id) {
throw new CustomError('id is required');
}
const result = await db
.select()
.from(schema.kvContainer)
.where(eq(schema.kvContainer.id, id))
.limit(1);
const container = result[0];
if (!container) {
ctx.throw('未发现该代码内容');
}
if (container.uid !== tokenUser.id) {
ctx.throw('没有权限访问该代码内容');
}
ctx.body = container;
})
.addTo(app);
app
.route({
path: 'light-code',
key: 'update',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const data = ctx.query.data;
const { id, ...container } = data;
if (id) {
const result = await db
.select()
.from(schema.kvContainer)
.where(eq(schema.kvContainer.id, id))
.limit(1);
const existing = result[0];
if (existing) {
await db
.update(schema.kvContainer)
.set({
...container,
updatedAt: new Date().toISOString(),
})
.where(eq(schema.kvContainer.id, id));
const updated = await db
.select()
.from(schema.kvContainer)
.where(eq(schema.kvContainer.id, id))
.limit(1);
ctx.body = updated[0];
} else {
ctx.body = null;
}
} else {
const [created] = await db
.insert(schema.kvContainer)
.values({
...container,
uid: tokenUser.id,
})
.returning();
ctx.body = created;
}
return ctx;
})
.addTo(app);
app
.route({
path: 'container',
key: 'delete',
middleware: ['auth'],
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const id = ctx.query.id;
const result = await db
.select()
.from(schema.kvContainer)
.where(eq(schema.kvContainer.id, id))
.limit(1);
const container = result[0];
if (!container) {
ctx.throw('未发现该容器');
}
if (container.uid !== tokenUser.id) {
ctx.throw('没有权限访问该容器');
}
await db.delete(schema.kvContainer).where(eq(schema.kvContainer.id, id));
ctx.body = container;
})
.addTo(app);