json-api/get.php

43 lines
1.2 KiB
PHP
Raw Normal View History

2019-09-14 17:38:35 +02:00
<?php
require_once 'api/get.php';
require_once 'shared/main.php';
require_once 'shared/ratelimits.php';
$updateId = isset($_GET['id']) ? $_GET['id'] : null;
$usePack = isset($_GET['lang']) ? $_GET['lang'] : 0;
$desiredEdition = isset($_GET['edition']) ? $_GET['edition'] : 0;
$noLinks = isset($_GET['noLinks']) ? $_GET['noLinks'] : 0;
2019-09-14 17:38:35 +02:00
header('Content-Type: application/json');
2022-10-22 02:35:44 +02:00
$edition = is_array($desiredEdition) ? implode('_', $desiredEdition) : $desiredEdition;
$resource = hash('sha1', strtolower("get-$updateId-$usePack-$edition"));
if(checkIfUserIsRateLimited($resource) && !$noLinks) {
2019-09-14 17:38:35 +02:00
http_response_code(429);
sendResponse(['error' => 'USER_RATE_LIMITED']);
die();
}
$mode = $noLinks ? 2 : 1;
$apiResponse = uupGetFiles($updateId, $usePack, $desiredEdition, $mode);
2019-09-14 17:38:35 +02:00
if(isset($apiResponse['error'])) {
switch($apiResponse['error']) {
case 'NO_FILES':
http_response_code(500);
break;
case 'XML_PARSE_ERROR':
http_response_code(500);
break;
case 'EMPTY_FILELIST':
http_response_code(500);
break;
default:
http_response_code(400);
}
}
sendResponse($apiResponse);