From b925e9a5f6d58390bd038b28c6bd93da24808101 Mon Sep 17 00:00:00 2001 From: whatever127 <46111995+whatever127@users.noreply.github.com> Date: Sat, 14 Sep 2019 17:38:35 +0200 Subject: [PATCH] Initial commit --- .gitmodules | 3 ++ LICENSE | 21 +++++++++ api | 1 + fetchupd.php | 37 ++++++++++++++++ get.php | 39 ++++++++++++++++ index.php | 7 +++ listeditions.php | 14 ++++++ listid.php | 14 ++++++ listlangs.php | 13 ++++++ readme.md | 100 ++++++++++++++++++++++++++++++++++++++++++ shared/main.php | 13 ++++++ shared/ratelimits.php | 51 +++++++++++++++++++++ 12 files changed, 313 insertions(+) create mode 100644 .gitmodules create mode 100644 LICENSE create mode 160000 api create mode 100644 fetchupd.php create mode 100644 get.php create mode 100644 index.php create mode 100644 listeditions.php create mode 100644 listid.php create mode 100644 listlangs.php create mode 100644 readme.md create mode 100644 shared/main.php create mode 100644 shared/ratelimits.php diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..46a3b01 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "api"] + path = api + url = git@github.com:uup-dump/api.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0557511 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 whatever127 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/api b/api new file mode 160000 index 0000000..d628c2f --- /dev/null +++ b/api @@ -0,0 +1 @@ +Subproject commit d628c2fe69ed91adb397d966812477767b2d8a69 diff --git a/fetchupd.php b/fetchupd.php new file mode 100644 index 0000000..7316abd --- /dev/null +++ b/fetchupd.php @@ -0,0 +1,37 @@ + 'USER_RATE_LIMITED']); + die(); +} + +$apiResponse = uupFetchUpd($arch, $ring, $flight, $build, 0, $sku, 1); +if(isset($apiResponse['error'])) { + switch($apiResponse['error']) { + case 'EMPTY_FILELIST': + http_response_code(500); + break; + + case 'NO_UPDATE_FOUND': + http_response_code(500); + break; + + default: + http_response_code(400); + } +} + +sendResponse($apiResponse); diff --git a/get.php b/get.php new file mode 100644 index 0000000..6ff5690 --- /dev/null +++ b/get.php @@ -0,0 +1,39 @@ + 'USER_RATE_LIMITED']); + die(); +} + +$apiResponse = uupGetFiles($updateId, $usePack, $desiredEdition, 1); +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); diff --git a/index.php b/index.php new file mode 100644 index 0000000..34f5aec --- /dev/null +++ b/index.php @@ -0,0 +1,7 @@ + uupApiVersion()]); diff --git a/listeditions.php b/listeditions.php new file mode 100644 index 0000000..d8992e6 --- /dev/null +++ b/listeditions.php @@ -0,0 +1,14 @@ += 9841 and <= PHP_INT_MAX-1 + + - `sku` - SKU number to use when fetching information + - **Supported values:** Any integer + +#### `/get.php` +Retrieves download links for specified Update ID and provides lists of ready to +use UUP sets. + +Parameters: + - `id` - Update identifier + - **Supported values:** any update identifier + + - `lang` - Create UUP set for selected language (optional) + - **Supported values:** language name in xx-xx format + + - `edition` - Create UUP set for selected edition (optional) + - **Supported values:** any edition name + - **NOTE:** You need to specify `lang` to get successful request + +#### `/listlangs.php` +Lists available languages for specified Update ID + +Parameters: + - `id` - Update identifier (optional) + - **Supported values:** any update identifier + + +#### `/listlangs.php` +Lists available editions for specified Update ID + +Parameters: + - `lang` - Generate list for selected language + - **Supported values:** language name in xx-xx format + + - `id` - Update identifier (optional) + - **Supported values:** any update identifier diff --git a/shared/main.php b/shared/main.php new file mode 100644 index 0000000..3e989e3 --- /dev/null +++ b/shared/main.php @@ -0,0 +1,13 @@ + $apiResponse, + 'jsonApiVersion' => $webApiVersion, + ]; + + echo json_encode($response); +} diff --git a/shared/ratelimits.php b/shared/ratelimits.php new file mode 100644 index 0000000..43219b4 --- /dev/null +++ b/shared/ratelimits.php @@ -0,0 +1,51 @@ + microtime(1) && $accessedRes != $resource) { + return true; + } + + $info['lastAccess'] = microtime(1); + $info['resource'] = $resource; + + @file_put_contents('cache/'.$ipHash.'.json', json_encode($info)."\n"); + + if($lastAccess + $currentResLimit > microtime(1) && $accessedRes == $resource) { + return true; + } + + return false; +}