[UI] Use thumbnail path for thumbs
This commit is contained in:
parent
e1995f44ce
commit
3afa872cec
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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())) {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user