1
0
mirror of https://github.com/ONLYOFFICE/onlyoffice-owncloud.git synced 2025-07-30 10:43:07 +03:00
Files
onlyoffice-owncloud/controller/webassetcontroller.php
2025-01-14 11:45:27 +03:00

84 lines
2.2 KiB
PHP

<?php
/**
* @author Ascensio System SIA <integration@onlyoffice.com>
*
* (c) Copyright Ascensio System SIA 2025
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
namespace OCA\Onlyoffice\Controller;
use OC\AppFramework\Http;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Response;
use OCP\ILogger;
use OCP\IRequest;
/**
* Class WebAssetController
*
* @package OCA\Onlyoffice\Controller
*/
class WebAssetController extends Controller {
/**
* @var ILogger
*/
private $logger;
/**
* WebAssetController constructor.
*
* @param string $AppName - application name
* @param IRequest $request - request object
* @param ILogger $logger
*/
public function __construct($AppName, IRequest $request, ILogger $logger) {
parent::__construct($AppName, $request);
$this->logger = $logger;
}
/**
* Loads the onlyoffice.js file for integration into ownCloud Web
*
* @PublicPage
* @NoCSRFRequired
*
* @return Response
*/
public function get(): Response {
$basePath = \dirname(__DIR__, 1);
$filePath = \realpath($basePath . '/js/web/onlyoffice.js');
try {
return new DataDisplayResponse(
\file_get_contents($filePath),
Http::STATUS_OK,
[
'Content-Type' => "text/javascript",
'Content-Length' => \filesize($filePath),
'Cache-Control' => 'max-age=0, no-cache, no-store, must-revalidate',
'Pragma' => 'no-cache',
'Expires' => 'Tue, 24 Sep 1985 22:15:00 GMT',
'X-Frame-Options' => 'DENY'
]
);
} catch(\Exception $e) {
$this->logger->logException($e, ['app' => $this->appName]);
return new DataResponse(["message" => $e->getMessage()], Http::STATUS_NOT_FOUND);
}
}
}