Skip to content

Commit cc4f8eb

Browse files
committed
init
Signed-off-by: Hoang Pham <hoangmaths96@gmail.com>
1 parent 12b3304 commit cc4f8eb

File tree

78 files changed

+7114
-4256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+7114
-4256
lines changed

.env.example

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ TLS=false
1818
TLS_KEY=
1919
TLS_CERT=
2020

21-
# Turn off SSL certificate validation in development mode for easier testing
22-
IS_DEV=false
23-
2421
# Storage strategy for whiteboard data and socket-related temporary data
2522
# Valid values are: 'redis' or 'lru' (Least Recently Used cache)
2623
# This strategy is used for:
@@ -38,7 +35,23 @@ STORAGE_STRATEGY=lru
3835
# Example: redis://user:password@redis.example.com:6379/0
3936
REDIS_URL=redis://localhost:6379
4037

38+
# Timeout in milliseconds for the whiteboard server's graceful shutdown process
39+
# If the server cannot close all connections within this time, it will force shutdown
40+
# Default: 3600000 (1 hour)
41+
FORCE_CLOSE_TIMEOUT=3600000
42+
43+
# Maximum file upload size in megabytes
44+
# This limits the size of files that can be uploaded to the whiteboard
45+
# Default: 2 (MB)
46+
MAX_UPLOAD_FILE_SIZE=2
47+
48+
# Time-to-live in milliseconds for cached authentication tokens
49+
# Higher values reduce authentication overhead but increase memory usage
50+
# Must be smaller than 15 minutes (900000ms) since that's the JWT default expiration time
51+
# Default: 600000 (10 minutes)
52+
CACHED_TOKEN_TTL=600000
53+
4154
# Prometheus metrics endpoint
4255
# Set this to access the monitoring endpoint at /metrics
4356
# either providing it as Bearer token or as ?token= query parameter
44-
# METRICS_TOKEN=
57+
METRICS_TOKEN=

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"autoloader-suffix": "Whiteboard",
55
"optimize-autoloader": true,
66
"platform": {
7-
"php": "8.1"
7+
"php": "8.4"
88
},
99
"sort-packages": true
1010
},
@@ -14,18 +14,18 @@
1414
"firebase/php-jwt": "^6.10"
1515
},
1616
"require-dev": {
17-
"nextcloud/coding-standard": "^1.0",
17+
"nextcloud/coding-standard": "^1.3.2",
1818
"nextcloud/ocp": "dev-master",
1919
"phpunit/phpunit": "^9",
20-
"psalm/phar": "^5.2",
20+
"psalm/phar": "^6.0",
2121
"psr/log": "^3.0.2",
2222
"roave/security-advisories": "dev-latest",
2323
"sabre/dav": "^4.3"
2424
},
2525
"scripts": {
2626
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
27-
"cs:check": "php-cs-fixer fix --dry-run --diff",
28-
"cs:fix": "php-cs-fixer fix",
27+
"cs:check": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run",
28+
"cs:fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix",
2929
"psalm": "psalm.phar",
3030
"test:unit": "phpunit -c tests/phpunit.xml"
3131
}

composer.lock

Lines changed: 121 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/AppInfo/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function __construct(array $params = []) {
3838
parent::__construct(self::APP_ID, $params);
3939
}
4040

41+
#[\Override]
4142
public function register(IRegistrationContext $context): void {
4243
include_once __DIR__ . '/../../vendor/autoload.php';
4344

@@ -48,10 +49,11 @@ public function register(IRegistrationContext $context): void {
4849
$context->registerSetupCheck(SetupCheck::class);
4950
}
5051

52+
#[\Override]
5153
public function boot(IBootContext $context): void {
5254
[$major] = Util::getVersion();
5355
if ($major < 30) {
54-
$context->injectFn(function (ITemplateManager $templateManager, IL10N $l10n) use ($major) {
56+
$context->injectFn(function (ITemplateManager $templateManager, IL10N $l10n) {
5557
$templateManager->registerTemplateFileCreator(function () use ($l10n) {
5658
return RegisterTemplateCreatorListener::getTemplateFileCreator($l10n);
5759
});

lib/Controller/WhiteboardController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OCP\AppFramework\Http\Attribute\PublicPage;
2525
use OCP\AppFramework\Http\DataResponse;
2626
use OCP\IRequest;
27+
use Psr\Log\LoggerInterface;
2728

2829
/**
2930
* @psalm-suppress UndefinedClass
@@ -39,6 +40,7 @@ public function __construct(
3940
private WhiteboardContentService $contentService,
4041
private ExceptionService $exceptionService,
4142
private ConfigService $configService,
43+
private LoggerInterface $logger,
4244
) {
4345
parent::__construct($appName, $request);
4446
}
@@ -69,9 +71,9 @@ public function show(int $fileId): DataResponse {
6971
#[PublicPage]
7072
public function update(int $fileId, array $data): DataResponse {
7173
try {
72-
$this->validateBackendSharedToken($fileId);
74+
$jwt = $this->getJwtFromRequest();
7375

74-
$userId = $this->getUserIdFromRequest();
76+
$userId = $this->jwtService->getUserIdFromJWT($jwt);
7577

7678
$user = $this->getUserFromIdServiceFactory->create($userId)->getUser();
7779

@@ -81,6 +83,8 @@ public function update(int $fileId, array $data): DataResponse {
8183

8284
return new DataResponse(['status' => 'success']);
8385
} catch (Exception $e) {
86+
$this->logger->error('Error syncing whiteboard data: ' . $e->getMessage());
87+
8488
return $this->exceptionService->handleException($e);
8589
}
8690
}

lib/Listener/AddContentSecurityPolicyListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct(
2020
) {
2121
}
2222

23+
#[\Override]
2324
public function handle(Event $event): void {
2425
if (!$event instanceof AddContentSecurityPolicyEvent) {
2526
return;
@@ -28,6 +29,8 @@ public function handle(Event $event): void {
2829
$policy = new EmptyContentSecurityPolicy();
2930

3031
$policy->addAllowedConnectDomain('*');
32+
$policy->addAllowedWorkerSrcDomain('*');
33+
3134
$event->addPolicy($policy);
3235
}
3336
}

lib/Listener/BeforeTemplateRenderedListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct(
3030
/**
3131
* @throws NotFoundException
3232
*/
33+
#[\Override]
3334
public function handle(Event $event): void {
3435
if (!($event instanceof BeforeTemplateRenderedEvent)) {
3536
return;

lib/Listener/LoadViewerListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __construct(
2525
) {
2626
}
2727

28+
#[\Override]
2829
public function handle(Event $event): void {
2930
if (!($event instanceof LoadViewer)) {
3031
return;

lib/Listener/RegisterTemplateCreatorListener.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __construct(
2525
) {
2626
}
2727

28+
#[\Override]
2829
public function handle(Event $event): void {
2930
if (!($event instanceof RegisterTemplateCreatorEvent)) {
3031
return;
@@ -39,7 +40,10 @@ public function handle(Event $event): void {
3940
public static function getTemplateFileCreator(IL10N $l10n): TemplateFileCreator {
4041
$whiteboard = new TemplateFileCreator(Application::APP_ID, $l10n->t('New whiteboard'), '.whiteboard');
4142
$whiteboard->addMimetype('application/vnd.excalidraw+json');
42-
$whiteboard->setIconSvgInline(file_get_contents(__DIR__ . '/../../img/app-filetype.svg'));
43+
$iconContent = file_get_contents(__DIR__ . '/../../img/app-filetype.svg');
44+
if ($iconContent !== false) {
45+
$whiteboard->setIconSvgInline($iconContent);
46+
}
4347
$whiteboard->setActionLabel($l10n->t('Create new whiteboard'));
4448
return $whiteboard;
4549
}

lib/Model/AuthenticatedUser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ public function __construct(
1717
) {
1818
}
1919

20+
#[\Override]
2021
public function getUID(): string {
2122
return $this->user->getUID();
2223
}
2324

25+
#[\Override]
2426
public function getDisplayName(): string {
2527
return $this->user->getDisplayName();
2628
}

0 commit comments

Comments
 (0)