| @@ -18,6 +18,7 @@ limitations under the License. | ||||
| require_once dirname(__FILE__).'/shared/main.php'; | ||||
| require_once dirname(__FILE__).'/shared/requests.php'; | ||||
| require_once dirname(__FILE__).'/shared/cache.php'; | ||||
| require_once dirname(__FILE__).'/shared/fileinfo.php'; | ||||
| require_once dirname(__FILE__).'/listid.php'; | ||||
|  | ||||
| function uupFetchUpd( | ||||
| @@ -288,10 +289,9 @@ function parseFetchUpdate($updateInfo, $out, $arch, $ring, $flight, $build, $sku | ||||
|     } | ||||
|  | ||||
|     $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('Parsing information to write...'); | ||||
|         if(!file_exists('fileinfo')) mkdir('fileinfo'); | ||||
|  | ||||
|         $fileList = preg_replace('/<Files>|<\/Files>/', '', $fileList[0]); | ||||
|         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('Writing new build information to the disk...'); | ||||
|  | ||||
|         $success = file_put_contents('fileinfo/'.$updateString.'.json', json_encode($temp)."\n"); | ||||
|         $success = uupApiWriteFileinfo($updateString, $temp); | ||||
|         if($success) { | ||||
|             consoleLogger('Successfully written build information to the disk.'); | ||||
|             $fileWrite = 'INFO_WRITTEN'; | ||||
|   | ||||
							
								
								
									
										7
									
								
								get.php
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								get.php
									
									
									
									
									
								
							| @@ -19,6 +19,7 @@ require_once dirname(__FILE__).'/shared/main.php'; | ||||
| require_once dirname(__FILE__).'/shared/requests.php'; | ||||
| require_once dirname(__FILE__).'/shared/packs.php'; | ||||
| require_once dirname(__FILE__).'/shared/cache.php'; | ||||
| require_once dirname(__FILE__).'/shared/fileinfo.php'; | ||||
|  | ||||
| /* | ||||
| $updateId       = Update Identifier | ||||
| @@ -43,10 +44,10 @@ function uupGetFiles( | ||||
|     } | ||||
|  | ||||
|     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)) { | ||||
|         $info = array( | ||||
|             'ring' => 'WIF', | ||||
| @@ -56,8 +57,6 @@ function uupGetFiles( | ||||
|             'sku' => '48', | ||||
|             'files' => array(), | ||||
|         ); | ||||
|     } else { | ||||
|         $info = json_decode($info, true); | ||||
|     } | ||||
|  | ||||
|     if(isset($info['build'])) { | ||||
|   | ||||
							
								
								
									
										19
									
								
								listid.php
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								listid.php
									
									
									
									
									
								
							| @@ -17,6 +17,7 @@ limitations under the License. | ||||
|  | ||||
| require_once dirname(__FILE__).'/shared/main.php'; | ||||
| require_once dirname(__FILE__).'/shared/cache.php'; | ||||
| require_once dirname(__FILE__).'/shared/fileinfo.php'; | ||||
|  | ||||
| function uupApiPrivateInvalidateFileinfoCache() { | ||||
|     $cache1 = new UupDumpCache('listid-0', false); | ||||
| @@ -27,18 +28,19 @@ function uupApiPrivateInvalidateFileinfoCache() { | ||||
| } | ||||
|  | ||||
| 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); | ||||
|  | ||||
|     consoleLogger('Parsing database info...'); | ||||
|  | ||||
|     $cacheFile = 'cache/fileinfo_v2.json'; | ||||
|     $cacheFile = $fileinfoRoot.'/cache.json'; | ||||
|     $cacheV2Version = 1; | ||||
|  | ||||
|     $database = @file_get_contents($cacheFile); | ||||
|     $database = json_decode($database, true); | ||||
|     $database = uupApiReadJson($cacheFile); | ||||
|  | ||||
|     if(isset($database['version'])) { | ||||
|         $version = $database['version']; | ||||
| @@ -57,12 +59,13 @@ function uupApiPrivateGetFromFileinfo($sortByDate = 0) { | ||||
|     $newDb = array(); | ||||
|     $builds = array(); | ||||
|     foreach($files as $file) { | ||||
|         if($file == '.' || $file == '..') continue; | ||||
|         if($file == '.' || $file == '..') | ||||
|             continue; | ||||
|  | ||||
|         $uuid = preg_replace('/\.json$/', '', $file); | ||||
|  | ||||
|         if(!isset($database[$uuid])) { | ||||
|             $info = @file_get_contents('fileinfo/'.$file); | ||||
|             $info = json_decode($info, true); | ||||
|             $info = uupApiReadFileinfoMeta($uuid); | ||||
|  | ||||
|             $title = isset($info['title']) ? $info['title'] : 'UNKNOWN'; | ||||
|             $build = isset($info['build']) ? $info['build'] : 'UNKNOWN'; | ||||
|   | ||||
							
								
								
									
										94
									
								
								shared/fileinfo.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								shared/fileinfo.php
									
									
									
									
									
										Normal 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; | ||||
| } | ||||
| @@ -16,7 +16,7 @@ limitations under the License. | ||||
| */ | ||||
|  | ||||
| function uupApiVersion() { | ||||
|     return '1.36.0'; | ||||
|     return '1.38.0'; | ||||
| } | ||||
|  | ||||
| require_once dirname(__FILE__).'/auths.php'; | ||||
|   | ||||
| @@ -166,3 +166,16 @@ function uupApiFixDownloadLink($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"); | ||||
| } | ||||
|   | ||||
| @@ -17,36 +17,10 @@ limitations under the License. | ||||
|  | ||||
| require_once dirname(__FILE__).'/shared/main.php'; | ||||
| require_once dirname(__FILE__).'/shared/cache.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; | ||||
| } | ||||
| require_once dirname(__FILE__).'/shared/fileinfo.php'; | ||||
|  | ||||
| function uupUpdateInfo($updateId, $onlyInfo = 0, $ignoreFiles = false) { | ||||
|     $info = uupApiPrivateGetFileinfo($updateId, $ignoreFiles); | ||||
|     $info = uupApiReadFileinfo($updateId, $ignoreFiles); | ||||
|     if($info === false) { | ||||
|         return ['error' => 'UPDATE_INFORMATION_NOT_EXISTS']; | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user