diff --git a/file_peer/peer_service.py b/file_peer/peer_service.py index 4e1fb15..8014ed4 100644 --- a/file_peer/peer_service.py +++ b/file_peer/peer_service.py @@ -54,7 +54,7 @@ def send(): ) -@app.route("/request", methods=["GET"]) +@app.route("/request", methods=["POST"]) def request_file(): data = request.json file_id = data["id"] @@ -64,7 +64,7 @@ def request_file(): url = f"http://{ip}:8080/send" params = { "id": file_id, - "filename": filename, + "filename": filename.replace(" ", "_"), } response = requests.get(url, params=params) diff --git a/frontend/src/hooks/usePoll.ts b/frontend/src/hooks/usePoll.ts index 598ef2b..ff3bc1d 100644 --- a/frontend/src/hooks/usePoll.ts +++ b/frontend/src/hooks/usePoll.ts @@ -7,7 +7,7 @@ export const usePoll = () => { .catch((error) => { console.error('Error:', error); }); - }, 30 * 60000) // poll every 30 minutes + }, 30 * 60000) // poll every 30 minutes return () => { // clean up clearInterval(interval); @@ -16,7 +16,7 @@ export const usePoll = () => { const pollServer = async () => { // request private ip from local api - return fetch('http://127.0.0.1:8080/ip') + return fetch('http://localhost:8080/ip') .then(response => response.text()) .then((data) => { // send private ip to central server diff --git a/frontend/src/screens/Results.tsx b/frontend/src/screens/Results.tsx index f889044..29415cb 100644 --- a/frontend/src/screens/Results.tsx +++ b/frontend/src/screens/Results.tsx @@ -72,7 +72,7 @@ const Results: React.FC = () => { {file.upvotes.length} {file.downvotes.length} {file.original_author.username} - Download + ))} @@ -86,3 +86,36 @@ const Results: React.FC = () => { }; export default Results; + + +function DownloadButton({ file }: { file: File }) { + const [success, setSuccess] = useState(false); + const handleDownload = () => { + // Implement download functionality + fetch("http://localhost:8080/request", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ id: file.id, filename: file.filename, ip: file.original_author.ip_address }), + }) + .then((response) => response.text()) + .then((data) => { + console.log("Success download response data:", data); + setSuccess(true); + }) + .catch((error) => { + console.error("Error:", error); + setSuccess(false); + }); + }; + return ( + <> + { + success === true ? +

Downloaded!

: + + } + + ); +} \ No newline at end of file