From 3e854719eda4ed7f8af2f7391e566e454c44510f Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 6 Nov 2022 00:36:35 -0700 Subject: [PATCH] viewer: fix folder-share video --- src/components/SelectionManager.vue | 2 +- src/components/Viewer.vue | 18 ++--------- src/services/dav/download.ts | 47 ++++++++++++++++++++--------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/components/SelectionManager.vue b/src/components/SelectionManager.vue index cf6dfa99..81574279 100644 --- a/src/components/SelectionManager.vue +++ b/src/components/SelectionManager.vue @@ -348,7 +348,7 @@ export default class SelectionManager extends Mixins(GlobalMixin, UserConfig) { return; } } - await dav.downloadFilesByIds(Array.from(selection.values())); + await dav.downloadFilesByPhotos(Array.from(selection.values())); } /** diff --git a/src/components/Viewer.vue b/src/components/Viewer.vue index 1fca297e..59340681 100644 --- a/src/components/Viewer.vue +++ b/src/components/Viewer.vue @@ -76,7 +76,7 @@ import { generateUrl } from "@nextcloud/router"; import * as dav from "../services/DavRequests"; import * as utils from "../services/Utils"; import { getPreviewUrl } from "../services/FileUtils"; -import { getAlbumFileInfos } from "../services/DavRequests"; +import { getDownloadLink } from "../services/DavRequests"; import PhotoSwipe, { PhotoSwipeOptions } from "photoswipe"; import "photoswipe/style.css"; @@ -264,19 +264,7 @@ export default class Viewer extends Mixins(GlobalMixin) { content.videoElement.classList.add("video-js"); // Get DAV URL for video - let url = `remote.php/dav/${content.data.photo.filename}`; // normal route - // Check if albums - const route = vuerouter.currentRoute; - if (route.name === "albums") { - const fInfos = getAlbumFileInfos( - [content.data.photo], - route.params.user, - route.params.name - ); - if (fInfos.length) { - url = `remote.php/dav/${fInfos[0].originalFilename}`; - } - } + const url = getDownloadLink(content.data.photo); // Add child with source element const source = document.createElement("source"); @@ -525,7 +513,7 @@ export default class Viewer extends Mixins(GlobalMixin) { private async downloadCurrent() { const photo = this.getCurrentPhoto(); if (!photo) return; - dav.downloadFilesByIds([photo]); + dav.downloadFilesByPhotos([photo]); } /** Open the sidebar */ diff --git a/src/services/dav/download.ts b/src/services/dav/download.ts index 81703d93..c24eba55 100644 --- a/src/services/dav/download.ts +++ b/src/services/dav/download.ts @@ -3,6 +3,7 @@ import { generateUrl } from "@nextcloud/router"; import { showError } from "@nextcloud/dialogs"; import { translate as t } from "@nextcloud/l10n"; import { IPhoto } from "../../types"; +import { getAlbumFileInfos } from "./albums"; /** * Download a file @@ -43,27 +44,14 @@ export async function downloadFiles(fileNames: string[]): Promise { * @param photo - The photo to download */ export async function downloadPublicPhoto(photo: IPhoto) { - // Public share download - - const token = window.vuerouter.currentRoute.params.token; - // TODO: allow proper dav access without the need of basic auth - // https://github.com/nextcloud/server/issues/19700 - const downloadURL = generateUrl( - `/s/${token}/download?path={dirname}&files={basename}`, - { - dirname: photo.filename.split("/").slice(0, -1).join("/"), - basename: photo.basename, - } - ); - - window.location.href = downloadURL; + window.location.href = getDownloadLink(photo); } /** * Download the files given by the fileIds * @param photos list of photos */ -export async function downloadFilesByIds(photos: IPhoto[]) { +export async function downloadFilesByPhotos(photos: IPhoto[]) { if (photos.length === 0) { return; } @@ -87,3 +75,32 @@ export async function downloadFilesByIds(photos: IPhoto[]) { await downloadFiles(fileInfos.map((f) => f.filename)); } + +/** Get URL to download one file (e.g. for video streaming) */ +export function getDownloadLink(photo: IPhoto) { + // Check if public + if (vuerouter.currentRoute.name === "folder-share") { + const token = window.vuerouter.currentRoute.params.token; + // TODO: allow proper dav access without the need of basic auth + // https://github.com/nextcloud/server/issues/19700 + return generateUrl(`/s/${token}/download?path={dirname}&files={basename}`, { + dirname: photo.filename.split("/").slice(0, -1).join("/"), + basename: photo.basename, + }); + } + + // Check if albums + const route = vuerouter.currentRoute; + if (route.name === "albums") { + const fInfos = getAlbumFileInfos( + [photo], + route.params.user, + route.params.name + ); + if (fInfos.length) { + return `remote.php/dav/${fInfos[0].originalFilename}`; + } + } + + return `remote.php/dav/${photo.filename}`; // normal route +}