From 5b3b882a302b3bc170e25ebc9bf12813e6529c14 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 21 Jun 2022 06:50:12 +0700 Subject: [PATCH] convert sendPost to generic sendData --- extension/background.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/extension/background.js b/extension/background.js index 86bda65..427fa5c 100644 --- a/extension/background.js +++ b/extension/background.js @@ -44,16 +44,16 @@ async function sendGet(path) { } -// send post request to API backend -async function sendPost(path, payload) { +// send post/put request to API backend +async function sendData(path, payload, method) { let access = await getAccess(); const url = `${access.url}:${access.port}/${path}`; - console.log("POST: " + url); - console.log("POST: " + JSON.stringify(payload)) + console.log(`${method}: ${url}`); + console.log(`${method}: ${JSON.stringify(payload)}`); const rawResponse = await fetch(url, { - method: "POST", + method: method, headers: { "Accept": "application/json", "Content-Type": "application/json", @@ -109,7 +109,7 @@ async function downloadLink(toDownload) { } ] } - let response = await sendPost(path, payload) + let response = await sendData(path, payload, "POST") return response @@ -126,7 +126,7 @@ async function subscribeLink(toSubscribe) { } ] } - let response = await sendPost(path, payload); + let response = await sendData(path, payload, "POST"); return response