update s3 config

main
wangqing 9 months ago
parent a7afa26247
commit 3512799de1

@ -20,10 +20,10 @@ public class AwsS3Config {
@Bean @Bean
public S3Client s3Client(){ public S3Client s3Client(){
// AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("GLwHmLTZ05Kw9RyCGJXnIkua", "ynOBIqdNXH5HBgrVA29DTn4cUSh1wAI"); // 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(); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build();
S3Client s3 = S3Client.builder() S3Client s3 = S3Client.builder()
.endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) .endpointOverride(URI.create("http://cdn2.indie.cn:19000/"))
.credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials)) .credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials))
.region(region) .region(region)
.serviceConfiguration(s3Config) .serviceConfiguration(s3Config)
@ -36,7 +36,7 @@ public class AwsS3Config {
public S3Presigner s3Presigner(){ public S3Presigner s3Presigner(){
S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build();
S3Presigner presigner = S3Presigner.builder() S3Presigner presigner = S3Presigner.builder()
.endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) .endpointOverride(URI.create("http://cdn2.indie.cn:19000/"))
.region(region) .region(region)
.build(); .build();

@ -1,9 +1,6 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import java.util.Collections; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; 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.SongRespDTO;
import com.luoo.music.dto.response.TagDTO; import com.luoo.music.dto.response.TagDTO;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
@ -80,11 +78,33 @@ public class JournalController {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
updateQuery(user,queryReq); updateQuery(user,queryReq);
List<JournalRespDTO> pageList=journalService.queryJournalByPage(queryReq); List<JournalRespDTO> pageList=journalService.queryJournalByPage(queryReq);
pageList = pageList.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
Set<String> journalCollectSet = getJournalCollectSet(user); Set<String> journalCollectSet = getJournalCollectSet(user);
updateCollectStatus(pageList,journalCollectSet); updateCollectStatus(pageList,journalCollectSet);
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(pageList.size()), pageList)); return Result.success(new PageResult<JournalRespDTO>(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<JournalRespDTO> pageList, Set<String> journalCollectSet) { private void updateCollectStatus(List<JournalRespDTO> pageList, Set<String> journalCollectSet) {
pageList.forEach(j->{ pageList.forEach(j->{
j.setHaveCollect(journalCollectSet.contains(j.getId())); j.setHaveCollect(journalCollectSet.contains(j.getId()));
@ -125,6 +145,7 @@ public class JournalController {
Set<String> journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds); Set<String> journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds);
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
.collect(Collectors.toList()); .collect(Collectors.toList());
list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list)); return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
} }
@ -199,6 +220,7 @@ public class JournalController {
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL); boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.JOURNAL);
journalRespDTO.setHaveCollect(isCollect); journalRespDTO.setHaveCollect(isCollect);
journalRespDTO = randomCDN(journalRespDTO);
return Result.success(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); boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),journalRespDTO.getId(), CollectTypeEnum.JOURNAL);
journalRespDTO.setHaveCollect(isCollect); journalRespDTO.setHaveCollect(isCollect);
journalRespDTO = randomCDN(journalRespDTO);
return Result.success(journalRespDTO); return Result.success(journalRespDTO);
} }
private boolean isLatest10(String journalNo) { private boolean isLatest10(String journalNo) {
@ -261,7 +284,7 @@ public class JournalController {
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL); : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL);
List<JournalRespDTO> list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) List<JournalRespDTO> list = journals.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet))
.collect(Collectors.toList()); .collect(Collectors.toList());
list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
return Result.success(list); return Result.success(list);
} }

@ -21,6 +21,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import util.JwtUtil; import util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired; 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.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Collections; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@RestController @RestController
@ -71,16 +69,42 @@ public class SongController {
return Result.unauthorized(null); return Result.unauthorized(null);
} }
List<SongRespDTO> results = journalSongService.findByJournalNo(journalNo); List<SongRespDTO> results = journalSongService.findByJournalNo(journalNo);
results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList());
Set<String> songCollectSet = getSongCollectSet(results,user); Set<String> songCollectSet = getSongCollectSet(results,user);
updateCollectStatus(results,songCollectSet); updateCollectStatus(results,songCollectSet);
return Result.success(results); 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 = "仅用于外部分享") @ApiOperation(value = "1.1 根据期刊id查询歌曲信息", notes = "仅用于外部分享")
@GetMapping("/journalId/{journalId}") @GetMapping("/journalId/{journalId}")
@GlobalInterceptor @GlobalInterceptor
public Result<List<SongRespDTO>> getByJournalId(@PathVariable String journalId) { public Result<List<SongRespDTO>> getByJournalId(@PathVariable String journalId) {
return Result.success(journalSongService.findByJournalId(journalId)); List<SongRespDTO> list = journalSongService.findByJournalId(journalId);
list = list.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList());
return Result.success(list);
} }
private void updateCollectStatus(List<SongRespDTO> results, Set<String> songCollectSet) { private void updateCollectStatus(List<SongRespDTO> results, Set<String> songCollectSet) {
@ -120,6 +144,7 @@ public class SongController {
Set<String> songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource); Set<String> songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource);
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
.collect(Collectors.toList()); .collect(Collectors.toList());
results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList());
return Result.success(new PageResult<SongRespDTO>(Long.valueOf(results.size()), results)); return Result.success(new PageResult<SongRespDTO>(Long.valueOf(results.size()), results));
} }
@ -157,6 +182,7 @@ public class SongController {
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet)) List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
.collect(Collectors.toList()); .collect(Collectors.toList());
results = results.stream().map(songRespDTO -> randomCDN(songRespDTO)).collect(Collectors.toList());
return Result.success(results); return Result.success(results);
} }
@ -173,6 +199,7 @@ public class SongController {
SongRespDTO songRespDTO=SongMapper.getSongRespDTO(song); SongRespDTO songRespDTO=SongMapper.getSongRespDTO(song);
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.SONG); boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.SONG);
songRespDTO.setHaveCollect(isCollect); songRespDTO.setHaveCollect(isCollect);
songRespDTO = randomCDN(songRespDTO);
return Result.success(songRespDTO); return Result.success(songRespDTO);
} }
} }

@ -19,10 +19,10 @@ public class AwsS3Config {
@Bean @Bean
public S3Client s3Client(){ public S3Client s3Client(){
// AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("GLwHmLTZ05Kw9RyCGJXnIkua", "ynOBIqdNXH5HBgrVA29DTn4cUSh1wAI"); // 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(); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build();
S3Client s3 = S3Client.builder() S3Client s3 = S3Client.builder()
.endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) .endpointOverride(URI.create("http://cdn2.indie.cn:19000/"))
.credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials)) .credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials))
.region(region) .region(region)
.serviceConfiguration(s3Config) .serviceConfiguration(s3Config)
@ -35,7 +35,7 @@ public class AwsS3Config {
public S3Presigner s3Presigner(){ public S3Presigner s3Presigner(){
S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build();
S3Presigner presigner = S3Presigner.builder() S3Presigner presigner = S3Presigner.builder()
.endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) .endpointOverride(URI.create("http://cdn2.indie.cn:19000/"))
.region(region) .region(region)
.build(); .build();

@ -29,10 +29,10 @@ public class AwsS3Config {
@Bean @Bean
public S3Client s3Client(){ public S3Client s3Client(){
// AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create("GLwHmLTZ05Kw9RyCGJXnIkua", "ynOBIqdNXH5HBgrVA29DTn4cUSh1wAI"); // 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(); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build();
S3Client s3 = S3Client.builder() S3Client s3 = S3Client.builder()
.endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) .endpointOverride(URI.create("http://cdn2.indie.cn:19000/"))
.credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials)) .credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials))
.region(region) .region(region)
.serviceConfiguration(s3Config) .serviceConfiguration(s3Config)
@ -45,7 +45,7 @@ public class AwsS3Config {
public S3Presigner s3Presigner(){ public S3Presigner s3Presigner(){
S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build(); S3Configuration s3Config = S3Configuration.builder().pathStyleAccessEnabled(true).build();
S3Presigner presigner = S3Presigner.builder() S3Presigner presigner = S3Presigner.builder()
.endpointOverride(URI.create("http://cdn1.indie.cn:19000/")) .endpointOverride(URI.create("http://cdn2.indie.cn:19000/"))
.region(region) .region(region)
.build(); .build();

Loading…
Cancel
Save