Skip to content

Commit

Permalink
PS-636 expose attributes (#435)
Browse files Browse the repository at this point in the history
* PS-636 expose - fix webvtt
* add REMOVE_BG_API_KEY default value for integration
* expose: add translations
  • Loading branch information
4rthem authored Apr 29, 2024
1 parent ba38566 commit 83d863a
Show file tree
Hide file tree
Showing 37 changed files with 405 additions and 157 deletions.
2 changes: 2 additions & 0 deletions databox/api/src/Api/InputTransformerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Api;

use ApiPlatform\Documentation\Documentation;
use ApiPlatform\Documentation\Entrypoint;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\OpenApi\OpenApi;
Expand Down Expand Up @@ -40,6 +41,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if (!is_object($data)
|| $data instanceof Entrypoint
|| $data instanceof OpenApi
|| $data instanceof Documentation
) {
return $data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getWorkflowJobDefinitions(array $config, Workflow $workflow): it

public static function getTitle(): string
{
return 'Phraseanet renditions';
return 'Phraseanet Renditions';
}

public static function getName(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function buildConfiguration(NodeBuilder $builder): void
{
$builder
->scalarNode('apiKey')
->isRequired()
->defaultValue('${REMOVE_BG_API_KEY}')
->cannotBeEmpty()
->end()
->booleanNode('processIncoming')
Expand Down
30 changes: 30 additions & 0 deletions expose/api/migrations/Version20240424150209.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240424150209 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->addSql('UPDATE asset SET web_vtt = NULL');
$this->addSql('ALTER TABLE asset ALTER web_vtt TYPE JSON USING web_vtt::json');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE asset ALTER web_vtt TYPE TEXT');
}
}
29 changes: 29 additions & 0 deletions expose/api/migrations/Version20240429095720.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240429095720 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE asset ADD translations JSON DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE asset DROP translations');
}
}
29 changes: 29 additions & 0 deletions expose/api/migrations/Version20240429145217.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240429145217 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE publication ADD translations JSON DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE publication DROP translations');
}
}
68 changes: 37 additions & 31 deletions expose/api/src/Controller/Admin/AssetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Alchemy\AdminBundle\Controller\AbstractAdminCrudController;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\JsonField;
use App\Entity\Asset;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
Expand Down Expand Up @@ -37,36 +38,41 @@ public function configureCrud(Crud $crud): Crud

public function configureFields(string $pageName): iterable
{
$id = IdField::new();
$originalName = TextField::new('originalName');
$description = TextareaField::new('description');
$lat = NumberField::new('lat');
$lng = NumberField::new('lng');
$altitude = NumberField::new('altitude');
$webVTT = TextareaField::new('webVTT');
$clientAnnotations = TextareaField::new('clientAnnotations');
$assetId = IdField::new('assetId');
$path = TextField::new('path');
$size = IntegerField::new('size')->setTemplatePath('@AlchemyAdmin/list/file_size.html.twig');
$title = TextField::new('title');
$mimeType = TextField::new('mimeType');
$ownerId = IdField::new('ownerId');
$createdAt = DateTimeField::new('createdAt');
$publication = AssociationField::new('publication');
$subDefinitions = AssociationField::new('subDefinitions');
$geoPoint = TextareaField::new('geoPoint');
$position = NumberField::new('position');

if (Crud::PAGE_INDEX === $pageName) {
return [$id, $publication, $title, $originalName, $size, $geoPoint, $path, $position, $createdAt];
} elseif (Crud::PAGE_DETAIL === $pageName) {
return [$id, $assetId, $title, $path, $size, $publication, $description, $originalName, $mimeType, $ownerId, $lat, $lng, $webVTT, $altitude, $createdAt, $clientAnnotations, $subDefinitions];
} elseif (Crud::PAGE_NEW === $pageName) {
return [$publication, $title, $originalName, $description, $lat, $lng, $altitude, $webVTT, $clientAnnotations];
} elseif (Crud::PAGE_EDIT === $pageName) {
return [$publication, $title, $originalName, $description, $lat, $lng, $altitude, $webVTT, $clientAnnotations];
}

return [];
yield IdField::new();
yield TextField::new('title');
yield AssociationField::new('publication');
yield IdField::new('ownerId');
yield TextField::new('originalName')
->hideOnIndex();
yield TextareaField::new('description')
->hideOnIndex();
yield JsonField::new('translations')
->hideOnIndex();
yield NumberField::new('lat');
yield NumberField::new('lng');
yield NumberField::new('altitude')
->hideOnIndex();
yield JsonField::new('webVTT')
->hideOnIndex();
yield JsonField::new('clientAnnotations')
->hideOnIndex();
yield IdField::new('assetId')
->hideOnIndex();
yield TextField::new('path')
->hideOnIndex();
yield IntegerField::new('size')
->setTemplatePath('@AlchemyAdmin/list/file_size.html.twig');
yield TextField::new('mimeType');
yield DateTimeField::new('createdAt')
->hideOnForm()
;
yield AssociationField::new('subDefinitions')
->hideOnIndex()
->hideOnForm()
;
yield TextareaField::new('geoPoint')
->hideOnForm()
->hideOnIndex();
yield NumberField::new('position');
}
}
55 changes: 28 additions & 27 deletions expose/api/src/Controller/Admin/PublicationCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Alchemy\AclBundle\Admin\PermissionView;
use Alchemy\AdminBundle\Controller\Acl\AbstractAclAdminCrudController;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\JsonField;
use App\Entity\Publication;
use App\Field\PublicationConfigField;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
Expand Down Expand Up @@ -36,34 +37,34 @@ public function configureCrud(Crud $crud): Crud

public function configureFields(string $pageName): iterable
{
$parent = AssociationField::new('parent')
yield AssociationField::new('parent')
->setRequired(false);
$title = TextField::new('title')->setTemplatePath('admin/list/publication_title_link.html.twig');
$description = TextareaField::new('description');
$slug = TextField::new('slug');
$profile = AssociationField::new('profile')
yield TextField::new('title')
->setTemplatePath('admin/list/publication_title_link.html.twig');
yield TextareaField::new('description')
->hideOnIndex();
yield TextField::new('slug');
yield AssociationField::new('profile')
->setRequired(false);
$date = DateTimeField::new('date');
$config = PublicationConfigField::new('config');
$ownerId = TextField::new('ownerId');
$clientAnnotations = TextareaField::new('clientAnnotations');
$zippyId = TextField::new('zippyId');
$id = IdField::new();
$createdAt = DateTimeField::new('createdAt');
$childrenCount = IntegerField::new('children.count', 'Children');
$assetsCount = IntegerField::new('assets.count', 'Assets');
$publiclyListed = BooleanField::new('publiclyListed')->renderAsSwitch(false);
$enabled = BooleanField::new('enabled')->renderAsSwitch(false);
$securityMethod = TextareaField::new('securityMethod');

if (Crud::PAGE_INDEX === $pageName) {
return [$id, $title, $slug, $profile, $parent, $childrenCount, $assetsCount, $publiclyListed, $enabled, $securityMethod, $createdAt];
} elseif (Crud::PAGE_NEW === $pageName) {
return [$parent, $title, $description, $slug, $profile, $date, $config, $ownerId, $clientAnnotations, $zippyId];
} elseif (Crud::PAGE_EDIT === $pageName) {
return [$parent, $title, $description, $slug, $profile, $date, $config, $ownerId, $clientAnnotations, $zippyId];
}

return [];
yield DateTimeField::new('date');
yield PublicationConfigField::new('config')
->hideOnIndex()
;
yield TextField::new('ownerId');
yield JsonField::new('clientAnnotations')
->hideOnIndex();
yield TextField::new('zippyId')
->hideOnIndex();
yield IdField::new();
yield DateTimeField::new('createdAt')
->hideOnForm();
yield JsonField::new('translations');
yield IntegerField::new('children.count', 'Children');
yield IntegerField::new('assets.count', 'Assets');
yield BooleanField::new('publiclyListed')
->renderAsSwitch(false);
yield BooleanField::new('enabled')
->renderAsSwitch(false);
yield TextareaField::new('securityMethod');
}
}
11 changes: 8 additions & 3 deletions expose/api/src/Controller/GetAssetWebVTTAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;

#[Route(path: '/publications/{id}/vtt/{hash}.vtt', name: 'asset_webvtt')]
#[Route(path: '/publications/{id}/vtt/{vttId}.vtt', name: 'asset_webvtt')]
final class GetAssetWebVTTAction extends AbstractController
{
public function __construct(private readonly EntityManagerInterface $em)
{
}

public function __invoke(string $id, string $hash, Request $request): Response
public function __invoke(string $id, string $vttId, Request $request): Response
{
$corsHeaders = [
'Access-Control-Allow-Origin' => '*',
Expand All @@ -43,7 +43,12 @@ public function __invoke(string $id, string $hash, Request $request): Response

$this->denyAccessUnlessGranted(AssetVoter::READ, $asset);

$response = new Response($asset->getWebVTT(), 200, [...$corsHeaders, 'Content-Type' => 'text/vtt']);
$webVTT = $asset->getWebVTTById($vttId);
if (null === $webVTT) {
throw new NotFoundHttpException(sprintf('WebVTT "%s" not found.', $vttId));
}

$response = new Response($webVTT['content'], 200, [...$corsHeaders, 'Content-Type' => 'text/vtt']);
$response->setCache([
's_maxage' => 7_776_000,
'max_age' => 7_776_000,
Expand Down
Loading

0 comments on commit 83d863a

Please sign in to comment.