1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| "use strict"; // voir https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Strict_mode
let chain;
async function updatePhoto(user, indexPhoto, publicCount) {
let imagePerPage = 50;
let position = (indexPhoto - 1) % (imagePerPage * 10);
let page = Math.trunc((indexPhoto - 1) / imagePerPage) + 1;
let pageMin = Math.trunc((page - 1) / 10) * 10 + 1;
let file2Load = "pages_" + pageMin + "_" + (pageMin + 9) + ".txt";
let file2LoadMore;
//console.log(file2Load);
let pageMax = Math.trunc((publicCount - 1) / imagePerPage) + 1;
if (pageMax <= (pageMin + 9) && pageMax >= pageMin && publicCount > (10 * imagePerPage))
{
file2LoadMore = "pages_" + (pageMin - 10) + "_" + (pageMin - 1) + ".txt";
}
if (pageMin == 1 && publicCount > (10 * imagePerPage))
{
file2LoadMore = "pages_" + (pageMin + 10) + "_" + (pageMin + 19) + ".txt";
}
if (pageMin > 1 && position < 250)
{
file2LoadMore = "pages_" + (pageMin - 10) + "_" + (pageMin - 1) + ".txt";
}
if (pageMin > 1 && position >= 250)
{
file2LoadMore = "pages_" + (pageMin + 10) + "_" + (pageMin + 19) + ".txt";
}
console.log(file2Load);
let result = await getFile(file2Load);
console.log(result);
}
function getFile(file2Load) {
return new Promise((resolve, reject) => {
let url = "http://127.0.0.1/wp-content/data/upload_date/" + file2Load;
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200)
{
resolve(this.responseText);
}
}
xhttp.open("GET", url, true);
xhttp.send();
});
} |
Partager