|
| 1 | +<?php |
| 2 | +namespace OCA\Solid\WellKnown; |
| 3 | + |
| 4 | +use OCP\IRequest; |
| 5 | +use OCP\IUserManager; |
| 6 | +use OCP\IURLGenerator; |
| 7 | +use OCP\IConfig; |
| 8 | + |
| 9 | +use OCP\AppFramework\Http\JSONResponse; |
| 10 | +use OCP\Http\WellKnown\GenericResponse; |
| 11 | +use OCP\Http\WellKnown\IHandler; |
| 12 | +use OCP\Http\WellKnown\IRequestContext; |
| 13 | +use OCP\Http\WellKnown\IResponse; |
| 14 | + |
| 15 | +class SolidHandler implements IHandler { |
| 16 | + /* @var IURLGenerator */ |
| 17 | + private $urlGenerator; |
| 18 | + |
| 19 | + public function __construct(IRequest $request, IURLGenerator $urlGenerator, IConfig $config, IUserManager $userManager) |
| 20 | + { |
| 21 | + require_once(__DIR__.'/../../vendor/autoload.php'); |
| 22 | + $this->urlGenerator = $urlGenerator; |
| 23 | + } |
| 24 | + |
| 25 | + public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse { |
| 26 | + if ($service !== 'solid') { |
| 27 | + return $previousResponse; |
| 28 | + } |
| 29 | + $webhooksRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.solidWebhook.register'); |
| 30 | + // FIXME: this shouldn't happen: |
| 31 | + if (strlen($webhooksRegisterEndpoint) == 0) { |
| 32 | + $webhooksRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.app.appLauncher') . 'webhook/register'; |
| 33 | + } |
| 34 | + |
| 35 | + $websocketsRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.solidWebsocket.register'); |
| 36 | + // FIXME: this shouldn't happen: |
| 37 | + if (strlen($websocketsRegisterEndpoint) == 0) { |
| 38 | + $websocketsRegisterEndpoint = $this->urlGenerator->linkToRoute('solid.app.appLauncher') . 'websocket/register'; |
| 39 | + } |
| 40 | + $body = [ |
| 41 | + "@context" => [ |
| 42 | + "https://www.w3.org/ns/solid/notification/v1" |
| 43 | + ], |
| 44 | + "notificationChannel" => [ |
| 45 | + [ |
| 46 | + "id" => "websocketNotification", |
| 47 | + "type" => ["WebSocketSubscription2021"], |
| 48 | + "subscription" => $websocketsRegisterEndpoint, |
| 49 | + "feature" => [] |
| 50 | + ], |
| 51 | + [ |
| 52 | + "id" => "webhookNotification", |
| 53 | + "type" => ["WebHookSubscription2022"], |
| 54 | + "subscription" => $webhooksRegisterEndpoint, |
| 55 | + "feature" => [] |
| 56 | + ] |
| 57 | + ] |
| 58 | + ]; |
| 59 | + $result = new JSONResponse($body); |
| 60 | + $result->addHeader("Access-Control-Allow-Origin", "*"); |
| 61 | + $result->setStatus(200); |
| 62 | + return new GenericResponse($result); |
| 63 | + } |
| 64 | +} |
0 commit comments