Skip to content

Commit b74e92a

Browse files
committed
Get rid of getRepresentationUrlForResource.
1 parent fadf2cc commit b74e92a

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

lib/handlers/allow.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ function allow (mode, checkPermissionsForDirectory) {
5656
if (mode === 'Read' && (resourcePath === '' || resourcePath === '/')) {
5757
// This is a hack to make NSS check the ACL for representation that is served for root (if any)
5858
// See https://github.com/solid/node-solid-server/issues/1063 for more info
59-
const representationUrl = await ldp.resourceMapper.getRepresentationUrlForResource(resourceUrl)
60-
if (representationUrl.endsWith('index.html')) {
61-
// We ONLY want to do this when the representation we return is a HTML file
59+
const representationUrl = `${rootUrl}/index.html`
60+
let representationPath
61+
try {
62+
representationPath = await ldp.resourceMapper.mapUrlToFile({ url: representationUrl })
63+
} catch (err) {
64+
}
65+
66+
// We ONLY want to do this when the HTML representation exists
67+
if (representationPath) {
6268
req.acl = ACL.createFromLDPAndRequest(representationUrl, ldp, req)
6369
const representationIsAllowed = await req.acl.can(userId, mode)
6470
if (representationIsAllowed) {

lib/resource-mapper.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,6 @@ class ResourceMapper {
100100
}
101101
}
102102

103-
async getRepresentationUrlForResource (resourceUrl) {
104-
let fullFilePath = this._getFilePath(resourceUrl)
105-
let isIndex = fullFilePath.endsWith('/')
106-
107-
// Append index filename if the URL ends with a '/'
108-
if (isIndex) {
109-
fullFilePath += this._indexFilename
110-
}
111-
112-
// Read all files in the corresponding folder
113-
const filename = fullFilePath.substr(fullFilePath.lastIndexOf('/') + 1)
114-
const folder = fullFilePath.substr(0, fullFilePath.length - filename.length)
115-
const files = await this._readdir(folder)
116-
117-
// Find a file with the same name (minus the dollar extension)
118-
let match = (files.find(f => this._removeDollarExtension(f) === filename || (isIndex && f.startsWith(this._indexFilename + '.'))))
119-
return `${resourceUrl}${match || ''}`
120-
}
121-
122103
// Maps a given server file to a URL
123104
async mapFileToUrl ({ path, hostname }) {
124105
// Determine the URL by chopping off everything after the dollar sign

0 commit comments

Comments
 (0)