getCurrentUserAsync () { const user = this.getCurrentUser() if (user !== null) { return Promise.resolve(user) } return this._updateCurrentUser() }
Promise.resolve(document.save()) .then( () => { return Promise.reject(new Error(field +' unique validation failed')); }).catch((err) => { should.exist(err); })
/** * Gets all capabilities of the logged in user * @returns {object} all capabilities */ getCapabilities () { return this._makeOCSrequest('GET', this.OCS_SERVICE_CLOUD, 'capabilities?format=json') .then(data => { const body = data.data.ocs.data this._versionNumber = body.version.major + '.' + body.version.minor + '.' + body.version.micro return Promise.resolve(body) }) }
/** * Deletes an application attribute * @param {string} app application ID (generally app-name) * @param {string} key attribute key to delete for the given application * @returns {Promise.<status>} boolean: true if successful * @returns {Promise.<error>} string: error message, if any. */ deleteAttribute (app, key) { const path = 'deleteattribute/' + encodeURIComponent(app) + '/' + encodeURIComponent(this.helpers._encodeString(key)) return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_PRIVATEDATA, path) .then(() => { return Promise.resolve(true) }) }
/** * Logs in to the specified ownCloud instance (Updates capabilities) * @returns {Promise.<status>} boolean: whether login was successful or not * @returns {Promise.<error>} string: error message, if any. */ login () { const self = this return this.helpers.getCapabilities() .then(() => { return Promise.resolve(self.getCurrentUser()) }) }
getSignKey () { if (this._signingKey !== null) { return Promise.resolve(this._signingKey) } const self = this return self._makeOCSrequest('GET', self.OCS_SERVICE_CLOUD, 'user/signing-key') .then(data => { self._signingKey = data.data.ocs.data['signing-key'] return Promise.resolve(self._signingKey) }) }
_sendDavReport (body) { if (!this.helpers.getAuthorization()) { return Promise.reject('Please specify an authorization first.') } return this.helpers.getCurrentUserAsync().then(user => { const path = '/files/' + user.id + '/' const headers = this.helpers.buildHeaders() headers['Content-Type'] = 'application/xml; charset=utf-8' return this.davClient.request('REPORT', this.helpers._buildFullWebDAVPathV2(path), headers, body).then(result => { if (result.status !== 207) { return Promise.reject(this.helpers.buildHttpErrorFromDavResponse(result.status, result.body)) } else { return Promise.resolve(this.helpers._parseBody(result.body, 2)) } }) }) }
/** * Returns a list of versions for the given file id * @param {string|number} fileId file id * @returns {Promise.<fileInfo>} Array[objects]: each object is an instance of class fileInfo * @returns {Promise.<error>} string: error message, if any. */ listVersions (fileId) { const path = '/meta/' + fileId + '/v' return this.davClient.propFind(this.helpers._buildFullWebDAVPathV2(path), [], 1, { Authorization: this.helpers.getAuthorization() }).then(result => { if (result.status !== 207) { return Promise.reject(this.helpers.buildHttpErrorFromDavResponse(result.status, result.body)) } else { return Promise.resolve(this.helpers._parseBody(result.body).splice(1)) } }) }
Promise.resolve(document.save()) .then( () => { return Promise.reject(new Error(field +' required validation failed')); }).catch((err) => { debug(err); should.exist(err); Object.keys(err.errors).length.should.be.exactly(errorsLength ? errorsLength : 1); err.errors.should.have.property(field); })
/** * Returns the file info for the given remote file * @param {string} path path of the file/folder at OC instance * @param {Object.<string, string>} properties WebDAV properties * @returns {Promise.<FileInfo>} object: instance of class fileInfo * @returns {Promise.<error>} string: error message, if any. */ fileInfo (path, properties) { return this.list(path, '0', properties).then(fileInfo => { return Promise.resolve(fileInfo[0]) }) }
/** * Returns the content of a version of a remote file version * @param {string} fileId id of the remote file at OC instance * @param {string} versionId id of the version of the remote file at OC instance */ getFileVersionContents (fileId, versionId) { const path = '/meta/' + fileId + '/v/' + versionId return this.helpers._get(this.helpers._buildFullWebDAVPathV2(path)).then(data => { const response = data.response const body = data.body if (response.statusCode === 200) { return Promise.resolve(body) } else { return Promise.reject(this.helpers.buildHttpErrorFromDavResponse(response.status, body)) } }) }
/** * Disables an app via the Provisioning API * @param {string} appName name of the app to be disabled * @returns {Promise.<status>} boolean: true if successful * @returns {Promise.<error>} string: error message, if any. */ disableApp (appName) { return this.helpers._makeOCSrequest('DELETE', this.helpers.OCS_SERVICE_CLOUD, 'apps/' + encodeURIComponent(appName)) .then(data => { const statusCode = parseInt(this.helpers._checkOCSstatusCode(data.data)) if (statusCode === 999) { return Promise.reject('Provisioning API has been disabled at your instance') } return Promise.resolve(true) }) }
/** * Updates the user logging in. * @returns {Promise.<_currentUser>} object: _currentUser * @returns {Promise.<error>} string: error message, if any. */ _updateCurrentUser () { const self = this return self._makeOCSrequest('GET', self.OCS_SERVICE_CLOUD, 'user') .then(data => { self._currentUser = data.data.ocs.data return Promise.resolve(self._currentUser) }) }
/** * Returns ownCloud config information * @returns {Promise.<configs>} object: {"version" : "1.7", "website" : "ownCloud" etc...} * @returns {Promise.<error>} string: error message, if any. */ getConfig () { return this.helpers._makeOCSrequest('GET', '', 'config') .then(data => { return Promise.resolve(data.data.ocs.data) }) }
/** * Sets an application attribute * @param {string} app application ID (Generally app-name) * @param {string} key attribute key or None to retrieve all values for the given application * @param {string} value value to set of given attribute * @returns {Promise.<status>} boolean: true if successful * @returns {Promise.<error>} string: error message, if any. */ setAttribute (app, key, value) { const path = 'setattribute/' + encodeURIComponent(app) + '/' + encodeURIComponent(this.helpers._encodeString(key)) return this.helpers._makeOCSrequest('POST', this.helpers.OCS_SERVICE_PRIVATEDATA, path, { value: this.helpers._encodeString(value) }) .then(() => { return Promise.resolve(true) }) }