Skip to content

Commit 694bcd0

Browse files
committed
POST does not error in multiuser mode
1 parent 2ca51da commit 694bcd0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/ldp.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,23 @@ class LDP {
432432
}
433433
}
434434

435-
getAvailablePath (host, containerURI, { slug = uuid.v1(), extension }) {
435+
async getAvailablePath (host, containerURI, { slug = uuid.v1(), extension }) {
436+
const fileName = slug + extension
437+
function ensureNotExists (self, newPath) {
438+
// Verify whether the new path already exists
439+
return self.exists(host, newPath).then(
440+
// If it does, generate another one
441+
() => ensureNotExists(self, URI.joinPaths(containerURI,
442+
`${uuid.v1().split('-')[0]}-${fileName}`).toString()),
443+
// If not, we found an appropriate path
444+
() => newPath
445+
)
446+
}
447+
const relativePath = await ensureNotExists(this, URI.joinPaths(containerURI, fileName).toString())
448+
return this.resourceMapper.resolveRelativeFilePath(host, relativePath)
449+
}
450+
451+
oldGetAvailablePath (host, containerURI, { slug = uuid.v1(), extension }) {
436452
const path = slug + extension
437453
function ensureNotExists (self, newPath) {
438454
// Verify whether the new path already exists

lib/resource-mapper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class ResourceMapper {
6262
: `${this._rootPath}/${hostname}${filePath}`
6363
}
6464

65+
resolveRelativeFilePath (hostname, filePath = '') {
66+
return !this._includeHost ? filePath : `/${hostname}${filePath}`
67+
}
68+
6569
// Maps a given server file to a URL
6670
async mapFileToUrl ({ path, hostname }) {
6771
// Remove the root path if specified

0 commit comments

Comments
 (0)