Add option to ignore files from fileinfo

This commit is contained in:
eraseyourknees@gmail.com 2022-08-25 18:27:28 +02:00
parent d5769f635c
commit 9a80701470

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2017 UUP dump API authors Copyright 2022 UUP dump API authors
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -16,15 +16,40 @@ limitations under the License.
*/ */
require_once dirname(__FILE__).'/shared/main.php'; require_once dirname(__FILE__).'/shared/main.php';
require_once dirname(__FILE__).'/shared/cache.php';
function uupUpdateInfo($updateId, $onlyInfo = 0) { function uupApiPrivateGetFileinfo($updateId, $ignoreFiles) {
$info = @file_get_contents('fileinfo/'.$updateId.'.json'); $cached = false;
if(empty($info)) { if($ignoreFiles) {
return array('error' => 'UPDATE_INFORMATION_NOT_EXISTS'); $res = "fileinfo-fileless-$updateId";
$cache = new UupDumpCache($res, false);
$info = $cache->get();
$cached = ($info !== false);
} }
if(!$cached) {
$info = @file_get_contents('fileinfo/'.$updateId.'.json');
if(empty($info)) return false;
$info = json_decode($info, true); $info = json_decode($info, true);
}
if($ignoreFiles) {
if(isset($info['files'])) unset($info['files']);
if(!$cached) {
$cache->put($info, false);
}
}
return $info;
}
function uupUpdateInfo($updateId, $onlyInfo = 0, $ignoreFiles = false) {
$info = uupApiPrivateGetFileinfo($updateId, $ignoreFiles);
if($info === false) {
return ['error' => 'UPDATE_INFORMATION_NOT_EXISTS'];
}
$parsedInfo = uupParseUpdateInfo($info, $onlyInfo); $parsedInfo = uupParseUpdateInfo($info, $onlyInfo);
if(isset($parsedInfo['error'])) { if(isset($parsedInfo['error'])) {
@ -39,7 +64,7 @@ function uupUpdateInfo($updateId, $onlyInfo = 0) {
function uupParseUpdateInfo($info, $onlyInfo = 0) { function uupParseUpdateInfo($info, $onlyInfo = 0) {
if(empty($info)) { if(empty($info)) {
return array('error' => 'UPDATE_INFORMATION_NOT_EXISTS'); return ['error' => 'UPDATE_INFORMATION_NOT_EXISTS'];
} }
if($onlyInfo) { if($onlyInfo) {
@ -57,4 +82,3 @@ function uupParseUpdateInfo($info, $onlyInfo = 0) {
'info' => $returnInfo, 'info' => $returnInfo,
); );
} }
?>