Commit 1920c417 authored by Chunchi Che's avatar Chunchi Che

try entertain match

parent 83aa5aaa
Pipeline #22773 passed with stages
in 14 minutes and 27 seconds
...@@ -2,18 +2,18 @@ import axios from "axios"; ...@@ -2,18 +2,18 @@ import axios from "axios";
const API_URL = "https://sapi.moecube.com:444/ygopro/match"; const API_URL = "https://sapi.moecube.com:444/ygopro/match";
interface MatchInfo { export interface MatchInfo {
ip: string; address: string;
port: number; port: number;
password: string; password: string;
} }
export async function match( export async function match(
userName: string, username: string,
extraId: number, extraId: number,
arena: string = "entertain" arena: string = "entertain"
): Promise<MatchInfo | undefined> { ): Promise<MatchInfo | undefined> {
const headers = { Authorization: "Basic " + btoa(userName + ":" + extraId) }; const headers = { Authorization: "Basic " + btoa(username + ":" + extraId) };
const response = await axios const response = await axios
.post(API_URL, undefined, { .post(API_URL, undefined, {
headers: headers, headers: headers,
...@@ -28,5 +28,5 @@ export async function match( ...@@ -28,5 +28,5 @@ export async function match(
return undefined; return undefined;
}); });
return response ? JSON.parse(response.data) : undefined; return response ? response.data : undefined;
} }
import React, { useEffect } from "react"; import React, { useEffect, useState } from "react";
import { match, MatchInfo } from "@/api";
interface SSOParams { interface SSOParams {
id: string; id: string;
...@@ -7,6 +9,7 @@ interface SSOParams { ...@@ -7,6 +9,7 @@ interface SSOParams {
email: string; email: string;
return_sso_url: string; return_sso_url: string;
token: string; token: string;
external_id: number;
} }
const Sso: React.FC = () => { const Sso: React.FC = () => {
...@@ -14,6 +17,12 @@ const Sso: React.FC = () => { ...@@ -14,6 +17,12 @@ const Sso: React.FC = () => {
const ssoParams: SSOParams | undefined = sso const ssoParams: SSOParams | undefined = sso
? getSSOParams(new URLSearchParams(atob(sso))) ? getSSOParams(new URLSearchParams(atob(sso)))
: undefined; : undefined;
const [matchInfo, setMatchInfo] = useState<MatchInfo | undefined>(undefined);
const onMatch = async () => {
if (ssoParams) {
setMatchInfo(await match(ssoParams.username, ssoParams.external_id));
}
};
useEffect(() => { useEffect(() => {
if (!sso) { if (!sso) {
...@@ -28,6 +37,11 @@ const Sso: React.FC = () => { ...@@ -28,6 +37,11 @@ const Sso: React.FC = () => {
<p>username={ssoParams?.username}</p> <p>username={ssoParams?.username}</p>
<p>name={ssoParams?.name}</p> <p>name={ssoParams?.name}</p>
<p>email={ssoParams?.email}</p> <p>email={ssoParams?.email}</p>
<button onClick={onMatch}>match</button>
<p>match info</p>
<p>address={matchInfo?.address}</p>
<p>port={matchInfo?.port}</p>
<p>password={matchInfo?.password}</p>
</div> </div>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment