11# encoding: utf-8
22# Created J/12/12/2013
3- # Updated D/03/05 /2020
3+ # Updated J/02/07 /2020
44#
55# Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
66# https://www.luigifab.fr/redmine/apijs
@@ -41,29 +41,33 @@ def find_project
4141 end
4242
4343
44- # #### Gestion de l'image miniature (photo ou vidéo) ################################ public ## # #
45- # » Vérifie si l'utilisateur a accès au projet avant l'envoi de la miniature au format JPG ou PNG
44+ # #### Gestion de l'image miniature (photo ou vidéo) ################################# #
45+ # » Vérifie si l'utilisateur a accès au projet avant l'envoi de la miniature
4646 # » Utilise un script python pour générer l'image thumb (taille 200x150)
47+ # » Utilise un script python pour générer l'image srcset (taille 400x300)
4748 # » Utilise un script python pour générer l'image show (taille 1200x900)
4849 # » Enregistre les commandes et leurs résultats dans le log
4950 # » Téléchargement d'une image avec mise en cache (inline/stale)
5051 def thumb
5152
5253 source = @attachment . diskfile
53- img_thumb = File . extname ( @attachment . filename ) . downcase == '.png' ? '.png' : '.jpg'
54- img_thumb = File . join ( APIJS_ROOT , 'thumb' , @attachment . created_on . strftime ( '%Y-%m' ) . to_s , @attachment . id . to_s + img_thumb )
54+ img_thumb = File . join ( APIJS_ROOT , 'thumb' , @attachment . created_on . strftime ( '%Y-%m' ) . to_s , @attachment . id . to_s + @attachment . getExt )
5555
5656 # génération de l'image thumb
5757 if File . file? ( source ) && !File . file? ( img_thumb )
58- cmd = @attachment . getCmd ( source , img_thumb , 200 , 150 )
58+ cmd = @attachment . getCmd ( source , img_thumb , 200 , 150 , true )
5959 logger . info 'APIJS::ApijsController#thumb: ' + cmd + ' (' + `#{ cmd } ` . gsub ( /^\s +|\s +$/ , '' ) + ')'
6060 end
61- # génération de l'image show
61+ # génération des images srcset et show
6262 if @attachment . isPhoto? && Setting . plugin_redmine_apijs [ 'create_all' ] == '1' && File . file? ( source )
63- img_show = File . extname ( @attachment . filename ) . downcase == '.png' ? '.png' : '.jpg'
64- img_show = File . join ( APIJS_ROOT , 'show' , @attachment . created_on . strftime ( '%Y-%m' ) . to_s , @attachment . id . to_s + img_show )
63+ img_srcset = File . join ( APIJS_ROOT , 'srcset' , @attachment . created_on . strftime ( '%Y-%m' ) . to_s , @attachment . id . to_s + @attachment . getExt )
64+ unless File . file? ( img_srcset )
65+ cmd = @attachment . getCmd ( source , img_srcset , 400 , 300 , true )
66+ logger . info 'APIJS::ApijsController#thumb: ' + cmd + ' (' + `#{ cmd } ` . gsub ( /^\s +|\s +$/ , '' ) + ')'
67+ end
68+ img_show = File . join ( APIJS_ROOT , 'show' , @attachment . created_on . strftime ( '%Y-%m' ) . to_s , @attachment . id . to_s + @attachment . getExt )
6569 unless File . file? ( img_show )
66- cmd = @attachment . getCmd ( source , img_show , 1200 , 900 )
70+ cmd = @attachment . getCmd ( source , img_show , 1200 , 900 , false )
6771 logger . info 'APIJS::ApijsController#thumb: ' + cmd + ' (' + `#{ cmd } ` . gsub ( /^\s +|\s +$/ , '' ) + ')'
6872 end
6973 end
@@ -74,25 +78,51 @@ def thumb
7478 # envoie de l'image avec mise en cache
7579 elsif File . file? ( img_thumb ) && stale? ( etag : img_thumb )
7680 send_file ( img_thumb , filename : filename_for_content_disposition ( @attachment . filename ) ,
77- type : File . extname ( img_thumb ) . downcase == '.png' ? 'image/png' : 'image/jpeg' , disposition : 'inline' )
81+ type : Redmine ::MimeType . of ( img_thumb ) , disposition : 'inline' )
82+ end
83+ end
84+
85+
86+ # #### Gestion de l'image miniature 2x (photo ou vidéo) ############################## #
87+ # » Vérifie si l'utilisateur a acc��s au projet avant l'envoi de l'aperçu
88+ # » Utilise un script python pour générer l'image srcset (taille 400x300)
89+ # » Enregistre les commandes et leurs résultats dans le log
90+ # » Téléchargement d'une image avec mise en cache (inline/stale)
91+ def srcset
92+
93+ source = @attachment . diskfile
94+ img_srcset = File . join ( APIJS_ROOT , 'srcset' , @attachment . created_on . strftime ( '%Y-%m' ) . to_s , @attachment . id . to_s + @attachment . getExt )
95+
96+ # génération de l'image srcset
97+ if File . file? ( source ) && !File . file? ( img_srcset )
98+ cmd = @attachment . getCmd ( source , img_srcset , 400 , 300 , true )
99+ logger . info 'APIJS::ApijsController#srcset: ' + cmd + ' (' + `#{ cmd } ` . gsub ( /^\s +|\s +$/ , '' ) + ')'
100+ end
101+
102+ # vérification d'accès
103+ if !User . current . allowed_to? ( { controller : 'projects' , action : 'show' } , @project )
104+ deny_access
105+ # envoie de l'image avec mise en cache
106+ elsif File . file? ( img_srcset ) && stale? ( etag : img_srcset )
107+ send_file ( img_srcset , filename : filename_for_content_disposition ( @attachment . filename ) ,
108+ type : Redmine ::MimeType . of ( img_srcset ) , disposition : 'inline' )
78109 end
79110 end
80111
81112
82- # #### Gestion de l'image aperçu (photo) ############################################ public ## # #
83- # » Vérifie si l'utilisateur a accès au projet avant l'envoi de l'aperçu au format JPG ou PNG
113+ # #### Gestion de l'image aperçu (photo) ############################################# #
114+ # » Vérifie si l'utilisateur a accès au projet avant l'envoi de l'aperçu
84115 # » Utilise un script python pour générer l'image show (taille 1200x900)
85116 # » Enregistre les commandes et leurs résultats dans le log
86117 # » Téléchargement d'une image avec mise en cache (inline/stale)
87118 def show
88119
89120 source = @attachment . diskfile
90- img_show = File . extname ( @attachment . filename ) . downcase == '.png' ? '.png' : '.jpg'
91- img_show = File . join ( APIJS_ROOT , 'show' , @attachment . created_on . strftime ( '%Y-%m' ) . to_s , @attachment . id . to_s + img_show )
121+ img_show = File . join ( APIJS_ROOT , 'show' , @attachment . created_on . strftime ( '%Y-%m' ) . to_s , @attachment . id . to_s + @attachment . getExt )
92122
93123 # génération de l'image show
94124 if File . file? ( source ) && !File . file? ( img_show )
95- cmd = @attachment . getCmd ( source , img_show , 1200 , 900 )
125+ cmd = @attachment . getCmd ( source , img_show , 1200 , 900 , false )
96126 logger . info 'APIJS::ApijsController#show: ' + cmd + ' (' + `#{ cmd } ` . gsub ( /^\s +|\s +$/ , '' ) + ')'
97127 end
98128
@@ -102,12 +132,12 @@ def show
102132 # envoie de l'image avec mise en cache
103133 elsif File . file? ( img_show ) && stale? ( etag : img_show )
104134 send_file ( img_show , filename : filename_for_content_disposition ( @attachment . filename ) ,
105- type : File . extname ( img_show ) . downcase == '.png' ? 'image/png' : 'image/jpeg' , disposition : 'inline' )
135+ type : Redmine :: MimeType . of ( img_show ) , disposition : 'inline' )
106136 end
107137 end
108138
109139
110- # #### Gestion du téléchargement des fichiers ####################################### public ## # #
140+ # #### Gestion du téléchargement des fichiers ######################################## #
111141 # » Vérifie si l'utilisateur a accès au projet avant
112142 # » Téléchargement d'une vidéo en 206 Partial Content (inline)
113143 # » Téléchargement d'une image avec mise en cache (inline/stale) ou téléchargement d'un fichier (attachment)
@@ -171,7 +201,7 @@ def download
171201 end
172202
173203
174- # #### Modification d'une description ############################################### public ## # #
204+ # #### Modification d'une description ################################################ #
175205 # » Vérifie si l'utilisateur a accès au projet et à la modification
176206 # » Renvoie l'id du fichier suivi de la description en cas de modification réussie
177207 # » Supprime certains caractères de la description avant son enregistrement
@@ -197,7 +227,7 @@ def editdesc
197227 end
198228
199229
200- # #### Suppression d'un fichier ##################################################### public ## # #
230+ # #### Suppression d'un fichier ###################################################### #
201231 # » Vérifie si l'utilisateur a accès au projet et à la suppresion
202232 # » Renvoie l'id du fichier suivi en cas de suppression réussie
203233 def delete
0 commit comments