2323
2424namespace OCA \DAV \BulkUpload ;
2525
26+ use Exception ;
2627use Psr \Log \LoggerInterface ;
28+ use Sabre \DAV \Exception \Forbidden ;
2729use Sabre \DAV \Server ;
2830use Sabre \DAV \ServerPlugin ;
2931use Sabre \HTTP \RequestInterface ;
@@ -37,6 +39,13 @@ class BulkUploadPlugin extends ServerPlugin {
3739 private Folder $ userFolder ;
3840 private LoggerInterface $ logger ;
3941
42+ /**
43+ * Reference to main server object
44+ *
45+ * @var Server
46+ */
47+ private $ server ;
48+
4049 public function __construct (
4150 Folder $ userFolder ,
4251 LoggerInterface $ logger
@@ -49,6 +58,7 @@ public function __construct(
4958 * Register listener on POST requests with the httpPost method.
5059 */
5160 public function initialize (Server $ server ): void {
61+ $ this ->server = $ server ;
5262 $ server ->on ('method:POST ' , [$ this , 'httpPost ' ], 10 );
5363 }
5464
@@ -89,6 +99,26 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
8999 $ mtime = null ;
90100 }
91101
102+ if ($ request ->getHeader ('OC-File-Type ' ) == 1 ) {
103+ // TODO: store default value in global location
104+ $ allowSymlinks = \OC ::$ server ->get (\OC \AllConfig::class)->getSystemValueBool (
105+ 'localstorage.allowsymlinks ' , false );
106+ if (!$ allowSymlinks ) {
107+ throw new Forbidden ("Server does not allow the creation of symlinks! " );
108+ }
109+ $ symlinkPath = $ headers ['x-file-path ' ];
110+ $ parentNode = $ this ->server ->tree ->getNodeForPath (dirname ($ symlinkPath ));
111+ if (!$ parentNode instanceof \OCA \DAV \Connector \Sabre \Directory) {
112+ throw new Exception ("Unable to upload ' $ symlinkPath' because the remote directory does not support symlink creation! " );
113+ }
114+ $ etag = $ parentNode ->createSymlink (basename ($ symlinkPath ), $ content );
115+ $ writtenFiles [$ headers ['x-file-path ' ]] = [
116+ "error " => false ,
117+ "etag " => $ etag ,
118+ ];
119+ continue ;
120+ }
121+
92122 $ node = $ this ->userFolder ->newFile ($ headers ['x-file-path ' ], $ content );
93123 $ node ->touch ($ mtime );
94124 $ node = $ this ->userFolder ->getById ($ node ->getId ())[0 ];
0 commit comments