46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OCA\RePod\Controller;
|
|
|
|
use OCA\GPodderSync\Core\PodcastData\PodcastDataReader;
|
|
use OCA\GPodderSync\Core\PodcastData\PodcastMetricsReader;
|
|
use OCA\RePod\AppInfo\Application;
|
|
use OCA\RePod\Service\UserService;
|
|
use OCP\AppFramework\Controller;
|
|
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
|
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
|
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
use OCP\IRequest;
|
|
|
|
class MetricsController extends Controller
|
|
{
|
|
public function __construct(
|
|
IRequest $request,
|
|
private PodcastDataReader $podcastDataReader,
|
|
private PodcastMetricsReader $podcastMetricsReader,
|
|
private UserService $userService
|
|
) {
|
|
parent::__construct(Application::APP_ID, $request);
|
|
}
|
|
|
|
#[NoAdminRequired]
|
|
#[NoCSRFRequired]
|
|
#[FrontpageRoute(verb: 'GET', url: '/metrics')]
|
|
public function index(): JSONResponse {
|
|
$subscriptions = $this->podcastMetricsReader->metrics($this->userService->getUserUID());
|
|
|
|
foreach ($subscriptions as $id => $subscription) {
|
|
try {
|
|
$subscriptions[$id]['data'] = $this->podcastDataReader->getCachedOrFetchPodcastData($subscription->getUrl(), $this->userService->getUserUID());
|
|
} catch (\Exception $e) {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return new JSONResponse($subscriptions);
|
|
}
|
|
}
|