refactor: move preview url to utils

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/563/head
Varun Patil 2023-04-12 22:05:24 -07:00
parent 3a629bf7aa
commit d2273cc76e
10 changed files with 30 additions and 39 deletions

View File

@ -37,7 +37,7 @@ import { getCurrentUser } from "@nextcloud/auth";
import NcCounterBubble from "@nextcloud/vue/dist/Components/NcCounterBubble"; import NcCounterBubble from "@nextcloud/vue/dist/Components/NcCounterBubble";
import { IAlbum, ICluster, IFace } from "../../types"; import { IAlbum, ICluster, IFace } from "../../types";
import { getPreviewUrl } from "../../services/FileUtils"; import { getPreviewUrl } from "../../services/utils/helpers";
import errorsvg from "../../assets/error.svg"; import errorsvg from "../../assets/error.svg";
import { API } from "../../services/API"; import { API } from "../../services/API";

View File

@ -32,7 +32,7 @@
import { defineComponent, PropType } from "vue"; import { defineComponent, PropType } from "vue";
import { IFolder, IPhoto } from "../../types"; import { IFolder, IPhoto } from "../../types";
import { getPreviewUrl } from "../../services/FileUtils"; import { getPreviewUrl } from "../../services/utils/helpers";
import UserConfig from "../../mixins/UserConfig"; import UserConfig from "../../mixins/UserConfig";
import FolderIcon from "vue-material-design-icons/Folder.vue"; import FolderIcon from "vue-material-design-icons/Folder.vue";

View File

@ -68,7 +68,6 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType } from "vue"; import { defineComponent, PropType } from "vue";
import { getPreviewUrl } from "../../services/FileUtils";
import { IDay, IPhoto } from "../../types"; import { IDay, IPhoto } from "../../types";
import * as utils from "../../services/Utils"; import * as utils from "../../services/Utils";
@ -191,7 +190,7 @@ export default defineComponent({
) - 1; ) - 1;
} }
return getPreviewUrl(this.data, false, size); return utils.getPreviewUrl(this.data, false, size);
}, },
/** Set src with overlay face rect */ /** Set src with overlay face rect */

View File

@ -69,7 +69,7 @@ import NcButton from "@nextcloud/vue/dist/Components/NcButton";
import NcLoadingIcon from "@nextcloud/vue/dist/Components/NcLoadingIcon"; import NcLoadingIcon from "@nextcloud/vue/dist/Components/NcLoadingIcon";
const NcListItem = () => import("@nextcloud/vue/dist/Components/NcListItem"); const NcListItem = () => import("@nextcloud/vue/dist/Components/NcListItem");
import { getPreviewUrl } from "../../services/FileUtils"; import { getPreviewUrl } from "../../services/utils/helpers";
import { IAlbum, IPhoto } from "../../types"; import { IAlbum, IPhoto } from "../../types";
import axios from "@nextcloud/axios"; import axios from "@nextcloud/axios";
import { API } from "../../services/API"; import { API } from "../../services/API";

View File

@ -84,9 +84,9 @@ import NcLoadingIcon from "@nextcloud/vue/dist/Components/NcLoadingIcon";
import Modal from "./Modal.vue"; import Modal from "./Modal.vue";
import { IPhoto } from "../../types"; import { IPhoto } from "../../types";
import { getPreviewUrl } from "../../services/FileUtils";
import { API } from "../../services/API"; import { API } from "../../services/API";
import * as dav from "../../services/DavRequests"; import * as dav from "../../services/DavRequests";
import * as utils from "../../services/Utils";
import PhotoIcon from "vue-material-design-icons/Image.vue"; import PhotoIcon from "vue-material-design-icons/Image.vue";
import LargePhotoIcon from "vue-material-design-icons/ImageArea.vue"; import LargePhotoIcon from "vue-material-design-icons/ImageArea.vue";
@ -160,7 +160,7 @@ export default defineComponent({
}, },
async sharePreview() { async sharePreview() {
const src = getPreviewUrl(this.photo, false, 2048); const src = utils.getPreviewUrl(this.photo, false, 2048);
this.shareWithHref(src, true); this.shareWithHref(src, true);
}, },

View File

@ -52,7 +52,6 @@ import axios from "@nextcloud/axios";
import { subscribe, unsubscribe } from "@nextcloud/event-bus"; import { subscribe, unsubscribe } from "@nextcloud/event-bus";
import { API } from "../../services/API"; import { API } from "../../services/API";
import { getPreviewUrl } from "../../services/FileUtils";
import * as utils from "../../services/Utils"; import * as utils from "../../services/Utils";
import "leaflet/dist/leaflet.css"; import "leaflet/dist/leaflet.css";
@ -292,7 +291,7 @@ export default defineComponent({
}, },
clusterPreviewUrl(cluster: IMarkerCluster) { clusterPreviewUrl(cluster: IMarkerCluster) {
return getPreviewUrl(cluster.preview, false, 256); return utils.getPreviewUrl(cluster.preview, false, 256);
}, },
clusterIconClass(cluster: IMarkerCluster) { clusterIconClass(cluster: IMarkerCluster) {

View File

@ -49,7 +49,6 @@ import NcActionButton from "@nextcloud/vue/dist/Components/NcActionButton";
import * as utils from "../../services/Utils"; import * as utils from "../../services/Utils";
import * as dav from "../../services/DavRequests"; import * as dav from "../../services/DavRequests";
import { IPhoto } from "../../types"; import { IPhoto } from "../../types";
import { getPreviewUrl } from "../../services/FileUtils";
import LeftMoveIcon from "vue-material-design-icons/ChevronLeft.vue"; import LeftMoveIcon from "vue-material-design-icons/ChevronLeft.vue";
import RightMoveIcon from "vue-material-design-icons/ChevronRight.vue"; import RightMoveIcon from "vue-material-design-icons/ChevronRight.vue";
@ -79,7 +78,6 @@ export default defineComponent({
}, },
data: () => ({ data: () => ({
getPreviewUrl,
years: [] as IYear[], years: [] as IYear[],
hasRight: false, hasRight: false,
hasLeft: false, hasLeft: false,
@ -175,7 +173,7 @@ export default defineComponent({
// Get random photo // Get random photo
year.preview ||= utils.randomChoice(year.photos); year.preview ||= utils.randomChoice(year.photos);
year.url = getPreviewUrl(year.preview, false, 512); year.url = utils.getPreviewUrl(year.preview, false, 512);
} }
await this.$nextTick(); await this.$nextTick();

View File

@ -188,7 +188,6 @@ import axios from "@nextcloud/axios";
import { subscribe, unsubscribe } from "@nextcloud/event-bus"; import { subscribe, unsubscribe } from "@nextcloud/event-bus";
import { getRootUrl } from "@nextcloud/router"; import { getRootUrl } from "@nextcloud/router";
import { getPreviewUrl } from "../../services/FileUtils";
import { getDownloadLink } from "../../services/DavRequests"; import { getDownloadLink } from "../../services/DavRequests";
import { API } from "../../services/API"; import { API } from "../../services/API";
import * as dav from "../../services/DavRequests"; import * as dav from "../../services/DavRequests";
@ -714,7 +713,7 @@ export default defineComponent({
// Get thumb image // Get thumb image
const thumbSrc: string = const thumbSrc: string =
this.thumbElem(photo)?.getAttribute("src") || this.thumbElem(photo)?.getAttribute("src") ||
getPreviewUrl(photo, false, 256); utils.getPreviewUrl(photo, false, 256);
// Get full image // Get full image
return { return {
@ -772,7 +771,9 @@ export default defineComponent({
this.photoswipe.addFilter("itemData", (itemData, index) => ({ this.photoswipe.addFilter("itemData", (itemData, index) => ({
...this.getItemData(this.list[index]), ...this.getItemData(this.list[index]),
msrc: thumbSize ? getPreviewUrl(photo, false, thumbSize) : undefined, msrc: thumbSize
? utils.getPreviewUrl(photo, false, thumbSize)
: undefined,
})); }));
this.isOpen = true; this.isOpen = true;
@ -783,7 +784,7 @@ export default defineComponent({
getItemData(photo: IPhoto) { getItemData(photo: IPhoto) {
const sw = Math.floor(screen.width * devicePixelRatio); const sw = Math.floor(screen.width * devicePixelRatio);
const sh = Math.floor(screen.height * devicePixelRatio); const sh = Math.floor(screen.height * devicePixelRatio);
let previewUrl = getPreviewUrl(photo, false, [sw, sh]); let previewUrl = utils.getPreviewUrl(photo, false, [sw, sh]);
const isvideo = photo.flag & this.c.FLAG_IS_VIDEO; const isvideo = photo.flag & this.c.FLAG_IS_VIDEO;

View File

@ -134,26 +134,4 @@ const genFileInfo = function (obj) {
return fileInfo; return fileInfo;
}; };
/** Get preview URL from photo object */ export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo };
const getPreviewUrl = function (
photo: IPhoto,
square: boolean,
size: number | [number, number]
) {
const [x, y] = typeof size === "number" ? [size, size] : size;
return API.Q(API.IMAGE_PREVIEW(photo.fileid), {
c: photo.etag,
x,
y,
a: square ? "0" : "1",
});
};
export {
encodeFilePath,
extractFilePaths,
sortCompare,
genFileInfo,
getPreviewUrl,
};

View File

@ -1,6 +1,22 @@
import { IPhoto } from "../../types"; import { IPhoto } from "../../types";
import { API } from "../API"; import { API } from "../API";
/** Get preview URL from photo object */
export function getPreviewUrl(
photo: IPhoto,
square: boolean,
size: number | [number, number]
) {
const [x, y] = typeof size === "number" ? [size, size] : size;
return API.Q(API.IMAGE_PREVIEW(photo.fileid), {
c: photo.etag,
x,
y,
a: square ? "0" : "1",
});
}
/** /**
* Get the path of the folder on folders route * Get the path of the folder on folders route
* This function does not check if this is the folder route * This function does not check if this is the folder route