Skip to content

Commit

Permalink
Merge pull request #233 from itning/3.0.0
Browse files Browse the repository at this point in the history
update spring boot version to 3.0.0
  • Loading branch information
itning authored Nov 26, 2022
2 parents 19474cf + ef3c362 commit b77ae28
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 56 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ docker run --name yunshu-nas -p 8888:8888 -e MYSQL_URL=mysql8 -e MYSQL_PORT=3306
| nas.basic-auth.password | basic基础认证密码 | basic基础认证密码,默认空 |
| nas.basic-auth.ignore-path | basic基础认证忽略路径 | 多个路径使用英文逗号分隔,默认空 |
| nas.server-url | 服务端地址,用于前端调用后端API地址 | http://127.0.0.1:8888 |
| ENABLED_ELASTICSEARCH | 是否开启Elasticsearch | true |
| ELASTICSEARCH_URI | Elasticsearch服务端URL | |
| ENABLED_ELASTICSEARCH | 是否开启Elasticsearch | false |
| ELASTICSEARCH_URI | Elasticsearch服务端URL | http://localhost:9200 |

# 启动脚本(aria2c 可以不用)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import jakarta.websocket.*;
import jakarta.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
Expand Down
5 changes: 5 additions & 0 deletions nas-deploy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.servlet.MultipartConfigElement;
import jakarta.servlet.MultipartConfigElement;

/**
* @author itning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class CustomWebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
String[] allMethod = Arrays.stream(HttpMethod.values()).map(Enum::name).toArray(String[]::new);
String[] allMethod = Arrays.stream(HttpMethod.values()).map(HttpMethod::name).toArray(String[]::new);
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowCredentials(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import jakarta.websocket.*;
import jakarta.websocket.server.ServerEndpoint;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import org.springframework.web.filter.OncePerRequestFilter;
import top.itning.yunshunas.common.config.NasProperties;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import top.itning.yunshunas.common.config.NasProperties;

import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down
6 changes: 3 additions & 3 deletions nas-deploy/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spring.datasource.url=jdbc:mysql://${MYSQL_URL:localhost}:${MYSQL_PORT:3306}/yun
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=${MYSQL_USERNAME:root}
spring.datasource.password=${MYSQL_PASSWORD:root}
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=false
spring.jpa.open-in-view=false
spring.jpa.hibernate.ddl-auto=update
Expand Down Expand Up @@ -69,5 +69,5 @@ nas.file-data-source.lyric-file-dir=/home/lyric_yunshu
# ElasticSearch配置
#
##########################################################
spring.data.elasticsearch.repositories.enabled=${ENABLED_ELASTICSEARCH:true}
spring.elasticsearch.uris=${ELASTICSEARCH_URI}
spring.data.elasticsearch.repositories.enabled=${ENABLED_ELASTICSEARCH:false}
spring.elasticsearch.uris=${ELASTICSEARCH_URI:http://localhost:9200}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.springframework.web.bind.annotation.*;
import top.itning.yunshunas.music.service.FileService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import java.io.IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import top.itning.yunshunas.music.service.MusicService;
import top.itning.yunshunas.music.service.SearchService;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import top.itning.yunshunas.music.dto.MusicManageDTO;
import top.itning.yunshunas.music.service.MusicManageService;

import javax.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotEmpty;

/**
* 音乐管理接口
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import jakarta.persistence.*;
import java.util.Date;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.springframework.web.bind.annotation.ResponseBody;
import top.itning.yunshunas.common.model.RestModel;

import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.ConstraintViolationException;

/**
* @author itning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import top.itning.yunshunas.music.dto.MusicMetaInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import top.itning.yunshunas.music.service.FileService;
import top.itning.yunshunas.music.service.MusicMetaInfoService;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import top.itning.yunshunas.music.repository.MusicRepository;
import top.itning.yunshunas.music.service.MusicService;

import javax.transaction.Transactional;
import jakarta.transaction.Transactional;

/**
* @author itning
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package top.itning.yunshunas.music.service.impl;

import co.elastic.clients.elasticsearch._types.query_dsl.MatchPhraseQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.HighlightQuery;
import org.springframework.data.elasticsearch.core.query.highlight.Highlight;
import org.springframework.data.elasticsearch.core.query.highlight.HighlightField;
import org.springframework.data.elasticsearch.core.query.highlight.HighlightFieldParameters;
import org.springframework.stereotype.Service;
import top.itning.yunshunas.music.datasource.CoverDataSource;
import top.itning.yunshunas.music.datasource.LyricDataSource;
Expand Down Expand Up @@ -42,20 +46,25 @@ public class SearchServiceImpl implements SearchService {
private static final String SEARCH_FILED_FOR_LYRIC = "content";

private final LyricElasticsearchRepository lyricElasticsearchRepository;
private final ElasticsearchRestTemplate elasticsearchRestTemplate;
private final MusicRepository musicRepository;
private final MusicDataSource musicDataSource;
private final LyricDataSource lyricDataSource;
private final CoverDataSource coverDataSource;
private final ElasticsearchTemplate elasticsearchTemplate;

@Autowired
public SearchServiceImpl(LyricElasticsearchRepository lyricElasticsearchRepository, ElasticsearchRestTemplate elasticsearchRestTemplate, MusicRepository musicRepository, MusicDataSource musicDataSource, LyricDataSource lyricDataSource, CoverDataSource coverDataSource) {
public SearchServiceImpl(LyricElasticsearchRepository lyricElasticsearchRepository,
MusicRepository musicRepository,
MusicDataSource musicDataSource,
LyricDataSource lyricDataSource,
CoverDataSource coverDataSource,
ElasticsearchTemplate elasticsearchTemplate) {
this.lyricElasticsearchRepository = lyricElasticsearchRepository;
this.elasticsearchRestTemplate = elasticsearchRestTemplate;
this.musicRepository = musicRepository;
this.musicDataSource = musicDataSource;
this.lyricDataSource = lyricDataSource;
this.coverDataSource = coverDataSource;
this.elasticsearchTemplate = elasticsearchTemplate;
}

@Override
Expand Down Expand Up @@ -96,14 +105,15 @@ public void deleteLyric(String lyricId) {

@Override
public List<SearchResult> searchLyric(String keyword, Pageable pageable) {
SearchHits<Lyric> search = elasticsearchRestTemplate.search(
new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.matchPhraseQuery(SEARCH_FILED_FOR_LYRIC, keyword))
.withHighlightBuilder(new HighlightBuilder().field(SEARCH_FILED_FOR_LYRIC, 50, 1))
SearchHits<Lyric> search = elasticsearchTemplate.search(
new NativeQueryBuilder()
.withQuery(new Query.Builder().matchPhrase(new MatchPhraseQuery.Builder().field(SEARCH_FILED_FOR_LYRIC).query(keyword).build()).build())
.withHighlightQuery(new HighlightQuery(new Highlight(Collections.singletonList(new HighlightField(SEARCH_FILED_FOR_LYRIC, HighlightFieldParameters.builder().withFragmentSize(50).withNumberOfFragments(1).build()))), null))
.withPageable(pageable)
.build()
, Lyric.class
.build(),
Lyric.class
);

if (!search.hasSearchHits()) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import top.itning.yunshunas.video.service.VideoService;
import top.itning.yunshunas.video.video.VideoTransformHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import top.itning.yunshunas.common.config.NasProperties;
import top.itning.yunshunas.video.repository.IVideoRepository;

import javax.annotation.Nonnull;
import jakarta.annotation.Nonnull;
import java.io.File;

/**
Expand Down
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.6</version>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>top.itning.yunshu-nas</groupId>
Expand Down Expand Up @@ -100,11 +100,6 @@
<artifactId>mapstruct-processor</artifactId>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
Expand Down

0 comments on commit b77ae28

Please sign in to comment.