feat: prefetch previous and next images in preview. (#1627)

pull/1631/head^2
niubility000 2021-11-15 21:54:28 +08:00 committed by GitHub
parent 958a44f95e
commit 7401d16e45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 2 deletions

View File

@ -137,6 +137,8 @@
> >
<i class="material-icons">chevron_right</i> <i class="material-icons">chevron_right</i>
</button> </button>
<link rel="prefetch" :href="previousRaw">
<link rel="prefetch" :href="nextRaw">
</div> </div>
</template> </template>
@ -146,7 +148,6 @@ import { files as api } from "@/api";
import { baseURL, resizePreview } from "@/utils/constants"; import { baseURL, resizePreview } from "@/utils/constants";
import url from "@/utils/url"; import url from "@/utils/url";
import throttle from "lodash.throttle"; import throttle from "lodash.throttle";
import HeaderBar from "@/components/header/HeaderBar"; import HeaderBar from "@/components/header/HeaderBar";
import Action from "@/components/header/Action"; import Action from "@/components/header/Action";
import ExtendedImage from "@/components/files/ExtendedImage"; import ExtendedImage from "@/components/files/ExtendedImage";
@ -172,6 +173,8 @@ export default {
navTimeout: null, navTimeout: null,
hoverNav: false, hoverNav: false,
autoPlay: false, autoPlay: false,
previousRaw: "",
nextRaw: "",
}; };
}, },
computed: { computed: {
@ -302,13 +305,14 @@ export default {
for (let j = i - 1; j >= 0; j--) { for (let j = i - 1; j >= 0; j--) {
if (mediaTypes.includes(this.listing[j].type)) { if (mediaTypes.includes(this.listing[j].type)) {
this.previousLink = this.listing[j].url; this.previousLink = this.listing[j].url;
this.previousRaw = this.prefetchUrl(this.listing[j]);
break; break;
} }
} }
for (let j = i + 1; j < this.listing.length; j++) { for (let j = i + 1; j < this.listing.length; j++) {
if (mediaTypes.includes(this.listing[j].type)) { if (mediaTypes.includes(this.listing[j].type)) {
this.nextLink = this.listing[j].url; this.nextLink = this.listing[j].url;
this.nextRaw = this.prefetchUrl(this.listing[j]);
break; break;
} }
} }
@ -316,6 +320,16 @@ export default {
return; return;
} }
}, },
prefetchUrl: function(item) {
const key = Date.parse(item.modified);
if (item.type === "image" && !this.fullSize) {
return `${baseURL}/api/preview/big${item.path}?k=${key}&inline=true`;
} else if (item.type === "image"){
return `${baseURL}/api/raw${item.path}?k=${key}&inline=true`;
} else{
return "";
}
},
openMore() { openMore() {
this.$store.commit("showHover", "more"); this.$store.commit("showHover", "more");
}, },