1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<figure class="fm-thumbnail">
<transition name="fade" mode="out-in">
<i v-if="!src" class="far fa-file-image fa-5x pb-2"/>
<img v-else
v-bind:src="src"
v-bind:alt="file.filename"
class="img-thumbnail">
</transition>
</figure>
</template>
<script>
import GET from '@/api/get';
export default {
name: 'Thumbnail',
data() {
return {
src: '',
};
},
props: {
disk: {
type: String,
required: true,
},
file: {
type: Object,
required: true,
},
},
watch: {
'file.timestamp': 'loadImage',
},
mounted() {
if (window.IntersectionObserver) {
const observer = new IntersectionObserver(
(entries, obs) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
this.loadImage();
obs.unobserve(this.$el);
}
});
},
{
root: null,
threshold: '0.5',
},
);
// add observer for template
observer.observe(this.$el);
} else {
this.loadImage();
}
},
computed: {
/**
* Authorization required
* @return {*}
*/
auth() {
return this.$store.getters['fm/settings/authHeader'];
},
},
methods: {
/**
* Load image
*/
loadImage() {
// if authorization required
if (this.auth) {
GET.thumbnail(
this.disk,
this.file.path,
).then((response) => {
const mimeType = response.headers['content-type'].toLowerCase();
const imgBase64 = Buffer.from(response.data, 'binary').toString('base64');
this.src = `data:${mimeType};base64,${imgBase64}`;
});
} else {
this.src = `${this.$store.getters['fm/settings/baseUrl']}thumbnails?disk=${this.disk}&path=${encodeURIComponent(this.file.path)}&v=${this.file.timestamp}`;
}
},
},
};
</script>
<style lang="scss">
.fm-thumbnail {
display: flex;
justify-content: center;
align-items: center;
.img-thumbnail {
width: 88px;
height: 88px;
}
.fade-enter-active, .fade-leave-active {
transition: opacity .3s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
}
</style>