move getAccess into function calls

This commit is contained in:
simon 2022-06-20 18:40:17 +07:00
parent fa0fecffcf
commit 4838c28557
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -23,8 +23,9 @@ function getBrowser() {
// send get request to API backend // send get request to API backend
async function sendGet(path, access) { async function sendGet(path) {
let access = await getAccess();
const url = `${access.url}:${access.port}/${path}`; const url = `${access.url}:${access.port}/${path}`;
console.log("GET: " + url); console.log("GET: " + url);
@ -44,8 +45,9 @@ async function sendGet(path, access) {
// send post request to API backend // send post request to API backend
async function sendPost(path, access, payload) { async function sendPost(path, payload) {
let access = await getAccess();
const url = `${access.url}:${access.port}/${path}`; const url = `${access.url}:${access.port}/${path}`;
console.log("POST: " + url); console.log("POST: " + url);
console.log("POST: " + JSON.stringify(payload)) console.log("POST: " + JSON.stringify(payload))
@ -80,8 +82,7 @@ async function getAccess() {
async function verifyConnection() { async function verifyConnection() {
const path = "api/ping/"; const path = "api/ping/";
let access = await getAccess(); let response = await sendGet(path)
let response = await sendGet(path, access)
console.log("verify connection: " + JSON.stringify(response)); console.log("verify connection: " + JSON.stringify(response));
return response return response
@ -108,8 +109,7 @@ async function downloadLink(toDownload) {
} }
] ]
} }
let access = await getAccess(); let response = await sendPost(path, payload)
let response = await sendPost(path, access, payload)
return response return response
@ -126,8 +126,7 @@ async function subscribeLink(toSubscribe) {
} }
] ]
} }
let access = await getAccess(); let response = await sendPost(path, payload);
let response = await sendPost(path, access, payload);
return response return response