diff --git a/changelog/unreleased/change-files-pass-full-path b/changelog/unreleased/change-files-pass-full-path new file mode 100644 index 000000000..d757ab77a --- /dev/null +++ b/changelog/unreleased/change-files-pass-full-path @@ -0,0 +1,9 @@ +Change: Pass full file or directory path to methods of Files class + +Since incompatibility with spaces, we changed the way how the methods of the class +Files(filesManagement.js) need to be called. +Now it is mandatory to pass the full webDav(v2) path of a file or directory. + +For example, before this change the path was: 'myfile.txt', with this change it is: 'files/admin/myfile.txt' + +https://github.com/owncloud/owncloud-sdk/pull/971 diff --git a/changelog/unreleased/change-remove-webdav-v1-support b/changelog/unreleased/change-remove-webdav-v1-support new file mode 100644 index 000000000..0383fe74b --- /dev/null +++ b/changelog/unreleased/change-remove-webdav-v1-support @@ -0,0 +1,6 @@ +Change: Remove webdav v1 api support + +The DAV api now uses dav v2 by default, webdav v1 has been entirely removed. + +https://github.com/owncloud/owncloud-sdk/pull/962 +https://github.com/owncloud/owncloud-sdk/issues/958 diff --git a/package.json b/package.json index ca158a69d..821586367 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "owncloud-sdk", - "version": "2.0.0-alpha", + "version": "2.0.0-alpha.1", "description": "ownCloud client library for JavaScript", "keywords": [ "owncloud", diff --git a/src/fileManagement.js b/src/fileManagement.js index b2f190d4e..9d075bd64 100644 --- a/src/fileManagement.js +++ b/src/fileManagement.js @@ -49,7 +49,6 @@ class Files { return Promise.reject(new Error('Username or password was incorrect')) } - path = this._sanitizePath(path) const headers = this.helpers.buildHeaders() return this.davClient.propFind(this.helpers._buildFullDAVPath(path), properties, depth, headers).then(result => { if (result.status !== 207) { @@ -78,8 +77,6 @@ class Files { return Promise.reject(new Error('Username or password was incorrect')) } - path = this._sanitizePath(path) - return this.helpers._get(this.helpers._buildFullDAVURL(path), options).then(data => { const response = data.response const body = data.body @@ -108,7 +105,7 @@ class Files { * @returns {string} Url of the remote file */ getFileUrl (path) { - return this.helpers._buildFullDAVURL(this._sanitizePath(path)) + return this.helpers._buildFullDAVURL(path) } /** @@ -154,7 +151,6 @@ class Files { return Promise.reject(new Error('Username or password was incorrect')) } - path = this._sanitizePath(path) options = options || [] const headers = Object.assign({}, this.helpers.buildHeaders(), options.headers) const previousEntityTag = options.previousEntityTag || false @@ -199,7 +195,6 @@ class Files { return Promise.reject(new Error('Username or password was incorrect')) } - path = this._sanitizePath(path) if (path[path.length - 1] !== '/') { path += '/' } @@ -227,8 +222,6 @@ class Files { return Promise.reject(new Error('Username or password was incorrect')) } - path = this._sanitizePath(path) - return this.davClient.request('DELETE', this.helpers._buildFullDAVPath(path), this.helpers.buildHeaders()).then(result => { if ([200, 201, 204, 207].indexOf(result.status) > -1) { return Promise.resolve(true) @@ -267,9 +260,6 @@ class Files { return Promise.reject(new Error('Username or password was incorrect')) } - source = this._sanitizePath(source) - target = this._sanitizePath(target) - const headers = this.helpers.buildHeaders() headers.Destination = this.helpers._buildFullDAVURL(target) return this.davClient.request('MOVE', this.helpers._buildFullDAVPath(source), headers).then(result => { @@ -296,9 +286,6 @@ class Files { return Promise.reject(new Error('Username or password was incorrect')) } - source = this._sanitizePath(source) - target = this._sanitizePath(target) - const headers = this.helpers.buildHeaders() headers.Destination = this.helpers._buildFullDAVURL(target) return this.davClient.request('COPY', this.helpers._buildFullDAVPath(source), headers).then(result => { @@ -325,8 +312,6 @@ class Files { return Promise.reject(new Error('Username or password was incorrect')) } - path = this._sanitizePath(path) - return this.davClient.propPatch(this.helpers._buildFullDAVPath(path), { '{http://owncloud.org/ns}favorite': value ? 'true' : 'false' }, this.helpers.buildHeaders()).then(result => { @@ -469,17 +454,5 @@ class Files { }) }) } - - _sanitizePath (path) { - path = path || '' - - if (path.startsWith('spaces/')) { - return path - } - - // Remove leading slash if present - path = path.startsWith('/') ? path.substr(1) : path - return '/files/' + this.helpers.getCurrentUser().id + '/' + path - } } module.exports = Files diff --git a/tests/fileTrashTest.js b/tests/fileTrashTest.js index ca1a0ce51..80531e104 100644 --- a/tests/fileTrashTest.js +++ b/tests/fileTrashTest.js @@ -188,7 +188,7 @@ describe('oc.fileTrash', function () { if (!trashEnabled) { pending() } - return oc.fileTrash.list('/').then(trashItems => { + return oc.fileTrash.list('').then(trashItems => { expect(trashItems.length).toEqual(1) expect(trashItems[0].getName()).toEqual(testUser) }) @@ -319,7 +319,7 @@ describe('oc.fileTrash', function () { return provider.executeTest(async () => { const oc = createOwncloud(testUser, testUserPassword) await oc.login() - return oc.fileTrash.list('/').then(trashItems => { + return oc.fileTrash.list('').then(trashItems => { expect(trashItems.length).toEqual(2) expect(trashItems[1].getProperty('{http://owncloud.org/ns}trashbin-original-filename')).toEqual(testFolder) }) @@ -336,7 +336,7 @@ describe('oc.fileTrash', function () { return provider.executeTest(async () => { const oc = createOwncloud(testUser, testUserPassword) await oc.login() - return oc.fileTrash.list('/').then(trashItems => { + return oc.fileTrash.list('').then(trashItems => { expect(trashItems.length).toEqual(2) expect(trashItems[1].getProperty('{http://owncloud.org/ns}trashbin-original-filename')).toEqual(testFolder) expect(trashItems[1].getProperty('{http://owncloud.org/ns}trashbin-original-location')).toEqual(testFolder) @@ -467,10 +467,10 @@ describe('oc.fileTrash', function () { const oc = createOwncloud(testUser, testUserPassword) await oc.login() return oc.fileTrash.restore(deletedFolderId, originalLocation).then(() => { - return oc.fileTrash.list('/').then(trashItems => { + return oc.fileTrash.list('').then(trashItems => { expect(trashItems.length).toEqual(1) expect(trashItems[0].getName()).toEqual(testUser) - return oc.files.fileInfo(testFolder).then(fileInfo => { + return oc.files.fileInfo(`files/${testUser}/${testFolder}`).then(fileInfo => { expect(fileInfo.getName()).toEqual(testFolder) }) }).catch(error => { @@ -600,10 +600,10 @@ describe('oc.fileTrash', function () { const oc = createOwncloud(testUser, testUserPassword) await oc.login() return oc.fileTrash.restore(deletedFolderId, originalLocation).then(() => { - return oc.fileTrash.list('/').then(trashItems => { + return oc.fileTrash.list('').then(trashItems => { expect(trashItems.length).toEqual(1) expect(trashItems[0].getName()).toEqual(testUser) - return oc.files.fileInfo(originalLocation).then(fileInfo => { + return oc.files.fileInfo(`files/${testUser}/${originalLocation}`).then(fileInfo => { expect(fileInfo.getName()).toEqual(originalLocation) }) }).catch(error => { @@ -710,7 +710,7 @@ describe('oc.fileTrash', function () { if (!trashEnabled) { pending() } - return oc.fileTrash.list('/').then(trashItems => { + return oc.fileTrash.list('').then(trashItems => { expect(trashItems.length).toEqual(2) expect(trashItems[1].getProperty('{http://owncloud.org/ns}trashbin-original-filename')).toEqual(testFile) expect(trashItems[1].getProperty('{http://owncloud.org/ns}trashbin-original-location')).toEqual(`${testFolder}/${testFile}`) @@ -829,10 +829,10 @@ describe('oc.fileTrash', function () { const oc = createOwncloud(testUser, testUserPassword) await oc.login() return oc.fileTrash.restore(deletedFolderId, originalLocation).then(() => { - return oc.fileTrash.list('/').then(trashItems => { + return oc.fileTrash.list('').then(trashItems => { expect(trashItems.length).toEqual(1) expect(trashItems[0].getName()).toEqual(testUser) - return oc.files.fileInfo(testFolder).then(fileInfo => { + return oc.files.fileInfo(`files/${testUser}/${testFolder}`).then(fileInfo => { expect(fileInfo.getName()).toEqual(testFolder) }) }).catch(error => { @@ -961,10 +961,10 @@ describe('oc.fileTrash', function () { const oc = createOwncloud(testUser, testUserPassword) await oc.login() return oc.fileTrash.restore(deletedFolderId, originalLocation).then(() => { - return oc.fileTrash.list('/').then(trashItems => { + return oc.fileTrash.list('').then(trashItems => { expect(trashItems.length).toEqual(1) expect(trashItems[0].getName()).toEqual(testUser) - return oc.files.fileInfo(originalLocation).then(fileInfo => { + return oc.files.fileInfo(`files/${testUser}/${originalLocation}`).then(fileInfo => { expect(fileInfo.getName()).toEqual(originalLocation) }) }).catch(error => { diff --git a/tests/filesTest.js b/tests/filesTest.js index a8055c15f..34af80ef7 100644 --- a/tests/filesTest.js +++ b/tests/filesTest.js @@ -231,7 +231,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.createFolder(testFolder).then(status => { + return oc.files.createFolder(`files/${config.testUser}/${testFolder}`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error).toBe(null) @@ -250,7 +250,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.createFolder(testSubDir).then(status => { + return oc.files.createFolder(`files/${config.testUser}/${testSubDir}`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error).toBe(null) @@ -276,7 +276,7 @@ describe('Main: Currently testing files management,', function () { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() const promises = testSubFiles.map(file => { - return oc.files.putFileContents(file, testContent).then(status => { + return oc.files.putFileContents(`files/${config.testUser}/${file}`, testContent).then(status => { expect(typeof status).toBe('object') expect(typeof status.ETag).toBe('string') expect(typeof status['OC-FileId']).toBe('string') @@ -301,7 +301,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.delete(testFolder).then(status => { + return oc.files.delete(`files/${config.testUser}/${testFolder}`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error).toBe(null) @@ -326,7 +326,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.list(testFolder).then(files => { + return oc.files.list(`files/${config.testUser}/${testFolder}`).then(files => { expect(typeof (files)).toBe('object') expect(files.length).toEqual(6) expect(files[1].getName()).toEqual('abc.txt') @@ -357,7 +357,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.list(testFolder, 'infinity') + return oc.files.list(`files/${config.testUser}/${testFolder}`, 'infinity') .then(files => { expect(typeof (files)).toBe('object') expect(files.length).toEqual(7) @@ -388,7 +388,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.list(testFolder, 2).then(files => { + return oc.files.list(`files/${config.testUser}/${testFolder}`, 2).then(files => { expect(typeof (files)).toBe('object') expect(files.length).toEqual(7) expect(files[3].getName()).toEqual('subdir') @@ -417,7 +417,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.list(nonExistentFile).then(files => { + return oc.files.list(`files/${config.testUser}/${nonExistentFile}`).then(files => { expect(files).toBe(null) }).catch(error => { expect(error.message).toBe('File with name ' + nonExistentFile + ' could not be located') @@ -437,7 +437,7 @@ describe('Main: Currently testing files management,', function () { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() for (let i = 0; i < testSubFiles.length; i++) { - await oc.files.getFileContents(testSubFiles[i], { resolveWithResponseObject: true }).then((resp) => { + await oc.files.getFileContents(`files/${config.testUser}/${testSubFiles[i]}`, { resolveWithResponseObject: true }).then((resp) => { expect(resp.body).toEqual(testContent) expect(resp.headers.ETag).toBeDefined() }).catch(error => { @@ -460,7 +460,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.getFileContents(nonExistentFile).then(content => { + return oc.files.getFileContents(`files/${config.testUser}/${nonExistentFile}`).then(content => { expect(content).toBe(null) }).catch(error => { expect(error.message).toBe('File with name ' + nonExistentFile + ' could not be located') @@ -488,7 +488,7 @@ describe('Main: Currently testing files management,', function () { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() try { - const status = await oc.files.putFileContents(newFile, testContent, options) + const status = await oc.files.putFileContents(`files/${config.testUser}/${newFile}`, testContent, options) expect(typeof status).toBe('object') // Progress callback is not called for nodejs env @@ -512,7 +512,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.putFileContents(nonExistentDir + '/' + 'file.txt', testContent).then(status => { + return oc.files.putFileContents(`files/${config.testUser}/${nonExistentDir}/file.txt`, testContent).then(status => { fail('The request to update non existent file was expected to fail but it passed with status ' + status) }).catch(error => { expect(error.message).toBe('Files cannot be created in non-existent collections') @@ -530,7 +530,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - const url = oc.files.getFileUrl('/foo/bar') + const url = oc.files.getFileUrl(`files/${config.testUser}/foo/bar`) expect(url).toBe(mockServerBaseUrl + 'remote.php/dav/files/' + config.testUser + '/foo/bar') }) }) @@ -546,7 +546,7 @@ describe('Main: Currently testing files management,', function () { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.createFolder(newFolder).then(status => { + return oc.files.createFolder(`files/${config.testUser}/${newFolder}`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error).toBe(null) @@ -578,7 +578,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.createFolder(testFolder + '/' + nonExistentDir + '/newFolder/').then(status => { + return oc.files.createFolder(`files/${config.testUser}/${testFolder}/${nonExistentDir}/newFolder/`).then(status => { expect(status).toBe(null) }).catch(error => { expect(error.message).toBe('Parent node does not exist') @@ -602,7 +602,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.delete(newFolder) + return oc.files.delete(`files/${config.testUser}/${newFolder}`) .then(status2 => { expect(status2).toEqual(true) }).catch(error => { @@ -628,7 +628,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.delete(nonExistentDir).then(status => { + return oc.files.delete(`files/${config.testUser}/${nonExistentDir}`).then(status => { expect(status).toBe(null) }).catch(error => { expect(error.message).toBe('File with name ' + nonExistentDir + ' could not be located') @@ -676,7 +676,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.move(testFolder + '/中文.txt', testFolder + '/中文.txt').then(status => { + return oc.files.move(`files/${config.testUser}/${testFolder}/中文.txt`, `files/${config.testUser}/${testFolder}/中文.txt`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error.message).toBe('Source and destination uri are identical.') @@ -730,7 +730,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.move(testFolder + '/中文.txt', testFolder + '/中文123.txt').then(status => { + return oc.files.move(`files/${config.testUser}/${testFolder}/中文.txt`, `files/${config.testUser}/${testFolder}/中文123.txt`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error).toBe(null) @@ -771,7 +771,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.move(nonExistentFile, '/abcd.txt').then(status => { + return oc.files.move(`files/${config.testUser}/${nonExistentFile}`, '/abcd.txt').then(status => { expect(status).toBe(null) }).catch(error => { expect(error.message).toBe('File with name ' + nonExistentFile + ' could not be located') @@ -814,7 +814,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.copy(file, file).then(status => { + return oc.files.copy(`files/${config.testUser}/${file}`, `files/${config.testUser}/${file}`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error.message).toBe('Source and destination uri are identical.') @@ -854,7 +854,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.copy(nonExistentFile, '/abcd.txt').then(status => { + return oc.files.copy(`files/${config.testUser}/${nonExistentFile}`, `files/${config.testUser}/abcd.txt`).then(status => { expect(status).toBe(null) }).catch(error => { expect(error.message).toBe('File with name ' + nonExistentFile + ' could not be located') @@ -984,7 +984,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.fileInfo(file, ['{http://owncloud.org/ns}fileid']) + return oc.files.fileInfo(`files/${config.testUser}/${file}`, ['{http://owncloud.org/ns}fileid']) .then(fileInfo => { const fileId = fileInfo.getFileId() expect(fileId).toEqual('123456789') @@ -1091,7 +1091,7 @@ describe('Main: Currently testing files management,', function () { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - const promise = oc.files.list('') + const promise = oc.files.list(`files/${config.testUser}/`) await promise.then(entries => { const tusSupport = entries[0].getTusSupport() expect(tusSupport.resumable).toEqual('1.0.0') @@ -1118,7 +1118,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - const promise = oc.files.fileInfo(dir) + const promise = oc.files.fileInfo(`files/${config.testUser}/${dir}`) return promise.then(entry => { const tusSupport = entry.getTusSupport() expect(tusSupport.resumable).toEqual('1.0.0') @@ -1141,7 +1141,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - const promise = oc.files.list('') + const promise = oc.files.list(`files/${config.testUser}/`) return promise.then(entries => { expect(entries[0].getTusSupport()).toEqual(null) expect(entries[1].getTusSupport()).toEqual(null) @@ -1190,7 +1190,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.move(srcFilePath, desFilePath).then(status => { + return oc.files.move(`files/${config.testUser}/${srcFilePath}`, `files/${config.testUser}/${desFilePath}`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error).toBe(null) @@ -1241,7 +1241,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.copy(srcFilePath, desFilePath).then(status => { + return oc.files.copy(`files/${config.testUser}/${srcFilePath}`, `files/${config.testUser}/${desFilePath}`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error).toBe(null) @@ -1296,7 +1296,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.copy(srcFilePath, desFilePath).then(status => { + return oc.files.copy(`files/${config.testUser}/${srcFilePath}`, `files/${config.testUser}/${desFilePath}`).then(status => { expect(status).toBe(true) }).catch(error => { expect(error).toBe(null) @@ -1320,7 +1320,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.favorite(file, false) + return oc.files.favorite(`files/${config.testUser}/${file}`, false) .then(status => { expect(status).toEqual(true) }).catch(error => { @@ -1349,7 +1349,7 @@ describe('Main: Currently testing files management,', function () { return provider.executeTest(async () => { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - return oc.files.favorite(file) + return oc.files.favorite(`files/${config.testUser}/${file}`) .then(status => { expect(status).toEqual(true) }).catch(error => { diff --git a/tests/signedUrlIntegrationTest.js b/tests/signedUrlIntegrationTest.js index 982ab5c87..84059f696 100644 --- a/tests/signedUrlIntegrationTest.js +++ b/tests/signedUrlIntegrationTest.js @@ -97,7 +97,7 @@ describe('Signed urls', function () { const oc = createOwncloud(config.testUser, config.testUserPassword) await oc.login() - const url = oc.files.getFileUrl(config.testFolder + '/' + config.testFile) + const url = oc.files.getFileUrl(`files/${config.testUser}/${config.testFolder}/${config.testFile}`) const signedUrl = await oc.signUrl(url) const response = await fetch(signedUrl) expect(response.ok).toEqual(true)