Skip to content

Instantly share code, notes, and snippets.

@pprathameshmore
Created July 5, 2021 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pprathameshmore/aca0798c7c712baa18e27586df1cb098 to your computer and use it in GitHub Desktop.
Save pprathameshmore/aca0798c7c712baa18e27586df1cb098 to your computer and use it in GitHub Desktop.
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