Commit 6be6ef36 authored by Chunchi Che's avatar Chunchi Che

add mdpro pullDecks api

parent e2380147
Pipeline #27582 passed with stages
in 7 minutes and 54 seconds
......@@ -36,6 +36,7 @@
"athleticWatchUrl": "wss://tiramisu.moecube.com:8923",
"entertainWatchUrl": "wss://tiramisu.moecube.com:7923",
"userApi": "https://sapi.moecube.com:444/accounts/users/{username}.json",
"mdproServer": "http://rarnu.xyz:38383",
"streamInterval": 20,
"startDelay": 1000,
"ui": {
......
......@@ -36,6 +36,7 @@
"athleticWatchUrl": "wss://tiramisu.moecube.com:8923",
"entertainWatchUrl": "wss://tiramisu.moecube.com:7923",
"userApi": "https://sapi.moecube.com:444/accounts/users/{username}.json",
"mdproServer": "http://rarnu.xyz:38383",
"streamInterval": 20,
"startDelay": 1000,
"ui": {
......
export * from "./cards";
export * from "./cookies";
export * from "./forbiddens";
export * from "./mdproDeck";
export * from "./mycard";
export * from "./ocgcore/idl/ocgcore";
export * from "./ocgcore/ocgHelper";
......
export * from "./pull";
import { useConfig } from "@/config";
import { MdproDeck } from "./schema";
import { mdproHeaders } from "./util";
const { mdproServer } = useConfig();
const API_PATH = "api/mdpro3/deck";
export interface PullReq {
page?: number;
size?: number;
keyWord?: number;
sortLike?: boolean;
sortRank?: boolean;
contributor?: string;
}
export interface PullResp {
code: number;
message: string;
data?: {
current: number;
size: number;
total: number;
pages: number;
records: MdproDeck[];
};
}
export async function pullDecks(req: PullReq): Promise<PullResp | undefined> {
const myHeaders = mdproHeaders();
const params = new URLSearchParams();
Object.entries(req).forEach(([key, value]) => {
if (value !== undefined) {
params.append(key, String(value));
}
});
const url = new URL(`${mdproServer}/${API_PATH}`);
url.search = params.toString();
const resp = await fetch(url.toString(), {
method: "GET",
headers: myHeaders,
redirect: "follow",
});
if (!resp.ok) {
console.error(`[Pull of Mdpro Decks] HTTPS error! status: ${resp.status}`);
return undefined;
} else {
return await resp.json();
}
}
export interface MdproDeck {
/*
*`ID` of the online deck.
* It is required when updating the deck, and optional
* when adding new deck. However, for the convenience,
* it is defined required here and it would be set to zero
* when adding new deck.
*/
deckId: string;
/* Contributor of the deck. */
deckContributor: string;
/* Name of the deck. */
deckName: string;
deckRank?: number;
deckLike?: number;
deckUploadDate?: string;
deckUpdateDate?: string;
/* Content of the deck. */
deckYdk: string;
}
export function mdproHeaders(): Headers {
const myHeaders = new Headers();
myHeaders.append("ReqSource", "MDPro3");
return myHeaders;
}
......@@ -3,6 +3,7 @@ import { LoaderFunction, useNavigate, useSearchParams } from "react-router-dom";
import { useSnapshot } from "valtio";
import { ygopro } from "@/api";
import { useEnv } from "@/hook";
import { AudioActionType, changeScene } from "@/infra/audio";
import { matStore, SideStage, sideStore } from "@/stores";
......@@ -24,7 +25,6 @@ import { AnnounceModal } from "./Message/AnnounceModal";
import { LifeBar, Mat, Menu, Underlying } from "./PlayMat";
import { ChatBox } from "./PlayMat/ChatBox";
import { HandChain } from "./PlayMat/HandChain";
import { useEnv } from "@/hook";
export const loader: LoaderFunction = async () => {
// 更新场景
......
......@@ -3,11 +3,11 @@ import React, { useEffect, useState } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
import { proxy, useSnapshot } from "valtio";
import { useEnv } from "@/hook";
import { replayStore } from "@/stores";
import { Uploader } from "../../Shared";
import { connectSrvpro } from "../util";
import { useEnv } from "@/hook";
const localStore = proxy({
open: false,
......
......@@ -16,6 +16,7 @@ import {
getJoinRoomPasswd,
getPrivateRoomID,
match,
pullDecks,
} from "@/api";
import { useConfig } from "@/config";
import { AudioActionType, changeScene } from "@/infra/audio";
......@@ -315,7 +316,15 @@ export const Component: React.FC = () => {
icon={<IconFont type="icon-record" size={24} />}
onClick={replayOpen}
/>
<Mode title={i18n("WIPTitle")} desc={i18n("WIPDesc")} icon={null} />
<Mode
title={i18n("WIPTitle")}
desc={i18n("WIPDesc")}
icon={null}
onClick={async () => {
const mdproDecks = await pullDecks({});
console.log(mdproDecks);
}}
/>
</div>
</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