diff --git a/backend/internal/modules/listing/handler_public.go b/backend/internal/modules/listing/handler_public.go index b4955ff..d877ca5 100644 --- a/backend/internal/modules/listing/handler_public.go +++ b/backend/internal/modules/listing/handler_public.go @@ -60,7 +60,17 @@ func (h *Handler) Screenshot(c *gin.Context) { writeListingError(c, err) return } - h.writePublicObject(c, filemodule.ImageVariantFallbackKeys(key, filemodule.ImageVariantMedium)...) + variant := c.Query("variant") + var fallbackKeys []string + switch variant { + case "thumb": + fallbackKeys = filemodule.ImageVariantFallbackKeys(key, filemodule.ImageVariantThumb) + case "raw": + fallbackKeys = []string{key} + default: + fallbackKeys = filemodule.ImageVariantFallbackKeys(key, filemodule.ImageVariantMedium) + } + h.writePublicObject(c, fallbackKeys...) } func (h *Handler) writePublicObject(c *gin.Context, keys ...string) { diff --git a/backend/internal/modules/listing/presenter.go b/backend/internal/modules/listing/presenter.go index ba47c6e..f6bab7b 100644 --- a/backend/internal/modules/listing/presenter.go +++ b/backend/internal/modules/listing/presenter.go @@ -65,15 +65,71 @@ func sellerListings(items []ListingDTO) []ListingDTO { } func applyPublicListingURLs(item *ListingDTO) { + if item == nil { + return + } item.SourceChannel = "" item.IsExternalUpload = false + rawScreenshotURLs := item.ScreenshotURLS item.ScreenshotURLS = publicScreenshotURLs(item.ID, item.ScreenshotURLS, item.Status, item.ReviewStatus) if item.AssetSummary != nil { delete(item.AssetSummary, "import_meta") delete(item.AssetSummary, "price_breakdown") + applyPublicScreenshotGroups(item.ID, item.AssetSummary, rawScreenshotURLs, item.ScreenshotURLS) } } +func applyPublicScreenshotGroups(listingID uint64, assetSummary map[string]any, rawURLs []string, publicURLs []string) { + rawGroups, ok := assetSummary["screenshot_groups"].(map[string]any) + if !ok { + return + } + urlMap := make(map[string]string, len(rawURLs)) + keyMap := make(map[string]string, len(rawURLs)) + for i, rawURL := range rawURLs { + if i < len(publicURLs) { + urlMap[rawURL] = publicURLs[i] + if key := extractListingObjectKey(rawURL); key != "" { + keyMap[key] = publicURLs[i] + } + } + } + newGroups := make(map[string]any, len(rawGroups)) + for groupKey, groupVal := range rawGroups { + switch list := groupVal.(type) { + case []string: + converted := make([]string, len(list)) + for i, u := range list { + if pub, found := urlMap[u]; found { + converted[i] = pub + } else if key := extractListingObjectKey(u); key != "" && keyMap[key] != "" { + converted[i] = keyMap[key] + } else { + converted[i] = u + } + } + newGroups[groupKey] = converted + case []any: + converted := make([]string, len(list)) + for i, v := range list { + if s, ok := v.(string); ok { + if pub, found := urlMap[s]; found { + converted[i] = pub + } else if key := extractListingObjectKey(s); key != "" && keyMap[key] != "" { + converted[i] = keyMap[key] + } else { + converted[i] = s + } + } + } + newGroups[groupKey] = converted + default: + newGroups[groupKey] = groupVal + } + } + assetSummary["screenshot_groups"] = newGroups +} + func applySellerListingPrice(item *ListingDTO) { if item == nil { return diff --git a/backend/internal/modules/listing/service_test.go b/backend/internal/modules/listing/service_test.go index 21a014a..2ccb380 100644 --- a/backend/internal/modules/listing/service_test.go +++ b/backend/internal/modules/listing/service_test.go @@ -672,3 +672,30 @@ func containsString(values []string, target string) bool { } return false } + +func TestApplyPublicScreenshotGroups(t *testing.T) { + rawURLs := []string{ + "/api/files/object?key=listing/coin.png", + "/api/files/object?key=listing/skin1.png", + } + publicURLs := []string{ + "/api/listings/88/screenshots/0", + "/api/listings/88/screenshots/1", + } + summary := map[string]any{ + "screenshot_groups": map[string]any{ + "coin": []any{"/api/files/object?key=listing/coin.png"}, + "skin": []string{"/api/files/object?key=listing/skin1.png"}, + }, + } + applyPublicScreenshotGroups(88, summary, rawURLs, publicURLs) + groups := summary["screenshot_groups"].(map[string]any) + coinList := groups["coin"].([]string) + if len(coinList) != 1 || coinList[0] != "/api/listings/88/screenshots/0" { + t.Fatalf("expected /api/listings/88/screenshots/0, got %#v", coinList) + } + skinList := groups["skin"].([]string) + if len(skinList) != 1 || skinList[0] != "/api/listings/88/screenshots/1" { + t.Fatalf("expected /api/listings/88/screenshots/1, got %#v", skinList) + } +} diff --git a/frontend/src/features/listings/views/ListingDetailView.vue b/frontend/src/features/listings/views/ListingDetailView.vue index 2845a24..e824de5 100644 --- a/frontend/src/features/listings/views/ListingDetailView.vue +++ b/frontend/src/features/listings/views/ListingDetailView.vue @@ -40,6 +40,9 @@ import { readAssetString, getRatioValue, isTopTierInsurance, + getScreenshotThumbURL, + getScreenshotMediumURL, + getScreenshotRawURL, type ListingDisplayResource, } from '@/shared/utils/listingDisplay' @@ -165,7 +168,9 @@ const detailScreenshots = computed(() => { url, })) }) -const detailScreenshotUrls = computed(() => detailScreenshots.value.map(shot => shot.url)) +const detailScreenshotRawUrls = computed(() => + detailScreenshots.value.map(shot => getScreenshotRawURL(shot.url)) +) const activeScreenshot = computed(() => { if (detailScreenshots.value.length === 0) return null @@ -533,12 +538,12 @@ function goBack() {