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('.')) {
continue
}else if (json[file] === sha256sum){
console.log('This picture has already been turned to sepia')
continue
}
// Modification des données
json[file] = sha256sum
// Ré-écriture dans le fichier output
await fs.writeFile('output.json', JSON.stringify(json))
try{
const image = await Jimp.read(readI)
image.sepia()
@ -97,74 +91,52 @@ app.get('/program', (_req, res) => {
})('./assets')
})
async function filter() {
const listStart = readdirSync('./assets') // si moins de 6 element dans la liste ....
async function listToSend() {
const listFiles = readdirSync('./assets')
const listFinal: Array<Array<string>> = []
for(const files of listStart)
{
for(const files of listFiles){
const listPerso = await filesList('./assets/' + files)
listFinal.push(listPerso)
}
const filteredList = listFinal.map((innerList) => innerList.filter((element) =>
path.basename(element).startsWith('.')))
// (a,b) => (a > b ? -1 : 1)
console.log(filteredList)
const listBS = filteredList.map((innerList) => innerList.reverse())
// console.log(listBS)
return listBS
const listToSend = filteredList.map((innerList) => innerList.reverse())
return listToSend
}
// function randomSort() {
// return Math.random() - 0.5
// }
// 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()
app.get('/code', async (_, res) => {
const data = await listToSend()
const lenght = data.length
// return json data
if (lenght !== 0){
res.json(data)
}
})
// function randomIntFromInterval(min: number, max: number) {
// return Math.floor(Math.random() * (max - min + 1) + min)
// }
async function base() {
const listA = readdirSync('./assets') // si moins de 6 element dans la liste ....
const listB: Array<Array<string>> = []
const listC: Array<string> = []
for(const perso of listA){
const listFiles = readdirSync('./assets')
const outerListFinal: Array<Array<string>> = []
const innerListFinal: Array<string> = []
for(const perso of listFiles){
const listPerso = await filesList('./assets/' + perso)
for(const image of listPerso){
const bName = path.basename(image)
if(bName.startsWith('.base')){
listC.push(image)
innerListFinal.push(image)
}
}
}
listB.push(listC)
outerListFinal.push(innerListFinal)
// console.log(listB)
return listB
return outerListFinal
}
app.get('/', async (_, res) => {
const list = await base()
const listBase = await base()
if(list.length === 0 ){
if(listBase.length === 0 ){
const board =
<>
<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" />
<div className="board">
<div className='row11' >
<img id='0' src={list[0][0]} width={620} />
<img id='0' src={listBase[0][0]} width={620} />
</div>
<div className='row12'>
<img id='1' src={list[0][1]} width={620} />
<img id='1' src={listBase[0][1]} width={620} />
</div>
<div className='row13'>
<img id='2' src={list[0][2]} width={620} />
<img id='2' src={listBase[0][2]} width={620} />
</div>
<div className="row21">
<img id='3' src={list[0][3]} width={620} />
<img id='3' src={listBase[0][3]} width={620} />
</div>
<div className='row22'>
<img id='4' src={list[0][4]} width={620} />
<img id='4' src={listBase[0][4]} width={620} />
</div>
<div className='row23'>
<img id='5' src={list[0][5]} width={620} />
<img id='5' src={listBase[0][5]} width={620} />
</div>
{<script dangerouslySetInnerHTML={{__html:`
let intervalIds = [];
@ -205,31 +177,36 @@ app.get('/', async (_, res) => {
})
.then(function(data) {
function runIntervals() {
setInterval(function() {
intervalIds.forEach(clearInterval);
intervalIds = [];
let min = 0;
let n = 1;
let max = 5;
let perso = Math.floor(Math.random() * (max - min + 1) + min);
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 = n++;
let gg = (data[perso][anim])
if(gg === undefined){
let anim = countAnim ++;
let check = (data[perso][anim]);
if(check === undefined){
anim = 0
}
let imgElement = document.getElementById(perso);
imgElement.src = (data[perso][anim]);
console.log(gg)
}, 5000));
}, timeInner));
}
if(imgElement.src != data[perso][0])
{
setTimeout(function(){
imgElement.src = (data[perso][0])
}, 29000);
}, 30000);
runIntervals()
}, timeOuter);
}
}
function stopIntervals() {
intervalIds.forEach(clearInterval);
@ -243,22 +220,3 @@ 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();
});