1111 </div >
1212 <div class =" modal-body text-center" >
1313 <template v-if =" showCropperModule " >
14- <cropper-module v-bind:imgUrl = " imgUrl "
14+ <cropper-module v-bind:imgSrc = " imgSrc "
1515 v-bind:maxHeight =" maxHeight"
1616 v-on:closeCropper =" closeCropper" ></cropper-module >
1717 </template >
18- <template v-else >
19- <img v-bind:src =" imgUrl"
18+ <transition v-else name =" fade" mode =" out-in" >
19+ <i v-if =" !imgSrc" class =" fas fa-spinner fa-spin fa-5x p-5 text-muted" ></i >
20+ <img v-else
21+ v-bind:src =" imgSrc"
2022 v-bind:alt =" selectedItem.basename"
2123 v-bind:style =" {'max-height': maxHeight+'px'}" >
22- </template >
24+ </transition >
2325 </div >
2426 <div v-if =" showFooter" class =" d-flex justify-content-between" >
2527 <span class =" d-block" >
@@ -40,6 +42,7 @@ import CropperModule from './../additions/Cropper.vue';
4042import modal from ' ./../mixins/modal' ;
4143import translate from ' ./../../../mixins/translate' ;
4244import helper from ' ./../../../mixins/helper' ;
45+ import GET from ' ./../../../http/get' ;
4346
4447export default {
4548 name: ' Preview' ,
@@ -48,14 +51,21 @@ export default {
4851 data () {
4952 return {
5053 showCropperModule: false ,
51- imgUrl : ' ' ,
54+ imgSrc : ' ' ,
5255 };
5356 },
5457 created () {
55- // Create image URL
56- this .setImgUrl ();
58+ this .loadImage ();
5759 },
5860 computed: {
61+ /**
62+ * Authorization required
63+ * @return {*}
64+ */
65+ auth () {
66+ return this .$store .getters [' fm/settings/authHeader' ];
67+ },
68+
5969 /**
6070 * Selected disk
6171 * @returns {*}
@@ -103,18 +113,31 @@ export default {
103113 },
104114
105115 /**
106- * Set image URL
116+ * Close cropper
107117 */
108- setImgUrl () {
109- this .imgUrl = ` ${ this .$store .getters [' fm/settings/baseUrl' ]} preview?disk=${ this .selectedDisk } &path=${ encodeURIComponent (this .selectedItem .path )} &v=${ this .selectedItem .timestamp } ` ;
118+ closeCropper () {
119+ this .showCropperModule = false ;
120+ this .loadImage ();
110121 },
111122
112123 /**
113- * Close cropper
124+ * Load image
114125 */
115- closeCropper () {
116- this .showCropperModule = false ;
117- this .setImgUrl ();
126+ loadImage () {
127+ // if authorization required
128+ if (this .auth ) {
129+ GET .preview (
130+ this .selectedDisk ,
131+ this .selectedItem .path ,
132+ ).then ((response ) => {
133+ const mimeType = response .headers [' content-type' ].toLowerCase ();
134+ const imgBase64 = Buffer .from (response .data , ' binary' ).toString (' base64' );
135+
136+ this .imgSrc = ` data:${ mimeType} ;base64,${ imgBase64} ` ;
137+ });
138+ } else {
139+ this .imgSrc = ` ${ this .$store .getters [' fm/settings/baseUrl' ]} preview?disk=${ this .selectedDisk } &path=${ encodeURIComponent (this .selectedItem .path )} &v=${ this .selectedItem .timestamp } ` ;
140+ }
118141 },
119142 },
120143};
0 commit comments