Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 2, 2023
1 parent 0ca6deb commit c5ab712
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ protected function handleSource(?AssetSourceInput $source, Workspace $workspace)
$file = new File();
$file->setPath($source->url);
$file->setOriginalName($source->originalName);
$file->setExtension(FileUtil::getExtensionFromPath($source->originalName ?: $source->url));
$extension = FileUtil::getExtensionFromPath($source->originalName ?: $source->url);
$file->setExtension($extension);
$file->setType($source->type ?? FileUtil::getTypeFromExtension($extension));
$file->setPathPublic(!$source->isPrivate);
$file->setStorage(File::STORAGE_URL);
$file->setWorkspace($workspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function transform(object $data, string $resourceClass, array $context =
throw new BadRequestHttpException('Rendition input error: You must provide either "name" or "definitionId"');
}
$rendition = $this->renditionManager->getOrCreateRendition($object, $definition);
$file = $this->handleSource($renditionInput->source, $workspace);
$file = $this->handleSource($renditionInput->sourceFile, $workspace);
$rendition->setFile($file);

$this->em->persist($rendition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function transform(object $data, string $resourceClass, array $context =

$workspace = $object->getAsset()->getWorkspace();

if (null !== $file = $this->handleSource($data->source, $workspace)) {
if (null !== $file = $this->handleSource($data->sourceFile, $workspace)) {
$object->setFile($file);
} elseif (null !== $file = $this->handleFromFile($data->sourceFileId)) {
$this->postFlushStackListener->addEvent(CopyFileToRenditionHandler::createEvent($object->getId(), $file->getId()));
Expand Down
1 change: 1 addition & 0 deletions databox/api/src/Api/Model/Input/AssetSourceInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AssetSourceInput
public ?string $url = null;

public ?string $originalName = null;
public ?string $type = null;

public bool $isPrivate = false;

Expand Down
2 changes: 1 addition & 1 deletion databox/api/src/Api/Model/Input/RenditionInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RenditionInput
/**
* @var AssetSourceInput|null
*/
public $source;
public $sourceFile;

/**
* @var string|null
Expand Down
2 changes: 1 addition & 1 deletion databox/client/src/components/Dialog/Asset/InfoAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function InfoAsset({
<Divider/>
<InfoRow
label={'Owner'}
value={data.owner?.username ?? '-'}
value={data.owner?.username ?? data.owner?.id ?? '-'}
copyValue={data.owner?.id}
icon={<PersonIcon/>}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function InfoCollection({
<Divider/>
<InfoRow
label={'Owner'}
value={data.owner?.username ?? '-'}
value={data.owner?.username ?? data.owner?.id ?? '-'}
copyValue={data.owner?.id}
icon={<PersonIcon/>}
/>
Expand Down
2 changes: 1 addition & 1 deletion databox/client/src/components/Media/Asset/FilePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ export default function FilePlayer({
width: '100%',
height: '100%',
}}
></div>
>Unsupported format</div>
}
}
1 change: 1 addition & 0 deletions databox/indexer/src/databox/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Source = {
isPrivate?: boolean;
alternateUrls?: AlternateUrl[];
importFile?: boolean;
type?: string;
};

export type AssetInput = {
Expand Down
1 change: 1 addition & 0 deletions databox/indexer/src/handlers/phraseanet/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function createAsset(
url: s.permalink.url,
isPrivate: false,
importFile: importFiles,
type: s.mime_type,
}
};
}).filter(s => Boolean(s)),
Expand Down
1 change: 1 addition & 0 deletions databox/indexer/src/handlers/phraseanet/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type PhraseanetConfig = {

export type SubDef = {
name: string;
mime_type?: string;
permalink: {
url: string;
}
Expand Down
22 changes: 15 additions & 7 deletions lib/php/auth-bundle/Client/KeycloakClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Alchemy\AuthBundle\Client;

use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Exception\ClientException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Symfony\Contracts\Cache\CacheInterface;
Expand All @@ -18,6 +19,7 @@ public function __construct(
private CacheInterface $keycloakRealmCache,
private string $clientId,
private string $clientSecret,
private LoggerInterface $logger,
) {
}

Expand Down Expand Up @@ -110,13 +112,19 @@ public function createUser(array $data, string $accessToken): array

public function getUser(string $accessToken, string $userId, array $options = []): ?array
{
return $this->wrapRequest(function () use ($userId, $accessToken, $options) {
return $this->keycloakClient->request('GET', sprintf('%s/%s', $this->urlGenerator->getUsersApiUrl(), $userId), array_merge([
'headers' => [
'Authorization' => 'Bearer '.$accessToken,
],
], $options));
});
try {
return $this->wrapRequest(function () use ($userId, $accessToken, $options) {
return $this->keycloakClient->request('GET', sprintf('%s/%s', $this->urlGenerator->getUsersApiUrl(), $userId), array_merge([
'headers' => [
'Authorization' => 'Bearer '.$accessToken,
],
], $options));
});
} catch (ClientException $e) {
$this->logger->error($e->getMessage());

return null;
}
}

public function getUsers(string $accessToken, int $limit = null, int $offset = null, array $options = []): array
Expand Down
4 changes: 2 additions & 2 deletions lib/php/auth-bundle/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function getUsers(int $limit = null, int $offset = null): array

public function getUser(string $userId): ?array
{
return $this->keycloakRealmCache->get('users_'.$userId, function () use ($userId): array {
return $this->executeWithAccessToken(fn (string $accessToken): array => $this->oauthClient->getUser($accessToken, $userId));
return $this->keycloakRealmCache->get('users_'.$userId, function () use ($userId): ?array {
return $this->executeWithAccessToken(fn (string $accessToken): ?array => $this->oauthClient->getUser($accessToken, $userId));
});
}

Expand Down

0 comments on commit c5ab712

Please sign in to comment.