2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
// 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);
|
||
}
|