Skip to content

Commit

Permalink
fix: Allow configuring the wopi_callback_url
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Apr 10, 2024
1 parent 6ce8afc commit e2ff3b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/Service/InitialStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function provideCapabilities(): void {
$this->initialState->provideInitialState('hasDrawSupport', $this->capabilitiesService->hasDrawSupport());
$this->initialState->provideInitialState('hasNextcloudBranding', $this->capabilitiesService->hasNextcloudBranding());
$this->initialState->provideInitialState('instanceId', $this->config->getSystemValue('instanceid'));
$this->initialState->provideInitialState('wopi_callback_url', $this->config->getAppValue(Application::APPNAME, 'wopi_callback_url', ''));

$this->provideOptions();

Expand Down Expand Up @@ -81,6 +82,7 @@ public function prepareParams(array $params): array {
'directGuest' => false,
'path' => '',
'urlsrc' => '',
'wopi_callback_url' => $this->config->getAppValue(Application::APPNAME, 'wopi_callback_url', ''),
'fileId' => '',
'title' => '',
'permissions' => '',
Expand Down
16 changes: 15 additions & 1 deletion src/helpers/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import { getRootUrl, generateUrl } from '@nextcloud/router'
import { languageToBCP47 } from './index.js'
import Config from './../services/config.tsx'
import { loadState } from '@nextcloud/initial-state'

const getSearchParam = (name) => {
const results = new RegExp('[?&]' + name + '=([^&#]*)').exec(window.location.href)
Expand All @@ -32,13 +33,26 @@ const getSearchParam = (name) => {
return decodeURI(results[1]) || ''
}

const getCallbackBaseUrl = () => {
const callbackUrl = Config.get('wopi_callback_url') || loadState('richdocuments', 'wopi_callback_url', '')
return callbackUrl || window.location.protocol + '//' + window.location.host + getRootUrl()
}

const getWopiSrc = (fileId) => {
// 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)
return wopiurl
}

const getWopiUrl = ({ fileId, title, readOnly, closeButton, revisionHistory, target = undefined }) => {
// Only set the revision history parameter if the versions app is enabled
revisionHistory = revisionHistory && window?.oc_appswebroots?.files_versions

// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
// index.php is forced here to avoid different wopi srcs for the same document
const wopiurl = window.location.protocol + '//' + window.location.host + getRootUrl() + '/index.php/apps/richdocuments/wopi/files/' + fileId
const wopiurl = getWopiSrc(fileId)
console.debug('[getWopiUrl] ' + wopiurl)
const wopisrc = encodeURIComponent(wopiurl)

Expand Down

0 comments on commit e2ff3b7

Please sign in to comment.