diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-10-03 18:48:35 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-10-05 23:44:20 +0200 |
commit | a27a4f757dc9372b0e22003b86a8a39f0e85f988 (patch) | |
tree | 01568e2a14cde721d3fab093a9bd1dc3b8c04492 /core/src/OC | |
parent | 5c21d11207e7f84f2e8f346995d0076e875a8052 (diff) | |
download | nextcloud-server-a27a4f757dc9372b0e22003b86a8a39f0e85f988.tar.gz nextcloud-server-a27a4f757dc9372b0e22003b86a8a39f0e85f988.zip |
Use @nextcloud/paths and deprecate OC helpers
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'core/src/OC')
-rw-r--r-- | core/src/OC/index.js | 17 | ||||
-rw-r--r-- | core/src/OC/path.js | 123 |
2 files changed, 16 insertions, 124 deletions
diff --git a/core/src/OC/index.js b/core/src/OC/index.js index 01964b3ca4a..2a43d95eade 100644 --- a/core/src/OC/index.js +++ b/core/src/OC/index.js @@ -38,7 +38,7 @@ import { encodePath, isSamePath, joinPaths -} from './path' +} from '@nextcloud/paths' import { build as buildQueryString, parse as parseQueryString @@ -189,10 +189,25 @@ export default { /* * Path helpers */ + /** + * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths + */ basename, + /** + * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths + */ encodePath, + /** + * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths + */ dirname, + /** + * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths + */ isSamePath, + /** + * @deprecated 18.0.0 use https://www.npmjs.com/package/@nextcloud/paths + */ joinPaths, /** diff --git a/core/src/OC/path.js b/core/src/OC/path.js deleted file mode 100644 index 145c90d1e5e..00000000000 --- a/core/src/OC/path.js +++ /dev/null @@ -1,123 +0,0 @@ -/** - * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @license GNU AGPL version 3 or any later version - * - * 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/>. - */ - -/** - * URI-Encodes a file path but keep the path slashes. - * - * @param {String} path path - * @returns {String} encoded path - */ -export const encodePath = path => { - if (!path) { - return path - } - const parts = path.split('/') - const result = [] - for (let i = 0; i < parts.length; i++) { - result.push(encodeURIComponent(parts[i])) - } - return result.join('/') -} - -/** - * Returns the base name of the given path. - * For example for "/abc/somefile.txt" it will return "somefile.txt" - * - * @param {String} path path - * @returns {String} base name - */ -export const basename = path => path.replace(/\\/g, '/').replace(/.*\//, '') - -/** - * Returns the dir name of the given path. - * For example for "/abc/somefile.txt" it will return "/abc" - * - * @param {String} path path - * @returns {String} dir name - */ -export const dirname = path => path.replace(/\\/g, '/').replace(/\/[^/]*$/, '') - -/** - * Returns whether the given paths are the same, without - * leading, trailing or doubled slashes and also removing - * the dot sections. - * - * @param {String} path1 first path - * @param {String} path2 second path - * @returns {bool} true if the paths are the same - * - * @since 9.0 - */ -export const isSamePath = (path1, path2) => { - const pathSections1 = (path1 || '').split('/').filter(p => p !== '.') - const pathSections2 = (path2 || '').split('/').filter(p => p !== '.') - path1 = joinPaths.apply(undefined, pathSections1) - path2 = joinPaths.apply(undefined, pathSections2) - - return path1 === path2 -} - -/** - * Join path sections - * - * @param {...String} path sections - * - * @returns {String} joined path, any leading or trailing slash - * will be kept - * - * @since 8.2 - */ -export const joinPaths = (...args) => { - if (args.length < 1) { - return '' - } - - // discard empty arguments - const nonEmptyArgs = args.filter(arg => arg.length > 0) - if (nonEmptyArgs.length < 1) { - return '' - } - - const lastArg = nonEmptyArgs[nonEmptyArgs.length - 1] - const leadingSlash = nonEmptyArgs[0].charAt(0) === '/' - const trailingSlash = lastArg.charAt(lastArg.length - 1) === '/' - const sections = nonEmptyArgs.reduce((acc, section) => acc.concat(section.split('/')), []) - - let first = !leadingSlash - const path = sections.reduce((acc, section) => { - if (section === '') { - return acc - } - - if (first) { - first = false - return acc + section - } - - return acc + '/' + section - }, '') - - if (trailingSlash) { - // add it back - return path + '/' - } - return path -} |