Hauptadresse statt Zweitadresse, Abspielgeschwindigkeit je Video
- Weitere Adressen einer Website (z. B. www.stommer.info) leiten per 301 auf die Hauptadresse um; vorher blockierte der Browser Skripte, Schriften und Videos, die von der Hauptadresse kamen (kein Titelvideo, Ersatzschrift) - Site::origin() nimmt verbindlich das Feld domain - Videos: Abspielgeschwindigkeit 0,5x bis 1x, gilt im Titelbereich und Rundgang Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b5ff837dcd
commit
cc47cac93e
14 files changed
+113
-16
No files matched your search
@@ -51,6 +51,15 @@ public static function configure(Schema $schema): Schema
|
||||
->default(fn (): ?int => app(CurrentProperty::class)->id())
|
||||
->placeholder('– keine (z. B. Umgebung) –')
|
||||
->live(),
|
||||
Select::make('playback_rate')
|
||||
->label('Abspielgeschwindigkeit')
|
||||
->helperText('Gilt überall, wo das Video gezeigt wird – im Titelbereich und im Rundgang. Drohnenflüge wirken mit 0,75× ruhiger; unter 0,6× kann die Bewegung ruckeln. Kapitelzeiten bleiben gleich.')
|
||||
->options(Video::PLAYBACK_RATES)
|
||||
->formatStateUsing(fn (mixed $state): string => self::rateKey($state))
|
||||
->dehydrateStateUsing(fn (mixed $state): float => (float) $state)
|
||||
->default('1')
|
||||
->selectablePlaceholder(false)
|
||||
->required(),
|
||||
Section::make('Kapitel')
|
||||
->description('Für den Rundgang: Besucher springen per Knopf zu einem Raum. Ist ein Raum aus dem Grundriss gewählt, bietet der Grundriss bei diesem Raum „Im Video ansehen“ an.')
|
||||
->collapsible()
|
||||
@@ -87,6 +96,16 @@ public static function configure(Schema $schema): Schema
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Option key for a stored rate (0.75 → "0.75", 1.0 → "1"); unknown values fall back to the original speed.
|
||||
*/
|
||||
public static function rateKey(mixed $rate): string
|
||||
{
|
||||
$key = rtrim(rtrim(number_format((float) ($rate ?: 1), 2, '.', ''), '0'), '.');
|
||||
|
||||
return array_key_exists($key, Video::PLAYBACK_RATES) ? $key : '1';
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of the visible floor plan rooms of the apartment (name => name).
|
||||
*
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
use App\Themes\Theme;
|
||||
use App\Themes\ThemeFactory;
|
||||
use Closure;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -44,11 +45,33 @@ public function handle(Request $request, Closure $next): Response
|
||||
$context->set($tenant);
|
||||
}
|
||||
|
||||
if ($redirect = $this->toMainAddress($request, $theme->site)) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
$this->useSiteOrigin($theme->site);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* A website answers on one main address. Visitors coming in through a further address (e.g. www.…) are
|
||||
* sent there permanently – otherwise the page would load its scripts, fonts and videos from the main
|
||||
* address, which the browser treats as another origin and blocks (no JavaScript, fallback fonts).
|
||||
* Only GET/HEAD: a form sent to the other address must not lose its input.
|
||||
*/
|
||||
private function toMainAddress(Request $request, Site $site): ?RedirectResponse
|
||||
{
|
||||
$origin = $site->exists ? $site->origin() : null;
|
||||
$mainHost = $origin === null ? null : parse_url($origin, PHP_URL_HOST);
|
||||
|
||||
if (! is_string($mainHost) || strcasecmp($mainHost, $request->getHost()) === 0 || ! $request->isMethodSafe()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new RedirectResponse($origin.$request->getRequestUri(), 301);
|
||||
}
|
||||
|
||||
/**
|
||||
* Links must carry the address the visitor came in on. AppServiceProvider forces APP_URL for every
|
||||
* generated URL, because on Strato the document root is a release folder; with one landlord that was
|
||||
|
||||
+3
-2
@@ -54,11 +54,12 @@ public function domains(): HasMany
|
||||
}
|
||||
|
||||
/**
|
||||
* Scheme and host for guest links. Empty while the website has no hostname yet.
|
||||
* Scheme and main host for guest links (the domain field; further addresses redirect there, see
|
||||
* ResolveTheme). Empty while the website has no hostname yet.
|
||||
*/
|
||||
public function origin(): ?string
|
||||
{
|
||||
$host = $this->domains()->value('host') ?: $this->domain;
|
||||
$host = $this->domain ?: $this->domains()->orderBy('id')->value('host');
|
||||
|
||||
if (! is_string($host) || $host === '') {
|
||||
return null;
|
||||
|
||||
+13
-1
@@ -19,7 +19,7 @@
|
||||
*
|
||||
* @property list<array{at?: string, label?: string, room?: string|null}>|null $chapters
|
||||
*/
|
||||
#[Fillable(['property_id', 'title', 'chapters'])]
|
||||
#[Fillable(['property_id', 'title', 'chapters', 'playback_rate'])]
|
||||
class Video extends Model implements HasMedia
|
||||
{
|
||||
/** @use HasFactory<VideoFactory> */
|
||||
@@ -29,6 +29,9 @@ class Video extends Model implements HasMedia
|
||||
|
||||
public const POSTER = 'poster';
|
||||
|
||||
/** Speeds offered in the admin (rate => label); the browser plays the file at this speed everywhere. */
|
||||
public const PLAYBACK_RATES = ['0.5' => 'Halb so schnell (0,5×)', '0.6' => 'Sehr ruhig (0,6×)', '0.75' => 'Ruhig (0,75×)', '0.85' => 'Etwas langsamer (0,85×)', '1' => 'Original (1×)'];
|
||||
|
||||
/** Largest accepted video file in KB (Strato allows uploads up to 128 MB). */
|
||||
public const MAX_KB = 100 * 1024;
|
||||
|
||||
@@ -41,6 +44,7 @@ protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'chapters' => 'array',
|
||||
'playback_rate' => 'float',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -79,6 +83,14 @@ public function url(): ?string
|
||||
return $this->getFirstMediaUrl(self::COLLECTION) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Playback speed for the browser, limited to 0.25–2; chapter times stay in video time.
|
||||
*/
|
||||
public function playbackRate(): float
|
||||
{
|
||||
return min(2.0, max(0.25, (float) ($this->playback_rate ?: 1)));
|
||||
}
|
||||
|
||||
public function mimeType(): string
|
||||
{
|
||||
return $this->getFirstMedia(self::COLLECTION)?->mime_type ?? 'video/mp4';
|
||||
|
||||
Reference in new issue
Block a user