👽 Move from GET to POST

This commit is contained in:
Clement Desmidt 2018-10-17 08:14:51 +02:00
parent a0e3bc77c3
commit a9ad1533c9
2 changed files with 32 additions and 7 deletions

View File

@ -10,10 +10,32 @@ ext.runtime.onMessage.addListener(
storage.get(['url', 'token'], function(resp) { storage.get(['url', 'token'], function(resp) {
url = resp.url; url = resp.url;
token = resp.token; token = resp.token;
var destination = url+"?v=1&u="+encodeURIComponent(data.url)+"&t="+encodeURIComponent(data.title)+"&m="+encodeURIComponent(token); var params = {
fetch(destination).then(function(response) { v: 1,
u: encodeURIComponent(data.url),
t: encodeURIComponent(data.title),
d: encodeURIComponent(data.description),
api_token: encodeURIComponent(token),
i: encodeURIComponent(data.image),
c: encodeURIComponent(data.comment),
};
var queryString = Object.keys(params).map((key) => {
return key + '=' + params[key];
}).join('&');
fetch(url + "/api/links", {
method: 'POST',
headers: {
'Accept': 'application/json'
},
body: new URLSearchParams(queryString)
})
.then(function(response) {
sendResponse({ action: "saved" }); sendResponse({ action: "saved" });
}); });
// var destination = url+"?v=1&u="+encodeURIComponent(data.url)+"&t="+encodeURIComponent(data.title)+"&m="+encodeURIComponent(token);
// fetch(destination).then(function(response) {
// sendResponse({ action: "saved" });
// });
}); });
return true; // https://stackoverflow.com/a/20077854 return true; // https://stackoverflow.com/a/20077854

View File

@ -2,20 +2,23 @@ import ext from "./utils/ext";
var extractTags = () => { var extractTags = () => {
var url = document.location.href; var url = document.location.href;
if(!url || !url.match(/^http/)) return; if (!url || !url.match(/^http/)) {
console.error("Invalid URL : " + url);
return;
}
var data = { var data = {
title: "", title: "",
description: "", description: "",
image: "", image: "",
url: document.location.href url: url
}; };
var ogTitle = document.querySelector("meta[property='og:title']"); var ogTitle = document.querySelector("meta[property='og:title']");
if(ogTitle) { if(ogTitle) {
data.title = ogTitle.getAttribute("content") data.title = ogTitle.getAttribute("content");
} else { } else {
data.title = document.title data.title = document.title;
} }
var descriptionTag = document.querySelector("meta[property='og:description']") || document.querySelector("meta[name='description']"); var descriptionTag = document.querySelector("meta[property='og:description']") || document.querySelector("meta[name='description']");