Skip to content

Commit

Permalink
Merge pull request #140 from eljeffeg/revert-139-fix-check
Browse files Browse the repository at this point in the history
Revert "Fix check"
  • Loading branch information
GuyKh authored Feb 18, 2025
2 parents 4e8936b + 1f8eb73 commit c06c333
Show file tree
Hide file tree
Showing 14 changed files with 1,369 additions and 3,517 deletions.
373 changes: 0 additions & 373 deletions LICENSE.txt

This file was deleted.

1,535 changes: 685 additions & 850 deletions _locales/en/messages.json

Large diffs are not rendered by default.

850 changes: 0 additions & 850 deletions _locales/fr/messages.json

This file was deleted.

159 changes: 41 additions & 118 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,49 @@ function getJsonFromUrl(query) {
// listen for messages - if they include photo URLs, intercept and get them
chrome.runtime.onMessage.addListener( function(request, sender, callback) {
if (request.action == "xhttp") {
delay(190);// see https://www.nginx.com/blog/rate-limiting-nginx/
const method = request.method ? request.method.toUpperCase() : 'GET';
if (method == 'POST') {
const jsData = getJsonFromUrl(request.data);
//console.log("jsDATA :",jsData.photo,jsData.file);
if (jsData.photo !== undefined) {
const photoOk = GetPhoto(jsData);
/*Chargement de la Photo par appel Url et mise en place d'un appel POST pour la transférer dans Geni - Loading the Photo by Url call and setting up a POST call for transfer into Geni.
Les parametres de l'appel sont transmis dans l'Objet "request", request.url contient l'url, request.data contient 3 clés à l'origine title, attribution, et photo l'url de l'image à charger -data.title, data.attribution et data.photo. Pendant le traitement, on crée la clé "data.file" qu'on remplit avec une chaine codée en base64. On efface data.photo.
The parameters of the call are transmitted in the "request" Object, request.url contains the url, request.data contains 3 keys at the origin title, attribution, and photo the url of the image to load - data.title, data.attribution and data.photo. During processing, we create the “data.file” key which we fill with a base64 encoded string. We delete data.photo.
https://www.geni.com/api/profile-34835287013/add-photo?fields=id,unions,name&access_token=AEWNhgu5Mdz7kGa4pXPXMohl45ZLVeoo1kFUH4p6
*/
photoOk.then((jsData) => {
request.data = jsData
//console.log("RQ_DAT1 url :",request.url,jsData.photo,jsData.file);
const header = "application/x-www-form-urlencoded";
GeniPostReq(request,header,callback);
fetch(request.url, {
method : method,
body: request.data,
headers: {
"Content-Type" : "application/x-www-form-urlencoded"
}
}).then((response) => {
if (!response.ok) {
console.error("Unable to get XMLHttpRequest: " + request.url);
var valrtn = {error: response.error, variable: request.variable, responseURL: response.responseURL};
callback(valrtn);
} else {
const responseText = response.text();
var valrtn = {source: responseText, variable: request.variable, responseURL: response.responseURL};
callback(valrtn);
const jsData = getJsonFromUrl(request);
if (jsData.photo !== undefined) {
// load the photo from the given URL
fetch(jsData.photo, {
method: 'GET',
headers: {
"Content-Type" : "text/plain; charset=UTF-8"
}
}).then((photoResponse) => {
if (!photoResponse.ok) {
var valrtn = {error: photoResponse.error, responseURL: photoResponse.responseURL};
callback(valrtn);
} else {
const photo = photoResponse.text()
let binary = ""
for(i=0;i<photo.length;i++){
binary += String.fromCharCode(photo.charCodeAt(i) & 0xff);
}
delete jsData.photo;
jsData.file = btoa(binary);
return fetch(getUrlFromJson(jsData));
}
});
}
}
});
return true
}
//console.log("RQ_DAT2 url :",request.url,jsData.photo,jsData.file);
const header = "application/x-www-form-urlencoded";
GeniPostReq(request,header,callback);

} else {
// pass this request through - note that all receivers need to change for fetch response
var vartn = {variable: request.variable};
Expand Down Expand Up @@ -91,93 +110,8 @@ chrome.runtime.onMessage.addListener( function(request, sender, callback) {
return true;
}
return false;
});
//Création et Mis à jour des donnes Geni - Creation and Update of Geni data
function GeniPostReq(request,header,callback) {
fetch(request.url, {
method : "POST",
body: request.data,
headers: {
"Content-Type" : header
}
})
.then((response) => {
if (!response.ok) {
return response.text()
.then((responseText)=> {
console.error("Unable to get Fetch Request: " + request.url);
var valrtn = {error: responseText, variable: request.variable, responseURL: request.url};
console.log("valrtn_FL ",valrtn,request.data);
callback(valrtn);
});

} else {
return response.text()
.then((responseText)=> {
var valrtn = {source: responseText, variable: request.variable, responseURL: request.url};
//console.log("valrtn_OK ",valrtn);
callback(valrtn);
});
}
})
}
// load the photo from the given URL
async function GetPhoto (jsData){
});

/*
Réécriture du 23 nov 2024.
Utilisation des API JS "ReadableStream: getReader() method" avec la method "read" qui récupère morceaux par morceaux (chunks) les éléments de l'image dans le contexte asynchrone.
Rewritten from Nov 23, 2024.
Using the JS API "ReadableStream: getReader() method" with the "read" method which retrieves the image elements piece by piece (chunks) in the asynchronous context
https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/getReader
La propriete "text()" de fetch ne se comporte pas comme xhr.responseText.
The "text()" property of fetch does not behave like xhr.responseText
*/
try {
const photoResponse = await fetch(jsData.photo, {
method: 'GET',
mode: "cors",
headers: {
"Content-Type" : "application/xml",
// "Access-Control-Allow-Origin": "*",
// "Access-Control-Allow-Methods": "GET",
// "Access-Control-Max-Age": "86400",
},
//credentials: "include",
// superflu jusqu'à preuve du contraire - superfluous until proven otherwise
});
if (!photoResponse.ok) {
throw new Error(`Erreur Photo : ${photoResponse.status}`);
}
const photoreader = photoResponse.body.getReader();
let binary = "";
while (true){
const {done,value} = await photoreader.read();
if (done){
// L'image est entièrement récupéré, on prépare les parametres du POST
// The image is fully recovered, we prepare the POST parameters
delete jsData.photo;
jsData.file = btoa(binary);
jsData = getUrlFromJson(jsData);
return jsData;
}
// Traitement de chaque chunk récupéré - Processing each retrieved chunk
// et construction progressive de la chaine binaire. - and progressive construction of the binary chain.
charsReceived = value.length;
for(i=0;i<charsReceived;i++){
binary += String.fromCharCode(value[i]);
}
}
/* Code obsolete et abandon du & 0xff - Obsolete code and abandonment of & 0xff
for(i=0;i<photoblob.size;i++){
// binary += String.fromCharCode(photoimg.charCodeAt(i) & 0xff);
binary += photoarray[i];
} */
}
catch({name, stat}) {
console.error(name, stat);
}
}
async function evalObject(expression, callback) {
await setupOffscreenDocument("offscreen.html");
await chrome.runtime.sendMessage({
Expand Down Expand Up @@ -250,14 +184,3 @@ async function setupOffscreenDocument(path) {
creating = null;
}
}
/*
En raison des restrictions générés par nginx, il est nécessaire de temporiser les appels pour ne pas saturer les serveurs et se faire jeter. Due to the restrictions generated by nginx, it is necessary to delay calls so as not to saturate the servers and get thrown out.
La programmation n'est pas optimum, mais à défaut de mieux ... The programming is not optimal, but for lack of anything better...
*/
function delay(ms){
let currDate = new Date().getTime();
let dateNow = currDate;
while(dateNow<currDate+ms){
dateNow = new Date().getTime();
}
}
Loading

0 comments on commit c06c333

Please sign in to comment.