Add f7push v0.1: FCM device registry and push API for F7cloud.

Portable occ-based config, OCS endpoints for APK registration, notification relay, and server-side push dispatch.
This commit is contained in:
root
2026-05-24 10:26:36 +03:00
commit df4e2dddec
17 changed files with 1005 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace OCA\F7Push\Service;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\Security\ISecureRandom;
class ConfigService {
public const APP_ID = 'f7push';
public function __construct(
private IConfig $config,
private IURLGenerator $urlGenerator,
private ISecureRandom $secureRandom,
) {
}
public function isEnabled(): bool {
return $this->config->getAppValue(self::APP_ID, 'enabled', 'yes') === 'yes';
}
public function listenNotifications(): bool {
return $this->config->getAppValue(self::APP_ID, 'listen_notifications', 'yes') === 'yes';
}
public function getFirebaseProjectId(): string {
return trim($this->config->getAppValue(self::APP_ID, 'firebase_project_id', ''));
}
public function getFirebaseCredentials(): string {
return trim($this->config->getAppValue(self::APP_ID, 'firebase_credentials', ''));
}
public function isFirebaseConfigured(): bool {
return $this->getFirebaseProjectId() !== '' && $this->getFirebaseCredentials() !== '';
}
public function getApiSecret(): string {
$secret = trim($this->config->getAppValue(self::APP_ID, 'api_secret', ''));
if ($secret === '') {
$secret = $this->secureRandom->generate(48, ISecureRandom::CHAR_ALPHANUMERIC);
$this->config->setAppValue(self::APP_ID, 'api_secret', $secret);
}
return $secret;
}
public function regenerateApiSecret(): string {
$secret = $this->secureRandom->generate(48, ISecureRandom::CHAR_ALPHANUMERIC);
$this->config->setAppValue(self::APP_ID, 'api_secret', $secret);
return $secret;
}
public function isSourceEnabled(string $source): bool {
$raw = $this->config->getAppValue(self::APP_ID, 'enabled_sources', '*');
$raw = trim($raw);
if ($raw === '' || $raw === '*') {
return true;
}
$parts = array_map('trim', explode(',', strtolower($raw)));
return in_array(strtolower($source), $parts, true);
}
public function getDefaultClickUrl(): string {
$configured = trim($this->config->getAppValue(self::APP_ID, 'default_click_url', ''));
if ($configured !== '') {
return rtrim($configured, '/');
}
return rtrim($this->urlGenerator->getAbsoluteURL(''), '/');
}
public function verifyApiSecret(?string $provided): bool {
if ($provided === null || $provided === '') {
return false;
}
return hash_equals($this->getApiSecret(), $provided);
}
}