Skip to content

Commit ee72c03

Browse files
Merge pull request #655 from ninachaubal/block-level-scope
Use block level scope instead of function level scope
2 parents 3bec51c + a3cc037 commit ee72c03

File tree

17 files changed

+218
-205
lines changed

17 files changed

+218
-205
lines changed

lib/api/authn/webid-tls.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var webid = require('webid/tls')
2-
var debug = require('../../debug').authentication
3-
var x509 // optional dependency, load lazily
1+
const webid = require('webid/tls')
2+
const debug = require('../../debug').authentication
3+
let x509 // optional dependency, load lazily
44

55
const CERTIFICATE_MATCHER = /^-----BEGIN CERTIFICATE-----\n(?:[A-Za-z0-9+/=]+\n)+-----END CERTIFICATE-----$/m
66

lib/capability-discovery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = capabilityDiscovery
2929
* @return {Router} Express router
3030
*/
3131
function capabilityDiscovery () {
32-
var router = express.Router('/')
32+
const router = express.Router('/')
3333

3434
// Advertise the server capability discover endpoint
3535
router.get('/.well-known/solid', serviceCapabilityDocument(serviceConfigDefaults))

lib/create-server.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
module.exports = createServer
22

3-
var express = require('express')
4-
var fs = require('fs')
5-
var https = require('https')
6-
var http = require('http')
7-
var SolidWs = require('solid-ws')
8-
var debug = require('./debug')
9-
var createApp = require('./create-app')
3+
const express = require('express')
4+
const fs = require('fs')
5+
const https = require('https')
6+
const http = require('http')
7+
const SolidWs = require('solid-ws')
8+
const debug = require('./debug')
9+
const createApp = require('./create-app')
1010
const globalTunnel = require('global-tunnel-ng')
1111

1212
function createServer (argv, app) {
1313
argv = argv || {}
1414
app = app || express()
15-
var ldpApp = createApp(argv)
16-
var ldp = ldpApp.locals.ldp || {}
17-
var mount = argv.mount || '/'
15+
const ldpApp = createApp(argv)
16+
const ldp = ldpApp.locals.ldp || {}
17+
let mount = argv.mount || '/'
1818
// Removing ending '/'
1919
if (mount.length > 1 &&
2020
mount[mount.length - 1] === '/') {
@@ -33,8 +33,8 @@ function createServer (argv, app) {
3333
globalTunnel.initialize(argv.httpProxy)
3434
}
3535

36-
var server
37-
var needsTLS = argv.sslKey || argv.sslCert ||
36+
let server
37+
const needsTLS = argv.sslKey || argv.sslCert ||
3838
(ldp.webid || ldp.multiuser) && !argv.certificateHeader
3939
if (!needsTLS) {
4040
server = http.createServer(app)
@@ -54,21 +54,21 @@ function createServer (argv, app) {
5454
throw new Error('Missing path for SSL cert')
5555
}
5656

57-
var key
57+
let key
5858
try {
5959
key = fs.readFileSync(argv.sslKey)
6060
} catch (e) {
6161
throw new Error('Can\'t find SSL key in ' + argv.sslKey)
6262
}
6363

64-
var cert
64+
let cert
6565
try {
6666
cert = fs.readFileSync(argv.sslCert)
6767
} catch (e) {
6868
throw new Error('Can\'t find SSL cert in ' + argv.sslCert)
6969
}
7070

71-
var credentials = Object.assign({
71+
const credentials = Object.assign({
7272
key: key,
7373
cert: cert
7474
}, argv)
@@ -100,7 +100,7 @@ function createServer (argv, app) {
100100

101101
// Setup Express app
102102
if (ldp.live) {
103-
var solidWs = SolidWs(server, ldpApp)
103+
const solidWs = SolidWs(server, ldpApp)
104104
ldpApp.locals.ldp.live = solidWs.publish.bind(solidWs)
105105
}
106106

lib/debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var debug = require('debug')
1+
const debug = require('debug')
22

33
exports.handlers = debug('solid:handlers')
44
exports.errors = debug('solid:errors')

lib/handlers/allow.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = allow
22

3-
var ACL = require('../acl-checker')
4-
var $rdf = require('rdflib')
5-
var utils = require('../utils')
6-
var debug = require('../debug.js').ACL
7-
var LegacyResourceMapper = require('../legacy-resource-mapper')
3+
const ACL = require('../acl-checker')
4+
const $rdf = require('rdflib')
5+
const utils = require('../utils')
6+
const debug = require('../debug.js').ACL
7+
const LegacyResourceMapper = require('../legacy-resource-mapper')
88

99
function allow (mode) {
1010
return function allowHandler (req, res, next) {
11-
var ldp = req.app.locals.ldp || {}
11+
const ldp = req.app.locals.ldp || {}
1212
if (!ldp.webid) {
1313
return next()
1414
}
@@ -22,7 +22,7 @@ function allow (mode) {
2222
})
2323

2424
// Determine the actual path of the request
25-
var reqPath = res && res.locals && res.locals.path
25+
let reqPath = res && res.locals && res.locals.path
2626
? res.locals.path
2727
: req.path
2828

lib/handlers/delete.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module.exports = handler
22

3-
var debug = require('../debug').handlers
3+
const debug = require('../debug').handlers
44

55
function handler (req, res, next) {
66
debug('DELETE -- Request on' + req.originalUrl)
77

8-
var ldp = req.app.locals.ldp
8+
const ldp = req.app.locals.ldp
99
ldp.delete(req.hostname, req.path, function (err) {
1010
if (err) {
1111
debug('DELETE -- Failed to delete: ' + err)

lib/handlers/get.js

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
module.exports = handler
22

3-
var fs = require('fs')
4-
var glob = require('glob')
5-
var _path = require('path')
6-
var $rdf = require('rdflib')
7-
var S = require('string')
8-
var Negotiator = require('negotiator')
3+
const fs = require('fs')
4+
const glob = require('glob')
5+
const _path = require('path')
6+
const $rdf = require('rdflib')
7+
const S = require('string')
8+
const Negotiator = require('negotiator')
99
const url = require('url')
1010
const mime = require('mime-types')
1111

12-
var debug = require('debug')('solid:get')
13-
var debugGlob = require('debug')('solid:glob')
14-
var allow = require('./allow')
12+
const debug = require('debug')('solid:get')
13+
const debugGlob = require('debug')('solid:glob')
14+
const allow = require('./allow')
1515

16-
var utils = require('../utils.js')
17-
var translate = require('../utils.js').translate
18-
var error = require('../http-error')
16+
const utils = require('../utils.js')
17+
const translate = require('../utils.js').translate
18+
const error = require('../http-error')
1919

2020
const RDFs = require('../ldp').RDF_MIME_TYPES
2121

2222
function handler (req, res, next) {
23-
var ldp = req.app.locals.ldp
24-
var includeBody = req.method === 'GET'
25-
var negotiator = new Negotiator(req)
26-
var baseUri = utils.getFullUri(req)
27-
var path = res.locals.path || req.path
28-
var requestedType = negotiator.mediaType()
29-
var possibleRDFType = negotiator.mediaType(RDFs)
23+
const ldp = req.app.locals.ldp
24+
const includeBody = req.method === 'GET'
25+
const negotiator = new Negotiator(req)
26+
const baseUri = utils.getFullUri(req)
27+
const path = res.locals.path || req.path
28+
const requestedType = negotiator.mediaType()
29+
let possibleRDFType = negotiator.mediaType(RDFs)
3030
// Fallback to text/turtle if content type is unknown
3131
possibleRDFType = (!possibleRDFType) ? 'text/turtle' : possibleRDFType
3232

@@ -39,7 +39,7 @@ function handler (req, res, next) {
3939

4040
debug(req.originalUrl + ' on ' + req.hostname)
4141

42-
var options = {
42+
const options = {
4343
'hostname': req.hostname,
4444
'path': path,
4545
'baseUri': baseUri,
@@ -60,12 +60,18 @@ function handler (req, res, next) {
6060
return next(err)
6161
}
6262

63+
let stream
64+
let contentType
65+
let container
66+
let contentRange
67+
let chunksize
68+
6369
if (ret) {
64-
var stream = ret.stream
65-
var contentType = ret.contentType
66-
var container = ret.container
67-
var contentRange = ret.contentRange
68-
var chunksize = ret.chunksize
70+
stream = ret.stream
71+
contentType = ret.contentType
72+
container = ret.container
73+
contentRange = ret.contentRange
74+
chunksize = ret.chunksize
6975
}
7076

7177
// Till here it must exist
@@ -85,8 +91,8 @@ function handler (req, res, next) {
8591

8692
if (useDataBrowser) {
8793
res.set('Content-Type', 'text/html')
88-
var defaultDataBrowser = _path.join(__dirname, '../../static/databrowser.html')
89-
var dataBrowserPath = ldp.dataBrowserPath === 'default' ? defaultDataBrowser : ldp.dataBrowserPath
94+
const defaultDataBrowser = _path.join(__dirname, '../../static/databrowser.html')
95+
const dataBrowserPath = ldp.dataBrowserPath === 'default' ? defaultDataBrowser : ldp.dataBrowserPath
9096
debug(' sending data browser file: ' + dataBrowserPath)
9197
res.sendFile(dataBrowserPath)
9298
return
@@ -100,7 +106,7 @@ function handler (req, res, next) {
100106
if (negotiator.mediaType([contentType])) {
101107
res.setHeader('Content-Type', contentType)
102108
if (contentRange) {
103-
var headers = { 'Content-Range': contentRange, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize }
109+
const headers = { 'Content-Range': contentRange, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize }
104110
res.writeHead(206, headers)
105111
return stream.pipe(res)
106112
} else {
@@ -129,13 +135,13 @@ function handler (req, res, next) {
129135
}
130136

131137
function globHandler (req, res, next) {
132-
var ldp = req.app.locals.ldp
133-
var root = !ldp.multiuser ? ldp.root : ldp.root + req.hostname + '/'
134-
var filename = utils.uriToFilename(req.path, root)
135-
var uri = utils.getFullUri(req)
138+
const ldp = req.app.locals.ldp
139+
const root = !ldp.multiuser ? ldp.root : ldp.root + req.hostname + '/'
140+
const filename = utils.uriToFilename(req.path, root)
141+
const uri = utils.getFullUri(req)
136142
const requestUri = url.resolve(uri, req.path)
137143

138-
var globOptions = {
144+
const globOptions = {
139145
noext: true,
140146
nobrace: true,
141147
nodir: true
@@ -148,13 +154,13 @@ function globHandler (req, res, next) {
148154
}
149155

150156
// Matches found
151-
var globGraph = $rdf.graph()
157+
const globGraph = $rdf.graph()
152158

153159
let reqOrigin = utils.getBaseUri(req)
154160

155161
debugGlob('found matches ' + matches)
156162
Promise.all(matches.map(match => new Promise((resolve, reject) => {
157-
var baseUri = utils.filenameToBaseUri(match, reqOrigin, root)
163+
const baseUri = utils.filenameToBaseUri(match, reqOrigin, root)
158164
fs.readFile(match, {encoding: 'utf8'}, function (err, fileData) {
159165
if (err) {
160166
debugGlob('error ' + err)
@@ -174,7 +180,7 @@ function globHandler (req, res, next) {
174180
})
175181
})))
176182
.then(() => {
177-
var data = $rdf.serialize(undefined, globGraph, requestUri, 'text/turtle')
183+
const data = $rdf.serialize(undefined, globGraph, requestUri, 'text/turtle')
178184
// TODO this should be added as a middleware in the routes
179185
res.setHeader('Content-Type', 'text/turtle')
180186
debugGlob('returning turtle')
@@ -186,14 +192,14 @@ function globHandler (req, res, next) {
186192
}
187193

188194
function aclAllow (match, req, res, callback) {
189-
var ldp = req.app.locals.ldp
195+
const ldp = req.app.locals.ldp
190196

191197
if (!ldp.webid) {
192198
return callback(true)
193199
}
194200

195-
var root = ldp.multiuser ? ldp.root + req.hostname + '/' : ldp.root
196-
var relativePath = '/' + _path.relative(root, match)
201+
const root = ldp.multiuser ? ldp.root + req.hostname + '/' : ldp.root
202+
const relativePath = '/' + _path.relative(root, match)
197203
res.locals.path = relativePath
198204
allow('Read', req, res, function (err) {
199205
callback(err)

lib/handlers/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module.exports = handler
22

3-
var path = require('path')
4-
var debug = require('debug')('solid:index')
5-
var utils = require('../utils')
6-
var Negotiator = require('negotiator')
3+
const path = require('path')
4+
const debug = require('debug')('solid:index')
5+
const utils = require('../utils')
6+
const Negotiator = require('negotiator')
77

88
function handler (req, res, next) {
9-
var indexFile = 'index.html'
10-
var ldp = req.app.locals.ldp
11-
var negotiator = new Negotiator(req)
12-
var requestedType = negotiator.mediaType()
13-
var filename = utils.reqToPath(req)
9+
const indexFile = 'index.html'
10+
const ldp = req.app.locals.ldp
11+
const negotiator = new Negotiator(req)
12+
const requestedType = negotiator.mediaType()
13+
const filename = utils.reqToPath(req)
1414

1515
ldp.stat(filename, function (err, stats) {
1616
if (err) return next()

lib/handlers/post.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module.exports = handler
22

3-
var Busboy = require('busboy')
4-
var debug = require('debug')('solid:post')
5-
var path = require('path')
6-
var header = require('../header')
7-
var patch = require('./patch')
8-
var error = require('../http-error')
9-
var { extensions } = require('mime-types')
3+
const Busboy = require('busboy')
4+
const debug = require('debug')('solid:post')
5+
const path = require('path')
6+
const header = require('../header')
7+
const patch = require('./patch')
8+
const error = require('../http-error')
9+
const { extensions } = require('mime-types')
1010

1111
function handler (req, res, next) {
12-
var ldp = req.app.locals.ldp
13-
var contentType = req.get('content-type')
12+
const ldp = req.app.locals.ldp
13+
const contentType = req.get('content-type')
1414
debug('content-type is ', contentType)
1515
// Handle SPARQL(-update?) query
1616
if (contentType === 'application/sparql' ||
@@ -20,7 +20,7 @@ function handler (req, res, next) {
2020
}
2121

2222
// Handle container path
23-
var containerPath = req.path
23+
let containerPath = req.path
2424
if (containerPath[containerPath.length - 1] !== '/') {
2525
containerPath += '/'
2626
}
@@ -31,8 +31,9 @@ function handler (req, res, next) {
3131
return next(error(err, 'Container not valid'))
3232
}
3333

34+
let stats
3435
if (ret) {
35-
var stats = ret.stream
36+
stats = ret.stream
3637
}
3738

3839
// Check if container is a directory
@@ -52,7 +53,7 @@ function handler (req, res, next) {
5253
function multi () {
5354
debug('receving multiple files')
5455

55-
var busboy = new Busboy({ headers: req.headers })
56+
const busboy = new Busboy({ headers: req.headers })
5657
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
5758
debug('One file received via multipart: ' + filename)
5859
ldp.put(

0 commit comments

Comments
 (0)