mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-06 23:21:16 +08:00
Compare commits
50 Commits
codex/add-
...
codex/fix-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afa0c7fb8f | ||
|
|
1852f87341 | ||
|
|
7010e8a058 | ||
|
|
38ee37d5be | ||
|
|
e398d8e989 | ||
|
|
85e77c265e | ||
|
|
8abdc73497 | ||
|
|
747d9c07d1 | ||
|
|
09cefbedbf | ||
|
|
d772bc182f | ||
|
|
358c53338d | ||
|
|
2110980797 | ||
|
|
1cd89eaa54 | ||
|
|
1d2e7eb96e | ||
|
|
4428e06f1d | ||
|
|
dddff54556 | ||
|
|
e7f7bbac22 | ||
|
|
37aae4ba5c | ||
|
|
54cfc98336 | ||
|
|
d42d38ff7a | ||
|
|
2b4601bd4b | ||
|
|
5071d9c6d5 | ||
|
|
cfaa4cd094 | ||
|
|
fc414794ff | ||
|
|
d8264956c3 | ||
|
|
effa7f25ca | ||
|
|
9b19fae69a | ||
|
|
ec04f64ce1 | ||
|
|
50bea76c0e | ||
|
|
05522fcdc7 | ||
|
|
3820eaa774 | ||
|
|
7effaf920a | ||
|
|
e40a6a3ca9 | ||
|
|
7c9475cfe2 | ||
|
|
17929dd95d | ||
|
|
f478b55538 | ||
|
|
c58c14f9b7 | ||
|
|
990d7cfbf9 | ||
|
|
43fa408f46 | ||
|
|
eb860a74af | ||
|
|
b3d050b42e | ||
|
|
db678a95c6 | ||
|
|
6d66cb48dc | ||
|
|
1fe2994743 | ||
|
|
126b10ce45 | ||
|
|
3b1843b6dd | ||
|
|
6a5d00f086 | ||
|
|
06368a6cf1 | ||
|
|
e9f25d3b1a | ||
|
|
fe167aa0b9 |
9
.github/workflows/deploy-docs.yml
vendored
9
.github/workflows/deploy-docs.yml
vendored
@@ -1,7 +1,11 @@
|
||||
name: Deploy Documentation
|
||||
|
||||
on:
|
||||
push:
|
||||
workflow_call:
|
||||
inputs:
|
||||
build-id:
|
||||
required: false
|
||||
type: string
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
@@ -16,6 +20,9 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Log build
|
||||
run: echo "Running documentation deployment from build ${{ inputs.build-id }}"
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
|
||||
11
.github/workflows/deploy-staging.yml
vendored
11
.github/workflows/deploy-staging.yml
vendored
@@ -5,6 +5,9 @@ on:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -21,3 +24,11 @@ jobs:
|
||||
key: ${{ secrets.SSH_KEY }}
|
||||
script: bash /opt/openisle/deploy-staging.sh
|
||||
|
||||
deploy-docs:
|
||||
needs: build-and-deploy
|
||||
if: ${{ success() }}
|
||||
uses: ./.github/workflows/deploy-docs.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
build-id: ${{ github.run_id }}
|
||||
|
||||
|
||||
@@ -246,3 +246,9 @@ https://resend.com/emails 创建账号并登录
|
||||
`RESEND_FROM_EMAIL`: **noreply@域名**
|
||||
`RESEND_API_KEY`:**刚刚复制的 Key**
|
||||

|
||||
|
||||
## 开源共建和API文档
|
||||
|
||||
- API文档: https://openisle-docs.netlify.app/docs/openapi
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
高效的开源社区前后端平台
|
||||
<br><br><br>
|
||||
<img alt="Image" src="https://openisle-1307107697.cos.accelerate.myqcloud.com/dynamic_assert/22752cfac5a04a9c90c41995b9f55fed.png" width="1200">
|
||||
<br><br><br>
|
||||
<a href="https://hellogithub.com/repository/nagisa77/OpenIsle" target="_blank"><img src="https://abroad.hellogithub.com/v1/widgets/recommend.svg?rid=8605546658d94cbab45182af2a02e4c8&claim_uid=p5GNFTtZl6HBAYQ" alt="Featured|HelloGitHub" style="width: 250px; height: 54px;" width="250" height="54" /></a>
|
||||
</p>
|
||||
|
||||
## 💡 简介
|
||||
|
||||
@@ -40,6 +40,10 @@ public class CachingConfig {
|
||||
public static final String CATEGORY_CACHE_NAME="openisle_categories";
|
||||
// 在线人数缓存名
|
||||
public static final String ONLINE_CACHE_NAME="openisle_online";
|
||||
// 注册验证码
|
||||
public static final String VERIFY_CACHE_NAME="openisle_verify";
|
||||
// 发帖频率限制
|
||||
public static final String LIMIT_CACHE_NAME="openisle_limit";
|
||||
|
||||
/**
|
||||
* 自定义Redis的序列化器
|
||||
|
||||
@@ -5,13 +5,21 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class OpenApiConfig {
|
||||
|
||||
private final SpringDocProperties springDocProperties;
|
||||
|
||||
@Value("${springdoc.info.title}")
|
||||
private String title;
|
||||
|
||||
@@ -30,19 +38,23 @@ public class OpenApiConfig {
|
||||
@Bean
|
||||
public OpenAPI openAPI() {
|
||||
SecurityScheme securityScheme = new SecurityScheme()
|
||||
.type(SecurityScheme.Type.HTTP)
|
||||
.scheme(scheme.toLowerCase())
|
||||
.bearerFormat("JWT")
|
||||
.in(SecurityScheme.In.HEADER)
|
||||
.name(header);
|
||||
.type(SecurityScheme.Type.HTTP)
|
||||
.scheme(scheme.toLowerCase())
|
||||
.bearerFormat("JWT")
|
||||
.in(SecurityScheme.In.HEADER)
|
||||
.name(header);
|
||||
|
||||
List<Server> servers = springDocProperties.getServers().stream()
|
||||
.map(s -> new Server().url(s.getUrl()).description(s.getDescription()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new OpenAPI()
|
||||
.servers(servers)
|
||||
.info(new Info()
|
||||
.title(title)
|
||||
.description(description)
|
||||
.version(version))
|
||||
.components(new Components()
|
||||
.addSecuritySchemes("JWT", securityScheme))
|
||||
.title(title)
|
||||
.description(description)
|
||||
.version(version))
|
||||
.components(new Components().addSecuritySchemes("JWT", securityScheme))
|
||||
.addSecurityItem(new SecurityRequirement().addList("JWT"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,9 @@ public class SecurityConfig {
|
||||
"http://192.168.7.98",
|
||||
"http://192.168.7.98:3000",
|
||||
"https://petstore.swagger.io",
|
||||
// 允许自建OpenAPI地址
|
||||
"https://docs.open-isle.com",
|
||||
"https://www.docs.open-isle.com",
|
||||
websiteUrl,
|
||||
websiteUrl.replace("://www.", "://")
|
||||
));
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.openisle.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "springdoc.api-docs")
|
||||
public class SpringDocProperties {
|
||||
private List<ServerConfig> servers = new ArrayList<>();
|
||||
|
||||
@Data
|
||||
public static class ServerConfig {
|
||||
private String url;
|
||||
private String description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.openisle.config;
|
||||
|
||||
import com.openisle.model.Role;
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Ensure a dedicated "system" user exists for internal operations.
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class SystemUserInitializer implements CommandLineRunner {
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
userRepository.findByUsername("system").orElseGet(() -> {
|
||||
User system = new User();
|
||||
system.setUsername("system");
|
||||
system.setEmail("system@openisle.local");
|
||||
// todo(tim): raw password 采用环境变量
|
||||
system.setPassword(passwordEncoder.encode("system"));
|
||||
system.setRole(Role.USER);
|
||||
system.setVerified(true);
|
||||
system.setApproved(true);
|
||||
system.setAvatar("https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/image.png");
|
||||
return userRepository.save(system);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.config.CachingConfig;
|
||||
import com.openisle.dto.*;
|
||||
import com.openisle.exception.FieldException;
|
||||
import com.openisle.model.RegisterMode;
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import com.openisle.service.*;
|
||||
import com.openisle.util.VerifyType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/auth")
|
||||
@@ -56,7 +60,8 @@ public class AuthController {
|
||||
User user = userService.registerWithInvite(
|
||||
req.getUsername(), req.getEmail(), req.getPassword());
|
||||
inviteService.consume(req.getInviteToken(), user.getUsername());
|
||||
emailService.sendEmail(user.getEmail(), "在网站填写验证码以验证", "您的验证码是 " + user.getVerificationCode());
|
||||
// 发送确认邮件
|
||||
userService.sendVerifyMail(user, VerifyType.REGISTER);
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"token", jwtService.generateToken(user.getUsername()),
|
||||
"reason_code", "INVITE_APPROVED"
|
||||
@@ -70,7 +75,8 @@ public class AuthController {
|
||||
}
|
||||
User user = userService.register(
|
||||
req.getUsername(), req.getEmail(), req.getPassword(), "", registerModeService.getRegisterMode());
|
||||
emailService.sendEmail(user.getEmail(), "在网站填写验证码以验证", "您的验证码是 " + user.getVerificationCode());
|
||||
// 发送确认邮件
|
||||
userService.sendVerifyMail(user, VerifyType.REGISTER);
|
||||
if (!user.isApproved()) {
|
||||
notificationService.createRegisterRequestNotifications(user, user.getRegisterReason());
|
||||
}
|
||||
@@ -79,13 +85,12 @@ public class AuthController {
|
||||
|
||||
@PostMapping("/verify")
|
||||
public ResponseEntity<?> verify(@RequestBody VerifyRequest req) {
|
||||
boolean ok = userService.verifyCode(req.getUsername(), req.getCode());
|
||||
Optional<User> userOpt = userService.findByUsername(req.getUsername());
|
||||
if (userOpt.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "Invalid credentials"));
|
||||
}
|
||||
boolean ok = userService.verifyCode(userOpt.get(), req.getCode(), VerifyType.REGISTER);
|
||||
if (ok) {
|
||||
Optional<User> userOpt = userService.findByUsername(req.getUsername());
|
||||
if (userOpt.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "Invalid credentials"));
|
||||
}
|
||||
|
||||
User user = userOpt.get();
|
||||
|
||||
if (user.isApproved()) {
|
||||
@@ -122,7 +127,7 @@ public class AuthController {
|
||||
User user = userOpt.get();
|
||||
if (!user.isVerified()) {
|
||||
user = userService.register(user.getUsername(), user.getEmail(), user.getPassword(), user.getRegisterReason(), registerModeService.getRegisterMode());
|
||||
emailService.sendEmail(user.getEmail(), "在网站填写验证码以验证", "您的验证码是 " + user.getVerificationCode());
|
||||
userService.sendVerifyMail(user, VerifyType.REGISTER);
|
||||
return ResponseEntity.badRequest().body(Map.of(
|
||||
"error", "User not verified",
|
||||
"reason_code", "NOT_VERIFIED",
|
||||
@@ -417,14 +422,17 @@ public class AuthController {
|
||||
if (userOpt.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "User not found"));
|
||||
}
|
||||
String code = userService.generatePasswordResetCode(req.getEmail());
|
||||
emailService.sendEmail(req.getEmail(), "请填写验证码以重置密码", "您的验证码是" + code);
|
||||
userService.sendVerifyMail(userOpt.get(), VerifyType.RESET_PASSWORD);
|
||||
return ResponseEntity.ok(Map.of("message", "Verification code sent"));
|
||||
}
|
||||
|
||||
@PostMapping("/forgot/verify")
|
||||
public ResponseEntity<?> verifyReset(@RequestBody VerifyForgotRequest req) {
|
||||
boolean ok = userService.verifyPasswordResetCode(req.getEmail(), req.getCode());
|
||||
Optional<User> userOpt = userService.findByEmail(req.getEmail());
|
||||
if (userOpt.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body(Map.of("error", "User not found"));
|
||||
}
|
||||
boolean ok = userService.verifyCode(userOpt.get(), req.getCode(), VerifyType.RESET_PASSWORD);
|
||||
if (ok) {
|
||||
String username = userService.findByEmail(req.getEmail()).get().getUsername();
|
||||
return ResponseEntity.ok(Map.of("token", jwtService.generateResetToken(username)));
|
||||
|
||||
@@ -5,6 +5,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -18,10 +19,10 @@ public class PostChangeLogDto {
|
||||
private String newTitle;
|
||||
private String oldContent;
|
||||
private String newContent;
|
||||
private String oldCategory;
|
||||
private String newCategory;
|
||||
private String oldTags;
|
||||
private String newTags;
|
||||
private CategoryDto oldCategory;
|
||||
private CategoryDto newCategory;
|
||||
private List<TagDto> oldTags;
|
||||
private List<TagDto> newTags;
|
||||
private Boolean oldClosed;
|
||||
private Boolean newClosed;
|
||||
private LocalDateTime oldPinnedAt;
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
package com.openisle.mapper;
|
||||
|
||||
import com.openisle.dto.CategoryDto;
|
||||
import com.openisle.dto.PostChangeLogDto;
|
||||
import com.openisle.dto.TagDto;
|
||||
import com.openisle.model.*;
|
||||
import com.openisle.repository.CategoryRepository;
|
||||
import com.openisle.repository.TagRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PostChangeLogMapper {
|
||||
|
||||
private final CategoryRepository categoryRepository;
|
||||
private final TagRepository tagRepository;
|
||||
private final CategoryMapper categoryMapper;
|
||||
private final TagMapper tagMapper;
|
||||
|
||||
public PostChangeLogDto toDto(PostChangeLog log) {
|
||||
PostChangeLogDto dto = new PostChangeLogDto();
|
||||
dto.setId(log.getId());
|
||||
@@ -22,11 +39,11 @@ public class PostChangeLogMapper {
|
||||
dto.setOldContent(c.getOldContent());
|
||||
dto.setNewContent(c.getNewContent());
|
||||
} else if (log instanceof PostCategoryChangeLog cat) {
|
||||
dto.setOldCategory(cat.getOldCategory());
|
||||
dto.setNewCategory(cat.getNewCategory());
|
||||
dto.setOldCategory(mapCategory(cat.getOldCategory()));
|
||||
dto.setNewCategory(mapCategory(cat.getNewCategory()));
|
||||
} else if (log instanceof PostTagChangeLog tag) {
|
||||
dto.setOldTags(tag.getOldTags());
|
||||
dto.setNewTags(tag.getNewTags());
|
||||
dto.setOldTags(mapTags(tag.getOldTags()));
|
||||
dto.setNewTags(mapTags(tag.getNewTags()));
|
||||
} else if (log instanceof PostClosedChangeLog cl) {
|
||||
dto.setOldClosed(cl.isOldClosed());
|
||||
dto.setNewClosed(cl.isNewClosed());
|
||||
@@ -39,4 +56,37 @@ public class PostChangeLogMapper {
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
private CategoryDto mapCategory(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
return categoryRepository.findByName(name)
|
||||
.map(categoryMapper::toDto)
|
||||
.orElseGet(() -> {
|
||||
CategoryDto dto = new CategoryDto();
|
||||
dto.setName(name);
|
||||
return dto;
|
||||
});
|
||||
}
|
||||
|
||||
private List<TagDto> mapTags(String tags) {
|
||||
if (tags == null || tags.isBlank()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.stream(tags.split(","))
|
||||
.map(String::trim)
|
||||
.map(this::mapTag)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private TagDto mapTag(String name) {
|
||||
return tagRepository.findByName(name)
|
||||
.map(tagMapper::toDto)
|
||||
.orElseGet(() -> {
|
||||
TagDto dto = new TagDto();
|
||||
dto.setName(name);
|
||||
return dto;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import com.openisle.model.Category;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface CategoryRepository extends JpaRepository<Category, Long> {
|
||||
List<Category> findByNameContainingIgnoreCase(String keyword);
|
||||
|
||||
Optional<Category> findByName(String name);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface TagRepository extends JpaRepository<Tag, Long> {
|
||||
List<Tag> findByNameContainingIgnoreCase(String keyword);
|
||||
@@ -15,4 +16,6 @@ public interface TagRepository extends JpaRepository<Tag, Long> {
|
||||
|
||||
List<Tag> findByCreatorOrderByCreatedAtDesc(User creator, Pageable pageable);
|
||||
List<Tag> findByCreator(User creator);
|
||||
|
||||
Optional<Tag> findByName(String name);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.openisle.service;
|
||||
import com.openisle.model.*;
|
||||
import com.openisle.repository.PostChangeLogRepository;
|
||||
import com.openisle.repository.PostRepository;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -15,6 +16,12 @@ import java.util.stream.Collectors;
|
||||
public class PostChangeLogService {
|
||||
private final PostChangeLogRepository logRepository;
|
||||
private final PostRepository postRepository;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
private User getSystemUser() {
|
||||
return userRepository.findByUsername("system")
|
||||
.orElseThrow(() -> new IllegalStateException("System user not found"));
|
||||
}
|
||||
|
||||
public void recordContentChange(Post post, User user, String oldContent, String newContent) {
|
||||
PostContentChangeLog log = new PostContentChangeLog();
|
||||
@@ -89,6 +96,7 @@ public class PostChangeLogService {
|
||||
public void recordVoteResult(Post post) {
|
||||
PostVoteResultChangeLog log = new PostVoteResultChangeLog();
|
||||
log.setPost(post);
|
||||
log.setUser(getSystemUser());
|
||||
log.setType(PostChangeType.VOTE_RESULT);
|
||||
logRepository.save(log);
|
||||
}
|
||||
@@ -96,6 +104,7 @@ public class PostChangeLogService {
|
||||
public void recordLotteryResult(Post post) {
|
||||
PostLotteryResultChangeLog log = new PostLotteryResultChangeLog();
|
||||
log.setPost(post);
|
||||
log.setUser(getSystemUser());
|
||||
log.setType(PostChangeType.LOTTERY_RESULT);
|
||||
logRepository.save(log);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.openisle.service;
|
||||
|
||||
import com.openisle.config.CachingConfig;
|
||||
import com.openisle.model.Post;
|
||||
import com.openisle.model.PostStatus;
|
||||
import com.openisle.model.PostType;
|
||||
@@ -28,12 +29,15 @@ import com.openisle.repository.PollVoteRepository;
|
||||
import com.openisle.model.Role;
|
||||
import com.openisle.exception.RateLimitException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import com.openisle.service.EmailSender;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
@@ -80,6 +84,8 @@ public class PostService {
|
||||
@Value("${app.website-url:https://www.open-isle.com}")
|
||||
private String websiteUrl;
|
||||
|
||||
private final RedisTemplate redisTemplate;
|
||||
|
||||
@org.springframework.beans.factory.annotation.Autowired
|
||||
public PostService(PostRepository postRepository,
|
||||
UserRepository userRepository,
|
||||
@@ -102,7 +108,8 @@ public class PostService {
|
||||
ApplicationContext applicationContext,
|
||||
PointService pointService,
|
||||
PostChangeLogService postChangeLogService,
|
||||
@Value("${app.post.publish-mode:DIRECT}") PublishMode publishMode) {
|
||||
@Value("${app.post.publish-mode:DIRECT}") PublishMode publishMode,
|
||||
RedisTemplate redisTemplate) {
|
||||
this.postRepository = postRepository;
|
||||
this.userRepository = userRepository;
|
||||
this.categoryRepository = categoryRepository;
|
||||
@@ -125,6 +132,8 @@ public class PostService {
|
||||
this.pointService = pointService;
|
||||
this.postChangeLogService = postChangeLogService;
|
||||
this.publishMode = publishMode;
|
||||
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
@@ -201,9 +210,9 @@ public class PostService {
|
||||
LocalDateTime endTime,
|
||||
java.util.List<String> options,
|
||||
Boolean multiple) {
|
||||
long recent = postRepository.countByAuthorAfter(username,
|
||||
java.time.LocalDateTime.now().minusMinutes(5));
|
||||
if (recent >= 1) {
|
||||
// 限制访问次数
|
||||
boolean limitResult = postRateLimit(username);
|
||||
if (!limitResult) {
|
||||
throw new RateLimitException("Too many posts");
|
||||
}
|
||||
if (tagIds == null || tagIds.isEmpty()) {
|
||||
@@ -300,6 +309,23 @@ public class PostService {
|
||||
return post;
|
||||
}
|
||||
|
||||
/**
|
||||
* 限制发帖频率
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
private boolean postRateLimit(String username){
|
||||
String key = CachingConfig.LIMIT_CACHE_NAME +":posts:"+username;
|
||||
String result = (String)redisTemplate.opsForValue().get(key);
|
||||
//最近没有创建过文章
|
||||
if(StringUtils.isEmpty(result)){
|
||||
// 限制频率为5分钟
|
||||
redisTemplate.opsForValue().set(key,"1", Duration.ofMinutes(5));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void joinLottery(Long postId, String username) {
|
||||
LotteryPost post = lotteryPostRepository.findById(postId)
|
||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||
@@ -368,6 +394,7 @@ public class PostService {
|
||||
for (User participant : pp.getParticipants()) {
|
||||
notificationService.createNotification(participant, NotificationType.POLL_RESULT_PARTICIPANT, pp, null, null, null, null, null);
|
||||
}
|
||||
postChangeLogService.recordVoteResult(pp);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -402,6 +429,7 @@ public class PostService {
|
||||
notificationService.createNotification(lp.getAuthor(), NotificationType.LOTTERY_DRAW, lp, null, null, null, null, null);
|
||||
notificationService.sendCustomPush(lp.getAuthor(), "抽奖已开奖", String.format("%s/posts/%d", websiteUrl, lp.getId()));
|
||||
}
|
||||
postChangeLogService.recordLotteryResult(lp);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.openisle.service;
|
||||
|
||||
import com.openisle.config.CachingConfig;
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.model.Role;
|
||||
import com.openisle.service.PasswordValidator;
|
||||
@@ -7,13 +8,18 @@ import com.openisle.service.UsernameValidator;
|
||||
import com.openisle.service.AvatarGenerator;
|
||||
import com.openisle.exception.FieldException;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import com.openisle.util.VerifyType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -25,6 +31,10 @@ public class UserService {
|
||||
private final ImageUploader imageUploader;
|
||||
private final AvatarGenerator avatarGenerator;
|
||||
|
||||
private final RedisTemplate redisTemplate;
|
||||
|
||||
private final EmailSender emailService;
|
||||
|
||||
public User register(String username, String email, String password, String reason, com.openisle.model.RegisterMode mode) {
|
||||
usernameValidator.validate(username);
|
||||
passwordValidator.validate(password);
|
||||
@@ -38,7 +48,7 @@ public class UserService {
|
||||
// 未验证 → 允许“重注册”:覆盖必要字段并重新发验证码
|
||||
u.setEmail(email); // 若不允许改邮箱可去掉
|
||||
u.setPassword(passwordEncoder.encode(password));
|
||||
u.setVerificationCode(genCode());
|
||||
// u.setVerificationCode(genCode());
|
||||
u.setRegisterReason(reason);
|
||||
u.setApproved(mode == com.openisle.model.RegisterMode.DIRECT);
|
||||
return userRepository.save(u);
|
||||
@@ -54,7 +64,7 @@ public class UserService {
|
||||
// 未验证 → 允许“重注册”
|
||||
u.setUsername(username); // 若不允许改用户名可去掉
|
||||
u.setPassword(passwordEncoder.encode(password));
|
||||
u.setVerificationCode(genCode());
|
||||
// u.setVerificationCode(genCode());
|
||||
u.setRegisterReason(reason);
|
||||
u.setApproved(mode == com.openisle.model.RegisterMode.DIRECT);
|
||||
return userRepository.save(u);
|
||||
@@ -67,7 +77,7 @@ public class UserService {
|
||||
user.setPassword(passwordEncoder.encode(password));
|
||||
user.setRole(Role.USER);
|
||||
user.setVerified(false);
|
||||
user.setVerificationCode(genCode());
|
||||
// user.setVerificationCode(genCode());
|
||||
user.setAvatar(avatarGenerator.generate(username));
|
||||
user.setRegisterReason(reason);
|
||||
user.setApproved(mode == com.openisle.model.RegisterMode.DIRECT);
|
||||
@@ -77,7 +87,7 @@ public class UserService {
|
||||
public User registerWithInvite(String username, String email, String password) {
|
||||
User user = register(username, email, password, "", com.openisle.model.RegisterMode.DIRECT);
|
||||
user.setVerified(true);
|
||||
user.setVerificationCode(genCode());
|
||||
// user.setVerificationCode(genCode());
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
@@ -85,16 +95,58 @@ public class UserService {
|
||||
return String.format("%06d", new Random().nextInt(1000000));
|
||||
}
|
||||
|
||||
public boolean verifyCode(String username, String code) {
|
||||
Optional<User> userOpt = userRepository.findByUsername(username);
|
||||
if (userOpt.isPresent() && code.equals(userOpt.get().getVerificationCode())) {
|
||||
User user = userOpt.get();
|
||||
user.setVerified(true);
|
||||
user.setVerificationCode(null);
|
||||
userRepository.save(user);
|
||||
return true;
|
||||
/**
|
||||
* 将验证码存入缓存,并发送邮件
|
||||
* @param user
|
||||
*/
|
||||
public void sendVerifyMail(User user, VerifyType verifyType){
|
||||
//缓存验证码
|
||||
String code = genCode();
|
||||
String key;
|
||||
String subject;
|
||||
String content = "您的验证码是:" + code;
|
||||
// 注册类型
|
||||
if(verifyType.equals(VerifyType.REGISTER)){
|
||||
key = CachingConfig.VERIFY_CACHE_NAME + ":register:code:" + user.getUsername();
|
||||
subject = "在网站填写验证码以验证(有效期为5分钟)";
|
||||
}else {
|
||||
// 重置密码
|
||||
key = CachingConfig.VERIFY_CACHE_NAME + ":reset_password:code:" + user.getUsername();
|
||||
subject = "请填写验证码以重置密码(有效期为5分钟)";
|
||||
}
|
||||
return false;
|
||||
|
||||
redisTemplate.opsForValue().set(key, code, 5, TimeUnit.MINUTES);// 五分钟后验证码过期
|
||||
emailService.sendEmail(user.getEmail(), subject, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证code是否正确
|
||||
* @param user
|
||||
* @param code
|
||||
* @param verifyType
|
||||
* @return
|
||||
*/
|
||||
public boolean verifyCode(User user, String code, VerifyType verifyType) {
|
||||
// 生成key
|
||||
String key1 = VerifyType.REGISTER.equals(verifyType)?":register:code:":":reset_password:code:";
|
||||
String key = CachingConfig.VERIFY_CACHE_NAME + key1 + user.getUsername();
|
||||
// 这里不能使用getAndDelete,需要6.x版本
|
||||
String cachedCode = (String)redisTemplate.opsForValue().get(key);
|
||||
// 如果校验code过期或者不存在
|
||||
// 或者校验code不一致
|
||||
if(Objects.isNull(cachedCode)
|
||||
|| !cachedCode.equals(code)){
|
||||
return false;
|
||||
}
|
||||
// 注册模式需要设置已经确认
|
||||
if(VerifyType.REGISTER.equals(verifyType)){
|
||||
user.setVerified(true);
|
||||
userRepository.save(user);
|
||||
}
|
||||
// 走到这里说明验证成功删除验证码
|
||||
redisTemplate.delete(key);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public Optional<User> authenticate(String username, String password) {
|
||||
@@ -165,26 +217,6 @@ public class UserService {
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
public String generatePasswordResetCode(String email) {
|
||||
User user = userRepository.findByEmail(email)
|
||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||
String code = genCode();
|
||||
user.setPasswordResetCode(code);
|
||||
userRepository.save(user);
|
||||
return code;
|
||||
}
|
||||
|
||||
public boolean verifyPasswordResetCode(String email, String code) {
|
||||
Optional<User> userOpt = userRepository.findByEmail(email);
|
||||
if (userOpt.isPresent() && code.equals(userOpt.get().getPasswordResetCode())) {
|
||||
User user = userOpt.get();
|
||||
user.setPasswordResetCode(null);
|
||||
userRepository.save(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public User updatePassword(String username, String newPassword) {
|
||||
passwordValidator.validate(newPassword);
|
||||
User user = userRepository.findByUsername(username)
|
||||
|
||||
20
backend/src/main/java/com/openisle/util/VerifyType.java
Normal file
20
backend/src/main/java/com/openisle/util/VerifyType.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.openisle.util;
|
||||
|
||||
/**
|
||||
* 验证码类型
|
||||
* @author smallclover
|
||||
* @since 2025-09-08
|
||||
*/
|
||||
public enum VerifyType {
|
||||
REGISTER(1),
|
||||
RESET_PASSWORD(2);
|
||||
private final int code;
|
||||
|
||||
VerifyType(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -108,6 +108,10 @@ rabbitmq.sharding.enabled=true
|
||||
# see https://springdoc.org/#springdoc-openapi-core-properties
|
||||
springdoc.api-docs.path=/api/v3/api-docs
|
||||
springdoc.api-docs.enabled=true
|
||||
springdoc.api-docs.servers[0].url=${WEBSITE_URL:https://www.open-isle.com}
|
||||
springdoc.api-docs.servers[0].description=正式环境
|
||||
springdoc.api-docs.servers[1].url=https://www.staging.open-isle.com
|
||||
springdoc.api-docs.servers[1].description=预发环境
|
||||
springdoc.info.title=OpenIsle
|
||||
springdoc.info.description=OpenIsle Open API Documentation
|
||||
springdoc.info.version=0.0.1
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.openisle.model.User;
|
||||
import com.openisle.service.*;
|
||||
import com.openisle.model.RegisterMode;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import com.openisle.util.VerifyType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -71,7 +72,9 @@ class AuthControllerTest {
|
||||
|
||||
@Test
|
||||
void verifyCodeEndpoint() throws Exception {
|
||||
Mockito.when(userService.verifyCode("u", "123")).thenReturn(true);
|
||||
User user = new User();
|
||||
user.setUsername("u");
|
||||
Mockito.when(userService.verifyCode(user, "123", VerifyType.REGISTER)).thenReturn(true);
|
||||
Mockito.when(jwtService.generateReasonToken("u")).thenReturn("reason_token");
|
||||
|
||||
mockMvc.perform(post("/api/auth/verify")
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.openisle.exception.RateLimitException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -37,11 +38,13 @@ class PostServiceTest {
|
||||
EmailSender emailSender = mock(EmailSender.class);
|
||||
ApplicationContext context = mock(ApplicationContext.class);
|
||||
PointService pointService = mock(PointService.class);
|
||||
PostChangeLogService postChangeLogService = mock(PostChangeLogService.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, PublishMode.DIRECT);
|
||||
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, PublishMode.DIRECT, redisTemplate);
|
||||
when(context.getBean(PostService.class)).thenReturn(service);
|
||||
|
||||
Post post = new Post();
|
||||
@@ -86,11 +89,13 @@ class PostServiceTest {
|
||||
EmailSender emailSender = mock(EmailSender.class);
|
||||
ApplicationContext context = mock(ApplicationContext.class);
|
||||
PointService pointService = mock(PointService.class);
|
||||
PostChangeLogService postChangeLogService = mock(PostChangeLogService.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, PublishMode.DIRECT);
|
||||
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, PublishMode.DIRECT, redisTemplate);
|
||||
when(context.getBean(PostService.class)).thenReturn(service);
|
||||
|
||||
Post post = new Post();
|
||||
@@ -141,11 +146,13 @@ class PostServiceTest {
|
||||
EmailSender emailSender = mock(EmailSender.class);
|
||||
ApplicationContext context = mock(ApplicationContext.class);
|
||||
PointService pointService = mock(PointService.class);
|
||||
PostChangeLogService postChangeLogService = mock(PostChangeLogService.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, PublishMode.DIRECT);
|
||||
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, PublishMode.DIRECT, redisTemplate);
|
||||
when(context.getBean(PostService.class)).thenReturn(service);
|
||||
|
||||
when(postRepo.countByAuthorAfter(eq("alice"), any())).thenReturn(1L);
|
||||
@@ -177,11 +184,13 @@ class PostServiceTest {
|
||||
EmailSender emailSender = mock(EmailSender.class);
|
||||
ApplicationContext context = mock(ApplicationContext.class);
|
||||
PointService pointService = mock(PointService.class);
|
||||
PostChangeLogService postChangeLogService = mock(PostChangeLogService.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, PublishMode.DIRECT);
|
||||
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, PublishMode.DIRECT, redisTemplate);
|
||||
when(context.getBean(PostService.class)).thenReturn(service);
|
||||
|
||||
User author = new User();
|
||||
|
||||
@@ -16,6 +16,6 @@ bun dev
|
||||
|
||||
使用以下路由:
|
||||
|
||||
- `docs/frontend/` 前端技术文档
|
||||
- `docs/backend/` 后端技术文档
|
||||
- `docs/openapi/` 后端 API 文档
|
||||
- `frontend/` 前端技术文档
|
||||
- `backend/` 后端技术文档
|
||||
- `openapi/` 后端 API 文档
|
||||
|
||||
@@ -19,7 +19,7 @@ function DocsCategory({ url }: { url: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
export default async function Page(props: PageProps<'/docs/[[...slug]]'>) {
|
||||
export default async function Page(props: PageProps<'/[[...slug]]'>) {
|
||||
const params = await props.params;
|
||||
const page = source.getPage(params.slug);
|
||||
if (!page) notFound();
|
||||
@@ -48,7 +48,7 @@ export async function generateStaticParams() {
|
||||
}
|
||||
|
||||
export async function generateMetadata(
|
||||
props: PageProps<'/docs/[[...slug]]'>
|
||||
props: PageProps<'/[[...slug]]'>
|
||||
): Promise<Metadata> {
|
||||
const params = await props.params;
|
||||
const page = source.getPage(params.slug);
|
||||
@@ -28,7 +28,7 @@ function TabTitle({ children }: { children: React.ReactNode }) {
|
||||
return <span className="text-[11px]">{children}</span>;
|
||||
}
|
||||
|
||||
export default function Layout({ children }: LayoutProps<'/docs'>) {
|
||||
export default function Layout({ children }: LayoutProps<'/'>) {
|
||||
return (
|
||||
// @ts-ignore
|
||||
<DocsLayout
|
||||
@@ -40,7 +40,7 @@ export default function Layout({ children }: LayoutProps<'/docs'>) {
|
||||
{
|
||||
title: 'OpenIsle 前端',
|
||||
description: <TabTitle>前端开发文档</TabTitle>,
|
||||
url: '/docs/frontend',
|
||||
url: '/frontend',
|
||||
icon: (
|
||||
<TabIcon color="#4ca154">
|
||||
<CompassIcon />
|
||||
@@ -50,7 +50,7 @@ export default function Layout({ children }: LayoutProps<'/docs'>) {
|
||||
{
|
||||
title: 'OpenIsle 后端',
|
||||
description: <TabTitle>后端开发文档</TabTitle>,
|
||||
url: '/docs/backend',
|
||||
url: '/backend',
|
||||
icon: (
|
||||
<TabIcon color="#1f66f4">
|
||||
<ServerIcon />
|
||||
@@ -60,7 +60,7 @@ export default function Layout({ children }: LayoutProps<'/docs'>) {
|
||||
{
|
||||
title: 'OpenIsle API',
|
||||
description: <TabTitle>后端 API 文档</TabTitle>,
|
||||
url: '/docs/openapi',
|
||||
url: '/openapi',
|
||||
icon: (
|
||||
<TabIcon color="#677489">
|
||||
<CodeXmlIcon />
|
||||
@@ -6,7 +6,7 @@ const inter = Inter({
|
||||
subsets: ['latin'],
|
||||
});
|
||||
|
||||
export default function Layout({ children }: LayoutProps<'/docs'>) {
|
||||
export default function Layout({ children }: LayoutProps<'/'>) {
|
||||
return (
|
||||
<html lang="zh" className={inter.className} suppressHydrationWarning>
|
||||
<body className="flex flex-col min-h-screen">
|
||||
|
||||
@@ -40,4 +40,4 @@ backend/
|
||||
|
||||
## API 接口
|
||||
|
||||
详细的 API 接口文档请查看 [API 文档](/docs/openapi)。
|
||||
详细的 API 接口文档请查看 [API 文档](/openapi)。
|
||||
|
||||
@@ -9,6 +9,6 @@ OpenIsle 是一个现代化的社区平台,提供完整的社交功能。
|
||||
|
||||
## 快速开始
|
||||
|
||||
- [后端开发指南](/docs/backend) - 了解后端架构和开发
|
||||
- [前端开发指南](/docs/frontend) - 了解前端技术栈和组件
|
||||
- [API 文档](/docs/openapi) - 查看完整的 API 接口文档
|
||||
- [后端开发指南](/backend) - 了解后端架构和开发
|
||||
- [前端开发指南](/frontend) - 了解前端技术栈和组件
|
||||
- [API 文档](/openapi) - 查看完整的 API 接口文档
|
||||
|
||||
@@ -8,7 +8,7 @@ export function baseOptions(): BaseLayoutProps {
|
||||
githubUrl: 'https://github.com/nagisa77/OpenIsle',
|
||||
nav: {
|
||||
title: 'OpenIsle Docs',
|
||||
url: '/docs',
|
||||
url: '/',
|
||||
},
|
||||
searchToggle: {
|
||||
enabled: false,
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as ClientAdapters from './media-adapter.client';
|
||||
// See https://fumadocs.vercel.app/docs/headless/source-api for more info
|
||||
export const source = loader({
|
||||
// it assigns a URL to your pages
|
||||
baseUrl: '/docs',
|
||||
baseUrl: '/',
|
||||
source: docs.toFumadocsSource(),
|
||||
pageTree: {
|
||||
transformers: [transformerOpenAPI()],
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
--background-color: white;
|
||||
--background-color-blur: rgba(255, 255, 255, 0.57);
|
||||
--menu-border-color: lightgray;
|
||||
--normal-border-color: lightgray;
|
||||
--normal-border-color: rgba(211, 211, 211, 0.63);
|
||||
--menu-selected-background-color: rgba(88, 241, 255, 0.166);
|
||||
--normal-light-background-color: rgba(242, 242, 242, 0.884);
|
||||
--menu-selected-background-color-hover: rgba(242, 242, 242, 0.884);
|
||||
@@ -348,6 +348,22 @@ body {
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjust diff2html layout on mobile */
|
||||
@media (max-width: 768px) {
|
||||
.content-diff .d2h-wrapper,
|
||||
.content-diff .d2h-code-line,
|
||||
.content-diff .d2h-code-side-line,
|
||||
.content-diff .d2h-code-line-ctn,
|
||||
.content-diff .d2h-code-side-line-ctn,
|
||||
.content-diff .d2h-file-header {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.content-diff .d2h-wrapper {
|
||||
overflow-x: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* Transition API */
|
||||
::view-transition-old(root),
|
||||
::view-transition-new(root) {
|
||||
|
||||
@@ -11,8 +11,18 @@
|
||||
<span v-if="log.username" class="change-log-user">{{ log.username }}</span>
|
||||
<span v-if="log.type === 'CONTENT'" class="change-log-content">变更了文章内容</span>
|
||||
<span v-else-if="log.type === 'TITLE'" class="change-log-content">变更了文章标题</span>
|
||||
<span v-else-if="log.type === 'CATEGORY'" class="change-log-content">变更了文章分类</span>
|
||||
<span v-else-if="log.type === 'TAG'" class="change-log-content">变更了文章标签</span>
|
||||
<template v-else-if="log.type === 'CATEGORY'">
|
||||
<div class="change-log-category-text">变更了文章分类, 从</div>
|
||||
<ArticleCategory :category="log.oldCategory" />
|
||||
<div class="change-log-category-text">修改为</div>
|
||||
<ArticleCategory :category="log.newCategory" />
|
||||
</template>
|
||||
<template v-else-if="log.type === 'TAG'">
|
||||
<div class="change-log-category-text">变更了文章标签, 从</div>
|
||||
<ArticleTags :tags="log.oldTags" />
|
||||
<div class="change-log-category-text">修改为</div>
|
||||
<ArticleTags :tags="log.newTags" />
|
||||
</template>
|
||||
<span v-else-if="log.type === 'CLOSED'" class="change-log-content">
|
||||
<template v-if="log.newClosed">关闭了文章</template>
|
||||
<template v-else>重新打开了文章</template>
|
||||
@@ -25,8 +35,12 @@
|
||||
<template v-if="log.newFeatured">将文章设为精选</template>
|
||||
<template v-else>取消精选文章</template>
|
||||
</span>
|
||||
<span v-else-if="log.type === 'VOTE_RESULT'" class="change-log-content">投票已出结果</span>
|
||||
<span v-else-if="log.type === 'LOTTERY_RESULT'" class="change-log-content">抽奖已开奖</span>
|
||||
<span v-else-if="log.type === 'VOTE_RESULT'" class="change-log-content"
|
||||
>系统已计算投票结果</span
|
||||
>
|
||||
<span v-else-if="log.type === 'LOTTERY_RESULT'" class="change-log-content"
|
||||
>系统已「精密计算」抽奖结果 (=゚ω゚)ノ</span
|
||||
>
|
||||
</div>
|
||||
<div class="change-log-time">{{ log.time }}</div>
|
||||
<div
|
||||
@@ -46,13 +60,14 @@ import 'diff2html/bundles/css/diff2html.min.css'
|
||||
import BaseImage from '~/components/BaseImage.vue'
|
||||
import { navigateTo } from 'nuxt/app'
|
||||
import { themeState } from '~/utils/theme'
|
||||
import ArticleCategory from '~/components/ArticleCategory.vue'
|
||||
import ArticleTags from '~/components/ArticleTags.vue'
|
||||
const props = defineProps({
|
||||
log: Object,
|
||||
title: String,
|
||||
})
|
||||
|
||||
const diffHtml = computed(() => {
|
||||
const isMobile = useIsMobile()
|
||||
// Track theme changes
|
||||
const isDark = import.meta.client && document.documentElement.dataset.theme === 'dark'
|
||||
themeState.mode
|
||||
@@ -67,7 +82,6 @@ const diffHtml = computed(() => {
|
||||
showFiles: false,
|
||||
matching: 'lines',
|
||||
drawFileList: false,
|
||||
outputFormat: isMobile.value ? 'line-by-line' : 'side-by-side',
|
||||
colorScheme,
|
||||
})
|
||||
} else if (props.log.type === 'TITLE') {
|
||||
@@ -79,7 +93,6 @@ const diffHtml = computed(() => {
|
||||
showFiles: false,
|
||||
matching: 'lines',
|
||||
drawFileList: false,
|
||||
outputFormat: isMobile.value ? 'line-by-line' : 'side-by-side',
|
||||
colorScheme,
|
||||
})
|
||||
}
|
||||
@@ -94,9 +107,12 @@ const diffHtml = computed(() => {
|
||||
/* padding-top: 5px; */
|
||||
/* padding-bottom: 30px; */
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid var(--normal-border-color);
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
.change-log-text {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
.change-log-user {
|
||||
@@ -124,4 +140,12 @@ const diffHtml = computed(() => {
|
||||
.content-diff {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.change-log-category {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1163,6 +1163,7 @@ onMounted(async () => {
|
||||
margin-top: 10px;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.info-content-container {
|
||||
@@ -1218,7 +1219,7 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
.post-time {
|
||||
font-size: 14px;
|
||||
font-size: 12px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
@@ -1284,10 +1285,6 @@ onMounted(async () => {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.post-time {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.info-content-text {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ import {
|
||||
DoubleDown,
|
||||
Open,
|
||||
Dislike,
|
||||
CheckOne,
|
||||
} from '@icon-park/vue-next'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
@@ -155,4 +156,5 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.vueApp.component('DoubleDown', DoubleDown)
|
||||
nuxtApp.vueApp.component('OpenIcon', Open)
|
||||
nuxtApp.vueApp.component('Dislike', Dislike)
|
||||
nuxtApp.vueApp.component('CheckOne', CheckOne)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user