53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { app, cnb } from '../../app.ts';
|
|
|
|
app.route({
|
|
path: 'cnb',
|
|
key: 'repo-create',
|
|
description: '创建代码仓库, 参数name, visibility, description',
|
|
middleware: ['auth'],
|
|
metadata: {
|
|
tags: ['opencode']
|
|
}
|
|
}).define(async (ctx) => {
|
|
const name = ctx.query?.name;
|
|
const visibility = ctx.query?.visibility ?? 'private';
|
|
const description = ctx.query?.description ?? '';
|
|
|
|
if (!name) {
|
|
ctx.throw(400, '缺少参数 name');
|
|
}
|
|
|
|
const res = await cnb.repo.createRepo(cnb.group, {
|
|
name,
|
|
visibility,
|
|
description,
|
|
});
|
|
ctx.forward(res);
|
|
}).addTo(app);
|
|
|
|
app.route({
|
|
path: 'cnb',
|
|
key: 'repo-create-file',
|
|
description: '在代码仓库中创建文件, 参数repoName, path, content, encoding',
|
|
middleware: ['auth'],
|
|
metadata: {
|
|
tags: ['opencode']
|
|
}
|
|
}).define(async (ctx) => {
|
|
const repoName = ctx.query?.repoName;
|
|
const path = ctx.query?.path;
|
|
const content = ctx.query?.content;
|
|
const encoding = ctx.query?.encoding ?? 'raw';
|
|
|
|
if (!repoName || !path || !content) {
|
|
ctx.throw(400, '缺少参数 repoName, path 或 content');
|
|
}
|
|
|
|
const res = await cnb.repo.createCommit(repoName, {
|
|
message: `添加文件 ${path} 通过 API `,
|
|
files: [
|
|
{ path, content, encoding },
|
|
],
|
|
});
|
|
ctx.forward(res);
|
|
}).addTo(app); |