Skip to content

Commit

Permalink
Merge pull request #2414 from nextcloud/fix/regressions
Browse files Browse the repository at this point in the history
fix: Make sure correct DAV path is used (and use DAV v2 on public shares
  • Loading branch information
susnux authored Aug 12, 2024
2 parents 7417482 + ad56ecb commit bd99947
Show file tree
Hide file tree
Showing 8 changed files with 9,356 additions and 33 deletions.
9,334 changes: 9,334 additions & 0 deletions css/main-DbamWgYd.chunk.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion css/viewer-main.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* extracted by css-entry-points-plugin */
@import './main-DduclpYy.chunk.css';
@import './main-DbamWgYd.chunk.css';
24 changes: 9 additions & 15 deletions js/viewer-main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22686,9 +22686,6 @@ function encodePath(path) {
function basename2(path) {
return path.replace(/\\/g, "/").replace(/.*\//, "");
}
function dirname2(path) {
return path.replace(/\\/g, "/").replace(/\/[^\/]*$/, "");
}
function _defineProperty$4(obj, key, value3) {
if (key in obj) {
Object.defineProperty(obj, key, { value: value3, enumerable: true, configurable: true, writable: true });
Expand Down Expand Up @@ -26979,19 +26976,13 @@ const genFileInfo = function(obj) {
});
return fileInfo;
};
function getDavPath({ filename, basename: basename3, source = "" }) {
if (isPublicShare()) {
return _$2(
`/s/${getSharingToken()}/download?path={dirname}&files={basename}`,
{ dirname: dirname2(filename), basename: basename3 }
);
}
function getDavPath({ filename, source = "" }) {
const prefixUser = davRootPath;
if (source && !source.includes(prefixUser)) {
return null;
}
if (filename.startsWith(prefixUser)) {
filename = filename.slice(prefixUser.length);
if (!filename.startsWith(prefixUser)) {
filename = `${davRootPath}${filename}`;
}
return davRemoteURL + encodePath(filename);
}
Expand Down Expand Up @@ -27265,7 +27256,7 @@ const statData = `<?xml version="1.0"?>
</d:prop>
</d:propfind>`;
async function getFileInfo(path, options2 = {}) {
const response = await client.stat(`${davRootPath}${path}`, Object.assign({
const response = await client.stat(path, Object.assign({
data: statData,
details: true
}, options2));
Expand Down Expand Up @@ -27302,7 +27293,7 @@ async function rawStat(origin2, path, options2 = {}) {
*
*/
async function getFileList(path, options2 = {}) {
const response = await client.getDirectoryContents(`${davRootPath}${path}`, Object.assign({
const response = await client.getDirectoryContents(path, Object.assign({
data: `<?xml version="1.0"?>
<d:propfind ${getDavNameSpaces()}>
<d:prop>
Expand Down Expand Up @@ -28233,6 +28224,9 @@ const _sfc_main$D = {
* @param {string|null} overrideHandlerId the ID of the handler with which to view the files, if any
*/
async openFile(path, overrideHandlerId = null) {
if (!path.startsWith(davRootPath)) {
path = `${davRootPath}${path}`;
}
await this.beforeOpen();
this.cancelRequestFile();
if (this.isSameFile(null, path)) {
Expand Down Expand Up @@ -28722,7 +28716,7 @@ var __component__$D = /* @__PURE__ */ normalizeComponent$1(
_sfc_staticRenderFns$D,
false,
null,
"e16cf4dc"
"9bc9aec6"
);
const ViewerComponent = __component__$D.exports;
function setAsyncState(vm, stateObject, state) {
Expand Down
2 changes: 1 addition & 1 deletion js/viewer-main.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/services/FileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { FileStat, ResponseDataDetailed } from 'webdav'

import { client } from './WebdavClient'
import { genFileInfo, type FileInfo } from '../utils/fileUtils'
import { davGetClient, davRootPath, getDavNameSpaces, getDavProperties } from '@nextcloud/files'
import { davGetClient, getDavNameSpaces, getDavProperties } from '@nextcloud/files'

const statData = `<?xml version="1.0"?>
<d:propfind ${getDavNameSpaces()}>
Expand All @@ -40,7 +40,7 @@ const statData = `<?xml version="1.0"?>
* @param options
*/
export default async function(path: string, options = {}): Promise<FileInfo> {
const response = await client.stat(`${davRootPath}${path}`, Object.assign({
const response = await client.stat(path, Object.assign({
data: statData,
details: true,
}, options)) as ResponseDataDetailed<FileStat>
Expand Down
4 changes: 2 additions & 2 deletions src/services/FileList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/

import { davRootPath, getDavNameSpaces, getDavProperties } from '@nextcloud/files'
import { getDavNameSpaces, getDavProperties } from '@nextcloud/files'
import { client } from './WebdavClient'
import { genFileInfo, type FileInfo } from '../utils/fileUtils'
import type { FileStat, ResponseDataDetailed } from 'webdav'
Expand All @@ -31,7 +31,7 @@ import type { FileStat, ResponseDataDetailed } from 'webdav'
* @param options
*/
export default async function(path: string, options = {}): Promise<FileInfo[]> {
const response = await client.getDirectoryContents(`${davRootPath}${path}`, Object.assign({
const response = await client.getDirectoryContents(path, Object.assign({
data: `<?xml version="1.0"?>
<d:propfind ${getDavNameSpaces()}>
<d:prop>
Expand Down
16 changes: 4 additions & 12 deletions src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
*
*/
import type { FileStat } from 'webdav'
import { dirname, encodePath } from '@nextcloud/paths'
import { generateUrl } from '@nextcloud/router'
import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'
import { encodePath } from '@nextcloud/paths'
import camelcase from 'camelcase'

import { isNumber } from './numberUtil'
Expand Down Expand Up @@ -120,17 +118,11 @@ const genFileInfo = function(obj: FileStat): FileInfo {
*
* @param fileInfo The fileInfo
* @param fileInfo.filename the file full path
* @param fileInfo.basename the file name
* @param fileInfo.source the file source if any
*/
function getDavPath({ filename, basename, source = '' }: { filename: string, basename: string, source?: string }): string|null {
function getDavPath({ filename, source = '' }: { filename: string, source?: string }): string|null {
// TODO: allow proper dav access without the need of basic auth
// https://github.com/nextcloud/server/issues/19700
if (isPublicShare()) {
return generateUrl(`/s/${getSharingToken()}/download?path={dirname}&files={basename}`,
{ dirname: dirname(filename), basename })
}

const prefixUser = davRootPath

// If we have a source but we're not a dav resource, return null
Expand All @@ -139,8 +131,8 @@ function getDavPath({ filename, basename, source = '' }: { filename: string, bas
}

// Workaround for files with different root like /remote.php/dav
if (filename.startsWith(prefixUser)) {
filename = filename.slice(prefixUser.length)
if (!filename.startsWith(prefixUser)) {
filename = `${davRootPath}${filename}`
}
return davRemoteURL + encodePath(filename)
}
Expand Down
3 changes: 3 additions & 0 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ export default {
* @param {string|null} overrideHandlerId the ID of the handler with which to view the files, if any
*/
async openFile(path, overrideHandlerId = null) {
if (!path.startsWith(davRootPath)) {
path = `${davRootPath}${path}`
}
await this.beforeOpen()
// cancel any previous request
Expand Down

0 comments on commit bd99947

Please sign in to comment.