Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
// WeyAi 客户端授权页(/client/authorize)的接口封装。
|
||||
// 接口约定见 WeyAi 仓库 docs/fork/账号登录接入方案.md 4.2、4.4:
|
||||
// 成功 { success: true, data };失败 { success: false, code, message, data },
|
||||
// 客户端只按 code 分支。
|
||||
|
||||
import { API } from '../../helpers/api';
|
||||
import { buildContextQuery } from './authorizeParams';
|
||||
|
||||
function unwrap(res) {
|
||||
const body = res?.data;
|
||||
if (body && body.success === false) {
|
||||
const err = new Error(body.message || 'request failed');
|
||||
err.response = res;
|
||||
throw err;
|
||||
}
|
||||
// 兼容 { success, data } 与直接返回数据两种形态
|
||||
if (body && typeof body === 'object' && 'data' in body) {
|
||||
return body.data;
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
export async function fetchOAuthContext(params) {
|
||||
const res = await API.get('/api/client/v1/oauth/context', {
|
||||
params: buildContextQuery(params),
|
||||
skipErrorHandler: true,
|
||||
disableDuplicate: true,
|
||||
});
|
||||
return unwrap(res);
|
||||
}
|
||||
|
||||
export async function submitAuthorize(payload) {
|
||||
const res = await API.post('/api/client/v1/oauth/authorize', payload, {
|
||||
skipErrorHandler: true,
|
||||
});
|
||||
return unwrap(res);
|
||||
}
|
||||
Reference in New Issue
Block a user