Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Dec 26, 2024
1 parent 294f7fc commit 68a4829
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package com.ghostchu.btn.sparkle.config;

import com.ghostchu.btn.sparkle.module.user.UserService;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
private final UserService userService;

public SaTokenConfigure(UserService userService) {
this.userService = userService;
}

// 注册拦截器
@Override
public void addInterceptors(InterceptorRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ResponseEntity<StdResp<Void>> noResourceFoundException(Exception e) {
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<StdResp<Void>> illegalArgument(IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new StdResp<>(false, "IllegalArgument: " + e.getMessage(), null));
.body(new StdResp<>(false, "无效参数: " + e.getMessage(), null));
}

@ExceptionHandler(AsyncRequestNotUsableException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public MVCAdviceHandler(UserService userService) {

@ModelAttribute("user")
public UserDto addUserToModel(HttpServletRequest request) {
if (!StpUtil.isLogin()) return null;
try {
var optional = userService.getUser((StpUtil.getLoginIdAsLong()));
// 同时更新最后访问时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.ghostchu.btn.sparkle.module.banhistory.internal.BanHistoryRepository;
import com.ghostchu.btn.sparkle.module.clientdiscovery.ClientDiscoveryService;
import com.ghostchu.btn.sparkle.module.clientdiscovery.ClientIdentity;
import com.ghostchu.btn.sparkle.module.user.UserService;
import com.ghostchu.btn.sparkle.util.IPMerger;
import com.ghostchu.btn.sparkle.util.IPUtil;
import com.ghostchu.btn.sparkle.util.LargeFileReader;
Expand Down Expand Up @@ -83,8 +82,6 @@ public class AnalyseService {
@Autowired
private MeterRegistry meterRegistry;
@Autowired
private UserService userService;
@Autowired
private ClientDiscoveryService clientDiscoveryService;
// @Autowired
// private RedisTrackedPeerRepository redisTrackedPeerRepository;
Expand Down Expand Up @@ -163,7 +160,7 @@ public List<AnalysedRule> getOverDownloadIPAddresses() {
@Modifying
@Lock(LockModeType.READ)
@Scheduled(cron = "${analyse.highriskips.interval}")
public void cronHighRiskIps() throws InterruptedException {
public void cronHighRiskIps() {
var startAt = System.currentTimeMillis();
final var ipTries = new DualIPv4v6Tries();
banHistoryRepository.findAllByPaging((Specification<BanHistory>) (root, query, criteriaBuilder) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.ghostchu.btn.sparkle.controller.SparkleController;
import com.ghostchu.btn.sparkle.exception.AccessDeniedException;
import com.ghostchu.btn.sparkle.module.audit.AuditService;
import com.ghostchu.btn.sparkle.module.ping.ability.impl.*;
import com.ghostchu.btn.sparkle.module.ping.ability.impl.CloudRuleAbility;
import com.ghostchu.btn.sparkle.module.ping.ability.impl.ReconfigureAbility;
import com.ghostchu.btn.sparkle.module.ping.ability.impl.SubmitBansAbility;
import com.ghostchu.btn.sparkle.module.ping.dto.BtnBanPing;
import com.ghostchu.btn.sparkle.module.ping.dto.BtnPeerHistoryPing;
import com.ghostchu.btn.sparkle.module.ping.dto.BtnPeerPing;
Expand All @@ -29,6 +31,7 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -46,8 +49,6 @@ public class PingController extends SparkleController {
@Autowired
private PingService pingService;
@Autowired
private SubmitPeersAbility submitPeersAbility;
@Autowired
private SubmitBansAbility submitBansAbility;
@Autowired
private ReconfigureAbility reconfigureAbility;
Expand All @@ -63,8 +64,6 @@ public class PingController extends SparkleController {
private String sparkleRootChina;
@Autowired
private GeoIPManager geoIPManager;
@Autowired
private SubmitHistoriesAbility submitHistoriesAbility;

@PostMapping("/peers/submit")
public ResponseEntity<String> submitPeers(@RequestBody @Validated BtnPeerPing ping) throws AccessDeniedException, UnknownHostException {
Expand Down Expand Up @@ -142,11 +141,11 @@ public ResponseEntity<Object> config() throws AccessDeniedException, JsonProcess
}
log.info("[OK] [Config] [{}] 响应配置元数据 (AppId={}, UA={})",
ip(req), cred.getAppId(), ua(req));
Map<String, Object> rootObject = new LinkedHashMap<>();
Map<String, Object> rootObject = new HashMap<>();
rootObject.put("min_protocol_version", pingService.getMinProtocolVersion());
rootObject.put("max_protocol_version", pingService.getMaxProtocolVersion());

Map<String, Object> abilityObject = new LinkedHashMap<>();
Map<String, Object> abilityObject = new HashMap<>();
rootObject.put("ability", abilityObject);
//abilityObject.put("submit_peers", submitPeersAbility);
abilityObject.put("submit_bans", submitBansAbility);
Expand Down Expand Up @@ -191,10 +190,6 @@ public ResponseEntity<String> rule() throws IOException, AccessDeniedException {
return ResponseEntity.status(200).contentType(MediaType.APPLICATION_JSON).body(objectMapper.writeValueAsString(btn));
}

private void checkIfInvalidPBH() throws AccessDeniedException {
String ua = req.getHeader("User-Agent");
}

public boolean isCredBanned(UserApplication userApplication) {
return userApplication.getBannedAt() != null || userApplication.getUser().getBannedAt() != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import lombok.NoArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.Objects;

@Controller
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

<div class="alert alert-warning" role="alert">
<b><i class="fa-solid fa-clock"></i> 运行受限</b> 由于 BTN 网络目前正面临巨大的负载,我们暂时禁用了 BTN
网络的部分自动分析功能,直至负载问题得到解决。过量下载分析功能当前处于禁用状态。
网络的部分自动分析功能,直至负载问题得到解决。
</div>


<div class="alert alert-danger" role="alert" th:if="${user.getBannedAt() != null}">
<b><i class="fa-solid fa-ban"></i> 账户暂停</b> 您的 BTN 账户已被管理员停用,原因: <span
th:text="${user.getBannedReason()}">未知</span>
Expand Down

0 comments on commit 68a4829

Please sign in to comment.