64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\F7Support\Controller;
|
|
|
|
use OCP\AppFramework\Controller;
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
use OCP\IConfig;
|
|
use OCP\IRequest;
|
|
use OCP\IURLGenerator;
|
|
use OCP\IUserSession;
|
|
use OCP\Util;
|
|
|
|
class PageController extends Controller {
|
|
public function __construct(
|
|
string $AppName,
|
|
IRequest $request,
|
|
private IUserSession $userSession,
|
|
private IURLGenerator $urlGenerator,
|
|
private IConfig $config,
|
|
) {
|
|
parent::__construct($AppName, $request);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function index(): TemplateResponse {
|
|
$user = $this->userSession->getUser();
|
|
$baseUrl = $this->urlGenerator->getBaseUrl();
|
|
$serverHost = parse_url($baseUrl, PHP_URL_HOST) ?: 'localhost';
|
|
|
|
// База REST API поддержки (без завершающего слэша). Переопределение: occ config:app:set f7support support_api_base --value=https://...
|
|
$supportApiBase = trim($this->config->getAppValue('f7support', 'support_api_base', 'https://support.f7cloud.ru'));
|
|
if ($supportApiBase === '') {
|
|
$supportApiBase = 'https://support.f7cloud.ru';
|
|
}
|
|
$supportParts = parse_url($supportApiBase);
|
|
$supportApiOrigin = ($supportParts['scheme'] ?? 'https') . '://' . ($supportParts['host'] ?? '');
|
|
|
|
// Optional full WebSocket URL prefix, e.g. wss://support.f7cloud.ru/api/ws (path before /tickets/{id})
|
|
$supportWsBase = $this->config->getAppValue('f7support', 'support_ws_base', '');
|
|
|
|
// POST /api/client/tickets/{id}/read — только если бэкенд уже выкатили (иначе 404 и шум в консоли NC).
|
|
// Включение: occ config:app:set f7support client_read_receipts --value=1
|
|
$clientReadReceipts = $this->config->getAppValue('f7support', 'client_read_receipts', '0');
|
|
|
|
Util::addStyle('f7support', 'f7support');
|
|
Util::addScript('f7support', 'main');
|
|
|
|
return new TemplateResponse('f7support', 'main', [
|
|
'username' => $user ? $user->getUID() : '',
|
|
'serverAddress' => $serverHost,
|
|
'supportApiBase' => $supportApiBase,
|
|
'supportApiOrigin' => $supportApiOrigin,
|
|
'supportWsBase' => $supportWsBase,
|
|
'clientReadReceipts' => $clientReadReceipts,
|
|
]);
|
|
}
|
|
}
|
|
|