diff --git a/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java b/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java index 853949c..20e6676 100644 --- a/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java +++ b/luoo_music/src/main/java/com/luoo/music/config/AwsS3Config.java @@ -20,10 +20,10 @@ public class AwsS3Config { @Bean public S3Client s3Client(){ // AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("GLwHmLTZ05Kw9RyCGJXnIkua", "ynOBIqdNXH5HBgrVA29DTn4cUSh1wAI"); - AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("YaUJkVdm3btJxproam5a", "sCkKJdcImazyae1aHWIMAGg9XZLRGh3XXYerAB48"); + AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("c1exJ7ANL18OpMOtdCq7", "tHaEqbdLbsg7EivlT8mQyG1JwFNO8ZSpqW7KUte4"); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Client s3 = S3Client.builder() - .endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) + .endpointOverride(URI.create("http://cdn2.indie.cn:19000/")) .credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials)) .region(region) .serviceConfiguration(s3Config) @@ -36,7 +36,7 @@ public class AwsS3Config { public S3Presigner s3Presigner(){ S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Presigner presigner = S3Presigner.builder() - .endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) + .endpointOverride(URI.create("http://cdn2.indie.cn:19000/")) .region(region) .build(); diff --git a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java index ac35068..5551d87 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/JournalController.java @@ -1,9 +1,6 @@ package com.luoo.music.controller; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -18,6 +15,7 @@ import com.luoo.music.dto.response.JournalRespDTO; import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.dto.response.TagDTO; import io.swagger.annotations.*; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.mongodb.core.MongoTemplate; @@ -80,10 +78,32 @@ public class JournalController { UserLoginDto user = jwtUtil.getUserLoginDto(authorization); updateQuery(user,queryReq); List pageList=journalService.queryJournalByPage(queryReq); + pageList = pageList.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); Set journalCollectSet = getJournalCollectSet(user); updateCollectStatus(pageList,journalCollectSet); return Result.success(new PageResult(Long.valueOf(pageList.size()), pageList)); } + + private JournalRespDTO randomCDN(JournalRespDTO journalRespDTO) { +// Random random = new Random(); +// int randomNum = random.nextInt(2)+1; + + Random random = new Random(); + int rate = random.nextInt(100); +// int randomNum = random.nextInt(2)+1; + int randomNum =1; + if (rate>20) { + randomNum =2; + } + if (StringUtils.isNotEmpty(journalRespDTO.getImage())){ + journalRespDTO.setImage(journalRespDTO.getImage().replaceFirst("cdn1","cdn"+randomNum)); + journalRespDTO.setImage(journalRespDTO.getImage().replaceFirst("cdn2","cdn"+randomNum)); + } + + return journalRespDTO; + } + + private void updateCollectStatus(List pageList, Set journalCollectSet) { pageList.forEach(j->{ @@ -125,6 +145,7 @@ public class JournalController { Set journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds); List list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); + list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(list.size()), list)); } @@ -199,6 +220,7 @@ public class JournalController { boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL); journalRespDTO.setHaveCollect(isCollect); + journalRespDTO = randomCDN(journalRespDTO); return Result.success(journalRespDTO); } @@ -218,6 +240,7 @@ public class JournalController { } boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),journalRespDTO.getId(), CollectTypeEnum.JOURNAL); journalRespDTO.setHaveCollect(isCollect); + journalRespDTO = randomCDN(journalRespDTO); return Result.success(journalRespDTO); } private boolean isLatest10(String journalNo) { @@ -261,7 +284,7 @@ public class JournalController { : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL); List list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) .collect(Collectors.toList()); - + list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); return Result.success(list); } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java index cd2996a..5af70c2 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java @@ -21,6 +21,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.springframework.util.StringUtils; import util.JwtUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -28,10 +29,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; @RestController @@ -71,16 +69,42 @@ public class SongController { return Result.unauthorized(null); } List results = journalSongService.findByJournalNo(journalNo); + results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); Set songCollectSet = getSongCollectSet(results,user); updateCollectStatus(results,songCollectSet); return Result.success(results); } - + + + private SongRespDTO randomCDN(SongRespDTO s){ + Random random = new Random(); + int rate = random.nextInt(100); +// int randomNum = random.nextInt(2)+1; + int randomNum =1; + if (rate>20) { + randomNum =2; + } + if (!StringUtils.isEmpty(s.getLrc())){ + s.setLrc(s.getLrc().replaceFirst("cdn1","cdn"+randomNum)); + s.setLrc(s.getLrc().replaceFirst("cdn2","cdn"+randomNum)); + } + if (!StringUtils.isEmpty(s.getSrc())){ + s.setSrc(s.getSrc().replaceFirst("cdn1","cdn"+randomNum)); + s.setSrc(s.getSrc().replaceFirst("cdn2","cdn"+randomNum)); + } + if (!StringUtils.isEmpty(s.getPic())){ + s.setPic(s.getPic().replaceFirst("cdn1","cdn"+randomNum)); + s.setPic(s.getPic().replaceFirst("cdn2","cdn"+randomNum)); + } + return s; + } @ApiOperation(value = "1.1 根据期刊id查询歌曲信息", notes = "仅用于外部分享") @GetMapping("/journalId/{journalId}") @GlobalInterceptor public Result> getByJournalId(@PathVariable String journalId) { - return Result.success(journalSongService.findByJournalId(journalId)); + List list = journalSongService.findByJournalId(journalId); + list = list.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); + return Result.success(list); } private void updateCollectStatus(List results, Set songCollectSet) { @@ -120,6 +144,7 @@ public class SongController { Set songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource); List results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) .collect(Collectors.toList()); + results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); return Result.success(new PageResult(Long.valueOf(results.size()), results)); } @@ -157,6 +182,7 @@ public class SongController { List results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) .collect(Collectors.toList()); + results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList()); return Result.success(results); } @@ -173,6 +199,7 @@ public class SongController { SongRespDTO songRespDTO=SongMapper.getSongRespDTO(song); boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.SONG); songRespDTO.setHaveCollect(isCollect); + songRespDTO = randomCDN(songRespDTO); return Result.success(songRespDTO); } } diff --git a/luoo_tag/src/main/java/com/luoo/tag/config/AwsS3Config.java b/luoo_tag/src/main/java/com/luoo/tag/config/AwsS3Config.java index 909a784..dd9bb8b 100644 --- a/luoo_tag/src/main/java/com/luoo/tag/config/AwsS3Config.java +++ b/luoo_tag/src/main/java/com/luoo/tag/config/AwsS3Config.java @@ -19,10 +19,10 @@ public class AwsS3Config { @Bean public S3Client s3Client(){ // AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("GLwHmLTZ05Kw9RyCGJXnIkua", "ynOBIqdNXH5HBgrVA29DTn4cUSh1wAI"); - AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("YaUJkVdm3btJxproam5a", "sCkKJdcImazyae1aHWIMAGg9XZLRGh3XXYerAB48"); + AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("c1exJ7ANL18OpMOtdCq7", "tHaEqbdLbsg7EivlT8mQyG1JwFNO8ZSpqW7KUte4"); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Client s3 = S3Client.builder() - .endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) + .endpointOverride(URI.create("http://cdn2.indie.cn:19000/")) .credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials)) .region(region) .serviceConfiguration(s3Config) @@ -35,7 +35,7 @@ public class AwsS3Config { public S3Presigner s3Presigner(){ S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Presigner presigner = S3Presigner.builder() - .endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) + .endpointOverride(URI.create("http://cdn2.indie.cn:19000/")) .region(region) .build(); diff --git a/luoo_user/src/main/java/com/luoo/user/config/AwsS3Config.java b/luoo_user/src/main/java/com/luoo/user/config/AwsS3Config.java index 9452d8e..12a9be6 100644 --- a/luoo_user/src/main/java/com/luoo/user/config/AwsS3Config.java +++ b/luoo_user/src/main/java/com/luoo/user/config/AwsS3Config.java @@ -29,10 +29,10 @@ public class AwsS3Config { @Bean public S3Client s3Client(){ // AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("GLwHmLTZ05Kw9RyCGJXnIkua", "ynOBIqdNXH5HBgrVA29DTn4cUSh1wAI"); - AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("YaUJkVdm3btJxproam5a", "sCkKJdcImazyae1aHWIMAGg9XZLRGh3XXYerAB48"); + AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("c1exJ7ANL18OpMOtdCq7", "tHaEqbdLbsg7EivlT8mQyG1JwFNO8ZSpqW7KUte4"); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Client s3 = S3Client.builder() - .endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) + .endpointOverride(URI.create("http://cdn2.indie.cn:19000/")) .credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials)) .region(region) .serviceConfiguration(s3Config) @@ -45,7 +45,7 @@ public class AwsS3Config { public S3Presigner s3Presigner(){ S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Presigner presigner = S3Presigner.builder() - .endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) + .endpointOverride(URI.create("http://cdn2.indie.cn:19000/")) .region(region) .build();