Skip to content

Commit

Permalink
fix: Use wopi callback url for all urls handed over to Collabora
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Apr 12, 2024
1 parent 77efd63 commit 2f82662
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ public function checkFileInfo($fileId, $access_token) {
$response['UserPrivateInfo']['ZoteroAPIKey'] = $zoteroAPIKey;
}
if ($wopi->hasTemplateId()) {
$templateUrl = 'index.php/apps/richdocuments/wopi/template/' . $wopi->getTemplateId() . '?access_token=' . $wopi->getToken();
$templateUrl = $this->urlGenerator->getAbsoluteURL($templateUrl);
$response['TemplateSource'] = $templateUrl;
$response['TemplateSource'] = $this->getWopiUrlForTemplate($wopi);
} elseif ($wopi->isTemplateToken()) {
// FIXME: Remove backward compatibility layer once TemplateSource is available in all supported Collabora versions
$userFolder = $this->rootFolder->getUserFolder($wopi->getOwnerUid());
Expand Down Expand Up @@ -283,7 +281,7 @@ private function setFederationFileInfo(Wopi $wopi, $response) {
$response['TemplateSource'] = $templateUrl;
}
if ($wopi->getTokenType() === Wopi::TOKEN_TYPE_REMOTE_USER || ($wopi->getTokenType() === Wopi::TOKEN_TYPE_REMOTE_GUEST && $initiator->getEditorUid())) {
$response['UserExtraInfo']['avatar'] = $wopi->getRemoteServer() . '/index.php/avatar/' . $initiator->getEditorUid() . '/'. self::WOPI_AVATAR_SIZE;
$response['UserExtraInfo']['avatar'] = $wopi->getRemoteServer() . '/index.php/avatar/' . $initiator->getEditorUid() . '/' . self::WOPI_AVATAR_SIZE;
}

return $response;
Expand Down Expand Up @@ -497,11 +495,7 @@ public function putFile($fileId,
if ($isPutRelative) {
// generate a token for the new file (the user still has to be logged in)
$wopi = $this->tokenManager->generateWopiToken((string)$file->getId(), null, $wopi->getEditorUid(), $wopi->getDirect());

$wopiUrl = 'index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopi->getToken();
$wopiUrl = $this->urlGenerator->getAbsoluteURL($wopiUrl);

return new JSONResponse([ 'Name' => $file->getName(), 'Url' => $wopiUrl ], Http::STATUS_OK);
return new JSONResponse(['Name' => $file->getName(), 'Url' => $this->getWopiUrlForFile($wopi, $file)], Http::STATUS_OK);
}
if ($wopi->hasTemplateId()) {
$wopi->setTemplateId(null);
Expand Down Expand Up @@ -665,17 +659,14 @@ public function postFile(string $fileId, string $access_token): JSONResponse {

// epub is exception (can be uploaded but not opened so don't try to get access token)
if ($file->getMimeType() == 'application/epub+zip') {
return new JSONResponse([ 'Name' => $file->getName() ], Http::STATUS_OK);
return new JSONResponse(['Name' => $file->getName()], Http::STATUS_OK);
}

// generate a token for the new file (the user still has to be
// logged in)
$wopi = $this->tokenManager->generateWopiToken((string)$file->getId(), null, $wopi->getEditorUid(), $wopi->getDirect());

$wopiUrl = 'index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopi->getToken();
$wopiUrl = $this->urlGenerator->getAbsoluteURL($wopiUrl);

return new JSONResponse([ 'Name' => $file->getName(), 'Url' => $wopiUrl ], Http::STATUS_OK);
return new JSONResponse(['Name' => $file->getName(), 'Url' => $this->getWopiUrlForFile($wopi, $file)], Http::STATUS_OK);
} catch (NotFoundException $e) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
return new JSONResponse([], Http::STATUS_NOT_FOUND);
Expand Down Expand Up @@ -706,6 +697,7 @@ private function lock(Wopi $wopi, string $lock): JSONResponse {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}

private function unlock(Wopi $wopi, string $lock): JSONResponse {
try {
$this->lockManager->unlock(new LockContext(
Expand Down Expand Up @@ -889,4 +881,12 @@ private function isMasterKeyEnabled(): bool {
return false;
}
}

private function getWopiUrlForFile(Wopi $wopi, File $file): string {
return $this->appConfig->getNextcloudUrl() . '/index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopi->getToken();
}

private function getWopiUrlForTemplate(Wopi $wopi): string {
return $this->appConfig->getNextcloudUrl() . '/index.php/apps/richdocuments/wopi/template/' . $wopi->getTemplateId() . '?access_token=' . $wopi->getToken();
}
}
2 changes: 1 addition & 1 deletion src/helpers/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getCallbackBaseUrl = () => {
}

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

0 comments on commit 2f82662

Please sign in to comment.