mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-09 08:30:55 +08:00
Compare commits
58 Commits
codex/fix-
...
codex/swit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08fe8a30c1 | ||
|
|
6f4b17f96e | ||
|
|
1e284e15df | ||
|
|
9d76926b8a | ||
|
|
d2ce203236 | ||
|
|
b2228296af | ||
|
|
7020ae19d0 | ||
|
|
227fb6f6cc | ||
|
|
0e46a67ea6 | ||
|
|
b20b705e46 | ||
|
|
4b3ffbab99 | ||
|
|
74039c89f9 | ||
|
|
10dca73d2f | ||
|
|
e37ed1b70b | ||
|
|
8500a7a914 | ||
|
|
3adf722b3b | ||
|
|
791e5a4daf | ||
|
|
7d25e87fbc | ||
|
|
d02c316a70 | ||
|
|
c189c80c05 | ||
|
|
07db73c9c7 | ||
|
|
c296e25927 | ||
|
|
61fc9d799d | ||
|
|
20c6c73f8c | ||
|
|
81d1f79aae | ||
|
|
4ff76d2586 | ||
|
|
f24bc239cc | ||
|
|
143691206d | ||
|
|
15ad85e6f1 | ||
|
|
843e53143d | ||
|
|
16c94690bd | ||
|
|
5be00e7013 | ||
|
|
1e0f62b421 | ||
|
|
a3201f05fb | ||
|
|
62cccb794d | ||
|
|
afa0c7fb8f | ||
|
|
da311806c1 | ||
|
|
1852f87341 | ||
|
|
7010e8a058 | ||
|
|
38ee37d5be | ||
|
|
e398d8e989 | ||
|
|
85e77c265e | ||
|
|
8abdc73497 | ||
|
|
747d9c07d1 | ||
|
|
09cefbedbf | ||
|
|
d772bc182f | ||
|
|
358c53338d | ||
|
|
2110980797 | ||
|
|
1cd89eaa54 | ||
|
|
1d2e7eb96e | ||
|
|
4428e06f1d | ||
|
|
dddff54556 | ||
|
|
e7f7bbac22 | ||
|
|
37aae4ba5c | ||
|
|
54cfc98336 | ||
|
|
d42d38ff7a | ||
|
|
2b4601bd4b | ||
|
|
5071d9c6d5 |
@@ -246,3 +246,9 @@ https://resend.com/emails 创建账号并登录
|
|||||||
`RESEND_FROM_EMAIL`: **noreply@域名**
|
`RESEND_FROM_EMAIL`: **noreply@域名**
|
||||||
`RESEND_API_KEY`:**刚刚复制的 Key**
|
`RESEND_API_KEY`:**刚刚复制的 Key**
|
||||||

|

|
||||||
|
|
||||||
|
## 开源共建和API文档
|
||||||
|
|
||||||
|
- API文档: https://docs.open-isle.com/openapi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
高效的开源社区前后端平台
|
高效的开源社区前后端平台
|
||||||
<br><br><br>
|
<br><br><br>
|
||||||
<img alt="Image" src="https://openisle-1307107697.cos.accelerate.myqcloud.com/dynamic_assert/22752cfac5a04a9c90c41995b9f55fed.png" width="1200">
|
<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>
|
</p>
|
||||||
|
|
||||||
## 💡 简介
|
## 💡 简介
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ public class CachingConfig {
|
|||||||
public static final String ONLINE_CACHE_NAME="openisle_online";
|
public static final String ONLINE_CACHE_NAME="openisle_online";
|
||||||
// 注册验证码
|
// 注册验证码
|
||||||
public static final String VERIFY_CACHE_NAME="openisle_verify";
|
public static final String VERIFY_CACHE_NAME="openisle_verify";
|
||||||
|
// 发帖频率限制
|
||||||
|
public static final String LIMIT_CACHE_NAME="openisle_limit";
|
||||||
|
// 用户访问统计
|
||||||
|
public static final String VISIT_CACHE_NAME="openisle_visit";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义Redis的序列化器
|
* 自定义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.info.Info;
|
||||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
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.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class OpenApiConfig {
|
public class OpenApiConfig {
|
||||||
|
|
||||||
|
private final SpringDocProperties springDocProperties;
|
||||||
|
|
||||||
@Value("${springdoc.info.title}")
|
@Value("${springdoc.info.title}")
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@@ -30,19 +38,23 @@ public class OpenApiConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public OpenAPI openAPI() {
|
public OpenAPI openAPI() {
|
||||||
SecurityScheme securityScheme = new SecurityScheme()
|
SecurityScheme securityScheme = new SecurityScheme()
|
||||||
.type(SecurityScheme.Type.HTTP)
|
.type(SecurityScheme.Type.HTTP)
|
||||||
.scheme(scheme.toLowerCase())
|
.scheme(scheme.toLowerCase())
|
||||||
.bearerFormat("JWT")
|
.bearerFormat("JWT")
|
||||||
.in(SecurityScheme.In.HEADER)
|
.in(SecurityScheme.In.HEADER)
|
||||||
.name(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()
|
return new OpenAPI()
|
||||||
|
.servers(servers)
|
||||||
.info(new Info()
|
.info(new Info()
|
||||||
.title(title)
|
.title(title)
|
||||||
.description(description)
|
.description(description)
|
||||||
.version(version))
|
.version(version))
|
||||||
.components(new Components()
|
.components(new Components().addSecuritySchemes("JWT", securityScheme))
|
||||||
.addSecuritySchemes("JWT", securityScheme))
|
|
||||||
.addSecurityItem(new SecurityRequirement().addList("JWT"));
|
.addSecurityItem(new SecurityRequirement().addList("JWT"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.openisle.config;
|
package com.openisle.config;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.core.Binding;
|
import org.springframework.amqp.core.Binding;
|
||||||
import org.springframework.amqp.core.BindingBuilder;
|
import org.springframework.amqp.core.BindingBuilder;
|
||||||
import org.springframework.amqp.core.Queue;
|
import org.springframework.amqp.core.Queue;
|
||||||
@@ -23,6 +24,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class RabbitMQConfig {
|
public class RabbitMQConfig {
|
||||||
|
|
||||||
public static final String EXCHANGE_NAME = "openisle-exchange";
|
public static final String EXCHANGE_NAME = "openisle-exchange";
|
||||||
@@ -38,7 +40,7 @@ public class RabbitMQConfig {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
System.out.println("RabbitMQ配置初始化: 队列数量=" + queueCount + ", 持久化=" + queueDurable);
|
log.info("RabbitMQ配置初始化: 队列数量={}, 持久化={}", queueCount, queueDurable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -51,7 +53,7 @@ public class RabbitMQConfig {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public List<Queue> shardedQueues() {
|
public List<Queue> shardedQueues() {
|
||||||
System.out.println("开始创建分片队列 Bean...");
|
log.info("开始创建分片队列 Bean...");
|
||||||
|
|
||||||
List<Queue> queues = new ArrayList<>();
|
List<Queue> queues = new ArrayList<>();
|
||||||
for (int i = 0; i < queueCount; i++) {
|
for (int i = 0; i < queueCount; i++) {
|
||||||
@@ -61,7 +63,7 @@ public class RabbitMQConfig {
|
|||||||
queues.add(queue);
|
queues.add(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("分片队列 Bean 创建完成,总数: " + queues.size());
|
log.info("分片队列 Bean 创建完成,总数: {}", queues.size());
|
||||||
return queues;
|
return queues;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ public class RabbitMQConfig {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public List<Binding> shardedBindings(TopicExchange exchange, @Qualifier("shardedQueues") List<Queue> shardedQueues) {
|
public List<Binding> shardedBindings(TopicExchange exchange, @Qualifier("shardedQueues") List<Queue> shardedQueues) {
|
||||||
System.out.println("开始创建分片绑定 Bean...");
|
log.info("开始创建分片绑定 Bean...");
|
||||||
List<Binding> bindings = new ArrayList<>();
|
List<Binding> bindings = new ArrayList<>();
|
||||||
if (shardedQueues != null) {
|
if (shardedQueues != null) {
|
||||||
for (Queue queue : shardedQueues) {
|
for (Queue queue : shardedQueues) {
|
||||||
@@ -82,7 +84,7 @@ public class RabbitMQConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("分片绑定 Bean 创建完成,总数: " + bindings.size());
|
log.info("分片绑定 Bean 创建完成,总数: {}", bindings.size());
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,14 +137,14 @@ public class RabbitMQConfig {
|
|||||||
@Qualifier("shardedBindings") List<Binding> shardedBindings,
|
@Qualifier("shardedBindings") List<Binding> shardedBindings,
|
||||||
Binding legacyBinding) {
|
Binding legacyBinding) {
|
||||||
return args -> {
|
return args -> {
|
||||||
System.out.println("=== 开始主动声明 RabbitMQ 组件 ===");
|
log.info("=== 开始主动声明 RabbitMQ 组件 ===");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 声明交换
|
// 声明交换
|
||||||
rabbitAdmin.declareExchange(exchange);
|
rabbitAdmin.declareExchange(exchange);
|
||||||
|
|
||||||
// 声明分片队列 - 检查存在性
|
// 声明分片队列 - 检查存在性
|
||||||
System.out.println("开始检查并声明 " + shardedQueues.size() + " 个分片队列...");
|
log.info("开始检查并声明 {} 个分片队列...", shardedQueues.size());
|
||||||
int successCount = 0;
|
int successCount = 0;
|
||||||
int skippedCount = 0;
|
int skippedCount = 0;
|
||||||
|
|
||||||
@@ -159,45 +161,44 @@ public class RabbitMQConfig {
|
|||||||
skippedCount++;
|
skippedCount++;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("队列声明失败: " + queueName + ", 错误: " + e.getMessage());
|
log.error("队列声明失败: {}, 错误: {}", queueName, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("分片队列处理完成: 成功 " + successCount + ", 跳过 " + skippedCount + ", 总数 " + shardedQueues.size());
|
log.info("分片队列处理完成: 成功 {}, 跳过 {}, 总数 {}", successCount, skippedCount, shardedQueues.size());
|
||||||
|
|
||||||
// 声明分片绑定
|
// 声明分片绑定
|
||||||
System.out.println("开始声明 " + shardedBindings.size() + " 个分片绑定...");
|
log.info("开始声明 {} 个分片绑定...", shardedBindings.size());
|
||||||
int bindingSuccessCount = 0;
|
int bindingSuccessCount = 0;
|
||||||
for (Binding binding : shardedBindings) {
|
for (Binding binding : shardedBindings) {
|
||||||
try {
|
try {
|
||||||
rabbitAdmin.declareBinding(binding);
|
rabbitAdmin.declareBinding(binding);
|
||||||
bindingSuccessCount++;
|
bindingSuccessCount++;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("绑定声明失败: " + e.getMessage());
|
log.error("绑定声明失败: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("分片绑定声明完成: 成功 " + bindingSuccessCount + "/" + shardedBindings.size());
|
log.info("分片绑定声明完成: 成功 {}/{}", bindingSuccessCount, shardedBindings.size());
|
||||||
|
|
||||||
// 声明遗留队列和绑定 - 检查存在性
|
// 声明遗留队列和绑定 - 检查存在性
|
||||||
try {
|
try {
|
||||||
rabbitAdmin.declareQueue(legacyQueue);
|
rabbitAdmin.declareQueue(legacyQueue);
|
||||||
rabbitAdmin.declareBinding(legacyBinding);
|
rabbitAdmin.declareBinding(legacyBinding);
|
||||||
System.out.println("遗留队列和绑定就绪: " + QUEUE_NAME + " (已存在或新创建)");
|
log.info("遗留队列和绑定就绪: {} (已存在或新创建)", QUEUE_NAME);
|
||||||
} catch (org.springframework.amqp.AmqpIOException e) {
|
} catch (org.springframework.amqp.AmqpIOException e) {
|
||||||
if (e.getMessage().contains("PRECONDITION_FAILED") && e.getMessage().contains("durable")) {
|
if (e.getMessage().contains("PRECONDITION_FAILED") && e.getMessage().contains("durable")) {
|
||||||
System.out.println("遗留队列已存在但 durable 设置不匹配: " + QUEUE_NAME + ", 保持现有队列");
|
log.warn("遗留队列已存在但 durable 设置不匹配: {}, 保持现有队列", QUEUE_NAME);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("遗留队列声明失败: " + QUEUE_NAME + ", 错误: " + e.getMessage());
|
log.error("遗留队列声明失败: {}, 错误: {}", QUEUE_NAME, e.getMessage());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("遗留队列声明失败: " + QUEUE_NAME + ", 错误: " + e.getMessage());
|
log.error("遗留队列声明失败: {}, 错误: {}", QUEUE_NAME, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("=== RabbitMQ 组件声明完成 ===");
|
log.info("=== RabbitMQ 组件声明完成 ===");
|
||||||
System.out.println("请检查 RabbitMQ 管理界面确认队列已正确创建");
|
log.info("请检查 RabbitMQ 管理界面确认队列已正确创建");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("RabbitMQ 组件声明过程中发生严重错误:");
|
log.error("RabbitMQ 组件声明过程中发生严重错误", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.openisle.repository.UserRepository;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
@@ -26,6 +27,8 @@ import org.springframework.web.cors.CorsConfiguration;
|
|||||||
import org.springframework.web.cors.CorsConfigurationSource;
|
import org.springframework.web.cors.CorsConfigurationSource;
|
||||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
@@ -44,6 +47,8 @@ public class SecurityConfig {
|
|||||||
@Value("${app.website-url}")
|
@Value("${app.website-url}")
|
||||||
private String websiteUrl;
|
private String websiteUrl;
|
||||||
|
|
||||||
|
private final RedisTemplate redisTemplate;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PasswordEncoder passwordEncoder() {
|
public PasswordEncoder passwordEncoder() {
|
||||||
return new BCryptPasswordEncoder();
|
return new BCryptPasswordEncoder();
|
||||||
@@ -90,6 +95,9 @@ public class SecurityConfig {
|
|||||||
"http://192.168.7.98",
|
"http://192.168.7.98",
|
||||||
"http://192.168.7.98:3000",
|
"http://192.168.7.98:3000",
|
||||||
"https://petstore.swagger.io",
|
"https://petstore.swagger.io",
|
||||||
|
// 允许自建OpenAPI地址
|
||||||
|
"https://docs.open-isle.com",
|
||||||
|
"https://www.docs.open-isle.com",
|
||||||
websiteUrl,
|
websiteUrl,
|
||||||
websiteUrl.replace("://www.", "://")
|
websiteUrl.replace("://www.", "://")
|
||||||
));
|
));
|
||||||
@@ -205,7 +213,8 @@ public class SecurityConfig {
|
|||||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||||
var auth = org.springframework.security.core.context.SecurityContextHolder.getContext().getAuthentication();
|
var auth = org.springframework.security.core.context.SecurityContextHolder.getContext().getAuthentication();
|
||||||
if (auth != null && auth.isAuthenticated() && !(auth instanceof org.springframework.security.authentication.AnonymousAuthenticationToken)) {
|
if (auth != null && auth.isAuthenticated() && !(auth instanceof org.springframework.security.authentication.AnonymousAuthenticationToken)) {
|
||||||
userVisitService.recordVisit(auth.getName());
|
String key = CachingConfig.VISIT_CACHE_NAME+":"+ LocalDate.now();
|
||||||
|
redisTemplate.opsForSet().add(key, auth.getName());
|
||||||
}
|
}
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,12 @@ import com.openisle.service.UserService;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -25,6 +31,9 @@ public class ActivityController {
|
|||||||
private final ActivityMapper activityMapper;
|
private final ActivityMapper activityMapper;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "List activities", description = "Retrieve all activities")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of activities",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = ActivityDto.class))))
|
||||||
public List<ActivityDto> list() {
|
public List<ActivityDto> list() {
|
||||||
return activityService.list().stream()
|
return activityService.list().stream()
|
||||||
.map(activityMapper::toDto)
|
.map(activityMapper::toDto)
|
||||||
@@ -32,6 +41,9 @@ public class ActivityController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/milk-tea")
|
@GetMapping("/milk-tea")
|
||||||
|
@Operation(summary = "Milk tea info", description = "Get milk tea activity information")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Milk tea info",
|
||||||
|
content = @Content(schema = @Schema(implementation = MilkTeaInfoDto.class)))
|
||||||
public MilkTeaInfoDto milkTea() {
|
public MilkTeaInfoDto milkTea() {
|
||||||
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
||||||
long count = activityService.countParticipants(a);
|
long count = activityService.countParticipants(a);
|
||||||
@@ -45,6 +57,10 @@ public class ActivityController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/milk-tea/redeem")
|
@PostMapping("/milk-tea/redeem")
|
||||||
|
@Operation(summary = "Redeem milk tea", description = "Redeem milk tea activity reward")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Redeem result",
|
||||||
|
content = @Content(schema = @Schema(implementation = java.util.Map.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public java.util.Map<String, String> redeemMilkTea(@RequestBody MilkTeaRedeemRequest req, Authentication auth) {
|
public java.util.Map<String, String> redeemMilkTea(@RequestBody MilkTeaRedeemRequest req, Authentication auth) {
|
||||||
User user = userService.findByIdentifier(auth.getName()).orElseThrow();
|
User user = userService.findByIdentifier(auth.getName()).orElseThrow();
|
||||||
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ package com.openisle.controller;
|
|||||||
import com.openisle.dto.CommentDto;
|
import com.openisle.dto.CommentDto;
|
||||||
import com.openisle.mapper.CommentMapper;
|
import com.openisle.mapper.CommentMapper;
|
||||||
import com.openisle.service.CommentService;
|
import com.openisle.service.CommentService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -18,11 +23,19 @@ public class AdminCommentController {
|
|||||||
private final CommentMapper commentMapper;
|
private final CommentMapper commentMapper;
|
||||||
|
|
||||||
@PostMapping("/{id}/pin")
|
@PostMapping("/{id}/pin")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Pin comment", description = "Pin a comment by its id")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Pinned comment",
|
||||||
|
content = @Content(schema = @Schema(implementation = CommentDto.class)))
|
||||||
public CommentDto pin(@PathVariable Long id, Authentication auth) {
|
public CommentDto pin(@PathVariable Long id, Authentication auth) {
|
||||||
return commentMapper.toDto(commentService.pinComment(auth.getName(), id));
|
return commentMapper.toDto(commentService.pinComment(auth.getName(), id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/unpin")
|
@PostMapping("/{id}/unpin")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Unpin comment", description = "Remove pin from a comment")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unpinned comment",
|
||||||
|
content = @Content(schema = @Schema(implementation = CommentDto.class)))
|
||||||
public CommentDto unpin(@PathVariable Long id, Authentication auth) {
|
public CommentDto unpin(@PathVariable Long id, Authentication auth) {
|
||||||
return commentMapper.toDto(commentService.unpinComment(auth.getName(), id));
|
return commentMapper.toDto(commentService.unpinComment(auth.getName(), id));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import com.openisle.service.AiUsageService;
|
|||||||
import com.openisle.service.PasswordValidator;
|
import com.openisle.service.PasswordValidator;
|
||||||
import com.openisle.service.PostService;
|
import com.openisle.service.PostService;
|
||||||
import com.openisle.service.RegisterModeService;
|
import com.openisle.service.RegisterModeService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -18,6 +23,10 @@ public class AdminConfigController {
|
|||||||
private final RegisterModeService registerModeService;
|
private final RegisterModeService registerModeService;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Get configuration", description = "Retrieve application configuration settings")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Current configuration",
|
||||||
|
content = @Content(schema = @Schema(implementation = ConfigDto.class)))
|
||||||
public ConfigDto getConfig() {
|
public ConfigDto getConfig() {
|
||||||
ConfigDto dto = new ConfigDto();
|
ConfigDto dto = new ConfigDto();
|
||||||
dto.setPublishMode(postService.getPublishMode());
|
dto.setPublishMode(postService.getPublishMode());
|
||||||
@@ -28,6 +37,10 @@ public class AdminConfigController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Update configuration", description = "Update application configuration settings")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Updated configuration",
|
||||||
|
content = @Content(schema = @Schema(implementation = ConfigDto.class)))
|
||||||
public ConfigDto updateConfig(@RequestBody ConfigDto dto) {
|
public ConfigDto updateConfig(@RequestBody ConfigDto dto) {
|
||||||
if (dto.getPublishMode() != null) {
|
if (dto.getPublishMode() != null) {
|
||||||
postService.setPublishMode(dto.getPublishMode());
|
postService.setPublishMode(dto.getPublishMode());
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package com.openisle.controller;
|
package com.openisle.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -10,6 +15,10 @@ import java.util.Map;
|
|||||||
@RestController
|
@RestController
|
||||||
public class AdminController {
|
public class AdminController {
|
||||||
@GetMapping("/api/admin/hello")
|
@GetMapping("/api/admin/hello")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Admin greeting", description = "Returns a greeting for admin users")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Greeting payload",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public Map<String, String> adminHello() {
|
public Map<String, String> adminHello() {
|
||||||
return Map.of("message", "Hello, Admin User");
|
return Map.of("message", "Hello, Admin User");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ package com.openisle.controller;
|
|||||||
import com.openisle.dto.PostSummaryDto;
|
import com.openisle.dto.PostSummaryDto;
|
||||||
import com.openisle.mapper.PostMapper;
|
import com.openisle.mapper.PostMapper;
|
||||||
import com.openisle.service.PostService;
|
import com.openisle.service.PostService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -20,6 +26,10 @@ public class AdminPostController {
|
|||||||
private final PostMapper postMapper;
|
private final PostMapper postMapper;
|
||||||
|
|
||||||
@GetMapping("/pending")
|
@GetMapping("/pending")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "List pending posts", description = "Retrieve posts awaiting approval")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Pending posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> pendingPosts() {
|
public List<PostSummaryDto> pendingPosts() {
|
||||||
return postService.listPendingPosts().stream()
|
return postService.listPendingPosts().stream()
|
||||||
.map(postMapper::toSummaryDto)
|
.map(postMapper::toSummaryDto)
|
||||||
@@ -27,31 +37,55 @@ public class AdminPostController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/approve")
|
@PostMapping("/{id}/approve")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Approve post", description = "Approve a pending post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Approved post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostSummaryDto.class)))
|
||||||
public PostSummaryDto approve(@PathVariable Long id) {
|
public PostSummaryDto approve(@PathVariable Long id) {
|
||||||
return postMapper.toSummaryDto(postService.approvePost(id));
|
return postMapper.toSummaryDto(postService.approvePost(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/reject")
|
@PostMapping("/{id}/reject")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Reject post", description = "Reject a pending post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Rejected post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostSummaryDto.class)))
|
||||||
public PostSummaryDto reject(@PathVariable Long id) {
|
public PostSummaryDto reject(@PathVariable Long id) {
|
||||||
return postMapper.toSummaryDto(postService.rejectPost(id));
|
return postMapper.toSummaryDto(postService.rejectPost(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/pin")
|
@PostMapping("/{id}/pin")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Pin post", description = "Pin a post to the top")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Pinned post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostSummaryDto.class)))
|
||||||
public PostSummaryDto pin(@PathVariable Long id, org.springframework.security.core.Authentication auth) {
|
public PostSummaryDto pin(@PathVariable Long id, org.springframework.security.core.Authentication auth) {
|
||||||
return postMapper.toSummaryDto(postService.pinPost(id, auth.getName()));
|
return postMapper.toSummaryDto(postService.pinPost(id, auth.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/unpin")
|
@PostMapping("/{id}/unpin")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Unpin post", description = "Remove a post from the top")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unpinned post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostSummaryDto.class)))
|
||||||
public PostSummaryDto unpin(@PathVariable Long id, org.springframework.security.core.Authentication auth) {
|
public PostSummaryDto unpin(@PathVariable Long id, org.springframework.security.core.Authentication auth) {
|
||||||
return postMapper.toSummaryDto(postService.unpinPost(id, auth.getName()));
|
return postMapper.toSummaryDto(postService.unpinPost(id, auth.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/rss-exclude")
|
@PostMapping("/{id}/rss-exclude")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Exclude from RSS", description = "Exclude a post from RSS feed")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Updated post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostSummaryDto.class)))
|
||||||
public PostSummaryDto excludeFromRss(@PathVariable Long id, org.springframework.security.core.Authentication auth) {
|
public PostSummaryDto excludeFromRss(@PathVariable Long id, org.springframework.security.core.Authentication auth) {
|
||||||
return postMapper.toSummaryDto(postService.excludeFromRss(id, auth.getName()));
|
return postMapper.toSummaryDto(postService.excludeFromRss(id, auth.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/rss-include")
|
@PostMapping("/{id}/rss-include")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Include in RSS", description = "Include a post in the RSS feed")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Updated post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostSummaryDto.class)))
|
||||||
public PostSummaryDto includeInRss(@PathVariable Long id, org.springframework.security.core.Authentication auth) {
|
public PostSummaryDto includeInRss(@PathVariable Long id, org.springframework.security.core.Authentication auth) {
|
||||||
return postMapper.toSummaryDto(postService.includeInRss(id, auth.getName()));
|
return postMapper.toSummaryDto(postService.includeInRss(id, auth.getName()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ import com.openisle.mapper.TagMapper;
|
|||||||
import com.openisle.model.Tag;
|
import com.openisle.model.Tag;
|
||||||
import com.openisle.service.PostService;
|
import com.openisle.service.PostService;
|
||||||
import com.openisle.service.TagService;
|
import com.openisle.service.TagService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -20,6 +26,10 @@ public class AdminTagController {
|
|||||||
private final TagMapper tagMapper;
|
private final TagMapper tagMapper;
|
||||||
|
|
||||||
@GetMapping("/pending")
|
@GetMapping("/pending")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "List pending tags", description = "Retrieve tags awaiting approval")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Pending tags",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = TagDto.class))))
|
||||||
public List<TagDto> pendingTags() {
|
public List<TagDto> pendingTags() {
|
||||||
return tagService.listPendingTags().stream()
|
return tagService.listPendingTags().stream()
|
||||||
.map(t -> tagMapper.toDto(t, postService.countPostsByTag(t.getId())))
|
.map(t -> tagMapper.toDto(t, postService.countPostsByTag(t.getId())))
|
||||||
@@ -27,6 +37,10 @@ public class AdminTagController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/approve")
|
@PostMapping("/{id}/approve")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Approve tag", description = "Approve a pending tag")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Approved tag",
|
||||||
|
content = @Content(schema = @Schema(implementation = TagDto.class)))
|
||||||
public TagDto approve(@PathVariable Long id) {
|
public TagDto approve(@PathVariable Long id) {
|
||||||
Tag tag = tagService.approveTag(id);
|
Tag tag = tagService.approveTag(id);
|
||||||
long count = postService.countPostsByTag(tag.getId());
|
long count = postService.countPostsByTag(tag.getId());
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import com.openisle.model.User;
|
|||||||
import com.openisle.service.EmailSender;
|
import com.openisle.service.EmailSender;
|
||||||
import com.openisle.repository.NotificationRepository;
|
import com.openisle.repository.NotificationRepository;
|
||||||
import com.openisle.repository.UserRepository;
|
import com.openisle.repository.UserRepository;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -22,6 +25,9 @@ public class AdminUserController {
|
|||||||
private String websiteUrl;
|
private String websiteUrl;
|
||||||
|
|
||||||
@PostMapping("/{id}/approve")
|
@PostMapping("/{id}/approve")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Approve user", description = "Approve a pending user registration")
|
||||||
|
@ApiResponse(responseCode = "200", description = "User approved")
|
||||||
public ResponseEntity<?> approve(@PathVariable Long id) {
|
public ResponseEntity<?> approve(@PathVariable Long id) {
|
||||||
User user = userRepository.findById(id).orElseThrow();
|
User user = userRepository.findById(id).orElseThrow();
|
||||||
user.setApproved(true);
|
user.setApproved(true);
|
||||||
@@ -33,6 +39,9 @@ public class AdminUserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/reject")
|
@PostMapping("/{id}/reject")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Reject user", description = "Reject a pending user registration")
|
||||||
|
@ApiResponse(responseCode = "200", description = "User rejected")
|
||||||
public ResponseEntity<?> reject(@PathVariable Long id) {
|
public ResponseEntity<?> reject(@PathVariable Long id) {
|
||||||
User user = userRepository.findById(id).orElseThrow();
|
User user = userRepository.findById(id).orElseThrow();
|
||||||
user.setApproved(false);
|
user.setApproved(false);
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -21,6 +26,10 @@ public class AiController {
|
|||||||
private final AiUsageService aiUsageService;
|
private final AiUsageService aiUsageService;
|
||||||
|
|
||||||
@PostMapping("/format")
|
@PostMapping("/format")
|
||||||
|
@Operation(summary = "Format markdown", description = "Format text via AI")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Formatted content",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<Map<String, String>> format(@RequestBody Map<String, String> req,
|
public ResponseEntity<Map<String, String>> format(@RequestBody Map<String, String> req,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
String text = req.get("text");
|
String text = req.get("text");
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ import com.openisle.model.User;
|
|||||||
import com.openisle.repository.UserRepository;
|
import com.openisle.repository.UserRepository;
|
||||||
import com.openisle.service.*;
|
import com.openisle.service.*;
|
||||||
import com.openisle.util.VerifyType;
|
import com.openisle.util.VerifyType;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
@@ -47,6 +52,9 @@ public class AuthController {
|
|||||||
private boolean loginCaptchaEnabled;
|
private boolean loginCaptchaEnabled;
|
||||||
|
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
|
@Operation(summary = "Register user", description = "Register a new user account")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Registration result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> register(@RequestBody RegisterRequest req) {
|
public ResponseEntity<?> register(@RequestBody RegisterRequest req) {
|
||||||
if (captchaEnabled && registerCaptchaEnabled && !captchaService.verify(req.getCaptcha())) {
|
if (captchaEnabled && registerCaptchaEnabled && !captchaService.verify(req.getCaptcha())) {
|
||||||
return ResponseEntity.badRequest().body(Map.of("error", "Invalid captcha"));
|
return ResponseEntity.badRequest().body(Map.of("error", "Invalid captcha"));
|
||||||
@@ -84,6 +92,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/verify")
|
@PostMapping("/verify")
|
||||||
|
@Operation(summary = "Verify account", description = "Verify registration code")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Verification result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> verify(@RequestBody VerifyRequest req) {
|
public ResponseEntity<?> verify(@RequestBody VerifyRequest req) {
|
||||||
Optional<User> userOpt = userService.findByUsername(req.getUsername());
|
Optional<User> userOpt = userService.findByUsername(req.getUsername());
|
||||||
if (userOpt.isEmpty()) {
|
if (userOpt.isEmpty()) {
|
||||||
@@ -111,6 +122,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
|
@Operation(summary = "Login", description = "Authenticate with username/email and password")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Authentication result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> login(@RequestBody LoginRequest req) {
|
public ResponseEntity<?> login(@RequestBody LoginRequest req) {
|
||||||
if (captchaEnabled && loginCaptchaEnabled && !captchaService.verify(req.getCaptcha())) {
|
if (captchaEnabled && loginCaptchaEnabled && !captchaService.verify(req.getCaptcha())) {
|
||||||
return ResponseEntity.badRequest().body(Map.of("error", "Invalid captcha"));
|
return ResponseEntity.badRequest().body(Map.of("error", "Invalid captcha"));
|
||||||
@@ -149,6 +163,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/google")
|
@PostMapping("/google")
|
||||||
|
@Operation(summary = "Login with Google", description = "Authenticate using Google account")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Authentication result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> loginWithGoogle(@RequestBody GoogleLoginRequest req) {
|
public ResponseEntity<?> loginWithGoogle(@RequestBody GoogleLoginRequest req) {
|
||||||
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
||||||
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
||||||
@@ -196,6 +213,9 @@ public class AuthController {
|
|||||||
|
|
||||||
|
|
||||||
@PostMapping("/reason")
|
@PostMapping("/reason")
|
||||||
|
@Operation(summary = "Submit register reason", description = "Submit registration reason for approval")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Submission result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> reason(@RequestBody MakeReasonRequest req) {
|
public ResponseEntity<?> reason(@RequestBody MakeReasonRequest req) {
|
||||||
String username = jwtService.validateAndGetSubjectForReason(req.getToken());
|
String username = jwtService.validateAndGetSubjectForReason(req.getToken());
|
||||||
Optional<User> userOpt = userService.findByUsername(username);
|
Optional<User> userOpt = userService.findByUsername(username);
|
||||||
@@ -224,6 +244,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/github")
|
@PostMapping("/github")
|
||||||
|
@Operation(summary = "Login with GitHub", description = "Authenticate using GitHub account")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Authentication result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> loginWithGithub(@RequestBody GithubLoginRequest req) {
|
public ResponseEntity<?> loginWithGithub(@RequestBody GithubLoginRequest req) {
|
||||||
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
||||||
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
||||||
@@ -272,6 +295,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/discord")
|
@PostMapping("/discord")
|
||||||
|
@Operation(summary = "Login with Discord", description = "Authenticate using Discord account")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Authentication result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> loginWithDiscord(@RequestBody DiscordLoginRequest req) {
|
public ResponseEntity<?> loginWithDiscord(@RequestBody DiscordLoginRequest req) {
|
||||||
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
||||||
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
||||||
@@ -319,6 +345,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/twitter")
|
@PostMapping("/twitter")
|
||||||
|
@Operation(summary = "Login with Twitter", description = "Authenticate using Twitter account")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Authentication result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> loginWithTwitter(@RequestBody TwitterLoginRequest req) {
|
public ResponseEntity<?> loginWithTwitter(@RequestBody TwitterLoginRequest req) {
|
||||||
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
||||||
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
||||||
@@ -367,6 +396,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/telegram")
|
@PostMapping("/telegram")
|
||||||
|
@Operation(summary = "Login with Telegram", description = "Authenticate using Telegram data")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Authentication result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> loginWithTelegram(@RequestBody TelegramLoginRequest req) {
|
public ResponseEntity<?> loginWithTelegram(@RequestBody TelegramLoginRequest req) {
|
||||||
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
boolean viaInvite = req.getInviteToken() != null && !req.getInviteToken().isEmpty();
|
||||||
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
InviteService.InviteValidateResult inviteValidateResult = inviteService.validate(req.getInviteToken());
|
||||||
@@ -412,11 +444,18 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/check")
|
@GetMapping("/check")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Check token", description = "Validate JWT token")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Token valid",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> checkToken() {
|
public ResponseEntity<?> checkToken() {
|
||||||
return ResponseEntity.ok(Map.of("valid", true));
|
return ResponseEntity.ok(Map.of("valid", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/forgot/send")
|
@PostMapping("/forgot/send")
|
||||||
|
@Operation(summary = "Send reset code", description = "Send verification code for password reset")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Sending result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> sendReset(@RequestBody ForgotPasswordRequest req) {
|
public ResponseEntity<?> sendReset(@RequestBody ForgotPasswordRequest req) {
|
||||||
Optional<User> userOpt = userService.findByEmail(req.getEmail());
|
Optional<User> userOpt = userService.findByEmail(req.getEmail());
|
||||||
if (userOpt.isEmpty()) {
|
if (userOpt.isEmpty()) {
|
||||||
@@ -427,6 +466,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/forgot/verify")
|
@PostMapping("/forgot/verify")
|
||||||
|
@Operation(summary = "Verify reset code", description = "Verify password reset code")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Verification result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> verifyReset(@RequestBody VerifyForgotRequest req) {
|
public ResponseEntity<?> verifyReset(@RequestBody VerifyForgotRequest req) {
|
||||||
Optional<User> userOpt = userService.findByEmail(req.getEmail());
|
Optional<User> userOpt = userService.findByEmail(req.getEmail());
|
||||||
if (userOpt.isEmpty()) {
|
if (userOpt.isEmpty()) {
|
||||||
@@ -441,6 +483,9 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/forgot/reset")
|
@PostMapping("/forgot/reset")
|
||||||
|
@Operation(summary = "Reset password", description = "Reset user password after verification")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Reset result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> resetPassword(@RequestBody ResetPasswordRequest req) {
|
public ResponseEntity<?> resetPassword(@RequestBody ResetPasswordRequest req) {
|
||||||
String username = jwtService.validateAndGetSubjectForReset(req.getToken());
|
String username = jwtService.validateAndGetSubjectForReset(req.getToken());
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ import com.openisle.service.CategoryService;
|
|||||||
import com.openisle.service.PostService;
|
import com.openisle.service.PostService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -25,6 +30,9 @@ public class CategoryController {
|
|||||||
private final CategoryMapper categoryMapper;
|
private final CategoryMapper categoryMapper;
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@Operation(summary = "Create category", description = "Create a new category")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Created category",
|
||||||
|
content = @Content(schema = @Schema(implementation = CategoryDto.class)))
|
||||||
public CategoryDto create(@RequestBody CategoryRequest req) {
|
public CategoryDto create(@RequestBody CategoryRequest req) {
|
||||||
Category c = categoryService.createCategory(req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon());
|
Category c = categoryService.createCategory(req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon());
|
||||||
long count = postService.countPostsByCategory(c.getId());
|
long count = postService.countPostsByCategory(c.getId());
|
||||||
@@ -32,6 +40,9 @@ public class CategoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
|
@Operation(summary = "Update category", description = "Update an existing category")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Updated category",
|
||||||
|
content = @Content(schema = @Schema(implementation = CategoryDto.class)))
|
||||||
public CategoryDto update(@PathVariable Long id, @RequestBody CategoryRequest req) {
|
public CategoryDto update(@PathVariable Long id, @RequestBody CategoryRequest req) {
|
||||||
Category c = categoryService.updateCategory(id, req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon());
|
Category c = categoryService.updateCategory(id, req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon());
|
||||||
long count = postService.countPostsByCategory(c.getId());
|
long count = postService.countPostsByCategory(c.getId());
|
||||||
@@ -39,11 +50,16 @@ public class CategoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
|
@Operation(summary = "Delete category", description = "Remove a category by id")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Category deleted")
|
||||||
public void delete(@PathVariable Long id) {
|
public void delete(@PathVariable Long id) {
|
||||||
categoryService.deleteCategory(id);
|
categoryService.deleteCategory(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "List categories", description = "Get all categories")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of categories",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = CategoryDto.class))))
|
||||||
public List<CategoryDto> list() {
|
public List<CategoryDto> list() {
|
||||||
List<Category> all = categoryService.listCategories();
|
List<Category> all = categoryService.listCategories();
|
||||||
List<Long> ids = all.stream().map(Category::getId).toList();
|
List<Long> ids = all.stream().map(Category::getId).toList();
|
||||||
@@ -55,6 +71,9 @@ public class CategoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
|
@Operation(summary = "Get category", description = "Get category by id")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Category detail",
|
||||||
|
content = @Content(schema = @Schema(implementation = CategoryDto.class)))
|
||||||
public CategoryDto get(@PathVariable Long id) {
|
public CategoryDto get(@PathVariable Long id) {
|
||||||
Category c = categoryService.getCategory(id);
|
Category c = categoryService.getCategory(id);
|
||||||
long count = postService.countPostsByCategory(c.getId());
|
long count = postService.countPostsByCategory(c.getId());
|
||||||
@@ -62,6 +81,9 @@ public class CategoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}/posts")
|
@GetMapping("/{id}/posts")
|
||||||
|
@Operation(summary = "List posts by category", description = "Get posts under a category")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> listPostsByCategory(@PathVariable Long id,
|
public List<PostSummaryDto> listPostsByCategory(@PathVariable Long id,
|
||||||
@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) {
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ import com.openisle.service.MessageService;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -26,16 +32,28 @@ public class ChannelController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "List channels", description = "List channels for the current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Channels",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = ChannelDto.class))))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public List<ChannelDto> listChannels(Authentication auth) {
|
public List<ChannelDto> listChannels(Authentication auth) {
|
||||||
return channelService.listChannels(getCurrentUserId(auth));
|
return channelService.listChannels(getCurrentUserId(auth));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{channelId}/join")
|
@PostMapping("/{channelId}/join")
|
||||||
|
@Operation(summary = "Join channel", description = "Join a channel")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Joined channel",
|
||||||
|
content = @Content(schema = @Schema(implementation = ChannelDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ChannelDto joinChannel(@PathVariable Long channelId, Authentication auth) {
|
public ChannelDto joinChannel(@PathVariable Long channelId, Authentication auth) {
|
||||||
return channelService.joinChannel(channelId, getCurrentUserId(auth));
|
return channelService.joinChannel(channelId, getCurrentUserId(auth));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/unread-count")
|
@GetMapping("/unread-count")
|
||||||
|
@Operation(summary = "Unread count", description = "Get unread channel count")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unread count",
|
||||||
|
content = @Content(schema = @Schema(implementation = Long.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public long unreadCount(Authentication auth) {
|
public long unreadCount(Authentication auth) {
|
||||||
return messageService.getUnreadChannelCount(getCurrentUserId(auth));
|
return messageService.getUnreadChannelCount(getCurrentUserId(auth));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -36,6 +42,10 @@ public class CommentController {
|
|||||||
private boolean commentCaptchaEnabled;
|
private boolean commentCaptchaEnabled;
|
||||||
|
|
||||||
@PostMapping("/posts/{postId}/comments")
|
@PostMapping("/posts/{postId}/comments")
|
||||||
|
@Operation(summary = "Create comment", description = "Add a comment to a post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Created comment",
|
||||||
|
content = @Content(schema = @Schema(implementation = CommentDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<CommentDto> createComment(@PathVariable Long postId,
|
public ResponseEntity<CommentDto> createComment(@PathVariable Long postId,
|
||||||
@RequestBody CommentRequest req,
|
@RequestBody CommentRequest req,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
@@ -53,6 +63,10 @@ public class CommentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/comments/{commentId}/replies")
|
@PostMapping("/comments/{commentId}/replies")
|
||||||
|
@Operation(summary = "Reply to comment", description = "Reply to an existing comment")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Reply created",
|
||||||
|
content = @Content(schema = @Schema(implementation = CommentDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<CommentDto> replyComment(@PathVariable Long commentId,
|
public ResponseEntity<CommentDto> replyComment(@PathVariable Long commentId,
|
||||||
@RequestBody CommentRequest req,
|
@RequestBody CommentRequest req,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
@@ -69,6 +83,9 @@ public class CommentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/posts/{postId}/comments")
|
@GetMapping("/posts/{postId}/comments")
|
||||||
|
@Operation(summary = "List comments", description = "List comments for a post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Comments",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = CommentDto.class))))
|
||||||
public List<CommentDto> listComments(@PathVariable Long postId,
|
public List<CommentDto> listComments(@PathVariable Long postId,
|
||||||
@RequestParam(value = "sort", required = false, defaultValue = "OLDEST") com.openisle.model.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);
|
||||||
@@ -80,6 +97,9 @@ public class CommentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/comments/{id}")
|
@DeleteMapping("/comments/{id}")
|
||||||
|
@Operation(summary = "Delete comment", description = "Delete a comment")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Deleted")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void deleteComment(@PathVariable Long id, Authentication auth) {
|
public void deleteComment(@PathVariable Long id, Authentication auth) {
|
||||||
log.debug("deleteComment called by user {} for comment {}", auth.getName(), id);
|
log.debug("deleteComment called by user {} for comment {}", auth.getName(), id);
|
||||||
commentService.deleteComment(auth.getName(), id);
|
commentService.deleteComment(auth.getName(), id);
|
||||||
@@ -87,12 +107,20 @@ public class CommentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/comments/{id}/pin")
|
@PostMapping("/comments/{id}/pin")
|
||||||
|
@Operation(summary = "Pin comment", description = "Pin a comment")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Pinned comment",
|
||||||
|
content = @Content(schema = @Schema(implementation = CommentDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public CommentDto pinComment(@PathVariable Long id, Authentication auth) {
|
public CommentDto pinComment(@PathVariable Long id, Authentication auth) {
|
||||||
log.debug("pinComment called by user {} for comment {}", auth.getName(), id);
|
log.debug("pinComment called by user {} for comment {}", auth.getName(), id);
|
||||||
return commentMapper.toDto(commentService.pinComment(auth.getName(), id));
|
return commentMapper.toDto(commentService.pinComment(auth.getName(), id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/comments/{id}/unpin")
|
@PostMapping("/comments/{id}/unpin")
|
||||||
|
@Operation(summary = "Unpin comment", description = "Unpin a comment")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unpinned comment",
|
||||||
|
content = @Content(schema = @Schema(implementation = CommentDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public CommentDto unpinComment(@PathVariable Long id, Authentication auth) {
|
public CommentDto unpinComment(@PathVariable Long id, Authentication auth) {
|
||||||
log.debug("unpinComment called by user {} for comment {}", auth.getName(), id);
|
log.debug("unpinComment called by user {} for comment {}", auth.getName(), id);
|
||||||
return commentMapper.toDto(commentService.unpinComment(auth.getName(), id));
|
return commentMapper.toDto(commentService.unpinComment(auth.getName(), id));
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
@@ -33,6 +37,9 @@ public class ConfigController {
|
|||||||
private final RegisterModeService registerModeService;
|
private final RegisterModeService registerModeService;
|
||||||
|
|
||||||
@GetMapping("/config")
|
@GetMapping("/config")
|
||||||
|
@Operation(summary = "Site config", description = "Get site configuration")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Site configuration",
|
||||||
|
content = @Content(schema = @Schema(implementation = SiteConfigDto.class)))
|
||||||
public SiteConfigDto getConfig() {
|
public SiteConfigDto getConfig() {
|
||||||
SiteConfigDto resp = new SiteConfigDto();
|
SiteConfigDto resp = new SiteConfigDto();
|
||||||
resp.setCaptchaEnabled(captchaEnabled);
|
resp.setCaptchaEnabled(captchaEnabled);
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/drafts")
|
@RequestMapping("/api/drafts")
|
||||||
@@ -18,12 +23,20 @@ public class DraftController {
|
|||||||
private final DraftMapper draftMapper;
|
private final DraftMapper draftMapper;
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@Operation(summary = "Save draft", description = "Save a draft for current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Draft saved",
|
||||||
|
content = @Content(schema = @Schema(implementation = DraftDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<DraftDto> saveDraft(@RequestBody DraftRequest req, Authentication auth) {
|
public ResponseEntity<DraftDto> saveDraft(@RequestBody DraftRequest req, Authentication auth) {
|
||||||
Draft draft = draftService.saveDraft(auth.getName(), req.getCategoryId(), req.getTitle(), req.getContent(), req.getTagIds());
|
Draft draft = draftService.saveDraft(auth.getName(), req.getCategoryId(), req.getTitle(), req.getContent(), req.getTagIds());
|
||||||
return ResponseEntity.ok(draftMapper.toDto(draft));
|
return ResponseEntity.ok(draftMapper.toDto(draft));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/me")
|
@GetMapping("/me")
|
||||||
|
@Operation(summary = "Get my draft", description = "Get current user's draft")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Draft details",
|
||||||
|
content = @Content(schema = @Schema(implementation = DraftDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<DraftDto> getMyDraft(Authentication auth) {
|
public ResponseEntity<DraftDto> getMyDraft(Authentication auth) {
|
||||||
return draftService.getDraft(auth.getName())
|
return draftService.getDraft(auth.getName())
|
||||||
.map(d -> ResponseEntity.ok(draftMapper.toDto(d)))
|
.map(d -> ResponseEntity.ok(draftMapper.toDto(d)))
|
||||||
@@ -31,6 +44,9 @@ public class DraftController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/me")
|
@DeleteMapping("/me")
|
||||||
|
@Operation(summary = "Delete my draft", description = "Delete current user's draft")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Draft deleted")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<?> deleteMyDraft(Authentication auth) {
|
public ResponseEntity<?> deleteMyDraft(Authentication auth) {
|
||||||
draftService.deleteDraft(auth.getName());
|
draftService.deleteDraft(auth.getName());
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package com.openisle.controller;
|
package com.openisle.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -7,6 +12,10 @@ import java.util.Map;
|
|||||||
@RestController
|
@RestController
|
||||||
public class HelloController {
|
public class HelloController {
|
||||||
@GetMapping("/api/hello")
|
@GetMapping("/api/hello")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Hello endpoint", description = "Returns a greeting for authenticated users")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Greeting payload",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public Map<String, String> hello() {
|
public Map<String, String> hello() {
|
||||||
return Map.of("message", "Hello, Authenticated User");
|
return Map.of("message", "Hello, Authenticated User");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ import org.springframework.security.core.Authentication;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -16,6 +21,10 @@ public class InviteController {
|
|||||||
private final InviteService inviteService;
|
private final InviteService inviteService;
|
||||||
|
|
||||||
@PostMapping("/generate")
|
@PostMapping("/generate")
|
||||||
|
@Operation(summary = "Generate invite", description = "Generate an invite token")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Invite token",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public Map<String, String> generate(Authentication auth) {
|
public Map<String, String> generate(Authentication auth) {
|
||||||
String token = inviteService.generate(auth.getName());
|
String token = inviteService.generate(auth.getName());
|
||||||
return Map.of("token", token);
|
return Map.of("token", token);
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -17,11 +23,17 @@ public class MedalController {
|
|||||||
private final MedalService medalService;
|
private final MedalService medalService;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "List medals", description = "List medals for user or globally")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of medals",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = MedalDto.class))))
|
||||||
public List<MedalDto> getMedals(@RequestParam(value = "userId", required = false) Long userId) {
|
public List<MedalDto> getMedals(@RequestParam(value = "userId", required = false) Long userId) {
|
||||||
return medalService.getMedals(userId);
|
return medalService.getMedals(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/select")
|
@PostMapping("/select")
|
||||||
|
@Operation(summary = "Select medal", description = "Select a medal for current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Medal selected")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<Void> selectMedal(@RequestBody MedalSelectRequest req, Authentication auth) {
|
public ResponseEntity<Void> selectMedal(@RequestBody MedalSelectRequest req, Authentication auth) {
|
||||||
try {
|
try {
|
||||||
medalService.selectMedal(auth.getName(), req.getType());
|
medalService.selectMedal(auth.getName(), req.getType());
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ import org.springframework.data.domain.Sort;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -37,12 +43,20 @@ public class MessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/conversations")
|
@GetMapping("/conversations")
|
||||||
|
@Operation(summary = "List conversations", description = "Get all conversations of current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of conversations",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConversationDto.class))))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<List<ConversationDto>> getConversations(Authentication auth) {
|
public ResponseEntity<List<ConversationDto>> getConversations(Authentication auth) {
|
||||||
List<ConversationDto> conversations = messageService.getConversations(getCurrentUserId(auth));
|
List<ConversationDto> conversations = messageService.getConversations(getCurrentUserId(auth));
|
||||||
return ResponseEntity.ok(conversations);
|
return ResponseEntity.ok(conversations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/conversations/{conversationId}")
|
@GetMapping("/conversations/{conversationId}")
|
||||||
|
@Operation(summary = "Get conversation", description = "Get messages of a conversation")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Conversation detail",
|
||||||
|
content = @Content(schema = @Schema(implementation = ConversationDetailDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<ConversationDetailDto> getMessages(@PathVariable Long conversationId,
|
public ResponseEntity<ConversationDetailDto> getMessages(@PathVariable Long conversationId,
|
||||||
@RequestParam(defaultValue = "0") int page,
|
@RequestParam(defaultValue = "0") int page,
|
||||||
@RequestParam(defaultValue = "20") int size,
|
@RequestParam(defaultValue = "20") int size,
|
||||||
@@ -53,12 +67,20 @@ public class MessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@Operation(summary = "Send message", description = "Send a direct message to a user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Message sent",
|
||||||
|
content = @Content(schema = @Schema(implementation = MessageDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<MessageDto> sendMessage(@RequestBody MessageRequest req, Authentication auth) {
|
public ResponseEntity<MessageDto> sendMessage(@RequestBody MessageRequest req, Authentication auth) {
|
||||||
Message message = messageService.sendMessage(getCurrentUserId(auth), req.getRecipientId(), req.getContent(), req.getReplyToId());
|
Message message = messageService.sendMessage(getCurrentUserId(auth), req.getRecipientId(), req.getContent(), req.getReplyToId());
|
||||||
return ResponseEntity.ok(messageService.toDto(message));
|
return ResponseEntity.ok(messageService.toDto(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/conversations/{conversationId}/messages")
|
@PostMapping("/conversations/{conversationId}/messages")
|
||||||
|
@Operation(summary = "Send message to conversation", description = "Reply within a conversation")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Message sent",
|
||||||
|
content = @Content(schema = @Schema(implementation = MessageDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<MessageDto> sendMessageToConversation(@PathVariable Long conversationId,
|
public ResponseEntity<MessageDto> sendMessageToConversation(@PathVariable Long conversationId,
|
||||||
@RequestBody ChannelMessageRequest req,
|
@RequestBody ChannelMessageRequest req,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
@@ -67,18 +89,29 @@ public class MessageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/conversations/{conversationId}/read")
|
@PostMapping("/conversations/{conversationId}/read")
|
||||||
|
@Operation(summary = "Mark conversation read", description = "Mark messages in conversation as read")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Marked as read")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<Void> markAsRead(@PathVariable Long conversationId, Authentication auth) {
|
public ResponseEntity<Void> markAsRead(@PathVariable Long conversationId, Authentication auth) {
|
||||||
messageService.markConversationAsRead(conversationId, getCurrentUserId(auth));
|
messageService.markConversationAsRead(conversationId, getCurrentUserId(auth));
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/conversations")
|
@PostMapping("/conversations")
|
||||||
|
@Operation(summary = "Find or create conversation", description = "Find existing or create new conversation with recipient")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Conversation id",
|
||||||
|
content = @Content(schema = @Schema(implementation = CreateConversationResponse.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<CreateConversationResponse> findOrCreateConversation(@RequestBody CreateConversationRequest req, Authentication auth) {
|
public ResponseEntity<CreateConversationResponse> findOrCreateConversation(@RequestBody CreateConversationRequest req, Authentication auth) {
|
||||||
MessageConversation conversation = messageService.findOrCreateConversation(getCurrentUserId(auth), req.getRecipientId());
|
MessageConversation conversation = messageService.findOrCreateConversation(getCurrentUserId(auth), req.getRecipientId());
|
||||||
return ResponseEntity.ok(new CreateConversationResponse(conversation.getId()));
|
return ResponseEntity.ok(new CreateConversationResponse(conversation.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/unread-count")
|
@GetMapping("/unread-count")
|
||||||
|
@Operation(summary = "Unread message count", description = "Get unread message count for current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unread count",
|
||||||
|
content = @Content(schema = @Schema(implementation = Long.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<Long> getUnreadCount(Authentication auth) {
|
public ResponseEntity<Long> getUnreadCount(Authentication auth) {
|
||||||
return ResponseEntity.ok(messageService.getUnreadMessageCount(getCurrentUserId(auth)));
|
return ResponseEntity.ok(messageService.getUnreadMessageCount(getCurrentUserId(auth)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ import com.openisle.service.NotificationService;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -23,6 +29,10 @@ public class NotificationController {
|
|||||||
private final NotificationMapper notificationMapper;
|
private final NotificationMapper notificationMapper;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "List notifications", description = "Retrieve notifications for the current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Notifications",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = NotificationDto.class))))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public List<NotificationDto> list(@RequestParam(value = "page", defaultValue = "0") int page,
|
public List<NotificationDto> list(@RequestParam(value = "page", defaultValue = "0") int page,
|
||||||
@RequestParam(value = "size", defaultValue = "30") int size,
|
@RequestParam(value = "size", defaultValue = "30") int size,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
@@ -32,6 +42,10 @@ public class NotificationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/unread")
|
@GetMapping("/unread")
|
||||||
|
@Operation(summary = "List unread notifications", description = "Retrieve unread notifications for the current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unread notifications",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = NotificationDto.class))))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public List<NotificationDto> listUnread(@RequestParam(value = "page", defaultValue = "0") int page,
|
public List<NotificationDto> listUnread(@RequestParam(value = "page", defaultValue = "0") int page,
|
||||||
@RequestParam(value = "size", defaultValue = "30") int size,
|
@RequestParam(value = "size", defaultValue = "30") int size,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
@@ -41,6 +55,10 @@ public class NotificationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/unread-count")
|
@GetMapping("/unread-count")
|
||||||
|
@Operation(summary = "Unread count", description = "Get count of unread notifications")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unread count",
|
||||||
|
content = @Content(schema = @Schema(implementation = NotificationUnreadCountDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public NotificationUnreadCountDto unreadCount(Authentication auth) {
|
public NotificationUnreadCountDto unreadCount(Authentication auth) {
|
||||||
long count = notificationService.countUnread(auth.getName());
|
long count = notificationService.countUnread(auth.getName());
|
||||||
NotificationUnreadCountDto uc = new NotificationUnreadCountDto();
|
NotificationUnreadCountDto uc = new NotificationUnreadCountDto();
|
||||||
@@ -49,26 +67,43 @@ public class NotificationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/read")
|
@PostMapping("/read")
|
||||||
|
@Operation(summary = "Mark notifications read", description = "Mark notifications as read")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Marked read")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void markRead(@RequestBody NotificationMarkReadRequest req, Authentication auth) {
|
public void markRead(@RequestBody NotificationMarkReadRequest req, Authentication auth) {
|
||||||
notificationService.markRead(auth.getName(), req.getIds());
|
notificationService.markRead(auth.getName(), req.getIds());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/prefs")
|
@GetMapping("/prefs")
|
||||||
|
@Operation(summary = "List preferences", description = "List notification preferences")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Preferences",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = NotificationPreferenceDto.class))))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public List<NotificationPreferenceDto> prefs(Authentication auth) {
|
public List<NotificationPreferenceDto> prefs(Authentication auth) {
|
||||||
return notificationService.listPreferences(auth.getName());
|
return notificationService.listPreferences(auth.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/prefs")
|
@PostMapping("/prefs")
|
||||||
|
@Operation(summary = "Update preference", description = "Update notification preference")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Preference updated")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void updatePref(@RequestBody NotificationPreferenceUpdateRequest req, Authentication auth) {
|
public void updatePref(@RequestBody NotificationPreferenceUpdateRequest req, Authentication auth) {
|
||||||
notificationService.updatePreference(auth.getName(), req.getType(), req.isEnabled());
|
notificationService.updatePreference(auth.getName(), req.getType(), req.isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/email-prefs")
|
@GetMapping("/email-prefs")
|
||||||
|
@Operation(summary = "List email preferences", description = "List email notification preferences")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Email preferences",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = NotificationPreferenceDto.class))))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public List<NotificationPreferenceDto> emailPrefs(Authentication auth) {
|
public List<NotificationPreferenceDto> emailPrefs(Authentication auth) {
|
||||||
return notificationService.listEmailPreferences(auth.getName());
|
return notificationService.listEmailPreferences(auth.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/email-prefs")
|
@PostMapping("/email-prefs")
|
||||||
|
@Operation(summary = "Update email preference", description = "Update email notification preference")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Email preference updated")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void updateEmailPref(@RequestBody NotificationPreferenceUpdateRequest req, Authentication auth) {
|
public void updateEmailPref(@RequestBody NotificationPreferenceUpdateRequest req, Authentication auth) {
|
||||||
notificationService.updateEmailPreference(auth.getName(), req.getType(), req.isEnabled());
|
notificationService.updateEmailPreference(auth.getName(), req.getType(), req.isEnabled());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
@@ -22,11 +26,16 @@ public class OnlineController {
|
|||||||
private static final String ONLINE_KEY = CachingConfig.ONLINE_CACHE_NAME +":";
|
private static final String ONLINE_KEY = CachingConfig.ONLINE_CACHE_NAME +":";
|
||||||
|
|
||||||
@PostMapping("/heartbeat")
|
@PostMapping("/heartbeat")
|
||||||
|
@Operation(summary = "Heartbeat", description = "Record user heartbeat")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Heartbeat recorded")
|
||||||
public void ping(@RequestParam String userId){
|
public void ping(@RequestParam String userId){
|
||||||
redisTemplate.opsForValue().set(ONLINE_KEY+userId,"1", Duration.ofSeconds(150));
|
redisTemplate.opsForValue().set(ONLINE_KEY+userId,"1", Duration.ofSeconds(150));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/count")
|
@GetMapping("/count")
|
||||||
|
@Operation(summary = "Online count", description = "Get current online user count")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Online count",
|
||||||
|
content = @Content(schema = @Schema(implementation = Long.class)))
|
||||||
public long count(){
|
public long count(){
|
||||||
return redisTemplate.keys(ONLINE_KEY+"*").size();
|
return redisTemplate.keys(ONLINE_KEY+"*").size();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -22,6 +28,10 @@ public class PointHistoryController {
|
|||||||
private final PointHistoryMapper pointHistoryMapper;
|
private final PointHistoryMapper pointHistoryMapper;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "Point history", description = "List point history for current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of point histories",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PointHistoryDto.class))))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public List<PointHistoryDto> list(Authentication auth) {
|
public List<PointHistoryDto> list(Authentication auth) {
|
||||||
return pointService.listHistory(auth.getName()).stream()
|
return pointService.listHistory(auth.getName()).stream()
|
||||||
.map(pointHistoryMapper::toDto)
|
.map(pointHistoryMapper::toDto)
|
||||||
@@ -29,6 +39,10 @@ public class PointHistoryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/trend")
|
@GetMapping("/trend")
|
||||||
|
@Operation(summary = "Point trend", description = "Get point trend data for current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Trend data",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = java.util.Map.class))))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public List<Map<String, Object>> trend(Authentication auth,
|
public List<Map<String, Object>> trend(Authentication auth,
|
||||||
@RequestParam(value = "days", defaultValue = "30") int days) {
|
@RequestParam(value = "days", defaultValue = "30") int days) {
|
||||||
return pointService.trend(auth.getName(), days);
|
return pointService.trend(auth.getName(), days);
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ import com.openisle.service.UserService;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -24,6 +30,9 @@ public class PointMallController {
|
|||||||
private final PointGoodMapper pointGoodMapper;
|
private final PointGoodMapper pointGoodMapper;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "List goods", description = "List all point goods")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of goods",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PointGoodDto.class))))
|
||||||
public List<PointGoodDto> list() {
|
public List<PointGoodDto> list() {
|
||||||
return pointMallService.listGoods().stream()
|
return pointMallService.listGoods().stream()
|
||||||
.map(pointGoodMapper::toDto)
|
.map(pointGoodMapper::toDto)
|
||||||
@@ -31,6 +40,10 @@ public class PointMallController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/redeem")
|
@PostMapping("/redeem")
|
||||||
|
@Operation(summary = "Redeem good", description = "Redeem a point good")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Remaining points",
|
||||||
|
content = @Content(schema = @Schema(implementation = java.util.Map.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public Map<String, Integer> redeem(@RequestBody PointRedeemRequest req, Authentication auth) {
|
public Map<String, Integer> redeem(@RequestBody PointRedeemRequest req, Authentication auth) {
|
||||||
User user = userService.findByIdentifier(auth.getName()).orElseThrow();
|
User user = userService.findByIdentifier(auth.getName()).orElseThrow();
|
||||||
int point = pointMallService.redeem(user, req.getGoodId(), req.getContact());
|
int point = pointMallService.redeem(user, req.getGoodId(), req.getContact());
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import com.openisle.mapper.PostChangeLogMapper;
|
|||||||
import com.openisle.service.PostChangeLogService;
|
import com.openisle.service.PostChangeLogService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -17,6 +22,9 @@ public class PostChangeLogController {
|
|||||||
private final PostChangeLogMapper mapper;
|
private final PostChangeLogMapper mapper;
|
||||||
|
|
||||||
@GetMapping("/{id}/change-logs")
|
@GetMapping("/{id}/change-logs")
|
||||||
|
@Operation(summary = "Post change logs", description = "List change logs for a post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Change logs",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostChangeLogDto.class))))
|
||||||
public List<PostChangeLogDto> listLogs(@PathVariable Long id) {
|
public List<PostChangeLogDto> listLogs(@PathVariable Long id) {
|
||||||
return changeLogService.listLogs(id).stream()
|
return changeLogService.listLogs(id).stream()
|
||||||
.map(mapper::toDto)
|
.map(mapper::toDto)
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ import com.openisle.dto.PollDto;
|
|||||||
import com.openisle.mapper.PostMapper;
|
import com.openisle.mapper.PostMapper;
|
||||||
import com.openisle.model.Post;
|
import com.openisle.model.Post;
|
||||||
import com.openisle.service.*;
|
import com.openisle.service.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -35,6 +41,10 @@ public class PostController {
|
|||||||
private boolean postCaptchaEnabled;
|
private boolean postCaptchaEnabled;
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Create post", description = "Create a new post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Created post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostDetailDto.class)))
|
||||||
public ResponseEntity<PostDetailDto> createPost(@RequestBody PostRequest req, Authentication auth) {
|
public ResponseEntity<PostDetailDto> createPost(@RequestBody PostRequest req, Authentication auth) {
|
||||||
if (captchaEnabled && postCaptchaEnabled && !captchaService.verify(req.getCaptcha())) {
|
if (captchaEnabled && postCaptchaEnabled && !captchaService.verify(req.getCaptcha())) {
|
||||||
return ResponseEntity.badRequest().build();
|
return ResponseEntity.badRequest().build();
|
||||||
@@ -53,6 +63,10 @@ public class PostController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Update post", description = "Update an existing post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Updated post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostDetailDto.class)))
|
||||||
public ResponseEntity<PostDetailDto> updatePost(@PathVariable Long id, @RequestBody PostRequest req,
|
public ResponseEntity<PostDetailDto> updatePost(@PathVariable Long id, @RequestBody PostRequest req,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
Post post = postService.updatePost(id, auth.getName(), req.getCategoryId(),
|
Post post = postService.updatePost(id, auth.getName(), req.getCategoryId(),
|
||||||
@@ -61,21 +75,35 @@ public class PostController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Delete post", description = "Delete a post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Post deleted")
|
||||||
public void deletePost(@PathVariable Long id, Authentication auth) {
|
public void deletePost(@PathVariable Long id, Authentication auth) {
|
||||||
postService.deletePost(id, auth.getName());
|
postService.deletePost(id, auth.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/close")
|
@PostMapping("/{id}/close")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Close post", description = "Close a post to prevent further replies")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Closed post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostSummaryDto.class)))
|
||||||
public PostSummaryDto close(@PathVariable Long id, Authentication auth) {
|
public PostSummaryDto close(@PathVariable Long id, Authentication auth) {
|
||||||
return postMapper.toSummaryDto(postService.closePost(id, auth.getName()));
|
return postMapper.toSummaryDto(postService.closePost(id, auth.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/reopen")
|
@PostMapping("/{id}/reopen")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Reopen post", description = "Reopen a closed post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Reopened post",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostSummaryDto.class)))
|
||||||
public PostSummaryDto reopen(@PathVariable Long id, Authentication auth) {
|
public PostSummaryDto reopen(@PathVariable Long id, Authentication auth) {
|
||||||
return postMapper.toSummaryDto(postService.reopenPost(id, auth.getName()));
|
return postMapper.toSummaryDto(postService.reopenPost(id, auth.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
|
@Operation(summary = "Get post", description = "Get post details by id")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Post detail",
|
||||||
|
content = @Content(schema = @Schema(implementation = PostDetailDto.class)))
|
||||||
public ResponseEntity<PostDetailDto> getPost(@PathVariable Long id, Authentication auth) {
|
public ResponseEntity<PostDetailDto> getPost(@PathVariable Long id, Authentication auth) {
|
||||||
String viewer = auth != null ? auth.getName() : null;
|
String viewer = auth != null ? auth.getName() : null;
|
||||||
Post post = postService.viewPost(id, viewer);
|
Post post = postService.viewPost(id, viewer);
|
||||||
@@ -83,23 +111,35 @@ public class PostController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/lottery/join")
|
@PostMapping("/{id}/lottery/join")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Join lottery", description = "Join a lottery for the post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Joined lottery")
|
||||||
public ResponseEntity<Void> joinLottery(@PathVariable Long id, Authentication auth) {
|
public ResponseEntity<Void> joinLottery(@PathVariable Long id, Authentication auth) {
|
||||||
postService.joinLottery(id, auth.getName());
|
postService.joinLottery(id, auth.getName());
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}/poll/progress")
|
@GetMapping("/{id}/poll/progress")
|
||||||
|
@Operation(summary = "Poll progress", description = "Get poll progress for a post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Poll progress",
|
||||||
|
content = @Content(schema = @Schema(implementation = PollDto.class)))
|
||||||
public ResponseEntity<PollDto> pollProgress(@PathVariable Long id) {
|
public ResponseEntity<PollDto> pollProgress(@PathVariable Long id) {
|
||||||
return ResponseEntity.ok(postMapper.toSummaryDto(postService.getPoll(id)).getPoll());
|
return ResponseEntity.ok(postMapper.toSummaryDto(postService.getPoll(id)).getPoll());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/poll/vote")
|
@PostMapping("/{id}/poll/vote")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Vote poll", description = "Vote on a poll option")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Vote recorded")
|
||||||
public ResponseEntity<Void> vote(@PathVariable Long id, @RequestParam("option") List<Integer> option, Authentication auth) {
|
public ResponseEntity<Void> vote(@PathVariable Long id, @RequestParam("option") List<Integer> option, Authentication auth) {
|
||||||
postService.votePoll(id, auth.getName(), option);
|
postService.votePoll(id, auth.getName(), option);
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "List posts", description = "List posts by various filters")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> listPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
public List<PostSummaryDto> listPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
||||||
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
||||||
@RequestParam(value = "tagId", required = false) Long tagId,
|
@RequestParam(value = "tagId", required = false) Long tagId,
|
||||||
@@ -115,10 +155,10 @@ public class PostController {
|
|||||||
if (tagId != null) {
|
if (tagId != null) {
|
||||||
tids = java.util.List.of(tagId);
|
tids = java.util.List.of(tagId);
|
||||||
}
|
}
|
||||||
|
// 只需要在请求的一开始统计一次
|
||||||
if (auth != null) {
|
// if (auth != null) {
|
||||||
userVisitService.recordVisit(auth.getName());
|
// userVisitService.recordVisit(auth.getName());
|
||||||
}
|
// }
|
||||||
|
|
||||||
boolean hasCategories = ids != null && !ids.isEmpty();
|
boolean hasCategories = ids != null && !ids.isEmpty();
|
||||||
boolean hasTags = tids != null && !tids.isEmpty();
|
boolean hasTags = tids != null && !tids.isEmpty();
|
||||||
@@ -137,6 +177,9 @@ public class PostController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/ranking")
|
@GetMapping("/ranking")
|
||||||
|
@Operation(summary = "Ranking posts", description = "List posts by view rankings")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Ranked posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> rankingPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
public List<PostSummaryDto> rankingPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
||||||
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
||||||
@RequestParam(value = "tagId", required = false) Long tagId,
|
@RequestParam(value = "tagId", required = false) Long tagId,
|
||||||
@@ -152,16 +195,19 @@ public class PostController {
|
|||||||
if (tagId != null) {
|
if (tagId != null) {
|
||||||
tids = java.util.List.of(tagId);
|
tids = java.util.List.of(tagId);
|
||||||
}
|
}
|
||||||
|
// 只需要在请求的一开始统计一次
|
||||||
if (auth != null) {
|
// if (auth != null) {
|
||||||
userVisitService.recordVisit(auth.getName());
|
// userVisitService.recordVisit(auth.getName());
|
||||||
}
|
// }
|
||||||
|
|
||||||
return postService.listPostsByViews(ids, tids, page, pageSize)
|
return postService.listPostsByViews(ids, tids, page, pageSize)
|
||||||
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/latest-reply")
|
@GetMapping("/latest-reply")
|
||||||
|
@Operation(summary = "Latest reply posts", description = "List posts by latest replies")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Posts sorted by latest reply",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> latestReplyPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
public List<PostSummaryDto> latestReplyPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
||||||
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
||||||
@RequestParam(value = "tagId", required = false) Long tagId,
|
@RequestParam(value = "tagId", required = false) Long tagId,
|
||||||
@@ -177,16 +223,19 @@ public class PostController {
|
|||||||
if (tagId != null) {
|
if (tagId != null) {
|
||||||
tids = java.util.List.of(tagId);
|
tids = java.util.List.of(tagId);
|
||||||
}
|
}
|
||||||
|
// 只需要在请求的一开始统计一次
|
||||||
if (auth != null) {
|
// if (auth != null) {
|
||||||
userVisitService.recordVisit(auth.getName());
|
// userVisitService.recordVisit(auth.getName());
|
||||||
}
|
// }
|
||||||
|
|
||||||
return postService.listPostsByLatestReply(ids, tids, page, pageSize)
|
return postService.listPostsByLatestReply(ids, tids, page, pageSize)
|
||||||
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/featured")
|
@GetMapping("/featured")
|
||||||
|
@Operation(summary = "Featured posts", description = "List featured posts")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Featured posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> featuredPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
public List<PostSummaryDto> featuredPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
||||||
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
||||||
@RequestParam(value = "tagId", required = false) Long tagId,
|
@RequestParam(value = "tagId", required = false) Long tagId,
|
||||||
@@ -202,9 +251,10 @@ public class PostController {
|
|||||||
if (tagId != null) {
|
if (tagId != null) {
|
||||||
tids = java.util.List.of(tagId);
|
tids = java.util.List.of(tagId);
|
||||||
}
|
}
|
||||||
if (auth != null) {
|
// 只需要在请求的一开始统计一次
|
||||||
userVisitService.recordVisit(auth.getName());
|
// if (auth != null) {
|
||||||
}
|
// userVisitService.recordVisit(auth.getName());
|
||||||
|
// }
|
||||||
return postService.listFeaturedPosts(ids, tids, page, pageSize)
|
return postService.listFeaturedPosts(ids, tids, page, pageSize)
|
||||||
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
.stream().map(postMapper::toSummaryDto).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/push")
|
@RequestMapping("/api/push")
|
||||||
@@ -17,6 +22,9 @@ public class PushSubscriptionController {
|
|||||||
private String publicKey;
|
private String publicKey;
|
||||||
|
|
||||||
@GetMapping("/public-key")
|
@GetMapping("/public-key")
|
||||||
|
@Operation(summary = "Get public key", description = "Retrieve web push public key")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Public key",
|
||||||
|
content = @Content(schema = @Schema(implementation = PushPublicKeyDto.class)))
|
||||||
public PushPublicKeyDto getPublicKey() {
|
public PushPublicKeyDto getPublicKey() {
|
||||||
PushPublicKeyDto r = new PushPublicKeyDto();
|
PushPublicKeyDto r = new PushPublicKeyDto();
|
||||||
r.setKey(publicKey);
|
r.setKey(publicKey);
|
||||||
@@ -24,6 +32,9 @@ public class PushSubscriptionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/subscribe")
|
@PostMapping("/subscribe")
|
||||||
|
@Operation(summary = "Subscribe", description = "Subscribe to push notifications")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Subscribed")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void subscribe(@RequestBody PushSubscriptionRequest req, Authentication auth) {
|
public void subscribe(@RequestBody PushSubscriptionRequest req, Authentication auth) {
|
||||||
pushSubscriptionService.saveSubscription(auth.getName(), req.getEndpoint(), req.getP256dh(), req.getAuth());
|
pushSubscriptionService.saveSubscription(auth.getName(), req.getEndpoint(), req.getP256dh(), req.getAuth());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
@@ -26,11 +31,18 @@ public class ReactionController {
|
|||||||
* Get all available reaction types.
|
* Get all available reaction types.
|
||||||
*/
|
*/
|
||||||
@GetMapping("/reaction-types")
|
@GetMapping("/reaction-types")
|
||||||
|
@Operation(summary = "List reaction types", description = "Get all available reaction types")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Reaction types",
|
||||||
|
content = @Content(schema = @Schema(implementation = ReactionType[].class)))
|
||||||
public ReactionType[] listReactionTypes() {
|
public ReactionType[] listReactionTypes() {
|
||||||
return ReactionType.values();
|
return ReactionType.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/posts/{postId}/reactions")
|
@PostMapping("/posts/{postId}/reactions")
|
||||||
|
@Operation(summary = "React to post", description = "React to a post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Reaction result",
|
||||||
|
content = @Content(schema = @Schema(implementation = ReactionDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<ReactionDto> reactToPost(@PathVariable Long postId,
|
public ResponseEntity<ReactionDto> reactToPost(@PathVariable Long postId,
|
||||||
@RequestBody ReactionRequest req,
|
@RequestBody ReactionRequest req,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
@@ -46,6 +58,10 @@ public class ReactionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/comments/{commentId}/reactions")
|
@PostMapping("/comments/{commentId}/reactions")
|
||||||
|
@Operation(summary = "React to comment", description = "React to a comment")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Reaction result",
|
||||||
|
content = @Content(schema = @Schema(implementation = ReactionDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<ReactionDto> reactToComment(@PathVariable Long commentId,
|
public ResponseEntity<ReactionDto> reactToComment(@PathVariable Long commentId,
|
||||||
@RequestBody ReactionRequest req,
|
@RequestBody ReactionRequest req,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
@@ -61,6 +77,10 @@ public class ReactionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/messages/{messageId}/reactions")
|
@PostMapping("/messages/{messageId}/reactions")
|
||||||
|
@Operation(summary = "React to message", description = "React to a message")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Reaction result",
|
||||||
|
content = @Content(schema = @Schema(implementation = ReactionDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public ResponseEntity<ReactionDto> reactToMessage(@PathVariable Long messageId,
|
public ResponseEntity<ReactionDto> reactToMessage(@PathVariable Long messageId,
|
||||||
@RequestBody ReactionRequest req,
|
@RequestBody ReactionRequest req,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ import org.jsoup.safety.Safelist;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
|
import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
|
||||||
import com.vladsch.flexmark.ext.tables.TablesExtension;
|
import com.vladsch.flexmark.ext.tables.TablesExtension;
|
||||||
@@ -63,6 +67,8 @@ public class RssController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/api/rss", produces = "application/rss+xml;charset=UTF-8")
|
@GetMapping(value = "/api/rss", produces = "application/rss+xml;charset=UTF-8")
|
||||||
|
@Operation(summary = "RSS feed", description = "Generate RSS feed for latest posts")
|
||||||
|
@ApiResponse(responseCode = "200", description = "RSS XML", content = @Content(schema = @Schema(implementation = String.class)))
|
||||||
public String feed() {
|
public String feed() {
|
||||||
// 建议 20;你现在是 10,这里保留你的 10
|
// 建议 20;你现在是 10,这里保留你的 10
|
||||||
List<Post> posts = postService.listLatestRssPosts(10);
|
List<Post> posts = postService.listLatestRssPosts(10);
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -24,6 +29,9 @@ public class SearchController {
|
|||||||
private final PostMapper postMapper;
|
private final PostMapper postMapper;
|
||||||
|
|
||||||
@GetMapping("/users")
|
@GetMapping("/users")
|
||||||
|
@Operation(summary = "Search users", description = "Search users by keyword")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of users",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserDto.class))))
|
||||||
public List<UserDto> searchUsers(@RequestParam String keyword) {
|
public List<UserDto> searchUsers(@RequestParam String keyword) {
|
||||||
return searchService.searchUsers(keyword).stream()
|
return searchService.searchUsers(keyword).stream()
|
||||||
.map(userMapper::toDto)
|
.map(userMapper::toDto)
|
||||||
@@ -31,6 +39,9 @@ public class SearchController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/posts")
|
@GetMapping("/posts")
|
||||||
|
@Operation(summary = "Search posts", description = "Search posts by keyword")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> searchPosts(@RequestParam String keyword) {
|
public List<PostSummaryDto> searchPosts(@RequestParam String keyword) {
|
||||||
return searchService.searchPosts(keyword).stream()
|
return searchService.searchPosts(keyword).stream()
|
||||||
.map(postMapper::toSummaryDto)
|
.map(postMapper::toSummaryDto)
|
||||||
@@ -38,6 +49,9 @@ public class SearchController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/posts/content")
|
@GetMapping("/posts/content")
|
||||||
|
@Operation(summary = "Search posts by content", description = "Search posts by content keyword")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> searchPostsByContent(@RequestParam String keyword) {
|
public List<PostSummaryDto> searchPostsByContent(@RequestParam String keyword) {
|
||||||
return searchService.searchPostsByContent(keyword).stream()
|
return searchService.searchPostsByContent(keyword).stream()
|
||||||
.map(postMapper::toSummaryDto)
|
.map(postMapper::toSummaryDto)
|
||||||
@@ -45,6 +59,9 @@ public class SearchController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/posts/title")
|
@GetMapping("/posts/title")
|
||||||
|
@Operation(summary = "Search posts by title", description = "Search posts by title keyword")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> searchPostsByTitle(@RequestParam String keyword) {
|
public List<PostSummaryDto> searchPostsByTitle(@RequestParam String keyword) {
|
||||||
return searchService.searchPostsByTitle(keyword).stream()
|
return searchService.searchPostsByTitle(keyword).stream()
|
||||||
.map(postMapper::toSummaryDto)
|
.map(postMapper::toSummaryDto)
|
||||||
@@ -52,6 +69,9 @@ public class SearchController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/global")
|
@GetMapping("/global")
|
||||||
|
@Operation(summary = "Global search", description = "Search users and posts globally")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Search results",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = SearchResultDto.class))))
|
||||||
public List<SearchResultDto> global(@RequestParam String keyword) {
|
public List<SearchResultDto> global(@RequestParam String keyword) {
|
||||||
return searchService.globalSearch(keyword).stream()
|
return searchService.globalSearch(keyword).stream()
|
||||||
.map(r -> {
|
.map(r -> {
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -26,6 +30,9 @@ public class SitemapController {
|
|||||||
private String websiteUrl;
|
private String websiteUrl;
|
||||||
|
|
||||||
@GetMapping(value = "/sitemap.xml", produces = MediaType.APPLICATION_XML_VALUE)
|
@GetMapping(value = "/sitemap.xml", produces = MediaType.APPLICATION_XML_VALUE)
|
||||||
|
@Operation(summary = "Sitemap", description = "Generate sitemap xml")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Sitemap xml",
|
||||||
|
content = @Content(schema = @Schema(implementation = String.class)))
|
||||||
public ResponseEntity<String> sitemap() {
|
public ResponseEntity<String> sitemap() {
|
||||||
List<Post> posts = postRepository.findByStatus(PostStatus.PUBLISHED);
|
List<Post> posts = postRepository.findByStatus(PostStatus.PUBLISHED);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,6 +26,9 @@ public class StatController {
|
|||||||
private final StatService statService;
|
private final StatService statService;
|
||||||
|
|
||||||
@GetMapping("/dau")
|
@GetMapping("/dau")
|
||||||
|
@Operation(summary = "Daily active users", description = "Get daily active user count")
|
||||||
|
@ApiResponse(responseCode = "200", description = "DAU count",
|
||||||
|
content = @Content(schema = @Schema(implementation = java.util.Map.class)))
|
||||||
public Map<String, Long> dau(@RequestParam(value = "date", required = false)
|
public Map<String, Long> dau(@RequestParam(value = "date", required = false)
|
||||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
|
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
|
||||||
long count = userVisitService.countDau(date);
|
long count = userVisitService.countDau(date);
|
||||||
@@ -28,6 +36,9 @@ public class StatController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/dau-range")
|
@GetMapping("/dau-range")
|
||||||
|
@Operation(summary = "DAU range", description = "Get daily active users over range of days")
|
||||||
|
@ApiResponse(responseCode = "200", description = "DAU data",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = java.util.Map.class))))
|
||||||
public List<Map<String, Object>> dauRange(@RequestParam(value = "days", defaultValue = "30") int days) {
|
public List<Map<String, Object>> dauRange(@RequestParam(value = "days", defaultValue = "30") int days) {
|
||||||
if (days < 1) days = 1;
|
if (days < 1) days = 1;
|
||||||
LocalDate end = LocalDate.now();
|
LocalDate end = LocalDate.now();
|
||||||
@@ -42,6 +53,9 @@ public class StatController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/new-users-range")
|
@GetMapping("/new-users-range")
|
||||||
|
@Operation(summary = "New users range", description = "Get new users over range of days")
|
||||||
|
@ApiResponse(responseCode = "200", description = "New user data",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = java.util.Map.class))))
|
||||||
public List<Map<String, Object>> newUsersRange(@RequestParam(value = "days", defaultValue = "30") int days) {
|
public List<Map<String, Object>> newUsersRange(@RequestParam(value = "days", defaultValue = "30") int days) {
|
||||||
if (days < 1) days = 1;
|
if (days < 1) days = 1;
|
||||||
LocalDate end = LocalDate.now();
|
LocalDate end = LocalDate.now();
|
||||||
@@ -56,6 +70,9 @@ public class StatController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/posts-range")
|
@GetMapping("/posts-range")
|
||||||
|
@Operation(summary = "Posts range", description = "Get posts count over range of days")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Post data",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = java.util.Map.class))))
|
||||||
public List<Map<String, Object>> postsRange(@RequestParam(value = "days", defaultValue = "30") int days) {
|
public List<Map<String, Object>> postsRange(@RequestParam(value = "days", defaultValue = "30") int days) {
|
||||||
if (days < 1) days = 1;
|
if (days < 1) days = 1;
|
||||||
LocalDate end = LocalDate.now();
|
LocalDate end = LocalDate.now();
|
||||||
@@ -70,6 +87,9 @@ public class StatController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/comments-range")
|
@GetMapping("/comments-range")
|
||||||
|
@Operation(summary = "Comments range", description = "Get comments count over range of days")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Comment data",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = java.util.Map.class))))
|
||||||
public List<Map<String, Object>> commentsRange(@RequestParam(value = "days", defaultValue = "30") int days) {
|
public List<Map<String, Object>> commentsRange(@RequestParam(value = "days", defaultValue = "30") int days) {
|
||||||
if (days < 1) days = 1;
|
if (days < 1) days = 1;
|
||||||
LocalDate end = LocalDate.now();
|
LocalDate end = LocalDate.now();
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import com.openisle.service.SubscriptionService;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
/** Endpoints for subscribing to posts, comments and users. */
|
/** Endpoints for subscribing to posts, comments and users. */
|
||||||
@RestController
|
@RestController
|
||||||
@@ -13,31 +16,49 @@ public class SubscriptionController {
|
|||||||
private final SubscriptionService subscriptionService;
|
private final SubscriptionService subscriptionService;
|
||||||
|
|
||||||
@PostMapping("/posts/{postId}")
|
@PostMapping("/posts/{postId}")
|
||||||
|
@Operation(summary = "Subscribe post", description = "Subscribe to a post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Subscribed")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void subscribePost(@PathVariable Long postId, Authentication auth) {
|
public void subscribePost(@PathVariable Long postId, Authentication auth) {
|
||||||
subscriptionService.subscribePost(auth.getName(), postId);
|
subscriptionService.subscribePost(auth.getName(), postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/posts/{postId}")
|
@DeleteMapping("/posts/{postId}")
|
||||||
|
@Operation(summary = "Unsubscribe post", description = "Unsubscribe from a post")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unsubscribed")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void unsubscribePost(@PathVariable Long postId, Authentication auth) {
|
public void unsubscribePost(@PathVariable Long postId, Authentication auth) {
|
||||||
subscriptionService.unsubscribePost(auth.getName(), postId);
|
subscriptionService.unsubscribePost(auth.getName(), postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/comments/{commentId}")
|
@PostMapping("/comments/{commentId}")
|
||||||
|
@Operation(summary = "Subscribe comment", description = "Subscribe to a comment")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Subscribed")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void subscribeComment(@PathVariable Long commentId, Authentication auth) {
|
public void subscribeComment(@PathVariable Long commentId, Authentication auth) {
|
||||||
subscriptionService.subscribeComment(auth.getName(), commentId);
|
subscriptionService.subscribeComment(auth.getName(), commentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/comments/{commentId}")
|
@DeleteMapping("/comments/{commentId}")
|
||||||
|
@Operation(summary = "Unsubscribe comment", description = "Unsubscribe from a comment")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unsubscribed")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void unsubscribeComment(@PathVariable Long commentId, Authentication auth) {
|
public void unsubscribeComment(@PathVariable Long commentId, Authentication auth) {
|
||||||
subscriptionService.unsubscribeComment(auth.getName(), commentId);
|
subscriptionService.unsubscribeComment(auth.getName(), commentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/users/{username}")
|
@PostMapping("/users/{username}")
|
||||||
|
@Operation(summary = "Subscribe user", description = "Subscribe to a user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Subscribed")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void subscribeUser(@PathVariable String username, Authentication auth) {
|
public void subscribeUser(@PathVariable String username, Authentication auth) {
|
||||||
subscriptionService.subscribeUser(auth.getName(), username);
|
subscriptionService.subscribeUser(auth.getName(), username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/users/{username}")
|
@DeleteMapping("/users/{username}")
|
||||||
|
@Operation(summary = "Unsubscribe user", description = "Unsubscribe from a user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Unsubscribed")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public void unsubscribeUser(@PathVariable String username, Authentication auth) {
|
public void unsubscribeUser(@PathVariable String username, Authentication auth) {
|
||||||
subscriptionService.unsubscribeUser(auth.getName(), username);
|
subscriptionService.unsubscribeUser(auth.getName(), username);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ import com.openisle.service.PostService;
|
|||||||
import com.openisle.service.TagService;
|
import com.openisle.service.TagService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -29,6 +35,10 @@ public class TagController {
|
|||||||
private final TagMapper tagMapper;
|
private final TagMapper tagMapper;
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@Operation(summary = "Create tag", description = "Create a new tag")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Created tag",
|
||||||
|
content = @Content(schema = @Schema(implementation = TagDto.class)))
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
public TagDto create(@RequestBody TagRequest req, org.springframework.security.core.Authentication auth) {
|
public TagDto create(@RequestBody TagRequest req, org.springframework.security.core.Authentication auth) {
|
||||||
boolean approved = true;
|
boolean approved = true;
|
||||||
if (postService.getPublishMode() == PublishMode.REVIEW && auth != null) {
|
if (postService.getPublishMode() == PublishMode.REVIEW && auth != null) {
|
||||||
@@ -49,6 +59,9 @@ public class TagController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
|
@Operation(summary = "Update tag", description = "Update an existing tag")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Updated tag",
|
||||||
|
content = @Content(schema = @Schema(implementation = TagDto.class)))
|
||||||
public TagDto update(@PathVariable Long id, @RequestBody TagRequest req) {
|
public TagDto update(@PathVariable Long id, @RequestBody TagRequest req) {
|
||||||
Tag tag = tagService.updateTag(id, req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon());
|
Tag tag = tagService.updateTag(id, req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon());
|
||||||
long count = postService.countPostsByTag(tag.getId());
|
long count = postService.countPostsByTag(tag.getId());
|
||||||
@@ -56,11 +69,16 @@ public class TagController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
|
@Operation(summary = "Delete tag", description = "Delete a tag by id")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Tag deleted")
|
||||||
public void delete(@PathVariable Long id) {
|
public void delete(@PathVariable Long id) {
|
||||||
tagService.deleteTag(id);
|
tagService.deleteTag(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
|
@Operation(summary = "List tags", description = "List tags with optional keyword")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of tags",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = TagDto.class))))
|
||||||
public List<TagDto> list(@RequestParam(value = "keyword", required = false) String keyword,
|
public List<TagDto> list(@RequestParam(value = "keyword", required = false) String keyword,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
List<Tag> tags = tagService.searchTags(keyword);
|
List<Tag> tags = tagService.searchTags(keyword);
|
||||||
@@ -77,6 +95,9 @@ public class TagController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
|
@Operation(summary = "Get tag", description = "Get tag by id")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Tag detail",
|
||||||
|
content = @Content(schema = @Schema(implementation = TagDto.class)))
|
||||||
public TagDto get(@PathVariable Long id) {
|
public TagDto get(@PathVariable Long id) {
|
||||||
Tag tag = tagService.getTag(id);
|
Tag tag = tagService.getTag(id);
|
||||||
long count = postService.countPostsByTag(tag.getId());
|
long count = postService.countPostsByTag(tag.getId());
|
||||||
@@ -84,6 +105,9 @@ public class TagController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}/posts")
|
@GetMapping("/{id}/posts")
|
||||||
|
@Operation(summary = "List posts by tag", description = "Get posts with specific tag")
|
||||||
|
@ApiResponse(responseCode = "200", description = "List of posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
public List<PostSummaryDto> listPostsByTag(@PathVariable Long id,
|
public List<PostSummaryDto> listPostsByTag(@PathVariable Long id,
|
||||||
@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) {
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -27,6 +31,9 @@ public class UploadController {
|
|||||||
private long maxUploadSize;
|
private long maxUploadSize;
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@Operation(summary = "Upload file", description = "Upload image file")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Upload result",
|
||||||
|
content = @Content(schema = @Schema(implementation = java.util.Map.class)))
|
||||||
public ResponseEntity<?> upload(@RequestParam("file") MultipartFile file) {
|
public ResponseEntity<?> upload(@RequestParam("file") MultipartFile file) {
|
||||||
if (checkImageType && (file.getContentType() == null || !file.getContentType().startsWith("image/"))) {
|
if (checkImageType && (file.getContentType() == null || !file.getContentType().startsWith("image/"))) {
|
||||||
return ResponseEntity.badRequest().body(Map.of("code", 1, "msg", "File is not an image"));
|
return ResponseEntity.badRequest().body(Map.of("code", 1, "msg", "File is not an image"));
|
||||||
@@ -48,6 +55,9 @@ public class UploadController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/url")
|
@PostMapping("/url")
|
||||||
|
@Operation(summary = "Upload from URL", description = "Upload image from remote URL")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Upload result",
|
||||||
|
content = @Content(schema = @Schema(implementation = java.util.Map.class)))
|
||||||
public ResponseEntity<?> uploadUrl(@RequestBody Map<String, String> body) {
|
public ResponseEntity<?> uploadUrl(@RequestBody Map<String, String> body) {
|
||||||
String link = body.get("url");
|
String link = body.get("url");
|
||||||
if (link == null || link.isBlank()) {
|
if (link == null || link.isBlank()) {
|
||||||
@@ -76,6 +86,9 @@ public class UploadController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/presign")
|
@GetMapping("/presign")
|
||||||
|
@Operation(summary = "Presign upload", description = "Get presigned upload URL")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Presigned URL",
|
||||||
|
content = @Content(schema = @Schema(implementation = java.util.Map.class)))
|
||||||
public java.util.Map<String, String> presign(@RequestParam("filename") String filename) {
|
public java.util.Map<String, String> presign(@RequestParam("filename") String filename) {
|
||||||
return imageUploader.presignUpload(filename);
|
return imageUploader.presignUpload(filename);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ import com.openisle.mapper.TagMapper;
|
|||||||
import com.openisle.mapper.UserMapper;
|
import com.openisle.mapper.UserMapper;
|
||||||
import com.openisle.model.User;
|
import com.openisle.model.User;
|
||||||
import com.openisle.service.*;
|
import com.openisle.service.*;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -48,12 +54,20 @@ public class UserController {
|
|||||||
private int defaultTagsLimit;
|
private int defaultTagsLimit;
|
||||||
|
|
||||||
@GetMapping("/me")
|
@GetMapping("/me")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Current user", description = "Get current authenticated user information")
|
||||||
|
@ApiResponse(responseCode = "200", description = "User detail",
|
||||||
|
content = @Content(schema = @Schema(implementation = UserDto.class)))
|
||||||
public ResponseEntity<UserDto> me(Authentication auth) {
|
public ResponseEntity<UserDto> me(Authentication auth) {
|
||||||
User user = userService.findByUsername(auth.getName()).orElseThrow();
|
User user = userService.findByUsername(auth.getName()).orElseThrow();
|
||||||
return ResponseEntity.ok(userMapper.toDto(user, auth));
|
return ResponseEntity.ok(userMapper.toDto(user, auth));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/me/avatar")
|
@PostMapping("/me/avatar")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Upload avatar", description = "Upload avatar for current user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Upload result",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> uploadAvatar(@RequestParam("file") MultipartFile file,
|
public ResponseEntity<?> uploadAvatar(@RequestParam("file") MultipartFile file,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
if (checkImageType && (file.getContentType() == null || !file.getContentType().startsWith("image/"))) {
|
if (checkImageType && (file.getContentType() == null || !file.getContentType().startsWith("image/"))) {
|
||||||
@@ -73,6 +87,10 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/me")
|
@PutMapping("/me")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Update profile", description = "Update current user's profile")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Updated profile",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public ResponseEntity<?> updateProfile(@RequestBody UpdateProfileDto dto,
|
public ResponseEntity<?> updateProfile(@RequestBody UpdateProfileDto dto,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
User user = userService.updateProfile(auth.getName(), dto.getUsername(), dto.getIntroduction());
|
User user = userService.updateProfile(auth.getName(), dto.getUsername(), dto.getIntroduction());
|
||||||
@@ -82,13 +100,21 @@ public class UserController {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 这个方法似乎没有使用?
|
||||||
@PostMapping("/me/signin")
|
@PostMapping("/me/signin")
|
||||||
|
@SecurityRequirement(name = "JWT")
|
||||||
|
@Operation(summary = "Daily sign in", description = "Sign in to receive rewards")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Sign in reward",
|
||||||
|
content = @Content(schema = @Schema(implementation = Map.class)))
|
||||||
public Map<String, Integer> signIn(Authentication auth) {
|
public Map<String, Integer> signIn(Authentication auth) {
|
||||||
int reward = levelService.awardForSignin(auth.getName());
|
int reward = levelService.awardForSignin(auth.getName());
|
||||||
return Map.of("reward", reward);
|
return Map.of("reward", reward);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}")
|
@GetMapping("/{identifier}")
|
||||||
|
@Operation(summary = "Get user", description = "Get user by identifier")
|
||||||
|
@ApiResponse(responseCode = "200", description = "User detail",
|
||||||
|
content = @Content(schema = @Schema(implementation = UserDto.class)))
|
||||||
public ResponseEntity<UserDto> getUser(@PathVariable("identifier") String identifier,
|
public ResponseEntity<UserDto> getUser(@PathVariable("identifier") String identifier,
|
||||||
Authentication auth) {
|
Authentication auth) {
|
||||||
User user = userService.findByIdentifier(identifier).orElseThrow(() -> new NotFoundException("User not found"));
|
User user = userService.findByIdentifier(identifier).orElseThrow(() -> new NotFoundException("User not found"));
|
||||||
@@ -96,6 +122,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/posts")
|
@GetMapping("/{identifier}/posts")
|
||||||
|
@Operation(summary = "User posts", description = "Get recent posts by user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "User posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostMetaDto.class))))
|
||||||
public java.util.List<PostMetaDto> userPosts(@PathVariable("identifier") String identifier,
|
public java.util.List<PostMetaDto> userPosts(@PathVariable("identifier") String identifier,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
int l = limit != null ? limit : defaultPostsLimit;
|
int l = limit != null ? limit : defaultPostsLimit;
|
||||||
@@ -106,6 +135,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/subscribed-posts")
|
@GetMapping("/{identifier}/subscribed-posts")
|
||||||
|
@Operation(summary = "Subscribed posts", description = "Get posts the user subscribed to")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Subscribed posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostMetaDto.class))))
|
||||||
public java.util.List<PostMetaDto> subscribedPosts(@PathVariable("identifier") String identifier,
|
public java.util.List<PostMetaDto> subscribedPosts(@PathVariable("identifier") String identifier,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
int l = limit != null ? limit : defaultPostsLimit;
|
int l = limit != null ? limit : defaultPostsLimit;
|
||||||
@@ -117,6 +149,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/replies")
|
@GetMapping("/{identifier}/replies")
|
||||||
|
@Operation(summary = "User replies", description = "Get recent replies by user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "User replies",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = CommentInfoDto.class))))
|
||||||
public java.util.List<CommentInfoDto> userReplies(@PathVariable("identifier") String identifier,
|
public java.util.List<CommentInfoDto> userReplies(@PathVariable("identifier") String identifier,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
int l = limit != null ? limit : defaultRepliesLimit;
|
int l = limit != null ? limit : defaultRepliesLimit;
|
||||||
@@ -127,6 +162,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/hot-posts")
|
@GetMapping("/{identifier}/hot-posts")
|
||||||
|
@Operation(summary = "User hot posts", description = "Get most reacted posts by user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Hot posts",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostMetaDto.class))))
|
||||||
public java.util.List<PostMetaDto> hotPosts(@PathVariable("identifier") String identifier,
|
public java.util.List<PostMetaDto> hotPosts(@PathVariable("identifier") String identifier,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
int l = limit != null ? limit : 10;
|
int l = limit != null ? limit : 10;
|
||||||
@@ -138,6 +176,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/hot-replies")
|
@GetMapping("/{identifier}/hot-replies")
|
||||||
|
@Operation(summary = "User hot replies", description = "Get most reacted replies by user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Hot replies",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = CommentInfoDto.class))))
|
||||||
public java.util.List<CommentInfoDto> hotReplies(@PathVariable("identifier") String identifier,
|
public java.util.List<CommentInfoDto> hotReplies(@PathVariable("identifier") String identifier,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
int l = limit != null ? limit : 10;
|
int l = limit != null ? limit : 10;
|
||||||
@@ -149,6 +190,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/hot-tags")
|
@GetMapping("/{identifier}/hot-tags")
|
||||||
|
@Operation(summary = "User hot tags", description = "Get tags frequently used by user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Hot tags",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = TagDto.class))))
|
||||||
public java.util.List<TagDto> hotTags(@PathVariable("identifier") String identifier,
|
public java.util.List<TagDto> hotTags(@PathVariable("identifier") String identifier,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
int l = limit != null ? limit : 10;
|
int l = limit != null ? limit : 10;
|
||||||
@@ -161,6 +205,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/tags")
|
@GetMapping("/{identifier}/tags")
|
||||||
|
@Operation(summary = "User tags", description = "Get recent tags used by user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "User tags",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = TagDto.class))))
|
||||||
public java.util.List<TagDto> userTags(@PathVariable("identifier") String identifier,
|
public java.util.List<TagDto> userTags(@PathVariable("identifier") String identifier,
|
||||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
int l = limit != null ? limit : defaultTagsLimit;
|
int l = limit != null ? limit : defaultTagsLimit;
|
||||||
@@ -171,6 +218,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/following")
|
@GetMapping("/{identifier}/following")
|
||||||
|
@Operation(summary = "Following users", description = "Get users that this user is following")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Following list",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserDto.class))))
|
||||||
public java.util.List<UserDto> following(@PathVariable("identifier") String identifier) {
|
public java.util.List<UserDto> following(@PathVariable("identifier") String identifier) {
|
||||||
User user = userService.findByIdentifier(identifier).orElseThrow();
|
User user = userService.findByIdentifier(identifier).orElseThrow();
|
||||||
return subscriptionService.getSubscribedUsers(user.getUsername()).stream()
|
return subscriptionService.getSubscribedUsers(user.getUsername()).stream()
|
||||||
@@ -179,6 +229,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/followers")
|
@GetMapping("/{identifier}/followers")
|
||||||
|
@Operation(summary = "Followers", description = "Get followers of this user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Followers list",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserDto.class))))
|
||||||
public java.util.List<UserDto> followers(@PathVariable("identifier") String identifier) {
|
public java.util.List<UserDto> followers(@PathVariable("identifier") String identifier) {
|
||||||
User user = userService.findByIdentifier(identifier).orElseThrow();
|
User user = userService.findByIdentifier(identifier).orElseThrow();
|
||||||
return subscriptionService.getSubscribers(user.getUsername()).stream()
|
return subscriptionService.getSubscribers(user.getUsername()).stream()
|
||||||
@@ -187,6 +240,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/admins")
|
@GetMapping("/admins")
|
||||||
|
@Operation(summary = "Admin users", description = "List administrator users")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Admin users",
|
||||||
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserDto.class))))
|
||||||
public java.util.List<UserDto> admins() {
|
public java.util.List<UserDto> admins() {
|
||||||
return userService.getAdmins().stream()
|
return userService.getAdmins().stream()
|
||||||
.map(userMapper::toDto)
|
.map(userMapper::toDto)
|
||||||
@@ -194,6 +250,9 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{identifier}/all")
|
@GetMapping("/{identifier}/all")
|
||||||
|
@Operation(summary = "User aggregate", description = "Get aggregate information for user")
|
||||||
|
@ApiResponse(responseCode = "200", description = "User aggregate",
|
||||||
|
content = @Content(schema = @Schema(implementation = UserAggregateDto.class)))
|
||||||
public ResponseEntity<UserAggregateDto> userAggregate(@PathVariable("identifier") String identifier,
|
public ResponseEntity<UserAggregateDto> userAggregate(@PathVariable("identifier") String identifier,
|
||||||
@RequestParam(value = "postsLimit", required = false) Integer postsLimit,
|
@RequestParam(value = "postsLimit", required = false) Integer postsLimit,
|
||||||
@RequestParam(value = "repliesLimit", required = false) Integer repliesLimit,
|
@RequestParam(value = "repliesLimit", required = false) Integer repliesLimit,
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.openisle.scheduler;
|
||||||
|
|
||||||
|
import com.openisle.config.CachingConfig;
|
||||||
|
import com.openisle.model.User;
|
||||||
|
import com.openisle.model.UserVisit;
|
||||||
|
import com.openisle.repository.UserRepository;
|
||||||
|
import com.openisle.repository.UserVisitRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行计划
|
||||||
|
* 将每天用户访问落库
|
||||||
|
* @author smallclover
|
||||||
|
* @since 2025-09-09
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserVisitScheduler {
|
||||||
|
private final RedisTemplate redisTemplate;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
private final UserVisitRepository userVisitRepository;
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 5 0 * * ?")// 每天 00:05 执行
|
||||||
|
public void persistDailyVisits(){
|
||||||
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
||||||
|
String key = CachingConfig.VISIT_CACHE_NAME+":"+ yesterday;
|
||||||
|
Set<String> usernames = redisTemplate.opsForSet().members(key);
|
||||||
|
if(!CollectionUtils.isEmpty(usernames)){
|
||||||
|
for(String username: usernames){
|
||||||
|
User user = userRepository.findByUsername(username).orElse(null);
|
||||||
|
if(user != null){
|
||||||
|
UserVisit userVisit = new UserVisit();
|
||||||
|
userVisit.setUser(user);
|
||||||
|
userVisit.setVisitDate(yesterday);
|
||||||
|
userVisitRepository.save(userVisit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.openisle.service;
|
package com.openisle.service;
|
||||||
|
|
||||||
|
import com.openisle.config.CachingConfig;
|
||||||
import com.openisle.model.Post;
|
import com.openisle.model.Post;
|
||||||
import com.openisle.model.PostStatus;
|
import com.openisle.model.PostStatus;
|
||||||
import com.openisle.model.PostType;
|
import com.openisle.model.PostType;
|
||||||
@@ -28,12 +29,15 @@ import com.openisle.repository.PollVoteRepository;
|
|||||||
import com.openisle.model.Role;
|
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.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import com.openisle.service.EmailSender;
|
import com.openisle.service.EmailSender;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -80,6 +84,8 @@ public class PostService {
|
|||||||
@Value("${app.website-url:https://www.open-isle.com}")
|
@Value("${app.website-url:https://www.open-isle.com}")
|
||||||
private String websiteUrl;
|
private String websiteUrl;
|
||||||
|
|
||||||
|
private final RedisTemplate redisTemplate;
|
||||||
|
|
||||||
@org.springframework.beans.factory.annotation.Autowired
|
@org.springframework.beans.factory.annotation.Autowired
|
||||||
public PostService(PostRepository postRepository,
|
public PostService(PostRepository postRepository,
|
||||||
UserRepository userRepository,
|
UserRepository userRepository,
|
||||||
@@ -102,7 +108,8 @@ public class PostService {
|
|||||||
ApplicationContext applicationContext,
|
ApplicationContext applicationContext,
|
||||||
PointService pointService,
|
PointService pointService,
|
||||||
PostChangeLogService postChangeLogService,
|
PostChangeLogService postChangeLogService,
|
||||||
@Value("${app.post.publish-mode:DIRECT}") PublishMode publishMode) {
|
@Value("${app.post.publish-mode:DIRECT}") PublishMode publishMode,
|
||||||
|
RedisTemplate redisTemplate) {
|
||||||
this.postRepository = postRepository;
|
this.postRepository = postRepository;
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
this.categoryRepository = categoryRepository;
|
this.categoryRepository = categoryRepository;
|
||||||
@@ -125,6 +132,8 @@ public class PostService {
|
|||||||
this.pointService = pointService;
|
this.pointService = pointService;
|
||||||
this.postChangeLogService = postChangeLogService;
|
this.postChangeLogService = postChangeLogService;
|
||||||
this.publishMode = publishMode;
|
this.publishMode = publishMode;
|
||||||
|
|
||||||
|
this.redisTemplate = redisTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
@@ -201,9 +210,9 @@ public class PostService {
|
|||||||
LocalDateTime endTime,
|
LocalDateTime endTime,
|
||||||
java.util.List<String> options,
|
java.util.List<String> options,
|
||||||
Boolean multiple) {
|
Boolean multiple) {
|
||||||
long recent = postRepository.countByAuthorAfter(username,
|
// 限制访问次数
|
||||||
java.time.LocalDateTime.now().minusMinutes(5));
|
boolean limitResult = postRateLimit(username);
|
||||||
if (recent >= 1) {
|
if (!limitResult) {
|
||||||
throw new RateLimitException("Too many posts");
|
throw new RateLimitException("Too many posts");
|
||||||
}
|
}
|
||||||
if (tagIds == null || tagIds.isEmpty()) {
|
if (tagIds == null || tagIds.isEmpty()) {
|
||||||
@@ -300,6 +309,23 @@ public class PostService {
|
|||||||
return post;
|
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) {
|
public void joinLottery(Long postId, String username) {
|
||||||
LotteryPost post = lotteryPostRepository.findById(postId)
|
LotteryPost post = lotteryPostRepository.findById(postId)
|
||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
package com.openisle.service;
|
package com.openisle.service;
|
||||||
|
|
||||||
|
import com.openisle.config.CachingConfig;
|
||||||
import com.openisle.model.User;
|
import com.openisle.model.User;
|
||||||
import com.openisle.model.UserVisit;
|
import com.openisle.model.UserVisit;
|
||||||
import com.openisle.repository.UserRepository;
|
import com.openisle.repository.UserRepository;
|
||||||
import com.openisle.repository.UserVisitRepository;
|
import com.openisle.repository.UserVisitRepository;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -17,6 +24,8 @@ public class UserVisitService {
|
|||||||
private final UserVisitRepository userVisitRepository;
|
private final UserVisitRepository userVisitRepository;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
private final RedisTemplate redisTemplate;
|
||||||
|
|
||||||
public boolean recordVisit(String username) {
|
public boolean recordVisit(String username) {
|
||||||
User user = userRepository.findByUsername(username)
|
User user = userRepository.findByUsername(username)
|
||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
@@ -30,10 +39,36 @@ public class UserVisitService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计访问次数,改为从缓存获取/数据库获取
|
||||||
|
* @param username
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public long countVisits(String username) {
|
public long countVisits(String username) {
|
||||||
User user = userRepository.findByUsername(username)
|
User user = userRepository.findByUsername(username)
|
||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
return userVisitRepository.countByUser(user);
|
|
||||||
|
// 如果缓存存在就返回
|
||||||
|
String key1 = CachingConfig.VISIT_CACHE_NAME + ":"+LocalDate.now()+":count:"+username;
|
||||||
|
Integer cached = (Integer) redisTemplate.opsForValue().get(key1);
|
||||||
|
if(cached != null){
|
||||||
|
return cached.longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redis Set 检查今天是否访问
|
||||||
|
String todayKey = CachingConfig.VISIT_CACHE_NAME + ":" + LocalDate.now();
|
||||||
|
boolean todayVisited = redisTemplate.opsForSet().isMember(todayKey, username);
|
||||||
|
|
||||||
|
Long visitCount = userVisitRepository.countByUser(user);
|
||||||
|
if (todayVisited) visitCount += 1;
|
||||||
|
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
LocalDateTime endOfDay = now.toLocalDate().atTime(23, 59, 59);
|
||||||
|
long secondsUntilEndOfDay = Duration.between(now, endOfDay).getSeconds();
|
||||||
|
|
||||||
|
// 写入缓存,设置 TTL,当天剩余时间
|
||||||
|
redisTemplate.opsForValue().set(key1, visitCount, Duration.ofSeconds(secondsUntilEndOfDay));
|
||||||
|
return visitCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long countDau(LocalDate date) {
|
public long countDau(LocalDate date) {
|
||||||
|
|||||||
@@ -108,7 +108,10 @@ rabbitmq.sharding.enabled=true
|
|||||||
# see https://springdoc.org/#springdoc-openapi-core-properties
|
# see https://springdoc.org/#springdoc-openapi-core-properties
|
||||||
springdoc.api-docs.path=/api/v3/api-docs
|
springdoc.api-docs.path=/api/v3/api-docs
|
||||||
springdoc.api-docs.enabled=true
|
springdoc.api-docs.enabled=true
|
||||||
springdoc.api-docs.server-url=${WEBSITE_URL:https://www.open-isle.com}
|
springdoc.api-docs.servers[0].url=https://www.open-isle.com
|
||||||
|
springdoc.api-docs.servers[0].description=Production Environment
|
||||||
|
springdoc.api-docs.servers[1].url=https://www.staging.open-isle.com
|
||||||
|
springdoc.api-docs.servers[1].description=Staging Environment
|
||||||
springdoc.info.title=OpenIsle
|
springdoc.info.title=OpenIsle
|
||||||
springdoc.info.description=OpenIsle Open API Documentation
|
springdoc.info.description=OpenIsle Open API Documentation
|
||||||
springdoc.info.version=0.0.1
|
springdoc.info.version=0.0.1
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.openisle.exception.RateLimitException;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.scheduling.TaskScheduler;
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@@ -38,11 +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);
|
||||||
|
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, PublishMode.DIRECT);
|
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, 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();
|
||||||
@@ -88,11 +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);
|
||||||
|
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, PublishMode.DIRECT);
|
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, 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();
|
||||||
@@ -144,11 +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);
|
||||||
|
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, PublishMode.DIRECT);
|
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, 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);
|
||||||
@@ -181,11 +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);
|
||||||
|
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, PublishMode.DIRECT);
|
imageUploader, taskScheduler, emailSender, context, pointService, postChangeLogService, 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();
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ bun dev
|
|||||||
|
|
||||||
使用以下路由:
|
使用以下路由:
|
||||||
|
|
||||||
- `docs/frontend/` 前端技术文档
|
- `frontend/` 前端技术文档
|
||||||
- `docs/backend/` 后端技术文档
|
- `backend/` 后端技术文档
|
||||||
- `docs/openapi/` 后端 API 文档
|
- `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 params = await props.params;
|
||||||
const page = source.getPage(params.slug);
|
const page = source.getPage(params.slug);
|
||||||
if (!page) notFound();
|
if (!page) notFound();
|
||||||
@@ -48,7 +48,7 @@ export async function generateStaticParams() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function generateMetadata(
|
export async function generateMetadata(
|
||||||
props: PageProps<'/docs/[[...slug]]'>
|
props: PageProps<'/[[...slug]]'>
|
||||||
): Promise<Metadata> {
|
): Promise<Metadata> {
|
||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
const page = source.getPage(params.slug);
|
const page = source.getPage(params.slug);
|
||||||
@@ -28,7 +28,7 @@ function TabTitle({ children }: { children: React.ReactNode }) {
|
|||||||
return <span className="text-[11px]">{children}</span>;
|
return <span className="text-[11px]">{children}</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Layout({ children }: LayoutProps<'/docs'>) {
|
export default function Layout({ children }: LayoutProps<'/'>) {
|
||||||
return (
|
return (
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
<DocsLayout
|
<DocsLayout
|
||||||
@@ -40,7 +40,7 @@ export default function Layout({ children }: LayoutProps<'/docs'>) {
|
|||||||
{
|
{
|
||||||
title: 'OpenIsle 前端',
|
title: 'OpenIsle 前端',
|
||||||
description: <TabTitle>前端开发文档</TabTitle>,
|
description: <TabTitle>前端开发文档</TabTitle>,
|
||||||
url: '/docs/frontend',
|
url: '/frontend',
|
||||||
icon: (
|
icon: (
|
||||||
<TabIcon color="#4ca154">
|
<TabIcon color="#4ca154">
|
||||||
<CompassIcon />
|
<CompassIcon />
|
||||||
@@ -50,7 +50,7 @@ export default function Layout({ children }: LayoutProps<'/docs'>) {
|
|||||||
{
|
{
|
||||||
title: 'OpenIsle 后端',
|
title: 'OpenIsle 后端',
|
||||||
description: <TabTitle>后端开发文档</TabTitle>,
|
description: <TabTitle>后端开发文档</TabTitle>,
|
||||||
url: '/docs/backend',
|
url: '/backend',
|
||||||
icon: (
|
icon: (
|
||||||
<TabIcon color="#1f66f4">
|
<TabIcon color="#1f66f4">
|
||||||
<ServerIcon />
|
<ServerIcon />
|
||||||
@@ -60,7 +60,7 @@ export default function Layout({ children }: LayoutProps<'/docs'>) {
|
|||||||
{
|
{
|
||||||
title: 'OpenIsle API',
|
title: 'OpenIsle API',
|
||||||
description: <TabTitle>后端 API 文档</TabTitle>,
|
description: <TabTitle>后端 API 文档</TabTitle>,
|
||||||
url: '/docs/openapi',
|
url: '/openapi',
|
||||||
icon: (
|
icon: (
|
||||||
<TabIcon color="#677489">
|
<TabIcon color="#677489">
|
||||||
<CodeXmlIcon />
|
<CodeXmlIcon />
|
||||||
@@ -6,7 +6,7 @@ const inter = Inter({
|
|||||||
subsets: ['latin'],
|
subsets: ['latin'],
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function Layout({ children }: LayoutProps<'/docs'>) {
|
export default function Layout({ children }: LayoutProps<'/'>) {
|
||||||
return (
|
return (
|
||||||
<html lang="zh" className={inter.className} suppressHydrationWarning>
|
<html lang="zh" className={inter.className} suppressHydrationWarning>
|
||||||
<body className="flex flex-col min-h-screen">
|
<body className="flex flex-col min-h-screen">
|
||||||
|
|||||||
@@ -40,4 +40,4 @@ backend/
|
|||||||
|
|
||||||
## API 接口
|
## API 接口
|
||||||
|
|
||||||
详细的 API 接口文档请查看 [API 文档](/docs/openapi)。
|
详细的 API 接口文档请查看 [API 文档](/openapi)。
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ OpenIsle 是一个现代化的社区平台,提供完整的社交功能。
|
|||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
- [后端开发指南](/docs/backend) - 了解后端架构和开发
|
- [后端开发指南](/backend) - 了解后端架构和开发
|
||||||
- [前端开发指南](/docs/frontend) - 了解前端技术栈和组件
|
- [前端开发指南](/frontend) - 了解前端技术栈和组件
|
||||||
- [API 文档](/docs/openapi) - 查看完整的 API 接口文档
|
- [API 文档](/openapi) - 查看完整的 API 接口文档
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export function baseOptions(): BaseLayoutProps {
|
|||||||
githubUrl: 'https://github.com/nagisa77/OpenIsle',
|
githubUrl: 'https://github.com/nagisa77/OpenIsle',
|
||||||
nav: {
|
nav: {
|
||||||
title: 'OpenIsle Docs',
|
title: 'OpenIsle Docs',
|
||||||
url: '/docs',
|
url: '/',
|
||||||
},
|
},
|
||||||
searchToggle: {
|
searchToggle: {
|
||||||
enabled: false,
|
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
|
// See https://fumadocs.vercel.app/docs/headless/source-api for more info
|
||||||
export const source = loader({
|
export const source = loader({
|
||||||
// it assigns a URL to your pages
|
// it assigns a URL to your pages
|
||||||
baseUrl: '/docs',
|
baseUrl: '/',
|
||||||
source: docs.toFumadocsSource(),
|
source: docs.toFumadocsSource(),
|
||||||
pageTree: {
|
pageTree: {
|
||||||
transformers: [transformerOpenAPI()],
|
transformers: [transformerOpenAPI()],
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ NUXT_PUBLIC_WEBSOCKET_URL=https://127.0.0.1:8082
|
|||||||
NUXT_PUBLIC_WEBSITE_BASE_URL=http://localhost:3000
|
NUXT_PUBLIC_WEBSITE_BASE_URL=http://localhost:3000
|
||||||
|
|
||||||
NUXT_PUBLIC_GOOGLE_CLIENT_ID=777830451304-nt8afkkap18gui4f9entcha99unal744.apps.googleusercontent.com
|
NUXT_PUBLIC_GOOGLE_CLIENT_ID=777830451304-nt8afkkap18gui4f9entcha99unal744.apps.googleusercontent.com
|
||||||
NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ
|
# NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ
|
||||||
|
; 本地
|
||||||
|
NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liOlrZnPKRF7s7NN
|
||||||
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
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -239,8 +239,16 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.info-content-text img {
|
.info-content-text img {
|
||||||
max-width: 100%;
|
max-width: min(800px, 100%);
|
||||||
|
max-height: 600px;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
cursor: pointer;
|
||||||
|
box-shadow: 4px 12px 48px 0 rgba(0, 0, 0, 0.11);
|
||||||
|
transition: box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-content-text img:hover {
|
||||||
|
box-shadow: 4px 12px 48px 0 rgba(0, 0, 0, 0.35);
|
||||||
}
|
}
|
||||||
|
|
||||||
.info-content-text table {
|
.info-content-text table {
|
||||||
@@ -346,25 +354,41 @@ body {
|
|||||||
position: relative;
|
position: relative;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Adjust diff2html layout on mobile */
|
.d2h-file-name {
|
||||||
@media (max-width: 768px) {
|
font-size: 12px !important;
|
||||||
.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 {
|
.d2h-file-header {
|
||||||
overflow-x: auto;
|
height: auto !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.d2h-code-linenumber {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.d2h-code-line {
|
||||||
|
padding-left: 10px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.d2h-diff-table {
|
||||||
|
font-size: 6px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.d2h-code-line ins {
|
||||||
|
height: 100%;
|
||||||
|
font-size: 13px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* .d2h-code-line {
|
||||||
|
height: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.d2h-code-line-ctn {
|
||||||
|
font-size: 12px !important;
|
||||||
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transition API */
|
|
||||||
::view-transition-old(root),
|
::view-transition-old(root),
|
||||||
::view-transition-new(root) {
|
::view-transition-new(root) {
|
||||||
animation: none;
|
animation: none;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export default {
|
|||||||
|
|
||||||
.timeline-content {
|
.timeline-content {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
width: calc(100% - 32px);
|
width: calc(100% - 42px);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
|
|||||||
@@ -6,8 +6,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="comment-bottom-container">
|
<div class="comment-bottom-container">
|
||||||
<div class="comment-submit" :class="{ disabled: isDisabled }" @click="submit">
|
<div class="comment-submit" :class="{ disabled: isDisabled }" @click="submit">
|
||||||
<template v-if="!loading"> 发布评论 </template>
|
<template v-if="!loading">
|
||||||
<template v-else> <loading-four /> 发布中... </template>
|
发布评论
|
||||||
|
<span class="shortcut-icon" v-if="!isMobile">
|
||||||
|
{{ isMac ? '⌘' : 'Ctrl' }} ⏎
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<loading-four /> 发布中...
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -24,6 +31,7 @@ import {
|
|||||||
} from '~/utils/vditor'
|
} from '~/utils/vditor'
|
||||||
import '~/assets/global.css'
|
import '~/assets/global.css'
|
||||||
import LoginOverlay from '~/components/LoginOverlay.vue'
|
import LoginOverlay from '~/components/LoginOverlay.vue'
|
||||||
|
import { useIsMobile } from '~/utils/screen'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'CommentEditor',
|
name: 'CommentEditor',
|
||||||
@@ -52,12 +60,22 @@ export default {
|
|||||||
},
|
},
|
||||||
components: { LoginOverlay },
|
components: { LoginOverlay },
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
|
const isMobile = useIsMobile()
|
||||||
const vditorInstance = ref(null)
|
const vditorInstance = ref(null)
|
||||||
const text = ref('')
|
const text = ref('')
|
||||||
const editorId = ref(props.editorId)
|
const editorId = ref(props.editorId)
|
||||||
if (!editorId.value) {
|
if (!editorId.value) {
|
||||||
editorId.value = 'editor-' + useId()
|
editorId.value = 'editor-' + useId()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isMac = ref(false)
|
||||||
|
|
||||||
|
if (navigator.userAgentData) {
|
||||||
|
isMac.value = navigator.userAgentData.platform === 'macOS'
|
||||||
|
} else {
|
||||||
|
isMac.value = /Mac|iPhone|iPad|iPod/.test(navigator.userAgent)
|
||||||
|
}
|
||||||
|
|
||||||
const getEditorTheme = getEditorThemeUtil
|
const getEditorTheme = getEditorThemeUtil
|
||||||
const getPreviewTheme = getPreviewThemeUtil
|
const getPreviewTheme = getPreviewThemeUtil
|
||||||
const applyTheme = () => {
|
const applyTheme = () => {
|
||||||
@@ -96,7 +114,27 @@ export default {
|
|||||||
applyTheme()
|
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(() => {
|
||||||
@@ -134,7 +172,7 @@ export default {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return { submit, isDisabled, editorId }
|
return { submit, isDisabled, editorId, isMac, isMobile}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -174,10 +212,16 @@ export default {
|
|||||||
.comment-submit:hover {
|
.comment-submit:hover {
|
||||||
background-color: var(--primary-color-hover);
|
background-color: var(--primary-color-hover);
|
||||||
}
|
}
|
||||||
|
/** 评论按钮快捷键样式 */
|
||||||
@media (max-width: 768px) {
|
.shortcut-icon {
|
||||||
.comment-editor-container {
|
padding: 2px 6px;
|
||||||
margin-bottom: 10px;
|
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>
|
||||||
|
|||||||
@@ -314,6 +314,7 @@ const gotoTag = (t) => {
|
|||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
transition: background-color 0.5s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-item:hover {
|
.menu-item:hover {
|
||||||
@@ -408,6 +409,7 @@ const gotoTag = (t) => {
|
|||||||
gap: 5px;
|
gap: 5px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
transition: background-color 0.5s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.section-item:hover {
|
.section-item:hover {
|
||||||
|
|||||||
@@ -70,23 +70,6 @@ export default {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
vditorInstance.value = createVditor(editorId.value, {
|
vditorInstance.value = createVditor(editorId.value, {
|
||||||
placeholder: '输入消息...',
|
placeholder: '输入消息...',
|
||||||
height: 150,
|
|
||||||
toolbar: [
|
|
||||||
'emoji',
|
|
||||||
'bold',
|
|
||||||
'italic',
|
|
||||||
'strike',
|
|
||||||
'link',
|
|
||||||
'|',
|
|
||||||
'list',
|
|
||||||
'|',
|
|
||||||
'line',
|
|
||||||
'quote',
|
|
||||||
'code',
|
|
||||||
'inline-code',
|
|
||||||
'|',
|
|
||||||
'upload',
|
|
||||||
],
|
|
||||||
preview: {
|
preview: {
|
||||||
actions: [],
|
actions: [],
|
||||||
markdown: { toc: false },
|
markdown: { toc: false },
|
||||||
@@ -149,11 +132,17 @@ export default {
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vditor {
|
||||||
|
min-height: 50px;
|
||||||
|
max-height: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
.message-bottom-container {
|
.message-bottom-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
padding: 10px;
|
margin-top: 10px;
|
||||||
|
margin-bottom: 10px;
|
||||||
background-color: var(--bg-color-soft);
|
background-color: var(--bg-color-soft);
|
||||||
border-top: 1px solid var(--border-color);
|
border-top: 1px solid var(--border-color);
|
||||||
border-bottom-left-radius: 8px;
|
border-bottom-left-radius: 8px;
|
||||||
|
|||||||
@@ -110,11 +110,13 @@ const diffHtml = computed(() => {
|
|||||||
border-bottom: 1px solid var(--normal-border-color);
|
border-bottom: 1px solid var(--normal-border-color);
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.change-log-text {
|
.change-log-text {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.change-log-user {
|
.change-log-user {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
@@ -132,6 +134,7 @@ const diffHtml = computed(() => {
|
|||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.change-log-time {
|
.change-log-time {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
|
|||||||
97
frontend_nuxt/config/uploadConfig.js
Normal file
97
frontend_nuxt/config/uploadConfig.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/**
|
||||||
|
* 文件上传配置 - 简化版
|
||||||
|
* 专注于 WebCodecs + MP4Box.js 视频压缩,支持 Chrome/Safari
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 声明全局变量以避免 TypeScript 错误
|
||||||
|
/* global useRuntimeConfig */
|
||||||
|
|
||||||
|
export const UPLOAD_CONFIG = {
|
||||||
|
VIDEO: {
|
||||||
|
MAX_SIZE: 20 * 1024 * 1024, // 20mb
|
||||||
|
TARGET_SIZE: 5 * 1024 * 1024, // 5mb
|
||||||
|
|
||||||
|
// 支持的输入格式
|
||||||
|
SUPPORTED_FORMATS: ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv'],
|
||||||
|
|
||||||
|
// 输出格式 - MP4 (兼容性最好)
|
||||||
|
OUTPUT_FORMAT: 'mp4',
|
||||||
|
OUTPUT_CODEC: 'h264',
|
||||||
|
},
|
||||||
|
|
||||||
|
// 图片文件配置
|
||||||
|
IMAGE: {
|
||||||
|
MAX_SIZE: 5 * 1024 * 1024, // 5MB
|
||||||
|
TARGET_SIZE: 5 * 1024 * 1024, // 5MB
|
||||||
|
SUPPORTED_FORMATS: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp'],
|
||||||
|
},
|
||||||
|
|
||||||
|
// 音频文件配置
|
||||||
|
AUDIO: {
|
||||||
|
MAX_SIZE: 5 * 1024 * 1024, // 5MB
|
||||||
|
TARGET_SIZE: 5 * 1024 * 1024, // 5MB
|
||||||
|
SUPPORTED_FORMATS: ['mp3', 'wav', 'ogg', 'aac', 'm4a'],
|
||||||
|
},
|
||||||
|
|
||||||
|
// 通用文件配置
|
||||||
|
GENERAL: {
|
||||||
|
MAX_SIZE: 100 * 1024 * 1024, // 100MB
|
||||||
|
CHUNK_SIZE: 5 * 1024 * 1024, // 5MB 分片大小
|
||||||
|
},
|
||||||
|
|
||||||
|
// 用户体验配置
|
||||||
|
UI: {
|
||||||
|
SUCCESS_DURATION: 2000,
|
||||||
|
ERROR_DURATION: 3000,
|
||||||
|
WARNING_DURATION: 3000,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件类型配置
|
||||||
|
*/
|
||||||
|
export function getFileTypeConfig(filename) {
|
||||||
|
const ext = filename.split('.').pop().toLowerCase()
|
||||||
|
|
||||||
|
if (UPLOAD_CONFIG.VIDEO.SUPPORTED_FORMATS.includes(ext)) {
|
||||||
|
return { type: 'video', config: UPLOAD_CONFIG.VIDEO }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UPLOAD_CONFIG.IMAGE.SUPPORTED_FORMATS.includes(ext)) {
|
||||||
|
return { type: 'image', config: UPLOAD_CONFIG.IMAGE }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UPLOAD_CONFIG.AUDIO.SUPPORTED_FORMATS.includes(ext)) {
|
||||||
|
return { type: 'audio', config: UPLOAD_CONFIG.AUDIO }
|
||||||
|
}
|
||||||
|
|
||||||
|
return { type: 'general', config: UPLOAD_CONFIG.GENERAL }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化文件大小
|
||||||
|
*/
|
||||||
|
export function formatFileSize(bytes) {
|
||||||
|
if (bytes === 0) return '0 B'
|
||||||
|
const k = 1024
|
||||||
|
const sizes = ['B', 'KB', 'MB', 'GB']
|
||||||
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||||
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算压缩节省的费用 (示例函数)
|
||||||
|
*/
|
||||||
|
export function calculateSavings(originalSize, compressedSize, costPerMB = 0.01) {
|
||||||
|
const originalMB = originalSize / (1024 * 1024)
|
||||||
|
const compressedMB = compressedSize / (1024 * 1024)
|
||||||
|
const savedMB = originalMB - compressedMB
|
||||||
|
const savedCost = savedMB * costPerMB
|
||||||
|
|
||||||
|
return {
|
||||||
|
savedMB: savedMB.toFixed(2),
|
||||||
|
savedCost: savedCost.toFixed(4),
|
||||||
|
originalCost: (originalMB * costPerMB).toFixed(4),
|
||||||
|
compressedCost: (compressedMB * costPerMB).toFixed(4),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
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',
|
||||||
port: 3000
|
port: 3000,
|
||||||
},
|
},
|
||||||
ssr: true,
|
ssr: true,
|
||||||
modules: ['@nuxt/image'],
|
modules: ['@nuxt/image'],
|
||||||
|
|||||||
31
frontend_nuxt/package-lock.json
generated
31
frontend_nuxt/package-lock.json
generated
@@ -19,6 +19,8 @@
|
|||||||
"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",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"nuxt": "latest",
|
"nuxt": "latest",
|
||||||
"sanitize-html": "^2.17.0",
|
"sanitize-html": "^2.17.0",
|
||||||
@@ -998,7 +1000,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/@icon-park/vue-next": {
|
"node_modules/@icon-park/vue-next": {
|
||||||
"version": "1.4.2",
|
"version": "1.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/@icon-park/vue-next/-/vue-next-1.4.2.tgz",
|
"resolved": "https://registry.npmmirror.com/@icon-park/vue-next/-/vue-next-1.4.2.tgz",
|
||||||
"integrity": "sha512-+QklF255wkfBOabY+xw6FAI0Bwln/RhdwCunNy/9sKdKuChtaU67QZqU67KGAvZUTeeBgsL+yaHHxqfQeGZXEQ==",
|
"integrity": "sha512-+QklF255wkfBOabY+xw6FAI0Bwln/RhdwCunNy/9sKdKuChtaU67QZqU67KGAvZUTeeBgsL+yaHHxqfQeGZXEQ==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -7222,7 +7224,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/diff2html": {
|
"node_modules/diff2html": {
|
||||||
"version": "3.4.52",
|
"version": "3.4.52",
|
||||||
"resolved": "https://registry.npmjs.org/diff2html/-/diff2html-3.4.52.tgz",
|
"resolved": "https://registry.npmmirror.com/diff2html/-/diff2html-3.4.52.tgz",
|
||||||
"integrity": "sha512-qhMg8/I3sZ4zm/6R/Kh0xd6qG6Vm86w6M+C9W+DuH1V8ACz+1cgEC8/k0ucjv6AGqZWzHm/8G1gh7IlrUqCMhg==",
|
"integrity": "sha512-qhMg8/I3sZ4zm/6R/Kh0xd6qG6Vm86w6M+C9W+DuH1V8ACz+1cgEC8/k0ucjv6AGqZWzHm/8G1gh7IlrUqCMhg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -7238,7 +7240,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/diff2html/node_modules/diff": {
|
"node_modules/diff2html/node_modules/diff": {
|
||||||
"version": "7.0.0",
|
"version": "7.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz",
|
"resolved": "https://registry.npmmirror.com/diff/-/diff-7.0.0.tgz",
|
||||||
"integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==",
|
"integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -7247,7 +7249,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/diff2html/node_modules/highlight.js": {
|
"node_modules/diff2html/node_modules/highlight.js": {
|
||||||
"version": "11.9.0",
|
"version": "11.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.9.0.tgz",
|
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-11.9.0.tgz",
|
||||||
"integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==",
|
"integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
@@ -8330,7 +8332,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/hogan.js": {
|
"node_modules/hogan.js": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/hogan.js/-/hogan.js-3.0.2.tgz",
|
"resolved": "https://registry.npmmirror.com/hogan.js/-/hogan.js-3.0.2.tgz",
|
||||||
"integrity": "sha512-RqGs4wavGYJWE07t35JQccByczmNUXQT0E12ZYV1VKYu5UiAU9lsos/yBAcf840+zrUQQxgVduCR5/B8nNtibg==",
|
"integrity": "sha512-RqGs4wavGYJWE07t35JQccByczmNUXQT0E12ZYV1VKYu5UiAU9lsos/yBAcf840+zrUQQxgVduCR5/B8nNtibg==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mkdirp": "0.3.0",
|
"mkdirp": "0.3.0",
|
||||||
@@ -8342,13 +8344,13 @@
|
|||||||
},
|
},
|
||||||
"node_modules/hogan.js/node_modules/abbrev": {
|
"node_modules/hogan.js/node_modules/abbrev": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
"resolved": "https://registry.npmmirror.com/abbrev/-/abbrev-1.1.1.tgz",
|
||||||
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
|
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/hogan.js/node_modules/mkdirp": {
|
"node_modules/hogan.js/node_modules/mkdirp": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz",
|
"resolved": "https://registry.npmmirror.com/mkdirp/-/mkdirp-0.3.0.tgz",
|
||||||
"integrity": "sha512-OHsdUcVAQ6pOtg5JYWpCBo9W/GySVuwvP9hueRMW7UqshC0tbfzLv8wjySTPm3tfUZ/21CE9E1pJagOA91Pxew==",
|
"integrity": "sha512-OHsdUcVAQ6pOtg5JYWpCBo9W/GySVuwvP9hueRMW7UqshC0tbfzLv8wjySTPm3tfUZ/21CE9E1pJagOA91Pxew==",
|
||||||
"deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)",
|
"deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)",
|
||||||
"license": "MIT/X11",
|
"license": "MIT/X11",
|
||||||
@@ -8358,7 +8360,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/hogan.js/node_modules/nopt": {
|
"node_modules/hogan.js/node_modules/nopt": {
|
||||||
"version": "1.0.10",
|
"version": "1.0.10",
|
||||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz",
|
"resolved": "https://registry.npmmirror.com/nopt/-/nopt-1.0.10.tgz",
|
||||||
"integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==",
|
"integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -8614,7 +8616,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/ipx": {
|
"node_modules/ipx": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/ipx/-/ipx-3.1.1.tgz",
|
"resolved": "https://registry.npmmirror.com/ipx/-/ipx-3.1.1.tgz",
|
||||||
"integrity": "sha512-7Xnt54Dco7uYkfdAw0r2vCly3z0rSaVhEXMzPvl3FndsTVm5p26j+PO+gyinkYmcsEUvX2Rh7OGK7KzYWRu6BA==",
|
"integrity": "sha512-7Xnt54Dco7uYkfdAw0r2vCly3z0rSaVhEXMzPvl3FndsTVm5p26j+PO+gyinkYmcsEUvX2Rh7OGK7KzYWRu6BA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -10139,6 +10141,15 @@
|
|||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/mp4box": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/mp4box/-/mp4box-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-gttYFNmlCjredsdnxqNC6ho0bx6zEwOqAwSKZNQXtsBqvSN1CjtzlTLY9Kfhvt14Co8Iu+qMuOOpnPIRjvvFtw==",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.8.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/mri": {
|
"node_modules/mri": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||||
@@ -10171,7 +10182,7 @@
|
|||||||
},
|
},
|
||||||
"node_modules/nanoid": {
|
"node_modules/nanoid": {
|
||||||
"version": "5.1.5",
|
"version": "5.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.1.5.tgz",
|
"resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-5.1.5.tgz",
|
||||||
"integrity": "sha512-Ir/+ZpE9fDsNH0hQ3C68uyThDXzYcim2EqcZ8zn8Chtt1iylPT9xXJB0kPCnqzgcEGikO9RxSrh63MsmVCU7Fw==",
|
"integrity": "sha512-Ir/+ZpE9fDsNH0hQ3C68uyThDXzYcim2EqcZ8zn8Chtt1iylPT9xXJB0kPCnqzgcEGikO9RxSrh63MsmVCU7Fw==",
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
"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",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"nuxt": "latest",
|
"nuxt": "latest",
|
||||||
"sanitize-html": "^2.17.0",
|
"sanitize-html": "^2.17.0",
|
||||||
|
|||||||
@@ -1,23 +1,48 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="about-page">
|
<div class="about-page">
|
||||||
<BaseTabs v-model="selectedTab" :tabs="tabs">
|
<BaseTabs v-model="selectedTab" :tabs="tabs">
|
||||||
<div class="about-loading" v-if="isFetching">
|
<template v-if="selectedTab === 'api'">
|
||||||
<l-hatch-spinner size="100" stroke="10" speed="1" color="var(--primary-color)" />
|
<div class="about-api">
|
||||||
</div>
|
<div class="about-api-title">调试Token</div>
|
||||||
<div
|
<div v-if="!authState.loggedIn" class="about-api-login">
|
||||||
v-else
|
请<NuxtLink to="/login" class="about-api-login-link">登录</NuxtLink>后查看 Token
|
||||||
class="about-content"
|
</div>
|
||||||
v-html="renderMarkdown(content)"
|
<div v-else class="about-api-token">
|
||||||
@click="handleContentClick"
|
<div class="token-row">
|
||||||
></div>
|
<span class="token-text">{{ shortToken }}</span>
|
||||||
|
<span @click="copyToken"><copy class="copy-icon" /></span>
|
||||||
|
</div>
|
||||||
|
<div class="warning-row">
|
||||||
|
<info-icon class="warning-icon" />
|
||||||
|
<div class="token-warning">请不要将 Token 泄露给他人</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="about-api-title">API文档和调试入口</div>
|
||||||
|
<div class="about-api-link">API Playground <share /></div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="about-loading" v-if="isFetching">
|
||||||
|
<l-hatch-spinner size="100" stroke="10" speed="1" color="var(--primary-color)" />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="about-content"
|
||||||
|
v-html="renderMarkdown(content)"
|
||||||
|
@click="handleContentClick"
|
||||||
|
></div>
|
||||||
|
</template>
|
||||||
</BaseTabs>
|
</BaseTabs>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { onMounted, ref, watch } from 'vue'
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
|
import { useRoute, useRouter } from '#imports'
|
||||||
|
import { authState, getToken } from '~/utils/auth'
|
||||||
import { handleMarkdownClick, renderMarkdown } from '~/utils/markdown'
|
import { handleMarkdownClick, renderMarkdown } from '~/utils/markdown'
|
||||||
import BaseTabs from '~/components/BaseTabs.vue'
|
import BaseTabs from '~/components/BaseTabs.vue'
|
||||||
|
import { toast } from '~/composables/useToast'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AboutPageView',
|
name: 'AboutPageView',
|
||||||
@@ -44,11 +69,25 @@ export default {
|
|||||||
label: '隐私政策',
|
label: '隐私政策',
|
||||||
file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/privacy.md',
|
file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/privacy.md',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'api',
|
||||||
|
label: 'API与调试',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
const selectedTab = ref(tabs[0].key)
|
const selectedTab = ref(tabs[0].key)
|
||||||
const content = ref('')
|
const content = ref('')
|
||||||
|
const token = computed(() => (authState.loggedIn ? getToken() : ''))
|
||||||
|
|
||||||
|
const shortToken = computed(() => {
|
||||||
|
if (!token.value) return ''
|
||||||
|
if (token.value.length <= 20) return token.value
|
||||||
|
return `${token.value.slice(0, 20)}...${token.value.slice(-10)}`
|
||||||
|
})
|
||||||
|
|
||||||
const loadContent = async (file) => {
|
const loadContent = async (file) => {
|
||||||
|
if (!file) return
|
||||||
try {
|
try {
|
||||||
isFetching.value = true
|
isFetching.value = true
|
||||||
const res = await fetch(file)
|
const res = await fetch(file)
|
||||||
@@ -65,19 +104,58 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadContent(tabs[0].file)
|
const initTab = route.query.tab
|
||||||
|
if (initTab && tabs.find((t) => t.key === initTab)) {
|
||||||
|
selectedTab.value = initTab
|
||||||
|
const tab = tabs.find((t) => t.key === initTab)
|
||||||
|
if (tab && tab.file) loadContent(tab.file)
|
||||||
|
} else {
|
||||||
|
loadContent(tabs[0].file)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(selectedTab, (name) => {
|
watch(selectedTab, (name) => {
|
||||||
const tab = tabs.find((t) => t.key === name)
|
const tab = tabs.find((t) => t.key === name)
|
||||||
if (tab) loadContent(tab.file)
|
if (tab && tab.file) loadContent(tab.file)
|
||||||
|
router.replace({ query: { ...route.query, tab: name } })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => route.query.tab,
|
||||||
|
(name) => {
|
||||||
|
if (name && name !== selectedTab.value && tabs.find((t) => t.key === name)) {
|
||||||
|
selectedTab.value = name
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const copyToken = async () => {
|
||||||
|
if (import.meta.client && token.value) {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(token.value)
|
||||||
|
toast.success('已复制 Token')
|
||||||
|
} catch (e) {
|
||||||
|
toast.error('复制失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleContentClick = (e) => {
|
const handleContentClick = (e) => {
|
||||||
handleMarkdownClick(e)
|
handleMarkdownClick(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { tabs, selectedTab, content, renderMarkdown, isFetching, handleContentClick }
|
return {
|
||||||
|
tabs,
|
||||||
|
selectedTab,
|
||||||
|
content,
|
||||||
|
renderMarkdown,
|
||||||
|
isFetching,
|
||||||
|
handleContentClick,
|
||||||
|
authState,
|
||||||
|
token,
|
||||||
|
copyToken,
|
||||||
|
shortToken,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -101,6 +179,66 @@ export default {
|
|||||||
height: 200px;
|
height: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.about-api {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.about-api-title {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
margin-top: 30px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.about-api-login-link {
|
||||||
|
color: var(--primary-color);
|
||||||
|
cursor: pointer;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.about-api-login-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.warning-icon {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token-warning {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.token-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
font: 14px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-btn {
|
||||||
|
padding: 4px 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.about-api-link {
|
||||||
|
color: var(--primary-color);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.about-api-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.about-tabs {
|
.about-tabs {
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
|
|||||||
@@ -424,7 +424,8 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
|||||||
|
|
||||||
.topic-container {
|
.topic-container {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: calc(var(--header-height) + 1px);
|
top: var(--header-height);
|
||||||
|
padding-top: 10px;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
background-color: var(--background-color-blur);
|
background-color: var(--background-color-blur);
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -432,12 +433,10 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px 0;
|
|
||||||
backdrop-filter: var(--blur-10);
|
backdrop-filter: var(--blur-10);
|
||||||
}
|
}
|
||||||
|
|
||||||
.topic-item-container {
|
.topic-item-container {
|
||||||
margin-left: 20px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -478,6 +477,7 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
color: gray;
|
color: gray;
|
||||||
border-bottom: 1px solid var(--normal-border-color);
|
border-bottom: 1px solid var(--normal-border-color);
|
||||||
|
padding-top: 30px;
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,6 +487,7 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-bottom: 1px solid var(--normal-border-color);
|
border-bottom: 1px solid var(--normal-border-color);
|
||||||
|
transition: background-color 0.5s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.article-item:hover {
|
.article-item:hover {
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="chat-container" :class="{ float: isFloatMode }">
|
<div class="chat-container" :class="{ float: isFloatMode }">
|
||||||
|
<vue-easy-lightbox
|
||||||
|
:visible="lightboxVisible"
|
||||||
|
:index="lightboxIndex"
|
||||||
|
:imgs="lightboxImgs"
|
||||||
|
@hide="lightboxVisible = false"
|
||||||
|
/>
|
||||||
<div v-if="!loading" class="chat-header">
|
<div v-if="!loading" class="chat-header">
|
||||||
<div class="header-main">
|
<div class="header-main">
|
||||||
<div class="back-button" @click="goBack">
|
<div class="back-button" @click="goBack">
|
||||||
@@ -14,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>
|
||||||
@@ -101,7 +107,7 @@ import {
|
|||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { getToken, fetchCurrentUser } from '~/utils/auth'
|
import { getToken, fetchCurrentUser } from '~/utils/auth'
|
||||||
import { toast } from '~/main'
|
import { toast } from '~/main'
|
||||||
import { renderMarkdown, stripMarkdownLength } from '~/utils/markdown'
|
import { renderMarkdown, stripMarkdownLength, handleMarkdownClick } from '~/utils/markdown'
|
||||||
import MessageEditor from '~/components/MessageEditor.vue'
|
import MessageEditor from '~/components/MessageEditor.vue'
|
||||||
import ReactionsGroup from '~/components/ReactionsGroup.vue'
|
import ReactionsGroup from '~/components/ReactionsGroup.vue'
|
||||||
import { useWebSocket } from '~/composables/useWebSocket'
|
import { useWebSocket } from '~/composables/useWebSocket'
|
||||||
@@ -110,6 +116,7 @@ import { useChannelsUnreadCount } from '~/composables/useChannelsUnreadCount'
|
|||||||
import TimeManager from '~/utils/time'
|
import TimeManager from '~/utils/time'
|
||||||
import BaseTimeline from '~/components/BaseTimeline.vue'
|
import BaseTimeline from '~/components/BaseTimeline.vue'
|
||||||
import BasePlaceholder from '~/components/BasePlaceholder.vue'
|
import BasePlaceholder from '~/components/BasePlaceholder.vue'
|
||||||
|
import VueEasyLightbox from 'vue-easy-lightbox'
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@@ -135,6 +142,9 @@ const isFloatMode = computed(() => route.query.float !== undefined)
|
|||||||
const floatRoute = useState('messageFloatRoute')
|
const floatRoute = useState('messageFloatRoute')
|
||||||
const replyTo = ref(null)
|
const replyTo = ref(null)
|
||||||
const newMessagesCount = ref(0)
|
const newMessagesCount = ref(0)
|
||||||
|
const lightboxVisible = ref(false)
|
||||||
|
const lightboxIndex = ref(0)
|
||||||
|
const lightboxImgs = ref([])
|
||||||
|
|
||||||
const isUserNearBottom = ref(true)
|
const isUserNearBottom = ref(true)
|
||||||
function updateNearBottom() {
|
function updateNearBottom() {
|
||||||
@@ -451,6 +461,17 @@ function minimize() {
|
|||||||
navigateTo('/')
|
navigateTo('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleContentClick(e) {
|
||||||
|
handleMarkdownClick(e)
|
||||||
|
if (e.target.tagName === 'IMG') {
|
||||||
|
const container = e.target.parentNode
|
||||||
|
const imgs = [...container.querySelectorAll('img')].map((i) => i.src)
|
||||||
|
lightboxImgs.value = imgs
|
||||||
|
lightboxIndex.value = imgs.indexOf(e.target.src)
|
||||||
|
lightboxVisible.value = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function openUser(id) {
|
function openUser(id) {
|
||||||
if (isFloatMode.value) {
|
if (isFloatMode.value) {
|
||||||
// 先不处理...
|
// 先不处理...
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ import {
|
|||||||
Open,
|
Open,
|
||||||
Dislike,
|
Dislike,
|
||||||
CheckOne,
|
CheckOne,
|
||||||
|
Share,
|
||||||
} from '@icon-park/vue-next'
|
} from '@icon-park/vue-next'
|
||||||
|
|
||||||
export default defineNuxtPlugin((nuxtApp) => {
|
export default defineNuxtPlugin((nuxtApp) => {
|
||||||
@@ -157,4 +158,5 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
nuxtApp.vueApp.component('OpenIcon', Open)
|
nuxtApp.vueApp.component('OpenIcon', Open)
|
||||||
nuxtApp.vueApp.component('Dislike', Dislike)
|
nuxtApp.vueApp.component('Dislike', Dislike)
|
||||||
nuxtApp.vueApp.component('CheckOne', CheckOne)
|
nuxtApp.vueApp.component('CheckOne', CheckOne)
|
||||||
|
nuxtApp.vueApp.component('Share', Share)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,6 +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, 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'
|
||||||
@@ -91,10 +93,81 @@ export function createVditor(editorId, options = {}) {
|
|||||||
multiple: false,
|
multiple: false,
|
||||||
handler: async (files) => {
|
handler: async (files) => {
|
||||||
const file = files[0]
|
const file = files[0]
|
||||||
vditor.tip('图片上传中', 0)
|
const ext = file.name.split('.').pop().toLowerCase()
|
||||||
|
const videoExts = ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv']
|
||||||
|
const isVideo = videoExts.includes(ext)
|
||||||
|
|
||||||
|
// 检查文件大小
|
||||||
|
const sizeCheck = checkFileSize(file)
|
||||||
|
if (!sizeCheck.isValid) {
|
||||||
|
console.log(
|
||||||
|
'文件大小不能超过',
|
||||||
|
formatFileSize(sizeCheck.maxSize),
|
||||||
|
',当前文件',
|
||||||
|
formatFileSize(sizeCheck.actualSize),
|
||||||
|
)
|
||||||
|
vditor.tip(
|
||||||
|
`文件大小不能超过 ${formatFileSize(sizeCheck.maxSize)},当前文件 ${formatFileSize(sizeCheck.actualSize)}`,
|
||||||
|
3000,
|
||||||
|
)
|
||||||
|
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.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) {
|
||||||
@@ -103,14 +176,13 @@ 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('上传失败')
|
||||||
return '上传失败'
|
return '上传失败'
|
||||||
}
|
}
|
||||||
|
|
||||||
const ext = file.name.split('.').pop().toLowerCase()
|
|
||||||
const imageExts = [
|
const imageExts = [
|
||||||
'apng',
|
'apng',
|
||||||
'bmp',
|
'bmp',
|
||||||
@@ -132,6 +204,8 @@ export function createVditor(editorId, options = {}) {
|
|||||||
md = ``
|
md = ``
|
||||||
} else if (audioExts.includes(ext)) {
|
} else if (audioExts.includes(ext)) {
|
||||||
md = `<audio controls="controls" src="${info.fileUrl}"></audio>`
|
md = `<audio controls="controls" src="${info.fileUrl}"></audio>`
|
||||||
|
} else if (videoExts.includes(ext)) {
|
||||||
|
md = `<video width="600" controls>\n <source src="${info.fileUrl}" type="video/${ext}">\n 你的浏览器不支持 video 标签。\n</video>`
|
||||||
} else {
|
} else {
|
||||||
md = `[${file.name}](${info.fileUrl})`
|
md = `[${file.name}](${info.fileUrl})`
|
||||||
}
|
}
|
||||||
|
|||||||
72
frontend_nuxt/utils/videoCompressor.js
Normal file
72
frontend_nuxt/utils/videoCompressor.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* 基于 WebCodecs + MP4Box.js 的视频压缩工具
|
||||||
|
* 专为现代浏览器 (Chrome/Safari) 优化
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { UPLOAD_CONFIG } from '../config/uploadConfig.js'
|
||||||
|
import { compressVideoWithWebCodecs, isWebCodecSupported } from './webcodecVideoCompressor.js'
|
||||||
|
|
||||||
|
// 导出配置供外部使用
|
||||||
|
export const VIDEO_CONFIG = UPLOAD_CONFIG.VIDEO
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查文件大小是否超出限制
|
||||||
|
*/
|
||||||
|
export function checkFileSize(file) {
|
||||||
|
return {
|
||||||
|
isValid: file.size <= VIDEO_CONFIG.MAX_SIZE,
|
||||||
|
actualSize: file.size,
|
||||||
|
maxSize: VIDEO_CONFIG.MAX_SIZE,
|
||||||
|
needsCompression: file.size > VIDEO_CONFIG.TARGET_SIZE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化文件大小显示
|
||||||
|
*/
|
||||||
|
export function formatFileSize(bytes) {
|
||||||
|
if (bytes === 0) return '0 B'
|
||||||
|
const k = 1024
|
||||||
|
const sizes = ['B', 'KB', 'MB', 'GB']
|
||||||
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||||
|
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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
98
frontend_nuxt/utils/webcodecVideoCompressor.js
Normal file
98
frontend_nuxt/utils/webcodecVideoCompressor.js
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user