Added check for updates

Uses the version number in config/speedtest.php hosted on github
This commit is contained in:
Henry Whitaker
2020-04-10 01:35:21 +01:00
parent dac08458d4
commit 16f9db371e
2 changed files with 43 additions and 2 deletions

View File

@@ -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,
];
} }
} }

View File

@@ -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);
} }