From a5d5278956e77d3e40dc5bc5cc04281b6c45707c Mon Sep 17 00:00:00 2001 From: Kalle Fagerberg Date: Sun, 18 Sep 2022 18:30:52 +0200 Subject: [PATCH] Removed unused code & check for userId==null --- lib/Controller/PersonalSettingsController.php | 27 ++++++++++--------- src/views/PersonalSettingsPage.vue | 12 --------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/lib/Controller/PersonalSettingsController.php b/lib/Controller/PersonalSettingsController.php index 2031405..48357e3 100644 --- a/lib/Controller/PersonalSettingsController.php +++ b/lib/Controller/PersonalSettingsController.php @@ -3,42 +3,31 @@ declare(strict_types=1); namespace OCA\GPodderSync\Controller; -use GuzzleHttp\Psr7\BufferStream; -use GuzzleHttp\Psr7\StreamWrapper; use OCA\GPodderSync\Core\PodcastData\PodcastDataReader; use OCA\GPodderSync\Core\PodcastData\PodcastMetricsReader; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; -use OCP\AppFramework\Http\StreamResponse; -use OCP\AppFramework\OCS\OCSException; -use OCP\Http\Client\IClient; -use OCP\Http\Client\IClientService; use OCP\IRequest; class PersonalSettingsController extends Controller { - private string $userId; + private ?string $userId; private PodcastMetricsReader $metricsReader; private PodcastDataReader $dataReader; - // TODO: Use httpClient via PodcastDataReader instead - private IClient $httpClient; - public function __construct( string $AppName, IRequest $request, - string $UserId, + ?string $UserId, PodcastMetricsReader $metricsReader, PodcastDataReader $dataReader, - IClientService $httpClientService, ) { parent::__construct($AppName, $request); $this->userId = $UserId ?? ''; $this->metricsReader = $metricsReader; $this->dataReader = $dataReader; - $this->httpClient = $httpClientService->newClient(); } /** @@ -49,6 +38,12 @@ class PersonalSettingsController extends Controller { * @return JSONResponse */ public function metrics(): JSONResponse { + if ($this->userId === null) { + return new JSONResponse([ + 'message' => "Unauthorized.", + 'subscriptions' => null, + ], statusCode: Http::STATUS_UNAUTHORIZED); + } $metrics = $this->metricsReader->metrics($this->userId); return new JSONResponse([ 'subscriptions' => $metrics, @@ -63,6 +58,12 @@ class PersonalSettingsController extends Controller { * @return JsonResponse */ public function podcastData(string $url = ''): JsonResponse { + if ($this->userId === null) { + return new JSONResponse([ + 'message' => "Unauthorized.", + 'data' => null, + ], statusCode: Http::STATUS_UNAUTHORIZED); + } if ($url === '') { return new JSONResponse([ 'message' => "Missing query parameter 'url'.", diff --git a/src/views/PersonalSettingsPage.vue b/src/views/PersonalSettingsPage.vue index 0ca85a5..2f3a7da 100644 --- a/src/views/PersonalSettingsPage.vue +++ b/src/views/PersonalSettingsPage.vue @@ -86,18 +86,6 @@ export default { } }, methods: { - formatSubscriptionDetails(sub) { - if (sub.listenedSeconds <= 0) { - return '(no time listened)' - } - const hours = Math.floor(sub.listenedSeconds / 3600) - const modMinutes = Math.floor(sub.listenedSeconds / 60) % 60 - if (hours === 0) { - const modSeconds = sub.listenedSeconds % 60 - return `(${modMinutes}min ${modSeconds}s listened)` - } - return `(${hours}h ${modMinutes}min listened)` - }, updateSorting(sorting) { this.subscriptions.sort(sorting.compare) },