Compare commits
4
Commits
a5c9357a24
..
uat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31d449916f | ||
|
|
2904e59e71 | ||
|
|
12c28963f5 | ||
|
|
32cac38a0e |
No files matched your search
@@ -181,6 +181,9 @@ app.register.max-per-device-per-day
|
||||
| GET | `/app/dramas/{id}` | 详情(含剧集列表,免费集带**已签名**播放地址) |
|
||||
| GET | `/app/search?keyword=&pageIndex=&pageSize=` | **匿名**。搜索已上线短剧:按标题/简介模糊匹配,分页返回卡片列表 |
|
||||
|
||||
首页、发现页和推荐流的卡片 `preview.posterUrl` 与详情的 `episodes[].posterUrl` 同源,
|
||||
有 READY 高清 poster 时返回签名地址;没有时为 `null`,客户端回退雪碧图。
|
||||
|
||||
`POST /app/dramas/page` 请求体:
|
||||
|
||||
```json
|
||||
@@ -289,6 +292,7 @@ app.register.max-per-device-per-day
|
||||
"likeCount": "45",
|
||||
"commentCount": "8",
|
||||
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c...",
|
||||
"posterUrl": "/files/transcoded/88/poster.jpg?e=1760000000&s=7b1e...",
|
||||
"thumbnailsUrl": "/files/transcoded/88/thumbnails/thumbnails.vtt?e=1760000000&s=8a1d..."
|
||||
}
|
||||
]
|
||||
@@ -306,6 +310,7 @@ app.register.max-per-device-per-day
|
||||
| `viewCount` | Long(JSON 字符串) | 取 `drama.view_count`,累计播放量,既有字段语义不变 |
|
||||
| `episodes[].likeCount` | Long(JSON 字符串) | 本集点赞数,取 `drama_episode.like_count` |
|
||||
| `episodes[].commentCount` | Long(JSON 字符串) | 本集未删除评论数,按 `episode_id` 统计 |
|
||||
| `episodes[].posterUrl` | String / null | 本集高清首帧 poster 签名地址;没有 READY 媒资时为 `null`,用于播放首帧占位 |
|
||||
| `episodes[].thumbnailsUrl` | String / null | 本集雪碧图 WebVTT 时间轴签名地址;没有 READY 产物时为 `null` |
|
||||
|
||||
计数是只读快照:互动操作完成后客户端重新拉取详情即可刷新;`Long` 字段一律按字符串下发,
|
||||
@@ -326,6 +331,7 @@ app.register.max-per-device-per-day
|
||||
"accessible": true,
|
||||
"accessType": "FREE",
|
||||
"playUrl": "/files/episode/202610/xxx.mp4?e=1760000000&s=9f2c...",
|
||||
"posterUrl": "/files/transcoded/88/poster.jpg?e=1760000000&s=7b1e...",
|
||||
"qualities": ["AUTO", "720p", "1080p"],
|
||||
"tracks": [
|
||||
{"quality": "AUTO", "playUrl": "/files/transcoded/88/master.m3u8?e=1760000000&s=9f2c..."},
|
||||
@@ -352,6 +358,9 @@ app.register.max-per-device-per-day
|
||||
`sprite_XXX.jpg#xywh=x,y,w,h`。有 READY `media_thumbnail` 时返回签名地址,
|
||||
无产物时为 `null`;该字段不影响 `playUrl`、`qualities` 和 HLS/原文件回落。
|
||||
|
||||
`posterUrl` 是转码产出的高清首帧 poster 签名地址;有 READY 媒资但没有 poster 时为
|
||||
`null`。客户端应优先用它作为视频纹理就绪前的占位,雪碧图仅作为回退和拖动预览使用。
|
||||
|
||||
**`GET /app/episodes/{id}/stats`(播放页计数刷新)**
|
||||
|
||||
只读返回本集点赞数、本集未删除评论数、所属剧收藏数,以及当前用户对
|
||||
@@ -1287,12 +1296,17 @@ commentSummary,createdAt`。游客的 userId 为空、anonymous 为 true;评
|
||||
| GET | `/admin/rewards/tasks/page` · `/tasks/{id}` | `reward:list` | 奖励任务分页与详情 |
|
||||
| POST | `/admin/rewards/tasks` | `reward:update` | 新建任务,默认下线 |
|
||||
| PUT | `/admin/rewards/tasks/{id}` · `/{id}/status` | `reward:update` | 编辑、上线 / 下线;编辑会递增版本 |
|
||||
| GET | `/admin/rewards/activities/page` · `/activities/{id}` | `reward:list` | 奖励活动分页与详情 |
|
||||
| POST | `/admin/rewards/activities` | `reward:update` | 新建活动,默认下线 |
|
||||
| PUT | `/admin/rewards/activities/{id}` · `/{id}/status` | `reward:update` | 编辑、上线 / 下线 |
|
||||
| GET · PUT | `/admin/rewards/check-in/rules` | `reward:checkin` | 查看 / 保存签到每日奖励规则,天数不能重复 |
|
||||
| GET | `/admin/rewards/grants/page` | `reward:grant` | 用户、任务、来源、状态筛选发放记录 |
|
||||
| POST | `/admin/rewards/grants/manual` | `reward:grant` | 人工补发;仍写 `REWARD` 钱包流水并要求幂等键 |
|
||||
|
||||
后台任务保存字段包括 `code`、`sectionCode`、`type`、`verifyMode`、`targetValue`、`rewardCoin`、`cycleType`、`cycleLimit`、三语言文案、动作、排序和生效时间。任务配置不允许后台写任意脚本,扩展字段只能放在 `configJson`。
|
||||
|
||||
后台活动保存字段包括 `code`、`coverUrl`、`actionType`、`actionUrl`、三语言标题、三语言摘要、三语言按钮文案、排序和生效时间。活动与任务共用 `reward:update` 权限,新建活动默认下线。
|
||||
|
||||
**校验与错误码**:
|
||||
|
||||
| 场景 | 结果 |
|
||||
|
||||
+45
@@ -3,8 +3,12 @@
|
||||
package com.fruitshorts.admin.controller;
|
||||
|
||||
import com.fruitshorts.commerce.reward.service.RewardCheckinService;
|
||||
import com.fruitshorts.commerce.reward.service.RewardActivityAdminService;
|
||||
import com.fruitshorts.commerce.reward.service.RewardGrantService;
|
||||
import com.fruitshorts.commerce.reward.service.RewardTaskService;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardActivityQueryReqVO;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardActivityRespVO;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardActivitySaveReqVO;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardCheckinRuleSaveReqVO;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardGrantQueryReqVO;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardGrantRespVO;
|
||||
@@ -45,6 +49,7 @@ import java.util.List;
|
||||
public class RewardAdminController {
|
||||
|
||||
private final RewardTaskService taskService;
|
||||
private final RewardActivityAdminService activityService;
|
||||
private final RewardCheckinService checkinService;
|
||||
private final RewardGrantService grantService;
|
||||
private final AppUserMapper appUserMapper;
|
||||
@@ -89,6 +94,46 @@ public class RewardAdminController {
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "奖励活动分页")
|
||||
@GetMapping("/activities/page")
|
||||
@PreAuthorize("@ss.hasPermission('reward:list')")
|
||||
public Result<PageResult<RewardActivityRespVO>> activityPage(@Validated RewardActivityQueryReqVO req) {
|
||||
return Result.ok(activityService.page(req));
|
||||
}
|
||||
|
||||
@Operation(summary = "奖励活动详情")
|
||||
@GetMapping("/activities/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('reward:list')")
|
||||
public Result<RewardActivityRespVO> activityDetail(@PathVariable Long id) {
|
||||
return Result.ok(activityService.detail(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "新建奖励活动")
|
||||
@PostMapping("/activities")
|
||||
@PreAuthorize("@ss.hasPermission('reward:update')")
|
||||
@OperationLog(module = "奖励中心", action = "新建奖励活动")
|
||||
public Result<Long> createActivity(@Valid @RequestBody RewardActivitySaveReqVO req) {
|
||||
return Result.ok(activityService.create(req));
|
||||
}
|
||||
|
||||
@Operation(summary = "编辑奖励活动")
|
||||
@PutMapping("/activities/{id}")
|
||||
@PreAuthorize("@ss.hasPermission('reward:update')")
|
||||
@OperationLog(module = "奖励中心", action = "编辑奖励活动")
|
||||
public Result<Void> updateActivity(@PathVariable Long id, @Valid @RequestBody RewardActivitySaveReqVO req) {
|
||||
activityService.update(id, req);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "奖励活动上下线")
|
||||
@PutMapping("/activities/{id}/status")
|
||||
@PreAuthorize("@ss.hasPermission('reward:update')")
|
||||
@OperationLog(module = "奖励中心", action = "奖励活动上下线")
|
||||
public Result<Void> updateActivityStatus(@PathVariable Long id, @RequestParam Integer status) {
|
||||
activityService.updateStatus(id, status);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "签到规则")
|
||||
@GetMapping("/check-in/rules")
|
||||
@PreAuthorize("@ss.hasPermission('reward:checkin')")
|
||||
|
||||
+2
-1
@@ -35,7 +35,8 @@ class AdminPermissionAnnotationTest {
|
||||
assertThat(permissionsOf(RewardAdminController.class))
|
||||
.containsExactlyInAnyOrder("reward:list", "reward:list", "reward:update",
|
||||
"reward:update", "reward:update", "reward:checkin", "reward:checkin",
|
||||
"reward:grant", "reward:grant");
|
||||
"reward:grant", "reward:grant", "reward:list", "reward:list",
|
||||
"reward:update", "reward:update", "reward:update");
|
||||
}
|
||||
|
||||
/** 收集控制器里所有映射方法的 @PreAuthorize 权限点(缺失则记为 MISSING,便于断言直接看到)。 */
|
||||
|
||||
+16
-5
@@ -27,6 +27,7 @@ import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.interaction.service.CommentService;
|
||||
import com.fruitshorts.media.service.PlaybackSigner;
|
||||
import com.fruitshorts.media.service.PosterUrlResolver;
|
||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||
import com.fruitshorts.content.vo.DramaCategoryRespVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -67,6 +68,7 @@ public class AppCatalogService {
|
||||
private final PlaybackSigner playbackSigner;
|
||||
private final CommentService commentService;
|
||||
private final ThumbnailUrlResolver thumbnailUrlResolver;
|
||||
private final PosterUrlResolver posterUrlResolver;
|
||||
|
||||
public AppFeedVO homeFeed() {
|
||||
Map<Long, Map<String, String>> categoryLocales = categoryLocaleMap();
|
||||
@@ -200,6 +202,9 @@ public class AppCatalogService {
|
||||
episodes.stream().map(DramaEpisode::getId).sorted().toList());
|
||||
Map<Long, String> thumbnailUrls = thumbnailUrlResolver.resolveAll(
|
||||
episodes.stream().map(DramaEpisode::getId).sorted().toList());
|
||||
Map<Long, String> posterUrls = posterUrlResolver.resolveAll(
|
||||
episodes.stream().map(DramaEpisode::getVideoAssetId)
|
||||
.filter(id -> id != null && id > 0L).distinct().toList());
|
||||
List<Map<String, String>> types = dramaCategoryService.localesForDrama(drama, categoryLocaleMap());
|
||||
|
||||
AppDramaDetailVO detail = new AppDramaDetailVO();
|
||||
@@ -222,7 +227,7 @@ public class AppCatalogService {
|
||||
detail.setFavoriteCount(drama.getFavoriteCount());
|
||||
detail.setCommentCount(commentService.countByDrama(dramaId));
|
||||
detail.setEpisodes(episodes.stream()
|
||||
.map(episode -> toEpisode(episode, episodeCommentCounts, thumbnailUrls))
|
||||
.map(episode -> toEpisode(episode, episodeCommentCounts, thumbnailUrls, posterUrls))
|
||||
.toList());
|
||||
return detail;
|
||||
}
|
||||
@@ -333,18 +338,21 @@ public class AppCatalogService {
|
||||
previews.values().stream().map(DramaEpisode::getId).sorted().toList());
|
||||
Map<Long, String> thumbnailUrls = thumbnailUrlResolver.resolveAll(
|
||||
previews.values().stream().map(DramaEpisode::getId).sorted().toList());
|
||||
Map<Long, String> posterUrls = posterUrlResolver.resolveAll(
|
||||
previews.values().stream().map(DramaEpisode::getVideoAssetId)
|
||||
.filter(id -> id != null && id > 0L).distinct().toList());
|
||||
Map<Long, ContentTag> tags = loadTags(dramas);
|
||||
return dramas.stream()
|
||||
.map(drama -> toCard(
|
||||
drama, categoryLocales, tags, previews.get(drama.getId()), commentCounts,
|
||||
thumbnailUrls))
|
||||
thumbnailUrls, posterUrls))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private AppDramaCardVO toCard(Drama drama, Map<Long, Map<String, String>> categoryLocales,
|
||||
Map<Long, ContentTag> tags,
|
||||
DramaEpisode preview, Map<Long, Long> commentCounts,
|
||||
Map<Long, String> thumbnailUrls) {
|
||||
Map<Long, String> thumbnailUrls, Map<Long, String> posterUrls) {
|
||||
List<Map<String, String>> types = dramaCategoryService.localesForDrama(drama, categoryLocales);
|
||||
AppDramaCardVO card = new AppDramaCardVO();
|
||||
card.setId(drama.getId());
|
||||
@@ -368,12 +376,12 @@ public class AppCatalogService {
|
||||
card.setLanguage(drama.getLanguage());
|
||||
card.setDramaType(drama.getDramaType());
|
||||
card.setPreview(preview == null
|
||||
? null : toEpisode(preview, commentCounts, thumbnailUrls));
|
||||
? null : toEpisode(preview, commentCounts, thumbnailUrls, posterUrls));
|
||||
return card;
|
||||
}
|
||||
|
||||
private AppEpisodeVO toEpisode(DramaEpisode episode, Map<Long, Long> commentCounts,
|
||||
Map<Long, String> thumbnailUrls) {
|
||||
Map<Long, String> thumbnailUrls, Map<Long, String> posterUrls) {
|
||||
AppEpisodeVO vo = new AppEpisodeVO();
|
||||
vo.setId(episode.getId());
|
||||
vo.setNumber(episode.getEpNo());
|
||||
@@ -388,6 +396,9 @@ public class AppCatalogService {
|
||||
vo.setLikeCount(episode.getLikeCount() == null ? 0L : episode.getLikeCount());
|
||||
vo.setCommentCount(commentCounts.getOrDefault(episode.getId(), 0L));
|
||||
vo.setThumbnailsUrl(thumbnailUrls.get(episode.getId()));
|
||||
if (episode.getVideoAssetId() != null) {
|
||||
vo.setPosterUrl(posterUrls.get(episode.getVideoAssetId()));
|
||||
}
|
||||
if (free) {
|
||||
// 播放地址统一在这里签名:客户端拿不到可长期复用的裸地址
|
||||
vo.setPlayUrl(playbackSigner.sign(playableSource(episode)));
|
||||
|
||||
@@ -35,7 +35,9 @@ public class AppSearchService {
|
||||
Page<Drama> page = new Page<>(safeIndex, safeSize);
|
||||
Page<Drama> result = dramaMapper.selectPage(page, Wrappers.<Drama>lambdaQuery()
|
||||
.eq(Drama::getStatus, ContentStatus.PUBLISHED.getCode())
|
||||
.and(w -> w.like(Drama::getTitle, keyword.trim())
|
||||
.and(w -> w.like(Drama::getTitleLocales, keyword.trim())
|
||||
.or().like(Drama::getSynopsisLocales, keyword.trim())
|
||||
.or().like(Drama::getTitle, keyword.trim())
|
||||
.or().like(Drama::getSynopsis, keyword.trim()))
|
||||
.orderByDesc(Drama::getSort)
|
||||
.orderByDesc(Drama::getId));
|
||||
|
||||
@@ -24,6 +24,8 @@ public class AppEpisodeVO {
|
||||
* 详情页拿到就能直接播,不必按集再请求一次播放票据。
|
||||
*/
|
||||
private String playUrl;
|
||||
/** 高清首帧 poster 地址;没有 READY 媒资时为 null */
|
||||
private String posterUrl;
|
||||
/** 雪碧图 WebVTT 时间轴地址;没有产物时为 null */
|
||||
private String thumbnailsUrl;
|
||||
}
|
||||
@@ -65,6 +65,11 @@ fruitshorts:
|
||||
# 仅作 sys_config 缺失/非法时的兜底;运行时优先读取后台「系统配置」
|
||||
register-max-per-ip-per-day: ${REGISTER_MAX_PER_IP_PER_DAY:5}
|
||||
register-max-per-device-per-day: ${REGISTER_MAX_PER_DEVICE_PER_DAY:3}
|
||||
google:
|
||||
# Google 登录允许的客户端 id(逗号分隔)。idToken 的 aud 随平台不同:
|
||||
# iOS 为 iOS 客户端 id,Android 为 serverClientId 对应的 Web 客户端 id。
|
||||
# 客户端 id 属公开信息,不是密钥;生产可用 GOOGLE_CLIENT_IDS 覆盖。
|
||||
client-ids: ${GOOGLE_CLIENT_IDS:11115008580-51gv4sj2c78rud6n127g3shu4d2n96un.apps.googleusercontent.com,11115008580-dbqe47fhp5560nhrocrppiq7hcnlvl1s.apps.googleusercontent.com,11115008580-1v5pt5mfgbbuba74ebia6hngj618ne3a.apps.googleusercontent.com}
|
||||
interaction:
|
||||
# MACHINE_FIRST:机审通过即发布,命中 REVIEW 级敏感词才转人工
|
||||
# PRE_REVIEW :全部先审后发(生产建议)
|
||||
|
||||
+8
-1
@@ -9,6 +9,7 @@ import com.fruitshorts.app.vo.AppBannerVO;
|
||||
import com.fruitshorts.app.vo.AppCategoryVO;
|
||||
import com.fruitshorts.app.vo.AppDramaCardVO;
|
||||
import com.fruitshorts.app.vo.AppDramaDetailVO;
|
||||
import com.fruitshorts.app.vo.AppEpisodeVO;
|
||||
import com.fruitshorts.app.vo.AppFeedVO;
|
||||
import com.fruitshorts.app.vo.AppSectionVO;
|
||||
import com.fruitshorts.app.vo.AppRankingEntryVO;
|
||||
@@ -75,6 +76,10 @@ class AppCatalogControllerContractTest {
|
||||
card.setLikeCount(3200L);
|
||||
card.setFavoriteCount(1800L);
|
||||
card.setCommentCount(96L);
|
||||
AppEpisodeVO preview = new AppEpisodeVO();
|
||||
preview.setId(21L);
|
||||
preview.setPosterUrl("/files/transcoded/21/poster.jpg?e=1&s=sig");
|
||||
card.setPreview(preview);
|
||||
AppSectionVO section = new AppSectionVO("hot", "热门推荐", List.of(card));
|
||||
AppFeedVO feed = new AppFeedVO(List.of(banner), List.of(section));
|
||||
given(catalogService.homeFeed()).willReturn(feed);
|
||||
@@ -88,7 +93,9 @@ class AppCatalogControllerContractTest {
|
||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].viewCount").value("12400"))
|
||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].likeCount").value("3200"))
|
||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].favoriteCount").value("1800"))
|
||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].commentCount").value("96"));
|
||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].commentCount").value("96"))
|
||||
.andExpect(jsonPath("$.data.sections[0].dramas[0].preview.posterUrl")
|
||||
.value("/files/transcoded/21/poster.jpg?e=1&s=sig"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+6
-4
@@ -60,10 +60,10 @@ class AppPlaybackContractTest {
|
||||
|
||||
@Test
|
||||
void should_return_free_access_when_episode_is_free() throws Exception {
|
||||
given(playbackService.play(isNull(), eq(11L), any(), any()))
|
||||
.willReturn(ticket(11L, true, PlaybackService.ACCESS_FREE,
|
||||
"/files/ep.mp4?s=1",
|
||||
"/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig"));
|
||||
PlayRespVO free = ticket(11L, true, PlaybackService.ACCESS_FREE,
|
||||
"/files/ep.mp4?s=1", "/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig");
|
||||
free.setPosterUrl("/files/transcoded/11/poster.jpg?e=1&s=sig");
|
||||
given(playbackService.play(isNull(), eq(11L), any(), any())).willReturn(free);
|
||||
|
||||
mockMvc.perform(get("/app/episodes/11/play").header("X-Device-Id", "device-9"))
|
||||
.andExpect(status().isOk())
|
||||
@@ -74,6 +74,8 @@ class AppPlaybackContractTest {
|
||||
.andExpect(jsonPath("$.data.accessible").value(true))
|
||||
.andExpect(jsonPath("$.data.accessType").value(PlaybackService.ACCESS_FREE))
|
||||
.andExpect(jsonPath("$.data.playUrl").value("/files/ep.mp4?s=1"))
|
||||
.andExpect(jsonPath("$.data.posterUrl")
|
||||
.value("/files/transcoded/11/poster.jpg?e=1&s=sig"))
|
||||
.andExpect(jsonPath("$.data.thumbnailsUrl")
|
||||
.value("/files/transcoded/11/thumbnails/thumbnails.vtt?e=1&s=sig"))
|
||||
.andExpect(jsonPath("$.data.likeCount").value("88"))
|
||||
|
||||
+18
-1
@@ -15,6 +15,7 @@ import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.interaction.service.CommentService;
|
||||
import com.fruitshorts.media.service.PlaybackSigner;
|
||||
import com.fruitshorts.media.service.PosterUrlResolver;
|
||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -40,6 +41,7 @@ class AppCatalogServiceTest {
|
||||
private DramaCategoryService dramaCategoryService;
|
||||
private CommentService commentService;
|
||||
private ThumbnailUrlResolver thumbnailUrlResolver;
|
||||
private PosterUrlResolver posterUrlResolver;
|
||||
private AppCatalogService catalogService;
|
||||
|
||||
@BeforeEach
|
||||
@@ -53,10 +55,12 @@ class AppCatalogServiceTest {
|
||||
PlaybackSigner playbackSigner = mock(PlaybackSigner.class);
|
||||
thumbnailUrlResolver = mock(ThumbnailUrlResolver.class);
|
||||
given(thumbnailUrlResolver.resolveAll(any())).willReturn(Map.of());
|
||||
posterUrlResolver = mock(PosterUrlResolver.class);
|
||||
given(posterUrlResolver.resolveAll(any())).willReturn(Map.of());
|
||||
commentService = mock(CommentService.class);
|
||||
catalogService = new AppCatalogService(dramaService, episodeService, bannerService,
|
||||
dramaCategoryService, mock(ContentTagService.class), dramaClassificationService, dramaPlaylistCategoryService,
|
||||
playbackSigner, commentService, thumbnailUrlResolver);
|
||||
playbackSigner, commentService, thumbnailUrlResolver, posterUrlResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,6 +82,10 @@ class AppCatalogServiceTest {
|
||||
.willReturn(Map.of(11L, 2L, 22L, 4L));
|
||||
given(thumbnailUrlResolver.resolveAll(List.of(11L, 22L)))
|
||||
.willReturn(Map.of(22L, "/files/transcoded/22/thumbnails/thumbnails.vtt"));
|
||||
firstEpisode.setVideoAssetId(101L);
|
||||
secondEpisode.setVideoAssetId(202L);
|
||||
given(posterUrlResolver.resolveAll(List.of(202L, 101L)))
|
||||
.willReturn(Map.of(202L, "/files/transcoded/22/poster.jpg?e=1&s=sig"));
|
||||
|
||||
AppDramaDetailVO detail = catalogService.dramaDetail(42L);
|
||||
|
||||
@@ -89,6 +97,8 @@ class AppCatalogServiceTest {
|
||||
assertThat(detail.getEpisodes().get(0).getCommentCount()).isEqualTo(4L);
|
||||
assertThat(detail.getEpisodes().get(0).getThumbnailsUrl())
|
||||
.isEqualTo("/files/transcoded/22/thumbnails/thumbnails.vtt");
|
||||
assertThat(detail.getEpisodes().get(0).getPosterUrl())
|
||||
.isEqualTo("/files/transcoded/22/poster.jpg?e=1&s=sig");
|
||||
verify(commentService).countByDrama(42L);
|
||||
verify(thumbnailUrlResolver).resolveAll(List.of(11L, 22L));
|
||||
}
|
||||
@@ -109,6 +119,8 @@ class AppCatalogServiceTest {
|
||||
second.setFavoriteCount(80L);
|
||||
DramaEpisode firstEpisode = episode(11L, 1L, 320L);
|
||||
DramaEpisode secondEpisode = episode(22L, 2L, 120L);
|
||||
firstEpisode.setVideoAssetId(101L);
|
||||
secondEpisode.setVideoAssetId(202L);
|
||||
Map<Long, DramaEpisode> previews = new LinkedHashMap<>();
|
||||
previews.put(2L, secondEpisode);
|
||||
previews.put(1L, firstEpisode);
|
||||
@@ -116,6 +128,8 @@ class AppCatalogServiceTest {
|
||||
given(dramaCategoryService.listBasic()).willReturn(List.of());
|
||||
given(commentService.countByEpisodes(List.of(11L, 22L)))
|
||||
.willReturn(Map.of(11L, 9L));
|
||||
given(posterUrlResolver.resolveAll(List.of(202L, 101L)))
|
||||
.willReturn(Map.of(101L, "/files/transcoded/11/poster.jpg?e=1&s=sig"));
|
||||
|
||||
List<AppDramaCardVO> cards = catalogService.toCards(List.of(first, second));
|
||||
|
||||
@@ -123,10 +137,13 @@ class AppCatalogServiceTest {
|
||||
assertThat(cards.get(0).getLikeCount()).isEqualTo(320L);
|
||||
assertThat(cards.get(0).getFavoriteCount()).isEqualTo(180L);
|
||||
assertThat(cards.get(0).getCommentCount()).isEqualTo(9L);
|
||||
assertThat(cards.get(0).getPreview().getPosterUrl())
|
||||
.isEqualTo("/files/transcoded/11/poster.jpg?e=1&s=sig");
|
||||
assertThat(cards.get(1).getLikeCount()).isEqualTo(120L);
|
||||
assertThat(cards.get(1).getFavoriteCount()).isEqualTo(80L);
|
||||
assertThat(cards.get(1).getCommentCount()).isZero();
|
||||
verify(commentService).countByEpisodes(List.of(11L, 22L));
|
||||
verify(posterUrlResolver).resolveAll(List.of(202L, 101L));
|
||||
verify(commentService, never()).countByDrama(any());
|
||||
}
|
||||
|
||||
|
||||
+18
-1
@@ -9,6 +9,7 @@ import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.media.dal.entity.MediaRendition;
|
||||
import com.fruitshorts.media.service.PlaybackSigner;
|
||||
import com.fruitshorts.media.service.PosterUrlResolver;
|
||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||
import com.fruitshorts.media.service.TranscodeService;
|
||||
import com.fruitshorts.playback.dal.entity.PlaybackTicket;
|
||||
@@ -48,6 +49,7 @@ class PlaybackServiceTest {
|
||||
private EntitlementPort entitlementPort;
|
||||
private TranscodeService transcodeService;
|
||||
private ThumbnailUrlResolver thumbnailUrlResolver;
|
||||
private PosterUrlResolver posterUrlResolver;
|
||||
private PlaybackService playbackService;
|
||||
|
||||
@BeforeEach
|
||||
@@ -59,11 +61,13 @@ class PlaybackServiceTest {
|
||||
entitlementPort = mock(EntitlementPort.class);
|
||||
transcodeService = mock(TranscodeService.class);
|
||||
thumbnailUrlResolver = mock(ThumbnailUrlResolver.class);
|
||||
posterUrlResolver = mock(PosterUrlResolver.class);
|
||||
playbackService = new PlaybackService(episodeService, dramaService, ticketMapper, signer,
|
||||
entitlementPort, transcodeService, thumbnailUrlResolver);
|
||||
entitlementPort, transcodeService, thumbnailUrlResolver, posterUrlResolver);
|
||||
given(dramaService.getPublished(anyLong())).willReturn(drama());
|
||||
given(transcodeService.listRenditions(anyLong())).willReturn(List.of());
|
||||
given(thumbnailUrlResolver.resolve(anyLong())).willReturn(null);
|
||||
given(posterUrlResolver.resolve(anyLong())).willReturn(null);
|
||||
given(signer.sign(anyString())).willReturn("/files/episode/1.mp4?e=1&s=sig");
|
||||
}
|
||||
|
||||
@@ -92,6 +96,19 @@ class PlaybackServiceTest {
|
||||
.isEqualTo("/files/transcoded/1/thumbnails/thumbnails.vtt?e=1&s=sig");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_signed_poster_url_when_poster_exists() {
|
||||
DramaEpisode episode = episode(11L, 1, 0, "/files/episode/1.mp4");
|
||||
episode.setVideoAssetId(101L);
|
||||
given(episodeService.getPublished(11L)).willReturn(episode);
|
||||
given(posterUrlResolver.resolve(101L))
|
||||
.willReturn("/files/transcoded/1/poster.jpg?e=1&s=sig");
|
||||
|
||||
PlayRespVO resp = playbackService.play(null, 11L, "device-9", "203.0.113.8");
|
||||
|
||||
assertThat(resp.getPosterUrl()).isEqualTo("/files/transcoded/1/poster.jpg?e=1&s=sig");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_null_thumbnails_url_when_thumbnail_is_absent() {
|
||||
given(episodeService.getPublished(11L)).willReturn(episode(11L, 1, 0, "/files/episode/1.mp4"));
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ public class SecurityConfig {
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
configuration.setAllowedOrigins(Arrays.stream(allowedOrigins.split(",")).map(String::trim).toList());
|
||||
configuration.setAllowedOriginPatterns(Arrays.stream(allowedOrigins.split(",")).map(String::trim).toList());
|
||||
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
|
||||
configuration.setAllowedHeaders(List.of("*"));
|
||||
configuration.setAllowCredentials(true);
|
||||
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.commerce.reward.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fruitshorts.commerce.reward.dal.entity.RewardActivity;
|
||||
import com.fruitshorts.commerce.reward.dal.mapper.RewardActivityMapper;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardActivityQueryReqVO;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardActivityRespVO;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardActivitySaveReqVO;
|
||||
import com.fruitshorts.common.exception.ErrorCode;
|
||||
import com.fruitshorts.common.exception.ServiceException;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/** 奖励中心活动的后台配置服务。 */
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RewardActivityAdminService {
|
||||
|
||||
private final RewardActivityMapper activityMapper;
|
||||
|
||||
/** 分页查询活动配置。 */
|
||||
public PageResult<RewardActivityRespVO> page(RewardActivityQueryReqVO req) {
|
||||
Page<RewardActivity> page = new Page<>(req.getSafePageIndex(), req.getSafePageSize());
|
||||
IPage<RewardActivity> result = activityMapper.selectPage(page, Wrappers.<RewardActivity>lambdaQuery()
|
||||
.eq(RewardActivity::getDeleted, 0)
|
||||
.eq(req.getStatus() != null, RewardActivity::getStatus, req.getStatus())
|
||||
.and(StringUtils.hasText(req.getKeyword()), w -> w
|
||||
.like(RewardActivity::getCode, req.getKeyword())
|
||||
.or().like(RewardActivity::getTitleId, req.getKeyword())
|
||||
.or().like(RewardActivity::getTitleEn, req.getKeyword())
|
||||
.or().like(RewardActivity::getTitleZh, req.getKeyword()))
|
||||
.orderByAsc(RewardActivity::getSort)
|
||||
.orderByDesc(RewardActivity::getId));
|
||||
return new PageResult<>(result.getTotal(), result.getRecords().stream()
|
||||
.map(RewardActivityRespVO::of).toList());
|
||||
}
|
||||
|
||||
/** 查询活动详情。 */
|
||||
public RewardActivityRespVO detail(Long id) {
|
||||
return RewardActivityRespVO.of(getExisting(id));
|
||||
}
|
||||
|
||||
/** 新建活动,默认下线,避免半配置内容立即展示。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long create(RewardActivitySaveReqVO req) {
|
||||
validate(req);
|
||||
String code = req.getCode().trim();
|
||||
requireCodeFree(code, null);
|
||||
RewardActivity activity = new RewardActivity();
|
||||
activity.setCode(code);
|
||||
apply(activity, req);
|
||||
activity.setStatus(0);
|
||||
activityMapper.insert(activity);
|
||||
return activity.getId();
|
||||
}
|
||||
|
||||
/** 编辑活动,保留现有上下线状态。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Long id, RewardActivitySaveReqVO req) {
|
||||
validate(req);
|
||||
RewardActivity activity = getExisting(id);
|
||||
String code = req.getCode().trim();
|
||||
requireCodeFree(code, id);
|
||||
activity.setCode(code);
|
||||
apply(activity, req);
|
||||
activityMapper.updateById(activity);
|
||||
}
|
||||
|
||||
/** 上线或下线活动。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateStatus(Long id, Integer status) {
|
||||
if (status == null || (status != 0 && status != 1)) {
|
||||
throw new ServiceException(ErrorCode.BAD_REQUEST, "状态只能是 0 或 1");
|
||||
}
|
||||
RewardActivity activity = getExisting(id);
|
||||
activity.setStatus(status);
|
||||
activityMapper.updateById(activity);
|
||||
}
|
||||
|
||||
private void validate(RewardActivitySaveReqVO req) {
|
||||
if (req == null || !StringUtils.hasText(req.getCode()) || !StringUtils.hasText(req.getTitleId())) {
|
||||
throw new ServiceException(ErrorCode.BAD_REQUEST, "请填写活动编码和印尼语标题");
|
||||
}
|
||||
}
|
||||
|
||||
private void apply(RewardActivity activity, RewardActivitySaveReqVO req) {
|
||||
activity.setCoverUrl(valueOrEmpty(req.getCoverUrl()));
|
||||
activity.setActionType(valueOrDefault(req.getActionType(), "NONE"));
|
||||
activity.setActionUrl(valueOrEmpty(req.getActionUrl()));
|
||||
activity.setTitleId(req.getTitleId().trim());
|
||||
activity.setTitleEn(valueOrEmpty(req.getTitleEn()));
|
||||
activity.setTitleZh(valueOrEmpty(req.getTitleZh()));
|
||||
activity.setSummaryId(valueOrEmpty(req.getSummaryId()));
|
||||
activity.setSummaryEn(valueOrEmpty(req.getSummaryEn()));
|
||||
activity.setSummaryZh(valueOrEmpty(req.getSummaryZh()));
|
||||
activity.setCtaId(valueOrEmpty(req.getCtaId()));
|
||||
activity.setCtaEn(valueOrEmpty(req.getCtaEn()));
|
||||
activity.setCtaZh(valueOrEmpty(req.getCtaZh()));
|
||||
activity.setSort(req.getSort() == null ? 0 : req.getSort());
|
||||
activity.setStartAt(req.getStartAt());
|
||||
activity.setEndAt(req.getEndAt());
|
||||
}
|
||||
|
||||
private RewardActivity getExisting(Long id) {
|
||||
RewardActivity activity = id == null ? null : activityMapper.selectById(id);
|
||||
if (activity == null || Integer.valueOf(1).equals(activity.getDeleted())) {
|
||||
throw new ServiceException(ErrorCode.DATA_NOT_FOUND, "奖励活动不存在");
|
||||
}
|
||||
return activity;
|
||||
}
|
||||
|
||||
private void requireCodeFree(String code, Long excludeId) {
|
||||
Long count = activityMapper.selectCount(Wrappers.<RewardActivity>lambdaQuery()
|
||||
.eq(RewardActivity::getCode, code)
|
||||
.eq(RewardActivity::getDeleted, 0)
|
||||
.ne(excludeId != null, RewardActivity::getId, excludeId));
|
||||
if (count != null && count > 0) {
|
||||
throw new ServiceException(ErrorCode.DATA_EXISTS, "活动编码已存在:" + code);
|
||||
}
|
||||
}
|
||||
|
||||
private String valueOrEmpty(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
private String valueOrDefault(String value, String fallback) {
|
||||
return StringUtils.hasText(value) ? value.trim() : fallback;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.commerce.reward.vo;
|
||||
|
||||
import com.fruitshorts.common.pojo.PageParam;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/** 后台奖励活动分页条件。 */
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class RewardActivityQueryReqVO extends PageParam {
|
||||
|
||||
private String keyword;
|
||||
private Integer status;
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.commerce.reward.vo;
|
||||
|
||||
import com.fruitshorts.commerce.reward.dal.entity.RewardActivity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 后台奖励活动响应。 */
|
||||
@Data
|
||||
public class RewardActivityRespVO {
|
||||
|
||||
private Long id;
|
||||
private String code;
|
||||
private String coverUrl;
|
||||
private String actionType;
|
||||
private String actionUrl;
|
||||
private String titleId;
|
||||
private String titleEn;
|
||||
private String titleZh;
|
||||
private String summaryId;
|
||||
private String summaryEn;
|
||||
private String summaryZh;
|
||||
private String ctaId;
|
||||
private String ctaEn;
|
||||
private String ctaZh;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
private String statusText;
|
||||
private LocalDateTime startAt;
|
||||
private LocalDateTime endAt;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
/** 将活动实体转换为后台展示模型。 */
|
||||
public static RewardActivityRespVO of(RewardActivity activity) {
|
||||
RewardActivityRespVO vo = new RewardActivityRespVO();
|
||||
vo.id = activity.getId();
|
||||
vo.code = activity.getCode();
|
||||
vo.coverUrl = activity.getCoverUrl();
|
||||
vo.actionType = activity.getActionType();
|
||||
vo.actionUrl = activity.getActionUrl();
|
||||
vo.titleId = activity.getTitleId();
|
||||
vo.titleEn = activity.getTitleEn();
|
||||
vo.titleZh = activity.getTitleZh();
|
||||
vo.summaryId = activity.getSummaryId();
|
||||
vo.summaryEn = activity.getSummaryEn();
|
||||
vo.summaryZh = activity.getSummaryZh();
|
||||
vo.ctaId = activity.getCtaId();
|
||||
vo.ctaEn = activity.getCtaEn();
|
||||
vo.ctaZh = activity.getCtaZh();
|
||||
vo.sort = activity.getSort();
|
||||
vo.status = activity.getStatus();
|
||||
vo.statusText = activity.getStatus() != null && activity.getStatus() == 1 ? "已上线" : "已下线";
|
||||
vo.startAt = activity.getStartAt();
|
||||
vo.endAt = activity.getEndAt();
|
||||
vo.createdAt = activity.getCreatedAt();
|
||||
vo.updatedAt = activity.getUpdatedAt();
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.commerce.reward.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 后台奖励活动新增和编辑参数。 */
|
||||
@Data
|
||||
public class RewardActivitySaveReqVO {
|
||||
|
||||
@NotBlank(message = "请填写活动编码")
|
||||
@Size(max = 64, message = "活动编码过长")
|
||||
private String code;
|
||||
@Size(max = 512, message = "封面地址过长")
|
||||
private String coverUrl;
|
||||
private String actionType;
|
||||
@Size(max = 512, message = "跳转地址过长")
|
||||
private String actionUrl;
|
||||
@NotBlank(message = "请填写印尼语标题")
|
||||
private String titleId;
|
||||
private String titleEn;
|
||||
private String titleZh;
|
||||
private String summaryId;
|
||||
private String summaryEn;
|
||||
private String summaryZh;
|
||||
private String ctaId;
|
||||
private String ctaEn;
|
||||
private String ctaZh;
|
||||
private Integer sort;
|
||||
private LocalDateTime startAt;
|
||||
private LocalDateTime endAt;
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.commerce.reward.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.fruitshorts.commerce.reward.dal.entity.RewardActivity;
|
||||
import com.fruitshorts.commerce.reward.dal.mapper.RewardActivityMapper;
|
||||
import com.fruitshorts.commerce.reward.vo.RewardActivitySaveReqVO;
|
||||
import com.fruitshorts.common.exception.ErrorCode;
|
||||
import com.fruitshorts.common.exception.ServiceException;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/** 奖励活动后台配置服务测试。 */
|
||||
class RewardActivityAdminServiceTest {
|
||||
|
||||
private RewardActivityMapper activityMapper;
|
||||
private RewardActivityAdminService service;
|
||||
|
||||
@BeforeAll
|
||||
static void initTableInfo() {
|
||||
TableInfoHelper.initTableInfo(
|
||||
new MapperBuilderAssistant(new MybatisConfiguration(), ""), RewardActivity.class);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
activityMapper = mock(RewardActivityMapper.class);
|
||||
service = new RewardActivityAdminService(activityMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_create_activity_offline_when_status_is_missing() {
|
||||
given(activityMapper.selectCount(any())).willReturn(0L);
|
||||
AtomicReference<RewardActivity> saved = captureInsert();
|
||||
|
||||
service.create(activity("spring_event"));
|
||||
|
||||
assertThat(saved.get().getCode()).isEqualTo("spring_event");
|
||||
assertThat(saved.get().getStatus()).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_reject_when_activity_code_already_exists() {
|
||||
given(activityMapper.selectCount(any())).willReturn(1L);
|
||||
|
||||
assertThatThrownBy(() -> service.create(activity("spring_event")))
|
||||
.isInstanceOf(ServiceException.class)
|
||||
.satisfies(ex -> assertThat(((ServiceException) ex).getCode())
|
||||
.isEqualTo(ErrorCode.DATA_EXISTS.getCode()))
|
||||
.hasMessageContaining("活动编码已存在");
|
||||
verify(activityMapper, never()).insert(any(RewardActivity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_update_status_when_status_is_valid() {
|
||||
RewardActivity existing = new RewardActivity();
|
||||
existing.setId(9L);
|
||||
existing.setDeleted(0);
|
||||
given(activityMapper.selectById(9L)).willReturn(existing);
|
||||
|
||||
service.updateStatus(9L, 1);
|
||||
|
||||
assertThat(existing.getStatus()).isOne();
|
||||
verify(activityMapper).updateById(existing);
|
||||
}
|
||||
|
||||
private AtomicReference<RewardActivity> captureInsert() {
|
||||
AtomicReference<RewardActivity> saved = new AtomicReference<>();
|
||||
given(activityMapper.insert(any(RewardActivity.class))).willAnswer(invocation -> {
|
||||
RewardActivity activity = invocation.getArgument(0);
|
||||
activity.setId(9L);
|
||||
saved.set(activity);
|
||||
return 1;
|
||||
});
|
||||
return saved;
|
||||
}
|
||||
|
||||
private RewardActivitySaveReqVO activity(String code) {
|
||||
RewardActivitySaveReqVO req = new RewardActivitySaveReqVO();
|
||||
req.setCode(code);
|
||||
req.setTitleId("Acara musim semi");
|
||||
req.setTitleEn("Spring event");
|
||||
req.setTitleZh("春季活动");
|
||||
req.setSummaryId("Dapatkan koin tambahan");
|
||||
req.setActionType("OPEN_HOME");
|
||||
return req;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.media.service;
|
||||
|
||||
import com.fruitshorts.media.dal.entity.MediaAsset;
|
||||
import com.fruitshorts.media.dal.mapper.MediaAssetMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** 把 READY 媒资的高清 poster 解析成公开且已签名的地址。 */
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PosterUrlResolver {
|
||||
|
||||
private final MediaAssetMapper mediaAssetMapper;
|
||||
private final PlaybackSigner signer;
|
||||
|
||||
/** 单集播放使用。 */
|
||||
public String resolve(Long mediaAssetId) {
|
||||
if (mediaAssetId == null || mediaAssetId <= 0L) {
|
||||
return null;
|
||||
}
|
||||
return toUrl(mediaAssetMapper.selectById(mediaAssetId));
|
||||
}
|
||||
|
||||
/** 首页和详情列表批量解析,避免按分集逐条查询媒资。 */
|
||||
public Map<Long, String> resolveAll(Collection<Long> mediaAssetIds) {
|
||||
Map<Long, String> result = new LinkedHashMap<>();
|
||||
if (mediaAssetIds == null || mediaAssetIds.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
mediaAssetMapper.selectBatchIds(mediaAssetIds).forEach(asset -> {
|
||||
String url = toUrl(asset);
|
||||
if (url != null) {
|
||||
result.put(asset.getId(), url);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private String toUrl(MediaAsset asset) {
|
||||
if (asset == null || !TranscodeService.STATUS_SUCCESS.equals(asset.getTranscodeStatus())
|
||||
|| !StringUtils.hasText(asset.getPosterUrl())) {
|
||||
return null;
|
||||
}
|
||||
String signed = signer.sign(asset.getPosterUrl());
|
||||
return StringUtils.hasText(signed) ? signed : null;
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.media.service;
|
||||
|
||||
import com.fruitshorts.media.dal.entity.MediaAsset;
|
||||
import com.fruitshorts.media.dal.mapper.MediaAssetMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/** 高清首帧地址解析的签名和空值回退测试。 */
|
||||
class PosterUrlResolverTest {
|
||||
|
||||
private final MediaAssetMapper mapper = mock(MediaAssetMapper.class);
|
||||
private final PlaybackSigner signer = mock(PlaybackSigner.class);
|
||||
private final PosterUrlResolver resolver = new PosterUrlResolver(mapper, signer);
|
||||
|
||||
@Test
|
||||
void should_sign_poster_when_media_is_ready() {
|
||||
MediaAsset asset = asset(11L, "/files/transcoded/11/poster.jpg", TranscodeService.STATUS_SUCCESS);
|
||||
given(mapper.selectById(11L)).willReturn(asset);
|
||||
given(signer.sign(asset.getPosterUrl())).willReturn(asset.getPosterUrl() + "?e=1&s=sig");
|
||||
|
||||
assertThat(resolver.resolve(11L)).isEqualTo("/files/transcoded/11/poster.jpg?e=1&s=sig");
|
||||
verify(signer).sign(asset.getPosterUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_null_when_media_has_no_ready_poster() {
|
||||
MediaAsset asset = asset(12L, "/files/transcoded/12/poster.jpg", TranscodeService.STATUS_FAILED);
|
||||
given(mapper.selectById(12L)).willReturn(asset);
|
||||
|
||||
assertThat(resolver.resolve(12L)).isNull();
|
||||
assertThat(resolver.resolve(null)).isNull();
|
||||
verify(signer, never()).sign(asset.getPosterUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_resolve_posters_in_one_batch_when_assets_are_ready() {
|
||||
MediaAsset ready = asset(11L, "/files/transcoded/11/poster.jpg", TranscodeService.STATUS_SUCCESS);
|
||||
MediaAsset absent = asset(12L, "", TranscodeService.STATUS_SUCCESS);
|
||||
given(mapper.selectBatchIds(List.of(11L, 12L))).willReturn(List.of(ready, absent));
|
||||
given(signer.sign(ready.getPosterUrl())).willReturn(ready.getPosterUrl() + "?e=1&s=sig");
|
||||
|
||||
assertThat(resolver.resolveAll(List.of(11L, 12L)))
|
||||
.isEqualTo(Map.of(11L, "/files/transcoded/11/poster.jpg?e=1&s=sig"));
|
||||
assertThat(resolver.resolveAll(List.of())).isEmpty();
|
||||
verify(mapper).selectBatchIds(List.of(11L, 12L));
|
||||
}
|
||||
|
||||
private MediaAsset asset(Long id, String posterUrl, String status) {
|
||||
MediaAsset asset = new MediaAsset();
|
||||
asset.setId(id);
|
||||
asset.setPosterUrl(posterUrl);
|
||||
asset.setTranscodeStatus(status);
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
+3
@@ -10,6 +10,7 @@ import com.fruitshorts.content.service.DramaService;
|
||||
import com.fruitshorts.content.service.EpisodeService;
|
||||
import com.fruitshorts.media.dal.entity.MediaRendition;
|
||||
import com.fruitshorts.media.service.PlaybackSigner;
|
||||
import com.fruitshorts.media.service.PosterUrlResolver;
|
||||
import com.fruitshorts.media.service.ThumbnailUrlResolver;
|
||||
import com.fruitshorts.media.service.TranscodeService;
|
||||
import com.fruitshorts.playback.dal.entity.PlaybackTicket;
|
||||
@@ -51,6 +52,7 @@ public class PlaybackService {
|
||||
private final EntitlementPort entitlementPort;
|
||||
private final TranscodeService transcodeService;
|
||||
private final ThumbnailUrlResolver thumbnailUrlResolver;
|
||||
private final PosterUrlResolver posterUrlResolver;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PlayRespVO play(Long userId, Long episodeId, String deviceId, String clientIp) {
|
||||
@@ -75,6 +77,7 @@ public class PlaybackService {
|
||||
vo.setPreviewSeconds(episode.getPreviewSeconds());
|
||||
vo.setQualities(qualitiesOf(episode.getId()));
|
||||
vo.setThumbnailsUrl(thumbnailUrlResolver.resolve(episode.getId()));
|
||||
vo.setPosterUrl(posterUrlResolver.resolve(episode.getVideoAssetId()));
|
||||
|
||||
if (!StringUtils.hasText(source)) {
|
||||
// 还没转码或没上传片源:明确告诉客户端"没有片源",而不是给一个播不了的地址
|
||||
|
||||
@@ -25,6 +25,8 @@ public class PlayRespVO {
|
||||
private List<String> qualities;
|
||||
/** 各档签名地址。AUTO 是主播放列表,其余是单档 HLS。 */
|
||||
private List<PlayTrackVO> tracks;
|
||||
/** 高清首帧 poster 地址;没有 READY 媒资时为 null */
|
||||
private String posterUrl;
|
||||
/** 雪碧图 WebVTT 时间轴地址;没有产物时为 null */
|
||||
private String thumbnailsUrl;
|
||||
/** 需要多少金币解锁 */
|
||||
|
||||
+9
-4
@@ -6,20 +6,25 @@ import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Google 登录配置。
|
||||
*
|
||||
* <p>凭据只从配置/环境变量读,不入库、不提交到仓库:
|
||||
* <pre>
|
||||
* fruitshorts.auth.google.client-id: 1234567890-xxx.apps.googleusercontent.com
|
||||
* fruitshorts.auth.google.client-ids: 1234-ios.apps.googleusercontent.com,1234-web.apps.googleusercontent.com
|
||||
* </pre>
|
||||
* 未配置 clientId 时,Google 登录接口明确返回"未配置"错误,不会静默放行。
|
||||
* 客户端各平台拿到的 idToken,其 audience 并不相同:iOS 是 iOS 客户端 id,
|
||||
* Android 是 serverClientId 对应的 Web 客户端 id,因此这里必须允许配置多个。
|
||||
* 未配置时,Google 登录接口明确返回"未配置"错误,不会静默放行。
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "fruitshorts.auth.google")
|
||||
public class GoogleAuthProperties {
|
||||
|
||||
/** Google OAuth 客户端 id,用于校验 idToken 的 audience。 */
|
||||
private String clientId = "";
|
||||
/** 允许的 Google OAuth 客户端 id 列表,用于校验 idToken 的 audience。 */
|
||||
private List<String> clientIds = new ArrayList<>();
|
||||
}
|
||||
+7
-3
@@ -19,6 +19,7 @@ import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Google idToken 校验器。
|
||||
@@ -45,11 +46,14 @@ public class GoogleIdTokenVerifier {
|
||||
/**
|
||||
* 校验 idToken 并返回 Google 用户信息。
|
||||
*
|
||||
* <p>audience 按平台不同而不同(iOS 用 iOS 客户端 id,Android 用 Web 客户端 id),
|
||||
* 因此只要命中配置列表里的任意一个即视为合法,同时拦截其他应用盗用令牌。
|
||||
*
|
||||
* @param idToken 客户端从 Google 拿到的 idToken
|
||||
*/
|
||||
public GoogleUser verify(String idToken) {
|
||||
String clientId = properties.getClientId();
|
||||
if (!StringUtils.hasText(clientId)) {
|
||||
List<String> clientIds = properties.getClientIds();
|
||||
if (clientIds == null || clientIds.isEmpty()) {
|
||||
throw new ServiceException(ErrorCode.OPERATION_NOT_ALLOWED, "Google 登录未配置");
|
||||
}
|
||||
if (!StringUtils.hasText(idToken)) {
|
||||
@@ -58,7 +62,7 @@ public class GoogleIdTokenVerifier {
|
||||
JsonNode body = fetchTokenInfo(idToken);
|
||||
String aud = body.path("aud").asText("");
|
||||
String sub = body.path("sub").asText("");
|
||||
if (!clientId.equals(aud) || !StringUtils.hasText(sub)) {
|
||||
if (!clientIds.contains(aud) || !StringUtils.hasText(sub)) {
|
||||
throw new ServiceException(ErrorCode.UNAUTHORIZED, "Google 令牌无效");
|
||||
}
|
||||
return new GoogleUser(sub, body.path("email").asText(""),
|
||||
|
||||
Reference in new issue
Block a user