-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathDevelopController.php
More file actions
63 lines (57 loc) · 1.94 KB
/
DevelopController.php
File metadata and controls
63 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Controller;
use OCA\Libresign\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\Response;
use OCP\Files\SimpleFS\InMemoryFile;
use OCP\IConfig;
use OCP\IRequest;
class DevelopController extends Controller {
public function __construct(
IRequest $request,
private IConfig $config,
) {
parent::__construct(Application::APP_ID, $request);
}
/**
* Get a demo PDF file to be used by test purpose
*
* To use this endpoint is necessary to enable the debug mode in your instance. To do this, run the command:
*
* `occ config:system:set debug --value true --type boolean`
*
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: 'application/pdf',Content-Disposition: 'inline; filename="file.pdf"'}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
*
* 200: PDF returned
* 404: Debug mode not enabled
*/
#[NoCSRFRequired]
#[PublicPage]
#[FrontpageRoute(verb: 'GET', url: '/develop/pdf')]
public function pdf(): FileDisplayResponse|Response {
if (!$this->isDebugMode()) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$file = new InMemoryFile('file.pdf', file_get_contents(__DIR__ . '/../../tests/php/fixtures/pdfs/small_valid.pdf'));
$response = new FileDisplayResponse($file);
$response->setHeaders([
'Content-Disposition' => 'inline; filename="file.pdf"',
'Content-Type' => 'application/pdf',
]);
return $response;
}
public function isDebugMode(): bool {
return $this->config->getSystemValue('debug', false) === true;
}
}