Skip to content

Commit a144e99

Browse files
committed
flyway
1 parent 1ae3de6 commit a144e99

35 files changed

+6161
-1492
lines changed

blog-sever/gradle/libs.versions.toml

Lines changed: 159 additions & 86 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-all.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

blog-sever/server-java/build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ configurations {
2121

2222

2323
dependencies {
24+
implementation("org.flywaydb:flyway-core")
25+
implementation("org.flywaydb:flyway-database-postgresql")
2426
compileOnly ("org.projectlombok:lombok")
2527
annotationProcessor ("org.projectlombok:lombok")
28+
testCompileOnly ("org.projectlombok:lombok")
29+
testAnnotationProcessor ("org.projectlombok:lombok")
30+
2631
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
2732
implementation("org.springframework.boot:spring-boot-starter-security")
2833
implementation("org.springframework.boot:spring-boot-starter-web")
@@ -50,7 +55,7 @@ dependencies {
5055
// https://mvnrepository.com/artifact/com.freewayso/image-combiner
5156
implementation(libs.imageCombiner)
5257

53-
58+
implementation(libs.bundles.springUtils)
5459

5560
implementation(libs.javaJwt)
5661

blog-sever/server-java/src/main/java/com/site/blog/ServerJava.java renamed to blog-sever/server-java/src/main/java/com/site/blog/BlogApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
@SpringBootApplication
2323

2424
@Slf4j
25-
public class ServerJava {
25+
public class BlogApp {
2626
public static void main(String[] args) throws UnknownHostException {
27-
var application= SpringApplication.run(ServerJava.class, args);
27+
var application= SpringApplication.run(BlogApp.class, args);
2828

2929
log.info("""
3030
..######..##.....##..######...######..########..######...######.

blog-sever/server-java/src/main/java/com/site/blog/config/listener/ConstantsInitListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.context.ApplicationListener;
1616
import org.springframework.core.Ordered;
1717
import org.springframework.core.env.ConfigurableEnvironment;
18+
import org.springframework.stereotype.Component;
1819

1920
import java.sql.Connection;
2021
import java.sql.DriverManager;
@@ -32,7 +33,7 @@
3233
*
3334
* @author yanni
3435
*/
35-
36+
@Component
3637
public class ConstantsInitListener implements ApplicationListener<ApplicationContextInitializedEvent>, Ordered {
3738

3839
private static final Log log = Log.get();

blog-sever/server-java/src/main/java/com/site/blog/config/listener/SqlConstant.java

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,7 @@
66
* @modified By:
77
*/
88
public interface SqlConstant {
9-
String initAdminSql= """
10-
INSERT INTO "public"."admin_user" ("id", "username", "password", "nickname", "locked", "role", "avatar") VALUES ('myid', 'admin', 'e10adc3949ba59abbe56e057f20f883e', '啊啊啊', 'f', 1, 'http://localhost:2801/upload/20220615_163021.jpg');
11-
""";
12-
String insertConfigDataSql = """
13-
INSERT INTO "public"."blog_config" VALUES ('sysAuthor', '开发者', '飞雪', '2019-08-24 20:33:17', '2019-08-30 03:27:35', 1);
14-
INSERT INTO "public"."blog_config" VALUES ('init', '初始化', 'init', '2019-08-24 20:33:17', '2019-08-30 03:27:35', 'init');
15-
INSERT INTO "public"."blog_config" VALUES ('sysAuthorImg', '开发者头像', 'http://localhost/2801/logo.img', '2019-08-24 20:33:14', '2019-08-24 21:56:23', 2);
16-
INSERT INTO "public"."blog_config" VALUES ('sysEmail', '开发者邮箱', 'xxxx@qq.com', '2019-08-24 14:06:48', '2019-08-24 14:06:51', 4);
17-
INSERT INTO "public"."blog_config" VALUES ('sysUrl', '服务器url', 'localhost:2801', '2019-08-24 14:03:23', '2019-08-24 14:03:26', 6);
18-
INSERT INTO "public"."blog_config" VALUES ('sysVersion', '当前版本号', '1.1.0', '2019-08-24 20:33:23', '2019-08-24 11:58:06', 7);
19-
INSERT INTO "public"."blog_config" VALUES ('websiteName', '博客名', '七月飞雪', '2018-11-11 20:33:01', '2021-08-10 09:54:45', 8);
20-
INSERT INTO "public"."blog_config" VALUES ('sysCopyRight', '版权所', 'yzqdev', '2019-08-24 20:33:31', '2022-05-14 20:42:11.383', 3);
21-
INSERT INTO "public"."blog_config" VALUES ('sysUpdateTime', '最后修改时间', '2022-03-24 20:33:23', '2019-08-24 20:33:20', '2022-05-14 20:43:17.239', 5);""";
22-
String initTagSql= """
23-
INSERT INTO "public"."tag" ("tag_id", "tag_name", "create_time", "show") VALUES ('1', '默认tag', '2021-08-26 13:05:01', 't');
24-
""";
25-
String initCateSql= """
26-
INSERT INTO "public"."category" ("category_id", "category_name", "category_icon", "category_rank", "create_time", "show") VALUES ('1', '默认分类', '', 1, '2019-08-30 15:07:02', 't');
27-
""";
28-
String initLinkSql= """
29-
INSERT INTO "public"."link" ("link_id", "link_type", "link_name", "link_url", "link_description", "link_rank", "is_deleted", "create_time", "update_time") VALUES ('1', 0, '百度', 'https://www.baidu.com', '这是百度', 0, 1, '2021-08-25 20:17:06', '2021-08-25 20:17:06');
30-
INSERT INTO "public"."link" ("link_id", "link_type", "link_name", "link_url", "link_description", "link_rank", "is_deleted", "create_time", "update_time") VALUES ('2', 0, 'github', 'https://github.com', '这是github', 0, 1, '2019-09-02 21:24:44', NULL);
31-
INSERT INTO "public"."link" ("link_id", "link_type", "link_name", "link_url", "link_description", "link_rank", "is_deleted", "create_time", "update_time") VALUES ('4', 1, '饿了吗', 'https://element-plus.gitee.io/#/zh-CN/component/link#tu-biao', '222222', 123, 0, '2019-09-03 14:47:21', NULL);
32-
""";
33-
String oldSqlString="""
34-
oldstring
35-
""";
369

37-
String initSysDictTypeSql= """
38-
INSERT INTO "public"."sys_dict_type" ("id", "name", "code", "sort", "remark", "status", "create_time", "update_time") VALUES ('1537673136371220481', '邮件类型', 'email_type', 0, '啊啊', 't', NULL, NULL);
39-
INSERT INTO "public"."sys_dict_type" ("id", "name", "code", "sort", "remark", "status", "create_time", "update_time") VALUES ('1537672535637835778', '性别', 'sex', 0, '', 't', '2022-06-17 15:14:00', '2022-06-17 15:14:03');
40-
41-
""";
42-
String initSysDictDataSql= """
43-
INSERT INTO "public"."sys_dict_data" ("id", "type_id", "value", "code", "sort", "remark", "status", "create_time", "update_time") VALUES ('1537686611881369602', 'sex', '男', 'man', 0, '', 't', '2022-06-17 15:14:14', '2022-06-17 15:14:16');
44-
INSERT INTO "public"."sys_dict_data" ("id", "type_id", "value", "code", "sort", "remark", "status", "create_time", "update_time") VALUES ('1537687111485890562', 'sex', '女', 'girl', 0, '啊', 't', '2022-06-17 14:42:30.883645', '2022-06-17 14:42:30.883645');
45-
46-
""";
10+
11+
4712
}

blog-sever/server-java/src/main/java/com/site/blog/config/security/JwtAuthenticationTokenFilter.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@
3434
/**
3535
* @author yzqde
3636
*/
37-
@Component
37+
@Component
3838
@Slf4j
39-
@RequiredArgsConstructor
39+
@RequiredArgsConstructor
4040
public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
4141

4242

4343
private final UserDetailsServiceImpl userDetailsService;
4444

45-
private final AdminUserService adminUserService;
46-
45+
private final AdminUserService adminUserService;
4746

4847

4948
@Override
@@ -58,18 +57,18 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
5857
String authToken = authHeader;
5958
log.info("authToken:{}", authToken);
6059
//verify token
61-
if (!JwtService.verifyToken(authToken )) {
60+
if (!JwtService.verifyToken(authToken)) {
6261
log.info("invalid token");
6362
filterChain.doFilter(request, response);
6463
return;
6564
}
6665

67-
final String userName = (String) JwtService.getUsername(authToken) ;
68-
AdminUser user = adminUserService.getOne( new QueryWrapper<AdminUser>().eq("username",userName));
66+
final String userName = (String) JwtService.getUsername(authToken);
67+
AdminUser user = adminUserService.getOne(new QueryWrapper<AdminUser>().eq("username", userName));
6968
UserVo userVo = new UserVo();
70-
BeanUtils.copyProperties(user,userVo);
69+
BeanUtils.copyProperties(user, userVo);
7170
log.info("这里设置用户到session");
72-
log.info("user={}","myid");
71+
log.info("user={}", "myid");
7372
log.info("user=" + user);
7473
request.setAttribute(BaseConstants.USER_ATTR, userVo);
7574
UserDetails userDetails = userDetailsService.loadUserByUsername(userName);

blog-sever/server-java/src/main/java/com/site/blog/config/security/SecurityConfig.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,40 @@
3232
@EnableMethodSecurity
3333
@RequiredArgsConstructor
3434
public class SecurityConfig {
35-
private final JwtAuthenticationTokenFilter authenticationTokenFilter;
36-
35+
private final JwtAuthenticationTokenFilter authenticationTokenFilter;
3736

3837

3938
@Bean
4039
public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception {
4140
return authConfig.getAuthenticationManager();
4241
}
42+
4343
@Bean
44-
CorsConfigurationSource corsConfigSource() {
44+
CorsConfigurationSource corsConfigSource() {
4545
CorsConfiguration configuration = new CorsConfiguration();
4646
configuration.setAllowedHeaders(Collections.singletonList("*"));
4747
configuration.setAllowedOriginPatterns(Collections.singletonList("*"));
48-
configuration.setAllowCredentials(true);
48+
configuration.setAllowCredentials(true);
4949
configuration.setAllowedMethods(Collections.singletonList("*"));
5050
configuration.setMaxAge(3600L);
5151
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
5252
source.registerCorsConfiguration("/**", configuration);
5353
return source;
5454
}
55+
5556
@Bean
5657
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
57-
http.cors(i->i.configurationSource(corsConfigSource()));
58+
http.cors(i -> i.configurationSource(corsConfigSource()));
5859
http.csrf(i -> i.disable());
5960
http.formLogin(i -> i.disable());
6061
http.httpBasic(i -> i.disable());
6162
http.authorizeHttpRequests(auth -> {
62-
auth.requestMatchers( "/css/**","/upload/**", "/js/**", "/index.html", "/img/**", "/fonts/**" , "/verifyCode", "/swagger-ui/*", "/v2/api-docs/**", "/v3/api-docs/**",
63-
"/swagger-resources",
64-
"/swagger-resources/**",
63+
auth.requestMatchers("/css/**", "/upload/**", "/js/**", "/index.html", "/img/**", "/fonts/**", "/verifyCode", "/swagger-ui/*", "/v2/api-docs/**", "/v3/api-docs/**",
64+
"/swagger-resources",
65+
"/swagger-resources/**",
6566

66-
"/swagger-ui/**",
67-
"/webjars/**", "/api-docs","/v2/auth/**","/v2/home/**").permitAll()
67+
"/swagger-ui/**",
68+
"/webjars/**", "/api-docs", "/v2/auth/**", "/v2/home/**").permitAll()
6869
.requestMatchers("/v2/admin/**").authenticated();
6970
;
7071
});

blog-sever/server-java/src/main/java/com/site/blog/controller/CommentController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public Result updateCommentStatus(@PathVariable("id") String id, @RequestParam("
9696
public Result<String> deleteComment(@PathVariable("id") String id) {
9797
boolean flag = commentService.removeById(id);
9898
if (flag) {
99-
return ResultGenerator.getResultByHttp(HttpStatusEnum.OK);
99+
return ResultGenerator.getResultByHttp(HttpStatusEnum.OK,true,null);
100100
}
101-
return ResultGenerator.getResultByHttp(HttpStatusEnum.INTERNAL_SERVER_ERROR);
101+
return ResultGenerator.getResultByHttp(HttpStatusEnum.INTERNAL_SERVER_ERROR,false,null);
102102
}
103103

104104

blog-sever/server-java/src/main/java/com/site/blog/controller/HomeBlogController.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.site.blog.util.RequestHelper;
1717
import com.site.blog.util.ResultGenerator;
1818
import lombok.RequiredArgsConstructor;
19+
import lombok.extern.slf4j.Slf4j;
1920
import org.apache.commons.text.StringEscapeUtils;
2021
import org.springframework.beans.BeanUtils;
2122
import org.springframework.util.StringUtils;
@@ -34,6 +35,7 @@
3435
@RequestMapping("/v2/home")
3536
@io.swagger.v3.oas.annotations.tags.Tag(name = "首页数据", description = "首页")
3637
@RequiredArgsConstructor
38+
@Slf4j
3739
public class HomeBlogController {
3840

3941

@@ -383,27 +385,31 @@ public Result link() {
383385
* @date 2019/9/6 17:40
384386
*/
385387
@PostMapping(value = "/blog/comment")
386-
@ResponseBody
388+
387389
public Result<? super String> comment(Comment comment) {
388-
var request = RequestHelper.getHttpServletRequest();
389-
String ref = request.getHeader("Referer");
390-
391-
392-
// 对非法字符进行转义,防止xss漏洞
393-
comment.setCommentBody(StringEscapeUtils.escapeHtml4(comment.getCommentBody()));
394-
comment.setCommentStatus(true);
395-
comment.setCommentatorIp(RequestHelper.getRequestIp());
396-
comment.setUserAgent(RequestHelper.getUa().getBrowser() + RequestHelper.getUa().getVersion());
397-
comment.setOs(RequestHelper.getUa().getOs().toString());
398-
comment.setCommentCreateTime(LocalDateTime.now());
399-
comment.setDeleted(true);
400-
if (!StringUtils.hasText(ref)) {
401-
return ResultGenerator.getResultByHttp(HttpStatusEnum.INTERNAL_SERVER_ERROR,false, "非法请求");
402-
}
403-
boolean flag = commentService.save(comment);
404-
if (flag) {
405-
return ResultGenerator.getResultByHttp(HttpStatusEnum.OK, true, comment);
406-
}
390+
try {
391+
var request = RequestHelper.getHttpServletRequest();
392+
String ref = request.getHeader("Referer");
393+
394+
395+
// 对非法字符进行转义,防止xss漏洞
396+
comment.setCommentBody(StringEscapeUtils.escapeHtml4(comment.getCommentBody()));
397+
comment.setCommentStatus(true);
398+
comment.setCommentatorIp(RequestHelper.getRequestIp());
399+
comment.setUserAgent(RequestHelper.getUa().getBrowser() + RequestHelper.getUa().getVersion());
400+
comment.setOs(RequestHelper.getUa().getOs().toString());
401+
comment.setCommentCreateTime(LocalDateTime.now());
402+
comment.setDeleted(true);
403+
// if (!StringUtils.hasText(ref)) {
404+
// return ResultGenerator.getResultByHttp(HttpStatusEnum.INTERNAL_SERVER_ERROR,false, "非法请求");
405+
// }
406+
boolean flag = commentService.save(comment);
407+
if (flag) {
408+
return ResultGenerator.getResultByHttp(HttpStatusEnum.OK, true, comment);
409+
}
410+
}catch (Exception e){
411+
log.error(e.getMessage(),e);
412+
}
407413
return ResultGenerator.getResultByHttp(HttpStatusEnum.INTERNAL_SERVER_ERROR, false, null);
408414
}
409415

0 commit comments

Comments
 (0)