@@ -163,39 +163,35 @@ class LDP {
163163 }
164164 }
165165
166- post ( host , containerPath , stream , { container, slug, extension } , callback ) {
166+ async post ( host , containerPath , stream , { container, slug, extension } ) {
167167 const ldp = this
168168 debug . handlers ( 'POST -- On parent: ' + containerPath )
169169 // prepare slug
170170 if ( slug ) {
171171 slug = decodeURIComponent ( slug )
172172 if ( slug . match ( / \/ | \| | : / ) ) {
173- callback ( error ( 400 , 'The name of new file POSTed may not contain : | or /' ) )
174- return
173+ throw error ( 400 , 'The name of new file POSTed may not contain : | or /' )
175174 }
176175 }
177176 // Containers should not receive an extension
178177 if ( container ) {
179178 extension = ''
180179 }
181180 // TODO: possibly package this in ldp.post
182- ldp . getAvailablePath ( host , containerPath , { slug, extension } )
183- . then ( async resourcePath => {
184- debug . handlers ( 'POST -- Will create at: ' + resourcePath )
185- let originalPath = resourcePath
186- if ( container ) {
187- // Create directory by an LDP PUT to the container's .meta resource
188- resourcePath = path . join ( originalPath , ldp . suffixMeta )
189- if ( originalPath && ! originalPath . endsWith ( '/' ) ) {
190- originalPath += '/'
191- }
192- }
193- const { url : putUrl } = await this . resourceMapper . mapFileToUrl (
194- { path : this . resourceMapper . _rootPath + resourcePath , hostname : host } )
195- await ldp . put ( putUrl , stream )
196- callback ( null , originalPath )
197- } )
198- . catch ( ( err ) => callback ( err ) )
181+ let resourcePath = await ldp . getAvailablePath ( host , containerPath , { slug, extension } )
182+ debug . handlers ( 'POST -- Will create at: ' + resourcePath )
183+ let originalPath = resourcePath
184+ if ( container ) {
185+ // Create directory by an LDP PUT to the container's .meta resource
186+ resourcePath = path . join ( originalPath , ldp . suffixMeta )
187+ if ( originalPath && ! originalPath . endsWith ( '/' ) ) {
188+ originalPath += '/'
189+ }
190+ }
191+ const { url : putUrl } = await this . resourceMapper . mapFileToUrl (
192+ { path : this . resourceMapper . _rootPath + resourcePath , hostname : host } )
193+ await ldp . put ( putUrl , stream )
194+ return originalPath
199195 }
200196
201197 /**
0 commit comments