Browse Source

feat: add baseUrl to AdsInterfaceDto and implement getBaseUrl method in ImageUrlBuilderService

Dave 1 month ago
parent
commit
d6b627c95f

+ 0 - 6
apps/box-mgnt-api/src/mgnt-backend/feature/ads/MIGRATION_NOTES.md

@@ -1,6 +0,0 @@
-# Ads migration notes
-
-- **Schema change** – `Ads` documents no longer store `adsModuleId`; the enum `adType` now sits directly on `Ads`.
-- **API compatibility** – mgnt endpoints still accept legacy `adsModuleId`, but the service resolves it to `adType` (logging a warning) and rejects when neither value is present. Once every caller switches to `adType`, you can remove the legacy branch.
-- **Data migration** – backfill every existing `Ads` record by copying `AdsModule.adType` into the new `adType` field, verify reads/writes no longer reference `adsModuleId`, and then retire the legacy key/payload mapping after caches flush.
-- **Cache migration** – `box:app:adpool:{adType}` and `app:ad:by-id:{adId}` now drive ad placement; legacy pools keyed by `adsModuleId` are only read once during fallback and should be pruned once the new adType-based caches are warm.

+ 1 - 1
apps/box-mgnt-api/src/mgnt-backend/feature/ads/ads.dto.ts

@@ -274,7 +274,7 @@ export interface AdsInterfaceDto {
   imgSource: PrismaImageSource;
   adsCoverImg?: string | null; // stored key (optional to expose)
   adsCoverImgUrl?: string | null; // final URL for frontend to use
-
+  baseUrl?: string | null; // base URL used to build adsCoverImgUrl
   startDt: bigint;
   expiryDt: bigint;
   seq: number;

+ 1 - 1
apps/box-mgnt-api/src/mgnt-backend/feature/ads/ads.service.ts

@@ -126,7 +126,7 @@ export class AdsService {
       imgSource: ad.imgSource,
       adsCoverImg: ad.adsCoverImg,
       adsCoverImgUrl: this.imageUrlBuilderService.buildAdsCoverUrl(ad),
-
+      baseUrl: this.imageUrlBuilderService.getBaseUrl(ad.imgSource),
       startDt: ad.startDt,
       expiryDt: ad.expiryDt,
       seq: ad.seq,

+ 12 - 0
apps/box-mgnt-api/src/mgnt-backend/feature/ads/image/image-url-builder.service.ts

@@ -75,6 +75,18 @@ export class ImageUrlBuilderService {
     return key;
   }
 
+  getBaseUrl(imgSource: 'LOCAL_ONLY' | 'S3_ONLY' | 'S3_AND_LOCAL'): string {
+    switch (imgSource) {
+      case 'S3_ONLY':
+        return this.s3BaseUrl;
+      case 'S3_AND_LOCAL':
+        return this.s3BaseUrl;
+      case 'LOCAL_ONLY':
+      default:
+        return this.localBaseUrl;
+    }
+  }
+
   // helpers
   private normalizeBaseUrl(url: string, configKey: string): string {
     const trimmed = url.trim().replace(/\/+$/, '');