further work on export favorites as playlist
This commit is contained in:
parent
49825a038f
commit
7813cf4a51
@ -24,11 +24,11 @@
|
|||||||
namespace OCA\Radio\Controller;
|
namespace OCA\Radio\Controller;
|
||||||
|
|
||||||
use OC;
|
use OC;
|
||||||
|
use OCA\Radio\ExportResponse;
|
||||||
use OCA\Radio\AppInfo\Application;
|
use OCA\Radio\AppInfo\Application;
|
||||||
use OCA\Radio\Service\FavoriteService;
|
use OCA\Radio\Service\FavoriteService;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\DataResponse; // FIXME: Remove if not required
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\Http\Response;
|
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use SimpleXMLElement;
|
use SimpleXMLElement;
|
||||||
|
|
||||||
@ -53,6 +53,7 @@ class ExportController extends Controller {
|
|||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
|
|
||||||
$xml = new SimpleXMLElement('<?xml version="1.0"?><playlist></playlist>');
|
$xml = new SimpleXMLElement('<?xml version="1.0"?><playlist></playlist>');
|
||||||
$xml->addAttribute('encoding', 'UTF-8');
|
$xml->addAttribute('encoding', 'UTF-8');
|
||||||
$trackList = $xml->addChild('trackList');
|
$trackList = $xml->addChild('trackList');
|
||||||
@ -61,24 +62,8 @@ class ExportController extends Controller {
|
|||||||
$track->addChild('title', 'Radio Test 404fm');
|
$track->addChild('title', 'Radio Test 404fm');
|
||||||
$track->addChild('image', 'http://localhost/favicon.ico');
|
$track->addChild('image', 'http://localhost/favicon.ico');
|
||||||
|
|
||||||
$user = OC::$server->getUserSession()->getUser();
|
return new ExportResponse($xml->asXML());
|
||||||
if (is_null($user)) {
|
|
||||||
throw new HintException('User not logged in');
|
|
||||||
}
|
|
||||||
|
|
||||||
$userName = $user->getDisplayName();
|
|
||||||
$productName = OC::$server->getThemingDefaults()->getName();
|
|
||||||
$dateTime = OC::$server->getDateTimeFormatter();
|
|
||||||
|
|
||||||
$export_name = '"' . $productName . ' Radio Favorites (' . $userName . ') (' . $dateTime->formatDate(time()) . ').xspf"';
|
|
||||||
|
|
||||||
$response = new Response();
|
|
||||||
$response->addHeader('Content-Type', 'application/xspf+xml');
|
|
||||||
$response->addHeader('Content-Disposition', 'attachment; filename=' . $export_name);
|
|
||||||
$response->render();
|
|
||||||
//return new DataResponse($this->service->findAll($this->userId));
|
|
||||||
return $response;
|
|
||||||
//return $xml->asXML();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
56
lib/ExportResponse.php
Normal file
56
lib/ExportResponse.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use OC;
|
||||||
|
use OC\HintException;
|
||||||
|
use OCP\AppFramework\Http\Response;
|
||||||
|
|
||||||
|
class ExportResponse extends Response {
|
||||||
|
private $returnstring;
|
||||||
|
|
||||||
|
public function __construct($returnstring) {
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$user = OC::$server->getUserSession()->getUser();
|
||||||
|
if (is_null($user)) {
|
||||||
|
throw new HintException('User not logged in');
|
||||||
|
}
|
||||||
|
|
||||||
|
$userName = $user->getDisplayName();
|
||||||
|
$productName = OC::$server->getThemingDefaults()->getName();
|
||||||
|
$dateTime = OC::$server->getDateTimeFormatter();
|
||||||
|
|
||||||
|
$export_name = '"' . $productName . ' Radio Favorites (' . $userName . ') (' . $dateTime->formatDate(time()) . ').xspf"';
|
||||||
|
$this->addHeader("Cache-Control", "private");
|
||||||
|
$this->addHeader("Content-Type", " application/xspf+xml");
|
||||||
|
$this->addHeader("Content-Length", strlen($returnstring));
|
||||||
|
$this->addHeader("Content-Disposition", "attachment; filename=" . $export_name);
|
||||||
|
$this->returnstring = $returnstring;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render() {
|
||||||
|
return $this->returnstring;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user