forked from uup-dump/api
Add optional WU response caching
This commit is contained in:
parent
e28e612dd2
commit
bb3878d78e
52
fetchupd.php
52
fetchupd.php
@ -19,7 +19,15 @@ require_once dirname(__FILE__).'/shared/main.php';
|
|||||||
require_once dirname(__FILE__).'/shared/requests.php';
|
require_once dirname(__FILE__).'/shared/requests.php';
|
||||||
require_once dirname(__FILE__).'/listid.php';
|
require_once dirname(__FILE__).'/listid.php';
|
||||||
|
|
||||||
function uupFetchUpd($arch = 'amd64', $ring = 'WIF', $flight = 'Active', $build = 'latest', $minor = '0', $sku = '48') {
|
function uupFetchUpd(
|
||||||
|
$arch = 'amd64',
|
||||||
|
$ring = 'WIF',
|
||||||
|
$flight = 'Active',
|
||||||
|
$build = 'latest',
|
||||||
|
$minor = '0',
|
||||||
|
$sku = '48',
|
||||||
|
$cacheRequests = 0
|
||||||
|
) {
|
||||||
uupApiPrintBrand();
|
uupApiPrintBrand();
|
||||||
|
|
||||||
$arch = strtolower($arch);
|
$arch = strtolower($arch);
|
||||||
@ -80,12 +88,44 @@ function uupFetchUpd($arch = 'amd64', $ring = 'WIF', $flight = 'Active', $build
|
|||||||
|
|
||||||
$build = '10.0.'.$build.'.'.$minor;
|
$build = '10.0.'.$build.'.'.$minor;
|
||||||
|
|
||||||
consoleLogger('Fetching information from the server...');
|
$cacheHash = hash('sha1', strtolower("api-fetch-$arch-$ring-$flight-$build-$minor-$sku"));
|
||||||
$postData = composeFetchUpdRequest(uupDevice(), uupEncryptedData(), $arch, $flight, $ring, $build, $sku);
|
$cached = 0;
|
||||||
$out = sendWuPostRequest('https://fe3.delivery.mp.microsoft.com/ClientWebService/client.asmx', $postData);
|
|
||||||
|
|
||||||
$out = html_entity_decode($out);
|
if(file_exists('cache/'.$cacheHash.'.json.gz') && $cacheRequests == 1) {
|
||||||
consoleLogger('Information has been successfully fetched.');
|
$cache = @gzdecode(@file_get_contents('cache/'.$cacheHash.'.json.gz'));
|
||||||
|
$cache = json_decode($cache, 1);
|
||||||
|
|
||||||
|
if(!empty($cache['content']) && ($cache['expires'] > time())) {
|
||||||
|
consoleLogger('Using cached response...');
|
||||||
|
$out = $cache['content'];
|
||||||
|
$cached = 1;
|
||||||
|
} else {
|
||||||
|
$cached = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$cached) {
|
||||||
|
consoleLogger('Fetching information from the server...');
|
||||||
|
$postData = composeFetchUpdRequest(uupDevice(), uupEncryptedData(), $arch, $flight, $ring, $build, $sku);
|
||||||
|
$out = sendWuPostRequest('https://fe3.delivery.mp.microsoft.com/ClientWebService/client.asmx', $postData);
|
||||||
|
|
||||||
|
$out = html_entity_decode($out);
|
||||||
|
consoleLogger('Information has been successfully fetched.');
|
||||||
|
|
||||||
|
if($cacheRequests == 1) {
|
||||||
|
$cache = array(
|
||||||
|
'expires' => time()+90,
|
||||||
|
'content' => $out,
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!file_exists('cache')) mkdir('cache');
|
||||||
|
@file_put_contents('cache/'.$cacheHash.'.json.gz', gzencode(json_encode($cache)."\n"));
|
||||||
|
|
||||||
|
unset($cache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
preg_match_all('/<UpdateInfo>.*?<\/UpdateInfo>/', $out, $updateInfos);
|
preg_match_all('/<UpdateInfo>.*?<\/UpdateInfo>/', $out, $updateInfos);
|
||||||
$updateInfo = preg_grep('/<Action>Install<\/Action>/', $updateInfos[0]);
|
$updateInfo = preg_grep('/<Action>Install<\/Action>/', $updateInfos[0]);
|
||||||
|
51
get.php
51
get.php
@ -19,7 +19,12 @@ require_once dirname(__FILE__).'/shared/main.php';
|
|||||||
require_once dirname(__FILE__).'/shared/requests.php';
|
require_once dirname(__FILE__).'/shared/requests.php';
|
||||||
require_once dirname(__FILE__).'/shared/packs.php';
|
require_once dirname(__FILE__).'/shared/packs.php';
|
||||||
|
|
||||||
function uupGetFiles($updateId = 'c2a1d787-647b-486d-b264-f90f3782cdc6', $usePack = 0, $desiredEdition = 0) {
|
function uupGetFiles(
|
||||||
|
$updateId = 'c2a1d787-647b-486d-b264-f90f3782cdc6',
|
||||||
|
$usePack = 0,
|
||||||
|
$desiredEdition = 0,
|
||||||
|
$cacheRequests = 0
|
||||||
|
) {
|
||||||
uupApiPrintBrand();
|
uupApiPrintBrand();
|
||||||
|
|
||||||
$info = @file_get_contents('fileinfo/'.$updateId.'.json');
|
$info = @file_get_contents('fileinfo/'.$updateId.'.json');
|
||||||
@ -160,6 +165,9 @@ function uupGetFiles($updateId = 'c2a1d787-647b-486d-b264-f90f3782cdc6', $usePac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cacheHash = hash('sha1', strtolower("api-get-$updateId"));
|
||||||
|
$cached = 0;
|
||||||
|
|
||||||
$rev = 1;
|
$rev = 1;
|
||||||
if(preg_match('/_rev\./', $updateId)) {
|
if(preg_match('/_rev\./', $updateId)) {
|
||||||
$rev = preg_replace('/.*_rev\./', '', $updateId);
|
$rev = preg_replace('/.*_rev\./', '', $updateId);
|
||||||
@ -170,11 +178,42 @@ function uupGetFiles($updateId = 'c2a1d787-647b-486d-b264-f90f3782cdc6', $usePac
|
|||||||
$updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN';
|
$updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN';
|
||||||
$updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId;
|
$updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId;
|
||||||
|
|
||||||
$fetchTime = time();
|
if(file_exists('cache/'.$cacheHash.'.json.gz') && $cacheRequests == 1) {
|
||||||
consoleLogger('Fetching information from the server...');
|
$cache = @gzdecode(@file_get_contents('cache/'.$cacheHash.'.json.gz'));
|
||||||
$postData = composeFileGetRequest($updateId, uupDevice(), $info, $rev);
|
$cache = json_decode($cache, 1);
|
||||||
$out = sendWuPostRequest('https://fe3.delivery.mp.microsoft.com/ClientWebService/client.asmx/secured', $postData);
|
|
||||||
consoleLogger('Information has been successfully fetched.');
|
if(!empty($cache['content']) && ($cache['expires'] > time())) {
|
||||||
|
consoleLogger('Using cached response...');
|
||||||
|
$out = $cache['content'];
|
||||||
|
$fetchTime = $cache['fetchTime'];
|
||||||
|
$cached = 1;
|
||||||
|
} else {
|
||||||
|
$cached = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$cached) {
|
||||||
|
$fetchTime = time();
|
||||||
|
consoleLogger('Fetching information from the server...');
|
||||||
|
$postData = composeFileGetRequest($updateId, uupDevice(), $info, $rev);
|
||||||
|
$out = sendWuPostRequest('https://fe3.delivery.mp.microsoft.com/ClientWebService/client.asmx/secured', $postData);
|
||||||
|
consoleLogger('Information has been successfully fetched.');
|
||||||
|
|
||||||
|
if($cacheRequests == 1) {
|
||||||
|
$cache = array(
|
||||||
|
'expires' => time()+90,
|
||||||
|
'content' => $out,
|
||||||
|
'fetchTime' => $fetchTime,
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!file_exists('cache')) mkdir('cache');
|
||||||
|
@file_put_contents('cache/'.$cacheHash.'.json.gz', gzencode(json_encode($cache)."\n"));
|
||||||
|
|
||||||
|
unset($cache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
consoleLogger('Parsing information...');
|
consoleLogger('Parsing information...');
|
||||||
$xmlOut = simplexml_load_string($out);
|
$xmlOut = simplexml_load_string($out);
|
||||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function uupApiVersion() {
|
function uupApiVersion() {
|
||||||
return '1.15.13';
|
return '1.16.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once dirname(__FILE__).'/auths.php';
|
require_once dirname(__FILE__).'/auths.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user