mirror of
https://github.com/r4sas/recastin-panel
synced 2025-03-12 13:21:14 +00:00
Added error message callback, make stream name and user_id unique
This commit is contained in:
parent
f83c344d14
commit
b5731a28d9
@ -80,7 +80,20 @@
|
||||
save: function () {
|
||||
this.axios.post('/streams/' + this.$route.params.streamId + '/endpoints/update', this.endpoint).then(() => {
|
||||
this.$router.push('/ucp/streams/' + this.$route.params.streamId + '/');
|
||||
})
|
||||
}).catch(error => {
|
||||
const notification = {
|
||||
template: `<span>${error.response.data.message}</span>`
|
||||
};
|
||||
|
||||
this.$notify(
|
||||
{
|
||||
component: notification,
|
||||
icon: 'fa fa-exclamation-triangle',
|
||||
horizontalAlign: 'right',
|
||||
verticalAlign: 'top',
|
||||
type: 'danger'
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -83,7 +83,20 @@
|
||||
save: function () {
|
||||
this.axios.post('/streams/update', this.stream).then(() => {
|
||||
this.$router.push('/ucp/streams/');
|
||||
})
|
||||
}).catch(error => {
|
||||
const notification = {
|
||||
template: `<span>${error.response.data.message}</span>`
|
||||
};
|
||||
|
||||
this.$notify(
|
||||
{
|
||||
component: notification,
|
||||
icon: 'fa fa-exclamation-triangle',
|
||||
horizontalAlign: 'right',
|
||||
verticalAlign: 'top',
|
||||
type: 'danger'
|
||||
});
|
||||
});
|
||||
},
|
||||
deleteEndpoint: function (endpoint) {
|
||||
this.endpoints.splice(this.endpoints.indexOf(endpoint), 1);
|
||||
|
@ -4,7 +4,6 @@ namespace App\Controller;
|
||||
|
||||
use App\Entity\Streams;
|
||||
use App\Repository\StreamsRepository;
|
||||
use Doctrine\Common\Util\Debug;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
@ -3,13 +3,12 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Component\Forms\Endpoint as EndpointForm;
|
||||
use App\Component\Forms\Streams as StreamsForm;
|
||||
use App\Component\ServiceManager;
|
||||
use App\Entity\Endpoint;
|
||||
use App\Entity\User;
|
||||
use App\Repository\EndpointRepository;
|
||||
use App\Repository\StreamsRepository;
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@ -96,14 +95,22 @@ class Streams extends Controller
|
||||
return new Response('Access denied', 401);
|
||||
}
|
||||
|
||||
if (empty($requestBody['name']) || !$this->isValidString($requestBody['name'])) {
|
||||
return new JsonResponse(['message' => 'Name is empty or contains illegal strings'], 500);
|
||||
}
|
||||
|
||||
$stream->setUser($this->getUser());
|
||||
$stream->setName($requestBody['name']);
|
||||
$stream->setActive($requestBody['active']);
|
||||
|
||||
$manager = $this->get('doctrine.orm.entity_manager');
|
||||
|
||||
$manager->persist($stream);
|
||||
$manager->flush();
|
||||
try {
|
||||
$manager->persist($stream);
|
||||
$manager->flush();
|
||||
} catch (UniqueConstraintViolationException $e) {
|
||||
return new JsonResponse(['message' => sprintf('"%s" is already taken', $stream->getName())], 500);
|
||||
}
|
||||
|
||||
return new JsonResponse($stream);
|
||||
}
|
||||
@ -205,6 +212,18 @@ class Streams extends Controller
|
||||
return new JsonResponse([]);
|
||||
}
|
||||
|
||||
if (empty($requestBody['name'])) {
|
||||
return new JsonResponse(['message' => 'Name is empty'], 500);
|
||||
}
|
||||
|
||||
if (empty($requestBody['server']) || !$this->isValidString($requestBody['server'])) {
|
||||
return new JsonResponse(['message' => 'Server is empty or contains illegal strings'], 500);
|
||||
}
|
||||
|
||||
if (!empty($requestBody['streamKey']) && !$this->isValidString($requestBody['streamKey'])) {
|
||||
return new JsonResponse(['message' => 'Stream-Key contains illegal strings'], 500);
|
||||
}
|
||||
|
||||
$endpoint = !empty($requestBody['id']) ? $this->endpointRepository->find($requestBody['id']) : new Endpoint();
|
||||
|
||||
$endpoint->setName($requestBody['name']);
|
||||
@ -243,4 +262,14 @@ class Streams extends Controller
|
||||
|
||||
return new JsonResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $string
|
||||
* @return false|int
|
||||
* @author Soner Sayakci <shyim@posteo.de>
|
||||
*/
|
||||
private function isValidString(?string $string)
|
||||
{
|
||||
return preg_match('/^[a-z|A-Z|a-z|A-Z|0-9|.|\-|_|]+$/', $string);
|
||||
}
|
||||
}
|
@ -5,9 +5,17 @@ namespace App\Entity;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\Mapping\UniqueConstraint;
|
||||
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="App\Repository\StreamsRepository")
|
||||
* @ORM\Table(name="streams",
|
||||
* uniqueConstraints={
|
||||
* @UniqueConstraint(name="stream_name",
|
||||
* columns={"name", "user_id"})
|
||||
* }
|
||||
* )
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
*/
|
||||
class Streams implements \JsonSerializable
|
||||
@ -21,7 +29,7 @@ class Streams implements \JsonSerializable
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255, nullable=false)
|
||||
* @ORM\Column(type="string", length=50, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
38
src/Migrations/Version20180425210736.php
Normal file
38
src/Migrations/Version20180425210736.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20180425210736 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('CREATE TABLE streams (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, name VARCHAR(255) NOT NULL, active TINYINT(1) NOT NULL, live TINYINT(1) DEFAULT \'0\' NOT NULL, stream_key VARCHAR(255) NOT NULL, INDEX IDX_FFF7AFAA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(100) NOT NULL, password VARCHAR(255) NOT NULL, email VARCHAR(100) NOT NULL, role VARCHAR(255) DEFAULT \'user\' NOT NULL, created_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_8D93D649F85E0677 (username), UNIQUE INDEX UNIQ_8D93D649E7927C74 (email), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('CREATE TABLE endpoint (id INT AUTO_INCREMENT NOT NULL, stream_id INT DEFAULT NULL, active TINYINT(1) DEFAULT \'1\' NOT NULL, name VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, server VARCHAR(255) NOT NULL, streamKey VARCHAR(255) NOT NULL, INDEX IDX_C4420F7BD0ED463E (stream_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('CREATE TABLE queue (id INT AUTO_INCREMENT NOT NULL, task VARCHAR(100) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
|
||||
$this->addSql('ALTER TABLE streams ADD CONSTRAINT FK_FFF7AFAA76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
|
||||
$this->addSql('ALTER TABLE endpoint ADD CONSTRAINT FK_C4420F7BD0ED463E FOREIGN KEY (stream_id) REFERENCES streams (id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE endpoint DROP FOREIGN KEY FK_C4420F7BD0ED463E');
|
||||
$this->addSql('ALTER TABLE streams DROP FOREIGN KEY FK_FFF7AFAA76ED395');
|
||||
$this->addSql('DROP TABLE streams');
|
||||
$this->addSql('DROP TABLE user');
|
||||
$this->addSql('DROP TABLE endpoint');
|
||||
$this->addSql('DROP TABLE queue');
|
||||
}
|
||||
}
|
30
src/Migrations/Version20180425213959.php
Normal file
30
src/Migrations/Version20180425213959.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20180425213959 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE streams CHANGE name name VARCHAR(50) NOT NULL');
|
||||
$this->addSql('CREATE UNIQUE INDEX stream_name ON streams (name, user_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('DROP INDEX stream_name ON streams');
|
||||
$this->addSql('ALTER TABLE streams CHANGE name name VARCHAR(255) NOT NULL COLLATE utf8mb4_unicode_ci');
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ use App\Entity\User;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Bridge\Doctrine\RegistryInterface;
|
||||
use Symfony\Bundle\MakerBundle\Str;
|
||||
|
||||
/**
|
||||
* @method Streams|null find($id, $lockMode = null, $lockVersion = null)
|
||||
@ -67,12 +66,9 @@ class StreamsRepository extends ServiceEntityRepository
|
||||
public function getStreamByNameAndUsername(string $streamName, string $userName, string $streamKey): ?Streams
|
||||
{
|
||||
$qb = $this->createQueryBuilder('streams')
|
||||
->addSelect('endpoints')
|
||||
->addSelect('user')
|
||||
->leftJoin('streams.endpoints', 'endpoints')
|
||||
->innerJoin('streams.user', 'user')
|
||||
->andWhere('streams.active = true')
|
||||
->andWhere('endpoints.active = true')
|
||||
->andWhere('streams.name = :streamName')
|
||||
->andWhere('user.username = :userName')
|
||||
->andWhere('streams.streamKey = :streamKey')
|
||||
|
Loading…
x
Reference in New Issue
Block a user