Files
htmlviewer-directediting/HtmlDirectEditor.php
T
Hermes 88d618b58a htmlviewer-directediting: HTML rendering in Nextcloud iOS app
- htmlviewer: IEditor + Bridge + srcdoc iframe template + content controller
- text app: open() bridges text/html to htmlviewer template
- idempotent install.sh for re-deployment after app updates
- iPhone-tested 2026-09-11
2026-09-11 12:19:44 +00:00

89 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 HtmlViewer / patch by Hermes Agent
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* DirectEditing editor for text/html so the Nextcloud iOS/Android apps
* open HTML files in an embedded WebView instead of falling back to
* QuickLook source display.
*/
namespace OCA\HtmlViewer\DirectEditing;
use OCA\HtmlViewer\AppInfo\Application;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\DirectEditing\IEditor;
use OCP\DirectEditing\IToken;
use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\IURLGenerator;
class HtmlDirectEditor implements IEditor {
public function __construct(
private IL10N $l10n,
private IURLGenerator $urlGenerator,
) {
}
#[\Override]
public function getId(): string {
return Application::APP_ID;
}
#[\Override]
public function getName(): string {
return $this->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();
}
}
}