remove
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,6 +5,7 @@ app
|
||||
path: 'config',
|
||||
key: 'shareConfig',
|
||||
middleware: ['auth'],
|
||||
description: '获取分享的配置,需要传入configKey和username参数',
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import './list.ts';
|
||||
@@ -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);
|
||||
};
|
||||
@@ -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);
|
||||
@@ -1,45 +0,0 @@
|
||||
import { sequelize } from '../../../modules/sequelize.ts';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
export type Github = Partial<InstanceType<typeof GithubModel>>;
|
||||
|
||||
/**
|
||||
* 用户代码容器
|
||||
*/
|
||||
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);
|
||||
// });
|
||||
Reference in New Issue
Block a user