[UI] Use thumbnail path for thumbs

This commit is contained in:
Diogo Peralta Cordeiro 2021-04-19 12:20:10 +01:00 committed by Hugo Sales
parent e1995f44ce
commit 3afa872cec
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 20 additions and 5 deletions

View File

@ -52,7 +52,7 @@ class ImageEncoder extends Plugin
{ {
$original_mimetype = $mimetype ?? $sfile->getMimeType(); $original_mimetype = $mimetype ?? $sfile->getMimeType();
// TODO: Encode in place // TODO: Encode in place
$mimetype = self::preferredType(); //$mimetype = self::preferredType();
return Event::stop; return Event::stop;
} }

View File

@ -26,8 +26,11 @@ use App\Core\DB\DB;
use App\Core\GSFile; use App\Core\GSFile;
use App\Entity\AttachmentThumbnail; use App\Entity\AttachmentThumbnail;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\NotFoundException;
use App\Util\Exception\ServerException;
use Symfony\Component\HttpFoundation\HeaderUtils; use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class Attachment extends Controller class Attachment extends Controller
{ {
@ -49,7 +52,18 @@ class Attachment extends Controller
return GSFile::sendFile($res['file_path'], $res['mimetype'], $res['title'], HeaderUtils::DISPOSITION_ATTACHMENT); return GSFile::sendFile($res['file_path'], $res['mimetype'], $res['title'], HeaderUtils::DISPOSITION_ATTACHMENT);
} }
public function attachment_thumbnail(Request $request, int $id) /**
* Controller to produce a thumbnail for a given attachment id
*
* @param Request $request
* @param int $id Attachment ID
*
* @throws NotFoundException
* @throws ServerException
*
* @return Response
*/
public function attachment_thumbnail(Request $request, int $id): Response
{ {
$attachment = DB::findOneBy('attachment', ['id' => $id]); $attachment = DB::findOneBy('attachment', ['id' => $id]);
if (!is_null($attachment->getScope())) { if (!is_null($attachment->getScope())) {

View File

@ -44,6 +44,6 @@ abstract class Attachments
$r->connect('attachment_view', '/attachment/{id<\d+>}/view', [C\Attachment::class, 'attachment_view']); $r->connect('attachment_view', '/attachment/{id<\d+>}/view', [C\Attachment::class, 'attachment_view']);
$r->connect('attachment_download', '/attachment/{id<\d+>}/download', [C\Attachment::class, 'attachment_download']); $r->connect('attachment_download', '/attachment/{id<\d+>}/download', [C\Attachment::class, 'attachment_download']);
$r->connect('attachment_thumbnail', '/attachment/{id<\d+>}/thumbnail', [C\Attachment::class, 'attachment_thumbnail']); $r->connect('attachment_thumbnail', '/attachment/{id<\d+>}/thumbnail', [C\Attachment::class, 'attachment_thumbnail']);
$r->connect('thumbnail', '/thumbnail/{id<\d+>}', [C\Attachment::class, 'attachment_thumbnail']); $r->connect('thumbnail', '/thumbnail/{id<\d+>}', [C\Attachment::class, 'attachment_thumbnail']); // Backwards-compatibility
} }
} }

View File

@ -23,16 +23,17 @@
</div> </div>
<div class="note-attachments"> <div class="note-attachments">
{% for attachment in note.getAttachments() %} {% for attachment in note.getAttachments() %}
{% set thumbnail_parameters = {'id': attachment.getId(), 'w': config('thumbnail','width'), 'h': config('thumbnail','height')} %}
{% if attachment.mimetype starts with 'image/' %} {% if attachment.mimetype starts with 'image/' %}
<div> <div>
<figure> <figure>
<img src="{{ path('attachment_view', {'id': attachment.getId()}) }}" alt="{{ attachment.getTitle() }}"> <img src="{{ path('attachment_thumbnail', thumbnail_parameters) }}" alt="{{ attachment.getTitle() }}">
<figcaption> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </figcaption> <figcaption> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </figcaption>
</figure> </figure>
</div> </div>
{% elseif attachment.mimetype starts with 'video/' %} {% elseif attachment.mimetype starts with 'video/' %}
<div> <div>
<video src="{{ path('attachment_view', {'id': attachment.getId()}) }}"> <video src="{{ path('attachment_view', {'id': attachment.getId()}) }}" controls poster="{{ path('attachment_thumbnail') }}, thumbnail_parameters">
<i> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </i> <i> <a href="{{ path('attachment_show', {'id': attachment.getId()}) }}">{{ attachment.getTitle() }}</a> </i>
</video> </video>
</div> </div>