perf: 优化github app 并增加白名单模糊匹配

pull/70/head
moonrailgun 2 years ago
parent 4d554df237
commit f77d267f80

@ -21,6 +21,8 @@ if (
const defaultTailchatApiUrl = process.env.TAILCHAT_API_URL;
const tailchatAppId = process.env.TAILCHAT_APP_ID;
const tailchatAppSecret = process.env.TAILCHAT_APP_SECRET;
const tailchatWebUrl =
process.env.TAILCHAT_WEB_URL || process.env.TAILCHAT_API_URL;
export function app(app: Probot) {
app.on('issues.opened', async (ctx) => {
@ -70,7 +72,7 @@ export function app(app: Probot) {
await Promise.all([
ctx.octokit.issues.createComment(
ctx.issue({
body: 'Thanks for opening this issue! Tailchat topic is created!',
body: `Thanks for opening this issue! Tailchat topic is created in ${tailchatWebUrl}/main/group/${groupId}/${panelId}!`,
})
),
ctx.octokit.issues.addLabels(
@ -160,6 +162,8 @@ export function app(app: Probot) {
/**
*
*
* serverless
*/
function createTailchatContextWithConfig(githubRaw: string) {
const content = Buffer.from(githubRaw, 'base64').toString();

@ -4,6 +4,7 @@ import crypto from 'crypto';
export class TailchatClient {
request: AxiosInstance;
jwt: string | null = null;
userId: string | null = null;
loginP: Promise<void>;
constructor(
@ -37,6 +38,7 @@ export class TailchatClient {
async login() {
try {
console.log('正在登录...');
const { data } = await this.request.post('/api/openapi/bot/login', {
appId: this.appId,
token: this.getBotToken(),
@ -52,7 +54,7 @@ export class TailchatClient {
this.whoami().then(console.log);
} catch (err) {
console.error(err);
throw err;
throw new Error('登录失败, 请检查应用凭证');
}
}
@ -67,7 +69,7 @@ export class TailchatClient {
return data;
} catch (err: any) {
console.error('服务调用失败');
console.error('服务调用失败:', err);
const data: string = err?.response?.data;
if (data) {
throw new Error(

@ -64,5 +64,9 @@ export function sleep(ms: number): Promise<void> {
* url
*/
export function checkPathMatch(urlList: string[], url: string): boolean {
return urlList.includes(url.split('?')[0]);
const fuzzList = urlList.map((url) => url.replaceAll('/', '.'));
const fuzzUrl = url.split('?')[0].replaceAll('/', '.');
// 考虑到serviceName中间可能会有. 且注册的时候不可能把所有情况都列出来,因此进行模糊处理
return fuzzList.includes(fuzzUrl);
}

@ -24,7 +24,7 @@ class OpenBotService extends TcService {
visibility: 'public',
});
this.registerAuthWhitelist(['/bot/login']);
this.registerAuthWhitelist(['/login']);
}
/**
@ -59,7 +59,7 @@ class OpenBotService extends TcService {
avatar,
});
return { jwt };
return { jwt, userId, email, nickname, avatar };
}
/**

Loading…
Cancel
Save