Skip to content

Support PackageIcon attribute & icon caching#423

Closed
iodes wants to merge 5 commits intoloic-sharma:masterfrom
iodes:feature/icon-attribute
Closed

Support PackageIcon attribute & icon caching#423
iodes wants to merge 5 commits intoloic-sharma:masterfrom
iodes:feature/icon-attribute

Conversation

@iodes
Copy link

@iodes iodes commented Nov 13, 2019

Summary of the changes (in less than 80 chars)

  • Support PackageIcon attribute added in the latest version of NuGet.
  • If a PackageIcon exists, it is automatically cached on the server.
  • This pull request resolves the NU5048 warning.

Addresses #123

return NotFound();
}

return File(iconStream, "image/png");
Copy link
Owner

@loic-sharma loic-sharma Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content type image/png may be incorrect. Can we use an empty string "" instead? If not, we can copy nuget.org's logic: https://github.com/NuGet/NuGet.Services.Metadata/blob/91f97be8882ec83c3dfd7521ebe62865ab3adb5d/src/Catalog/Icons/IconProcessor.cs#L170-L278

Copy link
Owner

@loic-sharma loic-sharma Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes if the empty string "" does not work:

  • I would add a DetermineContentTypeAsync to BaGet's StreamExtensions. That way you can do:
var contentType = iconStream.DetermineContentTypeAsync(cancellationToken);
return File(iconStream, contentType);
  • When copying the DetermineContentType method from NuGet.org, you can act as if onlyGallerySupported is true:
// Checks are ordered by format popularity among external icons for existing packages
if (ArrayStartsWith(imageData, PngHeader))
{
    return "image/png";
}

if (ArrayStartsWith(imageData, JpegHeader))
{
    return "image/jpeg";
}

return "";

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out using an empty string "" does not work. I will try image/xyz instead.

routes.MapRoute(
name: Routes.PackageDownloadIconRouteName,
template: "v3/package/{id}/{version}/icon",
defaults: new { controller = "PackageContent", action = "DownloadIconAsync" });
Copy link
Owner

@loic-sharma loic-sharma Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently ported BaGet to ASP.NET Core 3. You will need to change this to:

endpoints.MapControllerRoute(
    name: Routes.PackageDownloadIconRouteName,
     pattern: "v3/package/{id}/{version}/icon",
     defaults: new { controller = "PackageContent", action = "DownloadIcon" })

Sorry about that! 😅

<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="NuGet.Packaging" Version="$(NuGetPackageVersion)" />
<PackageReference Include="NuGet.Packaging" Version="5.3.1" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change. You can bump up the NuGet.Packaging version here:

<NuGetPackageVersion>5.0.0-rtm.5856</NuGetPackageVersion>

lowercasedNormalizedVersion,
iconPath);

result = await _storage.PutAsync(iconPath, iconStream, IconContentType, cancellationToken);
Copy link
Owner

@loic-sharma loic-sharma Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as here: let's try to use an empty string "" if possible, otherwise we can detect the content type

<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NuGet.Protocol" Version="$(NuGetPackageVersion)" />
<PackageReference Include="NuGet.Protocol" Version="5.3.1" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change. You can bump up the NuGet.Packaging version here:

<NuGetPackageVersion>5.0.0-rtm.5856</NuGetPackageVersion>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NuGet.Protocol" Version="5.0.0-rtm.5856" />
<PackageReference Include="NuGet.Protocol" Version="5.3.1" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now uses a variable $(NuGetPackageVersion). That is defined here:

<NuGetPackageVersion>5.0.0-rtm.5856</NuGetPackageVersion>

@loic-sharma
Copy link
Owner

loic-sharma commented Jan 21, 2020

I apologize for taking so long to look at this. I've left a few minor comments, I'll merge this in once you've addressed them. Thank you, this is amazing work! 😊

@softlion
Copy link

@loic-sharma you can update the merging branch directly if the changes are so minor, to speed up fix merging.

@loic-sharma loic-sharma changed the base branch from master to iodes-package-icon February 9, 2020 23:49
@loic-sharma loic-sharma changed the base branch from iodes-package-icon to master February 9, 2020 23:50
{
Id = id,
Version = versionString,
Id2 = id,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Id2 is unused

@loic-sharma loic-sharma mentioned this pull request Feb 10, 2020
48 tasks
@loic-sharma
Copy link
Owner

I've updated your changes with the latest master branch here: #469. Feel free to review, and thanks for opening this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants