Skip to content

Commit 103347f

Browse files
authored
Merge pull request #215 from BlueprintFramework/use-http-client
Use proper http client
2 parents b42f110 + 14c432e commit 103347f

2 files changed

Lines changed: 9 additions & 17 deletions

File tree

app/Console/Commands/BlueprintFramework/MetadataCacheCommand.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Illuminate\Console\Command;
1515
use Illuminate\Support\Facades\DB;
16+
use Illuminate\Support\Facades\Http;
1617
use Pterodactyl\Models\ExtensionCachedMetadata;
1718
use Pterodactyl\BlueprintFramework\Services\PlaceholderService\BlueprintPlaceholderService;
1819
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Console\BlueprintConsoleLibrary as BlueprintExtensionLibrary;
@@ -41,12 +42,8 @@ public function handle()
4142
$installedExtensions = $this->blueprint->extensions();
4243

4344
// get version info
44-
$context = stream_context_create(['http' => ['method' => 'GET', 'header' => 'User-Agent: BlueprintFramework']]);
45-
$remoteVersions = @file_get_contents(
46-
$this->PlaceholderService->api_url() . '/api/extensions/latest',
47-
false,
48-
$context
49-
);
45+
$res = Http::get($this->PlaceholderService->api_url() . '/api/extensions/latest');
46+
$remoteVersions = $res->body();
5047

5148
if($remoteVersions) {
5249
$remoteVersionsData = json_decode($remoteVersions, true);

app/Console/Commands/BlueprintFramework/Version/VersionCacheCommand.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Pterodactyl\Console\Commands\BlueprintFramework\Version;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Http;
67
use Pterodactyl\BlueprintFramework\Services\PlaceholderService\BlueprintPlaceholderService;
78
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Console\BlueprintConsoleLibrary as BlueprintExtensionLibrary;
89

@@ -20,22 +21,16 @@ public function __construct(
2021

2122
public function handle()
2223
{
23-
$api_url = $this->PlaceholderService->api_url() . '/api/latest';
24-
$context = stream_context_create([
25-
'http' => [
26-
'method' => 'GET',
27-
'header' => 'User-Agent: BlueprintFramework',
28-
],
29-
]);
30-
$response = @file_get_contents($api_url, false, $context);
24+
$res = Http::get($this->PlaceholderService->api_url() . '/api/latest');
25+
$body = $res->body();
3126

32-
if ($response === false || empty($response)) {
27+
if ($body === false || empty($body)) {
3328
$this->blueprint->dbSet('blueprint', 'internal:version:latest', 'unknown');
3429
return false;
3530
}
3631

37-
if ($response) {
38-
$cleaned_response = preg_replace('/[[:^print:]]/', '', $response);
32+
if ($body) {
33+
$cleaned_response = preg_replace('/[[:^print:]]/', '', $body);
3934
$data = json_decode($cleaned_response, true);
4035
if (isset($data['name'])) {
4136
$latest_version = $data['name'];

0 commit comments

Comments
 (0)