mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2025-04-20 18:20:12 +00:00
split youtube message
This commit is contained in:
parent
ce827efb05
commit
5a59c4c80b
@ -84,7 +84,7 @@ async function getCookieState() {
|
||||
return response;
|
||||
}
|
||||
|
||||
// send ping to server, return response
|
||||
// send ping to server
|
||||
async function verifyConnection() {
|
||||
const path = 'api/ping/';
|
||||
let message = await sendGet(path);
|
||||
@ -100,34 +100,34 @@ async function verifyConnection() {
|
||||
}
|
||||
|
||||
// send youtube link from injected buttons
|
||||
async function youtubeLink(youtubeMessage) {
|
||||
let path;
|
||||
let payload;
|
||||
|
||||
if (youtubeMessage.action === 'download') {
|
||||
path = 'api/download/';
|
||||
payload = {
|
||||
async function download(url) {
|
||||
return await sendData(
|
||||
'api/download/',
|
||||
{
|
||||
data: [
|
||||
{
|
||||
youtube_id: youtubeMessage.url,
|
||||
youtube_id: url,
|
||||
status: 'pending',
|
||||
},
|
||||
],
|
||||
};
|
||||
} else if (youtubeMessage.action === 'subscribe') {
|
||||
path = 'api/channel/';
|
||||
payload = {
|
||||
},
|
||||
'POST'
|
||||
);
|
||||
}
|
||||
|
||||
async function subscribe(url) {
|
||||
return await sendData(
|
||||
'api/channel/',
|
||||
{
|
||||
data: [
|
||||
{
|
||||
channel_id: youtubeMessage.url,
|
||||
channel_id: url,
|
||||
channel_subscribed: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
let response = await sendData(path, payload, 'POST');
|
||||
return response;
|
||||
},
|
||||
'POST'
|
||||
);
|
||||
}
|
||||
|
||||
async function cookieStr(cookieLines) {
|
||||
@ -185,7 +185,8 @@ type Message =
|
||||
| { type: 'verify' }
|
||||
| { type: 'cookieState' }
|
||||
| { type: 'sendCookie' }
|
||||
| { type: 'youtube', action: 'download' | 'subscribe', url: string }
|
||||
| { type: 'download', url: string }
|
||||
| { type: 'subscribe', url: string }
|
||||
*/
|
||||
function handleMessage(request, sender, sendResponse) {
|
||||
console.log('message background.js listener got message', request);
|
||||
@ -204,9 +205,11 @@ function handleMessage(request, sender, sendResponse) {
|
||||
case 'sendCookie': {
|
||||
return await sendCookies();
|
||||
}
|
||||
case 'youtube': {
|
||||
// TODO split this up
|
||||
return await youtubeLink(request.youtube);
|
||||
case 'download': {
|
||||
return await download(request.url);
|
||||
}
|
||||
case 'subscribe': {
|
||||
return await subscribe(request.url);
|
||||
}
|
||||
default: {
|
||||
let err = new Error(`unknown message type ${JSON.stringify(request.type)}`);
|
||||
|
@ -102,7 +102,7 @@ function sendCookie() {
|
||||
// send ping message to TA backend
|
||||
function pingBackend() {
|
||||
clearError();
|
||||
function handleResponse(message) {
|
||||
function handleResponse() {
|
||||
console.log('connection validated');
|
||||
setStatusIcon(true);
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ function sendUrl(url, action, button) {
|
||||
buttonError(button);
|
||||
}
|
||||
|
||||
let message = { type: 'youtube', action, url };
|
||||
let message = { type: action, url };
|
||||
|
||||
console.log('youtube link: ' + JSON.stringify(message));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user