diff options
author | John Molakvoæ <skjnldsv@protonmail.com> | 2023-03-17 16:58:24 +0100 |
---|---|---|
committer | John Molakvoæ <skjnldsv@protonmail.com> | 2023-04-06 14:49:30 +0200 |
commit | b761039cf1946cb64898b9117d1b15dd89080451 (patch) | |
tree | 27ef66889525e0fbe0f295d1bdc96fb3d8ac479c /apps/files/lib/Controller | |
parent | 2ff1c00f556633c9c36a9328d4eb77eba2dd25e7 (diff) | |
download | nextcloud-server-b761039cf1946cb64898b9117d1b15dd89080451.tar.gz nextcloud-server-b761039cf1946cb64898b9117d1b15dd89080451.zip |
perf(files): fetch previews faster and cache properly
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files/lib/Controller')
-rw-r--r-- | apps/files/lib/Controller/ApiController.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 9baf5e97892..85507132edd 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -42,10 +42,12 @@ use OCA\Files\Service\TagService; use OCA\Files\Service\UserConfig; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; +use OCP\AppFramework\Http\StreamResponse; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\NotFoundException; @@ -417,4 +419,22 @@ class ApiController extends Controller { $node = $this->userFolder->get($folderpath); return $node->getType(); } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function serviceWorker(): StreamResponse { + $response = new StreamResponse(__DIR__ . '/../../../../dist/preview-service-worker.js'); + $response->setHeaders([ + 'Content-Type' => 'application/javascript', + 'Service-Worker-Allowed' => '/' + ]); + $policy = new ContentSecurityPolicy(); + $policy->addAllowedWorkerSrcDomain("'self'"); + $policy->addAllowedScriptDomain("'self'"); + $policy->addAllowedConnectDomain("'self'"); + $response->setContentSecurityPolicy($policy); + return $response; + } } |