@@ -182,7 +182,7 @@ public function showFile(string $fileid = null): Response {
182182 * @return TemplateResponse|RedirectResponse
183183 * @throws NotFoundException
184184 */
185- public function index ($ dir = '' , $ view = '' , $ fileid = null , $ fileNotFound = false ) {
185+ public function index ($ dir = '' , $ view = '' , $ fileid = null , $ fileNotFound = false , $ openfile = null ) {
186186 if ($ fileid !== null ) {
187187 try {
188188 return $ this ->redirectToFile ($ fileid );
@@ -331,9 +331,61 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
331331 $ policy ->addAllowedFrameDomain ('\'self \'' );
332332 $ response ->setContentSecurityPolicy ($ policy );
333333
334+ $ this ->provideInitialState ($ dir , $ openfile );
335+
334336 return $ response ;
335337 }
336338
339+ /**
340+ * Add openFileInfo in initialState if $openfile is set.
341+ * @param string $dir - the ?dir= URL param
342+ * @param string $openfile - the ?openfile= URL param
343+ * @return void
344+ */
345+ private function provideInitialState ($ dir , $ openfile ) {
346+ if ($ openfile === null ) {
347+ return ;
348+ }
349+
350+ $ user = $ this ->userSession ->getUser ();
351+
352+ if ($ user === null ) {
353+ return ;
354+ }
355+
356+ $ uid = $ user ->getUID ();
357+ $ userFolder = $ this ->rootFolder ->getUserFolder ($ uid );
358+ $ nodes = $ userFolder ->getById ((int ) $ openfile );
359+ $ node = array_shift ($ nodes );
360+
361+ if ($ node === null ) {
362+ return ;
363+ }
364+
365+ // properly format full path and make sure
366+ // we're relative to the user home folder
367+ $ isRoot = $ node === $ userFolder ;
368+ $ path = $ userFolder ->getRelativePath ($ node ->getPath ());
369+ $ directory = $ userFolder ->getRelativePath ($ node ->getParent ()->getPath ());
370+
371+ // Prevent opening a file from another folder.
372+ if ($ dir !== $ directory ) {
373+ return ;
374+ }
375+
376+ $ this ->initialState ->provideInitialState (
377+ 'openFileInfo ' , [
378+ 'id ' => $ node ->getId (),
379+ 'name ' => $ isRoot ? '' : $ node ->getName (),
380+ 'path ' => $ path ,
381+ 'directory ' => $ directory ,
382+ 'mime ' => $ node ->getMimetype (),
383+ 'type ' => $ node ->getType (),
384+ 'permissions ' => $ node ->getPermissions (),
385+ ]
386+ );
387+ }
388+
337389 /**
338390 * Redirects to the file list and highlight the given file id
339391 *
0 commit comments