serve 88x31 buttons from cache URLs instead of base64, preload the art font
Deploy / deploy (push) Successful in 3s
Deploy / deploy (push) Successful in 3s
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// Serves an 88x31 button from the local cache (see inc/buttons.php).
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
$h = $_GET['h'] ?? '';
|
||||
$file = DATA_DIR . '/buttons/' . $h;
|
||||
if (!preg_match('/^[0-9a-f]{32}$/', $h) || !is_file($file)) {
|
||||
http_response_code(404);
|
||||
exit;
|
||||
}
|
||||
|
||||
$raw = (string) file_get_contents($file);
|
||||
$nl = strpos($raw, "\n");
|
||||
$type = $nl !== false ? substr($raw, 0, $nl) : '';
|
||||
if (!preg_match('#^image/[\w.+-]+$#', $type)) {
|
||||
http_response_code(404);
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Content-Type: ' . $type);
|
||||
header('Cache-Control: public, max-age=31536000, immutable'); // URL carries ?v=<mtime>
|
||||
echo substr($raw, $nl + 1);
|
||||
Reference in New Issue
Block a user