Commit 5d3048b6 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/online_deck' into 'main'

修复Mdpro在线卡组接口变动后带来的兼容性问题

See merge request !382
parents 0cb3e38c 5120df34
export * from "./mget";
export * from "./pull";
export * from "./update";
export * from "./upload";
import { useConfig } from "@/config";
import { MdproDeck } from "./schema";
import { mdproHeaders } from "./util";
const { mdproServer } = useConfig();
const API_PATH = "/api/mdpro3/deck";
interface MgetResp {
code: number;
message: string;
data?: MdproDeck;
}
export async function mgetDeck(id: string): Promise<MgetResp | undefined> {
const myHeaders = mdproHeaders();
const resp = await fetch(`${mdproServer}/${API_PATH}/${id}`, {
method: "GET",
headers: myHeaders,
redirect: "follow",
});
if (!resp.ok) {
console.error(`[Mget of Mdpro Decks] HTTPS error! status: ${resp.status}`);
return undefined;
} else {
return await resp.json();
}
}
......@@ -16,6 +16,6 @@ export interface MdproDeck {
deckUploadDate?: string;
deckUpdateDate?: string;
/* Content of the deck. */
deckYdk: string;
deckYdk?: string;
deckCase: number;
}
......@@ -3,7 +3,7 @@ import React, { memo, useEffect } from "react";
import { type INTERNAL_Snapshot as Snapshot, proxy, useSnapshot } from "valtio";
import YGOProDeck from "ygopro-deck-encode";
import { pullDecks } from "@/api";
import { mgetDeck, pullDecks } from "@/api";
import { MdproDeck } from "@/api/mdproDeck/schema";
import { useConfig } from "@/config";
import { IconFont } from "@/ui/Shared";
......@@ -120,17 +120,30 @@ const MdproDeckBlock: React.FC<Snapshot<MdproDeck>> = (deck) => (
);
const copyMdproDeckToEditing = async (mdproDeck: MdproDeck) => {
const deck = YGOProDeck.fromYdkString(mdproDeck.deckYdk);
// currently the content of the deck, which we named `Ydk`,
// haven't been downloaded, so we need to fetch from server again by `mgetDeck`
// API.
if (!(deck.main.length + deck.extra.length + deck.side.length === 0)) {
const deckName = mdproDeck.deckName;
const ideck = { deckName, ...deck };
const editingDeck = await iDeckToEditingDeck(ideck);
const deckID = mdproDeck.deckId;
const resp = await mgetDeck(deckID);
setSelectedDeck(ideck);
editDeckStore.set(editingDeck);
if (resp?.code !== 0) {
message.error(resp?.message);
} else if (resp.data?.deckYdk !== undefined) {
const deck = YGOProDeck.fromYdkString(resp.data.deckYdk);
if (!(deck.main.length + deck.extra.length + deck.side.length === 0)) {
const deckName = mdproDeck.deckName;
const ideck = { deckName, ...deck };
const editingDeck = await iDeckToEditingDeck(ideck);
setSelectedDeck(ideck);
editDeckStore.set(editingDeck);
} else {
message.error("卡组解析失败,请联系技术人员解决:<ccc@neos.moe>");
}
} else {
message.error("卡组解析失败,请联系技术人员解决:<ccc@neos.moe>");
message.error("卡组复制失败,请联系技术人员结局:<ccc@neos.moe>");
}
};
......
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