优化历史包袱,修复发布页面默认0 恢哈伏笔

This commit is contained in:
yml2213
2026-05-23 09:41:45 +08:00
parent d1f46fd02e
commit 40f5252b2e
12 changed files with 101 additions and 335 deletions
+37 -19
View File
@@ -448,6 +448,8 @@ func rowsToDTO(rows []listingRow) []ListingDTO {
}
func (row listingRow) toDTO() ListingDTO {
assetSummary := decodeAssetSummary(row.AssetSummary)
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(row.ScreenshotURLS))
return ListingDTO{
ID: row.ID,
AccountID: row.AccountID,
@@ -461,8 +463,9 @@ func (row listingRow) toDTO() ListingDTO {
LoginPlatform: row.LoginPlatform,
RankLevel: row.RankLevel,
HafCoinAmount: row.HafCoinAmount,
AssetSummary: decodeAssetSummary(row.AssetSummary),
ScreenshotURLS: decodeScreenshots(row.ScreenshotURLS),
AssetSummary: assetSummary,
ScreenshotURLS: screenshotURLS,
CoverURL: firstScreenshotURL(screenshotURLS),
PriceHourly: row.PriceHourly,
PriceDaily: row.PriceDaily,
PriceWeekly: row.PriceWeekly,
@@ -479,6 +482,8 @@ func (row listingRow) toDTO() ListingDTO {
}
func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
assetSummary := decodeAssetSummary(account.AssetSummary)
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(account.ScreenshotURLS))
return &ListingDTO{
ID: listing.ID,
AccountID: account.ID,
@@ -490,8 +495,9 @@ func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
LoginPlatform: account.LoginPlatform,
RankLevel: account.RankLevel,
HafCoinAmount: account.HafCoinAmount,
AssetSummary: decodeAssetSummary(account.AssetSummary),
ScreenshotURLS: decodeScreenshots(account.ScreenshotURLS),
AssetSummary: assetSummary,
ScreenshotURLS: screenshotURLS,
CoverURL: firstScreenshotURL(screenshotURLS),
PriceHourly: listing.PriceHourly,
PriceDaily: listing.PriceDaily,
PriceWeekly: listing.PriceWeekly,
@@ -508,21 +514,9 @@ func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
}
func marshalScreenshots(urls []string) (datatypes.JSON, error) {
cleaned := make([]string, 0, len(urls))
seen := make(map[string]struct{}, len(urls))
for _, url := range urls {
url = strings.TrimSpace(url)
if url == "" {
continue
}
if _, ok := seen[url]; ok {
continue
}
seen[url] = struct{}{}
cleaned = append(cleaned, url)
if len(cleaned) >= 12 {
break
}
cleaned := cleanScreenshotURLs(urls)
if len(cleaned) > 12 {
cleaned = cleaned[:12]
}
raw, err := json.Marshal(cleaned)
if err != nil {
@@ -564,6 +558,30 @@ func decodeAssetSummary(raw datatypes.JSON) map[string]any {
return summary
}
func cleanScreenshotURLs(urls []string) []string {
cleaned := make([]string, 0, len(urls))
seen := make(map[string]struct{}, len(urls))
for _, url := range urls {
url = strings.TrimSpace(url)
if url == "" {
continue
}
if _, ok := seen[url]; ok {
continue
}
seen[url] = struct{}{}
cleaned = append(cleaned, url)
}
return cleaned
}
func firstScreenshotURL(urls []string) string {
if len(urls) == 0 {
return ""
}
return urls[0]
}
func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizType string, bizID uint64, meta AuditMeta, detail map[string]any) error {
raw, err := json.Marshal(detail)
if err != nil {