fixing bugs , cleaning

Co-authored-by: Avior <github@avior.me>
This commit is contained in:
Edhueppe 2023-02-22 17:06:55 +01:00
parent 4b3181f1b8
commit 777d9db78e
2 changed files with 88 additions and 87 deletions

View File

@ -68,16 +68,10 @@ app.get('/program', (_req, res) => {
if (bFile.startsWith('.')) { if (bFile.startsWith('.')) {
continue continue
}else if (json[file] === sha256sum){ }else if (json[file] === sha256sum){
console.log('This picture has already been turned to sepia')
continue continue
} }
// Modification des données
json[file] = sha256sum json[file] = sha256sum
// Ré-écriture dans le fichier output
await fs.writeFile('output.json', JSON.stringify(json)) await fs.writeFile('output.json', JSON.stringify(json))
try{ try{
const image = await Jimp.read(readI) const image = await Jimp.read(readI)
image.sepia() image.sepia()
@ -97,74 +91,52 @@ app.get('/program', (_req, res) => {
})('./assets') })('./assets')
}) })
async function filter() { async function listToSend() {
const listStart = readdirSync('./assets') // si moins de 6 element dans la liste .... const listFiles = readdirSync('./assets')
const listFinal: Array<Array<string>> = [] const listFinal: Array<Array<string>> = []
for(const files of listStart) for(const files of listFiles){
{
const listPerso = await filesList('./assets/' + files) const listPerso = await filesList('./assets/' + files)
listFinal.push(listPerso) listFinal.push(listPerso)
} }
const filteredList = listFinal.map((innerList) => innerList.filter((element) => const filteredList = listFinal.map((innerList) => innerList.filter((element) =>
path.basename(element).startsWith('.'))) path.basename(element).startsWith('.')))
// (a,b) => (a > b ? -1 : 1) const listToSend = filteredList.map((innerList) => innerList.reverse())
console.log(filteredList) return listToSend
const listBS = filteredList.map((innerList) => innerList.reverse())
// console.log(listBS)
return listBS
} }
// function randomSort() { app.get('/code', async (_, res) => {
// return Math.random() - 0.5 const data = await listToSend()
// }
// async function randomI(): Promise<[] | [string, string, string, string, string, string]> {
// const filteredList = await filter()
// const sorted = filteredList.sort(randomSort).slice(0, 6)
// while (sorted.length < 6 && sorted.length > 0 ) {
// const listLength = sorted.length
// sorted.push(...filteredList.sort(randomSort).slice(0, 6 - listLength))
// }
// return sorted as []
// }
app.get('/code', async (_, res) => { // envoie a /code list de list des anims par perso (en théorie )
const data = await filter()
// const baseI = await base()
const lenght = data.length const lenght = data.length
// return json data
if (lenght !== 0){ if (lenght !== 0){
res.json(data) res.json(data)
} }
}) })
// function randomIntFromInterval(min: number, max: number) {
// return Math.floor(Math.random() * (max - min + 1) + min)
// }
async function base() { async function base() {
const listA = readdirSync('./assets') // si moins de 6 element dans la liste .... const listFiles = readdirSync('./assets')
const listB: Array<Array<string>> = [] const outerListFinal: Array<Array<string>> = []
const listC: Array<string> = [] const innerListFinal: Array<string> = []
for(const perso of listA){ for(const perso of listFiles){
const listPerso = await filesList('./assets/' + perso) const listPerso = await filesList('./assets/' + perso)
for(const image of listPerso){ for(const image of listPerso){
const bName = path.basename(image) const bName = path.basename(image)
if(bName.startsWith('.base')){ if(bName.startsWith('.base')){
listC.push(image) innerListFinal.push(image)
} }
} }
} }
listB.push(listC) outerListFinal.push(innerListFinal)
// console.log(listB) // console.log(listB)
return listB return outerListFinal
} }
app.get('/', async (_, res) => { app.get('/', async (_, res) => {
const list = await base() const listBase = await base()
if(list.length === 0 ){ if(listBase.length === 0 ){
const board = const board =
<> <>
<link rel="stylesheet" href='/test/index.css' type="text/css" /> <link rel="stylesheet" href='/test/index.css' type="text/css" />
@ -180,22 +152,22 @@ app.get('/', async (_, res) => {
<link rel="stylesheet" href='/test/index.css' type="text/css" /> <link rel="stylesheet" href='/test/index.css' type="text/css" />
<div className="board"> <div className="board">
<div className='row11' > <div className='row11' >
<img id='0' src={list[0][0]} width={620} /> <img id='0' src={listBase[0][0]} width={620} />
</div> </div>
<div className='row12'> <div className='row12'>
<img id='1' src={list[0][1]} width={620} /> <img id='1' src={listBase[0][1]} width={620} />
</div> </div>
<div className='row13'> <div className='row13'>
<img id='2' src={list[0][2]} width={620} /> <img id='2' src={listBase[0][2]} width={620} />
</div> </div>
<div className="row21"> <div className="row21">
<img id='3' src={list[0][3]} width={620} /> <img id='3' src={listBase[0][3]} width={620} />
</div> </div>
<div className='row22'> <div className='row22'>
<img id='4' src={list[0][4]} width={620} /> <img id='4' src={listBase[0][4]} width={620} />
</div> </div>
<div className='row23'> <div className='row23'>
<img id='5' src={list[0][5]} width={620} /> <img id='5' src={listBase[0][5]} width={620} />
</div> </div>
{<script dangerouslySetInnerHTML={{__html:` {<script dangerouslySetInnerHTML={{__html:`
let intervalIds = []; let intervalIds = [];
@ -205,31 +177,36 @@ app.get('/', async (_, res) => {
}) })
.then(function(data) { .then(function(data) {
function runIntervals() { function runIntervals() {
setInterval(function() {
intervalIds.forEach(clearInterval); intervalIds.forEach(clearInterval);
intervalIds = []; intervalIds = [];
let min = 0; let timeOuter = 5000;
let n = 1; let timeInner = 1000;
let max = 5; let countAnim = 1;
let perso = Math.floor(Math.random() * (max - min + 1) + min); let minPerso = 0;
let maxPerso = 5;
let perso = Math.floor(Math.random() * (maxPerso - minPerso + 1) + minPerso);
let length = data[perso].length
if(length*timeInner > timeOuter){
timeOuter = length*timeInner + timeInner
}
let imgElement = document.getElementById(perso); let imgElement = document.getElementById(perso);
if (imgElement){ if (imgElement){
intervalIds.push(setInterval(function() { intervalIds.push(setInterval(function() {
let anim = n++; let anim = countAnim ++;
let gg = (data[perso][anim]) let check = (data[perso][anim]);
if(gg === undefined){ if(check === undefined){
anim = 0 anim = 0
} }
let imgElement = document.getElementById(perso); let imgElement = document.getElementById(perso);
imgElement.src = (data[perso][anim]); imgElement.src = (data[perso][anim]);
console.log(gg) }, timeInner));
}
}, 5000)); if(imgElement.src != data[perso][0])
{
setTimeout(function(){
runIntervals()
}, timeOuter);
} }
setTimeout(function(){
imgElement.src = (data[perso][0])
}, 29000);
}, 30000);
} }
function stopIntervals() { function stopIntervals() {
intervalIds.forEach(clearInterval); intervalIds.forEach(clearInterval);
@ -242,23 +219,4 @@ app.get('/', async (_, res) => {
</> </>
)) ))
} }
}) })
// img de 1 a 6
// animer les images par rappoirt a un format de fichier, (base.ext) -> (anim1, anim2, ...animX)
/*
/assets/florian.bouillon/
/assets/florian.bouillon/base.ext
/assets/florian.bouillon/anim1.ext
/assets/florian.bouillon/anim2.ext
/assets/florian.bouillon/anim3.ext
/assets/florian.bouillon/anim4.ext
1. je veux que tu récupères uniquement les images qui suivent le format ci-dessus
2. aléatoirement, je veux que toutes les 30secs, une image passe de base.ext, a toutes ces animations
ex: base.ext > anim1.ext > anim2.ext > animX.ext
*/

45
test.js
View File

@ -1 +1,44 @@
setTimeout((imgElement.src = (data[perso][0])), 9000); let intervalIds = [];
fetch('http://localhost:3000/code')
.then(function(response) {
return response.json();
})
.then(function(data) {
function runIntervals() {
intervalIds.forEach(clearInterval);
intervalIds = [];
let timeOuter = 5000;
let timeInner = 1000;
let countAnim = 1;
let minPerso = 0;
let maxPerso = 5;
let perso = Math.floor(Math.random() * (maxPerso - minPerso + 1) + minPerso);
let length = data[perso].length
if(length*timeInner > timeOuter){
timeOuter = length*timeInner + timeInner
}
let imgElement = document.getElementById(perso);
if (imgElement){
intervalIds.push(setInterval(function() {
let anim = countAnim ++;
let check = (data[perso][anim]);
if(check === undefined){
anim = 0
}
let imgElement = document.getElementById(perso);
imgElement.src = (data[perso][anim]);
}, timeInner));
}
if(imgElement.src != data[perso][0])
{
setTimeout(function(){
runIntervals()
}, timeOuter);
}
}
function stopIntervals() {
intervalIds.forEach(clearInterval);
intervalIds = [];
}
runIntervals();
});