init
This commit is contained in:
27
src/app.ts
Normal file
27
src/app.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { App } from "@kevisual/router";
|
||||
import { useContextKey } from "@kevisual/context";
|
||||
import { CNB } from "@kevisual/cnb";
|
||||
import { Gitea } from '@kevisual/gitea';
|
||||
import path from "node:path";
|
||||
|
||||
export const app = useContextKey("app", () => {
|
||||
const app = new App({
|
||||
});
|
||||
return app;
|
||||
});
|
||||
|
||||
export const cnb = useContextKey("cnb", () => {
|
||||
const token = useContextKey("CNB_API_KEY") || useContextKey('CNB_TOKEN')
|
||||
return new CNB({ token });
|
||||
});
|
||||
|
||||
export const gitea = useContextKey('gitea', () => {
|
||||
const GITEA_TOKEN = useContextKey("GITEA_TOKEN")
|
||||
const GITEA_URL = useContextKey("GITEA_URL")
|
||||
return new Gitea({
|
||||
token: GITEA_TOKEN,
|
||||
baseURL: GITEA_URL,
|
||||
})
|
||||
})
|
||||
|
||||
export const rootPath = path.join(process.cwd(), "storages");
|
||||
4
src/cli.ts
Normal file
4
src/cli.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { parse } from '@kevisual/router/commander'
|
||||
import { app } from './index.ts'
|
||||
|
||||
parse({ app })
|
||||
2
src/index.ts
Normal file
2
src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './app.ts';
|
||||
import './routes/cnb.ts';
|
||||
18
src/routes/cnb.ts
Normal file
18
src/routes/cnb.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { app, cnb } from '../app';
|
||||
import dayjs from 'dayjs';
|
||||
app.route({
|
||||
path: 'cnb',
|
||||
key: 'list-today',
|
||||
description: '获取今日更新的仓库列表',
|
||||
}).define(async (ctx) => {
|
||||
const res = await cnb.repo.getRepoList({ page_size: 100 });
|
||||
const today = dayjs().format('YYYY-MM-DD');
|
||||
const list = res.data || [];
|
||||
const todayList = list.filter(item => {
|
||||
const updatedAt = dayjs(item.updated_at).format('YYYY-MM-DD');
|
||||
return updatedAt === today;
|
||||
});
|
||||
ctx.body = {
|
||||
list: todayList,
|
||||
}
|
||||
}).addTo(app)
|
||||
Reference in New Issue
Block a user