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