更新数据库配置,添加默认时间戳,优化轻代码路由处理,新增示例代码文件

This commit is contained in:
2026-01-26 03:46:32 +08:00
parent 0e350b1bca
commit 3464bd240b
5 changed files with 127 additions and 67 deletions

View File

@@ -81,6 +81,7 @@ app
path: 'light-code',
key: 'update',
middleware: ['auth'],
isDebug: true,
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -111,16 +112,28 @@ app
ctx.body = null;
}
} else {
const [created] = await db
.insert(schema.kvContainer)
.values({
...container,
uid: tokenUser.id,
})
.returning();
ctx.body = created;
try {
console.log('created', container, 'userId', tokenUser.id);
const [created] = await db
.insert(schema.kvContainer)
.values({
title: container.title || '',
description: container.description || '',
type: container.type || 'light-code',
code: container.code || '',
data: container.data || {},
tags: container.tags || [],
hash: container.hash || '',
uid: tokenUser.id,
})
.returning();
ctx.body = created;
} catch (error) {
console.error('Error creating container:', error);
throw error;
}
}
return ctx;
})
.addTo(app);