Commit f89bc5b0 authored by Chunchi Che's avatar Chunchi Che

add update api

parent 506a733a
Pipeline #27593 passed with stages
in 7 minutes and 31 seconds
export * from "./pull"; export * from "./pull";
export * from "./update";
export * from "./upload"; export * from "./upload";
...@@ -20,7 +20,7 @@ const defaultPullReq: PullReq = { ...@@ -20,7 +20,7 @@ const defaultPullReq: PullReq = {
size: 20, size: 20,
}; };
export interface PullResp { interface PullResp {
code: number; code: number;
message: string; message: string;
data?: { data?: {
......
import { useConfig } from "@/config";
import { MdproDeck } from "./schema";
import { mdproHeaders } from "./util";
const { mdproServer } = useConfig();
const API_PATH = "api/mdpro3/deck/update";
interface UpdateResp {
code: number;
message: string;
data: MdproDeck;
}
export async function updateDeck(
req: MdproDeck,
): Promise<UpdateResp | undefined> {
const myHeaders = mdproHeaders();
const resp = await fetch(`${mdproServer}/${API_PATH}`, {
method: "PUT",
headers: myHeaders,
body: JSON.stringify(req),
redirect: "follow",
});
if (!resp.ok) {
console.error(`[Update of MdproDeck] HTTPS error! status: ${resp.status}`);
return undefined;
} else {
return await resp.json();
}
}
...@@ -6,7 +6,7 @@ import { mdproHeaders } from "./util"; ...@@ -6,7 +6,7 @@ import { mdproHeaders } from "./util";
const { mdproServer } = useConfig(); const { mdproServer } = useConfig();
const API_PATH = "api/mdpro3/deck/upload"; const API_PATH = "api/mdpro3/deck/upload";
export interface UploadResp { interface UploadResp {
code: number; code: number;
message: string; message: string;
data: MdproDeck; data: MdproDeck;
...@@ -21,6 +21,7 @@ export async function uploadDeck( ...@@ -21,6 +21,7 @@ export async function uploadDeck(
method: "POST", method: "POST",
headers: myHeaders, headers: myHeaders,
body: JSON.stringify(req), body: JSON.stringify(req),
redirect: "follow",
}); });
if (!resp.ok) { if (!resp.ok) {
......
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