feat: add dicker ignore; add search logic
This commit is contained in:
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
src/main/resources/application.yml
|
||||||
@@ -15,10 +15,12 @@ FROM harbor.merlin.xin/mirrors/docker.io/library/eclipse-temurin:17-jre-alpine
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/target/*.jar app.jar
|
COPY --from=builder /app/target/*.jar app.jar
|
||||||
|
|
||||||
RUN mkdir -p uploads/photo
|
RUN mkdir -p /app/uploads/photo \
|
||||||
|
&& chown -R spring:spring /app/uploads
|
||||||
|
|
||||||
# 非 root 用户运行
|
# 非 root 用户运行
|
||||||
RUN addgroup -S spring && adduser -S spring -G spring
|
RUN addgroup -S spring && adduser -S spring -G spring
|
||||||
USER spring
|
USER spring
|
||||||
|
|
||||||
ENTRYPOINT ["java","-jar","/app/app.jar"]
|
ENTRYPOINT ["java","-jar","/app/app.jar", "--spring.config.location=file:/app/application.yml"]
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class SecurityConfig {
|
|||||||
.requestMatchers(
|
.requestMatchers(
|
||||||
"/login",
|
"/login",
|
||||||
"/register",
|
"/register",
|
||||||
"/test",
|
"/health",
|
||||||
"/code/**",
|
"/code/**",
|
||||||
"/blog/**"
|
"/blog/**"
|
||||||
).permitAll()
|
).permitAll()
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package xin.merlin.myblog_server.controller;
|
package xin.merlin.myblog_server.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -13,6 +16,8 @@ import xin.merlin.myblog_server.utils.JwtUtil;
|
|||||||
import xin.merlin.myblog_server.utils.RequestBack;
|
import xin.merlin.myblog_server.utils.RequestBack;
|
||||||
import xin.merlin.myblog_server.utils.enums.ResultCode;
|
import xin.merlin.myblog_server.utils.enums.ResultCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/blog")
|
@RequestMapping("/blog")
|
||||||
public class BasicController {
|
public class BasicController {
|
||||||
@@ -43,8 +48,24 @@ public class BasicController {
|
|||||||
@GetMapping("/get/news")
|
@GetMapping("/get/news")
|
||||||
public RequestBack getNews(@RequestParam Integer current,@RequestParam Integer size) {
|
public RequestBack getNews(@RequestParam Integer current,@RequestParam Integer size) {
|
||||||
Page<News> page = new Page<>(current,size);
|
Page<News> page = new Page<>(current,size);
|
||||||
|
page.setOrders(List.of(OrderItem.desc("published")));
|
||||||
return RequestBack.success(ResultCode.SUCCESS,newsService.page(page));
|
return RequestBack.success(ResultCode.SUCCESS,newsService.page(page));
|
||||||
}
|
}
|
||||||
|
// 搜索新闻
|
||||||
|
@PostMapping("/search/news")
|
||||||
|
public RequestBack searchNews(@RequestParam Integer current,
|
||||||
|
@RequestParam Integer size,
|
||||||
|
@RequestBody News news) {
|
||||||
|
|
||||||
|
Page<News> page = new Page<>(current, size);
|
||||||
|
QueryWrapper<News> qw = new QueryWrapper<>();
|
||||||
|
qw.like(news.getTitle() != null, "title", news.getTitle())
|
||||||
|
.orderByDesc("published");
|
||||||
|
|
||||||
|
IPage<News> result = newsService.page(page, qw);
|
||||||
|
|
||||||
|
return RequestBack.success(ResultCode.SUCCESS, result);
|
||||||
|
}
|
||||||
// 获取文章
|
// 获取文章
|
||||||
@GetMapping("/get/article/{a_id}")
|
@GetMapping("/get/article/{a_id}")
|
||||||
public RequestBack getArticle(@PathVariable Integer a_id) {
|
public RequestBack getArticle(@PathVariable Integer a_id) {
|
||||||
@@ -62,5 +83,20 @@ public class BasicController {
|
|||||||
commentService.save(comment);
|
commentService.save(comment);
|
||||||
return RequestBack.success(ResultCode.SUCCESS);
|
return RequestBack.success(ResultCode.SUCCESS);
|
||||||
}
|
}
|
||||||
|
// 搜索新闻
|
||||||
|
@PostMapping("/search/articles")
|
||||||
|
public RequestBack searchArticles(@RequestParam Integer current,
|
||||||
|
@RequestParam Integer size,
|
||||||
|
@RequestBody Article article) {
|
||||||
|
|
||||||
|
Page<Article> page = new Page<>(current, size);
|
||||||
|
QueryWrapper<Article> qw = new QueryWrapper<>();
|
||||||
|
qw.like(article.getTitle() != null, "title", article.getTitle())
|
||||||
|
.orderByDesc("published");
|
||||||
|
|
||||||
|
IPage<Article> result = articleService.page(page, qw);
|
||||||
|
|
||||||
|
return RequestBack.success(ResultCode.SUCCESS, result);
|
||||||
|
}
|
||||||
// 联系管理员
|
// 联系管理员
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package xin.merlin.myblog_server.controller;
|
package xin.merlin.myblog_server.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.github.benmanes.caffeine.cache.Cache;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -17,7 +15,6 @@ import xin.merlin.myblog_server.service.LoginService;
|
|||||||
import xin.merlin.myblog_server.service.impl.UserServiceImpl;
|
import xin.merlin.myblog_server.service.impl.UserServiceImpl;
|
||||||
import xin.merlin.myblog_server.utils.JwtUtil;
|
import xin.merlin.myblog_server.utils.JwtUtil;
|
||||||
import xin.merlin.myblog_server.utils.RequestBack;
|
import xin.merlin.myblog_server.utils.RequestBack;
|
||||||
import xin.merlin.myblog_server.utils.SHA256Util;
|
|
||||||
import xin.merlin.myblog_server.utils.enums.ResultCode;
|
import xin.merlin.myblog_server.utils.enums.ResultCode;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -31,8 +28,6 @@ public class LoginController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserServiceImpl userServiceImpl;
|
private UserServiceImpl userServiceImpl;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SHA256Util sha256Util;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JwtUtil jwtUtil;
|
private JwtUtil jwtUtil;
|
||||||
|
|||||||
@@ -1,19 +1,12 @@
|
|||||||
package xin.merlin.myblog_server.controller;
|
package xin.merlin.myblog_server.controller;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
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 xin.merlin.myblog_server.utils.JwtUtil;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class TestController {
|
public class TestController {
|
||||||
|
@GetMapping("/health")
|
||||||
@Autowired
|
|
||||||
private JwtUtil jwtUtil;
|
|
||||||
|
|
||||||
@GetMapping("/test")
|
|
||||||
public String test() {
|
public String test() {
|
||||||
String token = jwtUtil.generateToken("1223",12);
|
return "ok";
|
||||||
return token;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
package xin.merlin.myblog_server.utils;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class SHA256Util {
|
|
||||||
/**
|
|
||||||
* 对输入字符串进行SHA-256加密
|
|
||||||
* @param input 输入字符串
|
|
||||||
* @return 加密后的十六进制字符串
|
|
||||||
*/
|
|
||||||
public String encryptSHA256(String input) {
|
|
||||||
try {
|
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
|
||||||
byte[] encodedhash = digest.digest(input.getBytes());
|
|
||||||
return bytesToHex(encodedhash);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new RuntimeException("SHA-256 algorithm not found", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将字节数组转换为十六进制字符串
|
|
||||||
* @param hash 字节数组
|
|
||||||
* @return 十六进制字符串
|
|
||||||
*/
|
|
||||||
private String bytesToHex(byte[] hash) {
|
|
||||||
StringBuilder hexString = new StringBuilder(2 * hash.length);
|
|
||||||
for (int i = 0; i < hash.length; i++) {
|
|
||||||
String hex = Integer.toHexString(0xff & hash[i]);
|
|
||||||
if (hex.length() == 1) {
|
|
||||||
hexString.append('0');
|
|
||||||
}
|
|
||||||
hexString.append(hex);
|
|
||||||
}
|
|
||||||
return hexString.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用用户ID生成盐值,并对密码进行加密
|
|
||||||
* @param password 用户输入的密码
|
|
||||||
* @return 加密后的密码哈希值
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String encryptPassword(String password) {
|
|
||||||
// 将盐值与密码拼接后进行SHA-256加密
|
|
||||||
return encryptSHA256( password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
server:
|
server:
|
||||||
port: 8080
|
port: 8080
|
||||||
# port: 8443
|
|
||||||
# ssl:
|
|
||||||
# key-store: classpath:merlin.xin.pfx
|
|
||||||
# key-store-password: 7p7vcfmu
|
|
||||||
# key-store-type: PKCS12
|
|
||||||
# address: 0.0.0.0
|
|
||||||
|
|
||||||
jwt:
|
jwt:
|
||||||
secret: CkmEXxVBNBsMUo4VNhDcH0YBhA1O4zSkQgSM243YzDY=
|
secret: CkmEXxVBNBsMUo4VNhDcH0YBhA1O4zSkQgSM243YzDY=
|
||||||
@@ -27,12 +21,6 @@ spring:
|
|||||||
jackson:
|
jackson:
|
||||||
time-zone: Asia/Shanghai
|
time-zone: Asia/Shanghai
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
# url: jdbc:mysql://8.138.214.149:3306/blog
|
|
||||||
# username: root
|
|
||||||
# password: 3604162
|
|
||||||
# username: root
|
|
||||||
# password: server2025_xyf_Merlin
|
|
||||||
# driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
|
|
||||||
|
|
||||||
mail:
|
mail:
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user