Commit 03a1ce6b authored by Chunchi Che's avatar Chunchi Che

fix upload API

parent da0d79e4
Pipeline #27788 passed with stages
in 7 minutes and 50 seconds
......@@ -8,7 +8,6 @@ const API_PATH = "/api/mdpro3/sync/single";
export interface SyncReq {
userId: number;
token: string;
deckContributor: string;
deck: {
deckId: string;
......@@ -20,10 +19,11 @@ export interface SyncReq {
export async function syncDeck(
req: SyncReq,
token: string,
): Promise<MdproResp<boolean> | undefined> {
const myHeaders = mdproHeaders();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("token", req.token);
myHeaders.append("token", token);
const resp = await fetch(`${mdproServer}/${API_PATH}`, {
method: "POST",
......
......@@ -8,17 +8,17 @@ const API_PATH = "/api/mdpro3/deck/public";
export interface UpdatePublicReq {
userId: number;
token: string;
deckId: string;
isPublic: boolean;
}
export async function updatePublic(
req: UpdatePublicReq,
token: string,
): Promise<MdproResp<void> | undefined> {
const myHeaders = mdproHeaders();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("token", req.token);
myHeaders.append("token", token);
const resp = await fetch(`${mdproServer}/${API_PATH}`, {
method: "POST",
......
......@@ -25,9 +25,9 @@ export async function uploadDeck(
const deckId = generateResp.data;
const syncRes = await syncDeck({
const syncRes = await syncDeck(
{
userId: req.userId,
token: req.token,
deckContributor: req.deckContributor,
deck: {
deckId,
......@@ -35,19 +35,23 @@ export async function uploadDeck(
deckCase: req.deck.deckCase,
deckYdk: req.deck.deckYdk,
},
});
},
req.token,
);
if (syncRes === undefined) return undefined;
if (syncRes.code === 0 && syncRes.data === true) {
// succeed in syncing
return await updatePublic({
return await updatePublic(
{
userId: req.userId,
token: req.token,
deckId,
isPublic: true,
});
},
req.token,
);
} else {
return { code: syncRes.code, message: syncRes.message };
}
......
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