Skip to content

Commit 14d02cf

Browse files
committed
Refactor into resolveFilePath.
1 parent b52ef3e commit 14d02cf

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

lib/handlers/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function hasReadPermissions (file, req, res, callback) {
204204
return callback(true)
205205
}
206206

207-
const root = ldp.resourceMapper.getBaseFilePath(req.hostname)
207+
const root = ldp.resourceMapper.resolveFilePath(req.hostname)
208208
const relativePath = '/' + _path.relative(root, file)
209209
res.locals.path = relativePath
210210
allow('Read')(req, res, err => callback(!err))

lib/handlers/patch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function patchHandler (req, res, next) {
6767
const result = await withLock(path, { mustExist: false }, async () => {
6868
const graph = await readGraph(resource)
6969
await applyPatch(patchObject, graph, url)
70-
return writeGraph(graph, resource, ldp.resourceMapper.getBaseFilePath(req.hostname), ldp.serverUri)
70+
return writeGraph(graph, resource, ldp.resourceMapper.resolveFilePath(req.hostname), ldp.serverUri)
7171
})
7272

7373
// Send the result to the client

lib/ldp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class LDP {
219219
let isOverQuota
220220
try {
221221
const { hostname } = URL.parse(url.url || url)
222-
isOverQuota = await overQuota(this.resourceMapper.getBaseFilePath(hostname), this.serverUri)
222+
isOverQuota = await overQuota(this.resourceMapper.resolveFilePath(hostname), this.serverUri)
223223
} catch (err) {
224224
throw error(500, 'Error finding user quota')
225225
}

lib/models/account-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class AccountManager {
131131
*/
132132
accountDirFor (accountName) {
133133
const { hostname } = url.parse(this.accountUriFor(accountName))
134-
return this.store.resourceMapper.getBaseFilePath(hostname)
134+
return this.store.resourceMapper.resolveFilePath(hostname)
135135
}
136136

137137
/**

lib/resource-mapper.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ class ResourceMapper {
5050
return this.resolveUrl(hostname, pathname)
5151
}
5252

53-
// Returns the URL for the relative path on the pod
53+
// Returns the URL corresponding to the relative path on the pod
5454
resolveUrl (hostname, pathname = '') {
5555
return !this._includeHost ? `${this._rootUrl}${pathname}`
5656
: `${this._protocol}//${hostname}${this._port}${this._rootUrl}${pathname}`
5757
}
5858

59-
// Gets the base file path for the given host name
60-
getBaseFilePath (hostname) {
61-
return !this._includeHost ? this._rootPath : `${this._rootPath}/${hostname}`
59+
// Returns the file path corresponding to the relative file path on the pod
60+
resolveFilePath (hostname, filePath = '') {
61+
return !this._includeHost ? `${this._rootPath}${filePath}`
62+
: `${this._rootPath}/${hostname}${filePath}`
6263
}
6364

6465
// Maps a given server file to a URL
@@ -79,7 +80,7 @@ class ResourceMapper {
7980
async mapUrlToFile ({ url, contentType, createIfNotExists, searchIndex = true }) {
8081
// Parse the URL and find the base file path
8182
const { pathname, hostname } = this._parseUrl(url)
82-
let filePath = `${this.getBaseFilePath(hostname)}${decodeURIComponent(pathname)}`
83+
const filePath = this.resolveFilePath(hostname, decodeURIComponent(pathname))
8384
if (filePath.indexOf('/..') >= 0) {
8485
throw new Error('Disallowed /.. segment in URL')
8586
}

lib/server-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function ensureDirCopyExists (fromDir, toDir) {
5959
*/
6060
async function ensureWelcomePage (argv) {
6161
const { resourceMapper, templates, server, host } = argv
62-
const serverRootDir = resourceMapper.getBaseFilePath(host.hostname)
62+
const serverRootDir = resourceMapper.resolveFilePath(host.hostname)
6363
const existingIndexPage = path.join(serverRootDir, 'index.html')
6464
const packageData = require('../package.json')
6565

0 commit comments

Comments
 (0)