From 84d455d19cacb5cf8ec4e3fc3ef94ad7ba7aff6c Mon Sep 17 00:00:00 2001 From: Hermes Date: Fri, 11 Sep 2026 12:19:56 +0000 Subject: [PATCH] Clean repo layout: patches/ + install.sh only --- DirectController.php | 58 ----------- HtmlDirectEditor.php | 88 ---------------- HtmlDirectEditorBridge.php | 44 -------- RegisterDirectEditorListener.php | 32 ------ TextDirectEditor-current.php | 171 ------------------------------- TextDirectEditor-orig.php | 164 ----------------------------- directEditing.php | 37 ------- patch_app.py | 26 ----- testde.php | 10 -- testde2.php | 9 -- 10 files changed, 639 deletions(-) delete mode 100644 DirectController.php delete mode 100644 HtmlDirectEditor.php delete mode 100644 HtmlDirectEditorBridge.php delete mode 100644 RegisterDirectEditorListener.php delete mode 100644 TextDirectEditor-current.php delete mode 100644 TextDirectEditor-orig.php delete mode 100644 directEditing.php delete mode 100644 patch_app.py delete mode 100644 testde.php delete mode 100644 testde2.php diff --git a/DirectController.php b/DirectController.php deleted file mode 100644 index 79337ec..0000000 --- a/DirectController.php +++ /dev/null @@ -1,58 +0,0 @@ -userSession->getUser(); - if ($user === null) { - return new NotFoundResponse(); - } - - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); - $nodes = $userFolder->getById($fileId); - if (empty($nodes)) { - return new NotFoundResponse(); - } - $file = array_shift($nodes); - if (!$file instanceof File) { - return new NotFoundResponse(); - } - - $response = new DataDisplayResponse($file->getContent()); - $response->addHeader('Content-Type', 'text/html; charset=utf-8'); - return $response; - } -} diff --git a/HtmlDirectEditor.php b/HtmlDirectEditor.php deleted file mode 100644 index bb178ea..0000000 --- a/HtmlDirectEditor.php +++ /dev/null @@ -1,88 +0,0 @@ -l10n->t('HTML Viewer'); - } - - #[\Override] - public function getMimetypes(): array { - return [ - 'text/html', - ]; - } - - #[\Override] - public function getMimetypesOptional(): array { - return []; - } - - #[\Override] - public function getCreators(): array { - return []; - } - - #[\Override] - public function isSecure(): bool { - return false; - } - - #[\Override] - public function open(IToken $token): Response { - $token->useTokenScope(); - - try { - $file = $token->getFile(); - - return new TemplateResponse( - Application::APP_ID, - 'directEditing', - [ - 'fileId' => $file->getId(), - 'fileName' => $file->getName(), - 'fileContent' => $file->getContent(), - ], - 'base' - ); - } catch (InvalidPathException|NotFoundException) { - return new NotFoundResponse(); - } - } -} diff --git a/HtmlDirectEditorBridge.php b/HtmlDirectEditorBridge.php deleted file mode 100644 index bd01563..0000000 --- a/HtmlDirectEditorBridge.php +++ /dev/null @@ -1,44 +0,0 @@ -getFile(); - - return new TemplateResponse( - Application::APP_ID, - 'directEditing', - [ - 'fileId' => $file->getId(), - 'fileName' => $file->getName(), - 'fileContent' => $file->getContent(), - ], - 'base' - ); - } catch (\Throwable) { - return new NotFoundResponse(); - } - } -} \ No newline at end of file diff --git a/RegisterDirectEditorListener.php b/RegisterDirectEditorListener.php deleted file mode 100644 index fca33f4..0000000 --- a/RegisterDirectEditorListener.php +++ /dev/null @@ -1,32 +0,0 @@ - */ -final class RegisterDirectEditorListener implements IEventListener { - - public function __construct( - private HtmlDirectEditor $editor, - ) { - } - - #[\Override] - public function handle(Event $event): void { - if (!$event instanceof RegisterDirectEditorEvent) { - return; - } - $event->register($this->editor); - } -} diff --git a/TextDirectEditor-current.php b/TextDirectEditor-current.php deleted file mode 100644 index 13f3438..0000000 --- a/TextDirectEditor-current.php +++ /dev/null @@ -1,171 +0,0 @@ -l10n = $l10n; - $this->initialStateProvider = $initialStateProvider; - $this->apiService = $apiService; - $this->appConfig = $appConfig; - } - - /** - * Return a unique identifier for the editor - * - * e.g. richdocuments - * - * @return string - */ - public function getId(): string { - return Application::APP_NAME; - } - - /** - * Return a readable name for the editor - * - * e.g. Collabora Online - * - * @return string - */ - public function getName(): string { - return $this->l10n->t('Nextcloud Text'); - } - - /** - * A list of mimetypes that should open the editor by default - * - * @return string[] - */ - public function getMimetypes(): array { - return [ - 'text/markdown', - 'text/plain', - 'application/cmd', - 'application/x-empty', - 'application/x-msdos-program', - 'application/javascript', - 'application/json', - 'application/x-perl', - 'application/x-php', - 'application/x-tex', - 'application/xml', - 'application/yaml', - 'text/css', - 'text/csv', - - 'text/org', - 'text/x-c', - 'text/x-c++src', - 'text/x-h', - 'text/x-java-source', - 'text/x-ldif', - 'text/x-nfo', - 'text/x-python', - 'text/x-shellscript', - ]; - } - - /** - * A list of mimetypes that can be opened in the editor optionally - * - * @return string[] - */ - public function getMimetypesOptional(): array { - return []; - } - - /** - * Return a list of file creation options to be presented to the user - * - * @return TextDocumentCreator[] - */ - public function getCreators(): array { - return [ - new TextDocumentCreator($this->l10n, $this->appConfig), - ]; - } - - /** - * Return if the view is able to securely view a file without downloading it to the browser - * - * @return bool - */ - public function isSecure(): bool { - return false; - } - - /** - * Return a template response for displaying the editor - * - * open can only be called once when the client requests the editor with a one-time-use token - * For handling editing and later requests, editors need to impelement their own token handling and take care of invalidation - * - * This behavior is similar to the current direct editing implementation in collabora where we generate a one-time token and switch over to the regular wopi token for the actual editing/saving process - * - * @param IToken $token - * @return Response - */ - public function open(IToken $token): Response { - $token->useTokenScope(); - try { - // HTML patch (Hermes Agent 2026-09): route text/html to the - // htmlviewer sandbox template, because the iOS/Android apps - // only know the hard-coded editor id "text" and would - // otherwise show HTML source in QuickLook. - if ($token->getFile()->getMimeType() === 'text/html') { - return \OCA\HtmlViewer\DirectEditing\HtmlDirectEditorBridge::openHtml($token); - } - $session = $this->apiService->create($token->getFile()->getId()); - $this->initialStateProvider->provideFile([ - 'fileId' => $token->getFile()->getId(), - 'mimetype' => $token->getFile()->getMimeType(), - 'session' => \json_encode($session->getData()) - ]); - $this->initialStateProvider->provideDirectEditToken($token->getToken()); - $this->initialStateProvider->provideState(); - Util::addScript('text', 'text-text'); - Util::addStyle('text', 'text-text'); - return new TemplateResponse('text', 'main', [], 'base'); - } catch (InvalidPathException $e) { - } catch (NotFoundException $e) { - } catch (NotPermittedException $e) { - } - return new NotFoundResponse(); - } -} diff --git a/TextDirectEditor-orig.php b/TextDirectEditor-orig.php deleted file mode 100644 index 3c62ee2..0000000 --- a/TextDirectEditor-orig.php +++ /dev/null @@ -1,164 +0,0 @@ -l10n = $l10n; - $this->initialStateProvider = $initialStateProvider; - $this->apiService = $apiService; - $this->appConfig = $appConfig; - } - - /** - * Return a unique identifier for the editor - * - * e.g. richdocuments - * - * @return string - */ - public function getId(): string { - return Application::APP_NAME; - } - - /** - * Return a readable name for the editor - * - * e.g. Collabora Online - * - * @return string - */ - public function getName(): string { - return $this->l10n->t('Nextcloud Text'); - } - - /** - * A list of mimetypes that should open the editor by default - * - * @return string[] - */ - public function getMimetypes(): array { - return [ - 'text/markdown', - 'text/plain', - 'application/cmd', - 'application/x-empty', - 'application/x-msdos-program', - 'application/javascript', - 'application/json', - 'application/x-perl', - 'application/x-php', - 'application/x-tex', - 'application/xml', - 'application/yaml', - 'text/css', - 'text/csv', - 'text/html', - 'text/org', - 'text/x-c', - 'text/x-c++src', - 'text/x-h', - 'text/x-java-source', - 'text/x-ldif', - 'text/x-nfo', - 'text/x-python', - 'text/x-shellscript', - ]; - } - - /** - * A list of mimetypes that can be opened in the editor optionally - * - * @return string[] - */ - public function getMimetypesOptional(): array { - return []; - } - - /** - * Return a list of file creation options to be presented to the user - * - * @return TextDocumentCreator[] - */ - public function getCreators(): array { - return [ - new TextDocumentCreator($this->l10n, $this->appConfig), - ]; - } - - /** - * Return if the view is able to securely view a file without downloading it to the browser - * - * @return bool - */ - public function isSecure(): bool { - return false; - } - - /** - * Return a template response for displaying the editor - * - * open can only be called once when the client requests the editor with a one-time-use token - * For handling editing and later requests, editors need to impelement their own token handling and take care of invalidation - * - * This behavior is similar to the current direct editing implementation in collabora where we generate a one-time token and switch over to the regular wopi token for the actual editing/saving process - * - * @param IToken $token - * @return Response - */ - public function open(IToken $token): Response { - $token->useTokenScope(); - try { - $session = $this->apiService->create($token->getFile()->getId()); - $this->initialStateProvider->provideFile([ - 'fileId' => $token->getFile()->getId(), - 'mimetype' => $token->getFile()->getMimeType(), - 'session' => \json_encode($session->getData()) - ]); - $this->initialStateProvider->provideDirectEditToken($token->getToken()); - $this->initialStateProvider->provideState(); - Util::addScript('text', 'text-text'); - Util::addStyle('text', 'text-text'); - return new TemplateResponse('text', 'main', [], 'base'); - } catch (InvalidPathException $e) { - } catch (NotFoundException $e) { - } catch (NotPermittedException $e) { - } - return new NotFoundResponse(); - } -} diff --git a/directEditing.php b/directEditing.php deleted file mode 100644 index eb7b78b..0000000 --- a/directEditing.php +++ /dev/null @@ -1,37 +0,0 @@ - - - - \ No newline at end of file diff --git a/patch_app.py b/patch_app.py deleted file mode 100644 index f47358b..0000000 --- a/patch_app.py +++ /dev/null @@ -1,26 +0,0 @@ -import re -APP='/media/orange/RocketChat/nextcloud1/nextcloud_data/custom_apps/htmlviewer' - -p=APP+'/lib/AppInfo/Application.php' -c=open(p).read() -if 'RegisterDirectEditorListener' not in c: - c=c.replace( - 'use OCP\\Security\\CSP\\AddContentSecurityPolicyEvent;', - 'use OCP\\Security\\CSP\\AddContentSecurityPolicyEvent;\nuse OCA\\HtmlViewer\\Listener\\RegisterDirectEditorListener;\nuse OCP\\DirectEditing\\RegisterDirectEditorEvent;' - ) - c=c.replace( - " $context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class);", - " $context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class);\n $context->registerEventListener(RegisterDirectEditorEvent::class, RegisterDirectEditorListener::class);" - ) - open(p,'w').write(c) -print('Application.php patched:', 'RegisterDirectEditorEvent' in open(p).read()) - -p=APP+'/appinfo/routes.php' -c=open(p).read() -if 'Direct#content' not in c: - c=c.replace( - "['name' => 'settings#disableWarning', 'url' => '/settings/warning', 'verb' => 'GET'],", - "['name' => 'settings#disableWarning', 'url' => '/settings/warning', 'verb' => 'GET'],\n\t\t['name' => 'Direct#content', 'url' => '/direct/{fileId}', 'verb' => 'GET']," - ) - open(p,'w').write(c) -print('routes.php patched:', 'Direct#content' in open(p).read()) diff --git a/testde.php b/testde.php deleted file mode 100644 index 8ce3ded..0000000 --- a/testde.php +++ /dev/null @@ -1,10 +0,0 @@ -get(\OCP\DirectEditing\IManager::class); -echo "manager ok\n"; -$ev = new \OCP\DirectEditing\RegisterDirectEditorEvent($m); -\OC::server->get(\OCP\EventDispatcher\IEventDispatcher::class)->dispatchTyped($ev); -echo "dispatched\n"; -var_dump(array_keys($m->getEditors())); \ No newline at end of file diff --git a/testde2.php b/testde2.php deleted file mode 100644 index ac1ec86..0000000 --- a/testde2.php +++ /dev/null @@ -1,9 +0,0 @@ -get(\OCP\DirectEditing\IManager::class); -$ev = new \OCP\DirectEditing\RegisterDirectEditorEvent($m); -\OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class)->dispatchTyped($ev); -echo json_encode(array_keys($m->getEditors())), PHP_EOL; \ No newline at end of file