22"use strict" ;
33
44var mime = require ( 'mime' ) ;
5- var fs = require ( 'fs' ) ;
6- var mkdirp = require ( 'fs-extra' ) . mkdirp ;
75var path = require ( 'path' ) ;
86var $rdf = require ( 'rdflib' ) ;
97
@@ -12,37 +10,31 @@ var file = require('../fileStore.js');
1210var header = require ( '../header.js' ) ;
1311
1412function handler ( req , res ) {
15- var options = req . app . locals . ldp ;
13+ var ldp = req . app . locals . ldp ;
1614 debug ( "PUT -- Request path: " + req . originalUrl ) ;
1715 debug ( "PUT -- Text length: " + ( req . text ? req . text . length : 'undefined' ) ) ;
1816 res . header ( 'MS-Author-Via' , 'SPARQL' ) ;
1917
20- var filePath = file . uriToFilename ( req . path , options . root ) ;
18+ var filePath = file . uriToFilename ( req . path , ldp . root ) ;
2119
2220 // PUT requests not supported on containers. Use POST instead
2321 if ( filePath [ filePath . length - 1 ] === '/' ) {
24- return res . status ( 409 )
22+ return res
23+ . status ( 409 )
2524 . send ( "PUT to containers not supported. Use POST method instead" ) ;
2625 }
2726
28- writeFile ( filePath , req . text , function ( err ) {
27+ ldp . writeFile ( filePath , req . text , function ( err ) {
2928 if ( err ) {
3029 debug ( "PUT -- Write error: " + err ) ;
31- return res . status ( 500 ) . send ( "Can't write file: " + err ) ;
30+ return res
31+ . status ( 500 )
32+ . send ( "Can't write file: " + err ) ;
3233 }
34+
3335 debug ( "PUT -- Write Ok. Bytes written: " + req . text . length ) ;
3436 return res . sendStatus ( 201 ) ;
3537 } ) ;
3638}
3739
38- function writeFile ( filePath , contents , cb ) {
39- mkdirp ( path . dirname ( filePath ) , function ( err ) {
40- if ( err ) {
41- debug ( "PUT -- Error creating directory: " + err ) ;
42- return cb ( err ) ;
43- }
44- fs . writeFile ( filePath , contents , cb ) ;
45- } ) ;
46- }
47-
4840exports . handler = handler ;
0 commit comments