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,7 +120,17 @@ const MdproDeckBlock: React.FC<Snapshot<MdproDeck>> = (deck) => ( ...@@ -120,7 +120,17 @@ 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.
const deckID = mdproDeck.deckId;
const resp = await mgetDeck(deckID);
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)) { if (!(deck.main.length + deck.extra.length + deck.side.length === 0)) {
const deckName = mdproDeck.deckName; const deckName = mdproDeck.deckName;
...@@ -132,6 +142,9 @@ const copyMdproDeckToEditing = async (mdproDeck: MdproDeck) => { ...@@ -132,6 +142,9 @@ const copyMdproDeckToEditing = async (mdproDeck: MdproDeck) => {
} else { } else {
message.error("卡组解析失败,请联系技术人员解决:<ccc@neos.moe>"); message.error("卡组解析失败,请联系技术人员解决:<ccc@neos.moe>");
} }
} else {
message.error("卡组复制失败,请联系技术人员结局:<ccc@neos.moe>");
}
}; };
function truncateString(str: string, maxLen: number): string { function truncateString(str: string, maxLen: number): string {
......
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