Add fileinfo database caching

This commit is contained in:
mkuba50 2017-10-08 17:10:00 +02:00
parent ff1e138a50
commit 181198d077
2 changed files with 33 additions and 8 deletions

View File

@ -26,19 +26,40 @@ function uupListIds() {
$files = preg_grep('/\.json$/', $files);
consoleLogger('Parsing database info...');
$database = @file_get_contents('cache/fileinfo.json');
$database = json_decode($database, true);
if(empty($database)) $database = array();
$newDb = array();
$builds = array();
foreach($files as $file) {
if($file == '.' || $file == '..') continue;
$uuid = preg_replace('/\.json$/', '', $file);
if(!isset($database[$uuid])) {
$info = @file_get_contents('fileinfo/'.$file);
$info = json_decode($info, true);
$uuid = preg_replace('/\.json$/', '', $file);
$title = isset($info['title']) ? $info['title'] : 'UNKNOWN';
$build = isset($info['build']) ? $info['build'] : 'UNKNOWN';
$arch = isset($info['arch']) ? $info['arch'] : 'UNKNOWN';
$temp = array(
'title' => $title,
'build' => $build,
'arch' => $arch,
);
$newDb = array_merge($newDb, array($uuid => $temp));
} else {
$title = $database[$uuid]['title'];
$build = $database[$uuid]['build'];
$arch = $database[$uuid]['arch'];
$newDb = array_merge($newDb, array($uuid => $database[$uuid]));
}
$temp = array(
'title' => $title,
'build' => $build,
@ -60,6 +81,10 @@ function uupListIds() {
consoleLogger('Done parsing database info.');
if(!file_exists('cache')) mkdir('cache');
$success = @file_put_contents('cache/fileinfo.json', json_encode($newDb)."\n");
if(!$success) consoleLogger('Failed to update database cache.');
return array(
'apiVersion' => uupApiVersion(),
'builds' => $builds,

View File

@ -16,7 +16,7 @@ limitations under the License.
*/
function uupApiVersion() {
return '1.0.0';
return '1.1.0';
}
function uupApiPrintBrand() {