mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 11:28:13 +03:00
Also support file uploaded for statuspolling
This commit is contained in:
@@ -68,7 +68,7 @@ export default function ARCImportPage({ game }: { game: "sdvx" | "iidx" }) {
|
||||
<Button
|
||||
className="mx-auto"
|
||||
variant="primary"
|
||||
onClick={runImport}
|
||||
onClick={() => runImport()}
|
||||
disabled={
|
||||
importState.state === "waiting_init" ||
|
||||
importState.state === "waiting_processing"
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import MiniTable from "components/tables/components/MiniTable";
|
||||
import DebugContent from "components/util/DebugContent";
|
||||
import Divider from "components/util/Divider";
|
||||
import useImport from "components/util/import/useImport";
|
||||
import prettyBytes from "pretty-bytes";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import { Button, Form } from "react-bootstrap";
|
||||
import { FileUploadImportTypes } from "tachi-common";
|
||||
import { ImportStates, NotStartedState } from "types/import";
|
||||
import { SetState } from "types/react";
|
||||
import SubmitFile from "util/submit-file";
|
||||
import ImportStateRenderer from "./ImportStateRenderer";
|
||||
|
||||
type ParseFunctionReturn = { valid: boolean; info: Record<string, React.ReactChild> };
|
||||
@@ -98,7 +97,7 @@ export default function ImportFileInfo({
|
||||
);
|
||||
}, [errMsg, data]);
|
||||
|
||||
const [importState, setImportState] = useState<ImportStates>(NotStartedState);
|
||||
const { importState, runImport } = useImport("/import/file", {});
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -136,23 +135,31 @@ export default function ImportFileInfo({
|
||||
Processing...
|
||||
</Button>
|
||||
) : importState.state === "waiting_processing" ? (
|
||||
<>
|
||||
<Button className="btn-primary" disabled>
|
||||
Processing...
|
||||
</Button>
|
||||
<DebugContent data={importState.progressInfo} />
|
||||
</>
|
||||
<Button className="btn-primary" disabled>
|
||||
Processing...
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
className="btn-primary"
|
||||
onClick={() =>
|
||||
SubmitFile(
|
||||
importType,
|
||||
file,
|
||||
setImportState,
|
||||
onClick={() => {
|
||||
const formData = new FormData();
|
||||
formData.append("importType", importType);
|
||||
formData.append("scoreData", file);
|
||||
|
||||
for (const [key, value] of Object.entries(
|
||||
moreInfo
|
||||
)
|
||||
}
|
||||
)) {
|
||||
formData.append(key, value);
|
||||
}
|
||||
|
||||
runImport({
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-User-Intent": "true",
|
||||
},
|
||||
body: formData,
|
||||
});
|
||||
}}
|
||||
>
|
||||
Submit File
|
||||
</Button>
|
||||
|
||||
@@ -89,7 +89,7 @@ function KAIImporter({ kaiType, game }: Pick<Props, "kaiType" | "game">) {
|
||||
<Button
|
||||
className="mx-auto"
|
||||
variant="primary"
|
||||
onClick={runImport}
|
||||
onClick={() => runImport()}
|
||||
disabled={
|
||||
importState.state === "waiting_init" ||
|
||||
importState.state === "waiting_processing"
|
||||
|
||||
@@ -26,10 +26,13 @@ export type ImportPollStatus =
|
||||
export default function useImport(url: string, options: RequestInit) {
|
||||
const [importState, setImportState] = useState<ImportStates>(NotStartedState);
|
||||
|
||||
const runImport = async () => {
|
||||
const runImport = async (overrideOptions?: RequestInit) => {
|
||||
setImportState({ state: "waiting_init" });
|
||||
|
||||
const initRes = await APIFetchV1<ImportDocument | ImportDeferred>(url, options);
|
||||
const initRes = await APIFetchV1<ImportDocument | ImportDeferred>(
|
||||
url,
|
||||
overrideOptions ?? options
|
||||
);
|
||||
|
||||
if (!initRes.success) {
|
||||
setImportState({ state: "failed", error: initRes.description });
|
||||
|
||||
Reference in New Issue
Block a user