mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 21:33:08 +01:00
Added check for updates
Uses the version number in config/speedtest.php hosted on github
This commit is contained in:
@@ -7,7 +7,47 @@ use Exception;
|
|||||||
class UpdateHelper {
|
class UpdateHelper {
|
||||||
public static function check()
|
public static function check()
|
||||||
{
|
{
|
||||||
$current = config('app.version', false);
|
$current = config('speedtest.version', false);
|
||||||
(!$current) ? false : '';
|
if($current === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$gitVersion = UpdateHelper::checkLatestVersion();
|
||||||
|
if($gitVersion === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bool)(version_compare($current, $gitVersion['version']));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function checkLatestVersion()
|
||||||
|
{
|
||||||
|
$user = config('speedtest.user');
|
||||||
|
$repo = config('speedtest.repo');
|
||||||
|
$branch = config('speedtest.branch');
|
||||||
|
|
||||||
|
$url = 'https://raw.githubusercontent.com/'.$user
|
||||||
|
.'/'
|
||||||
|
.$repo
|
||||||
|
.'/'
|
||||||
|
.$branch
|
||||||
|
.'/config/speedtest.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$gitFile = file_get_contents($url);
|
||||||
|
} catch(Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pattern = "/'version' => '([0-9]{1,}\.[0-9]{1,}\.[0-9]{1,})'/";
|
||||||
|
$version = [];
|
||||||
|
preg_match($pattern, $gitFile, $version);
|
||||||
|
$version = $version[1];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'repo' => $user . '/' . $repo,
|
||||||
|
'branch' => $branch,
|
||||||
|
'version' => $version,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class UpdateController extends Controller
|
|||||||
public function checkForUpdate()
|
public function checkForUpdate()
|
||||||
{
|
{
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
'method' => 'check for updates',
|
||||||
'update' => UpdateHelper::check(),
|
'update' => UpdateHelper::check(),
|
||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user