fc77ee76d6
The primary license of the project is changing to: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later The Additional Permission is designed to permit publicly distributed Javascript code to be relicensed under LGPL-3.0-or-later, but not server-side Javascript code. As such, we've relicensed here static Javscript files under LGPL-3.0-or-later, and those that run as part of build and/or server side under AGPL-3.0-or-later. Note that in future, Javascript files may be updated to be stronger copyleft license with the Additional Permission, particularly if they adapted to run on server side and/or turned into templates. Of course, we'd seek public discussion with the contributor community about such changes. This commit is one of the many steps to relicense the entire codebase. Documentation granting permission for this relicensing (from all past contributors who hold copyrights) is on file with Software Freedom Conservancy, Inc.
41 lines
1 KiB
JavaScript
41 lines
1 KiB
JavaScript
// License: LGPL-3.0-or-later
|
|
// super-agent with default json and csrf wrappers
|
|
// Also has a Promise api ('.then' and '.catch') rather than the default '.end'
|
|
|
|
var request = require('superagent')
|
|
|
|
var wrapper = {}
|
|
module.exports = wrapper
|
|
|
|
wrapper.post = function() {
|
|
var req = request.post.apply(this, arguments).set('X-CSRF-Token', window._csrf).type('json')
|
|
return convert_to_promise(req)
|
|
}
|
|
|
|
wrapper.put = function() {
|
|
var req = request.put.apply(this, arguments).set('X-CSRF-Token', window._csrf).type('json')
|
|
return convert_to_promise(req)
|
|
}
|
|
|
|
wrapper.del = function() {
|
|
var req = request.del.apply(this, arguments).set('X-CSRF-Token', window._csrf).type('json')
|
|
return convert_to_promise(req)
|
|
}
|
|
|
|
wrapper.get = function(path) {
|
|
var req = request.get.call(this, path).accept('json')
|
|
return convert_to_promise(req)
|
|
}
|
|
|
|
function convert_to_promise(req) {
|
|
req.perform = function() {
|
|
return new Promise(function(resolve, reject) {
|
|
req.end(function(err, resp) {
|
|
if(resp && resp.ok) { resolve(resp) }
|
|
else { reject(resp) }
|
|
})
|
|
})
|
|
}
|
|
return req
|
|
}
|
|
|