diff --git a/admin/dashboard/main.php b/admin/dashboard/main.php index 6318bd4..0dfd175 100644 --- a/admin/dashboard/main.php +++ b/admin/dashboard/main.php @@ -147,62 +147,4 @@ function time_elapsed_string($datetime, $full = false) { return $string ? implode(', ', $string) . ' ago' : 'just now'; } -const GITHUB_SOURCE_API = 'https://api.github.com/repos/Supernova3339/anonfiles/releases'; - -function checkForUpdates(Request $request, Response $response): Response - { - $jsonResponse = [ - 'status' => 'OK', - 'message' => 'Already Latest Version', - 'upgrade' => false, - ]; - - $acceptPrerelease = param($request, 'prerelease', 'false') === 'true'; - - try { - $json = $this->getApiJson(); - - foreach ($json as $release) { - if ( - $release->prerelease === $acceptPrerelease && - version_compare($release->tag_name, PLATFORM_VERSION, '>') && - version_compare($release->tag_name, 'prerelease', '<') - ) { - $jsonResponse['message'] = 'New version available!', [$release->tag_name]); - $jsonResponse['upgrade'] = true; - break; - } - - if (version_compare($release->tag_name, PLATFORM_VERSION, '<=')) { - break; - } - } - } catch (RuntimeException $e) { - $jsonResponse['status'] = 'ERROR'; - $jsonResponse['message'] = $e->getMessage(); - } - - return json($response, $jsonResponse); - } - - function getApiJson() - { - $opts = [ - 'http' => [ - 'method' => 'GET', - 'header' => [ - 'User-Agent: AnonFiles-App', - 'Accept: application/vnd.github.v3+json', - ], - ], - ]; - - $data = @file_get_contents(self::GITHUB_SOURCE_API, false, stream_context_create($opts)); - - if ($data === false) { - throw new RuntimeException('Cannot contact the Github API. Try again.'); - } - - return json_decode($data); - } ?>