Repositories | Polyback | Log in to see private repositories


polyback-website / 95e5150e67c9f9be1d23113dda4841462e1440a7 / api/client/content.php

1,268 bytes | parent directory

<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';

// Era client content packs for the Polyback Player (signed-in players only).
//   GET /api/client/content            -> {"eras":{"2014M":{"sha256":..,"size":..},...}}
//   GET /api/client/content?era=2014M  -> the pack (tar.gz)
// Authorization: Bearer <token from the join link>

use pizzaboxer\ProjectPolygon\ClientContent;
use pizzaboxer\ProjectPolygon\ClientVersions;

header("Cache-Control: no-store");

if (ClientContent::TokenUser(ClientContent::RequestToken()) === null)
{
	http_response_code(401);
	header("content-type: application/json");
	die(json_encode(["success" => false, "message" => "Unauthorized"]));
}

$manifest = ClientContent::Manifest();
if (!isset($_GET["era"]))
{
	header("content-type: application/json");
	die(json_encode($manifest));
}

$era = ClientVersions::Normalize((string) $_GET["era"]);
if ($era === null || !isset($manifest["eras"][$era]))
{
	http_response_code(404);
	die();
}
$path = ClientContent::Directory() . "/$era.tar.gz";
if (!is_file($path))
{
	http_response_code(404);
	die();
}
header("content-type: application/gzip");
header("Content-Length: " . filesize($path));
header("Content-Disposition: attachment; filename=\"$era.tar.gz\"");
readfile($path);