Move SHOUTcast 2 installation to Vue/API (with Flow upload).

This commit is contained in:
Buster "Silver Eagle" Neece 2021-10-13 10:24:56 -05:00
parent 6fb86c80e9
commit 765d7c2fe2
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
10 changed files with 231 additions and 148 deletions

View File

@ -1,53 +0,0 @@
<?php
return [
'method' => 'post',
'enctype' => 'multipart/form-data',
'groups' => [
[
'use_grid' => true,
'elements' => [
'details' => [
'markup',
[
'label' => __('Instructions'),
'markup' => __('<p>SHOUTcast 2 DNAS is not free software, and its restrictive license does not allow AzuraCast to distribute the SHOUTcast binary. In order to install SHOUTcast, you should download the Linux x64 binary from the <a href="%s" target="_blank">SHOUTcast Radio Manager</a> web site. Upload the <code>sc_serv2_linux_x64-latest.tar.gz</code> into the field below to automatically extract it into the proper directory.</p>',
'https://radiomanager.shoutcast.com/register/serverSoftwareFreemium'),
'form_group_class' => 'col-sm-12',
],
],
'current_version' => [
'markup',
[
'label' => __('Current Installed Version'),
'markup' => '<p class="text-danger">' . __('SHOUTcast is not currently installed on this installation.') . '</p>',
'form_group_class' => 'col-sm-12',
],
],
'binary' => [
'file',
[
'label' => __('Select SHOUTcast 64-bit .tar.gz File'),
'required' => true,
'type' => 'archive',
'form_group_class' => 'col-md-6',
'button_text' => __('Select File'),
'button_icon' => 'cloud_upload',
],
],
'submit' => [
'submit',
[
'type' => 'submit',
'label' => __('Upload'),
'class' => 'ui-button btn-lg btn-primary',
'form_group_class' => 'col-sm-12',
],
],
],
],
],
];

View File

@ -53,7 +53,7 @@ return static function (RouteCollectorProxy $app) {
$group->group(
'/install',
function (RouteCollectorProxy $group) {
$group->map(['GET', 'POST'], '/shoutcast', Controller\Admin\InstallShoutcastController::class)
$group->get('/shoutcast', Controller\Admin\ShoutcastAction::class)
->setName('admin:install_shoutcast:index');
$group->get('/geolite', Controller\Admin\GeoLiteAction::class)

View File

@ -183,6 +183,16 @@ return static function (RouteCollectorProxy $app) {
'/geolite',
Controller\Api\Admin\GeoLite\PostAction::class
);
$group->get(
'/shoutcast',
Controller\Api\Admin\Shoutcast\GetAction::class
)->setName('api:admin:shoutcast');
$group->post(
'/shoutcast',
Controller\Api\Admin\Shoutcast\PostAction::class
);
}
)->add(new Middleware\Permissions(Acl::GLOBAL_SETTINGS));

View File

@ -0,0 +1,105 @@
<template>
<div class="card">
<div class="card-header bg-primary-dark">
<h2 class="card-title">
<translate key="lang_title">Install SHOUTcast 2 DNAS</translate>
</h2>
</div>
<div class="card-body">
<b-overlay variant="card" :show="loading">
<b-form-row>
<div class="col-md-7">
<fieldset>
<legend>
<translate key="lang_instructions">Instructions</translate>
</legend>
<p class="card-text">
<translate key="lang_instructions_1a">SHOUTcast 2 DNAS is not free software, and its restrictive license does not allow AzuraCast to distribute the SHOUTcast binary.</translate>
</p>
<p class="card-text">
<translate key="lang_instructions_1b">In order to install SHOUTcast:</translate>
</p>
<ul>
<li>
<translate key="lang_instructions_2">Download the Linux x64 binary from the SHOUTcast Radio Manager:</translate>
<br>
<a href="https://radiomanager.shoutcast.com/register/serverSoftwareFreemium"
target="_blank">
<translate key="lang_instructions_2_url">SHOUTcast Radio Manager</translate>
</a>
</li>
<li>
<translate key="lang_instructions_3">The file name should look like:</translate>
<br>
<code>sc_serv2_linux_x64-latest.tar.gz</code>
</li>
<li>
<translate key="lang_instructions_4">Upload the file on this page to automatically extract it into the proper directory.</translate>
</li>
</ul>
</fieldset>
</div>
<div class="col-md-5">
<fieldset class="mb-3">
<legend>
<translate key="lang_current_version">Current Installed Version</translate>
</legend>
<p v-if="version" class="text-success card-text">
{{ langInstalledVersion }}
</p>
<p v-else class="text-danger card-text">
<translate
key="lang_not_installed">SHOUTcast 2 DNAS is not currently installed on this installation.</translate>
</p>
</fieldset>
<flow-upload :target-url="apiUrl" @complete="relist"></flow-upload>
</div>
</b-form-row>
</b-overlay>
</div>
</div>
</template>
<script>
import FlowUpload from "~/components/Common/FlowUpload";
export default {
name: 'AdminShoutcast',
components: {FlowUpload},
props: {
apiUrl: String
},
data() {
return {
loading: true,
version: null,
};
},
computed: {
langInstalledVersion() {
const text = this.$gettext('SHOUTcast version "%{ version }" is currently installed.');
return this.$gettextInterpolate(text, {
version: this.version
});
}
},
mounted() {
this.relist();
},
methods: {
relist() {
this.loading = true;
this.axios.get(this.apiUrl).then((resp) => {
this.version = resp.data.version;
this.loading = false;
});
}
}
}
</script>

View File

@ -0,0 +1,7 @@
import initBase from '~/base.js';
import '~/vendor/bootstrapVue.js';
import AdminShoutcast from '~/components/Admin/Shoutcast.vue';
export default initBase(AdminShoutcast);

View File

@ -13,6 +13,7 @@ module.exports = {
AdminGeoLite: '~/pages/Admin/GeoLite.js',
AdminPermissions: '~/pages/Admin/Permissions.js',
AdminSettings: '~/pages/Admin/Settings.js',
AdminShoutcast: '~/pages/Admin/Shoutcast.js',
AdminStorageLocations: '~/pages/Admin/StorageLocations.js',
PublicFullPlayer: '~/pages/Public/FullPlayer.js',
PublicHistory: '~/pages/Public/History.js',

View File

@ -1,94 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Controller\Admin;
use App\Config;
use App\Environment;
use App\Form\Form;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Radio\Frontend\SHOUTcast;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UploadedFileInterface;
use Symfony\Component\Process\Process;
class InstallShoutcastController
{
protected array $form_config;
public function __construct(
protected SHOUTcast $adapter,
Config $config
) {
$this->form_config = $config->get('forms/install_shoutcast');
}
public function __invoke(
ServerRequest $request,
Response $response,
Environment $environment
): ResponseInterface {
$form_config = $this->form_config;
$version = $this->adapter->getVersion();
if (null !== $version) {
$form_config['groups'][0]['elements']['current_version'][1]['markup'] = '<p class="text-success">' . __(
'SHOUTcast version "%s" is currently installed.',
$version
) . '</p>';
}
$form = new Form($form_config, []);
if ($form->isValid($request)) {
try {
$sc_base_dir = $environment->getParentDirectory() . '/servers/shoutcast2';
$values = $form->getValues();
$import_file = $values['binary'] ?? null;
if ($import_file instanceof UploadedFileInterface) {
$sc_tgz_path = $sc_base_dir . '/sc_serv.tar.gz';
if (is_file($sc_tgz_path)) {
unlink($sc_tgz_path);
}
$import_file->moveTo($sc_tgz_path);
$process = new Process(
[
'tar',
'xvzf',
$sc_tgz_path,
],
$sc_base_dir
);
$process->mustRun();
unlink($sc_tgz_path);
}
return $response->withRedirect($request->getUri()->getPath());
} catch (Exception $e) {
$form
->getField('binary')
->addError(get_class($e) . ': ' . $e->getMessage());
}
}
return $request->getView()->renderToResponse(
$response,
'system/form_page',
[
'form' => $form,
'render_mode' => 'edit',
'title' => __('Install SHOUTcast'),
]
);
}
}

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Controller\Admin;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Version;
use Psr\Http\Message\ResponseInterface;
class ShoutcastAction
{
public function __invoke(
ServerRequest $request,
Response $response,
Version $version
): ResponseInterface {
$router = $request->getRouter();
return $request->getView()->renderVuePage(
response: $response,
component: 'Vue_AdminShoutcast',
id: 'admin-shoutcast',
title: __('Install SHOUTcast 2 DNAS'),
props: [
'apiUrl' => (string)$router->named('api:admin:shoutcast'),
],
);
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Controller\Api\Admin\Shoutcast;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Radio\Frontend\SHOUTcast;
use Psr\Http\Message\ResponseInterface;
class GetAction
{
public function __invoke(
ServerRequest $request,
Response $response,
SHOUTcast $shoutcast
): ResponseInterface {
return $response->withJson(
[
'success' => true,
'version' => $shoutcast->getVersion(),
]
);
}
}

View File

@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace App\Controller\Api\Admin\Shoutcast;
use App\Entity;
use App\Environment;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Service\Flow;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Process\Process;
class PostAction
{
public function __invoke(
ServerRequest $request,
Response $response,
Environment $environment
): ResponseInterface {
$flowResponse = Flow::process($request, $response);
if ($flowResponse instanceof ResponseInterface) {
return $flowResponse;
}
$scBaseDir = $environment->getParentDirectory() . '/servers/shoutcast2';
$scTgzPath = $scBaseDir . '/sc_serv.tar.gz';
if (is_file($scTgzPath)) {
unlink($scTgzPath);
}
$flowResponse->moveTo($scTgzPath);
$process = new Process(
[
'tar',
'xvzf',
$scTgzPath,
],
$scBaseDir
);
$process->mustRun();
unlink($scTgzPath);
return $response->withJson(Entity\Api\Status::success());
}
}