Files
monkey-ai-web/src/pages/ClientAuthorize/clientAuthorizeApi.js
T
zhanjunhao 2aa9d73325 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

38 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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);
}