This commit is contained in:
1 parent
2904e59e71
commit
31d449916f
11 files changed
+201
-12
No files matched your search
+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)));
|
||||
|
||||
@@ -24,6 +24,8 @@ public class AppEpisodeVO {
|
||||
* 详情页拿到就能直接播,不必按集再请求一次播放票据。
|
||||
*/
|
||||
private String playUrl;
|
||||
/** 高清首帧 poster 地址;没有 READY 媒资时为 null */
|
||||
private String posterUrl;
|
||||
/** 雪碧图 WebVTT 时间轴地址;没有产物时为 null */
|
||||
private String thumbnailsUrl;
|
||||
}
|
||||
+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"));
|
||||
|
||||
Reference in new issue
Block a user