From a1f6318d0c4b30293a643e250cd67ac556c565ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E4=BB=A3=E7=B6=BA=E5=87=9B?= Date: Thu, 26 Sep 2024 22:44:10 +0800 Subject: [PATCH] fix: skland generate cred by code fix #281 --- src/utils/skland.js | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/utils/skland.js b/src/utils/skland.js index e37f4042..2e2f6743 100644 --- a/src/utils/skland.js +++ b/src/utils/skland.js @@ -72,7 +72,7 @@ export async function fetchSkland(path, cred, token, body) { } : {}), headers: { - Cred: cred, + ...(cred ? { Cred: cred } : {}), ...(await sign(path, token)), ...(body ? { 'Content-Type': 'application/json' } : {}), }, @@ -87,10 +87,12 @@ export async function fetchSkland(path, cred, token, body) { } } -async function fetchSklandOAuthCode(token) { - if (!PROXY_SERVER) throw new Error('No proxy server.'); - - const res = await fetch(`${PROXY_SERVER}/as.hypergryph.com/user/oauth2/v2/grant`, { +/** + * @param {string} token + * @returns {{ cred: string, token: string }} + */ +export async function sklandOAuthLogin(token) { + const res = await fetch(`${PROXY_SERVER}/skland/oauth_combine`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -100,26 +102,13 @@ async function fetchSklandOAuthCode(token) { const data = await res.json(); - if (data.status === 0) { + if (data.code === 0) { return data.data; } else { - throw new SklandError(data.msg, data.status); + throw new SklandError(data.message, data.code); } } -/** - * @param {string} token - * @returns {{ cred: string, token: string }} - */ -export async function sklandOAuthLogin(token) { - const { code } = await fetchSklandOAuthCode(token); - - return await fetchSkland('/api/v1/user/auth/generate_cred_by_code', undefined, undefined, { - code, - kind: 1, - }); -} - /** * @param {SklandError} err */