public async Task <byte[]> LoadImage(BadgeRequest request, string badgeValue, string additionalQuery) { if (badgeValue == null) { badgeValue = "unknown"; request.Color = "lightgrey"; } string requestUri = $"/badge/{request.Subject}-{badgeValue}-{request.Color}.{request.ImageExt.ToEnumMember()}" + additionalQuery; byte[] image = await FromCache(requestUri); if (image == null) { image = await client.GetByteArrayAsync(requestUri); await SaveCache(requestUri, image, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(1), SlidingExpiration = TimeSpan.FromHours(12) }); } else { await RefreshCache(requestUri); } return(image); }
public async Task <ActionResult <string> > Get(BadgeRequest request) { if (request.BadgeType == BadgeType.Unknown || request.ImageExt == ImageExt.Unknown) { return(BadRequest()); } var item = await marketplace.LoadVsmItemDataFromApi(request.ItemName); return(new ObjectResult(await shiledsIo.LoadImage(request, item?.ToBadgeValue(request.BadgeType), Request.QueryString.ToString())) { ContentTypes = new MediaTypeCollection { request.ContentType } }); }