去掉游戏sha256
This commit is contained in:
parent
4e56597adb
commit
7740d611b6
@ -51,12 +51,6 @@ const defaultPlatformForm = {
|
||||
const defaultBridgeScriptForm = {
|
||||
bridgeScriptUrl: "",
|
||||
bridgeScriptVersion: "",
|
||||
bridgeScriptSha256: "",
|
||||
};
|
||||
|
||||
const defaultBridgeHashState = {
|
||||
loading: false,
|
||||
error: "",
|
||||
};
|
||||
|
||||
const emptyCatalog = { items: [], pageSize: 50 };
|
||||
@ -81,7 +75,6 @@ export function useGamesPage() {
|
||||
const [gameForm, setGameForm] = useState(defaultGameForm);
|
||||
const [platformForm, setPlatformForm] = useState(defaultPlatformForm);
|
||||
const [bridgeScriptForm, setBridgeScriptForm] = useState(defaultBridgeScriptForm);
|
||||
const [bridgeHashState, setBridgeHashState] = useState(defaultBridgeHashState);
|
||||
const [loadingAction, setLoadingAction] = useState("");
|
||||
const [syncPlatform, setSyncPlatform] = useState(null);
|
||||
const [syncCandidates, setSyncCandidates] = useState([]);
|
||||
@ -217,7 +210,6 @@ export function useGamesPage() {
|
||||
|
||||
const openBridgeScript = () => {
|
||||
setBridgeScriptForm(bridgeScriptFormFromPlatforms(platformData.items || []));
|
||||
setBridgeHashState(defaultBridgeHashState);
|
||||
setActiveAction("bridge-script");
|
||||
};
|
||||
|
||||
@ -235,78 +227,12 @@ export function useGamesPage() {
|
||||
}
|
||||
if (activeAction === "bridge-script") {
|
||||
setBridgeScriptForm(defaultBridgeScriptForm);
|
||||
setBridgeHashState(defaultBridgeHashState);
|
||||
}
|
||||
setActiveAction("");
|
||||
setEditingGameId("");
|
||||
setEditingPlatformCode("");
|
||||
};
|
||||
|
||||
const refreshBridgeScriptHash = useCallback(async () => {
|
||||
const url = bridgeScriptForm.bridgeScriptUrl.trim();
|
||||
if (activeAction !== "bridge-script" || url === "") {
|
||||
return "";
|
||||
}
|
||||
setBridgeHashState({ loading: true, error: "" });
|
||||
try {
|
||||
const hash = await calculateBridgeScriptSha256(url);
|
||||
setBridgeScriptForm((current) => {
|
||||
if (current.bridgeScriptUrl.trim() !== url) {
|
||||
return current;
|
||||
}
|
||||
return { ...current, bridgeScriptSha256: hash };
|
||||
});
|
||||
setBridgeHashState(defaultBridgeHashState);
|
||||
return hash;
|
||||
} catch (err) {
|
||||
const message = err.message || "生成 SHA256 失败";
|
||||
setBridgeHashState({ loading: false, error: message });
|
||||
showToast(message, "error");
|
||||
return "";
|
||||
}
|
||||
}, [activeAction, bridgeScriptForm.bridgeScriptUrl, showToast]);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeAction !== "bridge-script") {
|
||||
return undefined;
|
||||
}
|
||||
const url = bridgeScriptForm.bridgeScriptUrl.trim();
|
||||
const version = bridgeScriptForm.bridgeScriptVersion.trim();
|
||||
if (!url || !version) {
|
||||
setBridgeScriptForm((current) =>
|
||||
current.bridgeScriptSha256 ? { ...current, bridgeScriptSha256: "" } : current,
|
||||
);
|
||||
setBridgeHashState(defaultBridgeHashState);
|
||||
return undefined;
|
||||
}
|
||||
let cancelled = false;
|
||||
const timer = window.setTimeout(async () => {
|
||||
setBridgeHashState({ loading: true, error: "" });
|
||||
try {
|
||||
const hash = await calculateBridgeScriptSha256(url);
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
setBridgeScriptForm((current) => {
|
||||
if (current.bridgeScriptUrl.trim() !== url || current.bridgeScriptVersion.trim() !== version) {
|
||||
return current;
|
||||
}
|
||||
return { ...current, bridgeScriptSha256: hash };
|
||||
});
|
||||
setBridgeHashState(defaultBridgeHashState);
|
||||
} catch (err) {
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
setBridgeHashState({ loading: false, error: err.message || "生成 SHA256 失败" });
|
||||
}
|
||||
}, 500);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
window.clearTimeout(timer);
|
||||
};
|
||||
}, [activeAction, bridgeScriptForm.bridgeScriptUrl, bridgeScriptForm.bridgeScriptVersion]);
|
||||
|
||||
const submitGame = async (event) => {
|
||||
event.preventDefault();
|
||||
const payload = gamePayload(gameForm);
|
||||
@ -361,13 +287,6 @@ export function useGamesPage() {
|
||||
showToast("请填写 bridge_script_url 和 bridge_script_version", "error");
|
||||
return;
|
||||
}
|
||||
let bridgeScriptSha256 = bridgeScriptForm.bridgeScriptSha256.trim();
|
||||
if (!bridgeScriptSha256) {
|
||||
bridgeScriptSha256 = await refreshBridgeScriptHash();
|
||||
}
|
||||
if (!bridgeScriptSha256) {
|
||||
return;
|
||||
}
|
||||
setLoadingAction("bridge-script");
|
||||
try {
|
||||
await Promise.all(
|
||||
@ -375,10 +294,13 @@ export function useGamesPage() {
|
||||
const config = parseJsonObject(platform.adapterConfigJson);
|
||||
config.bridge_script_url = bridgeScriptUrl;
|
||||
config.bridge_script_version = bridgeScriptVersion;
|
||||
config.bridge_script_sha256 = bridgeScriptSha256;
|
||||
delete config.bridgeScriptUrl;
|
||||
delete config.bridgeScriptVersion;
|
||||
delete config.bridge_script_sha256;
|
||||
delete config.bridgeScriptSha256;
|
||||
delete config.bridge_script_hash;
|
||||
delete config.script_sha256;
|
||||
delete config.scriptSha256;
|
||||
return upsertGamePlatform(
|
||||
platformUpsertPayload(platform, JSON.stringify(config, null, 2)),
|
||||
platform.platformCode,
|
||||
@ -518,7 +440,6 @@ export function useGamesPage() {
|
||||
abilities,
|
||||
activeAction,
|
||||
allSyncGamesSelected,
|
||||
bridgeHashState,
|
||||
bridgeScriptForm,
|
||||
changeGameStatus,
|
||||
deleteGame,
|
||||
@ -550,7 +471,6 @@ export function useGamesPage() {
|
||||
platformForm,
|
||||
platformOptions,
|
||||
loadNextPage,
|
||||
refreshBridgeScriptHash,
|
||||
reload: reloadCatalog,
|
||||
resetFilters,
|
||||
resolveGameURL,
|
||||
@ -592,16 +512,13 @@ function bridgeScriptFormFromPlatform(platform) {
|
||||
return {
|
||||
bridgeScriptUrl: readConfigString(config.bridge_script_url ?? config.bridgeScriptUrl),
|
||||
bridgeScriptVersion: readConfigString(config.bridge_script_version ?? config.bridgeScriptVersion),
|
||||
bridgeScriptSha256: readConfigString(
|
||||
config.bridge_script_sha256 ?? config.bridgeScriptSha256 ?? config.bridge_script_hash,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function bridgeScriptFormFromPlatforms(platforms) {
|
||||
for (const platform of platforms) {
|
||||
const form = bridgeScriptFormFromPlatform(platform);
|
||||
if (form.bridgeScriptUrl || form.bridgeScriptVersion || form.bridgeScriptSha256) {
|
||||
if (form.bridgeScriptUrl || form.bridgeScriptVersion) {
|
||||
return form;
|
||||
}
|
||||
}
|
||||
@ -629,21 +546,6 @@ function platformUpsertPayload(platform, adapterConfigJson) {
|
||||
};
|
||||
}
|
||||
|
||||
async function calculateBridgeScriptSha256(url) {
|
||||
if (!window.crypto?.subtle) {
|
||||
throw new Error("当前浏览器不支持 SHA256 计算");
|
||||
}
|
||||
const response = await fetch(url, { cache: "no-store" });
|
||||
if (!response.ok) {
|
||||
throw new Error(`拉取 JS 失败:HTTP ${response.status}`);
|
||||
}
|
||||
const buffer = await response.arrayBuffer();
|
||||
const digest = await window.crypto.subtle.digest("SHA-256", buffer);
|
||||
return Array.from(new Uint8Array(digest))
|
||||
.map((byte) => byte.toString(16).padStart(2, "0"))
|
||||
.join("");
|
||||
}
|
||||
|
||||
async function saveGameUrl(platforms, game, gameUrl) {
|
||||
const platform = platforms.find((item) => item.platformCode === game.platformCode);
|
||||
if (!platform) {
|
||||
|
||||
@ -435,15 +435,8 @@ function GameFormDialog({ form, loading, mode, open, page, onClose, onSubmit })
|
||||
}
|
||||
|
||||
function BridgeScriptDialog({ form, loading, open, page, onClose, onSubmit }) {
|
||||
const hashState = page.bridgeHashState || {};
|
||||
const disabled = !page.abilities.canUpdate;
|
||||
const submitDisabled =
|
||||
disabled ||
|
||||
loading ||
|
||||
hashState.loading ||
|
||||
!form.bridgeScriptUrl.trim() ||
|
||||
!form.bridgeScriptVersion.trim() ||
|
||||
!form.bridgeScriptSha256.trim();
|
||||
const submitDisabled = disabled || loading || !form.bridgeScriptUrl.trim() || !form.bridgeScriptVersion.trim();
|
||||
return (
|
||||
<AdminFormDialog
|
||||
disabled={disabled}
|
||||
@ -455,17 +448,7 @@ function BridgeScriptDialog({ form, loading, open, page, onClose, onSubmit }) {
|
||||
onClose={onClose}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
<AdminFormSection
|
||||
title="通用桥接脚本"
|
||||
actions={
|
||||
<Button
|
||||
disabled={disabled || hashState.loading || !form.bridgeScriptUrl.trim()}
|
||||
onClick={page.refreshBridgeScriptHash}
|
||||
>
|
||||
{hashState.loading ? "生成中..." : "重新生成 SHA256"}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<AdminFormSection title="通用桥接脚本">
|
||||
<AdminFormFieldGrid columns="repeat(2, minmax(0, 1fr))">
|
||||
<TextField
|
||||
label="bridge_script_version"
|
||||
@ -484,17 +467,6 @@ function BridgeScriptDialog({ form, loading, open, page, onClose, onSubmit }) {
|
||||
value={form.bridgeScriptUrl}
|
||||
onChange={(event) => page.setBridgeScriptForm({ ...form, bridgeScriptUrl: event.target.value })}
|
||||
/>
|
||||
<TextField
|
||||
className={styles.fullField}
|
||||
error={Boolean(hashState.error)}
|
||||
helperText={hashState.error || (hashState.loading ? "正在拉取 JS 并计算 SHA256" : "")}
|
||||
label="bridge_script_sha256"
|
||||
required
|
||||
value={form.bridgeScriptSha256}
|
||||
onChange={(event) =>
|
||||
page.setBridgeScriptForm({ ...form, bridgeScriptSha256: event.target.value })
|
||||
}
|
||||
/>
|
||||
</AdminFormFieldGrid>
|
||||
</AdminFormSection>
|
||||
</AdminFormDialog>
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"noEmit": true,
|
||||
"ignoreDeprecations": "6.0",
|
||||
"ignoreDeprecations": "5.0",
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user