Compare commits

..
1 Commits
Author SHA1 Message Date
deploy-bot 6aa66cfa49 v0.9.5 2026-12-04 17:50:18 +00:00
10 changed files with 22 additions and 159 deletions

No files matched your search

-6
View File
@@ -4,12 +4,6 @@ Every release has a section here, named after its version (for example `v0.1.0 -
heading). The release pull request to `production` is stopped by PR CI when its section is missing, and the text of heading). The release pull request to `production` is stopped by PR CI when its section is missing, and the text of
the section is the text of the release in Gitea. the section is the text of the release in Gitea.
## v0.9.6 - 2026-12-04
- **Media at the IriksIT API, as a site that already used it expects.** The file route tells the API what kind of file it wants (`X-Media-Kind`) and passes on the placeholder the API sends when it cannot serve it (a picture for a picture; a clip with status 200 for a video, because a player refuses anything else), never cached. A busy API is told apart from a file that is gone: 503 with `Retry-After` instead of a 404 that a cache may keep. A download is no longer collected on the server first, so a video starts playing at once. New: `Media::kind()`, `Adapter::openFile()`, and `MediaStorageException` carries the placeholder.
- **Date fields of a list.** An empty date is saved as no date (before: an empty text, which a strict database refuses in a date column and which wiped a date that was there), and a date column that is cast to a date and time is shown as the day, which is what the field takes. Deleting a file while the API cannot be reached keeps the row and answers 502, instead of a 500.
- **A tap on the phone number or WhatsApp button** counts only for a page of the site (where the statistics are on) and never for a program, as the pulse does.
## v0.9.5 - 2026-12-04 ## v0.9.5 - 2026-12-04
- **Lists for blocks.** A `cards` block can show the latest published posts (`source` = `posts`, each with a `url` from the new `manager.blocks.post_url` / `MANAGER_BLOCKS_POST_URL`), and can be limited to the records whose yes/no field is on (`only_if`, applied before the count). Every item whose list has a select that points at another list gets `<field>_label`, the name behind the id. - **Lists for blocks.** A `cards` block can show the latest published posts (`source` = `posts`, each with a `url` from the new `manager.blocks.post_url` / `MANAGER_BLOCKS_POST_URL`), and can be limited to the records whose yes/no field is on (`only_if`, applied before the count). Every item whose list has a select that points at another list gets `<field>_label`, the name behind the id.
+2 -14
View File
@@ -2,7 +2,6 @@
namespace IriksIT\Manager\Exceptions; namespace IriksIT\Manager\Exceptions;
use Psr\Http\Message\StreamInterface;
use RuntimeException; use RuntimeException;
/** /**
@@ -11,19 +10,8 @@ use RuntimeException;
*/ */
class MediaStorageException extends RuntimeException class MediaStorageException extends RuntimeException
{ {
/** public function __construct(string $message, public readonly int $status = 0, public readonly ?int $retryAfter = null)
* @param StreamInterface|null $placeholder what the API sent instead of the file: a picture, clip, sound or page of the same kind that says what is wrong {
* @param string|null $placeholderType its content type
* @param string|null $reason the API's name for what is wrong (not-found, unavailable, ...)
*/
public function __construct(
string $message,
public readonly int $status = 0,
public readonly ?int $retryAfter = null,
public readonly ?StreamInterface $placeholder = null,
public readonly ?string $placeholderType = null,
public readonly ?string $reason = null,
) {
parent::__construct($message); parent::__construct($message);
} }
} }
-15
View File
@@ -28,21 +28,6 @@ class Media extends Model
return $this->belongsTo(config('manager.user_model'), 'uploaded_by'); return $this->belongsTo(config('manager.user_model'), 'uploaded_by');
} }
/**
* What kind of media this is, in the words of the IriksIT API: it sends a placeholder of this kind when the file itself cannot be served.
* Null for a file there is nothing to show for.
*/
public function kind(): ?string
{
return match (true) {
str_starts_with($this->mime_type, 'image/') => 'image',
str_starts_with($this->mime_type, 'video/') => 'video',
str_starts_with($this->mime_type, 'audio/') => 'audio',
$this->mime_type === 'application/pdf' => 'pdf',
default => null,
};
}
public function isImage(): bool public function isImage(): bool
{ {
return str_starts_with($this->mime_type, 'image/'); return str_starts_with($this->mime_type, 'image/');
+1 -15
View File
@@ -6,13 +6,10 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use IriksIT\Manager\Modules\Statistics\VisitRecorder;
use IriksIT\Manager\Support\Leads\Intake; use IriksIT\Manager\Support\Leads\Intake;
use IriksIT\Manager\Support\Leads\Phone; use IriksIT\Manager\Support\Leads\Phone;
use IriksIT\Manager\Support\Leads\Report; use IriksIT\Manager\Support\Leads\Report;
use IriksIT\Manager\Support\Login\Turnstile; use IriksIT\Manager\Support\Login\Turnstile;
use IriksIT\Manager\Support\ModuleRegistry;
use IriksIT\Manager\Support\UserAgent;
/** /**
* The one place the forms of the public site are sent to (`manager.leads.form`). A form is a name (the last part of the address) with a * The one place the forms of the public site are sent to (`manager.leads.form`). A form is a name (the last part of the address) with a
@@ -55,18 +52,7 @@ class LeadFormController
public function tap(Request $request): JsonResponse public function tap(Request $request): JsonResponse
{ {
$data = $request->validate(['kind' => ['required', 'in:call,whatsapp'], 'path' => ['required', 'string', 'max:255']]); $data = $request->validate(['kind' => ['required', 'in:call,whatsapp'], 'path' => ['required', 'string', 'max:255']]);
$path = parse_url($data['path'], PHP_URL_PATH) ?: '/'; Report::tap($data['kind'], parse_url($data['path'], PHP_URL_PATH) ?: '/');
// A program is no caller, and where the statistics are on, only a page that exists counts (nobody can fill the list with made-up addresses).
if ((new UserAgent((string) $request->userAgent()))->isBot()) {
return response()->json(['ok' => true], 201);
}
if (app(ModuleRegistry::class)->enabled('statistics') && ($path = app(VisitRecorder::class)->pathOf($path)) === null) {
return response()->json(['ok' => true], 201);
}
Report::tap($data['kind'], $path);
return response()->json(['ok' => true], 201); return response()->json(['ok' => true], 201);
} }
-47
View File
@@ -53,11 +53,6 @@ class MediaFileController
try { try {
$stream = $library->open($media); $stream = $library->open($media);
} catch (MediaStorageException $e) { } catch (MediaStorageException $e) {
// The API sent a picture, clip, sound or page that says what is wrong: show that instead of an error the browser cannot display.
if ($e->placeholder !== null && $e->placeholderType !== null) {
return $this->placeholder($e);
}
if ($e->status === 404) { if ($e->status === 404) {
abort(404); abort(404);
} }
@@ -68,48 +63,6 @@ class MediaFileController
return response()->stream(fn () => $this->send($stream, $start, $length), $partial ? 206 : 200, $headers); return response()->stream(fn () => $this->send($stream, $start, $length), $partial ? 206 : 200, $headers);
} }
/**
* Passes the API's placeholder on. With the status the API gave, except for video and audio: a player refuses anything that is not a 200.
* Never cached: it would outlive the problem.
*/
private function placeholder(MediaStorageException $e): Response
{
$body = $e->placeholder;
$playable = str_starts_with((string) $e->placeholderType, 'video/') || str_starts_with((string) $e->placeholderType, 'audio/');
$headers = [
'Content-Type' => (string) $e->placeholderType,
'Content-Disposition' => 'inline',
'X-Content-Type-Options' => 'nosniff',
'Cache-Control' => 'no-store',
'X-Media-Fallback' => (string) $e->reason,
];
if ($e->retryAfter !== null) {
$headers['Retry-After'] = (string) $e->retryAfter;
}
return response()->stream(function () use ($body): void {
if ($body === null) {
return;
}
try {
while (! $body->eof()) {
$chunk = $body->read(65536);
if ($chunk === '') {
break;
}
echo $chunk;
}
} finally {
$body->close();
}
}, $playable ? 200 : ($e->status ?: 503), $headers);
}
/** @return array<string, string> */ /** @return array<string, string> */
private function headers(Media $media): array private function headers(Media $media): array
{ {
+3 -19
View File
@@ -2,17 +2,13 @@
namespace IriksIT\Manager\Modules\Media; namespace IriksIT\Manager\Modules\Media;
use GuzzleHttp\Psr7\StreamWrapper;
use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use IriksIT\Manager\Exceptions\MediaStorageException; use IriksIT\Manager\Exceptions\MediaStorageException;
use IriksIT\Manager\Models\Media; use IriksIT\Manager\Models\Media;
use IriksIT\Manager\Support\IriksStorage\Adapter as IriksAdapter;
use IriksIT\Manager\Support\MediaUsage; use IriksIT\Manager\Support\MediaUsage;
use League\Flysystem\FilesystemException;
/** /**
* The one place that knows where media files physically are. Everything else works with Media * The one place that knows where media files physically are. Everything else works with Media
@@ -133,14 +129,7 @@ class MediaLibrary
*/ */
public function open(Media $media) public function open(Media $media)
{ {
$disk = Storage::disk($media->disk); $stream = Storage::disk($media->disk)->readStream($media->location);
// At the IriksIT API: through its own way in, so a busy API is told apart from a file that is gone, and a placeholder can be passed on.
if ($disk instanceof FilesystemAdapter && ($adapter = $disk->getAdapter()) instanceof IriksAdapter) {
return StreamWrapper::getResource($adapter->openFile($media->location, $media->kind()));
}
$stream = $disk->readStream($media->location);
if (! is_resource($stream)) { if (! is_resource($stream)) {
throw new MediaStorageException('The file is no longer there.', 404); throw new MediaStorageException('The file is no longer there.', 404);
@@ -154,13 +143,8 @@ class MediaLibrary
{ {
$disk = Storage::disk($media->disk); $disk = Storage::disk($media->disk);
// A storage that cannot be reached throws its own exceptions: the row stays, and the caller hears the one it knows. if ($disk->exists($media->location) && ! $disk->delete($media->location)) {
try { throw new MediaStorageException('The file could not be deleted.');
if ($disk->exists($media->location) && ! $disk->delete($media->location)) {
throw new MediaStorageException('The file could not be deleted.');
}
} catch (FilesystemException $e) {
throw new MediaStorageException('The file could not be deleted: '.$e->getMessage(), 0);
} }
$media->delete(); $media->delete();
-2
View File
@@ -153,8 +153,6 @@ final class Fields
$out[$key] = match ($field['type']) { $out[$key] = match ($field['type']) {
'toggle' => filter_var($value, FILTER_VALIDATE_BOOLEAN), 'toggle' => filter_var($value, FILTER_VALIDATE_BOOLEAN),
'number' => $value === null || $value === '' ? null : $value + 0, 'number' => $value === null || $value === '' ? null : $value + 0,
// No date is no date: an empty text in a date column is an error on a strict database, and it is not what was meant.
'date' => $value === null || $value === '' ? null : (is_scalar($value) ? trim((string) $value) : null),
'select' => $field['source'] !== null && ($value === null || $value === '') ? null : (is_scalar($value) ? trim((string) $value) : ''), 'select' => $field['source'] !== null && ($value === null || $value === '') ? null : (is_scalar($value) ? trim((string) $value) : ''),
'list', 'media_list' => self::strings($value), 'list', 'media_list' => self::strings($value),
'repeater' => self::cleanItems($field['items'], $value), 'repeater' => self::cleanItems($field['items'], $value),
+10 -14
View File
@@ -2,7 +2,6 @@
namespace IriksIT\Manager\Support\IriksStorage; namespace IriksIT\Manager\Support\IriksStorage;
use GuzzleHttp\Psr7\StreamWrapper;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use IriksIT\Manager\Exceptions\MediaStorageException; use IriksIT\Manager\Exceptions\MediaStorageException;
use IriksIT\Manager\Support\Names; use IriksIT\Manager\Support\Names;
@@ -19,7 +18,6 @@ use League\Flysystem\UnableToReadFile;
use League\Flysystem\UnableToRetrieveMetadata; use League\Flysystem\UnableToRetrieveMetadata;
use League\Flysystem\UnableToSetVisibility; use League\Flysystem\UnableToSetVisibility;
use League\Flysystem\UnableToWriteFile; use League\Flysystem\UnableToWriteFile;
use Psr\Http\Message\StreamInterface;
/** /**
* A Laravel disk (`driver` => `iriksit`) whose files live at the IriksIT API. The API knows files by an id of its own, not * A Laravel disk (`driver` => `iriksit`) whose files live at the IriksIT API. The API knows files by an id of its own, not
@@ -89,24 +87,22 @@ class Adapter implements FilesystemAdapter
public function readStream(string $path) public function readStream(string $path)
{ {
$id = $this->id($path) ?? throw UnableToReadFile::fromLocation($path, 'There is no such file.');
try { try {
return StreamWrapper::getResource($this->openFile($path)); $body = $this->client->open($id);
} catch (MediaStorageException $e) { } catch (MediaStorageException $e) {
throw UnableToReadFile::fromLocation($path, $e->getMessage(), $e); throw UnableToReadFile::fromLocation($path, $e->getMessage(), $e);
} }
}
/** $stream = fopen('php://temp', 'r+b');
* The content of a file as it comes in (nothing is kept here first, so a video starts playing at once). `$kind` (image, video, audio while (! $body->eof()) {
* or pdf) lets the API answer with a placeholder when it cannot serve the file; that travels in the exception. fwrite($stream, $body->read(1024 * 1024));
* }
* @throws MediaStorageException with status 404 when there is no such file $body->close();
*/ rewind($stream);
public function openFile(string $path, ?string $kind = null): StreamInterface
{
$id = $this->id($path) ?? throw new MediaStorageException('There is no such file.', 404);
return $this->client->open($id, $kind); return $stream;
} }
public function delete(string $path): void public function delete(string $path): void
+5 -23
View File
@@ -61,17 +61,14 @@ class Client
/** /**
* The content of a file as a stream; read it and close it. * The content of a file as a stream; read it and close it.
* *
* `$kind` (image, video, audio or pdf) tells the API what is expected: when the file cannot be served it then sends a placeholder of that
* kind instead of an error, and that travels along in the exception.
*
* @throws MediaStorageException with status 404 when the API does not know the file * @throws MediaStorageException with status 404 when the API does not know the file
*/ */
public function open(string $id, ?string $kind = null): StreamInterface public function open(string $id): StreamInterface
{ {
$response = $this->call(fn (PendingRequest $request) => $request->withHeaders($kind !== null ? ['X-Media-Kind' => $kind] : [])->withOptions(['stream' => true])->get($this->url('/storage/'.rawurlencode($id).'/download'))); $response = $this->call(fn (PendingRequest $request) => $request->withOptions(['stream' => true])->get($this->url('/storage/'.rawurlencode($id).'/download')));
if ($response->status() !== 200) { if ($response->status() !== 200) {
throw $this->failure('download a file', $response, withPlaceholder: true); throw $this->failure('download a file', $response);
} }
return $response->toPsrResponse()->getBody(); return $response->toPsrResponse()->getBody();
@@ -269,26 +266,11 @@ class Client
} }
} }
private function failure(string $action, Response $response, bool $withPlaceholder = false): MediaStorageException private function failure(string $action, Response $response): MediaStorageException
{ {
$retry = $response->header('Retry-After');
$fallback = $response->header('X-Media-Fallback');
$type = $response->header('Content-Type');
// The API sent a placeholder instead of the file: the header says so, and the type is one a browser may show. Its body is that picture, not a message.
if ($withPlaceholder && preg_match('/^[a-z-]{1,30}$/', $fallback) === 1 && preg_match('#^(image/png|video/mp4|audio/mpeg|application/pdf)$#', $type) === 1) {
return new MediaStorageException(
"The IriksIT storage could not {$action} (HTTP {$response->status()}: {$fallback}).",
$response->status(),
is_numeric($retry) ? (int) $retry : null,
$response->toPsrResponse()->getBody(),
$type,
$fallback,
);
}
$reason = $response->json('message'); $reason = $response->json('message');
$detail = is_string($reason) && $reason !== '' ? ': '.mb_substr($reason, 0, 200) : ''; $detail = is_string($reason) && $reason !== '' ? ': '.mb_substr($reason, 0, 200) : '';
$retry = $response->header('Retry-After');
return new MediaStorageException( return new MediaStorageException(
"The IriksIT storage could not {$action} (HTTP {$response->status()}{$detail}).", "The IriksIT storage could not {$action} (HTTP {$response->status()}{$detail}).",
+1 -4
View File
@@ -96,10 +96,7 @@ final class Resources
$values = []; $values = [];
foreach ($resource['fields'] as $key => $field) { foreach ($resource['fields'] as $key => $field) {
$value = $stored !== null ? ($stored[$key] ?? $field['default']) : ($model->getAttribute($key) ?? $field['default']); $values[$key] = $stored !== null ? ($stored[$key] ?? $field['default']) : ($model->getAttribute($key) ?? $field['default']);
// A date column that is cast to a date and time is shown as the day it is, which is what a date field takes.
$values[$key] = $field['type'] === 'date' && $value instanceof \DateTimeInterface ? $value->format('Y-m-d') : ($field['type'] === 'date' && $value === '' ? null : $value);
} }
return ['id' => $model->getKey(), 'values' => $values]; return ['id' => $model->getKey(), 'values' => $values];