Skip to content

Commit

Permalink
fix(smtp): added frontend attachments endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jun 7, 2024
1 parent 67d0fcc commit de0057e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Sender/Frontend/Message/Attachments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Buggregator\Trap\Sender\Frontend\Message;

use Buggregator\Trap\Sender\Frontend\Event;

/**
* @internal
*/
final class Attachments implements \JsonSerializable
{
private array $data = [];

Check failure on line 14 in src/Sender/Frontend/Message/Attachments.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Property Buggregator\Trap\Sender\Frontend\Message\Attachments::$data type has no value type specified in iterable type array.

Check failure on line 14 in src/Sender/Frontend/Message/Attachments.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Property Buggregator\Trap\Sender\Frontend\Message\Attachments::$data type has no value type specified in iterable type array.

/**
* @param array<array-key, Event\AttachedFile> $files
* @param array<array-key, mixed> $meta
*/
public function __construct(
Event $event,
array $files,
public readonly array $meta = [],
) {
foreach ($files as $file) {
$this->data[] = [
'uuid' => $file->uuid,
'name' => $file->file->getClientFilename(),
'path' => "$event->uuid/attachment/$file->uuid",
'size' => $file->file->getSize(),
'mime' => $file->file->getClientMediaType(),
];
}
}

public function jsonSerialize(): array

Check failure on line 36 in src/Sender/Frontend/Message/Attachments.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Method Buggregator\Trap\Sender\Frontend\Message\Attachments::jsonSerialize() return type has no value type specified in iterable type array.

Check failure on line 36 in src/Sender/Frontend/Message/Attachments.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Method Buggregator\Trap\Sender\Frontend\Message\Attachments::jsonSerialize() return type has no value type specified in iterable type array.
{
return [
'data' => $this->data,
'meta' => $this->meta + ['grid' => []],
];
}
}
25 changes: 25 additions & 0 deletions src/Sender/Frontend/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Buggregator\Trap\Handler\Router\Attribute\StaticRoute;
use Buggregator\Trap\Handler\Router\Method;
use Buggregator\Trap\Logger;
use Buggregator\Trap\Sender\Frontend\Event\AttachedFile;
use Buggregator\Trap\Sender\Frontend\Message\Attachments;
use Buggregator\Trap\Sender\Frontend\Message\EventCollection;
use Buggregator\Trap\Sender\Frontend\Message\Settings;
use Buggregator\Trap\Sender\Frontend\Message\Success;
Expand Down Expand Up @@ -58,6 +60,29 @@ public function eventShow(string $uuid): Event|Success
return $event ?? new Success(status: false);
}

#[RegexpRoute(Method::Get, '#^api/smtp/(?<uuid>[a-f0-9-]++)/attachments$#i')]
#[
AssertSuccess(Method::Get, 'api/smtp/018ff30e-a452-7316-b60f-a2d1c3fe16ab/attachments', [
'uuid' => '018ff30e-a452-7316-b60f-a2d1c3fe16ab',
]),
]
public function smtpAttachments(string $uuid): Attachments|Success
{
$this->debug('Show SMTP %s attachments', $uuid);
$event = $this->eventsStorage->get($uuid);

if ($event === null) {
return new Success(status: false);
}

$attaches = [];
foreach ($event->assets as $attachment) {

Check failure on line 79 in src/Sender/Frontend/Service.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Argument of an invalid type ArrayAccess<string, Buggregator\Trap\Sender\Frontend\Event\Asset> supplied for foreach, only iterables are supported.

Check failure on line 79 in src/Sender/Frontend/Service.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyNullIterator

src/Sender/Frontend/Service.php:79:18: PossiblyNullIterator: Cannot iterate over nullable var ArrayAccess<string, Buggregator\Trap\Sender\Frontend\Event\Asset>|null (see https://psalm.dev/097)

Check failure on line 79 in src/Sender/Frontend/Service.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MixedAssignment

src/Sender/Frontend/Service.php:79:36: MixedAssignment: Unable to determine the type that $attachment is being assigned to (see https://psalm.dev/032)

Check failure on line 79 in src/Sender/Frontend/Service.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Argument of an invalid type ArrayAccess<string, Buggregator\Trap\Sender\Frontend\Event\Asset> supplied for foreach, only iterables are supported.

Check failure on line 79 in src/Sender/Frontend/Service.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

PossiblyNullIterator

src/Sender/Frontend/Service.php:79:18: PossiblyNullIterator: Cannot iterate over nullable var ArrayAccess<string, Buggregator\Trap\Sender\Frontend\Event\Asset>|null (see https://psalm.dev/097)

Check failure on line 79 in src/Sender/Frontend/Service.php

View workflow job for this annotation

GitHub Actions / psalm (ubuntu-latest, 8.2, locked)

MixedAssignment

src/Sender/Frontend/Service.php:79:36: MixedAssignment: Unable to determine the type that $attachment is being assigned to (see https://psalm.dev/032)
$attachment instanceof AttachedFile and $attaches[] = $attachment;

Check failure on line 80 in src/Sender/Frontend/Service.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Only booleans are allowed in &&, Buggregator\Trap\Sender\Frontend\Event\AttachedFile given on the right side.

Check failure on line 80 in src/Sender/Frontend/Service.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Only booleans are allowed in &&, Buggregator\Trap\Sender\Frontend\Event\AttachedFile given on the right side.
}

return new Attachments($event, files: $attaches);
}

#[StaticRoute(Method::Delete, 'api/events')]
#[
AssertFail(Method::Delete, '/api/events'),
Expand Down

0 comments on commit de0057e

Please sign in to comment.