fix token on edit page
This commit is contained in:
@@ -3,10 +3,14 @@ export const get = async (url: string) => {
|
||||
const json = await resp.json();
|
||||
return json;
|
||||
};
|
||||
export const post = async (url: string, json: any) => {
|
||||
export const post = async (
|
||||
url: string,
|
||||
json: any,
|
||||
headers: Record<string, string> = {}
|
||||
) => {
|
||||
const resp = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
headers: { "Content-Type": "application/json", ...headers },
|
||||
body: JSON.stringify(json),
|
||||
});
|
||||
const result = await resp.json();
|
||||
|
||||
@@ -2,10 +2,11 @@ import React from "react";
|
||||
import { get, post } from "@/common";
|
||||
|
||||
const EditPage = () => {
|
||||
const [token, setToken] = React.useState("");
|
||||
const ref = React.useRef();
|
||||
const upload = async () => {
|
||||
const html = ref.current.innerHTML;
|
||||
await post("/api/html", { html });
|
||||
await post("/api/html", { html }, { token });
|
||||
alert("Upload success");
|
||||
refresh();
|
||||
};
|
||||
@@ -18,6 +19,11 @@ const EditPage = () => {
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<input
|
||||
value={token}
|
||||
placeholder={"token"}
|
||||
onChange={(event) => setToken(event.target.value)}
|
||||
/>
|
||||
<button onClick={() => upload()}>Upload</button>
|
||||
<div
|
||||
ref={ref}
|
||||
|
||||
Reference in New Issue
Block a user