Skip to content

Commit 40fad16

Browse files
committed
fix: Use wopi callback url for all urls handed over to Collabora
Signed-off-by: Julius Härtl <[email protected]>
1 parent 77efd63 commit 40fad16

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/Controller/WopiController.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/helpers/url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const getCallbackBaseUrl = () => {
3838
}
3939

4040
const getWopiSrc = (fileId) => {
41-
// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
41+
// WOPISrc - URL that Collabora will use to access Nextcloud
4242
// index.php is forced here to avoid different wopi srcs for the same document
4343
const wopiurl = getCallbackBaseUrl() + '/index.php/apps/richdocuments/wopi/files/' + fileId
4444
console.debug('[getWopiUrl] ' + wopiurl)

0 commit comments

Comments
 (0)