Skip to content

Commit

Permalink
Merge pull request #43756 from nextcloud/chore/encodepath
Browse files Browse the repository at this point in the history
chore(files): replace `encodeFilePath` by `encodePath` from `@nextcloud/paths`
  • Loading branch information
susnux authored Feb 22, 2024
2 parents 0254af8 + c8868a3 commit bd10b48
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 53 deletions.
4 changes: 2 additions & 2 deletions apps/files/src/components/TemplatePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
</template>

<script>
import { encodePath } from '@nextcloud/paths'
import { generateUrl } from '@nextcloud/router'
import { encodeFilePath } from '../utils/fileUtils.ts'
import { getToken, isPublic } from '../utils/davUtils.js'
// preview width generation
Expand Down Expand Up @@ -124,7 +124,7 @@ export default {
}
// TODO: find a nicer standard way of doing this?
if (isPublic()) {
return generateUrl(`/apps/files_sharing/publicpreview/${getToken()}?fileId=${this.fileid}&file=${encodeFilePath(this.filename)}&x=${previewWidth}&y=${previewWidth}&a=1`)
return generateUrl(`/apps/files_sharing/publicpreview/${getToken()}?fileId=${this.fileid}&file=${encodePath(this.filename)}&x=${previewWidth}&y=${previewWidth}&a=1`)
}
return generateUrl(`/core/preview?fileId=${this.fileid}&x=${previewWidth}&y=${previewWidth}&a=1`)
},
Expand Down
13 changes: 1 addition & 12 deletions apps/files/src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { basename, extname } from 'path'
import { FileType, type Node } from '@nextcloud/files'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
import { basename, extname } from 'path'

// TODO: move to @nextcloud/files
/**
Expand All @@ -41,17 +41,6 @@ export const getUniqueName = (name: string, otherNames: string[], suffix = (n: n
return newName
}

export const encodeFilePath = function(path) {
const pathSections = (path.startsWith('/') ? path : `/${path}`).split('/')
let relativePath = ''
pathSections.forEach((section) => {
if (section !== '') {
relativePath += '/' + encodeURIComponent(section)
}
})
return relativePath
}

/**
* Extract dir and name from file path
*
Expand Down
10 changes: 4 additions & 6 deletions apps/files_versions/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import type { FileStat, ResponseDataDetailed } from 'webdav'

import { getCurrentUser } from '@nextcloud/auth'
import { joinPaths } from '@nextcloud/paths'
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { joinPaths, encodePath } from '@nextcloud/paths'
import moment from '@nextcloud/moment'

import { encodeFilePath } from '../../../files/src/utils/fileUtils.ts'

import client from '../utils/davClient.js'
import davRequest from '../utils/davRequest.js'
import logger from '../utils/logger.js'
import type { FileStat, ResponseDataDetailed } from 'webdav'

export interface Version {
fileId: string, // The id of the file associated to the version.
Expand Down Expand Up @@ -120,7 +118,7 @@ function formatVersion(version: any, fileInfo: any): Version {
hasPreview: version.props['has-preview'] === 1,
previewUrl,
url: joinPaths('/remote.php/dav', version.filename),
source: generateRemoteUrl('dav') + encodeFilePath(version.filename),
source: generateRemoteUrl('dav') + encodePath(version.filename),
fileVersion: version.basename,
}
}
Expand Down
6 changes: 3 additions & 3 deletions dist/3222-3222.js → dist/4070-4070.js

Large diffs are not rendered by default.

File renamed without changes.
2 changes: 1 addition & 1 deletion dist/3222-3222.js.map → dist/4070-4070.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_versions-files_versions.js

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions dist/files_versions-files_versions.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,6 @@
*
*/

/**
* @copyright Copyright (c) 2021 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @copyright Copyright (c) 2022 John Molakvoæ <[email protected]>
*
Expand Down
2 changes: 1 addition & 1 deletion dist/files_versions-files_versions.js.map

Large diffs are not rendered by default.

0 comments on commit bd10b48

Please sign in to comment.