added webhook transport (probably only for debugging)
This commit is contained in:
parent
b28e0619f5
commit
066d89873a
3 changed files with 81 additions and 0 deletions
|
@ -30,4 +30,15 @@ use OCA\DavPush\Transport\Transport;
|
|||
|
||||
class WebPushTransport extends Transport {
|
||||
protected $id = "web-push";
|
||||
|
||||
public function registerSubscription($options) {
|
||||
return [
|
||||
'success' => True,
|
||||
'response' => "web push test",
|
||||
];
|
||||
}
|
||||
|
||||
public function notify(string $userId, string $collectionName, $data) {
|
||||
|
||||
}
|
||||
}
|
68
lib/PushTransports/WebhookTransport.php
Normal file
68
lib/PushTransports/WebhookTransport.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2024 Jonathan Treffler <mail@jonathan-treffler.de>
|
||||
*
|
||||
* @author Jonathan Treffler <mail@jonathan-treffler.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\DavPush\PushTransports;
|
||||
|
||||
use OCA\DavPush\Transport\Transport;
|
||||
|
||||
class WebhookTransport extends Transport {
|
||||
protected $id = "webhook";
|
||||
|
||||
public function registerSubscription($options) {
|
||||
$url = False;
|
||||
|
||||
foreach($options as $option) {
|
||||
if($option["name"] == "{DAV:Push}endpoint") {
|
||||
$url = $option["value"];
|
||||
}
|
||||
}
|
||||
|
||||
if($url) {
|
||||
return [
|
||||
'success' => True,
|
||||
'response' => "",
|
||||
'data' => [ "url" => $url ],
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'success' => False,
|
||||
'error' => "webhook url not provided",
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function notify(string $userId, string $collectionName, $data) {
|
||||
$options = [
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'content' => "Collection " . $collectionName . "has been changed",
|
||||
],
|
||||
];
|
||||
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($data["url"], false, $context);
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ use OCP\EventDispatcher\IEventDispatcher;
|
|||
|
||||
use OCA\DavPush\Events\RegisterTransportsEvent;
|
||||
use OCA\DavPush\PushTransports\WebPushTransport;
|
||||
use OCA\DavPush\PushTransports\WebhookTransport;
|
||||
|
||||
class TransportManager {
|
||||
private array $transports = [];
|
||||
|
@ -37,6 +38,7 @@ class TransportManager {
|
|||
public function __construct(IEventDispatcher $dispatcher) {
|
||||
// register integrated transports
|
||||
$this->registerTransport(new WebPushTransport());
|
||||
$this->registerTransport(new WebhookTransport());
|
||||
|
||||
// register transports provided by other apps
|
||||
$event = new RegisterTransportsEvent($this);
|
||||
|
|
Loading…
Reference in a new issue