Skip to content

Commit

Permalink
Merge pull request #148 from Lixuhuilll/ArkLevelOpen
Browse files Browse the repository at this point in the history
热度排行实现降低未开放关卡权重的功能
  • Loading branch information
dragove authored Dec 11, 2023
2 parents 6743d06 + e01f95a commit f55e691
Show file tree
Hide file tree
Showing 15 changed files with 403 additions and 31 deletions.
31 changes: 31 additions & 0 deletions src/main/java/plus/maa/backend/common/utils/ArkLevelUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package plus.maa.backend.common.utils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.regex.Pattern;

public class ArkLevelUtil {

private static final Pattern NOT_KEY_INFO = Pattern.compile(
// level_、各种难度前缀、season_、前导零、以-或者_划分的后缀
"^level_|^easy_|^hard_|^tough_|^main_|season_|(?<!\\d)0+(?=\\d)|[-_]+[^-_]+($|[-_]+\\D+$)"
);

/**
* 从 stageId 或者 seasonId 中提取一个地图系列的唯一标识
*
* @param id stageId 或者 seasonId
* @return 地图系列的唯一标识 <br>
* 例如:a1(骑兵与猎人)、act11d0(沃伦姆德的薄暮)、act11mini(未尽篇章)、crisis_v2_1(浊燃作战)
*/
@NotNull
public static String getKeyInfoById(@Nullable String id) {
if (id == null) {
return "";
}
// 去除所有非关键信息
return NOT_KEY_INFO.matcher(id).replaceAll("");
}

}
22 changes: 18 additions & 4 deletions src/main/java/plus/maa/backend/config/HttpInterfaceConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package plus.maa.backend.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
Expand All @@ -13,14 +18,23 @@ public class HttpInterfaceConfig {

@Bean
GithubRepository githubRepository() {

ObjectMapper mapper = Jackson2ObjectMapperBuilder.json()
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.build();

WebClient client = WebClient.builder()
.baseUrl("https://api.github.com")
.exchangeStrategies(ExchangeStrategies
.builder()
.codecs(codecs -> codecs
.defaultCodecs()
// 最大 20MB
.maxInMemorySize(20 * 1024 * 1024))
.codecs(codecs -> {
codecs.defaultCodecs()
.jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
codecs.defaultCodecs()
.jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
// 最大 20MB
codecs.defaultCodecs().maxInMemorySize(20 * 1024 * 1024);
})
.build())
.defaultHeaders(headers -> {
headers.add("Accept", "application/vnd.github+json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.Nullable;

import java.io.Serializable;

Expand All @@ -25,4 +26,7 @@ public class ArkLevelInfo implements Serializable {
private String name;
private int width;
private int height;
// 当前版本地图是否开放
@Nullable
private Boolean isOpen;
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package plus.maa.backend.repository;

import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import plus.maa.backend.repository.entity.ArkLevel;
import plus.maa.backend.repository.entity.ArkLevelSha;

import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

/**
* @author john180
*/
public interface ArkLevelRepository extends MongoRepository<ArkLevel, String> {
List<ArkLevelSha> findAllShaBy();

Page<ArkLevel> findAllByCatOne(String catOne, Pageable pageable);

@Query("""
{
"$or": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.service.annotation.GetExchange;
import plus.maa.backend.repository.entity.github.GithubCommit;
import plus.maa.backend.repository.entity.github.GithubContent;
import plus.maa.backend.repository.entity.github.GithubTrees;

import java.util.List;
Expand All @@ -23,4 +24,7 @@ public interface GithubRepository {
@GetExchange(value = "/repos/MaaAssistantArknights/MaaAssistantArknights/commits")
List<GithubCommit> getCommits(@RequestHeader("Authorization") String token);

@GetExchange(value = "/repos/MaaAssistantArknights/MaaAssistantArknights/contents/{path}")
List<GithubContent> getContents(@RequestHeader("Authorization") String token, @PathVariable("path") String path);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.Nullable;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
Expand Down Expand Up @@ -38,4 +39,7 @@ public class ArkLevel {
private String name;
private int width;
private int height;
// 当前版本地图是否开放
@Nullable
private Boolean isOpen;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package plus.maa.backend.repository.entity.gamedata;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ArkCrisisV2Info {
private String seasonId;
private String name;
// 时间戳,单位:秒
private long startTs;
private long endTs;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package plus.maa.backend.repository.entity.gamedata;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

@Data
// 忽略对服务器无用的数据
@JsonIgnoreProperties(ignoreUnknown = true)
public class MaaArkStage {

/**
* 例: CB-EX8
*/
private String code;

/**
* 例: act5d0_ex08
*/
private String stageId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public boolean isDir() {
return Objects.equals(type, "dir");
}

public boolean isFile() {
return Objects.equals(type, "file");
}

public String getFileExtension() {
return name == null ?
StringUtils.EMPTY :
Expand Down
Loading

0 comments on commit f55e691

Please sign in to comment.