chore: refactor url creation

This commit is contained in:
Ramires Viana
2022-05-02 13:47:22 +00:00
parent f663237a16
commit 9734f707f0
12 changed files with 106 additions and 69 deletions

View File

@@ -103,7 +103,7 @@
</a>
<a
target="_blank"
:href="downloadUrl + '&inline=true'"
:href="raw"
class="button button--flat"
v-if="!req.isDir"
>
@@ -145,7 +145,7 @@
<script>
import { mapState } from "vuex";
import { files as api } from "@/api";
import { baseURL, resizePreview } from "@/utils/constants";
import { resizePreview } from "@/utils/constants";
import url from "@/utils/url";
import throttle from "lodash.throttle";
import HeaderBar from "@/components/header/HeaderBar";
@@ -186,23 +186,14 @@ export default {
return this.nextLink !== "";
},
downloadUrl() {
return `${baseURL}/api/raw${url.encodePath(this.req.path)}?auth=${
this.jwt
}`;
},
previewUrl() {
// reload the image when the file is replaced
const key = Date.parse(this.req.modified);
if (this.req.type === "image" && !this.fullSize) {
return `${baseURL}/api/preview/big${url.encodePath(
this.req.path
)}?k=${key}`;
}
return `${baseURL}/api/raw${url.encodePath(this.req.path)}?k=${key}`;
return api.getDownloadURL(this.req);
},
raw() {
return `${this.previewUrl}&inline=true`;
if (this.req.type === "image" && !this.fullSize) {
return api.getPreviewURL(this.req, "big");
}
return api.getDownloadURL(this.req, true);
},
showMore() {
return this.$store.state.show === "more";
@@ -276,9 +267,7 @@ export default {
}
if (this.req.subtitles) {
this.subtitles = this.req.subtitles.map(
(sub) => `${baseURL}/api/raw${sub}?inline=true`
);
this.subtitles = api.getSubtitlesURL(this.req);
}
let dirs = this.$route.fullPath.split("/");
@@ -320,15 +309,14 @@ export default {
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 {
prefetchUrl(item) {
if (item.type !== "image") {
return "";
}
return this.fullSize
? api.getDownloadURL(item, true)
: api.getPreviewURL(item, "big");
},
openMore() {
this.$store.commit("showHover", "more");
@@ -358,7 +346,7 @@ export default {
this.$router.push({ path: uri });
},
download() {
api.download(null, this.$route.path);
window.open(this.downloadUrl);
},
},
};