@@ -4,11 +4,14 @@ var mime = require('mime-types')
44var debug = require ( '../debug' ) . handlers
55var utils = require ( '../utils.js' )
66var error = require ( '../http-error' )
7- const sparqlPatch = require ( './patch/sparql-patcher.js' )
8- const sparqlUpdatePatch = require ( './patch/sparql-update-patcher.js' )
97
108const DEFAULT_CONTENT_TYPE = 'text/turtle'
119
10+ const PATCHERS = {
11+ 'application/sparql' : require ( './patch/sparql-patcher.js' ) ,
12+ 'application/sparql-update' : require ( './patch/sparql-update-patcher.js' )
13+ }
14+
1215function handler ( req , res , next ) {
1316 req . setEncoding ( 'utf8' )
1417 req . text = ''
@@ -37,26 +40,16 @@ function patchHandler (req, res, next) {
3740
3841 debug ( 'PATCH -- Content-type ' + patchContentType + ' patching target ' + targetContentType + ' <' + targetURI + '>' )
3942
40- if ( patchContentType === 'application/sparql' ) {
41- sparqlPatch ( filename , targetURI , req . text , function ( err , result ) {
42- if ( err ) {
43- return next ( err )
44- }
45- res . json ( result )
46- return next ( )
47- } )
48- } else if ( patchContentType === 'application/sparql-update' ) {
49- return sparqlUpdatePatch ( filename , targetURI , req . text , function ( err , patchKB ) {
50- if ( err ) {
51- return next ( err )
52- }
53-
54- // subscription.publishDelta(req, res, patchKB, targetURI)
55- debug ( 'PATCH -- applied OK (sync)' )
56- res . send ( 'Patch applied OK\n' )
57- return next ( )
58- } )
59- } else {
43+ const patch = PATCHERS [ patchContentType ]
44+ if ( ! patch ) {
6045 return next ( error ( 400 , 'Unknown patch content type: ' + patchContentType ) )
6146 }
62- } // postOrPatch
47+ patch ( filename , targetURI , req . text , function ( err , result ) {
48+ if ( err ) {
49+ next ( err )
50+ } else {
51+ res . send ( result )
52+ next ( )
53+ }
54+ } )
55+ }
0 commit comments