Save date of fetching build to fileinfo database

This commit is contained in:
mkuba50 2019-02-08 17:20:28 +01:00
parent e32d7446ca
commit 767de7a1a5
4 changed files with 39 additions and 9 deletions

View File

@ -1,6 +1,6 @@
<?php
/*
Copyright 2018 UUP dump API authors
Copyright 2019 UUP dump API authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -88,7 +88,7 @@ function uupFetchUpd(
$build = '10.0.'.$build.'.'.$minor;
$cacheHash = hash('sha1', strtolower("api-fetch-$arch-$ring-$flight-$build-$minor-$sku"));
$cacheHash = hash('sha256', strtolower("api-fetch-$arch-$ring-$flight-$build-$minor-$sku"));
$cached = 0;
if(file_exists('cache/'.$cacheHash.'.json.gz') && $cacheRequests == 1) {
@ -285,6 +285,7 @@ function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku
$temp['containsCU'] = 1;
}
$temp['created'] = time();
$temp['files'] = $shaArray;
consoleLogger('Successfully parsed the information.');

View File

@ -222,7 +222,7 @@ function uupGetFiles(
}
function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests) {
$cacheHash = hash('sha1', strtolower("api-get-${updateId}_rev.$rev"));
$cacheHash = hash('sha256', strtolower("api-get-${updateId}_rev.$rev"));
$cached = 0;
if(file_exists('cache/'.$cacheHash.'.json.gz') && $cacheRequests == 1) {

View File

@ -1,6 +1,6 @@
<?php
/*
Copyright 2018 UUP dump API authors
Copyright 2019 UUP dump API authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -17,7 +17,7 @@ limitations under the License.
require_once dirname(__FILE__).'/shared/main.php';
function uupListIds($search = null) {
function uupListIds($search = null, $sortByDate = 0) {
uupApiPrintBrand();
if(!file_exists('fileinfo')) return array('error' => 'NO_FILEINFO_DIR');
@ -27,8 +27,24 @@ function uupListIds($search = null) {
consoleLogger('Parsing database info...');
$database = @file_get_contents('cache/fileinfo.json');
$cacheFile = 'cache/fileinfo_v2.json';
$cacheV2Version = 1;
$database = @file_get_contents($cacheFile);
$database = json_decode($database, true);
if(isset($database['version'])) {
$version = $database['version'];
} else {
$version = 0;
}
if($version == $cacheV2Version && isset($database['database'])) {
$database = $database['database'];
} else {
$database = array();
}
if(empty($database)) $database = array();
$newDb = array();
@ -44,11 +60,13 @@ function uupListIds($search = null) {
$title = isset($info['title']) ? $info['title'] : 'UNKNOWN';
$build = isset($info['build']) ? $info['build'] : 'UNKNOWN';
$arch = isset($info['arch']) ? $info['arch'] : 'UNKNOWN';
$created = isset($info['created']) ? $info['created'] : null;
$temp = array(
'title' => $title,
'build' => $build,
'arch' => $arch,
'created' => $created,
);
$newDb[$uuid] = $temp;
@ -56,6 +74,7 @@ function uupListIds($search = null) {
$title = $database[$uuid]['title'];
$build = $database[$uuid]['build'];
$arch = $database[$uuid]['arch'];
$created = $database[$uuid]['created'];
$newDb[$uuid] = $database[$uuid];
}
@ -64,6 +83,7 @@ function uupListIds($search = null) {
'title' => $title,
'build' => $build,
'arch' => $arch,
'created' => $created,
'uuid' => $uuid,
);
@ -77,6 +97,10 @@ function uupListIds($search = null) {
$tmp = 0;
}
if($sortByDate) {
$tmp = $created.$tmp;
}
$buildAssoc[$tmp][] = $arch.$title.$uuid;
$builds[$tmp.$arch.$title.$uuid] = $temp;
}
@ -104,9 +128,14 @@ function uupListIds($search = null) {
if($newDb != $database) {
if(!file_exists('cache')) mkdir('cache');
$cacheData = array(
'version' => $cacheV2Version,
'database' => $newDb,
);
$success = @file_put_contents(
'cache/fileinfo.json',
json_encode($newDb)."\n"
$cacheFile,
json_encode($cacheData)."\n"
);
if(!$success) consoleLogger('Failed to update database cache.');

View File

@ -16,7 +16,7 @@ limitations under the License.
*/
function uupApiVersion() {
return '1.19.3';
return '1.20.0';
}
require_once dirname(__FILE__).'/auths.php';