Fix design validation, canonical routes, media headers and favicon

This commit is contained in:
2026-11-23 18:52:26 +08:00
parent 01ede89dcd
commit 584455c66d
18 changed files with 153 additions and 65 deletions
+6 -7
View File
@@ -23,23 +23,22 @@ final class MediaController
'Content-Type' => $media['mime'], 'X-Content-Type-Options' => 'nosniff',
'Content-Security-Policy' => "default-src 'none'; sandbox",
'Cache-Control' => 'public, max-age=31536000, immutable',
'Access-Control-Allow-Origin' => '*', 'Accept-Ranges' => 'bytes',
'Access-Control-Allow-Origin' => '*',
];
$range = $request->header('range');
if ($range === null) {
return (new Response(200, $headers + ['Content-Length' => (string) $length]))->withFile($path);
return (new Response(200, $headers))->withFile($path);
}
$unsatisfiable = $headers + ['Accept-Ranges' => 'bytes', 'Content-Range' => "bytes */$length"];
if (!preg_match('/^bytes=(\d*)-(\d*)$/D', $range, $parts) || $parts[1] === '' && $parts[2] === '') {
return new Response(416, $headers + ['Content-Range' => "bytes */$length"]);
return new Response(416, $unsatisfiable);
}
$start = $parts[1] === '' ? max(0, $length - (int) $parts[2]) : (int) $parts[1];
$end = $parts[1] === '' || $parts[2] === '' ? $length - 1 : min($length - 1, (int) $parts[2]);
if ($end < $start) {
return new Response(416, $headers + ['Content-Range' => "bytes */$length"]);
return new Response(416, $unsatisfiable);
}
$count = $end - $start + 1;
return (new Response(206, $headers + ['Content-Length' => (string) $count, 'Content-Range' => "bytes $start-$end/$length"]))
->withFile($path, $start, $count);
return (new Response(206, $headers))->withFile($path, $start, $end - $start + 1);
}
}