Skip to content

Commit

Permalink
fix: set proper WOPI response and remove unnecessary WOPI callback fr…
Browse files Browse the repository at this point in the history
…om iframe

Signed-off-by: codewithvk <[email protected]>
  • Loading branch information
codewithvk committed Jan 23, 2025
1 parent 557305a commit c49acd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
27 changes: 11 additions & 16 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,7 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
try {
$wopi = $this->wopiMapper->getWopiForToken($access_token);

// TODO: condition for $wopi not found? -auth???
$userSettingsUri = $this->generateUserSettingsUri($wopi);

if ($fileId == '-1' && $wopi->getTokenType() == WOPI::TOKEN_TYPE_SETTING_AUTH) {
$response = [
'UserSettingsUri' => $userSettingsUri,
];

return new JSONResponse($response);
}

[$fileId, , $version] = Helper::parseFileId($fileId);

$file = $this->getFileForWopiToken($wopi);
if (!($file instanceof File)) {
throw new NotFoundException('No valid file found for ' . $fileId);
Expand All @@ -142,6 +129,9 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
$isSmartPickerEnabled = (bool)$wopi->getCanwrite() && !$isPublic && !$wopi->getDirect();
$isTaskProcessingEnabled = $isSmartPickerEnabled && $this->taskProcessingManager->isTaskProcessingEnabled();

$userSettings = $this->generateSettings($wopi, 'userconfig');
$sharedSettings = $this->generateSettings($wopi, 'systemconfig');

// If the file is locked manually by a user we want to open it read only for all others
$canWriteThroughLock = true;
try {
Expand Down Expand Up @@ -182,7 +172,8 @@ public function checkFileInfo(string $fileId, string $access_token): JSONRespons
'EnableRemoteAIContent' => $isTaskProcessingEnabled,
'HasContentRange' => true,
'ServerPrivateInfo' => [],
'UserSettingsUri' => $userSettingsUri,
'UserSettings' => $userSettings,
// 'SharedSettings' => $sharedSettings,
];

$enableZotero = $this->config->getAppValue(Application::APPNAME, 'zoteroEnabled', 'yes') === 'yes';
Expand Down Expand Up @@ -991,8 +982,12 @@ private function generateSettingToken(Wopi $wopi): string {
return $res['token'];
}
// todo extract nextcloud url from everything
private function generateUserSettingsUri(Wopi $wopi): string {
private function generateSettings(Wopi $wopi, string $type): array {
$nextcloudUrl = $this->appConfig->getNextcloudUrl() ?: trim($this->urlGenerator->getAbsoluteURL(''), '/');
return $nextcloudUrl . '/index.php/apps/richdocuments/wopi/settings' . '?type=userconfig' . '&access_token=' . $this->generateSettingToken($wopi) . '&fileId=' . '-1';
$uri = $nextcloudUrl . '/index.php/apps/richdocuments/wopi/settings' . '?type=' . $type . '&access_token=' . $this->generateSettingToken($wopi) . '&fileId=' . '-1';
return [
'uri' => $uri,
'stamp' => time()
];
}
}
6 changes: 1 addition & 5 deletions src/helpers/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,8 @@ const getNextcloudUrl = () => {
}

export const getCoolServerUrl = (collaboraBaseUrl) => {
// todo fix wopi Url
const wopiurl = getCallbackBaseUrl() + '/index.php/apps/richdocuments/wopi/files/-1'

return collaboraBaseUrl
+ '/browser/dist/admin/adminIntegratorSettings.html?'
+ 'WOPISrc=' + encodeURIComponent(wopiurl)
+ '/browser/dist/admin/adminIntegratorSettings.html'
}

export {
Expand Down

0 comments on commit c49acd5

Please sign in to comment.