@@ -177,23 +177,34 @@ function writeGraph (graph, resource, root, serverUri) {
177177 debug ( 'PATCH -- Writing patched file' )
178178 return new Promise ( ( resolve , reject ) => {
179179 const resourceSym = graph . sym ( resource . url )
180- const serialized = $rdf . serialize ( resourceSym , graph , resource . url , resource . contentType )
181180
182- // First check if we are above quota
183- overQuota ( root , serverUri ) . then ( ( isOverQuota ) => {
184- if ( isOverQuota ) {
185- return reject ( error ( 413 ,
186- 'User has exceeded their storage quota' ) )
187- }
188-
189- fs . writeFile ( resource . path , serialized , { encoding : 'utf8' } , function ( err ) {
190- if ( err ) {
191- return reject ( error ( 500 , `Failed to write file after patch: ${ err } ` ) )
181+ function doWrite ( serialized ) {
182+ // First check if we are above quota
183+ overQuota ( root , serverUri ) . then ( ( isOverQuota ) => {
184+ if ( isOverQuota ) {
185+ return reject ( error ( 413 ,
186+ 'User has exceeded their storage quota' ) )
192187 }
193- debug ( 'PATCH -- applied successfully' )
194- resolve ( 'Patch applied successfully.\n' )
188+
189+ fs . writeFile ( resource . path , serialized , { encoding : 'utf8' } , function ( err ) {
190+ if ( err ) {
191+ return reject ( error ( 500 , `Failed to write file after patch: ${ err } ` ) )
192+ }
193+ debug ( 'PATCH -- applied successfully' )
194+ resolve ( 'Patch applied successfully.\n' )
195+ } )
196+ } ) . catch ( ( ) => reject ( error ( 500 , 'Error finding user quota' ) ) )
197+ }
198+
199+ if ( resource . contentType === 'application/ld+json' ) {
200+ $rdf . serialize ( resourceSym , graph , resource . url , resource . contentType , function ( err , result ) {
201+ if ( err ) return reject ( error ( 500 , `Failed to serialize after patch: ${ err } ` ) )
202+ doWrite ( result )
195203 } )
196- } ) . catch ( ( ) => reject ( error ( 500 , 'Error finding user quota' ) ) )
204+ } else {
205+ const serialized = $rdf . serialize ( resourceSym , graph , resource . url , resource . contentType )
206+ doWrite ( serialized )
207+ }
197208 } )
198209}
199210
0 commit comments