1.distinguish the auth between app and web

main
Gary 7 months ago
parent 6116568fe3
commit f6e1f51cae

@ -5,17 +5,13 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import com.luoo.music.dao.CommentDao;
import com.luoo.music.dto.mapper.CommentMapper;
import com.luoo.music.dto.mapper.JournalMapper;
import com.luoo.music.dto.request.CollectQueryReq;
import com.luoo.music.dto.request.JournalQueryReq;
import com.luoo.music.dto.response.CommentDTO;
import com.luoo.music.dto.response.JournalFilterDTO;
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;
@ -23,9 +19,10 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag;
import com.luoo.music.service.JournalService;
import com.luoo.music.service.UserCollectInfoService;
import com.luoo.music.util.DeviceTypeUtil;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
@ -74,12 +71,12 @@ public class JournalController {
@GlobalInterceptor
public Result<PageResult<JournalRespDTO>> page(
@RequestHeader(value = "Authorization", required = false) String authorization,
@RequestHeader(value = "device_type", required = false) String deviceType,
@VerifyParam JournalQueryReq queryReq) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
updateQuery(user,queryReq);
updateQuery(deviceType,user,queryReq);
Long count = journalService.countJournal(queryReq);
List<JournalRespDTO> pageList=journalService.queryJournalByPage(queryReq);
// pageList = pageList.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
Set<String> journalCollectSet = getJournalCollectSet(user);
updateCollectStatus(pageList,journalCollectSet);
return Result.success(new PageResult<JournalRespDTO>(count, pageList));
@ -94,7 +91,10 @@ public class JournalController {
private Set<String> getJournalCollectSet(UserLoginDto user) {
return null == user ? Collections.emptySet():getJournalCollectSet(user.getUserId());
}
private void updateQuery(UserLoginDto user, JournalQueryReq queryReq) {
private void updateQuery(String deviceType, UserLoginDto user, JournalQueryReq queryReq) {
if(DeviceTypeUtil.isWeb(deviceType)) {
return;
}
if (null == user) {
queryReq.setCategoryId(null);
queryReq.setPageNum(1);

@ -9,6 +9,8 @@ import com.luoo.music.service.JournalService;
import com.luoo.music.service.JournalSongService;
import com.luoo.music.service.SongInfoService;
import com.luoo.music.service.UserCollectInfoService;
import com.luoo.music.util.DeviceTypeUtil;
import annotation.GlobalInterceptor;
import annotation.VerifyParam;
import api.PageResult;
@ -68,9 +70,10 @@ public class SongController {
@GlobalInterceptor
public Result<List<SongRespDTO>> getByJournalNo(
@RequestHeader(value = "Authorization", required = false) String authorization,
@RequestHeader(value = "device_type", required = false) String deviceType,
@PathVariable String journalNo) {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
if (null == user && !isLatest10(journalNo)) {
if (!DeviceTypeUtil.isWeb(deviceType)&&null == user && !isLatest10(journalNo)) {
return Result.unauthorized(null);
}
List<SongRespDTO> results = journalSongService.findByJournalNo(journalNo);
@ -183,9 +186,9 @@ public class SongController {
@ApiOperation(value = "3.随机播放歌曲", notes = "雀乐FM")
@ApiImplicitParams({ @ApiImplicitParam(name = "limit", value = "随机歌曲数最少1首最多30首", required = false) })
@GetMapping("/random/{limit}")
@GlobalInterceptor(checkAppUserLogin = true)
@GlobalInterceptor
public Result<List<SongRespDTO>> random(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestHeader(value = "Authorization", required = false) String authorization,
@PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
List<JournalSong> songs = journalSongService.random(limit);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);

@ -0,0 +1,8 @@
package com.luoo.music.util;
public class DeviceTypeUtil {
private static final String WEB="web";
public static boolean isWeb(String deviceType) {
return WEB.equals(deviceType);
}
}
Loading…
Cancel
Save