mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2025-04-21 10:40:11 +00:00
move logic into background.js
This commit is contained in:
parent
16a52bfdc7
commit
ce827efb05
@ -87,10 +87,16 @@ async function getCookieState() {
|
|||||||
// send ping to server, return response
|
// send ping to server, return response
|
||||||
async function verifyConnection() {
|
async function verifyConnection() {
|
||||||
const path = 'api/ping/';
|
const path = 'api/ping/';
|
||||||
let response = await sendGet(path);
|
let message = await sendGet(path);
|
||||||
console.log('verify connection: ' + JSON.stringify(response));
|
console.log('verify connection: ' + JSON.stringify(message));
|
||||||
|
|
||||||
return response;
|
if (message?.response === 'pong') {
|
||||||
|
return true;
|
||||||
|
} else if (message?.detail) {
|
||||||
|
throw new Error(message.detail);
|
||||||
|
} else {
|
||||||
|
throw new Error(`got unknown message ${JSON.stringify(message)}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// send youtube link from injected buttons
|
// send youtube link from injected buttons
|
||||||
|
@ -103,15 +103,8 @@ function sendCookie() {
|
|||||||
function pingBackend() {
|
function pingBackend() {
|
||||||
clearError();
|
clearError();
|
||||||
function handleResponse(message) {
|
function handleResponse(message) {
|
||||||
// TODO move this check into background.js
|
|
||||||
if (message?.response === 'pong') {
|
|
||||||
setStatusIcon(true);
|
|
||||||
console.log('connection validated');
|
console.log('connection validated');
|
||||||
} else if (message?.detail) {
|
setStatusIcon(true);
|
||||||
handleError(message.detail);
|
|
||||||
} else {
|
|
||||||
handleError(`got unknown message ${JSON.stringify(message)}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleError(error) {
|
function handleError(error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user