feat: 更新助手配置,添加应用ID和URL,优化身份验证和代理逻辑
This commit is contained in:
@@ -9,18 +9,28 @@ import './hot-api/key-sender/index.ts';
|
||||
|
||||
import os from 'node:os';
|
||||
import { authCache } from '@/module/cache/auth.ts';
|
||||
export const getTokenUser = async (ctx: any) => {
|
||||
const getTokenUser = async (token: string) => {
|
||||
const query = assistantConfig.query
|
||||
const res = await query.post({
|
||||
path: 'user',
|
||||
key: 'me',
|
||||
token: ctx.state.token || ctx.query.token,
|
||||
token: token,
|
||||
});
|
||||
if (res.code !== 200) {
|
||||
return ctx.throw(401, 'not login');
|
||||
return res;
|
||||
}
|
||||
export const getTokenUserCache = async (token: string) => {
|
||||
const tokenUser = await authCache.get(token);
|
||||
if (tokenUser) {
|
||||
return {
|
||||
code: 200,
|
||||
data: tokenUser,
|
||||
};
|
||||
}
|
||||
const tokenUser = res.data || {};
|
||||
return tokenUser;
|
||||
const res = await getTokenUser(token);
|
||||
if (res.code === 200) {
|
||||
authCache.set(token, res.data);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
const checkAuth = async (ctx: any, isAdmin = false) => {
|
||||
const config = assistantConfig.getConfig();
|
||||
@@ -33,7 +43,12 @@ const checkAuth = async (ctx: any, isAdmin = false) => {
|
||||
// 鉴权代理
|
||||
let tokenUser = await authCache.get(token);
|
||||
if (!tokenUser) {
|
||||
tokenUser = await getTokenUser(ctx);
|
||||
const tokenUserRes = await getTokenUser(token);
|
||||
if (tokenUserRes.code !== 200) {
|
||||
return ctx.throw(tokenUserRes.code, 'not login');
|
||||
} else {
|
||||
tokenUser = tokenUserRes.data;
|
||||
}
|
||||
authCache.set(token, tokenUser);
|
||||
}
|
||||
ctx.state = {
|
||||
|
||||
Reference in New Issue
Block a user