Commit 5120df34 authored by Chunchi Che's avatar Chunchi Che

fix copy mdpro deck locally

parent 0cb3e38c
Pipeline #27681 passed with stages
in 8 minutes and 40 seconds
export * from "./mget";
export * from "./pull"; export * from "./pull";
export * from "./update"; export * from "./update";
export * from "./upload"; 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 { ...@@ -16,6 +16,6 @@ export interface MdproDeck {
deckUploadDate?: string; deckUploadDate?: string;
deckUpdateDate?: string; deckUpdateDate?: string;
/* Content of the deck. */ /* Content of the deck. */
deckYdk: string; deckYdk?: string;
deckCase: number; deckCase: number;
} }
...@@ -3,7 +3,7 @@ import React, { memo, useEffect } from "react"; ...@@ -3,7 +3,7 @@ import React, { memo, useEffect } from "react";
import { type INTERNAL_Snapshot as Snapshot, proxy, useSnapshot } from "valtio"; import { type INTERNAL_Snapshot as Snapshot, proxy, useSnapshot } from "valtio";
import YGOProDeck from "ygopro-deck-encode"; import YGOProDeck from "ygopro-deck-encode";
import { pullDecks } from "@/api"; import { mgetDeck, pullDecks } from "@/api";
import { MdproDeck } from "@/api/mdproDeck/schema"; import { MdproDeck } from "@/api/mdproDeck/schema";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { IconFont } from "@/ui/Shared"; import { IconFont } from "@/ui/Shared";
...@@ -120,17 +120,30 @@ const MdproDeckBlock: React.FC<Snapshot<MdproDeck>> = (deck) => ( ...@@ -120,17 +120,30 @@ const MdproDeckBlock: React.FC<Snapshot<MdproDeck>> = (deck) => (
); );
const copyMdproDeckToEditing = async (mdproDeck: MdproDeck) => { 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 deckID = mdproDeck.deckId;
const deckName = mdproDeck.deckName; const resp = await mgetDeck(deckID);
const ideck = { deckName, ...deck };
const editingDeck = await iDeckToEditingDeck(ideck);
setSelectedDeck(ideck); if (resp?.code !== 0) {
editDeckStore.set(editingDeck); 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 { } 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