gitee clientId默认第一个出现401则随机一个
This commit is contained in:
parent
bfb7a6447e
commit
7cd0cee836
@ -36,6 +36,18 @@ module.exports = (app) => {
|
||||
}), user.paypalIpn);
|
||||
app.get('/giteeClientId', (req, res) => {
|
||||
const giteeClientIds = conf.values.giteeClientId.split(',');
|
||||
// 仅一个 则直接返回
|
||||
if (giteeClientIds.length === 1) {
|
||||
res.send(giteeClientIds[0]);
|
||||
return;
|
||||
}
|
||||
// 是否随机一个clientId 默认第一个 如果random 为1 则使用随机 避免单个应用接口次数用满无法自动切换其他应用
|
||||
const random = req.query.random;
|
||||
if (!random) {
|
||||
res.send(giteeClientIds[0]);
|
||||
return;
|
||||
}
|
||||
// 随机一个
|
||||
const clientId = giteeClientIds[Math.floor((giteeClientIds.length * Math.random()))];
|
||||
res.send(clientId);
|
||||
});
|
||||
|
@ -68,12 +68,13 @@ export default {
|
||||
/**
|
||||
* https://developer.gitee.com/apps/building-oauth-apps/authorization-options-for-oauth-apps/
|
||||
*/
|
||||
async startOauth2(lastToken, silent = false, isMain) {
|
||||
async startOauth2(lastToken, silent = false, isMain, randomClientId) {
|
||||
let tokenBody;
|
||||
if (!silent) {
|
||||
const clientId = (await networkSvc.request({
|
||||
method: 'GET',
|
||||
url: 'giteeClientId',
|
||||
params: { random: randomClientId },
|
||||
})).body;
|
||||
// Get an OAuth2 code
|
||||
const { code } = await networkSvc.startOauth2(
|
||||
@ -119,7 +120,7 @@ export default {
|
||||
})).body;
|
||||
} catch (err) {
|
||||
if (err.status === 401) {
|
||||
this.startOauth2();
|
||||
this.startOauth2(null, false, isMain, 1);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
@ -219,7 +220,7 @@ export default {
|
||||
return tree;
|
||||
} catch (err) {
|
||||
if (err.status === 401) {
|
||||
this.startOauth2();
|
||||
this.startOauth2(null, false, null, 1);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user