Simplify jsonSerialize keys to match API naming (fixes #266)

This commit is contained in:
Jonas Heinrich 2021-04-07 12:37:46 +02:00
parent 4a32718fc4
commit 6e80cae3ec
11 changed files with 274 additions and 27 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ yarn-error.log*
js/ js/
build/ build/
coverage/ coverage/
utils/docker-ci

View File

@ -1,5 +1,11 @@
## 1.1.0 - 2021-04 ## 1.1.0 - 2021-04
### Changed
- Simplify jsonSerialize keys to match API naming
[#266](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/266) @onny
- Update npm modules
[#269](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/269) @onny
## 1.0.3 - 2021-03 ## 1.0.3 - 2021-03
### Added ### Added

View File

@ -26,6 +26,7 @@ return [
'favorite' => ['url' => '/api/favorites'], 'favorite' => ['url' => '/api/favorites'],
'recent' => ['url' => '/api/recent'], 'recent' => ['url' => '/api/recent'],
'export' => ['url' => '/export'], 'export' => ['url' => '/export'],
'station' => ['url' => '/station'],
], ],
'routes' => [ 'routes' => [

View File

@ -0,0 +1,104 @@
<?php
/**
* Radio App
*
* @author Jonas Heinrich
* @copyright 2021 Jonas Heinrich <onny@project-insanity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Radio\Controller;
use OCA\Radio\AppInfo\Application;
use OCA\Radio\Service\RecentService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
class StationController extends Controller {
/** @var StationController */
private $service;
/** @var RadioBrowserApiService */
private $radiobrowserapi;
/** @var string */
private $userId;
use Errors;
public function __construct(IRequest $request,
RecentService $service,
RadioBrowserApiService $radiobrowserapi,
$userId) {
parent::__construct(Application::APP_ID, $request);
$this->service = $service;
$this->radiobrowserapi = $radiobrowserapi;
$this->userId = $userId;
}
/**
* @NoAdminRequired
*/
public function index(): DataResponse {
return new DataResponse($this->service->findAll($this->userId));
}
/**
* @NoAdminRequired
*/
public function show(int $id): DataResponse {
return $this->handleNotFound(function () use ($id) {
return $this->service->find($id, $this->userId);
});
}
/**
* @NoAdminRequired
*/
public function create(string $stationuuid, string $name, string $favicon, string $urlresolved,
string $bitrate, string $country, string $language, string $homepage,
string $codec, string $tags): DataResponse {
return new DataResponse($this->service->create($stationuuid, $name,
$favicon, $urlresolved, $bitrate, $country, $language, $homepage, $codec,
$tags, $this->userId));
}
/**
* @NoAdminRequired
*/
public function update(int $id, string $stationuuid, string $name,
string $favicon, string $urlresolved, string $bitrate, string $country,
string $language, string $homepage, string $codec, string $tags): DataResponse {
return $this->handleNotFound(function () use ($id, $stationuuid, $name,
$favicon, $urlresolved, $bitrate, $country, $language, $homepage, $codec,
$tags) {
return $this->service->update($id, $stationuuid, $name, $favicon,
$urlresolved, $bitrate, $country, $language, $homepage, $codec,
$tags, $this->userId);
});
}
/**
* @NoAdminRequired
*/
public function destroy(int $id): DataResponse {
return $this->handleNotFound(function () use ($id) {
return $this->service->delete($id, $this->userId);
});
}
}

View File

@ -46,7 +46,7 @@ class Station extends Entity implements JsonSerializable {
'stationuuid' => $this->stationuuid, 'stationuuid' => $this->stationuuid,
'name' => $this->name, 'name' => $this->name,
'favicon' => $this->favicon, 'favicon' => $this->favicon,
'urlresolved' => $this->urlresolved, 'url_resolved' => $this->urlresolved,
'bitrate' => $this->bitrate, 'bitrate' => $this->bitrate,
'country' => $this->country, 'country' => $this->country,
'language' => $this->language, 'language' => $this->language,

View File

@ -0,0 +1,153 @@
<?php
/**
* Radio App
*
* @author Jonas Heinrich
* @copyright 2021 Jonas Heinrich <onny@project-insanity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
declare(strict_types=1);
namespace OCA\Radio\Service;
use OCP\IURLGenerator;
use OCP\Http\Client\IClientService;
use function urlencode;
class RadioBrowserApiService {
/** @var IClientService */
private $clientService;
/** @var IURLGenerator */
private $url;
public $baseUrl = "https://api.fyyd.de/0.2";
public function __construct(
IClientService $clientService,
IURLGenerator $url
) {
$this->clientService = $clientService;
$this->url = $url;
}
public function queryEpisodes(int $podcast_id, int $count = 20, int $page = 0) {
$url = $this->baseUrl . "/podcast/episodes";
$options['query'] = [
'podcast_id' => $podcast_id,
'count' => $count,
'page' => $page
];
$client = $this->clientService->newClient();
try {
$response = $client->get($url, $options);
} catch (Exception $e) {
$this->logger->error("Could not search for podcasts: " . $e->getMessage());
throw $e;
}
$body = $response->getBody();
$parsed = json_decode($body, true);
return $parsed;
}
public function queryEpisode(int $episode_id) {
$url = $this->baseUrl . "/episode";
$options['query'] = [
'episode_id' => $episode_id,
];
$client = $this->clientService->newClient();
try {
$response = $client->get($url, $options);
} catch (Exception $e) {
$this->logger->error("Could not search for podcasts: " . $e->getMessage());
throw $e;
}
$body = $response->getBody();
$parsed = json_decode($body, true);
return $parsed;
}
public function queryPodcast(int $podcast_id) {
$url = $this->baseUrl . "/podcast";
$options['query'] = [
'podcast_id' => $podcast_id,
];
$client = $this->clientService->newClient();
try {
$response = $client->get($url, $options);
} catch (Exception $e) {
$this->logger->error("Could not search for podcasts: " . $e->getMessage());
throw $e;
}
$body = $response->getBody();
$parsed = json_decode($body, true);
return $parsed;
}
public function queryCategory(string $category, int $count = 20,
int $page = 0) {
if ($category === 'hot') {
$url = $this->baseUrl . "/feature/podcast/hot";
$options['query'] = [
'count' => $count,
'page' => $page,
];
} else if ($category === 'latest') {
$url = $this->baseUrl . "/podcast/latest";
$options['query'] = [
'count' => $count,
'page' => $page,
];
} else {
$url = $this->baseUrl . "/category";
$options['query'] = [
'count' => $count,
'page' => $page,
'category_id' => $category,
];
}
$client = $this->clientService->newClient();
try {
$response = $client->get($url, $options);
} catch (Exception $e) {
$this->logger->error("Could not search for podcasts: " . $e->getMessage());
throw $e;
}
$body = $response->getBody();
$parsed = json_decode($body, true);
return $parsed;
}
}

View File

@ -34,7 +34,7 @@
{{ t('radio', 'Stream URL') }} {{ t('radio', 'Stream URL') }}
</span> </span>
<div class="content"> <div class="content">
<input type="text" :value="urlResolved" disabled="disabled"> <input type="text" :value="sidebarStation.url_resolved" disabled="disabled">
<Actions> <Actions>
<ActionButton icon="icon-clippy" @click="copyLink"> <ActionButton icon="icon-clippy" @click="copyLink">
{{ t('radio', 'Copy link to clipboard') }} {{ t('radio', 'Copy link to clipboard') }}
@ -108,13 +108,6 @@ export default {
}, },
}, },
computed: { computed: {
urlResolved() {
if (this.sidebarStation.url_resolved) {
return this.sidebarStation.url_resolved
} else {
return this.sidebarStation.urlresolved
}
},
stationTags() { stationTags() {
if (this.sidebarStation.tags) { if (this.sidebarStation.tags) {
return this.sidebarStation.tags.replaceAll(',', ', ') return this.sidebarStation.tags.replaceAll(',', ', ')
@ -127,7 +120,7 @@ export default {
this.$emit('toggleSidebar') this.$emit('toggleSidebar')
}, },
copyLink() { copyLink() {
this.$copyText(this.urlResolved).then( this.$copyText(this.sidebarStation.url_resolved).then(
function() { function() {
showSuccess(t('radio', 'Link copied to clipboard')) showSuccess(t('radio', 'Link copied to clipboard'))
}, },

View File

@ -33,16 +33,10 @@ export class RadioApi {
} }
addFavorite(station) { addFavorite(station) {
let stationSrc = ''
if (!station.url_resolved) {
stationSrc = station.urlresolved
} else {
stationSrc = station.url_resolved
}
station = { station = {
id: -1, id: -1,
name: station.name.toString(), name: station.name.toString(),
urlresolved: stationSrc.toString(), url_resolved: station.url_resolved.toString(),
favicon: station.favicon.toString(), favicon: station.favicon.toString(),
stationuuid: station.stationuuid.toString(), stationuuid: station.stationuuid.toString(),
bitrate: station.bitrate.toString(), bitrate: station.bitrate.toString(),
@ -100,16 +94,10 @@ export class RadioApi {
} }
addRecent(station) { addRecent(station) {
let stationSrc = ''
if (!station.url_resolved) {
stationSrc = station.urlresolved
} else {
stationSrc = station.url_resolved
}
station = { station = {
id: -1, id: -1,
name: station.name.toString(), name: station.name.toString(),
urlresolved: stationSrc.toString(), url_resolved: station.url_resolved.toString(),
favicon: station.favicon.toString(), favicon: station.favicon.toString(),
stationuuid: station.stationuuid.toString(), stationuuid: station.stationuuid.toString(),
bitrate: station.bitrate.toString(), bitrate: station.bitrate.toString(),

View File

@ -120,7 +120,7 @@ export default ({
context.commit('setBuffering', true) context.commit('setBuffering', true)
context.commit('setTitle', station.name) context.commit('setTitle', station.name)
context.commit('setPausing', false) context.commit('setPausing', false)
player.doPlay(station.url_resolved || station.urlresolved) player.doPlay(station.url_resolved)
}, },
}, },

View File

@ -254,7 +254,7 @@ export default {
e.preventDefault() e.preventDefault()
const station = { const station = {
name: this.station.name, name: this.station.name,
urlresolved: this.station.streamUrl, url_resolved: this.station.streamUrl,
favicon: this.station.faviconUrl, favicon: this.station.faviconUrl,
stationuuid: this.uuidv4(), stationuuid: this.uuidv4(),
bitrate: '', bitrate: '',

View File

@ -147,7 +147,8 @@ export default {
= document.getElementById('app-content-vue').scrollHeight = document.getElementById('app-content-vue').scrollHeight
const tableHeight = height const tableHeight = height
if (tableHeight < contentHeight) { if (tableHeight < contentHeight) {
this.preFill() // this.preFill()
console.log('prefill')
} }
}, },