fix playing favorite stations

This commit is contained in:
Jonas Heinrich 2020-11-13 12:43:44 +01:00
parent f3c64ac7b1
commit 67f4bebefc
6 changed files with 21 additions and 103 deletions

View File

@ -24,9 +24,7 @@
return [
'resources' => [
'favorite' => ['url' => '/api/favorites'],
'favorite_api' => ['url' => '/api/0.1/favorites'],
'recent' => ['url' => '/api/recents'],
'recent_api' => ['url' => '/api/0.1/recents']
],
'routes' => [

View File

@ -1,80 +0,0 @@
<?php
namespace OCA\Radio\Controller;
use OCA\Radio\AppInfo\Application;
use OCA\Radio\Service\StationService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
class FavoriteApiController extends ApiController {
/** @var StationService */
private $service;
/** @var string */
private $userId;
use Errors;
public function __construct(IRequest $request,
StationService $service,
$userId) {
parent::__construct(Application::APP_ID, $request);
$this->service = $service;
$this->userId = $userId;
}
/**
* @CORS
* @NoCSRFRequired
* @NoAdminRequired
*/
public function index(): DataResponse {
return new DataResponse($this->service->findAll($this->userId));
}
/**
* @CORS
* @NoCSRFRequired
* @NoAdminRequired
*/
public function show(int $id): DataResponse {
return $this->handleNotFound(function () use ($id) {
return $this->service->find($id, $this->userId);
});
}
/**
* @CORS
* @NoCSRFRequired
* @NoAdminRequired
*/
public function create(string $stationuuid, string $name, string $favicon, string $urlresolved): DataResponse {
return new DataResponse($this->service->create($stationuuid, $name,
$favicon, $urlresolved, $this->userId));
}
/**
* @CORS
* @NoCSRFRequired
* @NoAdminRequired
*/
public function update(int $id, string $title,
string $content): DataResponse {
return $this->handleNotFound(function () use ($id, $stationuuid, $name, $favicon, $urlresolved) {
return $this->service->update($id, $stationuuid, $name, $favicon, $urlresolved, $this->userId);
});
}
/**
* @CORS
* @NoCSRFRequired
* @NoAdminRequired
*/
public function destroy(int $id): DataResponse {
return $this->handleNotFound(function () use ($id) {
return $this->service->delete($id, $this->userId);
});
}
}

View File

@ -44,7 +44,7 @@ class FavoriteController extends Controller {
/**
* @NoAdminRequired
*/
public function create(string $stationuuid, string $name, string $favicon, string $urlresolved = "lol"): DataResponse {
public function create(string $stationuuid, string $name, string $favicon, string $urlresolved): DataResponse {
return new DataResponse($this->service->create($stationuuid, $name,
$favicon, $urlresolved, $this->userId));
}

View File

@ -19,7 +19,7 @@ class Station extends Entity implements JsonSerializable {
'stationuuid' => $this->stationuuid,
'name' => $this->name,
'favicon' => $this->favicon,
'url_resolved' => $this->urlresolved
'urlresolved' => $this->urlresolved
];
}
}

View File

@ -71,7 +71,6 @@ export default {
},
data: () => ({
tableData: [],
offset: 0,
pageLoading: false,
blurHashes: require('../assets/blurHashes.json'),
favorites: null,
@ -107,8 +106,8 @@ export default {
methods: {
async onRoute() {
this.offset = 0
this.tableData = []
this.pageLoading = true
const route = this.$route
this.loadStations(route.name)
},
@ -136,8 +135,15 @@ export default {
}
} else {
try {
const stationMap = {
id: -1,
name: station.name,
urlresolved: station.url_resolved,
favicon: station.favicon,
stationuuid: station.stationuuid,
}
await axios
.post(generateUrl('/apps/radio/api/favorites'), station)
.post(generateUrl('/apps/radio/api/favorites'), stationMap)
.then(response => {
this.favorites.push([response.data.id, station.stationuuid])
})
@ -159,8 +165,14 @@ export default {
}
vm.$store.dispatch('setTitle', station.name)
let stationSrc = ''
if (!station.url_resolved) {
stationSrc = station.urlresolved
} else {
stationSrc = station.url_resolved
}
audioPlayer = new Howl({
src: [station.url_resolved],
src: stationSrc,
volume: vm.player.volume,
/* onfade() { // FIXME
if (this.volume() === 0) {
@ -202,11 +214,6 @@ export default {
let queryURI = queryBase
let sortBy = 'clickcount'
// Inital page loading
if (vm.offset === 0) {
vm.pageLoading = true
}
if (vm.$route.name === 'CATEGORIES') {
vm.tableData = [
{
@ -234,8 +241,8 @@ export default {
return true
}
// Skip loading more stations on certain sites
if (vm.offset > 0
// FIXME: Skip loading more stations on certain sites
if (vm.tableData.length > 0
&& (vm.$route.name === 'FAVORITES'
|| vm.$route.name === 'RECENT')) {
return true
@ -246,9 +253,7 @@ export default {
} else if (menuState === 'NEW') {
sortBy = 'lastchangetime'
} else if (menuState === 'SEARCH') {
// const searchQuery = vm.$route.hash.substr(1)
const searchQuery = vm.$route.params.query
console.log(searchQuery)
queryURI = queryBase + '/byname/' + searchQuery
} else if (menuState === 'FAVORITES') {
queryURI = generateUrl('/apps/radio/api/favorites')
@ -259,7 +264,7 @@ export default {
limit: 20,
order: sortBy,
reverse: true,
offset: vm.offset,
offset: vm.tableData.length,
},
})
.then(function(response) {
@ -272,7 +277,6 @@ export default {
response.data[i].blurHash = blurHash
}
vm.tableData = vm.tableData.concat(response.data)
vm.offset += 20
vm.pageLoading = false
})
},

View File

@ -54,10 +54,6 @@ export default {
<style>
#app-settings {
margin-bottom: -5px;
}
.wrap {
background: var(--color-main-background);
border: 3px solid #0082c9;