async function fetchVisitData(dirUrl) { try { if (!dirUrl || typeof dirUrl !== "string") { throw new Error("dirUrl must be a valid string"); } const baseDir = dirUrl.split("/")[0]; const visitDataPath = `${baseDir}/visit_data.json`; // Request signed URL const signedUrlResponse = await fetch("http://localhost:3001/generate-signed-url", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ dirUrl: visitDataPath }), }); if (!signedUrlResponse.ok) { throw new Error(`Failed to generate signed URL: ${signedUrlResponse.status}`); } const { url } = await signedUrlResponse.json(); // Fetch the actual data const fileResponse = await fetch(url); if (!fileResponse.ok) { throw new Error(`Failed to fetch visit_data.json: ${fileResponse.status}`); } const visitData = await fileResponse.json(); console.log("Visit Data:", visitData); return visitData; } catch (error) { console.error("Error fetching visit data:", error); throw error; } } async function populatePropertyDetails(dirUrl) { try { const visitData = await fetchVisitData(dirUrl); document.getElementById("visitName").textContent = visitData.visitName || "N/A"; document.getElementById("address").textContent = visitData.address || "N/A"; // Pas de "Address:" document.getElementById("owner").textContent = visitData.owner || "N/A"; // Pas de "Owner:" ajouté ici document.getElementById("price").textContent = visitData.price || "N/A"; // Pas de "Price:" document.getElementById("description-content").textContent = visitData.description || "No description available."; } catch (error) { document.getElementById("error").textContent = "Failed to load property details."; } }