mirror of
https://github.com/AmanTahiliani/PeerNotes.git
synced 2026-08-07 11:55:12 -04:00
add download functionality
This commit is contained in:
@@ -54,7 +54,7 @@ def send():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/request", methods=["GET"])
|
@app.route("/request", methods=["POST"])
|
||||||
def request_file():
|
def request_file():
|
||||||
data = request.json
|
data = request.json
|
||||||
file_id = data["id"]
|
file_id = data["id"]
|
||||||
@@ -64,7 +64,7 @@ def request_file():
|
|||||||
url = f"http://{ip}:8080/send"
|
url = f"http://{ip}:8080/send"
|
||||||
params = {
|
params = {
|
||||||
"id": file_id,
|
"id": file_id,
|
||||||
"filename": filename,
|
"filename": filename.replace(" ", "_"),
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.get(url, params=params)
|
response = requests.get(url, params=params)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export const usePoll = () => {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
});
|
});
|
||||||
}, 30 * 60000) // poll every 30 minutes
|
}, 30 * 60000) // poll every 30 minutes
|
||||||
return () => {
|
return () => {
|
||||||
// clean up
|
// clean up
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
@@ -16,7 +16,7 @@ export const usePoll = () => {
|
|||||||
|
|
||||||
const pollServer = async () => {
|
const pollServer = async () => {
|
||||||
// request private ip from local api
|
// 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(response => response.text())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
// send private ip to central server
|
// send private ip to central server
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ const Results: React.FC = () => {
|
|||||||
<td>{file.upvotes.length}</td>
|
<td>{file.upvotes.length}</td>
|
||||||
<td>{file.downvotes.length}</td>
|
<td>{file.downvotes.length}</td>
|
||||||
<td>{file.original_author.username}</td>
|
<td>{file.original_author.username}</td>
|
||||||
<td><a href="">Download</a></td>
|
<td><DownloadButton file={file} /></td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -86,3 +86,36 @@ const Results: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default Results;
|
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 ?
|
||||||
|
<p>Downloaded!</p> :
|
||||||
|
<button onClick={handleDownload}>Download</button>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user