From 30ea594365b7ae5b9b870c32f161e0b52980be5b Mon Sep 17 00:00:00 2001 From: Massiles Ghernaout <749-gm213204@users.noreply.www-apps.univ-lehavre.fr> Date: Fri, 6 Feb 2026 19:58:36 +0100 Subject: [PATCH 01/19] added crypto-js since web browsers do not have md5 algo support :/ --- frontend/package-lock.json | 7 +++++++ frontend/package.json | 1 + frontend/src/App.jsx | 29 +++++++++++++---------------- frontend/vite.config.mts | 9 +-------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 421c5f3..b9a4c6a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -8,6 +8,7 @@ "name": "md5-swarm-frontend", "version": "0.1.0", "dependencies": { + "crypto-js": "^4.2.0", "react": "^18.3.1", "react-dom": "^18.3.1" }, @@ -1292,6 +1293,12 @@ "dev": true, "license": "MIT" }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==", + "license": "MIT" + }, "node_modules/debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index 1e7346a..178c676 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,6 +9,7 @@ "test": "echo \"no frontend tests yet\"" }, "dependencies": { + "crypto-js": "^4.2.0", "react": "^18.3.1", "react-dom": "^18.3.1" }, diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 1a1d947..0110ddb 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,4 +1,5 @@ import React, { useEffect, useState } from "react"; +import CryptoJS from "crypto-js"; const MODES = { gentle: 5000, @@ -7,7 +8,11 @@ const MODES = { }; async function apiRequest(path, options = {}) { - const res = await fetch(`/api${path}`, { + console.log("API_URL: ", import.meta.env.VITE_API_URL); + console.log("path: ", path); + console.log("options: ", options); + + const res = await fetch(`${import.meta.env.VITE_API_URL || "http://localhost:8080"}${path}`, { headers: { "Content-Type": "application/json" }, ...options, }); @@ -72,33 +77,25 @@ function App() { // Envoi auto de hash aléatoires selon le mode useEffect(() => { + console.log("autoRunning: ", autoRunning); + console.log("mode: ", mode); if (!autoRunning) return; const delay = MODES[mode] || MODES.normal; const interval = setInterval(async () => { - const randomText = Math.random().toString(36).slice(2, 8); - const encoder = new TextEncoder(); - const data = encoder.encode(randomText); - const digest = await window.crypto.subtle.digest("MD5", data).catch(() => null); - - if (!digest) return; - - const hashArray = Array.from(new Uint8Array(digest)); - const hash = hashArray.map((b) => b.toString(16).padStart(2, "0")).join(""); - + const hash = CryptoJS.MD5(randomText).toString(CryptoJS.enc.Hex); + console.log("auto send", delay, hash); try { const res = await apiRequest("/hash/manual", { method: "POST", body: JSON.stringify({ hash }), }); setJobs((prev) => [...prev, { id: res.id, hash }]); - } catch (e) { console.error("auto send error", e); } - }, delay); return () => clearInterval(interval); @@ -160,7 +157,7 @@ function App() { checked={mode === "gentle"} onChange={() => setMode("gentle")} /> - {" "}Gentil (toutes les 5s) + Gentil (toutes les 5s)

+ + {MODE_LABELS[mode]} + + + + Télécharge deux fichiers : hashes (inputs) et résultats (outputs), un élément par ligne, même ordre. + + + )} {jobs.length === 0 ? (

Aucun job pour le moment.

) : ( -- GitLab