feat(gallery): use authorized content types

This commit is contained in:
Eric Leroy-Terquem 2024-04-05 14:25:28 +02:00
parent f02cb19fd4
commit 7c6c3608c9
No known key found for this signature in database
GPG key ID: ECE60B4C1FA2ABB3
2 changed files with 25 additions and 12 deletions

View file

@ -8,8 +8,8 @@
- champ.piece_justificative_file.each do |attachment|
.gallery-item
- blob = attachment.blob
- if blob.content_type == 'application/pdf'
= link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: "application/pdf", title: "#{champ.libelle} -- #{blob.filename}" do
- if blob.content_type.in?(AUTHORIZED_PDF_TYPES)
= link_to blob.url, id: blob.id, data: { iframe: true, src: blob.url }, class: 'gallery-link', type: blob.content_type, title: "#{champ.libelle} -- #{blob.filename}" do
.thumbnail
= image_tag("pdf-placeholder.png")
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }
@ -18,7 +18,7 @@
= champ.libelle
= render Attachment::ShowComponent.new(attachment: attachment, new_tab: true)
- else
- elsif blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
= link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
.thumbnail
= image_tag(blob.url)
@ -27,3 +27,10 @@
.champ-libelle
= champ.libelle
= render Attachment::ShowComponent.new(attachment: attachment, new_tab: true)
- else
.thumbnail
= image_tag('apercu-indisponible.png')
.champ-libelle
= champ.libelle
= render Attachment::ShowComponent.new(attachment: attachment, new_tab: true)

View file

@ -1,15 +1,25 @@
AUTHORIZED_CONTENT_TYPES = [
# multimedia
AUTHORIZED_PDF_TYPES = [
'application/pdf', # text x 4628654
'application/x-pdf', # text x 30
'image/pdf', # text x 23
'text/pdf' # text x 12
]
AUTHORIZED_IMAGE_TYPES = [
'image/jpeg', # multimedia x 1467465
'image/png', # multimedia x 126662
'image/tiff', # multimedia x 3985
'image/bmp', # multimedia x 3656
'video/mp4', # multimedia x 2075
'image/webp', # multimedia x 529
'video/quicktime', # multimedia x 486
'image/gif', # multimedia x 463
'image/vnd.dwg' # multimedia x 137 auto desk
]
AUTHORIZED_CONTENT_TYPES = AUTHORIZED_IMAGE_TYPES + AUTHORIZED_PDF_TYPES + [
# multimedia
'video/mp4', # multimedia x 2075
'video/quicktime', # multimedia x 486
'video/3gpp', # multimedia x 216
'image/vnd.dwg', # multimedia x 137 auto desk
'audio/mpeg', # multimedia x 26
'video/x-ms-wm', # multimedia x 15 video microsoft ?
'audio/mp4', # audio .mp4, .m4a
@ -45,7 +55,6 @@ AUTHORIZED_CONTENT_TYPES = [
'text/xml', # program x 10
# text / sheet / presentation
'application/pdf', # text x 4628654
'application/vnd.ms-excel', # text x 166674
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', # text x 103879
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', # text x 86336
@ -69,18 +78,15 @@ AUTHORIZED_CONTENT_TYPES = [
'application/vnd.ms-word.document.macroenabled.12', # text x 61
'application/vnd.openxmlformats-officedocument.spreadsheetml.template', # text x 59
'application/vnd.openxmlformats-officedocument.presentationml.slideshow', # text x 32
'application/x-pdf', # text x 30
'application/kswps', # inconnu x 26 , text ?
'application/x-iwork-numbers-sffnumbers', # text x 25
'text/rtf', # text x 25
'image/pdf', # text x 23
'application/vnd.ms-xpsdocument', # text x 23
'application/vnd.ms-excel.sheet.binary.macroenabled.12', # text x 21
'application/vnd.ms-powerpoint.presentation.macroenabled.12', # text x 15
'application/x-msword', # text x 15
'application/vnd.oasis.opendocument.spreadsheet-template', # text x 14
'application/vnd.oasis.opendocument.text-master', # text x 12
'text/pdf', # text x 12
'application/x-abiword', # text x 11
'application/x-iwork-keynote-sffnumbers', # text x 11
'application/x-iwork-keynote-sffkey', # text x 10