Skip to content

Commit 3979844

Browse files
committed
Remove utils#uriToFilename
All usages have been refactored to use the ResourceMapper instead. This also removes the related reqToPath and uriToRelativeFilename functions.
1 parent 00aa705 commit 3979844

File tree

2 files changed

+0
-45
lines changed

2 files changed

+0
-45
lines changed

lib/utils.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
module.exports.uriToFilename = uriToFilename
2-
module.exports.uriToRelativeFilename = uriToRelativeFilename
31
module.exports.getBaseUri = getBaseUri
42
module.exports.pathBasename = pathBasename
53
module.exports.getFullUri = getFullUri
64
module.exports.hasSuffix = hasSuffix
75
module.exports.serialize = serialize
86
module.exports.translate = translate
97
module.exports.stringToStream = stringToStream
10-
module.exports.reqToPath = reqToPath
118
module.exports.debrack = debrack
129
module.exports.stripLineEndings = stripLineEndings
1310
module.exports.fullUrlForReq = fullUrlForReq
1411
module.exports.routeResolvedFile = routeResolvedFile
1512
module.exports.getQuota = getQuota
1613
module.exports.overQuota = overQuota
1714

18-
const fs = require('fs-extra')
1915
const path = require('path')
2016
const util = require('util')
2117
const $rdf = require('rdflib')
@@ -73,29 +69,6 @@ function debrack (s) {
7369
return s.substring(1, s.length - 1)
7470
}
7571

76-
function uriToFilename (uri, base) {
77-
const decoded = uri.split('/').map(decodeURIComponent).join('/')
78-
let filename = path.join(base, decoded)
79-
// Make sure filename ends with '/' if filename exists and is a directory.
80-
// TODO this sync operation can be avoided and can be left
81-
// to do, to other components, see `ldp.get`
82-
try {
83-
const fileStats = fs.statSync(filename)
84-
if (fileStats.isDirectory() && !filename.endsWith('/')) {
85-
filename += '/'
86-
} else if (fileStats.isFile() && filename.endsWith('/')) {
87-
filename = filename.substr(0, filename.length - 1)
88-
}
89-
} catch (err) {}
90-
return filename
91-
}
92-
93-
function uriToRelativeFilename (uri, base) {
94-
const filename = uriToFilename(uri, base)
95-
const relative = path.relative(base, filename)
96-
return relative
97-
}
98-
9972
function getBaseUri (req) {
10073
// Obtain the protocol from the configured server URI
10174
// (in case the server is running behind a reverse proxy)
@@ -221,12 +194,6 @@ function stripLineEndings (obj) {
221194
return obj.replace(/(\r\n|\n|\r)/gm, '')
222195
}
223196

224-
function reqToPath (req) {
225-
const ldp = req.app.locals.ldp
226-
const root = ldp.multiuser ? ldp.root + req.hostname + '/' : ldp.root
227-
return uriToFilename(req.path, root)
228-
}
229-
230197
/**
231198
* Adds a route that serves a static file from another Node module
232199
*/

test/unit/utils-test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ describe('Utility functions', function () {
2121
})
2222
})
2323

24-
describe('uriToFilename', function () {
25-
it('should decode hex-encoded space', function () {
26-
assert.equal(utils.uriToFilename('uri%20', 'base/'), 'base/uri ')
27-
})
28-
it('should decode hex-encoded at sign', function () {
29-
assert.equal(utils.uriToFilename('film%4011', 'base/'), 'base/film@11')
30-
})
31-
it('should decode hex-encoded single quote', function () {
32-
assert.equal(utils.uriToFilename('quote%27', 'base/'), 'base/quote\'')
33-
})
34-
})
35-
3624
describe('stripLineEndings()', () => {
3725
it('should pass through falsy string arguments', () => {
3826
assert.equal(utils.stripLineEndings(''), '')

0 commit comments

Comments
 (0)