refactor: 🚧 rework metrics

This commit is contained in:
Michel Roux 2024-10-22 18:32:41 +02:00
parent cbe8750fd2
commit 427c6b2ee8
2 changed files with 46 additions and 1 deletions

View File

@ -0,0 +1,45 @@
<?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);
}
}

View File

@ -24,7 +24,7 @@ export const useSubscriptions = defineStore('subscriptions', {
} catch {} } catch {}
const metrics = await axios.get<PersonalSettingsMetricsInterface>( const metrics = await axios.get<PersonalSettingsMetricsInterface>(
generateUrl('/apps/gpoddersync/personal_settings/metrics'), generateUrl('/apps/repod/metrics'),
) )
this.subs = [...metrics.data.subscriptions] this.subs = [...metrics.data.subscriptions]