Removed unused code & check for userId==null

This commit is contained in:
Kalle Fagerberg 2022-09-18 18:30:52 +02:00 committed by thrillfall
parent c689439dd4
commit a5d5278956
2 changed files with 14 additions and 25 deletions

View File

@ -3,42 +3,31 @@ declare(strict_types=1);
namespace OCA\GPodderSync\Controller; namespace OCA\GPodderSync\Controller;
use GuzzleHttp\Psr7\BufferStream;
use GuzzleHttp\Psr7\StreamWrapper;
use OCA\GPodderSync\Core\PodcastData\PodcastDataReader; use OCA\GPodderSync\Core\PodcastData\PodcastDataReader;
use OCA\GPodderSync\Core\PodcastData\PodcastMetricsReader; use OCA\GPodderSync\Core\PodcastData\PodcastMetricsReader;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse; 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; use OCP\IRequest;
class PersonalSettingsController extends Controller { class PersonalSettingsController extends Controller {
private string $userId; private ?string $userId;
private PodcastMetricsReader $metricsReader; private PodcastMetricsReader $metricsReader;
private PodcastDataReader $dataReader; private PodcastDataReader $dataReader;
// TODO: Use httpClient via PodcastDataReader instead
private IClient $httpClient;
public function __construct( public function __construct(
string $AppName, string $AppName,
IRequest $request, IRequest $request,
string $UserId, ?string $UserId,
PodcastMetricsReader $metricsReader, PodcastMetricsReader $metricsReader,
PodcastDataReader $dataReader, PodcastDataReader $dataReader,
IClientService $httpClientService,
) { ) {
parent::__construct($AppName, $request); parent::__construct($AppName, $request);
$this->userId = $UserId ?? ''; $this->userId = $UserId ?? '';
$this->metricsReader = $metricsReader; $this->metricsReader = $metricsReader;
$this->dataReader = $dataReader; $this->dataReader = $dataReader;
$this->httpClient = $httpClientService->newClient();
} }
/** /**
@ -49,6 +38,12 @@ class PersonalSettingsController extends Controller {
* @return JSONResponse * @return JSONResponse
*/ */
public function metrics(): 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); $metrics = $this->metricsReader->metrics($this->userId);
return new JSONResponse([ return new JSONResponse([
'subscriptions' => $metrics, 'subscriptions' => $metrics,
@ -63,6 +58,12 @@ class PersonalSettingsController extends Controller {
* @return JsonResponse * @return JsonResponse
*/ */
public function podcastData(string $url = ''): JsonResponse { public function podcastData(string $url = ''): JsonResponse {
if ($this->userId === null) {
return new JSONResponse([
'message' => "Unauthorized.",
'data' => null,
], statusCode: Http::STATUS_UNAUTHORIZED);
}
if ($url === '') { if ($url === '') {
return new JSONResponse([ return new JSONResponse([
'message' => "Missing query parameter 'url'.", 'message' => "Missing query parameter 'url'.",

View File

@ -86,18 +86,6 @@ export default {
} }
}, },
methods: { 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) { updateSorting(sorting) {
this.subscriptions.sort(sorting.compare) this.subscriptions.sort(sorting.compare)
}, },