Files
jsmr/JSMR.UI.Blazor/Services/ImageUrlProvider.cs
Brian Bicknell 634050c06f
All checks were successful
ci / build-test (push) Successful in 2m16s
ci / publish-image (push) Has been skipped
Updated CI for Blazor WebAssembly. Added styles for product cards.
2025-11-15 02:34:15 -05:00

74 lines
2.8 KiB
C#

namespace JSMR.UI.Blazor.Services;
public static class ImageUrlProvider
{
public static string GetImageURL(string? productId, bool hasImage, DateTime? salesDate, string size)
{
string folder = "modpub";
string imageSize = "main";
string imageWorkType = productId != null ? productId.StartsWith("RJ") ? "doujin" : "professional" : "doujin";
switch (size)
{
case "small":
imageSize = "sam";
folder = "modpub";
break;
case "300x300":
imageSize = hasImage ? "main_300x300" : "main";
folder = "resize";
break;
case "240x":
//imageSize = hasImage ? imageWorkType == "doujin" ? "main_240x240" : "sam_170x" : "main";
imageSize = hasImage ? imageWorkType == "doujin" ? "main_240x240" : "main_240x240" : "main";
folder = "resize";
break;
case "main":
default:
imageSize = "main";
folder = "modpub";
break;
}
if (hasImage == false || productId == null)
{
string noImageUrlTemplate = "/images/web/home/no_img_[imageSize].gif";
string noImageUrl = noImageUrlTemplate.Replace("[imageSize]", imageSize);
return noImageUrl;
}
var imageUrlTemplate = "//img.dlsite.jp/[folder]/images2/[imageType1]/[imageWorkType]/[fullRoundedProductId]/[productId][imageType2]_img_[imageSize].jpg";
string productIdWithoutPrefixString = productId.Substring(2);
int productIdWithoutPrefix = Convert.ToInt32(productId.Substring(2));
string productIdPrefix = productId.Substring(0, 2);
int roundedProductId = (int)Math.Round(Math.Ceiling((double)productIdWithoutPrefix / 1000) * 1000);
int productIdWithPrefixStringLength = productIdWithoutPrefixString.Length;
int zeroPadLength = productIdWithPrefixStringLength - roundedProductId.ToString().Length;
var fullRoundedProductId = productIdPrefix.PadRight(productIdPrefix.Length + zeroPadLength, '0') + roundedProductId;
bool hasSalesDate = salesDate.HasValue;
string imageType1 = hasSalesDate ? "work" : "ana";
string imageType2 = hasSalesDate ? "" : "_ana";
string productLinkPage = salesDate.HasValue ? "work" : "announce";
string imageUrl = imageUrlTemplate
.Replace("[folder]", folder)
.Replace("[imageType1]", imageType1)
.Replace("[imageWorkType]", imageWorkType)
.Replace("[fullRoundedProductId]", fullRoundedProductId)
.Replace("[productId]", productId)
.Replace("[imageType2]", imageType2)
.Replace("[imageSize]", imageSize);
return imageUrl;
}
}