Repositories | Polyback | Log in to see private repositories
969 bytes | parent directory
<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';
// Raw bytes of an asset stored by the importer (for embedding into place files).
// GET ?assetId=N. Auth as in upload.php.
use pizzaboxer\ProjectPolygon\Database;
use pizzaboxer\ProjectPolygon\Polygon;
$configuredKey = SITE_CONFIG["keys"]["AssetImport"] ?? "";
$givenKey = $_SERVER["HTTP_X_POLYGON_IMPORT_KEY"] ?? "";
if (strlen($configuredKey) < 16) { http_response_code(503); die(); }
if (!hash_equals($configuredKey, $givenKey)) { http_response_code(401); die(); }
$assetId = (int) ($_GET["assetId"] ?? 0);
$known = Database::singleton()->run("SELECT COUNT(*) FROM import_assets WHERE assetId = :id", [":id" => $assetId])->fetchColumn();
$path = Polygon::GetSharedResource("assets/$assetId");
if ($assetId <= 0 || !$known || !file_exists($path)) { http_response_code(404); die(); }
header("content-type: application/octet-stream");
header("content-length: " . filesize($path));
readfile($path);