viewer: fix folder-share video

pull/175/head
Varun Patil 2022-11-06 00:36:35 -07:00
parent 4d9c301f26
commit 3e854719ed
3 changed files with 36 additions and 31 deletions

View File

@ -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()));
}
/**

View File

@ -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 */

View File

@ -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<boolean> {
* @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
}