Skip to content

Commit

Permalink
chore: refactor iframes to load collabora directly
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Aug 31, 2023
1 parent 4f6adcf commit 1b274c7
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 162 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
['name' => 'document#remote', 'url' => 'remote', 'verb' => 'GET'],
['name' => 'document#createFromTemplate', 'url' => 'indexTemplate', 'verb' => 'GET'],
['name' => 'document#publicPage', 'url' => '/public', 'verb' => 'GET'],
['name' => 'document#token', 'url' => '/token', 'verb' => 'POST'],

['name' => 'document#editOnline', 'url' => 'editonline', 'verb' => 'GET'],
['name' => 'document#editOnlineTarget', 'url' => 'editonline/{fileId}/{target}', 'verb' => 'GET'],
Expand Down
17 changes: 15 additions & 2 deletions lib/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function extAppGetData(int $fileId) {
* @param string|null $path
* @return RedirectResponse|TemplateResponse
*/
public function index($fileId, ?string $path = null) {
public function index($fileId, ?string $path = null, ?int $version = null) {
try {
$folder = $this->rootFolder->getUserFolder($this->uid);

Expand Down Expand Up @@ -184,7 +184,7 @@ public function index($fileId, ?string $path = null) {
$params = [
'permissions' => $item->getPermissions(),
'title' => $item->getName(),
'fileId' => $item->getId() . '_' . $this->config->getSystemValue('instanceid'),
'fileId' => $item->getId() . '_' . $this->config->getSystemValue('instanceid') . ($version !== null ? '_' . $version : ''),
'token' => $token,
'token_ttl' => $wopi->getExpiry(),
'urlsrc' => $urlSrc,
Expand Down Expand Up @@ -489,4 +489,17 @@ public function editOnlineTarget(int $fileId, ?string $target = null) {

return $this->renderErrorPage('File not found', Http::STATUS_NOT_FOUND);
}



#[Http\Attribute\NoAdminRequired]

Check failure on line 495 in lib/Controller/DocumentController.php

View workflow job for this annotation

GitHub Actions / Nextcloud

UndefinedAttributeClass

lib/Controller/DocumentController.php:495:4: UndefinedAttributeClass: Attribute class OCP\AppFramework\Http\Attribute\NoAdminRequired does not exist (see https://psalm.dev/241)
#[Http\Attribute\NoCSRFRequired]

Check failure on line 496 in lib/Controller/DocumentController.php

View workflow job for this annotation

GitHub Actions / Nextcloud

UndefinedAttributeClass

lib/Controller/DocumentController.php:496:4: UndefinedAttributeClass: Attribute class OCP\AppFramework\Http\Attribute\NoCSRFRequired does not exist (see https://psalm.dev/241)
public function token(int $fileId, ?string $shareToken = null) {
[$urlSrc, $token, $wopi] = $this->tokenManager->getToken((string)$fileId, $shareToken, $this->uid, false);

return new Http\DataResponse([
'urlSrc' => $urlSrc,
...$wopi->jsonSerialize(),

Check failure on line 502 in lib/Controller/DocumentController.php

View workflow job for this annotation

GitHub Actions / Nextcloud

InvalidOperand

lib/Controller/DocumentController.php:502:7: InvalidOperand: Cannot use spread operator on non-iterable type mixed (see https://psalm.dev/058)
]);
}
}
2 changes: 0 additions & 2 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ const odfViewer = {
$iframe.addClass('full')
$('#content').addClass('full-height')
$('footer').addClass('hidden')
$('#imgframe').addClass('hidden')
$('#controls').addClass('hidden')
$('#content').addClass('loading')
} else {
Expand Down Expand Up @@ -162,7 +161,6 @@ const odfViewer = {
if (isPublic) {
$('#content').removeClass('full-height')
$('footer').removeClass('hidden')
$('#imgframe').removeClass('hidden')
$('.directLink').removeClass('hidden')
$('.directDownload').removeClass('hidden')
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/coolParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const getUIDefaults = () => {
}

const getCollaboraTheme = () => {
return loadState('richdocuments', 'theme', '')
return loadState('richdocuments', 'theme', 'nextcloud')
}

const generateCSSVarTokens = () => {
Expand Down
9 changes: 9 additions & 0 deletions src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,17 @@ const splitPath = (path) => {
return [directory, fileName]
}

const getRandomId = (length = 5) => {
return Math.random()
.toString(36)
.replace(/[^a-z]+/g, '')
.slice(0, length || 5)

}

export {
languageToBCP47,
getNextcloudVersion,
splitPath,
getRandomId,
}
40 changes: 40 additions & 0 deletions src/services/LoggedInPostMessageHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import PostMessageHandler from './PostMessageHandler.js'

export default class LoggedInPostMessageHandler extends PostMessageHandler {

#context = null

constructor(context) {
super()
this.#context = context
}

Frame_Ready() {}
App_LoadingStatus() {}
Action_Load_Resp() {}
Clicked_Button() {}
UI_Share() {
this.#context.share()
}

UI_Mention() {}
UI_Close() {}
UI_SaveAs() {}
Download_As() {}
Views_List() {}
Get_Views_Resp() {}
UI_ZoteroKeyMissing() {}
Action_loadRevViewer() {}
Action_Save_Resp() {}
File_Rename() {}
Action_GetLinkPreview() {}
UI_InsertGraphic() {}
UI_CreateFile() {}
UI_Paste() {}
UI_Hyperlink() {}
UI_FileVersions() {}
UI_PickLink() {}
App_VersionRestore() {}
Host_VersionRestore() {}

}
35 changes: 35 additions & 0 deletions src/services/PostMessageHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

export default class PostMessageHandler {

#context = null

constructor(context) {
this.#context = context
}

Frame_Ready() {}
App_LoadingStatus() {}
Action_Load_Resp() {}
Clicked_Button() {}
UI_Share() {}
UI_Mention() {}
UI_Close() {}
UI_SaveAs() {}
Download_As() {}
Views_List() {}
Get_Views_Resp() {}
UI_ZoteroKeyMissing() {}
Action_loadRevViewer() {}
Action_Save_Resp() {}
File_Rename() {}
Action_GetLinkPreview() {}
UI_InsertGraphic() {}
UI_CreateFile() {}
UI_Paste() {}
UI_Hyperlink() {}
UI_FileVersions() {}
UI_PickLink() {}
App_VersionRestore() {}
Host_VersionRestore() {}

}
Loading

0 comments on commit 1b274c7

Please sign in to comment.