add download button

This commit is contained in:
Simon Vieille 2020-03-22 20:34:33 +01:00
parent 06977855aa
commit 7491ee3121
Signed by: deblan
GPG Key ID: 03383D15A1D31745
4 changed files with 35 additions and 1 deletions

View File

@ -30,6 +30,13 @@
.modal-movie .modal-content {
width: 95%;
max-width: 1280px;
background: #242627;
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
}
.button-download {
margin: 5px;
}
.movie {

View File

@ -90,7 +90,7 @@ var SnapshotEvent = function() {
forEach(links, function(i, link) {
link.addEventListener('click', function(e) {
e.preventDefault();
view.innerHTML = template.innerHTML.replace('{src}', link.getAttribute('href'));
view.innerHTML = template.innerHTML.replace(/{src}/g, link.getAttribute('href'));
view.querySelector('.modal-close').addEventListener('click', function() {
view.innerHTML = '';

View File

@ -6,6 +6,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Filesystem\Filesystem;
use App\Motion\SnapshotRepository;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
class EventController extends AbstractController
{
@ -36,4 +38,26 @@ class EventController extends AbstractController
'date' => $date,
]);
}
/**
* @Route("/download_snapshot", name="download_snapshot")
*/
public function downloadSnapshot(SnapshotRepository $snapshotRepository, Request $request): BinaryFileResponse
{
$src = ltrim($request->query->get('src'), '/');
$snapshots = $snapshotRepository->find();
foreach ($snapshots as $snapshot) {
if ($snapshot->getMovie() === $src) {
return new BinaryFileResponse($src, 200, [
'Content-Type' => 'application/octect-stream',
'Content-Length' => filesize($src),
'Content-Disposition' => sprintf('attachment; filename="%s"', basename($src)),
'Content-Transfer-Encoding' => 'binary',
]);
}
}
throw $this->createNotFoundException();
}
}

View File

@ -32,6 +32,9 @@
<video controls class="image movie">
<source src="{src}" type="video/mp4" />
</video>
<a href="{{ path('download_snapshot') }}?src={src}">
<button class="button button-download is-dark">Télécharger</button>
</a>
</div>
<button class="modal-close is-large" aria-label="close"></button>
</div>