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;
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'.",

View File

@ -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)
},