@@ -44,8 +44,8 @@ class ResourceMapper {
44
44
// Maps the request for a given resource and representation format to a server file
45
45
// When searchIndex is true and the URL ends with a '/', and contentType includes 'text/html' indexFilename will be matched.
46
46
async mapUrlToFile ( { url, contentType, createIfNotExists, searchIndex = true } ) {
47
- let fullPath = this . getFullPath ( url )
48
- let isIndex = searchIndex && fullPath . endsWith ( '/' )
47
+ let fullFilePath = this . getFilePath ( url )
48
+ let isIndex = searchIndex && fullFilePath . endsWith ( '/' )
49
49
let path
50
50
51
51
// Append index filename if the URL ends with a '/'
@@ -54,21 +54,21 @@ class ResourceMapper {
54
54
throw new Error ( `Index file needs to have ${ this . _indexContentType } as content type` )
55
55
}
56
56
if ( contentType && contentType . includes ( this . _indexContentType ) ) {
57
- fullPath += this . _indexFilename
57
+ fullFilePath += this . _indexFilename
58
58
}
59
59
}
60
60
// Create the path for a new file
61
61
if ( createIfNotExists ) {
62
- path = fullPath
62
+ path = fullFilePath
63
63
// If the extension is not correct for the content type, append the correct extension
64
64
if ( searchIndex && this . _getContentTypeByExtension ( path ) !== contentType ) {
65
65
path += `$${ contentType in extensions ? `.${ extensions [ contentType ] [ 0 ] } ` : '.unknown' } `
66
66
}
67
67
// Determine the path of an existing file
68
68
} else {
69
69
// Read all files in the corresponding folder
70
- const filename = fullPath . substr ( fullPath . lastIndexOf ( '/' ) + 1 )
71
- const folder = fullPath . substr ( 0 , fullPath . length - filename . length )
70
+ const filename = fullFilePath . substr ( fullFilePath . lastIndexOf ( '/' ) + 1 )
71
+ const folder = fullFilePath . substr ( 0 , fullFilePath . length - filename . length )
72
72
73
73
// Find a file with the same name (minus the dollar extension)
74
74
let match = searchIndex ? await this . _getMatchingFile ( folder , filename , isIndex , contentType ) : ''
@@ -79,7 +79,7 @@ class ResourceMapper {
79
79
if ( isIndex ) {
80
80
match = ''
81
81
} else {
82
- throw new HTTPError ( 404 , `File not found: ${ fullPath } ` )
82
+ throw new HTTPError ( 404 , `File not found: ${ fullFilePath } ` )
83
83
}
84
84
}
85
85
path = `${ folder } ${ match } `
@@ -101,17 +101,17 @@ class ResourceMapper {
101
101
}
102
102
103
103
async getRepresentationUrlForResource ( resourceUrl ) {
104
- let fullPath = this . getFullPath ( resourceUrl )
105
- let isIndex = fullPath . endsWith ( '/' )
104
+ let fullFilePath = this . getFilePath ( resourceUrl )
105
+ let isIndex = fullFilePath . endsWith ( '/' )
106
106
107
107
// Append index filename if the URL ends with a '/'
108
108
if ( isIndex ) {
109
- fullPath += this . _indexFilename
109
+ fullFilePath += this . _indexFilename
110
110
}
111
111
112
112
// Read all files in the corresponding folder
113
- const filename = fullPath . substr ( fullPath . lastIndexOf ( '/' ) + 1 )
114
- const folder = fullPath . substr ( 0 , fullPath . length - filename . length )
113
+ const filename = fullFilePath . substr ( fullFilePath . lastIndexOf ( '/' ) + 1 )
114
+ const folder = fullFilePath . substr ( 0 , fullFilePath . length - filename . length )
115
115
const files = await this . _readdir ( folder )
116
116
117
117
// Find a file with the same name (minus the dollar extension)
@@ -141,13 +141,13 @@ class ResourceMapper {
141
141
}
142
142
143
143
// Determine the full file path corresponding to a URL
144
- getFullPath ( url ) {
144
+ getFilePath ( url ) {
145
145
const { pathname, hostname } = this . _parseUrl ( url )
146
- const fullPath = decodeURIComponent ( `${ this . getBasePath ( hostname ) } ${ pathname } ` )
147
- if ( fullPath . indexOf ( '/..' ) >= 0 ) {
146
+ const fullFilePath = decodeURIComponent ( `${ this . getBasePath ( hostname ) } ${ pathname } ` )
147
+ if ( fullFilePath . indexOf ( '/..' ) >= 0 ) {
148
148
throw new Error ( 'Disallowed /.. segment in URL' )
149
149
}
150
- return fullPath
150
+ return fullFilePath
151
151
}
152
152
153
153
// Parses a URL into a hostname and pathname
0 commit comments