Simplify jsonSerialize keys to match API naming (fixes #266)
This commit is contained in:
parent
4a32718fc4
commit
6e80cae3ec
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,3 +17,4 @@ yarn-error.log*
|
||||
js/
|
||||
build/
|
||||
coverage/
|
||||
utils/docker-ci
|
||||
|
@ -1,5 +1,11 @@
|
||||
## 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
|
||||
|
||||
### Added
|
||||
|
@ -26,6 +26,7 @@ return [
|
||||
'favorite' => ['url' => '/api/favorites'],
|
||||
'recent' => ['url' => '/api/recent'],
|
||||
'export' => ['url' => '/export'],
|
||||
'station' => ['url' => '/station'],
|
||||
],
|
||||
'routes' => [
|
||||
|
||||
|
104
lib/Controller/StationController.php
Normal file
104
lib/Controller/StationController.php
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ class Station extends Entity implements JsonSerializable {
|
||||
'stationuuid' => $this->stationuuid,
|
||||
'name' => $this->name,
|
||||
'favicon' => $this->favicon,
|
||||
'urlresolved' => $this->urlresolved,
|
||||
'url_resolved' => $this->urlresolved,
|
||||
'bitrate' => $this->bitrate,
|
||||
'country' => $this->country,
|
||||
'language' => $this->language,
|
||||
|
153
lib/Service/RadioBrowserApiService.php
Normal file
153
lib/Service/RadioBrowserApiService.php
Normal 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;
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@
|
||||
{{ t('radio', 'Stream URL') }}
|
||||
</span>
|
||||
<div class="content">
|
||||
<input type="text" :value="urlResolved" disabled="disabled">
|
||||
<input type="text" :value="sidebarStation.url_resolved" disabled="disabled">
|
||||
<Actions>
|
||||
<ActionButton icon="icon-clippy" @click="copyLink">
|
||||
{{ t('radio', 'Copy link to clipboard') }}
|
||||
@ -108,13 +108,6 @@ export default {
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
urlResolved() {
|
||||
if (this.sidebarStation.url_resolved) {
|
||||
return this.sidebarStation.url_resolved
|
||||
} else {
|
||||
return this.sidebarStation.urlresolved
|
||||
}
|
||||
},
|
||||
stationTags() {
|
||||
if (this.sidebarStation.tags) {
|
||||
return this.sidebarStation.tags.replaceAll(',', ', ')
|
||||
@ -127,7 +120,7 @@ export default {
|
||||
this.$emit('toggleSidebar')
|
||||
},
|
||||
copyLink() {
|
||||
this.$copyText(this.urlResolved).then(
|
||||
this.$copyText(this.sidebarStation.url_resolved).then(
|
||||
function() {
|
||||
showSuccess(t('radio', 'Link copied to clipboard'))
|
||||
},
|
||||
|
@ -33,16 +33,10 @@ export class RadioApi {
|
||||
}
|
||||
|
||||
addFavorite(station) {
|
||||
let stationSrc = ''
|
||||
if (!station.url_resolved) {
|
||||
stationSrc = station.urlresolved
|
||||
} else {
|
||||
stationSrc = station.url_resolved
|
||||
}
|
||||
station = {
|
||||
id: -1,
|
||||
name: station.name.toString(),
|
||||
urlresolved: stationSrc.toString(),
|
||||
url_resolved: station.url_resolved.toString(),
|
||||
favicon: station.favicon.toString(),
|
||||
stationuuid: station.stationuuid.toString(),
|
||||
bitrate: station.bitrate.toString(),
|
||||
@ -100,16 +94,10 @@ export class RadioApi {
|
||||
}
|
||||
|
||||
addRecent(station) {
|
||||
let stationSrc = ''
|
||||
if (!station.url_resolved) {
|
||||
stationSrc = station.urlresolved
|
||||
} else {
|
||||
stationSrc = station.url_resolved
|
||||
}
|
||||
station = {
|
||||
id: -1,
|
||||
name: station.name.toString(),
|
||||
urlresolved: stationSrc.toString(),
|
||||
url_resolved: station.url_resolved.toString(),
|
||||
favicon: station.favicon.toString(),
|
||||
stationuuid: station.stationuuid.toString(),
|
||||
bitrate: station.bitrate.toString(),
|
||||
|
@ -120,7 +120,7 @@ export default ({
|
||||
context.commit('setBuffering', true)
|
||||
context.commit('setTitle', station.name)
|
||||
context.commit('setPausing', false)
|
||||
player.doPlay(station.url_resolved || station.urlresolved)
|
||||
player.doPlay(station.url_resolved)
|
||||
},
|
||||
|
||||
},
|
||||
|
@ -254,7 +254,7 @@ export default {
|
||||
e.preventDefault()
|
||||
const station = {
|
||||
name: this.station.name,
|
||||
urlresolved: this.station.streamUrl,
|
||||
url_resolved: this.station.streamUrl,
|
||||
favicon: this.station.faviconUrl,
|
||||
stationuuid: this.uuidv4(),
|
||||
bitrate: '',
|
||||
|
@ -147,7 +147,8 @@ export default {
|
||||
= document.getElementById('app-content-vue').scrollHeight
|
||||
const tableHeight = height
|
||||
if (tableHeight < contentHeight) {
|
||||
this.preFill()
|
||||
// this.preFill()
|
||||
console.log('prefill')
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user