From 27e5fb5e8205292e7153ae80ca5459bdfc3f9c8b Mon Sep 17 00:00:00 2001 From: abearxiong Date: Tue, 30 Dec 2025 00:46:07 +0800 Subject: [PATCH] remove --- src/routes/app-manager/list.ts | 8 +++++ src/routes/app-manager/user-app.ts | 3 ++ src/routes/config/config-key.ts | 4 +-- src/routes/config/list.ts | 4 +++ src/routes/config/share-config.ts | 1 + src/routes/config/upload-config.ts | 2 ++ src/routes/github/index.ts | 1 - src/routes/github/lib/get-token.ts | 50 ------------------------------ src/routes/github/list.ts | 48 ---------------------------- src/routes/github/models/github.ts | 45 --------------------------- 10 files changed, 19 insertions(+), 147 deletions(-) delete mode 100644 src/routes/github/index.ts delete mode 100644 src/routes/github/lib/get-token.ts delete mode 100644 src/routes/github/list.ts delete mode 100644 src/routes/github/models/github.ts diff --git a/src/routes/app-manager/list.ts b/src/routes/app-manager/list.ts index d5bb617..ca9ae68 100644 --- a/src/routes/app-manager/list.ts +++ b/src/routes/app-manager/list.ts @@ -11,6 +11,7 @@ app path: 'app', key: 'list', middleware: ['auth'], + description: '获取应用列表,根据key进行过滤', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; @@ -36,6 +37,7 @@ app path: 'app', key: 'get', middleware: ['auth'], + description: '获取应用详情,可以通过id,或者key+version来获取', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; @@ -68,6 +70,7 @@ app path: 'app', key: 'update', middleware: ['auth'], + description: '创建或更新应用信息,如果传入id则为更新,否则为创建', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; @@ -99,6 +102,7 @@ app path: 'app', key: 'delete', middleware: ['auth'], + description: '删除应用信息,如果应用已发布,则不允许删除', }) .define(async (ctx) => { const id = ctx.query.id; @@ -133,6 +137,7 @@ app path: 'app', key: 'canUploadFiles', middleware: ['auth'], + description: '检查是否可以上传文件,如果当前版本已存在,则不允许上传', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; @@ -153,6 +158,7 @@ app key: 'uploadFiles', middleware: ['auth'], isDebug: true, + description: '上传应用文件,如果应用版本不存在,则创建应用版本记录', }) .define(async (ctx) => { try { @@ -227,6 +233,7 @@ app path: 'app', key: 'publish', middleware: ['auth'], + description: '发布应用,将某个版本的应用设置为当前应用的版本', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; @@ -272,6 +279,7 @@ app .route({ path: 'app', key: 'getApp', + description: '获取应用信息,可以通过id,或者key+version来获取, 参数在data中传入', }) .define(async (ctx) => { const { user, key, id } = ctx.query.data; diff --git a/src/routes/app-manager/user-app.ts b/src/routes/app-manager/user-app.ts index 43c0383..9cf4828 100644 --- a/src/routes/app-manager/user-app.ts +++ b/src/routes/app-manager/user-app.ts @@ -8,6 +8,7 @@ app path: 'user-app', key: 'list', middleware: ['auth'], + description: '获取用户应用列表', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; @@ -63,6 +64,7 @@ app path: 'user-app', key: 'update', middleware: ['auth'], + description: '创建或更新用户应用,参数在data中传入', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; @@ -113,6 +115,7 @@ app path: 'user-app', key: 'delete', middleware: ['auth'], + description: '删除用户应用,可以指定id,参数:deleteFile表示是否删除文件,默认不删除', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; diff --git a/src/routes/config/config-key.ts b/src/routes/config/config-key.ts index 38017ad..34edd99 100644 --- a/src/routes/config/config-key.ts +++ b/src/routes/config/config-key.ts @@ -1,8 +1,5 @@ import { app } from '@/app.ts'; import { ConfigModel } from './models/model.ts'; -import { ShareConfigService } from './services/share.ts'; -import { oss } from '@/app.ts'; -import { ConfigOssService } from '@kevisual/oss/services'; import { User } from '@/models/user.ts'; import { defaultKeys } from './models/default-keys.ts'; @@ -11,6 +8,7 @@ app path: 'config', key: 'defaultConfig', middleware: ['auth'], + description: '获取默认配置项,可以指定configKey', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; diff --git a/src/routes/config/list.ts b/src/routes/config/list.ts index 5ea0206..8d0b236 100644 --- a/src/routes/config/list.ts +++ b/src/routes/config/list.ts @@ -9,6 +9,7 @@ app path: 'config', key: 'list', middleware: ['auth'], + description: '获取用户配置列表', }) .define(async (ctx) => { const { id } = ctx.state.tokenUser; @@ -29,6 +30,7 @@ app path: 'config', key: 'update', middleware: ['auth'], + description: '创建或更新用户配置,参数在data中传入', }) .define(async (ctx) => { const tokernUser = ctx.state.tokenUser; @@ -128,6 +130,7 @@ app path: 'config', key: 'get', middleware: ['auth'], + description: '获取用户配置,可以通过id或者key来获取', }) .define(async (ctx) => { const tokernUser = ctx.state.tokenUser; @@ -164,6 +167,7 @@ app path: 'config', key: 'delete', middleware: ['auth'], + description: '删除用户配置,可以通过id或者key来删除', }) .define(async (ctx) => { const tokernUser = ctx.state.tokenUser; diff --git a/src/routes/config/share-config.ts b/src/routes/config/share-config.ts index 9af16a0..e665616 100644 --- a/src/routes/config/share-config.ts +++ b/src/routes/config/share-config.ts @@ -5,6 +5,7 @@ app path: 'config', key: 'shareConfig', middleware: ['auth'], + description: '获取分享的配置,需要传入configKey和username参数', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; diff --git a/src/routes/config/upload-config.ts b/src/routes/config/upload-config.ts index 8dc2b1f..6c332a0 100644 --- a/src/routes/config/upload-config.ts +++ b/src/routes/config/upload-config.ts @@ -6,6 +6,7 @@ app path: 'config', key: 'getUploadConfig', middleware: ['auth'], + description: '获取用户上传配置,包括key、version、prefix等信息', }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; @@ -30,6 +31,7 @@ app path: 'config', key: 'updateUploadConfig', middleware: ['auth'], + description: '创建或更新用户上传配置,参数在data中传入', }) .define(async (ctx) => { const { id } = ctx.state.tokenUser; diff --git a/src/routes/github/index.ts b/src/routes/github/index.ts deleted file mode 100644 index 83ec5cd..0000000 --- a/src/routes/github/index.ts +++ /dev/null @@ -1 +0,0 @@ -import './list.ts'; diff --git a/src/routes/github/lib/get-token.ts b/src/routes/github/lib/get-token.ts deleted file mode 100644 index b2a79e3..0000000 --- a/src/routes/github/lib/get-token.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { useConfig } from '@kevisual/use-config'; - -type GithubConfig = { - clientId: string; - clientSecret: string; - redirect_uri: string; -}; -const { github } = useConfig<{ github: GithubConfig }>(); -// 获取 GitHub access_token 的函数 -async function getGithubToken(github: GithubConfig, code) { - const { clientId, clientSecret, redirect_uri } = github; - // 设置请求 URL 和参数 - const tokenUrl = 'https://github.com/login/oauth/access_token'; - const params = { - client_id: clientId, - client_secret: clientSecret, - code: code, - redirect_uri: redirect_uri, - }; - - try { - // 发送 POST 请求获取 access_token - const response = await fetch(tokenUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - body: JSON.stringify(params), - }); - - // 解析响应 JSON - const data: any = await response.json(); - - if (data.access_token) { - console.log('Access Token:', data.access_token); - return data.access_token; - } else { - console.error('Error:', data.error || 'Failed to get access token'); - return null; - } - } catch (error) { - console.error('Error fetching access token:', error); - return null; - } -} - -export const getAccessToken = async (code?: string) => { - return getGithubToken(github, code); -}; diff --git a/src/routes/github/list.ts b/src/routes/github/list.ts deleted file mode 100644 index 4c0b041..0000000 --- a/src/routes/github/list.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { app } from '@/app.ts'; -import { CustomError } from '@kevisual/router'; -import { getAccessToken } from './lib/get-token.ts'; -import { GithubModel } from './models/github.ts'; - -app - .route({ - path: 'github', - key: 'token', - middleware: ['auth'], - }) - .define(async (ctx) => { - const tokenUser = ctx.state.tokenUser; - const github = await GithubModel.findOne({ - where: { - uid: tokenUser.id, - }, - logging: false, - }); - if (github) { - ctx.body = { - githubToken: github.githubToken, - }; - return; - } - const { code } = ctx.query; - if (!code) { - throw new CustomError(400, 'code is required'); - } - try { - console.log('get access token from github, code:', code); - const token = await getAccessToken(code); - if (!token) { - throw new CustomError(500, 'Failed to get access token'); - } - await GithubModel.create({ - uid: tokenUser.id, - githubToken: token, - }); - ctx.body = { - githubToken: token, - }; - } catch (e) { - console.error('get access token from github error:', e); - throw new CustomError(500, 'Failed to get access token'); - } - }) - .addTo(app); diff --git a/src/routes/github/models/github.ts b/src/routes/github/models/github.ts deleted file mode 100644 index 7f1c15c..0000000 --- a/src/routes/github/models/github.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { sequelize } from '../../../modules/sequelize.ts'; -import { DataTypes, Model } from 'sequelize'; - -export type Github = Partial>; - -/** - * 用户代码容器 - */ -export class GithubModel extends Model { - declare id: string; - declare title: string; - declare githubToken: string; - declare uid: string; -} -GithubModel.init( - { - id: { - type: DataTypes.UUID, - primaryKey: true, - defaultValue: DataTypes.UUIDV4, - comment: 'id', - }, - title: { - type: DataTypes.STRING, - defaultValue: '', - }, - githubToken: { - type: DataTypes.STRING, - defaultValue: '', - }, - uid: { - type: DataTypes.UUID, - allowNull: true, - }, - }, - { - sequelize, - tableName: 'kv_github', - paranoid: true, - }, -); - -// GithubModel.sync({ alter: true, logging: false }).catch((e) => { -// console.error('GithubModel sync', e); -// });