File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -16,14 +16,24 @@ const PATCH_PARSERS = {
1616 'text/n3' : require ( './patch/n3-patch-parser.js' )
1717}
1818
19+ const DEFAULT_CONTENT_TYPE = 'text/turtle'
20+
1921// Handles a PATCH request
2022async function patchHandler ( req , res , next ) {
2123 debug ( `PATCH -- ${ req . originalUrl } ` )
2224 res . header ( 'MS-Author-Via' , 'SPARQL' )
2325 try {
2426 // Obtain details of the target resource
2527 const ldp = req . app . locals . ldp
26- const { path, contentType } = await ldp . resourceMapper . mapUrlToFile ( { url : req } )
28+ let path , contentType ;
29+ try {
30+ // First check if the file already exists
31+ ( { path, contentType } = await ldp . resourceMapper . mapUrlToFile ( { url : req } ) )
32+ } catch ( err ) {
33+ // If the file doesn't exist, request one to be created with the default content type
34+ ( { path, contentType } = await ldp . resourceMapper . mapUrlToFile (
35+ { url : req , createIfNotExists : true , contentType : DEFAULT_CONTENT_TYPE } ) )
36+ }
2737 const { url } = await ldp . resourceMapper . mapFileToUrl ( { path, hostname : req . hostname } )
2838 const resource = { path, contentType, url }
2939 debug ( 'PATCH -- Target <%s> (%s)' , url , contentType )
You can’t perform that action at this time.
0 commit comments