Split attachment paths (#848)

* fixed attachment statistics for sqlite

* Split attachment path into internal and external path, so the external source URL can be retained after a file is downloaded

* Make internal and external path for attachments nullable, to make clear that they have no internal or external path

* Added migrations for nullable columns for postgres and mysql

* Added migration for nullable internal and external pathes for sqlite

* Added translations

* Fixed upload error

* Restrict length of filename badge in attachment edit view

* Improved margins with badges in attachment edit

* Added a link to view external version from attachment edit

* Let media_url  stay in API attachments responses for backward compatibility

---------

Co-authored-by: jona <a@b.c>
Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
This commit is contained in:
Treeed 2025-02-22 17:29:14 +01:00 committed by GitHub
parent ebb977e99f
commit 29f92d9bd3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 561 additions and 371 deletions

View file

@ -152,35 +152,32 @@
</button>
{% set attach = form.vars.value %}
{# @var \App\Entity\Attachments\Attachment attach #}
{% if attach is not null %}
{% if attachment_manager.fileExisting(attach) %}
{% if not attach.external %}
<br><br>
<h6>
{% if not attach.hasInternal() and attach.external %}
<div class="mt-2">
<span class="badge bg-primary">
<i class="fas fa-fw {{ ext_to_fa_icon(attach.extension) }}"></i> {{ attach.filename }}
<i class="fas fa-fw fa-globe"></i> {% trans %}attachment.external_only{% endtrans %}
</span>
<br>
<span class="badge bg-secondary">
</div>
{% elseif attachment_manager.isInternalFileExisting(attach) %}
<div class="mt-2">
<div class="badge bg-primary mt-2" title="{{ attach.filename }}">
<i class="fas fa-fw {{ ext_to_fa_icon(attach.extension) }}"></i> {{ attach.filename|u.truncate(25, ' ...') }}
</div>
<br>
<div class="badge bg-secondary mt-1">
<i class="fas fa-hdd fa-fw"></i> {{ attachment_manager.humanFileSize(attach) }}
</span>
</h6>
{% else %}
<br><br>
<h6>
<span class="badge bg-primary">
<i class="fas fa-fw fa-globe"></i> {% trans %}attachment.external{% endtrans %}
</span>
</h6>
{% endif %}
</div>
</div>
{% if attach.secure %}
<h6>
<div>
<span class="badge bg-success">
<i class="fas fa-fw fa-shield-alt"></i> {% trans %}attachment.secure{% endtrans %}
</span>
</h6>
</div>
{% endif %}
{% if attach.secure and not is_granted('show_private', attach) %}
@ -190,16 +187,21 @@
<img class="img-fluid img-thumbnail thumbnail-sm" src="{{ attachment_thumbnail(attach, 'thumbnail_md') }}" alt="{% trans %}attachment.preview.alt{% endtrans %}" />
</a>
{% else %}
<a href="{{ entity_url(attach, 'file_view') }}" rel="noopener" target="_blank" data-turbo="false" class="link-external">{% trans %}attachment.view{% endtrans %}</a>
<a href="{{ entity_url(attach, 'file_view') }}" rel="noopener" target="_blank" data-turbo="false" class="link-external">{% trans %}attachment.view_local{% endtrans %}</a>
{% endif %}
{% else %}
<br><br>
<h6>
<div class="mt-2">
<span class="badge bg-warning">
<i class="fas fa-exclamation-circle fa-fw"></i> {% trans %}attachment.file_not_found{% endtrans %}
</span>
</h6>
</div>
{% endif %}
{% if attach.external %}
<div>
<a href="{{ attach.externalPath }}" rel="noopener" target="_blank" data-turbo="false" class="link-external"
title="{% trans with {"%host%": attach.host} %}attachment.view_external.view_at{% endtrans %}">{% trans %}attachment.view_external{% endtrans %}</a>
</div>
{% endif %}
{% endif %}