-
Notifications
You must be signed in to change notification settings - Fork 305
Removes acl files from list of files to match when mapping url to file #1109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b1562ac
218b36a
d3e6506
31f113a
08684fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,8 @@ class ResourceMapper { | |
| includeHost = false, | ||
| defaultContentType = 'application/octet-stream', | ||
| indexFilename = 'index', | ||
| overrideTypes = { acl: 'text/turtle', meta: 'text/turtle' } | ||
| overrideTypes = { acl: 'text/turtle', meta: 'text/turtle' }, | ||
| fileSuffixes = ['.acl', '.meta'] | ||
| }) { | ||
| this._rootUrl = this._removeTrailingSlash(rootUrl) | ||
| this._rootPath = this._removeTrailingSlash(rootPath) | ||
|
|
@@ -24,6 +25,7 @@ class ResourceMapper { | |
| this._defaultContentType = defaultContentType | ||
| this._indexFilename = indexFilename | ||
| this._types = { ...types, ...overrideTypes } | ||
| this._isControlFile = new RegExp(`(?:${fileSuffixes.map(fs => fs.replace('.', '\\.')).join('|')})$`) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regex is so difficult =P |
||
|
|
||
| // If the host needs to be replaced on every call, pre-split the root URL | ||
| if (includeHost) { | ||
|
|
@@ -68,11 +70,9 @@ class ResourceMapper { | |
| // Read all files in the corresponding folder | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outdated comment |
||
| const filename = fullPath.substr(fullPath.lastIndexOf('/') + 1) | ||
| const folder = fullPath.substr(0, fullPath.length - filename.length) | ||
| const files = await this._readdir(folder) | ||
|
|
||
| // Find a file with the same name (minus the dollar extension) | ||
| let match = !searchIndex ? '' : (files.find(f => this._removeDollarExtension(f) === filename || | ||
| (isIndex && f.startsWith(this._indexFilename + '.')))) | ||
| let match = searchIndex ? await this._getMatchingFile(folder, filename, isIndex) : '' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I would move this specific bit to a new function. Is there potential for reuse?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thinking was to make it more readable by giving it a name. Don't know of any potential reuse, no. |
||
| if (match === undefined) { | ||
| // Error if no match was found, | ||
| // unless the URL ends with a '/', | ||
|
|
@@ -90,6 +90,17 @@ class ResourceMapper { | |
| return { path, contentType: contentType || this._defaultContentType } | ||
| } | ||
|
|
||
| async _getMatchingFile (folder, filename, isIndex) { | ||
| const files = await this._readdir(folder) | ||
| const hasSameName = (f) => { | ||
| return this._removeDollarExtension(f) === filename | ||
| } | ||
| const isIndexFile = (f) => { | ||
| return isIndex && f.startsWith(this._indexFilename + '.') && !this._isControlFile.test(f) | ||
| } | ||
| return files.find(f => hasSameName(f) || isIndexFile(f)) | ||
| } | ||
|
|
||
| async getRepresentationUrlForResource (resourceUrl) { | ||
| let fullPath = this.getFullPath(resourceUrl) | ||
| let isIndex = fullPath.endsWith('/') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear variable name. I would name it something like
controlExtensions.