Skip to content

Add information to the extensions overview that a new version of an extension is available #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
sirzento opened this issue Apr 14, 2025 · 6 comments
Open
1 task done
Assignees
Labels
scope:admin Issues or pull requests related to the Pterodactyl admin area.

Comments

@sirzento
Copy link
Contributor

sirzento commented Apr 14, 2025

Scope

Extension development

Explanation

To do that, extension would need a configuration inside the conf.yml that points to a url that contains version informations.

For now, that could be a link to the extension from builtbybit.com, sourcexchange.net or just to the github release section.
With that link, the current available version can be parsed and compared against the current installed version.

If the version does not match, then a small icon could be displayed in the extension overview at the extension, which informs the admin that a new version is available for this extension.


Edit: website parameter inside the conf.yml should already have that information I guess.

With a get request to that website and a simple query you can already get the current version pretty fast:

builtbybit.com:

document.getElementsByClassName("resourceVersion")[0].innerHTML;

sourcexchange.nat:

document.getElementById("information-heading").nextElementSibling.innerHTML.match(/v([^\s]+)/)[1];

github.com:

Add /releases/latest to the url and change the first part from https://github.com/ to https://api.github.com/repos/.
Example:
https://github.com/BlueprintFramework/framework/ will be https://api.github.com/repos/BlueprintFramework/framework/releases/latest.
This API call will have the latest version inside the tag_name property.


Another Edit:
I am not a php guy but something like that should work. Maybe this could be binded to a button "Check for extension updates" in the overview to not throw a bunch of requests every time you access the extension overview.

function getVersionFromUrl($extension_url) {
    $context = stream_context_create(["http" => ["header" => "User-Agent: x"]]);
    $data = @file_get_contents($extension_url, false, $context);

    if (strpos($extension_url, "github.com") !== false) {
        $api_url = "https://api.github.com/repos" . parse_url($extension_url, PHP_URL_PATH);
        $api_url = rtrim($api_url, "/") . "/releases/latest";
        $data = @file_get_contents($api_url, false, $context);
        
        if ($data) {
            $version = json_decode($data)->tag_name;
            return $version ? $version : null;
        }
    } elseif (strpos($extension_url, "sourcexchange.net") !== false) {
        if ($data && preg_match('/Release v([^\s]+)/', $data, $matches)) {
            return trim($matches[1]);
        }
    } elseif (strpos($extension_url, "builtbybit.com") !== false) {
        if ($data && preg_match('/<span class="resourceVersion">v([^<]+)<\/span>/', $data, $matches)) {
            return trim($matches[1]);
        }
    }

    return null;
}

This will return the latest version if a valid url is given. Will return null if the website isn't valid or can't be reached.

Is there an existing issue for this?

  • I have searched the existing issues before opening this issue.
@0x7d8
Copy link
Collaborator

0x7d8 commented Apr 14, 2025

this can technically also be achieved with the blueprint api which already has access to all required urls

@sirzento sirzento changed the title Add information to the extension overview that a new version of an extension is available Add information to the extensions overview that a new version of an extension is available Apr 14, 2025
@sirzento
Copy link
Contributor Author

Yeah it does work when changing the file https://github.com/BlueprintFramework/framework/blob/main/resources/views/blueprint/admin/entry.blade.php to:

@if(isset($EXTENSION_ID))
  <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 text-center" style="padding-left: 0px; padding-right: 17px;">
    <a href="{{ route('admin.extensions.'.$EXTENSION_ID.'.index') }}">
      <button class="btn extension-btn" style="width:100%;margin-bottom:17px;">
        <div class="extension-btn-overlay"></div>
        <img src="{{ $EXTENSION_ICON }}" alt="{{ $EXTENSION_ID }}" class="extension-btn-image2"/>
        <img src="{{ $EXTENSION_ICON }}" alt="" class="extension-btn-image"/>
        <p class="extension-btn-text">{{ $EXTENSION_NAME }}</p>
        @if($EXTENSION_VERSION != $EXTENSION_LATEST_VERSION)
            <p class="extension-btn-version" data-toggle="tooltip" data-placement="top" data-original-title="Update available">{{ $EXTENSION_VERSION }} <i class="bi bi-info-circle-fill text-danger"></i></p>
        @else
            <p class="extension-btn-version">{{ $EXTENSION_VERSION }}</p>
        @endif
        <i class="bi bi-arrow-right-short" style="font-size: 34px;position: absolute;top: 15px;right: 30px;"></i>
      </button>
    </a>
  </div>
@endif

and in the file https://github.com/BlueprintFramework/framework/blob/main/resources/views/admin/extensions.blade.php at line 8/9 adding the function I wrote and changing the part starting at line 110 to:

      @foreach($blueprint->extensions() as $extension)
        @include("blueprint.admin.entry", [
          'EXTENSION_ID' => $extension['identifier'],
          'EXTENSION_NAME' => $extension['name'],
          'EXTENSION_VERSION' => $extension['version'],
          'EXTENSION_ICON' => !empty($extension['icon']) 
            ? '/assets/extensions/'.$extension['identifier'].'/icon.'.pathinfo($extension['icon'], PATHINFO_EXTENSION)
            : '/assets/extensions/'.$extension['identifier'].'/icon.jpg',
          'EXTENSION_LATEST_VERSION' => getVersionFromUrl($extension['website'])
        ])
      @endforeach

will check if a new version is available.

Image

Image

@0x7d8
Copy link
Collaborator

0x7d8 commented Apr 14, 2025

It will probably be implemented natively in the API so it requires way less calls

@0x7d8
Copy link
Collaborator

0x7d8 commented Apr 14, 2025

If emma allows me to

@prplwtf
Copy link
Member

prplwtf commented Apr 14, 2025

This feature idea is getting a green light from me and will be on the backlog for next release.

Updates should be fetched by the Blueprint API and properly handled. Version info should be periodically fetched by Blueprint, ideally in one request. Version checking should be able to be turned on or off through a flag.

Version info will be fetched daily, through a timestamp generated through the telemetry UUID.

@sirzento
Copy link
Contributor Author

Very nice to hear.

yeah doing it somehwere inside the php files was just some trying out on my part on how this could look like 😄

@prplwtf prplwtf added scope:admin Issues or pull requests related to the Pterodactyl admin area. and removed enhancement labels Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:admin Issues or pull requests related to the Pterodactyl admin area.
Projects
None yet
Development

No branches or pull requests

3 participants