Compare commits

..

2 Commits

Author SHA1 Message Date
Tim
08fe8a30c1 fix: remove config 2025-09-11 16:49:25 +08:00
Tim
6f4b17f96e feat: add webcodec compressor 2025-09-11 16:32:15 +08:00
44 changed files with 3612 additions and 1603 deletions

View File

@@ -12,7 +12,6 @@ jobs:
build-and-deploy: build-and-deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: Deploy environment: Deploy
if: ${{ !github.event.repository.fork }} # 只有非 fork 才执行
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

View File

@@ -1,3 +0,0 @@
{
"plugins": ["prettier-plugin-java"]
}

View File

@@ -46,8 +46,6 @@ public class CachingConfig {
public static final String LIMIT_CACHE_NAME="openisle_limit"; public static final String LIMIT_CACHE_NAME="openisle_limit";
// 用户访问统计 // 用户访问统计
public static final String VISIT_CACHE_NAME="openisle_visit"; public static final String VISIT_CACHE_NAME="openisle_visit";
// 文章缓存
public static final String POST_CACHE_NAME="openisle_posts";
/** /**
* 自定义Redis的序列化器 * 自定义Redis的序列化器
@@ -67,10 +65,7 @@ public class CachingConfig {
// Hibernate6Module 可以自动处理懒加载代理对象。 // Hibernate6Module 可以自动处理懒加载代理对象。
// Tag对象的creator是FetchType.LAZY // Tag对象的creator是FetchType.LAZY
objectMapper.registerModule(new Hibernate6Module() objectMapper.registerModule(new Hibernate6Module()
.disable(Hibernate6Module.Feature.USE_TRANSIENT_ANNOTATION) .disable(Hibernate6Module.Feature.USE_TRANSIENT_ANNOTATION));
// 将 Hibernate 特有的集合类型转换为标准 Java 集合类型
// 避免序列化时出现 org.hibernate.collection.spi.PersistentSet 这样的类型信息
.configure(Hibernate6Module.Feature.REPLACE_PERSISTENT_COLLECTIONS, true));
// service的时候带上类型信息 // service的时候带上类型信息
// 启用类型信息,避免 LinkedHashMap 问题 // 启用类型信息,避免 LinkedHashMap 问题
objectMapper.activateDefaultTyping( objectMapper.activateDefaultTyping(
@@ -97,10 +92,8 @@ public class CachingConfig {
// 个别缓存单独设置 TTL 时间 // 个别缓存单独设置 TTL 时间
Map<String, RedisCacheConfiguration> cacheConfigs = new HashMap<>(); Map<String, RedisCacheConfiguration> cacheConfigs = new HashMap<>();
RedisCacheConfiguration oneHourConfig = config.entryTtl(Duration.ofHours(1)); RedisCacheConfiguration oneHourConfig = config.entryTtl(Duration.ofHours(1));
RedisCacheConfiguration tenMinutesConfig = config.entryTtl(Duration.ofMinutes(10));
cacheConfigs.put(TAG_CACHE_NAME, oneHourConfig); cacheConfigs.put(TAG_CACHE_NAME, oneHourConfig);
cacheConfigs.put(CATEGORY_CACHE_NAME, oneHourConfig); cacheConfigs.put(CATEGORY_CACHE_NAME, oneHourConfig);
cacheConfigs.put(POST_CACHE_NAME, tenMinutesConfig);
return RedisCacheManager.builder(connectionFactory) return RedisCacheManager.builder(connectionFactory)
.cacheDefaults(config) .cacheDefaults(config)

View File

@@ -1,14 +1,13 @@
package com.openisle.controller; package com.openisle.controller;
import com.openisle.dto.PostChangeLogDto;
import com.openisle.dto.TimelineItemDto;
import com.openisle.mapper.PostChangeLogMapper;
import com.openisle.model.Comment; import com.openisle.model.Comment;
import com.openisle.dto.CommentDto; import com.openisle.dto.CommentDto;
import com.openisle.dto.CommentRequest; import com.openisle.dto.CommentRequest;
import com.openisle.mapper.CommentMapper; import com.openisle.mapper.CommentMapper;
import com.openisle.model.CommentSort; import com.openisle.service.CaptchaService;
import com.openisle.service.*; import com.openisle.service.CommentService;
import com.openisle.service.LevelService;
import com.openisle.service.PointService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@@ -22,8 +21,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -37,8 +34,6 @@ public class CommentController {
private final CaptchaService captchaService; private final CaptchaService captchaService;
private final CommentMapper commentMapper; private final CommentMapper commentMapper;
private final PointService pointService; private final PointService pointService;
private final PostChangeLogService changeLogService;
private final PostChangeLogMapper postChangeLogMapper;
@Value("${app.captcha.enabled:false}") @Value("${app.captcha.enabled:false}")
private boolean captchaEnabled; private boolean captchaEnabled;
@@ -90,43 +85,15 @@ public class CommentController {
@GetMapping("/posts/{postId}/comments") @GetMapping("/posts/{postId}/comments")
@Operation(summary = "List comments", description = "List comments for a post") @Operation(summary = "List comments", description = "List comments for a post")
@ApiResponse(responseCode = "200", description = "Comments", @ApiResponse(responseCode = "200", description = "Comments",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = TimelineItemDto.class)))) content = @Content(array = @ArraySchema(schema = @Schema(implementation = CommentDto.class))))
public List<TimelineItemDto<?>> listComments(@PathVariable Long postId, public List<CommentDto> listComments(@PathVariable Long postId,
@RequestParam(value = "sort", required = false, defaultValue = "OLDEST") CommentSort sort) { @RequestParam(value = "sort", required = false, defaultValue = "OLDEST") com.openisle.model.CommentSort sort) {
log.debug("listComments called for post {} with sort {}", postId, sort); log.debug("listComments called for post {} with sort {}", postId, sort);
List<CommentDto> commentDtoList = commentService.getCommentsForPost(postId, sort).stream() List<CommentDto> list = commentService.getCommentsForPost(postId, sort).stream()
.map(commentMapper::toDtoWithReplies) .map(commentMapper::toDtoWithReplies)
.collect(Collectors.toList()); .collect(Collectors.toList());
List<PostChangeLogDto> postChangeLogDtoList = changeLogService.listLogs(postId).stream() log.debug("listComments returning {} comments", list.size());
.map(postChangeLogMapper::toDto) return list;
.collect(Collectors.toList());
List<TimelineItemDto<?>> itemDtoList = new ArrayList<>();
itemDtoList.addAll(commentDtoList.stream()
.map(c -> new TimelineItemDto<>(
c.getId(),
"comment",
c.getCreatedAt(),
c // payload 是 CommentDto
))
.toList());
itemDtoList.addAll(postChangeLogDtoList.stream()
.map(l -> new TimelineItemDto<>(
l.getId(),
"log",
l.getTime(), // 注意字段名不一样
l // payload 是 PostChangeLogDto
))
.toList());
// 排序
Comparator<TimelineItemDto<?>> comparator = Comparator.comparing(TimelineItemDto::getCreatedAt);
if (CommentSort.NEWEST.equals(sort)) {
comparator = comparator.reversed();
}
itemDtoList.sort(comparator);
log.debug("listComments returning {} comments", itemDtoList.size());
return itemDtoList;
} }
@DeleteMapping("/comments/{id}") @DeleteMapping("/comments/{id}")

View File

@@ -27,8 +27,6 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PostController { public class PostController {
private final PostService postService; private final PostService postService;
private final CategoryService categoryService;
private final TagService tagService;
private final LevelService levelService; private final LevelService levelService;
private final CaptchaService captchaService; private final CaptchaService captchaService;
private final DraftService draftService; private final DraftService draftService;
@@ -149,16 +147,33 @@ public class PostController {
@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "pageSize", required = false) Integer pageSize,
Authentication auth) { Authentication auth) {
List<Long> ids = categoryIds;
List<Long> ids = categoryService.getSearchCategoryIds(categoryIds, categoryId); if (categoryId != null) {
List<Long> tids = tagService.getSearchTagIds(tagIds, tagId); ids = java.util.List.of(categoryId);
}
List<Long> tids = tagIds;
if (tagId != null) {
tids = java.util.List.of(tagId);
}
// 只需要在请求的一开始统计一次 // 只需要在请求的一开始统计一次
// if (auth != null) { // if (auth != null) {
// userVisitService.recordVisit(auth.getName()); // userVisitService.recordVisit(auth.getName());
// } // }
return postService.defaultListPosts(ids,tids,page, pageSize).stream() boolean hasCategories = ids != null && !ids.isEmpty();
.map(postMapper::toSummaryDto).collect(Collectors.toList()); boolean hasTags = tids != null && !tids.isEmpty();
if (hasCategories && hasTags) {
return postService.listPostsByCategoriesAndTags(ids, tids, page, pageSize)
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
}
if (hasTags) {
return postService.listPostsByTags(tids, page, pageSize)
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
}
return postService.listPostsByCategories(ids, page, pageSize)
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
} }
@GetMapping("/ranking") @GetMapping("/ranking")
@@ -172,9 +187,14 @@ public class PostController {
@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "pageSize", required = false) Integer pageSize,
Authentication auth) { Authentication auth) {
List<Long> ids = categoryIds;
List<Long> ids = categoryService.getSearchCategoryIds(categoryIds, categoryId); if (categoryId != null) {
List<Long> tids = tagService.getSearchTagIds(tagIds, tagId); ids = java.util.List.of(categoryId);
}
List<Long> tids = tagIds;
if (tagId != null) {
tids = java.util.List.of(tagId);
}
// 只需要在请求的一开始统计一次 // 只需要在请求的一开始统计一次
// if (auth != null) { // if (auth != null) {
// userVisitService.recordVisit(auth.getName()); // userVisitService.recordVisit(auth.getName());
@@ -195,16 +215,21 @@ public class PostController {
@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "pageSize", required = false) Integer pageSize,
Authentication auth) { Authentication auth) {
List<Long> ids = categoryIds;
List<Long> ids = categoryService.getSearchCategoryIds(categoryIds, categoryId); if (categoryId != null) {
List<Long> tids = tagService.getSearchTagIds(tagIds, tagId); ids = java.util.List.of(categoryId);
}
List<Long> tids = tagIds;
if (tagId != null) {
tids = java.util.List.of(tagId);
}
// 只需要在请求的一开始统计一次 // 只需要在请求的一开始统计一次
// if (auth != null) { // if (auth != null) {
// userVisitService.recordVisit(auth.getName()); // userVisitService.recordVisit(auth.getName());
// } // }
List<Post> posts = postService.listPostsByLatestReply(ids, tids, page, pageSize); return postService.listPostsByLatestReply(ids, tids, page, pageSize)
return posts.stream().map(postMapper::toSummaryDto).collect(Collectors.toList()); .stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
} }
@GetMapping("/featured") @GetMapping("/featured")
@@ -218,9 +243,14 @@ public class PostController {
@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "pageSize", required = false) Integer pageSize, @RequestParam(value = "pageSize", required = false) Integer pageSize,
Authentication auth) { Authentication auth) {
List<Long> ids = categoryIds;
List<Long> ids = categoryService.getSearchCategoryIds(categoryIds, categoryId); if (categoryId != null) {
List<Long> tids = tagService.getSearchTagIds(tagIds, tagId); ids = java.util.List.of(categoryId);
}
List<Long> tids = tagIds;
if (tagId != null) {
tids = java.util.List.of(tagId);
}
// 只需要在请求的一开始统计一次 // 只需要在请求的一开始统计一次
// if (auth != null) { // if (auth != null) {
// userVisitService.recordVisit(auth.getName()); // userVisitService.recordVisit(auth.getName());

View File

@@ -1,20 +0,0 @@
package com.openisle.dto;
import lombok.*;
import java.time.LocalDateTime;
/**
* comment and change_log Dto
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class TimelineItemDto<T> {
private Long id;
private String kind; // "comment" | "log"
private LocalDateTime createdAt;
private T payload; // 泛型,具体类型由外部决定
}

View File

@@ -67,6 +67,7 @@ public class PostMapper {
dto.setCategory(categoryMapper.toDto(post.getCategory())); dto.setCategory(categoryMapper.toDto(post.getCategory()));
dto.setTags(post.getTags().stream().map(tagMapper::toDto).collect(Collectors.toList())); dto.setTags(post.getTags().stream().map(tagMapper::toDto).collect(Collectors.toList()));
dto.setViews(post.getViews()); dto.setViews(post.getViews());
dto.setCommentCount(commentService.countComments(post.getId()));
dto.setStatus(post.getStatus()); dto.setStatus(post.getStatus());
dto.setPinnedAt(post.getPinnedAt()); dto.setPinnedAt(post.getPinnedAt());
dto.setRssExcluded(post.getRssExcluded() == null || post.getRssExcluded()); dto.setRssExcluded(post.getRssExcluded() == null || post.getRssExcluded());
@@ -81,12 +82,8 @@ public class PostMapper {
List<User> participants = commentService.getParticipants(post.getId(), 5); List<User> participants = commentService.getParticipants(post.getId(), 5);
dto.setParticipants(participants.stream().map(userMapper::toAuthorDto).collect(Collectors.toList())); dto.setParticipants(participants.stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
LocalDateTime last = post.getLastReplyAt(); LocalDateTime last = commentService.getLastCommentTime(post.getId());
if (last == null) { dto.setLastReplyAt(last != null ? last : post.getCreatedAt());
commentService.updatePostCommentStats(post);
}
dto.setCommentCount(post.getCommentCount());
dto.setLastReplyAt(post.getLastReplyAt());
dto.setReward(0); dto.setReward(0);
dto.setSubscribed(false); dto.setSubscribed(false);
dto.setType(post.getType()); dto.setType(post.getType());
@@ -99,6 +96,8 @@ public class PostMapper {
l.setPointCost(lp.getPointCost()); l.setPointCost(lp.getPointCost());
l.setStartTime(lp.getStartTime()); l.setStartTime(lp.getStartTime());
l.setEndTime(lp.getEndTime()); l.setEndTime(lp.getEndTime());
l.setParticipants(lp.getParticipants().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
l.setWinners(lp.getWinners().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
dto.setLottery(l); dto.setLottery(l);
} }
@@ -107,6 +106,7 @@ public class PostMapper {
p.setOptions(pp.getOptions()); p.setOptions(pp.getOptions());
p.setVotes(pp.getVotes()); p.setVotes(pp.getVotes());
p.setEndTime(pp.getEndTime()); p.setEndTime(pp.getEndTime());
p.setParticipants(pp.getParticipants().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
Map<Integer, List<AuthorDto>> optionParticipants = pollVoteRepository.findByPostId(pp.getId()).stream() Map<Integer, List<AuthorDto>> optionParticipants = pollVoteRepository.findByPostId(pp.getId()).stream()
.collect(Collectors.groupingBy(PollVote::getOptionIndex, .collect(Collectors.groupingBy(PollVote::getOptionIndex,
Collectors.mapping(v -> userMapper.toAuthorDto(v.getUser()), Collectors.toList()))); Collectors.mapping(v -> userMapper.toAuthorDto(v.getUser()), Collectors.toList())));

View File

@@ -39,19 +39,19 @@ public class Post {
columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6)") columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6)")
private LocalDateTime createdAt; private LocalDateTime createdAt;
@ManyToOne(optional = false, fetch = FetchType.EAGER) @ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "author_id") @JoinColumn(name = "author_id")
private User author; private User author;
@ManyToOne(optional = false, fetch = FetchType.EAGER) @ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "category_id") @JoinColumn(name = "category_id")
private Category category; private Category category;
@ManyToMany(fetch = FetchType.EAGER) @ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "post_tags", @JoinTable(name = "post_tags",
joinColumns = @JoinColumn(name = "post_id"), joinColumns = @JoinColumn(name = "post_id"),
inverseJoinColumns = @JoinColumn(name = "tag_id")) inverseJoinColumns = @JoinColumn(name = "tag_id"))
private Set<Tag> tags = new HashSet<>(); private java.util.Set<Tag> tags = new java.util.HashSet<>();
@Column(nullable = false) @Column(nullable = false)
private long views = 0; private long views = 0;
@@ -72,10 +72,4 @@ public class Post {
@Column(nullable = true) @Column(nullable = true)
private Boolean rssExcluded = true; private Boolean rssExcluded = true;
@Column(nullable = false)
private long commentCount = 0;
@Column(nullable = true)
private LocalDateTime lastReplyAt;
} }

View File

@@ -1,9 +1,8 @@
package com.openisle.repository; package com.openisle.repository;
import com.openisle.model.Comment;
import com.openisle.model.PointHistory; import com.openisle.model.PointHistory;
import com.openisle.model.Post;
import com.openisle.model.User; import com.openisle.model.User;
import com.openisle.model.Comment;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@@ -15,8 +14,6 @@ public interface PointHistoryRepository extends JpaRepository<PointHistory, Long
long countByUser(User user); long countByUser(User user);
List<PointHistory> findByUserAndCreatedAtAfterOrderByCreatedAtDesc(User user, LocalDateTime createdAt); List<PointHistory> findByUserAndCreatedAtAfterOrderByCreatedAtDesc(User user, LocalDateTime createdAt);
List<PointHistory> findByComment(Comment comment); List<PointHistory> findByComment(Comment comment);
List<PointHistory> findByPost(Post post);
} }

View File

@@ -8,6 +8,4 @@ import java.util.List;
public interface PostChangeLogRepository extends JpaRepository<PostChangeLog, Long> { public interface PostChangeLogRepository extends JpaRepository<PostChangeLog, Long> {
List<PostChangeLog> findByPostOrderByCreatedAtAsc(Post post); List<PostChangeLog> findByPostOrderByCreatedAtAsc(Post post);
void deleteByPost(Post post);
} }

View File

@@ -27,12 +27,12 @@ public class UserVisitScheduler {
private final UserRepository userRepository; private final UserRepository userRepository;
private final UserVisitRepository userVisitRepository; private final UserVisitRepository userVisitRepository;
@Scheduled(cron = "0 5 0 * * ?") // 每天 00:05 执行 @Scheduled(cron = "0 5 0 * * ?")// 每天 00:05 执行
public void persistDailyVisits(){ public void persistDailyVisits(){
LocalDate yesterday = LocalDate.now().minusDays(1); LocalDate yesterday = LocalDate.now().minusDays(1);
String key = CachingConfig.VISIT_CACHE_NAME + ":" + yesterday; String key = CachingConfig.VISIT_CACHE_NAME+":"+ yesterday;
Set<String> usernames = redisTemplate.opsForSet().members(key); Set<String> usernames = redisTemplate.opsForSet().members(key);
if (!CollectionUtils.isEmpty(usernames)) { if(!CollectionUtils.isEmpty(usernames)){
for(String username: usernames){ for(String username: usernames){
User user = userRepository.findByUsername(username).orElse(null); User user = userRepository.findByUsername(username).orElse(null);
if(user != null){ if(user != null){

View File

@@ -62,18 +62,4 @@ public class CategoryService {
public List<Category> listCategories() { public List<Category> listCategories() {
return categoryRepository.findAll(); return categoryRepository.findAll();
} }
/**
* 获取检索用的分类Id列表
* @param categoryIds
* @param categoryId
* @return
*/
public List<Long> getSearchCategoryIds(List<Long> categoryIds, Long categoryId){
List<Long> ids = categoryIds;
if (categoryId != null) {
ids = List.of(categoryId);
}
return ids;
}
} }

View File

@@ -1,6 +1,5 @@
package com.openisle.service; package com.openisle.service;
import com.openisle.config.CachingConfig;
import com.openisle.model.Comment; import com.openisle.model.Comment;
import com.openisle.model.Post; import com.openisle.model.Post;
import com.openisle.model.User; import com.openisle.model.User;
@@ -21,8 +20,6 @@ import com.openisle.model.Role;
import com.openisle.exception.RateLimitException; import com.openisle.exception.RateLimitException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@@ -50,10 +47,6 @@ public class CommentService {
private final PointService pointService; private final PointService pointService;
private final ImageUploader imageUploader; private final ImageUploader imageUploader;
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
@Transactional @Transactional
public Comment addComment(String username, Long postId, String content) { public Comment addComment(String username, Long postId, String content) {
log.debug("addComment called by user {} for post {}", username, postId); log.debug("addComment called by user {} for post {}", username, postId);
@@ -76,10 +69,6 @@ public class CommentService {
comment.setContent(content); comment.setContent(content);
comment = commentRepository.save(comment); comment = commentRepository.save(comment);
log.debug("Comment {} saved for post {}", comment.getId(), postId); log.debug("Comment {} saved for post {}", comment.getId(), postId);
// Update post comment statistics
updatePostCommentStats(post);
imageUploader.addReferences(imageUploader.extractUrls(content)); imageUploader.addReferences(imageUploader.extractUrls(content));
if (!author.getId().equals(post.getAuthor().getId())) { if (!author.getId().equals(post.getAuthor().getId())) {
notificationService.createNotification(post.getAuthor(), NotificationType.COMMENT_REPLY, post, comment, notificationService.createNotification(post.getAuthor(), NotificationType.COMMENT_REPLY, post, comment,
@@ -106,10 +95,6 @@ public class CommentService {
return commentRepository.findLastCommentTimeOfUserByUserId(userId); return commentRepository.findLastCommentTimeOfUserByUserId(userId);
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
@Transactional @Transactional
public Comment addReply(String username, Long parentId, String content) { public Comment addReply(String username, Long parentId, String content) {
log.debug("addReply called by user {} for parent comment {}", username, parentId); log.debug("addReply called by user {} for parent comment {}", username, parentId);
@@ -133,10 +118,6 @@ public class CommentService {
comment.setContent(content); comment.setContent(content);
comment = commentRepository.save(comment); comment = commentRepository.save(comment);
log.debug("Reply {} saved for parent {}", comment.getId(), parentId); log.debug("Reply {} saved for parent {}", comment.getId(), parentId);
// Update post comment statistics
updatePostCommentStats(parent.getPost());
imageUploader.addReferences(imageUploader.extractUrls(content)); imageUploader.addReferences(imageUploader.extractUrls(content));
if (!author.getId().equals(parent.getAuthor().getId())) { if (!author.getId().equals(parent.getAuthor().getId())) {
notificationService.createNotification(parent.getAuthor(), NotificationType.COMMENT_REPLY, parent.getPost(), notificationService.createNotification(parent.getAuthor(), NotificationType.COMMENT_REPLY, parent.getPost(),
@@ -247,10 +228,6 @@ public class CommentService {
return count; return count;
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
@Transactional @Transactional
public void deleteComment(String username, Long id) { public void deleteComment(String username, Long id) {
log.debug("deleteComment called by user {} for comment {}", username, id); log.debug("deleteComment called by user {} for comment {}", username, id);
@@ -266,10 +243,6 @@ public class CommentService {
log.debug("deleteComment completed for comment {}", id); log.debug("deleteComment completed for comment {}", id);
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
@Transactional @Transactional
public void deleteCommentCascade(Comment comment) { public void deleteCommentCascade(Comment comment) {
log.debug("deleteCommentCascade called for comment {}", comment.getId()); log.debug("deleteCommentCascade called for comment {}", comment.getId());
@@ -290,13 +263,9 @@ public class CommentService {
imageUploader.removeReferences(imageUploader.extractUrls(comment.getContent())); imageUploader.removeReferences(imageUploader.extractUrls(comment.getContent()));
// 逻辑删除评论 // 逻辑删除评论
Post post = comment.getPost();
commentRepository.delete(comment); commentRepository.delete(comment);
// 删除积分历史 // 删除积分历史
pointHistoryRepository.deleteAll(pointHistories); pointHistoryRepository.deleteAll(pointHistories);
// Update post comment statistics
updatePostCommentStats(post);
// 重新计算受影响用户的积分 // 重新计算受影响用户的积分
if (!usersToRecalculate.isEmpty()) { if (!usersToRecalculate.isEmpty()) {
@@ -342,23 +311,4 @@ public class CommentService {
int replies = commentRepository.findByParentOrderByCreatedAtAsc(comment).size(); int replies = commentRepository.findByParentOrderByCreatedAtAsc(comment).size();
return reactions + replies; return reactions + replies;
} }
/**
* Update post comment statistics (comment count and last reply time)
*/
public void updatePostCommentStats(Post post) {
long commentCount = commentRepository.countByPostId(post.getId());
post.setCommentCount(commentCount);
LocalDateTime lastReplyAt = commentRepository.findLastCommentTime(post);
if (lastReplyAt == null) {
post.setLastReplyAt(post.getCreatedAt());
} else {
post.setLastReplyAt(lastReplyAt);
}
postRepository.save(post);
log.debug("Updated post {} stats: commentCount={}, lastReplyAt={}",
post.getId(), commentCount, lastReplyAt);
}
} }

View File

@@ -109,10 +109,6 @@ public class PostChangeLogService {
logRepository.save(log); logRepository.save(log);
} }
public void deleteLogsForPost(Post post) {
logRepository.deleteByPost(post);
}
public List<PostChangeLog> listLogs(Long postId) { public List<PostChangeLog> listLogs(Long postId) {
Post post = postRepository.findById(postId) Post post = postRepository.findById(postId)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));

View File

@@ -1,26 +1,36 @@
package com.openisle.service; package com.openisle.service;
import com.openisle.config.CachingConfig; import com.openisle.config.CachingConfig;
import com.openisle.mapper.PostMapper; import com.openisle.model.Post;
import com.openisle.model.*; import com.openisle.model.PostStatus;
import com.openisle.model.PostType;
import com.openisle.model.PublishMode;
import com.openisle.model.User;
import com.openisle.model.Category;
import com.openisle.model.Comment;
import com.openisle.model.NotificationType;
import com.openisle.model.LotteryPost;
import com.openisle.model.PollPost;
import com.openisle.model.PollVote;
import com.openisle.repository.PostRepository; import com.openisle.repository.PostRepository;
import com.openisle.repository.LotteryPostRepository; import com.openisle.repository.LotteryPostRepository;
import com.openisle.repository.PollPostRepository; import com.openisle.repository.PollPostRepository;
import com.openisle.repository.UserRepository; import com.openisle.repository.UserRepository;
import com.openisle.repository.CategoryRepository; import com.openisle.repository.CategoryRepository;
import com.openisle.repository.TagRepository; import com.openisle.repository.TagRepository;
import com.openisle.service.SubscriptionService;
import com.openisle.service.CommentService;
import com.openisle.service.PostChangeLogService;
import com.openisle.repository.CommentRepository; import com.openisle.repository.CommentRepository;
import com.openisle.repository.ReactionRepository; import com.openisle.repository.ReactionRepository;
import com.openisle.repository.PostSubscriptionRepository; import com.openisle.repository.PostSubscriptionRepository;
import com.openisle.repository.NotificationRepository; import com.openisle.repository.NotificationRepository;
import com.openisle.repository.PollVoteRepository; import com.openisle.repository.PollVoteRepository;
import com.openisle.repository.PointHistoryRepository; import com.openisle.model.Role;
import com.openisle.exception.RateLimitException; import com.openisle.exception.RateLimitException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -42,8 +52,6 @@ import java.time.LocalDateTime;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.stream.Collectors;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
@@ -72,7 +80,6 @@ public class PostService {
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final PointService pointService; private final PointService pointService;
private final PostChangeLogService postChangeLogService; private final PostChangeLogService postChangeLogService;
private final PointHistoryRepository pointHistoryRepository;
private final ConcurrentMap<Long, ScheduledFuture<?>> scheduledFinalizations = new ConcurrentHashMap<>(); private final ConcurrentMap<Long, ScheduledFuture<?>> scheduledFinalizations = new ConcurrentHashMap<>();
@Value("${app.website-url:https://www.open-isle.com}") @Value("${app.website-url:https://www.open-isle.com}")
private String websiteUrl; private String websiteUrl;
@@ -101,7 +108,6 @@ public class PostService {
ApplicationContext applicationContext, ApplicationContext applicationContext,
PointService pointService, PointService pointService,
PostChangeLogService postChangeLogService, PostChangeLogService postChangeLogService,
PointHistoryRepository pointHistoryRepository,
@Value("${app.post.publish-mode:DIRECT}") PublishMode publishMode, @Value("${app.post.publish-mode:DIRECT}") PublishMode publishMode,
RedisTemplate redisTemplate) { RedisTemplate redisTemplate) {
this.postRepository = postRepository; this.postRepository = postRepository;
@@ -125,7 +131,6 @@ public class PostService {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.pointService = pointService; this.pointService = pointService;
this.postChangeLogService = postChangeLogService; this.postChangeLogService = postChangeLogService;
this.pointHistoryRepository = pointHistoryRepository;
this.publishMode = publishMode; this.publishMode = publishMode;
this.redisTemplate = redisTemplate; this.redisTemplate = redisTemplate;
@@ -190,14 +195,12 @@ public class PostService {
pointService.awardForFeatured(saved.getAuthor().getUsername(), saved.getId()); pointService.awardForFeatured(saved.getAuthor().getUsername(), saved.getId());
return saved; return saved;
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME, allEntries = true
)
public Post createPost(String username, public Post createPost(String username,
Long categoryId, Long categoryId,
String title, String title,
String content, String content,
List<Long> tagIds, java.util.List<Long> tagIds,
PostType type, PostType type,
String prizeDescription, String prizeDescription,
String prizeIcon, String prizeIcon,
@@ -508,10 +511,6 @@ public class PostService {
return listPostsByLatestReply(null, null, page, pageSize); return listPostsByLatestReply(null, null, page, pageSize);
} }
@Cacheable(
value = CachingConfig.POST_CACHE_NAME,
key = "new org.springframework.cache.interceptor.SimpleKey('latest_reply', #categoryIds, #tagIds, #page, #pageSize)"
)
public List<Post> listPostsByLatestReply(java.util.List<Long> categoryIds, public List<Post> listPostsByLatestReply(java.util.List<Long> categoryIds,
java.util.List<Long> tagIds, java.util.List<Long> tagIds,
Integer page, Integer page,
@@ -539,9 +538,9 @@ public class PostService {
posts = postRepository.findByCategoryInAndStatusOrderByCreatedAtDesc(categories, PostStatus.PUBLISHED); posts = postRepository.findByCategoryInAndStatusOrderByCreatedAtDesc(categories, PostStatus.PUBLISHED);
} }
} else { } else {
List<Tag> tags = tagRepository.findAllById(tagIds); java.util.List<com.openisle.model.Tag> tags = tagRepository.findAllById(tagIds);
if (tags.isEmpty()) { if (tags.isEmpty()) {
return new ArrayList<>(); return java.util.List.of();
} }
posts = postRepository.findByAllTagsOrderByCreatedAtDesc(tags, PostStatus.PUBLISHED, tags.size()); posts = postRepository.findByAllTagsOrderByCreatedAtDesc(tags, PostStatus.PUBLISHED, tags.size());
} }
@@ -639,43 +638,11 @@ public class PostService {
return paginate(sortByPinnedAndCreated(posts), page, pageSize); return paginate(sortByPinnedAndCreated(posts), page, pageSize);
} }
/**
* 默认的文章列表
* @param ids
* @param tids
* @param page
* @param pageSize
* @return
*/
@Cacheable(
value = CachingConfig.POST_CACHE_NAME,
key = "new org.springframework.cache.interceptor.SimpleKey('default', #ids, #tids, #page, #pageSize)"
)
public List<Post> defaultListPosts(List<Long> ids, List<Long> tids, Integer page, Integer pageSize){
boolean hasCategories = !CollectionUtils.isEmpty(ids);
boolean hasTags = !CollectionUtils.isEmpty(tids);
if (hasCategories && hasTags) {
return listPostsByCategoriesAndTags(ids, tids, page, pageSize)
.stream().collect(Collectors.toList());
}
if (hasTags) {
return listPostsByTags(tids, page, pageSize)
.stream().collect(Collectors.toList());
}
return listPostsByCategories(ids, page, pageSize)
.stream().collect(Collectors.toList());
}
public List<Post> listPendingPosts() { public List<Post> listPendingPosts() {
return postRepository.findByStatus(PostStatus.PENDING); return postRepository.findByStatus(PostStatus.PENDING);
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
public Post approvePost(Long id) { public Post approvePost(Long id) {
Post post = postRepository.findById(id) Post post = postRepository.findById(id)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
@@ -712,10 +679,6 @@ public class PostService {
return post; return post;
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
public Post pinPost(Long id, String username) { public Post pinPost(Long id, String username) {
Post post = postRepository.findById(id) Post post = postRepository.findById(id)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
@@ -728,10 +691,6 @@ public class PostService {
return saved; return saved;
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
public Post unpinPost(Long id, String username) { public Post unpinPost(Long id, String username) {
Post post = postRepository.findById(id) Post post = postRepository.findById(id)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
@@ -744,10 +703,6 @@ public class PostService {
return saved; return saved;
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
public Post closePost(Long id, String username) { public Post closePost(Long id, String username) {
Post post = postRepository.findById(id) Post post = postRepository.findById(id)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
@@ -763,10 +718,6 @@ public class PostService {
return saved; return saved;
} }
@CacheEvict(
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
public Post reopenPost(Long id, String username) { public Post reopenPost(Long id, String username) {
Post post = postRepository.findById(id) Post post = postRepository.findById(id)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
@@ -782,11 +733,7 @@ public class PostService {
return saved; return saved;
} }
@CacheEvict( @org.springframework.transaction.annotation.Transactional
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
@Transactional
public Post updatePost(Long id, public Post updatePost(Long id,
String username, String username,
Long categoryId, Long categoryId,
@@ -839,11 +786,7 @@ public class PostService {
return updated; return updated;
} }
@CacheEvict( @org.springframework.transaction.annotation.Transactional
value = CachingConfig.POST_CACHE_NAME,
allEntries = true
)
@Transactional
public void deletePost(Long id, String username) { public void deletePost(Long id, String username) {
Post post = postRepository.findById(id) Post post = postRepository.findById(id)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
@@ -862,25 +805,6 @@ public class PostService {
notificationRepository.deleteAll(notificationRepository.findByPost(post)); notificationRepository.deleteAll(notificationRepository.findByPost(post));
postReadService.deleteByPost(post); postReadService.deleteByPost(post);
imageUploader.removeReferences(imageUploader.extractUrls(post.getContent())); imageUploader.removeReferences(imageUploader.extractUrls(post.getContent()));
List<PointHistory> pointHistories = pointHistoryRepository.findByPost(post);
Set<User> usersToRecalculate = pointHistories.stream()
.map(PointHistory::getUser)
.collect(Collectors.toSet());
if (!pointHistories.isEmpty()) {
LocalDateTime deletedAt = LocalDateTime.now();
for (PointHistory history : pointHistories) {
history.setDeletedAt(deletedAt);
history.setPost(null);
}
pointHistoryRepository.saveAll(pointHistories);
}
if (!usersToRecalculate.isEmpty()) {
for (User affected : usersToRecalculate) {
int newPoints = pointService.recalculateUserPoints(affected);
affected.setPoint(newPoints);
}
userRepository.saveAll(usersToRecalculate);
}
if (post instanceof LotteryPost lp) { if (post instanceof LotteryPost lp) {
ScheduledFuture<?> future = scheduledFinalizations.remove(lp.getId()); ScheduledFuture<?> future = scheduledFinalizations.remove(lp.getId());
if (future != null) { if (future != null) {
@@ -888,7 +812,6 @@ public class PostService {
} }
} }
String title = post.getTitle(); String title = post.getTitle();
postChangeLogService.deleteLogsForPost(post);
postRepository.delete(post); postRepository.delete(post);
if (adminDeleting) { if (adminDeleting) {
notificationService.createNotification(author, NotificationType.POST_DELETED, notificationService.createNotification(author, NotificationType.POST_DELETED,
@@ -956,17 +879,15 @@ public class PostService {
.toList(); .toList();
} }
private List<Post> paginate(List<Post> posts, Integer page, Integer pageSize) { private java.util.List<Post> paginate(java.util.List<Post> posts, Integer page, Integer pageSize) {
if (page == null || pageSize == null) { if (page == null || pageSize == null) {
return posts; return posts;
} }
int from = page * pageSize; int from = page * pageSize;
if (from >= posts.size()) { if (from >= posts.size()) {
return new ArrayList<>(); return java.util.List.of();
} }
int to = Math.min(from + pageSize, posts.size()); int to = Math.min(from + pageSize, posts.size());
// 这里必须将list包装为arrayList类型否则序列化会有问题 return posts.subList(from, to);
// list.sublist返回的是内部类
return new ArrayList<>(posts.subList(from, to));
} }
} }

View File

@@ -120,18 +120,4 @@ public class TagService {
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
return tagRepository.findByCreator(user); return tagRepository.findByCreator(user);
} }
/**
* 获取检索用的标签Id列表
* @param tagIds
* @param tagId
* @return
*/
public List<Long> getSearchTagIds(List<Long> tagIds, Long tagId){
List<Long> ids = tagIds;
if (tagId != null) {
ids = List.of(tagId);
}
return ids;
}
} }

View File

@@ -100,7 +100,7 @@ public class UserService {
* @param user * @param user
*/ */
public void sendVerifyMail(User user, VerifyType verifyType){ public void sendVerifyMail(User user, VerifyType verifyType){
// 缓存验证码 //缓存验证码
String code = genCode(); String code = genCode();
String key; String key;
String subject; String subject;

View File

@@ -49,9 +49,9 @@ public class UserVisitService {
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
// 如果缓存存在就返回 // 如果缓存存在就返回
String key1 = CachingConfig.VISIT_CACHE_NAME + ":" +LocalDate.now() + ":count:" + username; String key1 = CachingConfig.VISIT_CACHE_NAME + ":"+LocalDate.now()+":count:"+username;
Integer cached = (Integer) redisTemplate.opsForValue().get(key1); Integer cached = (Integer) redisTemplate.opsForValue().get(key1);
if (cached != null){ if(cached != null){
return cached.longValue(); return cached.longValue();
} }

View File

@@ -1,19 +0,0 @@
-- Add comment count and last reply time fields to posts table for performance optimization
ALTER TABLE posts ADD COLUMN comment_count BIGINT NOT NULL DEFAULT 0;
ALTER TABLE posts ADD COLUMN last_reply_at DATETIME(6) NULL;
-- Add index on last_reply_at for sorting by latest reply
CREATE INDEX idx_posts_last_reply_at ON posts(last_reply_at);
-- Initialize comment_count and last_reply_at with existing data
UPDATE posts p SET
comment_count = (
SELECT COUNT(*)
FROM comments c
WHERE c.post_id = p.id AND c.deleted_at IS NULL
),
last_reply_at = (
SELECT MAX(c.created_at)
FROM comments c
WHERE c.post_id = p.id AND c.deleted_at IS NULL
);

View File

@@ -55,10 +55,6 @@ class PostControllerTest {
private UserVisitService userVisitService; private UserVisitService userVisitService;
@MockBean @MockBean
private PostReadService postReadService; private PostReadService postReadService;
@MockBean
private MedalService medalService;
@MockBean
private com.openisle.repository.PollVoteRepository pollVoteRepository;
@Test @Test
void createAndGetPost() throws Exception { void createAndGetPost() throws Exception {
@@ -67,13 +63,9 @@ class PostControllerTest {
Category cat = new Category(); Category cat = new Category();
cat.setId(1L); cat.setId(1L);
cat.setName("tech"); cat.setName("tech");
cat.setDescription("Technology category");
cat.setIcon("tech-icon");
Tag tag = new Tag(); Tag tag = new Tag();
tag.setId(1L); tag.setId(1L);
tag.setName("java"); tag.setName("java");
tag.setDescription("Java programming language");
tag.setIcon("java-icon");
Post post = new Post(); Post post = new Post();
post.setId(1L); post.setId(1L);
post.setTitle("t"); post.setTitle("t");
@@ -119,13 +111,9 @@ class PostControllerTest {
Category cat = new Category(); Category cat = new Category();
cat.setId(1L); cat.setId(1L);
cat.setName("tech"); cat.setName("tech");
cat.setDescription("Technology category");
cat.setIcon("tech-icon");
Tag tag = new Tag(); Tag tag = new Tag();
tag.setId(1L); tag.setId(1L);
tag.setName("java"); tag.setName("java");
tag.setDescription("Java programming language");
tag.setIcon("java-icon");
Post post = new Post(); Post post = new Post();
post.setId(1L); post.setId(1L);
post.setTitle("t2"); post.setTitle("t2");
@@ -159,13 +147,9 @@ class PostControllerTest {
Category cat = new Category(); Category cat = new Category();
cat.setId(1L); cat.setId(1L);
cat.setName("tech"); cat.setName("tech");
cat.setDescription("Technology category");
cat.setIcon("tech-icon");
Tag tag = new Tag(); Tag tag = new Tag();
tag.setId(1L); tag.setId(1L);
tag.setName("java"); tag.setName("java");
tag.setDescription("Java programming language");
tag.setIcon("java-icon");
Post post = new Post(); Post post = new Post();
post.setId(2L); post.setId(2L);
post.setTitle("hello"); post.setTitle("hello");
@@ -213,13 +197,9 @@ class PostControllerTest {
Category cat = new Category(); Category cat = new Category();
cat.setId(1L); cat.setId(1L);
cat.setName("tech"); cat.setName("tech");
cat.setDescription("Technology category");
cat.setIcon("tech-icon");
Tag tag = new Tag(); Tag tag = new Tag();
tag.setId(1L); tag.setId(1L);
tag.setName("java"); tag.setName("java");
tag.setDescription("Java programming language");
tag.setIcon("java-icon");
Post post = new Post(); Post post = new Post();
post.setId(1L); post.setId(1L);
post.setTitle("t"); post.setTitle("t");
@@ -282,8 +262,6 @@ class PostControllerTest {
Category cat = new Category(); Category cat = new Category();
cat.setId(1L); cat.setId(1L);
cat.setName("tech"); cat.setName("tech");
cat.setDescription("Technology category");
cat.setIcon("tech-icon");
Post post = new Post(); Post post = new Post();
post.setId(1L); post.setId(1L);
post.setTitle("t"); post.setTitle("t");

View File

@@ -1,90 +0,0 @@
package com.openisle.service;
import com.openisle.model.*;
import com.openisle.repository.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@TestPropertySource(locations = "classpath:application.properties")
@Transactional
public class PostCommentStatsTest {
@Autowired
private PostRepository postRepository;
@Autowired
private UserRepository userRepository;
@Autowired
private CategoryRepository categoryRepository;
@Autowired
private TagRepository tagRepository;
@Autowired
private CommentService commentService;
@Test
public void testPostCommentStatsUpdate() {
// Create test user
User user = new User();
user.setUsername("testuser");
user.setEmail("test@example.com");
user.setPassword("hash");
user = userRepository.save(user);
// Create test category
Category category = new Category();
category.setName("Test Category");
category.setDescription("Test Category Description");
category.setIcon("test-icon");
category = categoryRepository.save(category);
// Create test tag
Tag tag = new Tag();
tag.setName("Test Tag");
tag.setDescription("Test Tag Description");
tag.setIcon("test-tag-icon");
tag = tagRepository.save(tag);
// Create test post
Post post = new Post();
post.setTitle("Test Post");
post.setContent("Test content");
post.setAuthor(user);
post.setCategory(category);
post.getTags().add(tag);
post.setStatus(PostStatus.PUBLISHED);
post.setCommentCount(0L);
post = postRepository.save(post);
// Verify initial state
assertEquals(0L, post.getCommentCount());
assertNull(post.getLastReplyAt());
// Add a comment
commentService.addComment("testuser", post.getId(), "Test comment");
// Refresh post from database
post = postRepository.findById(post.getId()).orElseThrow();
// Verify comment count and last reply time are updated
assertEquals(1L, post.getCommentCount());
assertNotNull(post.getLastReplyAt());
// Add another comment
commentService.addComment("testuser", post.getId(), "Another comment");
// Refresh post again
post = postRepository.findById(post.getId()).orElseThrow();
// Verify comment count is updated
assertEquals(2L, post.getCommentCount());
}
}

View File

@@ -10,11 +10,8 @@ import org.springframework.data.redis.core.RedisTemplate;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.List;
import org.mockito.ArgumentCaptor;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
@@ -42,14 +39,12 @@ class PostServiceTest {
ApplicationContext context = mock(ApplicationContext.class); ApplicationContext context = mock(ApplicationContext.class);
PointService pointService = mock(PointService.class); PointService pointService = mock(PointService.class);
PostChangeLogService postChangeLogService = mock(PostChangeLogService.class); PostChangeLogService postChangeLogService = mock(PostChangeLogService.class);
PointHistoryRepository pointHistoryRepository = mock(PointHistoryRepository.class);
RedisTemplate redisTemplate = mock(RedisTemplate.class); RedisTemplate redisTemplate = mock(RedisTemplate.class);
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo, PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo, pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo,
reactionRepo, subRepo, notificationRepo, postReadService, reactionRepo, subRepo, notificationRepo, postReadService,
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, PublishMode.DIRECT, redisTemplate);
pointHistoryRepository, PublishMode.DIRECT, redisTemplate);
when(context.getBean(PostService.class)).thenReturn(service); when(context.getBean(PostService.class)).thenReturn(service);
Post post = new Post(); Post post = new Post();
@@ -65,13 +60,11 @@ class PostServiceTest {
when(reactionRepo.findByPost(post)).thenReturn(List.of()); when(reactionRepo.findByPost(post)).thenReturn(List.of());
when(subRepo.findByPost(post)).thenReturn(List.of()); when(subRepo.findByPost(post)).thenReturn(List.of());
when(notificationRepo.findByPost(post)).thenReturn(List.of()); when(notificationRepo.findByPost(post)).thenReturn(List.of());
when(pointHistoryRepository.findByPost(post)).thenReturn(List.of());
service.deletePost(1L, "alice"); service.deletePost(1L, "alice");
verify(postReadService).deleteByPost(post); verify(postReadService).deleteByPost(post);
verify(postRepo).delete(post); verify(postRepo).delete(post);
verify(postChangeLogService).deleteLogsForPost(post);
} }
@Test @Test
@@ -97,14 +90,12 @@ class PostServiceTest {
ApplicationContext context = mock(ApplicationContext.class); ApplicationContext context = mock(ApplicationContext.class);
PointService pointService = mock(PointService.class); PointService pointService = mock(PointService.class);
PostChangeLogService postChangeLogService = mock(PostChangeLogService.class); PostChangeLogService postChangeLogService = mock(PostChangeLogService.class);
PointHistoryRepository pointHistoryRepository = mock(PointHistoryRepository.class);
RedisTemplate redisTemplate = mock(RedisTemplate.class); RedisTemplate redisTemplate = mock(RedisTemplate.class);
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo, PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo, pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo,
reactionRepo, subRepo, notificationRepo, postReadService, reactionRepo, subRepo, notificationRepo, postReadService,
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, PublishMode.DIRECT, redisTemplate);
pointHistoryRepository, PublishMode.DIRECT, redisTemplate);
when(context.getBean(PostService.class)).thenReturn(service); when(context.getBean(PostService.class)).thenReturn(service);
Post post = new Post(); Post post = new Post();
@@ -126,7 +117,6 @@ class PostServiceTest {
when(reactionRepo.findByPost(post)).thenReturn(List.of()); when(reactionRepo.findByPost(post)).thenReturn(List.of());
when(subRepo.findByPost(post)).thenReturn(List.of()); when(subRepo.findByPost(post)).thenReturn(List.of());
when(notificationRepo.findByPost(post)).thenReturn(List.of()); when(notificationRepo.findByPost(post)).thenReturn(List.of());
when(pointHistoryRepository.findByPost(post)).thenReturn(List.of());
service.deletePost(1L, "admin"); service.deletePost(1L, "admin");
@@ -157,14 +147,12 @@ class PostServiceTest {
ApplicationContext context = mock(ApplicationContext.class); ApplicationContext context = mock(ApplicationContext.class);
PointService pointService = mock(PointService.class); PointService pointService = mock(PointService.class);
PostChangeLogService postChangeLogService = mock(PostChangeLogService.class); PostChangeLogService postChangeLogService = mock(PostChangeLogService.class);
PointHistoryRepository pointHistoryRepository = mock(PointHistoryRepository.class);
RedisTemplate redisTemplate = mock(RedisTemplate.class); RedisTemplate redisTemplate = mock(RedisTemplate.class);
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo, PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo, pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo,
reactionRepo, subRepo, notificationRepo, postReadService, reactionRepo, subRepo, notificationRepo, postReadService,
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, PublishMode.DIRECT, redisTemplate);
pointHistoryRepository, PublishMode.DIRECT, redisTemplate);
when(context.getBean(PostService.class)).thenReturn(service); when(context.getBean(PostService.class)).thenReturn(service);
when(postRepo.countByAuthorAfter(eq("alice"), any())).thenReturn(1L); when(postRepo.countByAuthorAfter(eq("alice"), any())).thenReturn(1L);
@@ -174,77 +162,6 @@ class PostServiceTest {
null, null, null, null, null, null, null, null, null)); null, null, null, null, null, null, null, null, null));
} }
@Test
void deletePostRemovesPointHistoriesAndRecalculatesPoints() {
PostRepository postRepo = mock(PostRepository.class);
UserRepository userRepo = mock(UserRepository.class);
CategoryRepository catRepo = mock(CategoryRepository.class);
TagRepository tagRepo = mock(TagRepository.class);
LotteryPostRepository lotteryRepo = mock(LotteryPostRepository.class);
PollPostRepository pollPostRepo = mock(PollPostRepository.class);
PollVoteRepository pollVoteRepo = mock(PollVoteRepository.class);
NotificationService notifService = mock(NotificationService.class);
SubscriptionService subService = mock(SubscriptionService.class);
CommentService commentService = mock(CommentService.class);
CommentRepository commentRepo = mock(CommentRepository.class);
ReactionRepository reactionRepo = mock(ReactionRepository.class);
PostSubscriptionRepository subRepo = mock(PostSubscriptionRepository.class);
NotificationRepository notificationRepo = mock(NotificationRepository.class);
PostReadService postReadService = mock(PostReadService.class);
ImageUploader imageUploader = mock(ImageUploader.class);
TaskScheduler taskScheduler = mock(TaskScheduler.class);
EmailSender emailSender = mock(EmailSender.class);
ApplicationContext context = mock(ApplicationContext.class);
PointService pointService = mock(PointService.class);
PostChangeLogService postChangeLogService = mock(PostChangeLogService.class);
PointHistoryRepository pointHistoryRepository = mock(PointHistoryRepository.class);
RedisTemplate redisTemplate = mock(RedisTemplate.class);
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo,
reactionRepo, subRepo, notificationRepo, postReadService,
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService,
pointHistoryRepository, PublishMode.DIRECT, redisTemplate);
when(context.getBean(PostService.class)).thenReturn(service);
Post post = new Post();
post.setId(10L);
User author = new User();
author.setId(20L);
author.setRole(Role.USER);
post.setAuthor(author);
User historyUser = new User();
historyUser.setId(30L);
PointHistory history = new PointHistory();
history.setUser(historyUser);
history.setPost(post);
when(postRepo.findById(10L)).thenReturn(Optional.of(post));
when(userRepo.findByUsername("author")).thenReturn(Optional.of(author));
when(commentRepo.findByPostAndParentIsNullOrderByCreatedAtAsc(post)).thenReturn(List.of());
when(reactionRepo.findByPost(post)).thenReturn(List.of());
when(subRepo.findByPost(post)).thenReturn(List.of());
when(notificationRepo.findByPost(post)).thenReturn(List.of());
when(pointHistoryRepository.findByPost(post)).thenReturn(List.of(history));
when(pointService.recalculateUserPoints(historyUser)).thenReturn(0);
service.deletePost(10L, "author");
ArgumentCaptor<List<PointHistory>> captor = ArgumentCaptor.forClass(List.class);
verify(pointHistoryRepository).saveAll(captor.capture());
List<PointHistory> savedHistories = captor.getValue();
assertEquals(1, savedHistories.size());
PointHistory savedHistory = savedHistories.get(0);
assertNull(savedHistory.getPost());
assertNotNull(savedHistory.getDeletedAt());
assertTrue(savedHistory.getDeletedAt().isBefore(LocalDateTime.now().plusSeconds(1)));
verify(pointService).recalculateUserPoints(historyUser);
verify(userRepo).saveAll(any());
}
@Test @Test
void finalizeLotteryNotifiesAuthor() { void finalizeLotteryNotifiesAuthor() {
PostRepository postRepo = mock(PostRepository.class); PostRepository postRepo = mock(PostRepository.class);
@@ -268,14 +185,12 @@ class PostServiceTest {
ApplicationContext context = mock(ApplicationContext.class); ApplicationContext context = mock(ApplicationContext.class);
PointService pointService = mock(PointService.class); PointService pointService = mock(PointService.class);
PostChangeLogService postChangeLogService = mock(PostChangeLogService.class); PostChangeLogService postChangeLogService = mock(PostChangeLogService.class);
PointHistoryRepository pointHistoryRepository = mock(PointHistoryRepository.class);
RedisTemplate redisTemplate = mock(RedisTemplate.class); RedisTemplate redisTemplate = mock(RedisTemplate.class);
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo, PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo, pollPostRepo, pollVoteRepo, notifService, subService, commentService, commentRepo,
reactionRepo, subRepo, notificationRepo, postReadService, reactionRepo, subRepo, notificationRepo, postReadService,
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, PublishMode.DIRECT, redisTemplate);
pointHistoryRepository, PublishMode.DIRECT, redisTemplate);
when(context.getBean(PostService.class)).thenReturn(service); when(context.getBean(PostService.class)).thenReturn(service);
User author = new User(); User author = new User();

View File

@@ -4,18 +4,7 @@ spring.datasource.username=sa
spring.datasource.password= spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.ddl-auto=create-drop
springdoc.info.title=openisle
springdoc.info.description=Test API documentation
springdoc.info.version=1.0.0
springdoc.info.scheme=Bearer
springdoc.info.header=Authorization
rabbitmq.queue.durable=true
rabbitmq.sharding.enabled=true
resend.api.key=dummy resend.api.key=dummy
resend.from.email=dummy@example.com
cos.base-url=http://test.example.com cos.base-url=http://test.example.com
cos.secret-id=dummy cos.secret-id=dummy
cos.secret-key=dummy cos.secret-key=dummy
@@ -29,7 +18,6 @@ app.upload.max-size=1048576
app.jwt.secret=TestSecret app.jwt.secret=TestSecret
app.jwt.reason-secret=TestReasonSecret app.jwt.reason-secret=TestReasonSecret
app.jwt.reset-secret=TestResetSecret app.jwt.reset-secret=TestResetSecret
app.jwt.invite-secret=TestInviteSecret
app.jwt.expiration=3600000 app.jwt.expiration=3600000
# Default publish mode for tests # Default publish mode for tests

View File

@@ -16,4 +16,4 @@ NUXT_PUBLIC_GOOGLE_CLIENT_ID=777830451304-nt8afkkap18gui4f9entcha99unal744.apps.
NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ
NUXT_PUBLIC_DISCORD_CLIENT_ID=1394985417044000779 NUXT_PUBLIC_DISCORD_CLIENT_ID=1394985417044000779
NUXT_PUBLIC_TWITTER_CLIENT_ID=ZTRTU05KSk9KTTJrTTdrVC1tc1E6MTpjaQ NUXT_PUBLIC_TWITTER_CLIENT_ID=ZTRTU05KSk9KTTJrTTdrVC1tc1E6MTpjaQ
NUXT_PUBLIC_TELEGRAM_BOT_ID=8450237135 NUXT_PUBLIC_TELEGRAM_BOT_ID=8450237135

View File

@@ -2,8 +2,6 @@
--primary-color-hover: rgb(9, 95, 105); --primary-color-hover: rgb(9, 95, 105);
--primary-color: rgb(10, 110, 120); --primary-color: rgb(10, 110, 120);
--primary-color-disabled: rgba(93, 152, 156, 0.5); --primary-color-disabled: rgba(93, 152, 156, 0.5);
--secondary-color: rgb(255, 255, 255);
--secondary-color-hover: rgba(10, 111, 120, 0.184);
--new-post-icon-color: rgba(10, 111, 120, 0.598); --new-post-icon-color: rgba(10, 111, 120, 0.598);
--header-height: 60px; --header-height: 60px;
--header-background-color: white; --header-background-color: white;
@@ -358,7 +356,7 @@ body {
} }
.d2h-file-name { .d2h-file-name {
font-size: 14px !important; font-size: 12px !important;
} }
.d2h-file-header { .d2h-file-header {
@@ -373,14 +371,14 @@ body {
padding-left: 10px !important; padding-left: 10px !important;
} }
/* .d2h-diff-table { .d2h-diff-table {
font-size: 6px !important; font-size: 6px !important;
} }
.d2h-code-line ins { .d2h-code-line ins {
height: 100%; height: 100%;
font-size: 13px !important; font-size: 13px !important;
} */ }
/* .d2h-code-line { /* .d2h-code-line {
height: 12px; height: 12px;

View File

@@ -35,7 +35,6 @@ const isImageIcon = (icon) => {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
gap: 10px; gap: 10px;
min-height: 25px;
} }
.article-info-item { .article-info-item {
@@ -64,9 +63,5 @@ const isImageIcon = (icon) => {
.article-info-item { .article-info-item {
font-size: 10px; font-size: 10px;
} }
.article-category-container {
min-height: 20px;
}
} }
</style> </style>

View File

@@ -44,7 +44,6 @@ const isImageIcon = (icon) => {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
gap: 10px; gap: 10px;
min-height: 25px;
} }
.article-info-item { .article-info-item {
@@ -73,9 +72,5 @@ const isImageIcon = (icon) => {
.article-info-item { .article-info-item {
font-size: 10px; font-size: 10px;
} }
.article-tags-container {
min-height: 20px;
}
} }
</style> </style>

View File

@@ -342,7 +342,7 @@ const copyCommentLink = () => {
const handleContentClick = (e) => { const handleContentClick = (e) => {
handleMarkdownClick(e) handleMarkdownClick(e)
if (e.target.tagName === 'IMG' && !e.target.classList.contains('emoji')) { if (e.target.tagName === 'IMG') {
const container = e.target.parentNode const container = e.target.parentNode
const imgs = [...container.querySelectorAll('img')].map((i) => i.src) const imgs = [...container.querySelectorAll('img')].map((i) => i.src)
lightboxImgs.value = imgs lightboxImgs.value = imgs

View File

@@ -5,10 +5,7 @@
</div> </div>
<div class="message-bottom-container"> <div class="message-bottom-container">
<div class="message-submit" :class="{ disabled: isDisabled }" @click="submit"> <div class="message-submit" :class="{ disabled: isDisabled }" @click="submit">
<template v-if="!loading"> <template v-if="!loading"> 发送 </template>
发送
<span class="shortcut-icon" v-if="!isMobile"> {{ isMac ? '' : 'Ctrl' }} </span>
</template>
<template v-else> <loading-four /> 发送中... </template> <template v-else> <loading-four /> 发送中... </template>
</div> </div>
</div> </div>
@@ -24,8 +21,6 @@ import {
getEditorTheme as getEditorThemeUtil, getEditorTheme as getEditorThemeUtil,
getPreviewTheme as getPreviewThemeUtil, getPreviewTheme as getPreviewThemeUtil,
} from '~/utils/vditor' } from '~/utils/vditor'
import { useIsMobile } from '~/utils/screen'
import { isMac } from '~/utils/device'
import '~/assets/global.css' import '~/assets/global.css'
export default { export default {
@@ -49,7 +44,6 @@ export default {
const vditorInstance = ref(null) const vditorInstance = ref(null)
const text = ref('') const text = ref('')
const editorId = ref(props.editorId) const editorId = ref(props.editorId)
const isMobile = useIsMobile()
if (!editorId.value) { if (!editorId.value) {
editorId.value = 'editor-' + useId() editorId.value = 'editor-' + useId()
} }
@@ -90,28 +84,6 @@ export default {
applyTheme() applyTheme()
}, },
}) })
// 不是手机的情况下不添加快捷键
if (!isMobile.value) {
// 添加快捷键监听 (Ctrl+Enter 或 Cmd+Enter)
const handleKeydown = (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault()
submit()
}
}
const el = document.getElementById(editorId.value)
if (el) {
el.addEventListener('keydown', handleKeydown)
}
onUnmounted(() => {
if (el) {
el.removeEventListener('keydown', handleKeydown)
}
})
}
}) })
onUnmounted(() => { onUnmounted(() => {
@@ -149,7 +121,7 @@ export default {
}, },
) )
return { submit, isDisabled, editorId, isMac, isMobile } return { submit, isDisabled, editorId }
}, },
} }
</script> </script>
@@ -196,17 +168,4 @@ export default {
.message-submit:not(.disabled):hover { .message-submit:not(.disabled):hover {
background-color: var(--primary-color-hover); background-color: var(--primary-color-hover);
} }
/** 评论按钮快捷键样式 */
.shortcut-icon {
padding: 2px 6px;
border-radius: 6px;
font-size: 12px;
font-weight: 500;
line-height: 1.2;
background-color: rgba(0, 0, 0, 0.25);
}
.comment-submit.disabled .shortcut-icon {
background-color: rgba(0, 0, 0, 0);
}
</style> </style>

View File

@@ -107,52 +107,14 @@ const likeCount = computed(() => counts.value['LIKE'] || 0)
const userReacted = (type) => const userReacted = (type) =>
reactions.value.some((r) => r.type === type && r.user === authState.username) reactions.value.some((r) => r.type === type && r.user === authState.username)
const baseReactionOrder = computed(() => {
if (reactionTypes.value.length) return [...reactionTypes.value]
const order = []
const seen = new Set()
for (const reaction of reactions.value) {
if (!seen.has(reaction.type)) {
seen.add(reaction.type)
order.push(reaction.type)
}
}
return order
})
const sortedReactionTypes = computed(() => {
const baseOrder = [...baseReactionOrder.value]
for (const type of Object.keys(counts.value)) {
if (!baseOrder.includes(type)) baseOrder.push(type)
}
const withMetadata = baseOrder.map((type, index) => ({
type,
count: counts.value[type] || 0,
index,
}))
const nonZero = withMetadata
.filter((item) => item.count > 0)
.sort((a, b) => {
if (b.count !== a.count) return b.count - a.count
return a.index - b.index
})
const zero = withMetadata.filter((item) => item.count === 0)
return [...nonZero, ...zero].map((item) => item.type)
})
const displayedReactions = computed(() => { const displayedReactions = computed(() => {
return sortedReactionTypes.value return Object.entries(counts.value)
.filter((type) => counts.value[type] > 0) .sort((a, b) => b[1] - a[1])
.slice(0, 3) .slice(0, 3)
.map((type) => ({ type })) .map(([type]) => ({ type }))
}) })
const panelTypes = computed(() => sortedReactionTypes.value.filter((t) => t !== 'LIKE')) const panelTypes = computed(() => reactionTypes.value.filter((t) => t !== 'LIKE'))
const panelVisible = ref(false) const panelVisible = ref(false)
let hideTimer = null let hideTimer = null

View File

@@ -1,15 +1,22 @@
/** /**
* 文件上传配置 * 文件上传配置 - 简化版
* 专注于 WebCodecs + MP4Box.js 视频压缩,支持 Chrome/Safari
*/ */
// 声明全局变量以避免 TypeScript 错误
/* global useRuntimeConfig */
export const UPLOAD_CONFIG = { export const UPLOAD_CONFIG = {
// 视频文件配置
VIDEO: { VIDEO: {
// 文件大小限制 (字节) MAX_SIZE: 20 * 1024 * 1024, // 20mb
MAX_SIZE: 20 * 1024 * 1024, TARGET_SIZE: 5 * 1024 * 1024, // 5mb
// 支持的输入格式 // 支持的输入格式
SUPPORTED_FORMATS: ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv'], SUPPORTED_FORMATS: ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv'],
// 输出格式 - MP4 (兼容性最好)
OUTPUT_FORMAT: 'mp4',
OUTPUT_CODEC: 'h264',
}, },
// 图片文件配置 // 图片文件配置

View File

@@ -1,5 +1,4 @@
import { defineNuxtConfig } from 'nuxt/config' import { defineNuxtConfig } from 'nuxt/config'
export default defineNuxtConfig({ export default defineNuxtConfig({
devServer: { devServer: {
host: '0.0.0.0', host: '0.0.0.0',
@@ -97,7 +96,26 @@ export default defineNuxtConfig({
}, },
}, },
vite: { vite: {
optimizeDeps: {}, build: {
build: {}, // increase warning limit and split large libraries into separate chunks
// chunkSizeWarningLimit: 1024,
// rollupOptions: {
// output: {
// manualChunks(id) {
// if (id.includes('node_modules')) {
// if (id.includes('vditor')) {
// return 'vditor'
// }
// if (id.includes('echarts')) {
// return 'echarts'
// }
// if (id.includes('highlight.js')) {
// return 'highlight'
// }
// }
// },
// },
// },
},
}, },
}) })

View File

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,7 @@
"ldrs": "^1.0.0", "ldrs": "^1.0.0",
"markdown-it": "^14.1.0", "markdown-it": "^14.1.0",
"mermaid": "^10.9.4", "mermaid": "^10.9.4",
"mp4box": "^2.1.1",
"nanoid": "^5.1.5", "nanoid": "^5.1.5",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",
"nuxt": "latest", "nuxt": "latest",

View File

@@ -594,6 +594,13 @@ const sanitizeDescription = (text) => stripMarkdown(text)
margin-bottom: 10px; margin-bottom: 10px;
} }
.article-tags-container {
display: flex;
flex-direction: row;
align-items: center;
gap: 10px;
}
.article-tag-item { .article-tag-item {
display: flex; display: flex;
flex-direction: row; flex-direction: row;

View File

@@ -20,7 +20,7 @@
</div> </div>
</div> </div>
<div class="messages-list" ref="messagesListEl"> <div class="messages-list" ref="messagesListEl" @click="handleContentClick">
<div v-if="loading" class="loading-container"> <div v-if="loading" class="loading-container">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch> <l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div> </div>
@@ -50,11 +50,7 @@
<div class="reply-content" v-html="renderMarkdown(item.replyTo.content)"></div> <div class="reply-content" v-html="renderMarkdown(item.replyTo.content)"></div>
</div> </div>
<div class="message-content"> <div class="message-content">
<div <div class="info-content-text" v-html="renderMarkdown(item.content)"></div>
class="info-content-text"
v-html="renderMarkdown(item.content)"
@click="handleContentClick"
></div>
</div> </div>
<ReactionsGroup <ReactionsGroup
:model-value="item.reactions" :model-value="item.reactions"
@@ -467,7 +463,7 @@ function minimize() {
function handleContentClick(e) { function handleContentClick(e) {
handleMarkdownClick(e) handleMarkdownClick(e)
if (e.target.tagName === 'IMG' && !e.target.classList.contains('emoji')) { if (e.target.tagName === 'IMG') {
const container = e.target.parentNode const container = e.target.parentNode
const imgs = [...container.querySelectorAll('img')].map((i) => i.src) const imgs = [...container.querySelectorAll('img')].map((i) => i.src)
lightboxImgs.value = imgs lightboxImgs.value = imgs

View File

@@ -122,8 +122,7 @@
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch> <l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div> </div>
<div v-else class="comments-container"> <div v-else class="comments-container">
<BasePlaceholder v-if="timelineItems.length === 0" text="暂无评论" icon="inbox" /> <BaseTimeline :items="timelineItems">
<BaseTimeline v-else :items="timelineItems">
<template #item="{ item }"> <template #item="{ item }">
<CommentItem <CommentItem
v-if="item.kind === 'comment'" v-if="item.kind === 'comment'"
@@ -185,7 +184,6 @@ import { useRoute } from 'vue-router'
import CommentItem from '~/components/CommentItem.vue' import CommentItem from '~/components/CommentItem.vue'
import CommentEditor from '~/components/CommentEditor.vue' import CommentEditor from '~/components/CommentEditor.vue'
import BaseTimeline from '~/components/BaseTimeline.vue' import BaseTimeline from '~/components/BaseTimeline.vue'
import BasePlaceholder from '~/components/BasePlaceholder.vue'
import PostChangeLogItem from '~/components/PostChangeLogItem.vue' import PostChangeLogItem from '~/components/PostChangeLogItem.vue'
import ArticleTags from '~/components/ArticleTags.vue' import ArticleTags from '~/components/ArticleTags.vue'
import ArticleCategory from '~/components/ArticleCategory.vue' import ArticleCategory from '~/components/ArticleCategory.vue'
@@ -322,7 +320,6 @@ const mapComment = (
level = 0, level = 0,
) => ({ ) => ({
id: c.id, id: c.id,
kind: 'comment',
userName: c.author.username, userName: c.author.username,
medal: c.author.displayMedal, medal: c.author.displayMedal,
userId: c.author.id, userId: c.author.id,
@@ -377,7 +374,6 @@ const changeLogIcon = (l) => {
const mapChangeLog = (l) => ({ const mapChangeLog = (l) => ({
id: l.id, id: l.id,
kind: 'log',
username: l.username, username: l.username,
userAvatar: l.userAvatar, userAvatar: l.userAvatar,
type: l.type, type: l.type,
@@ -438,7 +434,7 @@ const removeCommentFromList = (id, list) => {
const handleContentClick = (e) => { const handleContentClick = (e) => {
handleMarkdownClick(e) handleMarkdownClick(e)
if (e.target.tagName === 'IMG' && !e.target.classList.contains('emoji')) { if (e.target.tagName === 'IMG') {
const container = e.target.parentNode const container = e.target.parentNode
const imgs = [...container.querySelectorAll('img')].map((i) => i.src) const imgs = [...container.querySelectorAll('img')].map((i) => i.src)
lightboxImgs.value = imgs lightboxImgs.value = imgs
@@ -449,7 +445,7 @@ const handleContentClick = (e) => {
const onCommentDeleted = (id) => { const onCommentDeleted = (id) => {
removeCommentFromList(Number(id), comments.value) removeCommentFromList(Number(id), comments.value)
fetchTimeline() fetchComments()
} }
const { const {
@@ -561,7 +557,7 @@ const postComment = async (parentUserName, text, clear) => {
if (res.ok) { if (res.ok) {
const data = await res.json() const data = await res.json()
console.debug('Post comment response data', data) console.debug('Post comment response data', data)
await fetchTimeline() await fetchComments()
clear() clear()
if (data.reward && data.reward > 0) { if (data.reward && data.reward > 0) {
toast.success(`评论成功,获得 ${data.reward} 经验值`) toast.success(`评论成功,获得 ${data.reward} 经验值`)
@@ -616,7 +612,7 @@ const approvePost = async () => {
status.value = 'PUBLISHED' status.value = 'PUBLISHED'
toast.success('已通过审核') toast.success('已通过审核')
await refreshPost() await refreshPost()
await fetchTimeline() await fetchChangeLogs()
} else { } else {
toast.error('操作失败') toast.error('操作失败')
} }
@@ -632,7 +628,7 @@ const pinPost = async () => {
if (res.ok) { if (res.ok) {
toast.success('已置顶') toast.success('已置顶')
await refreshPost() await refreshPost()
await fetchTimeline() await fetchChangeLogs()
} else { } else {
toast.error('操作失败') toast.error('操作失败')
} }
@@ -648,7 +644,7 @@ const unpinPost = async () => {
if (res.ok) { if (res.ok) {
toast.success('已取消置顶') toast.success('已取消置顶')
await refreshPost() await refreshPost()
await fetchTimeline() await fetchChangeLogs()
} else { } else {
toast.error('操作失败') toast.error('操作失败')
} }
@@ -664,7 +660,7 @@ const excludeRss = async () => {
if (res.ok) { if (res.ok) {
rssExcluded.value = true rssExcluded.value = true
toast.success('已标记为rss不推荐') toast.success('已标记为rss不推荐')
await fetchTimeline() await fetchChangeLogs()
} else { } else {
toast.error('操作失败') toast.error('操作失败')
} }
@@ -680,8 +676,7 @@ const includeRss = async () => {
if (res.ok) { if (res.ok) {
rssExcluded.value = false rssExcluded.value = false
toast.success('已标记为rss推荐') toast.success('已标记为rss推荐')
await refreshPost() await fetchChangeLogs()
await fetchTimeline()
} else { } else {
toast.error('操作失败') toast.error('操作失败')
} }
@@ -698,7 +693,7 @@ const closePost = async () => {
closed.value = true closed.value = true
toast.success('已关闭') toast.success('已关闭')
await refreshPost() await refreshPost()
await fetchTimeline() await fetchChangeLogs()
} else { } else {
toast.error('操作失败') toast.error('操作失败')
} }
@@ -715,7 +710,7 @@ const reopenPost = async () => {
closed.value = false closed.value = false
toast.success('已重新打开') toast.success('已重新打开')
await refreshPost() await refreshPost()
await fetchTimeline() await fetchChangeLogs()
} else { } else {
toast.error('操作失败') toast.error('操作失败')
} }
@@ -760,7 +755,7 @@ const rejectPost = async () => {
status.value = 'REJECTED' status.value = 'REJECTED'
toast.success('已驳回') toast.success('已驳回')
await refreshPost() await refreshPost()
await fetchTimeline() await fetchChangeLogs()
} else { } else {
toast.error('操作失败') toast.error('操作失败')
} }
@@ -792,9 +787,9 @@ const fetchCommentSorts = () => {
]) ])
} }
const fetchCommentsAndChangeLog = async () => { const fetchComments = async () => {
isFetchingComments.value = true isFetchingComments.value = true
console.info('Fetching comments and chang log', { postId, sort: commentSort.value }) console.debug('Fetching comments', { postId, sort: commentSort.value })
try { try {
const token = getToken() const token = getToken()
const res = await fetch( const res = await fetch(
@@ -803,32 +798,11 @@ const fetchCommentsAndChangeLog = async () => {
headers: { Authorization: token ? `Bearer ${token}` : '' }, headers: { Authorization: token ? `Bearer ${token}` : '' },
}, },
) )
console.info('Fetch comments response status', res.status) console.debug('Fetch comments response status', res.status)
if (res.ok) { if (res.ok) {
const data = await res.json() const data = await res.json()
console.info('Fetched comments data', data) console.debug('Fetched comments count', data.length)
comments.value = data.map(mapComment)
const commentList = []
const changeLogList = []
// 时间线列表,包含评论和日志
const newTimelineItemList = []
for (const item of data) {
const mappedPayload =
item.kind === 'comment' ? mapComment(item.payload) : mapChangeLog(item.payload)
newTimelineItemList.push(mappedPayload)
if (item.kind === 'comment') {
commentList.push(mappedPayload)
} else {
changeLogList.push(mappedPayload)
}
}
comments.value = commentList
changeLogs.value = changeLogList
timelineItems.value = newTimelineItemList
isFetchingComments.value = false isFetchingComments.value = false
await nextTick() await nextTick()
gatherPostItems() gatherPostItems()
@@ -840,8 +814,37 @@ const fetchCommentsAndChangeLog = async () => {
} }
} }
const fetchChangeLogs = async () => {
try {
const res = await fetch(`${API_BASE_URL}/api/posts/${postId}/change-logs`)
if (res.ok) {
const data = await res.json()
changeLogs.value = data.map(mapChangeLog)
await nextTick()
gatherPostItems()
}
} catch (e) {
console.debug('Fetch change logs error', e)
}
}
//
// todo(tim): fetchComments, fetchChangeLogs 整合到一个请求,并且取消前端排序
//
const fetchTimeline = async () => { const fetchTimeline = async () => {
await fetchCommentsAndChangeLog() await Promise.all([fetchComments(), fetchChangeLogs()])
const cs = comments.value.map((c) => ({ ...c, kind: 'comment' }))
const ls = changeLogs.value.map((l) => ({ ...l, kind: 'log' }))
if (commentSort.value === 'NEWEST') {
timelineItems.value = [...cs, ...ls].sort(
(a, b) => new Date(b.createdAt) - new Date(a.createdAt),
)
} else {
timelineItems.value = [...cs, ...ls].sort(
(a, b) => new Date(a.createdAt) - new Date(b.createdAt),
)
}
} }
watch(commentSort, async () => { watch(commentSort, async () => {

View File

@@ -29,7 +29,7 @@
<reduce-user /> <reduce-user />
取消关注 取消关注
</div> </div>
<div v-if="!isMine" class="profile-page-header-send-mail-button" @click="sendMessage"> <div v-if="!isMine" class="profile-page-header-subscribe-button" @click="sendMessage">
<message-one /> <message-one />
发私信 发私信
</div> </div>
@@ -703,26 +703,6 @@ watch(selectedTab, async (val) => {
cursor: pointer; cursor: pointer;
} }
.profile-page-header-send-mail-button {
display: flex;
flex-direction: row;
gap: 5px;
align-items: center;
font-size: 14px;
border-radius: 8px;
padding: 5px 10px;
color: var(--primary-color);
border: 1px solid var(--primary-color);
margin-top: 15px;
width: fit-content;
cursor: pointer;
}
.profile-page-header-unsubscribe-button:hover,
.profile-page-header-send-mail-button:hover {
background-color: var(--secondary-color-hover);
}
.profile-level-container { .profile-level-container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@@ -1,28 +0,0 @@
export const isClient = typeof window !== 'undefined' && typeof document !== 'undefined'
export const isMac = getIsMac()
function getIsMac() {
if (!isClient) {
return false
}
try {
// 优先使用现代浏览器的 navigator.userAgentData API
if (navigator.userAgentData && navigator.userAgentData.platform) {
return navigator.userAgentData.platform === 'macOS'
}
// 降级到传统的 User-Agent 检测
if (navigator.userAgent) {
return /Mac|iPhone|iPad|iPod/i.test(navigator.userAgent)
}
// 默认返回false
return false
} catch (error) {
// 异常处理,记录错误并返回默认值
console.warn('检测Mac设备时发生错误:', error)
return false
}
}

View File

@@ -3,7 +3,8 @@ import { getToken, authState } from './auth'
import { searchUsers, fetchFollowings, fetchAdmins } from './user' import { searchUsers, fetchFollowings, fetchAdmins } from './user'
import { tiebaEmoji } from './tiebaEmoji' import { tiebaEmoji } from './tiebaEmoji'
import vditorPostCitation from './vditorPostCitation.js' import vditorPostCitation from './vditorPostCitation.js'
import { checkFileSize, formatFileSize } from './videoCompressor.js' import { checkFileSize, formatFileSize, compressVideo, VIDEO_CONFIG } from './videoCompressor.js'
import { UPLOAD_CONFIG } from '../config/uploadConfig.js'
export function getEditorTheme() { export function getEditorTheme() {
return document.documentElement.dataset.theme === 'dark' ? 'dark' : 'classic' return document.documentElement.dataset.theme === 'dark' ? 'dark' : 'classic'
@@ -94,6 +95,7 @@ export function createVditor(editorId, options = {}) {
const file = files[0] const file = files[0]
const ext = file.name.split('.').pop().toLowerCase() const ext = file.name.split('.').pop().toLowerCase()
const videoExts = ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv'] const videoExts = ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv']
const isVideo = videoExts.includes(ext)
// 检查文件大小 // 检查文件大小
const sizeCheck = checkFileSize(file) const sizeCheck = checkFileSize(file)
@@ -111,10 +113,61 @@ export function createVditor(editorId, options = {}) {
return '文件过大' return '文件过大'
} }
let processedFile = file
// 如果是视频文件且需要压缩
if (isVideo && sizeCheck.needsCompression) {
try {
vditor.tip('视频压缩中...', 0)
vditor.disabled()
// 使用 WebCodecs 压缩视频
processedFile = await compressVideo(file, (progress) => {
const messages = {
initializing: '初始化编码器',
preparing: '准备压缩',
analyzing: '分析视频',
compressing: '压缩中',
finalizing: '完成压缩',
completed: '压缩完成',
}
const message = messages[progress.stage] || progress.stage
vditor.tip(`${message} ${progress.progress}%`, 0)
})
const originalSize = formatFileSize(file.size)
const compressedSize = formatFileSize(processedFile.size)
const savings = Math.round((1 - processedFile.size / file.size) * 100)
vditor.tip(`压缩完成!${originalSize}${compressedSize} (节省 ${savings}%)`, 2000)
// 压缩成功但仍然超过最大限制,则阻止上传
if (processedFile.size > VIDEO_CONFIG.MAX_SIZE) {
vditor.tip(
`压缩后仍超过限制 (${formatFileSize(VIDEO_CONFIG.MAX_SIZE)}). 请降低分辨率或码率后再上传。`,
4000,
)
vditor.enable()
return '压缩后仍超过大小限制'
}
} catch (error) {
// 压缩失败时,如果原文件超过最大限制,则阻止上传
if (file.size > VIDEO_CONFIG.MAX_SIZE) {
vditor.tip(
`视频压缩失败,且文件超过限制 (${formatFileSize(VIDEO_CONFIG.MAX_SIZE)}). 请先压缩后再上传。`,
4000,
)
vditor.enable()
return '视频压缩失败且文件过大'
}
vditor.tip('视频压缩失败,将尝试上传原文件', 3000)
processedFile = file
}
}
vditor.tip('文件上传中', 0) vditor.tip('文件上传中', 0)
vditor.disabled() vditor.disabled()
const res = await fetch( const res = await fetch(
`${API_BASE_URL}/api/upload/presign?filename=${encodeURIComponent(file.name)}`, `${API_BASE_URL}/api/upload/presign?filename=${encodeURIComponent(processedFile.name)}`,
{ headers: { Authorization: `Bearer ${getToken()}` } }, { headers: { Authorization: `Bearer ${getToken()}` } },
) )
if (!res.ok) { if (!res.ok) {
@@ -123,7 +176,7 @@ export function createVditor(editorId, options = {}) {
return '获取上传地址失败' return '获取上传地址失败'
} }
const info = await res.json() const info = await res.json()
const put = await fetch(info.uploadUrl, { method: 'PUT', body: file }) const put = await fetch(info.uploadUrl, { method: 'PUT', body: processedFile })
if (!put.ok) { if (!put.ok) {
vditor.enable() vditor.enable()
vditor.tip('上传失败') vditor.tip('上传失败')

View File

@@ -1,8 +1,10 @@
/** /**
* 视频上传工具 * 基于 WebCodecs + MP4Box.js 的视频压缩工具
* 专为现代浏览器 (Chrome/Safari) 优化
*/ */
import { UPLOAD_CONFIG } from '../config/uploadConfig.js' import { UPLOAD_CONFIG } from '../config/uploadConfig.js'
import { compressVideoWithWebCodecs, isWebCodecSupported } from './webcodecVideoCompressor.js'
// 导出配置供外部使用 // 导出配置供外部使用
export const VIDEO_CONFIG = UPLOAD_CONFIG.VIDEO export const VIDEO_CONFIG = UPLOAD_CONFIG.VIDEO
@@ -15,6 +17,7 @@ export function checkFileSize(file) {
isValid: file.size <= VIDEO_CONFIG.MAX_SIZE, isValid: file.size <= VIDEO_CONFIG.MAX_SIZE,
actualSize: file.size, actualSize: file.size,
maxSize: VIDEO_CONFIG.MAX_SIZE, maxSize: VIDEO_CONFIG.MAX_SIZE,
needsCompression: file.size > VIDEO_CONFIG.TARGET_SIZE,
} }
} }
@@ -28,3 +31,42 @@ export function formatFileSize(bytes) {
const i = Math.floor(Math.log(bytes) / Math.log(k)) const i = Math.floor(Math.log(bytes) / Math.log(k))
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i] return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
} }
/**
* 压缩视频文件 - 使用 WebCodecs
*/
export async function compressVideo(file, onProgress = () => {}) {
// 检查是否需要压缩
const sizeCheck = checkFileSize(file)
if (!sizeCheck.needsCompression) {
onProgress({ stage: 'completed', progress: 100 })
return file
}
// 检查 WebCodecs 支持
if (!isWebCodecSupported()) {
throw new Error('当前浏览器不支持视频压缩功能,请使用支持 WebCodecs 的浏览器')
}
try {
return await compressVideoWithWebCodecs(file, { onProgress })
} catch (error) {
console.error('WebCodecs 压缩失败:', error)
throw new Error(`视频压缩失败: ${error.message}`)
}
}
/**
* 预加载 WebCodecs可选的性能优化
*/
export async function preloadVideoCompressor() {
try {
if (!isWebCodecSupported()) {
throw new Error('当前浏览器不支持 WebCodecs')
}
return { success: true, message: 'WebCodecs 已就绪' }
} catch (error) {
console.warn('WebCodecs 检测失败:', error)
return { success: false, error: error.message }
}
}

View File

@@ -0,0 +1,98 @@
import MP4Box from 'mp4box'
// 检查 WebCodecs 支持
export function isWebCodecSupported() {
return typeof window !== 'undefined' && typeof window.VideoEncoder !== 'undefined'
}
// 使用 WebCodecs + MP4Box.js 压缩视频
export async function compressVideoWithWebCodecs(file, opts = {}) {
const { onProgress = () => {}, width = 720, bitrate = 1_000_000 } = opts
if (!isWebCodecSupported()) {
throw new Error('当前浏览器不支持 WebCodecs')
}
onProgress({ stage: 'initializing', progress: 0 })
// 加载原始视频
const url = URL.createObjectURL(file)
const video = document.createElement('video')
video.src = url
video.muted = true
await video.play().catch(() => {})
video.pause()
await new Promise((resolve) => {
if (video.readyState >= 2) resolve()
else video.onloadedmetadata = () => resolve()
})
const targetWidth = width
const targetHeight = Math.round((video.videoHeight / video.videoWidth) * width)
const canvas = document.createElement('canvas')
canvas.width = targetWidth
canvas.height = targetHeight
const ctx = canvas.getContext('2d')
const chunks = []
const encoder = new VideoEncoder({
output: (chunk) => {
chunks.push(chunk)
},
error: (e) => {
throw e
},
})
encoder.configure({
codec: 'avc1.42001E',
width: targetWidth,
height: targetHeight,
bitrate,
framerate: 30,
})
const duration = video.duration
const frameCount = Math.floor(duration * 30)
for (let i = 0; i < frameCount; i++) {
video.currentTime = i / 30
await new Promise((res) => (video.onseeked = res))
ctx.drawImage(video, 0, 0, targetWidth, targetHeight)
const bitmap = await createImageBitmap(canvas)
const frame = new VideoFrame(bitmap, { timestamp: (i / 30) * 1000000 })
encoder.encode(frame)
frame.close()
bitmap.close()
onProgress({ stage: 'compressing', progress: Math.round(((i + 1) / frameCount) * 80) })
}
await encoder.flush()
onProgress({ stage: 'finalizing', progress: 90 })
const mp4box = MP4Box.createFile()
const track = mp4box.addTrack({
timescale: 1000,
width: targetWidth,
height: targetHeight,
})
let dts = 0
chunks.forEach((chunk) => {
const data = new Uint8Array(chunk.byteLength)
chunk.copyTo(data)
mp4box.addSample(track, data.buffer, {
duration: chunk.duration ? chunk.duration / 1000 : 33,
dts,
cts: dts,
is_sync: chunk.type === 'key',
})
dts += chunk.duration ? chunk.duration / 1000 : 33
})
const arrayBuffer = mp4box.flush()
const outputFile = new File([arrayBuffer], file.name.replace(/\.[^.]+$/, '.mp4'), {
type: 'video/mp4',
})
onProgress({ stage: 'completed', progress: 100 })
URL.revokeObjectURL(url)
return outputFile
}

114
package-lock.json generated
View File

@@ -11,54 +11,9 @@
"devDependencies": { "devDependencies": {
"husky": "^9.1.7", "husky": "^9.1.7",
"lint-staged": "^16.1.5", "lint-staged": "^16.1.5",
"prettier": "^3.6.2", "prettier": "^3.6.2"
"prettier-plugin-java": "^2.6.3"
} }
}, },
"node_modules/@chevrotain/cst-dts-gen": {
"version": "11.0.3",
"resolved": "https://registry.npmjs.org/@chevrotain/cst-dts-gen/-/cst-dts-gen-11.0.3.tgz",
"integrity": "sha512-BvIKpRLeS/8UbfxXxgC33xOumsacaeCKAjAeLyOn7Pcp95HiRbrpl14S+9vaZLolnbssPIUuiUd8IvgkRyt6NQ==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"@chevrotain/gast": "11.0.3",
"@chevrotain/types": "11.0.3",
"lodash-es": "4.17.21"
}
},
"node_modules/@chevrotain/gast": {
"version": "11.0.3",
"resolved": "https://registry.npmjs.org/@chevrotain/gast/-/gast-11.0.3.tgz",
"integrity": "sha512-+qNfcoNk70PyS/uxmj3li5NiECO+2YKZZQMbmjTqRI3Qchu8Hig/Q9vgkHpI3alNjr7M+a2St5pw5w5F6NL5/Q==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"@chevrotain/types": "11.0.3",
"lodash-es": "4.17.21"
}
},
"node_modules/@chevrotain/regexp-to-ast": {
"version": "11.0.3",
"resolved": "https://registry.npmjs.org/@chevrotain/regexp-to-ast/-/regexp-to-ast-11.0.3.tgz",
"integrity": "sha512-1fMHaBZxLFvWI067AVbGJav1eRY7N8DDvYCTwGBiE/ytKBgP8azTdgyrKyWZ9Mfh09eHWb5PgTSO8wi7U824RA==",
"dev": true,
"license": "Apache-2.0"
},
"node_modules/@chevrotain/types": {
"version": "11.0.3",
"resolved": "https://registry.npmjs.org/@chevrotain/types/-/types-11.0.3.tgz",
"integrity": "sha512-gsiM3G8b58kZC2HaWR50gu6Y1440cHiJ+i3JUvcp/35JchYejb2+5MVeJK0iKThYpAa/P2PYFV4hoi44HD+aHQ==",
"dev": true,
"license": "Apache-2.0"
},
"node_modules/@chevrotain/utils": {
"version": "11.0.3",
"resolved": "https://registry.npmjs.org/@chevrotain/utils/-/utils-11.0.3.tgz",
"integrity": "sha512-YslZMgtJUyuMbZ+aKvfF3x1f5liK4mWNxghFRv7jqRR9C3R3fAOGTTKvxXDa2Y1s9zSbcpuO0cAxDYsc9SrXoQ==",
"dev": true,
"license": "Apache-2.0"
},
"node_modules/ansi-escapes": { "node_modules/ansi-escapes": {
"version": "7.0.0", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.0.0.tgz", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.0.0.tgz",
@@ -127,34 +82,6 @@
"url": "https://github.com/chalk/chalk?sponsor=1" "url": "https://github.com/chalk/chalk?sponsor=1"
} }
}, },
"node_modules/chevrotain": {
"version": "11.0.3",
"resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-11.0.3.tgz",
"integrity": "sha512-ci2iJH6LeIkvP9eJW6gpueU8cnZhv85ELY8w8WiFtNjMHA5ad6pQLaJo9mEly/9qUyCpvqX8/POVUTf18/HFdw==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"@chevrotain/cst-dts-gen": "11.0.3",
"@chevrotain/gast": "11.0.3",
"@chevrotain/regexp-to-ast": "11.0.3",
"@chevrotain/types": "11.0.3",
"@chevrotain/utils": "11.0.3",
"lodash-es": "4.17.21"
}
},
"node_modules/chevrotain-allstar": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/chevrotain-allstar/-/chevrotain-allstar-0.3.1.tgz",
"integrity": "sha512-b7g+y9A0v4mxCW1qUhf3BSVPg+/NvGErk/dOkrDaHA0nQIQGAtrOjlX//9OQtRlSCy+x9rfB5N8yC71lH1nvMw==",
"dev": true,
"license": "MIT",
"dependencies": {
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"chevrotain": "^11.0.0"
}
},
"node_modules/cli-cursor": { "node_modules/cli-cursor": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-5.0.0.tgz", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-5.0.0.tgz",
@@ -315,18 +242,6 @@
"node": ">=0.12.0" "node": ">=0.12.0"
} }
}, },
"node_modules/java-parser": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/java-parser/-/java-parser-3.0.1.tgz",
"integrity": "sha512-sDIR7u9b7O2JViNUxiZRhnRz7URII/eE7g2B+BmGxDeS6Ex3OYAcCyz5oh0H4LQ+hL/BS8OJTz8apMy9xtGmrQ==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"chevrotain": "11.0.3",
"chevrotain-allstar": "0.3.1",
"lodash": "4.17.21"
}
},
"node_modules/lilconfig": { "node_modules/lilconfig": {
"version": "3.1.3", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz",
@@ -386,20 +301,6 @@
"node": ">=20.0.0" "node": ">=20.0.0"
} }
}, },
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true,
"license": "MIT"
},
"node_modules/lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
"dev": true,
"license": "MIT"
},
"node_modules/log-update": { "node_modules/log-update": {
"version": "6.1.0", "version": "6.1.0",
"resolved": "https://registry.npmjs.org/log-update/-/log-update-6.1.0.tgz", "resolved": "https://registry.npmjs.org/log-update/-/log-update-6.1.0.tgz",
@@ -558,19 +459,6 @@
"url": "https://github.com/prettier/prettier?sponsor=1" "url": "https://github.com/prettier/prettier?sponsor=1"
} }
}, },
"node_modules/prettier-plugin-java": {
"version": "2.7.5",
"resolved": "https://registry.npmjs.org/prettier-plugin-java/-/prettier-plugin-java-2.7.5.tgz",
"integrity": "sha512-LH5PKX+cjKOcjnnLXn3/cT8u7vxXxm68r5zsBPI3QQfkfyA/Sx8TTnhbwZdqwQXca431RquBG2ZtmyqmBwBKEw==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"java-parser": "3.0.1"
},
"peerDependencies": {
"prettier": "^3.0.0"
}
},
"node_modules/restore-cursor": { "node_modules/restore-cursor": {
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-5.1.0.tgz", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-5.1.0.tgz",

View File

@@ -20,11 +20,9 @@
"devDependencies": { "devDependencies": {
"husky": "^9.1.7", "husky": "^9.1.7",
"lint-staged": "^16.1.5", "lint-staged": "^16.1.5",
"prettier": "^3.6.2", "prettier": "^3.6.2"
"prettier-plugin-java": "^2.6.3"
}, },
"lint-staged": { "lint-staged": {
"frontend_nuxt/**/*": "prettier --write --cache --ignore-unknown", "frontend_nuxt/**/*": "prettier --write --cache --ignore-unknown"
"backend/src/**/*.java": "prettier --write --cache --ignore-unknown"
} }
} }