praeclarum / FuGetGallery

An alternative web UI for browsing nuget packages
https://www.fuget.org
MIT License
683 stars 121 forks source link

Move to extract Icon property to display in PackageData #149

Open timheuer opened 3 years ago

timheuer commented 3 years ago

With the deprecation of iconUrl packages have moved to icon which is a package-local path to an icon image. Move to using this in PackageData and extract that as base64 data URI to display

praeclarum commented 3 years ago

Yeah I've been debating how to handle this (license too). Never considered the base64 trick. I like it!

timheuer commented 3 years ago

I did a quick hack to prove 'it works' but now need to figure out how to extract/read the image stream which really could be anywhere in the package -- so thinking PackageData would have another List for Images (anything with JPG/JPEG/PNG?) and then i guess need to iterate and match against IconUrl. Streaming the bytes is I guess the tricky part because right now Fuget only does that with nuspec as far as I can see?

praeclarum commented 3 years ago

The current streaming support is through PackageData.Entry which loads the compressed data from nuget into a MemoryStream. The memory stream is used to get seekability, but not everything requires that so there's some room for optimization.

The entries are queried when the package data is loaded. I think I already also force nuspec loading at that point (to check the license) so it should be easy to match up the XML icon name with the entry list at that point.

Somewhere around here:

https://github.com/praeclarum/FuGetGallery/blob/54b646e549944463768af4bb0f87dd7aca54b921/Data/PackageData.cs#L364-L367

loic-sharma commented 3 years ago

FYI while the iconUrl field in .nuspec files have been deprecated, the iconUrl field in the package metadata API is still valid: https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource#catalog-entry

Even for packages with embedded icons, nuget.org will have a valid iconUrl there. I would recommend loading icons from that URL.