Added search of builds in local database

This commit is contained in:
mkuba50 2018-02-10 01:10:57 +01:00
parent 6dc23e6737
commit 77de8b3efc
2 changed files with 30 additions and 4 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2017 UUP dump API authors Copyright 2018 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.
@ -17,7 +17,7 @@ limitations under the License.
require_once dirname(__FILE__).'/shared/main.php'; require_once dirname(__FILE__).'/shared/main.php';
function uupListIds() { function uupListIds($search = null) {
uupApiPrintBrand(); uupApiPrintBrand();
if(!file_exists('fileinfo')) return array('error' => 'NO_FILEINFO_DIR'); if(!file_exists('fileinfo')) return array('error' => 'NO_FILEINFO_DIR');
@ -100,6 +100,32 @@ function uupListIds() {
if(!$success) consoleLogger('Failed to update database cache.'); if(!$success) consoleLogger('Failed to update database cache.');
} }
if($search) {
$searchSafe = preg_quote($search, '/');
if(preg_match('/^".*"$/', $searchSafe)) {
$searchSafe = preg_replace('/^"|"$/', '', $searchSafe);
} else {
$searchSafe = str_replace(' ', '.*', $searchSafe);
}
foreach($builds as $key => $val) {
$buildString[$key] = $val['title'].' '.$val['build'].' '.$val['arch'];
}
$remove = preg_grep('/.*'.$searchSafe.'.*/i', $buildString, PREG_GREP_INVERT);
$removeKeys = array_keys($remove);
foreach($removeKeys as $value) {
unset($builds[$value]);
}
if(empty($builds)) {
return array('error' => 'SEARCH_NO_RESULTS');
}
unset($remove, $removeKeys, $buildString);
}
return array( return array(
'apiVersion' => uupApiVersion(), 'apiVersion' => uupApiVersion(),
'builds' => $builds, 'builds' => $builds,

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
Copyright 2017 UUP dump API authors Copyright 2018 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,7 +16,7 @@ limitations under the License.
*/ */
function uupApiVersion() { function uupApiVersion() {
return '1.9.1'; return '1.10.0';
} }
function uupApiPrintBrand() { function uupApiPrintBrand() {