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