Skip to content

Commit 36764c6

Browse files
committed
Fix linting errors in handlers after rebase
1 parent 5cc7ac4 commit 36764c6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/handlers/allow.js

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

3+
const $rdf = require('rdflib')
34
const ACL = require('../acl-checker')
45
const debug = require('../debug.js').ACL
6+
const fs = require('fs')
7+
const { promisify } = require('util')
8+
const HTTPError = require('../http-error')
59

610
function allow (mode) {
711
return async function allowHandler (req, res, next) {
@@ -35,9 +39,9 @@ function allow (mode) {
3539

3640
// Obtain and store the ACL of the requested resource
3741
req.acl = new ACL(rootUrl + reqPath, {
38-
origin: req.get('origin'),
42+
agentOrigin: req.get('origin'),
3943
// host: req.get('host'),
40-
fetch: fetchFromLdp(ldp.resourceMapper, ldp),
44+
fetch: fetchFromLdp(ldp.resourceMapper),
4145
fetchGraph: (uri, options) => {
4246
// first try loading from local fs
4347
return ldp.getGraph(uri, options.contentType)
@@ -69,14 +73,17 @@ function allow (mode) {
6973
* - `callback(null, graph)` with the parsed RDF graph of the fetched resource
7074
* @return {Function} Returns a `fetch(uri, callback)` handler
7175
*/
72-
function fetchFromLdp (mapper, ldp) {
76+
function fetchFromLdp (mapper) {
7377
return async function fetch (url, graph = $rdf.graph()) {
7478
// Convert the URL into a filename
75-
const { path, contentType } = await mapper.mapUrlToFile({ url })
79+
let path, contentType
80+
try {
81+
({ path, contentType } = await mapper.mapUrlToFile({ url }))
82+
} catch (err) {
83+
throw new HTTPError(404, err)
84+
}
7685
// Read the file from disk
77-
const body = await new Promise((resolve, reject) => {
78-
ldp.readFile(path, (e, c) => e ? reject(e) : resolve(c))
79-
})
86+
const body = await promisify(fs.readFile)(path, {'encoding': 'utf8'})
8087
// Parse the file as Turtle
8188
$rdf.parse(body, graph, url, contentType)
8289
return graph

lib/handlers/patch.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ function readGraph (resource) {
110110
})
111111
}
112112

113-
114113
// Verifies whether the user is allowed to perform the patch on the target
115114
async function checkPermission (request, patchObject) {
116115
// If no ACL object was passed down, assume permissions are okay.

0 commit comments

Comments
 (0)