Merge pull request #24 from uup-dump-dev/master

1.38.0
This commit is contained in:
eraseyourknees 2022-09-14 19:06:05 +02:00 committed by GitHub
commit cf57876aca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 127 additions and 44 deletions

View File

@ -18,6 +18,7 @@ limitations under the License.
require_once dirname(__FILE__).'/shared/main.php'; 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/cache.php'; require_once dirname(__FILE__).'/shared/cache.php';
require_once dirname(__FILE__).'/shared/fileinfo.php';
require_once dirname(__FILE__).'/listid.php'; require_once dirname(__FILE__).'/listid.php';
function uupFetchUpd( function uupFetchUpd(
@ -288,10 +289,9 @@ function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku
} }
$fileWrite = 'NO_SAVE'; $fileWrite = 'NO_SAVE';
if(!file_exists('fileinfo/'.$updateString.'.json')) { if(!uupApiFileInfoExists($updateId)) {
consoleLogger('WARNING: This build is NOT in the database. It will be saved now.'); consoleLogger('WARNING: This build is NOT in the database. It will be saved now.');
consoleLogger('Parsing information to write...'); consoleLogger('Parsing information to write...');
if(!file_exists('fileinfo')) mkdir('fileinfo');
$fileList = preg_replace('/<Files>|<\/Files>/', '', $fileList[0]); $fileList = preg_replace('/<Files>|<\/Files>/', '', $fileList[0]);
preg_match_all('/<File.*?<\/File>/', $fileList, $fileList); preg_match_all('/<File.*?<\/File>/', $fileList, $fileList);
@ -349,7 +349,7 @@ function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku
consoleLogger('Successfully parsed the information.'); consoleLogger('Successfully parsed the information.');
consoleLogger('Writing new build information to the disk...'); consoleLogger('Writing new build information to the disk...');
$success = file_put_contents('fileinfo/'.$updateString.'.json', json_encode($temp)."\n"); $success = uupApiWriteFileinfo($updateString, $temp);
if($success) { if($success) {
consoleLogger('Successfully written build information to the disk.'); consoleLogger('Successfully written build information to the disk.');
$fileWrite = 'INFO_WRITTEN'; $fileWrite = 'INFO_WRITTEN';

View File

@ -19,6 +19,7 @@ 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';
require_once dirname(__FILE__).'/shared/cache.php'; require_once dirname(__FILE__).'/shared/cache.php';
require_once dirname(__FILE__).'/shared/fileinfo.php';
/* /*
$updateId = Update Identifier $updateId = Update Identifier
@ -43,10 +44,10 @@ function uupGetFiles(
} }
if(!uupApiCheckUpdateId($updateId)) { if(!uupApiCheckUpdateId($updateId)) {
return array('error' => 'INCORRECT_ID'); return array('error' => 'INCORRECT_ID');
} }
$info = @file_get_contents('fileinfo/'.$updateId.'.json'); $info = uupApiReadFileinfo($updateId);
if(empty($info)) { if(empty($info)) {
$info = array( $info = array(
'ring' => 'WIF', 'ring' => 'WIF',
@ -56,8 +57,6 @@ function uupGetFiles(
'sku' => '48', 'sku' => '48',
'files' => array(), 'files' => array(),
); );
} else {
$info = json_decode($info, true);
} }
if(isset($info['build'])) { if(isset($info['build'])) {

View File

@ -17,6 +17,7 @@ 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'; require_once dirname(__FILE__).'/shared/cache.php';
require_once dirname(__FILE__).'/shared/fileinfo.php';
function uupApiPrivateInvalidateFileinfoCache() { function uupApiPrivateInvalidateFileinfoCache() {
$cache1 = new UupDumpCache('listid-0', false); $cache1 = new UupDumpCache('listid-0', false);
@ -27,18 +28,19 @@ function uupApiPrivateInvalidateFileinfoCache() {
} }
function uupApiPrivateGetFromFileinfo($sortByDate = 0) { function uupApiPrivateGetFromFileinfo($sortByDate = 0) {
if(!file_exists('fileinfo')) return false; $dirs = uupApiGetFileinfoDirs();
$fileinfo = $dirs['fileinfoData'];
$fileinfoRoot = $dirs['fileinfo'];
$files = scandir('fileinfo'); $files = scandir($fileinfo);
$files = preg_grep('/\.json$/', $files); $files = preg_grep('/\.json$/', $files);
consoleLogger('Parsing database info...'); consoleLogger('Parsing database info...');
$cacheFile = 'cache/fileinfo_v2.json'; $cacheFile = $fileinfoRoot.'/cache.json';
$cacheV2Version = 1; $cacheV2Version = 1;
$database = @file_get_contents($cacheFile); $database = uupApiReadJson($cacheFile);
$database = json_decode($database, true);
if(isset($database['version'])) { if(isset($database['version'])) {
$version = $database['version']; $version = $database['version'];
@ -57,12 +59,13 @@ function uupApiPrivateGetFromFileinfo($sortByDate = 0) {
$newDb = array(); $newDb = array();
$builds = array(); $builds = array();
foreach($files as $file) { foreach($files as $file) {
if($file == '.' || $file == '..') continue; if($file == '.' || $file == '..')
continue;
$uuid = preg_replace('/\.json$/', '', $file); $uuid = preg_replace('/\.json$/', '', $file);
if(!isset($database[$uuid])) { if(!isset($database[$uuid])) {
$info = @file_get_contents('fileinfo/'.$file); $info = uupApiReadFileinfoMeta($uuid);
$info = json_decode($info, true);
$title = isset($info['title']) ? $info['title'] : 'UNKNOWN'; $title = isset($info['title']) ? $info['title'] : 'UNKNOWN';
$build = isset($info['build']) ? $info['build'] : 'UNKNOWN'; $build = isset($info['build']) ? $info['build'] : 'UNKNOWN';

94
shared/fileinfo.php Normal file
View File

@ -0,0 +1,94 @@
<?php
/*
Copyright 2022 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
require_once dirname(__FILE__).'/utils.php';
function uupApiGetFileinfoDirs() {
$dirs = [];
$dirs['fileinfo'] = 'fileinfo';
$dirs['fileinfoMeta'] = $dirs['fileinfo'].'/metadata';
$dirs['fileinfoData'] = $dirs['fileinfo'].'/full';
foreach($dirs as $dir) {
if(!file_exists($dir)) mkdir($dir);
}
return $dirs;
}
function uupApiGetFileinfoName($updateId, $meta = false) {
$fileName = $updateId.'.json';
$dirs = uupApiGetFileinfoDirs();
$fileinfoMeta = $dirs['fileinfoMeta'].'/'.$fileName;
$fileinfoData = $dirs['fileinfoData'].'/'.$fileName;
return $meta ? $fileinfoMeta : $fileinfoData;
}
function uupApiFileInfoExists($updateId) {
return file_exists(uupApiGetFileinfoName($updateId));
}
function uupApiWriteFileinfoMeta($updateId, $info) {
if(isset($info['files']))
unset($info['files']);
$file = uupApiGetFileinfoName($updateId, true);
return uupApiWriteJson($file, $info);
}
function uupApiWriteFileinfo($updateId, $info) {
$file = uupApiGetFileinfoName($updateId);
if(uupApiWriteJson($file, $info) === false)
return false;
return uupApiWriteFileinfoMeta($updateId, $info);
}
function uupApiReadFileinfoMeta($updateId) {
$file = uupApiGetFileinfoName($updateId, true);
if(file_exists($file))
return uupApiReadJson($file);
$info = uupApiReadFileinfo($updateId, false);
if($info === false)
return false;
if(isset($info['files']))
unset($info['files']);
if(uupApiWriteFileinfoMeta($updateId, $info) === false)
return false;
return $info;
}
function uupApiReadFileinfo($updateId, $meta = false) {
if(!uupApiFileInfoExists($updateId))
return false;
if($meta === true)
return uupApiReadFileinfoMeta($updateId);
$file = uupApiGetFileinfoName($updateId);
$info = uupApiReadJson($file);
return $info;
}

View File

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

View File

@ -166,3 +166,16 @@ function uupApiFixDownloadLink($link) {
$link $link
); );
} }
function uupApiReadJson($path) {
$data = @file_get_contents($path);
if(empty($data))
return false;
return json_decode($data, true);
}
function uupApiWriteJson($path, $data) {
return file_put_contents($path, json_encode($data)."\n");
}

View File

@ -17,36 +17,10 @@ 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'; require_once dirname(__FILE__).'/shared/cache.php';
require_once dirname(__FILE__).'/shared/fileinfo.php';
function uupApiPrivateGetFileinfo($updateId, $ignoreFiles) {
$cached = false;
if($ignoreFiles) {
$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);
}
if($ignoreFiles) {
if(isset($info['files'])) unset($info['files']);
if(!$cached) {
$cache->put($info, false);
}
}
return $info;
}
function uupUpdateInfo($updateId, $onlyInfo = 0, $ignoreFiles = false) { function uupUpdateInfo($updateId, $onlyInfo = 0, $ignoreFiles = false) {
$info = uupApiPrivateGetFileinfo($updateId, $ignoreFiles); $info = uupApiReadFileinfo($updateId, $ignoreFiles);
if($info === false) { if($info === false) {
return ['error' => 'UPDATE_INFORMATION_NOT_EXISTS']; return ['error' => 'UPDATE_INFORMATION_NOT_EXISTS'];
} }