Created
July 5, 2021 11:10
-
-
Save pprathameshmore/aca0798c7c712baa18e27586df1cb098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from "axios"; | |
import React from "react"; | |
const FileDownload = require("js-file-download"); | |
export default function VideoDownloader(props) { | |
console.log(props); | |
const { video } = props; | |
const { _id, title, thumbnail } = video; | |
const downloadVideo = async (event) => { | |
const videoId = event.target.id; | |
const filename = event.target.title; | |
console.log(filename); | |
axios | |
.get("http://localhost:3000/api/downloads/" + videoId + "/downloadfile", { | |
responseType: "blob", | |
}) | |
.then((response) => { | |
FileDownload(response.data, `${filename}.mp4`); | |
}); | |
}; | |
const removeVideo = async (event) => { | |
const videoId = event.target.title; | |
axios | |
.delete("http://localhost:3000/api/downloads/" + videoId) | |
.then((respsonse) => { | |
window.location.reload(); | |
}); | |
}; | |
return ( | |
<div className="card" style={{ width: "18rem" }}> | |
<img src={thumbnail} class="card-img-top" alt="thumbnail" /> | |
<div className="card-body"> | |
<h6 className="card-text">{title}</h6> | |
<button | |
id={_id} | |
className="btn btn-success rounded" | |
style={{ width: "100px" }} | |
onClick={downloadVideo} | |
title={title} | |
> | |
Download | |
</button> | |
<button | |
title={_id} | |
className="btn btn-danger rounded" | |
onClick={removeVideo} | |
> | |
Delete | |
</button> | |
</div> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment