send cookie to api

This commit is contained in:
simon 2022-06-22 19:46:37 +07:00
parent 5b3b882a30
commit ff0e8c1185
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -132,10 +132,25 @@ async function subscribeLink(toSubscribe) {
} }
async function cookieStr(cookieLines) {
let cookieString = cookieLines.join("\n");
const path = "api/cookie/";
let payload = {
"cookie": cookieString
}
let response = await sendData(path, payload, "PUT");
return response
}
function buildCookieLine(cookie) { function buildCookieLine(cookie) {
return [ return [
cookie.domain, cookie.domain,
cookie.hostOnly.toString().toUpperCase(), "TRUE",
cookie.path, cookie.path,
cookie.httpOnly.toString().toUpperCase(), cookie.httpOnly.toString().toUpperCase(),
cookie.expirationDate, cookie.expirationDate,
@ -165,8 +180,10 @@ async function sendCookies() {
cookieLines.push(buildCookieLine(cookie)); cookieLines.push(buildCookieLine(cookie));
} }
} }
console.log(cookieLines.length);
console.log(cookieLines.join("\n")); let response = cookieStr(cookieLines);
return response
} }
@ -196,6 +213,9 @@ function handleMessage(request, sender, sendResponse) {
} else if (request.cookie) { } else if (request.cookie) {
console.log("backgound: " + JSON.stringify(request)); console.log("backgound: " + JSON.stringify(request));
let response = sendCookies(); let response = sendCookies();
response.then(message => {
sendResponse(message)
})
} }
return true; return true;