@@ -194,8 +194,7 @@ public function checkFileInfo($fileId, $access_token) {
194194 $ response ['UserPrivateInfo ' ]['ZoteroAPIKey ' ] = $ zoteroAPIKey ;
195195 }
196196 if ($ wopi ->hasTemplateId ()) {
197- $ templateUrl = 'index.php/apps/richdocuments/wopi/template/ ' . $ wopi ->getTemplateId () . '?access_token= ' . $ wopi ->getToken ();
198- $ templateUrl = $ this ->urlGenerator ->getAbsoluteURL ($ templateUrl );
197+ $ templateUrl = $ this ->getWopiUrlForTemplate ($ wopi );
199198 $ response ['TemplateSource ' ] = $ templateUrl ;
200199 } elseif ($ wopi ->isTemplateToken ()) {
201200 // FIXME: Remove backward compatibility layer once TemplateSource is available in all supported Collabora versions
@@ -283,7 +282,7 @@ private function setFederationFileInfo(Wopi $wopi, $response) {
283282 $ response ['TemplateSource ' ] = $ templateUrl ;
284283 }
285284 if ($ wopi ->getTokenType () === Wopi::TOKEN_TYPE_REMOTE_USER || ($ wopi ->getTokenType () === Wopi::TOKEN_TYPE_REMOTE_GUEST && $ initiator ->getEditorUid ())) {
286- $ response ['UserExtraInfo ' ]['avatar ' ] = $ wopi ->getRemoteServer () . '/index.php/avatar/ ' . $ initiator ->getEditorUid () . '/ ' . self ::WOPI_AVATAR_SIZE ;
285+ $ response ['UserExtraInfo ' ]['avatar ' ] = $ wopi ->getRemoteServer () . '/index.php/avatar/ ' . $ initiator ->getEditorUid () . '/ ' . self ::WOPI_AVATAR_SIZE ;
287286 }
288287
289288 return $ response ;
@@ -497,11 +496,7 @@ public function putFile($fileId,
497496 if ($ isPutRelative ) {
498497 // generate a token for the new file (the user still has to be logged in)
499498 $ wopi = $ this ->tokenManager ->generateWopiToken ((string )$ file ->getId (), null , $ wopi ->getEditorUid (), $ wopi ->getDirect ());
500-
501- $ wopiUrl = 'index.php/apps/richdocuments/wopi/files/ ' . $ file ->getId () . '_ ' . $ this ->config ->getSystemValue ('instanceid ' ) . '?access_token= ' . $ wopi ->getToken ();
502- $ wopiUrl = $ this ->urlGenerator ->getAbsoluteURL ($ wopiUrl );
503-
504- return new JSONResponse ([ 'Name ' => $ file ->getName (), 'Url ' => $ wopiUrl ], Http::STATUS_OK );
499+ return new JSONResponse (['Name ' => $ file ->getName (), 'Url ' => $ this ->getWopiUrlForFile ($ wopi , $ file )], Http::STATUS_OK );
505500 }
506501 if ($ wopi ->hasTemplateId ()) {
507502 $ wopi ->setTemplateId (null );
@@ -665,17 +660,14 @@ public function postFile(string $fileId, string $access_token): JSONResponse {
665660
666661 // epub is exception (can be uploaded but not opened so don't try to get access token)
667662 if ($ file ->getMimeType () == 'application/epub+zip ' ) {
668- return new JSONResponse ([ 'Name ' => $ file ->getName () ], Http::STATUS_OK );
663+ return new JSONResponse (['Name ' => $ file ->getName ()], Http::STATUS_OK );
669664 }
670665
671666 // generate a token for the new file (the user still has to be
672667 // logged in)
673668 $ wopi = $ this ->tokenManager ->generateWopiToken ((string )$ file ->getId (), null , $ wopi ->getEditorUid (), $ wopi ->getDirect ());
674669
675- $ wopiUrl = 'index.php/apps/richdocuments/wopi/files/ ' . $ file ->getId () . '_ ' . $ this ->config ->getSystemValue ('instanceid ' ) . '?access_token= ' . $ wopi ->getToken ();
676- $ wopiUrl = $ this ->urlGenerator ->getAbsoluteURL ($ wopiUrl );
677-
678- return new JSONResponse ([ 'Name ' => $ file ->getName (), 'Url ' => $ wopiUrl ], Http::STATUS_OK );
670+ return new JSONResponse (['Name ' => $ file ->getName (), 'Url ' => $ this ->getWopiUrlForFile ($ wopi , $ file )], Http::STATUS_OK );
679671 } catch (NotFoundException $ e ) {
680672 $ this ->logger ->warning ($ e ->getMessage (), ['exception ' => $ e ]);
681673 return new JSONResponse ([], Http::STATUS_NOT_FOUND );
@@ -706,6 +698,7 @@ private function lock(Wopi $wopi, string $lock): JSONResponse {
706698 return new JSONResponse ([], Http::STATUS_INTERNAL_SERVER_ERROR );
707699 }
708700 }
701+
709702 private function unlock (Wopi $ wopi , string $ lock ): JSONResponse {
710703 try {
711704 $ this ->lockManager ->unlock (new LockContext (
@@ -889,4 +882,12 @@ private function isMasterKeyEnabled(): bool {
889882 return false ;
890883 }
891884 }
885+
886+ private function getWopiUrlForFile (Wopi $ wopi , File $ file ): string {
887+ return $ this ->appConfig ->getNextcloudUrl () . '/index.php/apps/richdocuments/wopi/files/ ' . $ file ->getId () . '_ ' . $ this ->config ->getSystemValue ('instanceid ' ) . '?access_token= ' . $ wopi ->getToken ();
888+ }
889+
890+ private function getWopiUrlForTemplate (Wopi $ wopi ): string {
891+ return $ this ->appConfig ->getNextcloudUrl () . '/index.php/apps/richdocuments/wopi/template/ ' . $ wopi ->getTemplateId () . '?access_token= ' . $ wopi ->getToken ();
892+ }
892893}
0 commit comments