Skip to content
This repository was archived by the owner on Jun 5, 2024. It is now read-only.

Pass raw url like /files/admin/myFile.txt instead of myFile.txt to files sdk #971

Merged
merged 3 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog/unreleased/change-files-pass-full-path
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions changelog/unreleased/change-remove-webdav-v1-support
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 1 addition & 28 deletions src/fileManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 += '/'
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand Down Expand Up @@ -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
24 changes: 12 additions & 12 deletions tests/fileTrashTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)
})
Expand All @@ -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)
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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}`)
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down
Loading