|
|
@@ -4,6 +4,7 @@ import cn.reghao.file.api.iface.OssService;
|
|
|
import cn.reghao.jutil.jdk.db.Page;
|
|
|
import cn.reghao.jutil.jdk.db.PageList;
|
|
|
import cn.reghao.jutil.jdk.result.Result;
|
|
|
+import cn.reghao.jutil.jdk.string.IDObfuscation;
|
|
|
import cn.reghao.jutil.web.WebResult;
|
|
|
import cn.reghao.jutil.tool.id.SnowFlake;
|
|
|
import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
|
|
|
@@ -14,6 +15,7 @@ import cn.reghao.tnb.content.app.data.db.repository.ImageRepository;
|
|
|
import cn.reghao.tnb.content.app.data.model.dto.AlbumImageData;
|
|
|
import cn.reghao.tnb.content.app.data.model.po.ImagePost;
|
|
|
import cn.reghao.tnb.content.app.data.model.po.ImageFile;
|
|
|
+import cn.reghao.tnb.content.app.data.model.vo.AlbumCard;
|
|
|
import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumCard;
|
|
|
import cn.reghao.tnb.content.app.data.model.vo.ImageAlbumQuery;
|
|
|
import cn.reghao.tnb.content.app.data.model.vo.ImageData;
|
|
|
@@ -26,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -43,13 +46,15 @@ public class ImagePostService {
|
|
|
private final ImageRepository imageRepository;
|
|
|
private final AlbumRepository albumRepository;
|
|
|
private final ContentPermission contentPermission;
|
|
|
+ private final IDObfuscation userIdObfuscation;
|
|
|
|
|
|
public ImagePostService(ImageRepository imageRepository, AlbumRepository albumRepository,
|
|
|
- ContentPermission contentPermission) {
|
|
|
+ ContentPermission contentPermission, IDObfuscation userIdObfuscation) {
|
|
|
this.idGenerator = new SnowFlake(1L, 1L);
|
|
|
this.imageRepository = imageRepository;
|
|
|
this.albumRepository = albumRepository;
|
|
|
this.contentPermission = contentPermission;
|
|
|
+ this.userIdObfuscation = userIdObfuscation;
|
|
|
}
|
|
|
|
|
|
public Result create(ImagePublishSbt imagePublishSbt) {
|
|
|
@@ -114,7 +119,7 @@ public class ImagePostService {
|
|
|
return albumRepository.getByImagePost(imageFileId, loginUser) != null;
|
|
|
}
|
|
|
|
|
|
- public PageList<ImagePost> getUserAlbums(long userId, int page) {
|
|
|
+ public PageList<AlbumCard> getUserAlbums(long userId, int page) {
|
|
|
List<Integer> scopes = contentPermission.getUserScopes();
|
|
|
long loginUser = UserContext.getUser();
|
|
|
if (loginUser == userId) {
|
|
|
@@ -125,24 +130,27 @@ public class ImagePostService {
|
|
|
int total = imageRepository.countByCriteria(imageAlbumQuery);
|
|
|
Page page1 = new Page(page, pageSize);
|
|
|
List<ImagePost> list = imageRepository.findImageAlbumByPage(page1, imageAlbumQuery);
|
|
|
- list.forEach(imageAlbum -> {
|
|
|
+ List<AlbumCard> albumCards = list.stream().map(imagePost -> {
|
|
|
try {
|
|
|
- int scope = imageAlbum.getScope();
|
|
|
+ int scope = imagePost.getScope();
|
|
|
if (scope != PostScope.PUBLIC.getCode()) {
|
|
|
- int channelId = imageAlbum.getChannelId();
|
|
|
- String coverUrl = imageAlbum.getCoverUrl();
|
|
|
+ int channelId = imagePost.getChannelId();
|
|
|
+ String coverUrl = imagePost.getCoverUrl();
|
|
|
if (!coverUrl.isBlank()) {
|
|
|
ImageFile imageFile = imageRepository.getByUrl(coverUrl);
|
|
|
String objectId = imageFile.getObjectId();
|
|
|
- imageAlbum.setCoverUrl(ossService.getSignedUrl(channelId, objectId));
|
|
|
+ imagePost.setCoverUrl(ossService.getSignedUrl(channelId, objectId));
|
|
|
}
|
|
|
}
|
|
|
+ String userIdStr = userIdObfuscation.obfuscate(imagePost.getUserId());
|
|
|
+ return new AlbumCard(imagePost, userIdStr);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- });
|
|
|
+ return null;
|
|
|
+ }).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
|
- return PageList.pageList(page, pageSize, total, list);
|
|
|
+ return PageList.pageList(page, pageSize, total, albumCards);
|
|
|
}
|
|
|
|
|
|
public String getImageAlbum(long albumId, int pageNumber) {
|
|
|
@@ -192,7 +200,8 @@ public class ImagePostService {
|
|
|
});
|
|
|
|
|
|
PageList<ImageData> pageList = PageList.pageList(pageNumber, pageSize, total, list);
|
|
|
- ImageAlbumCard imageAlbumCard = new ImageAlbumCard(imagePost);
|
|
|
+ String userIdStr = userIdObfuscation.obfuscate(imagePost.getUserId());
|
|
|
+ ImageAlbumCard imageAlbumCard = new ImageAlbumCard(imagePost, userIdStr);
|
|
|
imageAlbumCard.setImages(pageList);
|
|
|
if (scope != PostScope.PUBLIC.getCode()) {
|
|
|
imageAlbumCard.getImages().getList().forEach(imageData -> {
|