Skip to content

Commit 7401d16

Browse files
authored
feat: prefetch previous and next images in preview. (#1627)
1 parent 958a44f commit 7401d16

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

frontend/src/views/files/Preview.vue

+16-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
>
138138
<i class="material-icons">chevron_right</i>
139139
</button>
140+
<link rel="prefetch" :href="previousRaw">
141+
<link rel="prefetch" :href="nextRaw">
140142
</div>
141143
</template>
142144

@@ -146,7 +148,6 @@ import { files as api } from "@/api";
146148
import { baseURL, resizePreview } from "@/utils/constants";
147149
import url from "@/utils/url";
148150
import throttle from "lodash.throttle";
149-
150151
import HeaderBar from "@/components/header/HeaderBar";
151152
import Action from "@/components/header/Action";
152153
import ExtendedImage from "@/components/files/ExtendedImage";
@@ -172,6 +173,8 @@ export default {
172173
navTimeout: null,
173174
hoverNav: false,
174175
autoPlay: false,
176+
previousRaw: "",
177+
nextRaw: "",
175178
};
176179
},
177180
computed: {
@@ -302,20 +305,31 @@ export default {
302305
for (let j = i - 1; j >= 0; j--) {
303306
if (mediaTypes.includes(this.listing[j].type)) {
304307
this.previousLink = this.listing[j].url;
308+
this.previousRaw = this.prefetchUrl(this.listing[j]);
305309
break;
306310
}
307311
}
308-
309312
for (let j = i + 1; j < this.listing.length; j++) {
310313
if (mediaTypes.includes(this.listing[j].type)) {
311314
this.nextLink = this.listing[j].url;
315+
this.nextRaw = this.prefetchUrl(this.listing[j]);
312316
break;
313317
}
314318
}
315319
316320
return;
317321
}
318322
},
323+
prefetchUrl: function(item) {
324+
const key = Date.parse(item.modified);
325+
if (item.type === "image" && !this.fullSize) {
326+
return `${baseURL}/api/preview/big${item.path}?k=${key}&inline=true`;
327+
} else if (item.type === "image"){
328+
return `${baseURL}/api/raw${item.path}?k=${key}&inline=true`;
329+
} else{
330+
return "";
331+
}
332+
},
319333
openMore() {
320334
this.$store.commit("showHover", "more");
321335
},

0 commit comments

Comments
 (0)