11
11
:fileid="fileid"
12
12
@close="onClose" />
13
13
14
- <template v-else-if="data !== null">
15
- <img v-if="!livePhotoCanBePlayed"
16
- ref="image"
17
- :alt="alt"
14
+ <IconImageBroken v-if="!data" :size="64" />
15
+
16
+ <img v-else-if="!livePhotoCanBePlayed"
17
+ ref="image"
18
+ :alt="alt"
19
+ :class="{
20
+ dragging,
21
+ loaded,
22
+ zoomed: zoomRatio > 1
23
+ }"
24
+ :src="data"
25
+ :style="imgStyle"
26
+ @error.capture.prevent.stop.once="onFail"
27
+ @load="updateImgSize"
28
+ @wheel.stop.prevent="updateZoom"
29
+ @dblclick.prevent="onDblclick"
30
+ @pointerdown.prevent="pointerDown"
31
+ @pointerup.prevent="pointerUp"
32
+ @pointermove.prevent="pointerMove">
33
+
34
+ <template v-else-if="livePhoto">
35
+ <video v-show="livePhotoCanBePlayed"
36
+ ref="video"
18
37
:class="{
19
38
dragging,
20
39
loaded,
21
40
zoomed: zoomRatio > 1
22
41
}"
23
- :src="data"
24
42
:style="imgStyle"
25
- @error.capture.prevent.stop.once="onFail"
26
- @load="updateImgSize"
43
+ :playsinline="true"
44
+ :poster="data"
45
+ :src="livePhotoSrc"
46
+ preload="metadata"
47
+ @canplaythrough="doneLoadingLivePhoto"
48
+ @loadedmetadata="updateImgSize"
27
49
@wheel.stop.prevent="updateZoom"
50
+ @error.capture.prevent.stop.once="onFail"
28
51
@dblclick.prevent="onDblclick"
29
52
@pointerdown.prevent="pointerDown"
30
53
@pointerup.prevent="pointerUp"
31
- @pointermove.prevent="pointerMove">
32
-
33
- <template v-if="livePhoto">
34
- <video v-show="livePhotoCanBePlayed"
35
- ref="video"
36
- :class="{
37
- dragging,
38
- loaded,
39
- zoomed: zoomRatio > 1
40
- }"
41
- :style="imgStyle"
42
- :playsinline="true"
43
- :poster="data"
44
- :src="livePhotoSrc"
45
- preload="metadata"
46
- @canplaythrough="doneLoadingLivePhoto"
47
- @loadedmetadata="updateImgSize"
48
- @wheel.stop.prevent="updateZoom"
49
- @error.capture.prevent.stop.once="onFail"
50
- @dblclick.prevent="onDblclick"
51
- @pointerdown.prevent="pointerDown"
52
- @pointerup.prevent="pointerUp"
53
- @pointermove.prevent="pointerMove"
54
- @ended="stopLivePhoto" />
55
- <button v-if="width !== 0"
56
- class="live-photo_play_button"
57
- :style="{left: `calc(50% - ${width/2}px)`}"
58
- :disabled="!livePhotoCanBePlayed"
59
- :aria-description="t('viewer', 'Play the live photo')"
60
- @click="playLivePhoto"
61
- @pointerenter="playLivePhoto"
62
- @focus="playLivePhoto"
63
- @pointerleave="stopLivePhoto"
64
- @blur="stopLivePhoto">
65
- <PlayCircleOutline v-if="livePhotoCanBePlayed" />
66
- <NcLoadingIcon v-else />
67
- <!-- TRANSLATORS Label of the button used at the top left corner of live photos to play them -->
68
- {{ t('viewer', 'LIVE') }}
69
- </button>
70
- </template>
54
+ @pointermove.prevent="pointerMove"
55
+ @ended="stopLivePhoto" />
56
+ <button v-if="width !== 0"
57
+ class="live-photo_play_button"
58
+ :style="{left: `calc(50% - ${width/2}px)`}"
59
+ :disabled="!livePhotoCanBePlayed"
60
+ :aria-description="t('viewer', 'Play the live photo')"
61
+ @click="playLivePhoto"
62
+ @pointerenter="playLivePhoto"
63
+ @focus="playLivePhoto"
64
+ @pointerleave="stopLivePhoto"
65
+ @blur="stopLivePhoto">
66
+ <PlayCircleOutline v-if="livePhotoCanBePlayed" />
67
+ <NcLoadingIcon v-else />
68
+ <!-- TRANSLATORS Label of the button used at the top left corner of live photos to play them -->
69
+ {{ t('viewer', 'LIVE') }}
70
+ </button>
71
71
</template>
72
72
</div>
73
73
</template>
76
76
import Vue from 'vue'
77
77
import AsyncComputed from 'vue-async-computed'
78
78
import PlayCircleOutline from 'vue-material-design-icons/PlayCircleOutline.vue'
79
+ import IconImageBroken from 'vue-material-design-icons/ImageBroken.vue'
79
80
80
81
import axios from '@nextcloud/axios'
81
82
import { basename } from '@nextcloud/paths'
@@ -85,13 +86,15 @@ import { NcLoadingIcon } from '@nextcloud/vue'
85
86
import ImageEditor from './ImageEditor.vue'
86
87
import { findLivePhotoPeerFromFileId } from '../utils/livePhotoUtils'
87
88
import { getDavPath } from '../utils/fileUtils'
89
+ import { getPreviewIfAny } from '../utils/previewUtils'
88
90
89
91
Vue.use(AsyncComputed)
90
92
91
93
export default {
92
94
name: 'Images',
93
95
94
96
components: {
97
+ IconImageBroken,
95
98
ImageEditor,
96
99
PlayCircleOutline,
97
100
NcLoadingIcon,
@@ -175,23 +178,35 @@ export default {
175
178
176
179
// Load the raw gif instead of the static preview
177
180
if (this.mime === 'image/gif') {
181
+ // if the source failed fallback to the preview
182
+ if (this.fallback) {
183
+ return this.previewPath
184
+ }
178
185
return this.src
179
186
}
180
187
181
- // If there is no preview and we have a direct source
182
- // load it instead
183
- if (this.source && !this.hasPreview && !this.previewUrl) {
184
- return this.source
188
+ // First try the preview if any
189
+ if (!this.fallback && this.previewPath) {
190
+ return this.previewPath
185
191
}
186
192
187
193
// If loading the preview failed once, let's load the original file
188
- if (this.fallback) {
189
- return this.src
190
- }
194
+ return this.src
195
+ },
191
196
192
- return this.previewPath
197
+ async previewPath() {
198
+ return await getPreviewIfAny({
199
+ ...this.$attrs,
200
+ fileid: this.fileid,
201
+ filename: this.filename,
202
+ previewUrl: this.previewUrl,
203
+ hasPreview: this.hasPreview,
204
+ davPath: this.davPath,
205
+ etag: this.$attrs.etag,
206
+ })
193
207
},
194
208
},
209
+
195
210
watch: {
196
211
active(val, old) {
197
212
// the item was hidden before and is now the current view
0 commit comments