Skip to content

Commit 467962c

Browse files
Wrap lines to 80 chars
1 parent 6ebc535 commit 467962c

File tree

4 files changed

+95
-68
lines changed

4 files changed

+95
-68
lines changed

lib/acl.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ ACL.prototype.can = function (user, mode, resource, callback, options) {
105105
})
106106
}
107107

108-
ACL.prototype.findAgentClass = function (graph, user, mode, resource, acl, callback) {
108+
ACL.prototype.findAgentClass = function (graph, user, mode, resource, acl,
109+
callback) {
109110
var self = this
110111

111112
// Agent class statement
@@ -131,7 +132,8 @@ ACL.prototype.findAgentClass = function (graph, user, mode, resource, acl, callb
131132
}, callback)
132133
}
133134

134-
ACL.prototype.findRule = function (graph, user, mode, resource, accessType, acl, callback, options) {
135+
ACL.prototype.findRule = function (graph, user, mode, resource, accessType, acl,
136+
callback, options) {
135137
var self = this
136138

137139
// TODO check if this is necessary
@@ -155,7 +157,8 @@ ACL.prototype.findRule = function (graph, user, mode, resource, accessType, acl,
155157
var statementSubject = statement.subject.uri
156158

157159
// Check for origin
158-
var matchOrigin = self.matchOrigin(graph, statementSubject, options.origin, options.host)
160+
var matchOrigin = self.matchOrigin(graph, statementSubject,
161+
options.origin, options.host)
159162
if (!matchOrigin) {
160163
debug('The request does not match the origin')
161164
return done(false)
@@ -164,7 +167,8 @@ ACL.prototype.findRule = function (graph, user, mode, resource, accessType, acl,
164167
// Check for accessTo/defaultForNew
165168
if (!self.isAcl(resource) || accessType === 'defaultForNew') {
166169
debug('Checking for accessType:' + accessType)
167-
var accesses = self.matchAccessType(graph, statementSubject, accessType, resource)
170+
var accesses = self.matchAccessType(graph, statementSubject, accessType,
171+
resource)
168172
if (!accesses) {
169173
debug('Cannot find accessType ' + accessType)
170174
return done(false)
@@ -189,7 +193,8 @@ ACL.prototype.findRule = function (graph, user, mode, resource, accessType, acl,
189193

190194
debug('Inspect agentClass')
191195
// Check for AgentClass
192-
return self.findAgentClass(graph, user, mode, resource, statementSubject, done)
196+
return self.findAgentClass(graph, user, mode, resource, statementSubject,
197+
done)
193198
},
194199
function (found) {
195200
if (!found) {
@@ -209,7 +214,8 @@ ACL.prototype.getMode = function getMode (graph, mode) {
209214
'http://www.w3.org/ns/auth/acl#' + mode)
210215
}
211216

212-
ACL.prototype.matchAccessType = function matchAccessType (graph, rule, accessType, uri) {
217+
ACL.prototype.matchAccessType = function matchAccessType (graph, rule,
218+
accessType, uri) {
213219
var self = this
214220
var matches = self.match(
215221
graph,
@@ -250,7 +256,8 @@ function possibleACLs (uri, suffix) {
250256
var first = S(uri).endsWith(suffix) ? uri : uri + suffix
251257
var urls = [first]
252258
var parsedUri = url.parse(uri)
253-
var baseUrl = (parsedUri.protocol ? parsedUri.protocol + '//' : '') + (parsedUri.host || '')
259+
var baseUrl = (parsedUri.protocol ? parsedUri.protocol + '//' : '') +
260+
(parsedUri.host || '')
254261
if (baseUrl + '/' === uri) {
255262
return urls
256263
}
@@ -301,18 +308,19 @@ function getUserId (req, callback) {
301308
}
302309

303310
var delegator = rdfVocab.debrack(onBehalfOf)
304-
verifyDelegator(req.hostname, delegator, req.session.userId, function (err, res) {
305-
if (err) {
306-
err.status = 500
307-
return callback(err)
308-
}
311+
verifyDelegator(req.hostname, delegator, req.session.userId,
312+
function (err, res) {
313+
if (err) {
314+
err.status = 500
315+
return callback(err)
316+
}
309317

310-
if (res) {
311-
debug('Request User ID (delegation) :' + delegator)
312-
return callback(null, delegator)
313-
}
314-
return callback(null, req.session.userId)
315-
})
318+
if (res) {
319+
debug('Request User ID (delegation) :' + delegator)
320+
return callback(null, delegator)
321+
}
322+
return callback(null, req.session.userId)
323+
})
316324
}
317325

318326
function verifyDelegator (host, ldp, baseUri, delegator, delegatee, callback) {
@@ -365,7 +373,9 @@ function allow (mode) {
365373
getUserId(req, function (err, userId) {
366374
if (err) return next(err)
367375

368-
var reqPath = res && res.locals && res.locals.path ? res.locals.path : req.path
376+
var reqPath = res && res.locals && res.locals.path
377+
? res.locals.path
378+
: req.path
369379
ldp.exists(req.hostname, reqPath, function (err, stat) {
370380
if (reqPath[reqPath.length - 1] !== '/' &&
371381
!err &&

lib/identity-provider.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ IdentityProvider.prototype.create = function (options, cert, callback) {
102102
graphs.push(self.putGraph(options.preferences, createPreferences(options)))
103103
}
104104
if (options.inbox) {
105-
graphs.push(self.putGraph(options.inbox + self.suffixAcl, createInboxAcl(options)))
105+
graphs.push(self.putGraph(options.inbox + self.suffixAcl,
106+
createInboxAcl(options)))
106107
}
107108
if (options.defaultContainers && options.defaultContainers.length > 0) {
108109
throw new Error('default containers is not supported yet')
@@ -382,10 +383,12 @@ IdentityProvider.prototype.get = function (req, res, next) {
382383
if (err && err.status === 404) {
383384
// TODO maybe a personalized page
384385
// or a redirect
385-
debug('Account on ' + req.hostname + ' is available from ' + req.originalUrl)
386+
debug('Account on ' + req.hostname + ' is available from ' +
387+
req.originalUrl)
386388
return res.sendStatus(404)
387389
} else {
388-
debug('Account on ' + req.hostname + ' is not available ' + req.originalUrl)
390+
debug('Account on ' + req.hostname + ' is not available ' +
391+
req.originalUrl)
389392
return next()
390393
}
391394
})
@@ -410,7 +413,8 @@ IdentityProvider.prototype.newCert = function (req, res, next) {
410413
debug('Requesting new cert for ' + options.webid)
411414

412415
if (req.session.userId !== options.webid) {
413-
debug('user is not logged in: ' + req.session.userId + ' is not ' + options.webid)
416+
debug('user is not logged in: ' + req.session.userId + ' is not ' +
417+
options.webid)
414418
var error = new Error('You are not logged in, so you can\'t create a certificate')
415419
error.status = 401
416420
return next(error)
@@ -423,7 +427,8 @@ IdentityProvider.prototype.newCert = function (req, res, next) {
423427
// Get a new cert
424428
webid('tls').generate({
425429
spkac: spkac,
426-
commonName: options.name + ' [on ' + options.host + ' created at ' + options.date.toDateString() + ']',
430+
commonName: options.name + ' [on ' + options.host + ' created at ' +
431+
options.date.toDateString() + ']',
427432
issuer: { commonName: options.host },
428433
duration: 10,
429434
agent: options.webid
@@ -465,32 +470,33 @@ IdentityProvider.prototype.getGraph = function (uri, callback) {
465470
var hostname = parsed.hostname
466471
var reqPath = parsed.path
467472

468-
self.store.get(hostname, reqPath, null, true, 'text/turtle', function (err, stream) {
469-
if (err) {
470-
debug('Cannot find WebID card')
471-
var notexists = new Error('Cannot find WebID card')
472-
notexists.status = 500
473-
return callback(notexists)
474-
}
475-
var data = ''
476-
stream
477-
.on('data', function (chunk) {
478-
data += chunk
479-
})
480-
.on('end', function () {
481-
// TODO make sure that uri is correct
482-
parse(data, uri, 'text/turtle', function (err, card) {
483-
if (err) {
484-
debug('WebId can\'t be parsed: ' + err.message)
485-
var invalid = new Error('You have an invalid WebID card')
486-
invalid.status = 500
487-
return callback(invalid)
488-
}
489-
490-
return callback(null, card)
473+
self.store.get(hostname, reqPath, null, true, 'text/turtle',
474+
function (err, stream) {
475+
if (err) {
476+
debug('Cannot find WebID card')
477+
var notexists = new Error('Cannot find WebID card')
478+
notexists.status = 500
479+
return callback(notexists)
480+
}
481+
var data = ''
482+
stream
483+
.on('data', function (chunk) {
484+
data += chunk
491485
})
492-
})
493-
})
486+
.on('end', function () {
487+
// TODO make sure that uri is correct
488+
parse(data, uri, 'text/turtle', function (err, card) {
489+
if (err) {
490+
debug('WebId can\'t be parsed: ' + err.message)
491+
var invalid = new Error('You have an invalid WebID card')
492+
invalid.status = 500
493+
return callback(invalid)
494+
}
495+
496+
return callback(null, card)
497+
})
498+
})
499+
})
494500
}
495501

496502
// Handle POST requests on account creation

lib/ldp.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ function LDP (argv) {
5353
}
5454

5555
if (this.fileBrowser !== false) {
56-
this.fileBrowser = argv.fileBrowser || 'https://linkeddata.github.io/warp/#/list/'
56+
this.fileBrowser = argv.fileBrowser ||
57+
'https://linkeddata.github.io/warp/#/list/'
5758
}
5859

5960
if (this.dataBrowser !== false) {
@@ -124,7 +125,8 @@ LDP.prototype.readContainerMeta = function (directory, callback) {
124125
})
125126
}
126127

127-
LDP.prototype.listContainer = function (filename, uri, containerData, contentType, callback) {
128+
LDP.prototype.listContainer = function (filename, uri, containerData,
129+
contentType, callback) {
128130
var ldp = this
129131
var host = url.parse(uri).hostname
130132
var root = !ldp.idp ? ldp.root : ldp.root + host + '/'
@@ -184,7 +186,8 @@ LDP.prototype.listContainer = function (filename, uri, containerData, contentTyp
184186
})
185187
}
186188

187-
function addFile (ldp, resourceGraph, baseUri, uri, container, file, callback) {
189+
function addFile (ldp, resourceGraph, baseUri, uri, container, file,
190+
callback) {
188191
// Skip .meta and .acl
189192
if (S(file).endsWith(ldp.suffixMeta) || S(file).endsWith(ldp.suffixAcl)) {
190193
return callback(null)
@@ -324,7 +327,8 @@ LDP.prototype.listContainer = function (filename, uri, containerData, contentTyp
324327
})
325328
}
326329

327-
LDP.prototype.post = function (hostname, containerPath, slug, stream, container, callback) {
330+
LDP.prototype.post = function (hostname, containerPath, slug, stream, container,
331+
callback) {
328332
var ldp = this
329333

330334
debug.handlers('POST -- On parent: ' + containerPath)
@@ -361,13 +365,15 @@ LDP.prototype.put = function (host, resourcePath, stream, callback) {
361365

362366
// PUT requests not supported on containers. Use POST instead
363367
if (filePath[filePath.length - 1] === '/') {
364-
return callback(error(409, 'PUT not supported on containers, use POST instead'))
368+
return callback(error(409,
369+
'PUT not supported on containers, use POST instead'))
365370
}
366371

367372
mkdirp(path.dirname(filePath), function (err) {
368373
if (err) {
369374
debug.handlers('PUT -- Error creating directory: ' + err)
370-
return callback(error(err, 'Failed to create the path to the new resource'))
375+
return callback(error(err,
376+
'Failed to create the path to the new resource'))
371377
}
372378
var file = stream.pipe(fs.createWriteStream(filePath))
373379
file.on('error', function () {
@@ -384,7 +390,8 @@ LDP.prototype.exists = function (host, reqPath, callback) {
384390
this.get(host, reqPath, undefined, false, undefined, callback)
385391
}
386392

387-
LDP.prototype.get = function (host, reqPath, baseUri, includeBody, contentType, callback) {
393+
LDP.prototype.get = function (host, reqPath, baseUri, includeBody, contentType,
394+
callback) {
388395
var ldp = this
389396
var root = !ldp.idp ? ldp.root : ldp.root + host + '/'
390397
var filename = utils.uriToFilename(reqPath, root)
@@ -407,16 +414,17 @@ LDP.prototype.get = function (host, reqPath, baseUri, includeBody, contentType,
407414
metaFile = ''
408415
}
409416

410-
ldp.listContainer(filename, baseUri, metaFile, contentType, function (err, data) {
411-
if (err) {
412-
debug.handlers('GET container -- Read error:' + err.message)
413-
return callback(err)
414-
}
415-
var stream = stringToStream(data)
416-
// TODO 'text/turtle' is fixed, should be contentType instead
417-
// This forces one more translation turtle -> desired
418-
return callback(null, stream, 'text/turtle', true)
419-
})
417+
ldp.listContainer(filename, baseUri, metaFile, contentType,
418+
function (err, data) {
419+
if (err) {
420+
debug.handlers('GET container -- Read error:' + err.message)
421+
return callback(err)
422+
}
423+
var stream = stringToStream(data)
424+
// TODO 'text/turtle' is fixed, should be contentType instead
425+
// This forces one more translation turtle -> desired
426+
return callback(null, stream, 'text/turtle', true)
427+
})
420428
})
421429
} else {
422430
var stream = ldp.createReadStream(filename)

lib/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function uriBase (req) {
5757
function pathBasename (fullpath) {
5858
var bname = ''
5959
if (fullpath) {
60-
bname = (fullpath.lastIndexOf('/') === fullpath.length - 1) ? '' : path.basename(fullpath)
60+
bname = (fullpath.lastIndexOf('/') === fullpath.length - 1)
61+
? ''
62+
: path.basename(fullpath)
6163
}
6264
return bname
6365
}
@@ -99,7 +101,8 @@ function serialize (graph, baseUri, contentType, callback) {
99101
return callback(err)
100102
}
101103
if (result === undefined) {
102-
return callback(new Error('Error serializing the graph to ' + contentType))
104+
return callback(new Error('Error serializing the graph to ' +
105+
contentType))
103106
}
104107

105108
return callback(null, result)

0 commit comments

Comments
 (0)