@@ -129,7 +129,7 @@ class LDP {
129
129
}
130
130
}
131
131
132
- async post ( host , containerPath , stream , { container, slug, extension } ) {
132
+ async post ( hostname , containerPath , stream , { container, slug, extension, contentType } ) {
133
133
const ldp = this
134
134
debug . handlers ( 'POST -- On parent: ' + containerPath )
135
135
// prepare slug
@@ -144,26 +144,26 @@ class LDP {
144
144
extension = ''
145
145
}
146
146
// TODO: possibly package this in ldp.post
147
- let resourcePath = await ldp . getAvailablePath ( host , containerPath , { slug, extension } )
148
- debug . handlers ( 'POST -- Will create at: ' + resourcePath )
149
- let originalPath = resourcePath
147
+ let resourceUrl = await ldp . getAvailableUrl ( hostname , containerPath , { slug, extension } )
148
+ debug . handlers ( 'POST -- Will create at: ' + resourceUrl )
149
+ let originalUrl = resourceUrl
150
150
if ( container ) {
151
151
// Create directory by an LDP PUT to the container's .meta resource
152
- resourcePath = join ( originalPath , ldp . suffixMeta )
153
- if ( originalPath && ! originalPath . endsWith ( '/' ) ) {
154
- originalPath += '/'
152
+ resourceUrl = ` ${ resourceUrl } ${ resourceUrl . endsWith ( '/' ) ? '' : '/' } ${ ldp . suffixMeta } `
153
+ if ( originalUrl && ! originalUrl . endsWith ( '/' ) ) {
154
+ originalUrl += '/'
155
155
}
156
156
}
157
- const { url : putUrl , contentType } = await this . resourceMapper . mapFileToUrl ( { path : resourcePath , hostname : host } )
157
+ // const { url: putUrl } = await this.resourceMapper.mapFileToUrl({ path: resourceUrl , hostname })
158
158
159
159
// HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data
160
160
// for JSON bodies. So, the stream needs to be reset
161
161
if ( contentType . includes ( 'application/json' ) ) {
162
162
stream = intoStream ( JSON . stringify ( stream . body ) )
163
163
}
164
164
165
- await ldp . put ( putUrl , stream , contentType )
166
- return originalPath
165
+ await ldp . put ( resourceUrl , stream , contentType )
166
+ return URL . parse ( originalUrl ) . path
167
167
}
168
168
169
169
/**
@@ -432,11 +432,11 @@ class LDP {
432
432
}
433
433
}
434
434
435
- async getAvailablePath ( host , containerURI , { slug = uuid . v1 ( ) , extension } ) {
435
+ async getAvailableUrl ( hostname , containerURI , { slug = uuid . v1 ( ) , extension } ) {
436
436
const fileName = slug + extension
437
437
function ensureNotExists ( self , newPath ) {
438
438
// Verify whether the new path already exists
439
- return self . exists ( host , newPath ) . then (
439
+ return self . exists ( hostname , newPath ) . then (
440
440
// If it does, generate another one
441
441
( ) => ensureNotExists ( self , URI . joinPaths ( containerURI ,
442
442
`${ uuid . v1 ( ) . split ( '-' ) [ 0 ] } -${ fileName } ` ) . toString ( ) ) ,
@@ -445,7 +445,7 @@ class LDP {
445
445
)
446
446
}
447
447
const relativePath = await ensureNotExists ( this , URI . joinPaths ( containerURI , fileName ) . toString ( ) )
448
- return this . resourceMapper . resolveRelativeFilePath ( host , relativePath )
448
+ return this . resourceMapper . resolveUrl ( hostname , relativePath )
449
449
}
450
450
451
451
getTrustedOrigins ( req ) {
0 commit comments