commit 819cbcebacf4229ece8d02d3fadb1e4e7bce9613 Author: xiongxiao Date: Wed Mar 18 00:49:20 2026 +0800 init diff --git a/.cnb.yml b/.cnb.yml new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea4f1c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules + +storages \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..45cf440 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# 自有gitea仓库 + +需要把cnb存放的自动化的更新同步到自己的gitea仓库中,方便自己使用和修改。 + +## 同步方式 + +clone下来后,直接push到自己的gitea仓库中即可。 + +### 整个步骤 + +1. 获取当天的有更新的仓库 +2. clone下来 +3. push到自己的gitea仓库中 \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4211ee6 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "to-my-gitea", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "abearxiong (https://www.xiongxiao.me)", + "license": "MIT", + "packageManager": "pnpm@10.32.1", + "type": "module", + "dependencies": { + "@kevisual/cnb": "^0.0.51", + "@kevisual/context": "^0.0.8", + "@kevisual/gitea": "^0.0.6", + "@kevisual/router": "^0.1.3", + "dayjs": "^1.11.20" + } +} diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..60bbd71 --- /dev/null +++ b/src/app.ts @@ -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"); \ No newline at end of file diff --git a/src/cli.ts b/src/cli.ts new file mode 100644 index 0000000..d3b7efb --- /dev/null +++ b/src/cli.ts @@ -0,0 +1,4 @@ +import { parse } from '@kevisual/router/commander' +import { app } from './index.ts' + +parse({ app }) \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..86d9330 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +export * from './app.ts'; +import './routes/cnb.ts'; \ No newline at end of file diff --git a/src/routes/cnb.ts b/src/routes/cnb.ts new file mode 100644 index 0000000..823f028 --- /dev/null +++ b/src/routes/cnb.ts @@ -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) \ No newline at end of file