Skip to content

Commit 8c3cf52

Browse files
authored
Merge pull request #920 from PBH-BTN/master
v7.3.3
2 parents acda442 + f3ed673 commit 8c3cf52

File tree

55 files changed

+1138
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1138
-226
lines changed

.github/workflows/jvm-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
type=raw,ci
6464
type=sha
6565
- name: Build and push Docker image
66-
uses: docker/build-push-action@v6.11.0
66+
uses: docker/build-push-action@v6.12.0
6767
with:
6868
context: .
6969
file: ./Dockerfile
@@ -98,7 +98,7 @@ jobs:
9898
type=raw,ci
9999
type=sha
100100
- name: Build and push Docker image
101-
uses: docker/build-push-action@v6.11.0
101+
uses: docker/build-push-action@v6.12.0
102102
with:
103103
context: .
104104
file: ./Dockerfile

.github/workflows/jvm-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
type=raw,latest
160160
type=sha
161161
- name: Build and push Docker image
162-
uses: docker/build-push-action@v6.11.0
162+
uses: docker/build-push-action@v6.12.0
163163
with:
164164
context: .
165165
file: ./Dockerfile
@@ -195,7 +195,7 @@ jobs:
195195
type=raw,latest
196196
type=sha
197197
- name: Build and push Aliyun ACR
198-
uses: docker/build-push-action@v6.11.0
198+
uses: docker/build-push-action@v6.12.0
199199
with:
200200
context: .
201201
file: ./Dockerfile-Release

git-hooks/pre-commit

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ fi
1212
# 如果有修改,进入 webui 目录
1313
cd webui || exit 1
1414

15-
# 执行 prettier 格式化
16-
pnpm prettier --write src/
15+
# 去除CHANGED_FILES的webui/前缀
16+
CHANGED_FILES=$(echo "$CHANGED_FILES" | sed 's/webui\///g')
17+
18+
# 对有改动的文件执行 prettier 格式化
19+
echo "$CHANGED_FILES" | xargs -P 4 pnpm prettier --write
20+
1721
if [ $? -ne 0 ]; then
1822
echo "Prettier formatting failed."
1923
exit 1
2024
fi
2125

22-
# 执行 eslint 检查
23-
pnpm eslint . --ignore-pattern 'dist/*' --fix
26+
# 对有改动的文件执行 eslint 检查
27+
echo "$CHANGED_FILES" | xargs -P 4 pnpm eslint --cache --ignore-pattern 'dist/*' --fix
28+
2429
if [ $? -ne 0 ]; then
2530
echo "ESLint check failed."
2631
exit 1

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.ghostchu.peerbanhelper</groupId>
88
<artifactId>peerbanhelper</artifactId>
9-
<version>7.3.2</version>
9+
<version>7.3.3</version>
1010
<packaging>jar</packaging>
1111

1212
<name>PeerBanHelper</name>
@@ -432,13 +432,13 @@
432432
<dependency>
433433
<groupId>org.bouncycastle</groupId>
434434
<artifactId>bcprov-jdk18on</artifactId>
435-
<version>1.79</version>
435+
<version>1.80</version>
436436
</dependency>
437437
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpg-jdk18on -->
438438
<dependency>
439439
<groupId>org.bouncycastle</groupId>
440440
<artifactId>bcpg-jdk18on</artifactId>
441-
<version>1.79</version>
441+
<version>1.80</version>
442442
</dependency>
443443
<dependency>
444444
<groupId>com.vdurmont</groupId>

src/main/java/com/ghostchu/peerbanhelper/BuildMeta.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public final class BuildMeta {
1717
private String compileTime = "Unknown";
1818

1919
public void loadBuildMeta(YamlConfiguration configuration) {
20-
this.version = configuration.getString("maven.version");
21-
this.branch = configuration.getString("git.branch");
20+
this.version = ExternalSwitch.parse("pbh.buildmeta.maven.version", configuration.getString("maven.version"));
21+
this.branch = ExternalSwitch.parse("pbh.buildmeta.git.branch", configuration.getString("git.branch"));
2222
this.commit = configuration.getString("git.commit.id.commit-id");
2323
this.abbrev = configuration.getString("git.commit.id.abbrev");
2424
this.os = System.getProperty("os.name");
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.ghostchu.peerbanhelper;
2+
3+
import org.jetbrains.annotations.Nullable;
4+
5+
import java.util.Locale;
6+
7+
public class ExternalSwitch {
8+
public static String parse(String args, @Nullable String def) {
9+
var value = System.getProperty(args);
10+
if (value == null)
11+
value = System.getenv(args.replace(".", "_").replace("-", "_").toUpperCase(Locale.ROOT));
12+
if (value == null)
13+
return def;
14+
return value;
15+
}
16+
17+
public static boolean parseBoolean(String args, boolean def) {
18+
var value = parse(args, null);
19+
if (value == null)
20+
return def;
21+
return Boolean.parseBoolean(value);
22+
}
23+
24+
public static int parseInt(String args, int def) {
25+
var value = parse(args, null);
26+
if (value == null)
27+
return def;
28+
return Integer.parseInt(value);
29+
}
30+
31+
public static long parseLong(String args, long def) {
32+
var value = parse(args, null);
33+
if (value == null)
34+
return def;
35+
return Long.parseLong(value);
36+
}
37+
38+
public static double parseDouble(String args, double def) {
39+
var value = parse(args, null);
40+
if (value == null)
41+
return def;
42+
return Double.parseDouble(value);
43+
}
44+
45+
public static float parseFloat(String args, float def) {
46+
var value = parse(args, null);
47+
if (value == null)
48+
return def;
49+
return Float.parseFloat(value);
50+
}
51+
52+
public static short parseShort(String args, short def) {
53+
var value = parse(args, null);
54+
if (value == null)
55+
return def;
56+
return Short.parseShort(value);
57+
}
58+
59+
public static byte parseByte(String args, byte def) {
60+
var value = parse(args, null);
61+
if (value == null)
62+
return def;
63+
return Byte.parseByte(value);
64+
}
65+
66+
public static char parseChar(String args, char def) {
67+
var value = parse(args, null);
68+
if (value == null)
69+
return def;
70+
return value.charAt(0);
71+
}
72+
73+
public static String parse(String args) {
74+
return parse(args, null);
75+
}
76+
77+
public static boolean parseBoolean(String args) {
78+
return parseBoolean(args, false);
79+
}
80+
81+
public static int parseInt(String args) {
82+
return parseInt(args, 0);
83+
}
84+
85+
public static long parseLong(String args) {
86+
return parseLong(args, 0);
87+
}
88+
89+
public static double parseDouble(String args) {
90+
return parseDouble(args, 0);
91+
}
92+
93+
public static float parseFloat(String args) {
94+
return parseFloat(args, 0);
95+
}
96+
97+
public static short parseShort(String args) {
98+
return parseShort(args, (short) 0);
99+
}
100+
101+
public static byte parseByte(String args) {
102+
return parseByte(args, (byte) 0);
103+
}
104+
105+
public static char parseChar(String args) {
106+
return parseChar(args, '\u0000');
107+
}
108+
}

src/main/java/com/ghostchu/peerbanhelper/Main.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class Main {
9797
@Getter
9898
private static long startupAt = System.currentTimeMillis();
9999
private static String userAgent;
100-
public static final int PBH_BTN_PROTOCOL_IMPL_VERSION = 8;
100+
public static final int PBH_BTN_PROTOCOL_IMPL_VERSION = 10;
101101
public static final String PBH_BTN_PROTOCOL_READABLE_VERSION = "0.0.3";
102102

103103
public static void main(String[] args) {
@@ -112,7 +112,7 @@ public static void main(String[] args) {
112112
log.info("Current system language tag: {}", defLocaleTag);
113113
DEF_LOCALE = mainConfig.getString("language");
114114
if (DEF_LOCALE == null || DEF_LOCALE.equalsIgnoreCase("default")) {
115-
DEF_LOCALE = System.getenv("PBH_USER_LOCALE");
115+
DEF_LOCALE = ExternalSwitch.parse("PBH_USER_LOCALE");
116116
if (DEF_LOCALE == null) {
117117
DEF_LOCALE = defLocaleTag;
118118
}
@@ -180,7 +180,7 @@ public static void setupLogback() {
180180
}
181181

182182
try {
183-
var targetLevel = System.getProperty("pbh.log.level");
183+
var targetLevel = ExternalSwitch.parse("pbh.log.level");
184184
if (targetLevel != null) {
185185
var rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
186186
ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) rootLogger;
@@ -230,7 +230,7 @@ private static void setupProxySettings() {
230230
private static void setupConfDirectory(String[] args) {
231231
String osName = System.getProperty("os.name");
232232
String root = "data";
233-
if ("true".equalsIgnoreCase(System.getProperty("pbh.usePlatformConfigLocation"))) {
233+
if (ExternalSwitch.parseBoolean("pbh.usePlatformConfigLocation")) {
234234
if (osName.contains("Windows")) {
235235
root = new File(System.getenv("LOCALAPPDATA"), "PeerBanHelper").getAbsolutePath();
236236
} else {
@@ -243,20 +243,20 @@ private static void setupConfDirectory(String[] args) {
243243
root = dataDirectory.resolve("PeerBanHelper").toAbsolutePath().toString();
244244
}
245245
}
246-
if (System.getProperty("pbh.datadir") != null) {
247-
root = System.getProperty("pbh.datadir");
246+
if (ExternalSwitch.parse("pbh.datadir") != null) {
247+
root = ExternalSwitch.parse("pbh.datadir");
248248
}
249249

250250
dataDirectory = new File(root);
251251
logsDirectory = new File(dataDirectory, "logs");
252252
configDirectory = new File(dataDirectory, "config");
253253
pluginDirectory = new File(dataDirectory, "plugins");
254254
debugDirectory = new File(dataDirectory, "debug");
255-
if (System.getProperty("pbh.configdir") != null) {
256-
configDirectory = new File(System.getProperty("pbh.configdir"));
255+
if (ExternalSwitch.parse("pbh.configdir") != null) {
256+
configDirectory = new File(ExternalSwitch.parse("pbh.configdir"));
257257
}
258-
if (System.getProperty("pbh.logsdir") != null) {
259-
logsDirectory = new File(System.getProperty("pbh.logsdir"));
258+
if (ExternalSwitch.parse("pbh.logsdir") != null) {
259+
logsDirectory = new File(ExternalSwitch.parse("pbh.logsdir"));
260260
}
261261
// other directories aren't allowed to change by user to keep necessary structure
262262
}
@@ -270,7 +270,7 @@ private static YamlConfiguration loadConfiguration(File file) {
270270
configuration.load(file);
271271
} catch (IOException | InvalidConfigurationException e) {
272272
log.error("Unable to load configuration: invalid YAML configuration // 无法加载配置文件:无效的 YAML 配置,请检查是否有语法错误", e);
273-
if (!Desktop.isDesktopSupported() || System.getProperty("pbh.nogui") != null || Arrays.stream(startupArgs).anyMatch(arg -> arg.equalsIgnoreCase("nogui"))) {
273+
if (!Desktop.isDesktopSupported() || ExternalSwitch.parse("pbh.nogui") != null || Arrays.stream(startupArgs).anyMatch(arg -> arg.equalsIgnoreCase("nogui"))) {
274274
try {
275275
log.error("Bad configuration: {}", Files.readString(file.toPath()));
276276
} catch (IOException ex) {
@@ -338,7 +338,7 @@ private static void setupShutdownHook() {
338338

339339
private static void initGUI(String[] args) {
340340
String guiType = "swing";
341-
if (!Desktop.isDesktopSupported() || System.getProperty("pbh.nogui") != null || Arrays.stream(args).anyMatch(arg -> arg.equalsIgnoreCase("nogui"))) {
341+
if (!Desktop.isDesktopSupported() || ExternalSwitch.parse("pbh.nogui") != null || Arrays.stream(args).anyMatch(arg -> arg.equalsIgnoreCase("nogui"))) {
342342
guiType = "console";
343343
} else if (Arrays.stream(args).anyMatch(arg -> arg.equalsIgnoreCase("swing"))) {
344344
guiType = "swing";
@@ -354,7 +354,7 @@ public static String getUserAgent() {
354354
if (userAgent != null) return userAgent;
355355
String userAgentTemplate = "PeerBanHelper/%s (%s; %s,%s,%s) BTN-Protocol/%s BTN-Protocol-Version/%s";
356356
var osMXBean = ManagementFactory.getOperatingSystemMXBean();
357-
String release = System.getProperty("pbh.release");
357+
String release = ExternalSwitch.parse("pbh.release");
358358
if (release == null) {
359359
release = "unknown";
360360
}

src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.ghostchu.peerbanhelper.lab.Laboratory;
2828
import com.ghostchu.peerbanhelper.metric.BasicMetrics;
2929
import com.ghostchu.peerbanhelper.module.*;
30+
import com.ghostchu.peerbanhelper.module.impl.background.BackgroundModule;
3031
import com.ghostchu.peerbanhelper.module.impl.rule.*;
3132
import com.ghostchu.peerbanhelper.module.impl.webapi.*;
3233
import com.ghostchu.peerbanhelper.peer.Peer;
@@ -197,14 +198,13 @@ public void start() throws SQLException {
197198

198199
@SneakyThrows
199200
private void runTestCode() {
200-
if (!"LiveDebug".equalsIgnoreCase(System.getProperty("pbh.release"))) {
201+
if (!"LiveDebug".equalsIgnoreCase(ExternalSwitch.parse("pbh.release"))) {
201202
return;
202203
}
203204
// run some junky test code here
204205
// ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory
205206
// .getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
206207
// root.setLevel(ch.qos.logback.classic.Level.TRACE);
207-
208208
}
209209

210210

@@ -384,10 +384,7 @@ private void saveBanList() {
384384
}
385385

386386
private void registerHttpServer() {
387-
String token = System.getenv("PBH_API_TOKEN");
388-
if (token == null) {
389-
token = System.getProperty("pbh.api_token");
390-
}
387+
String token = ExternalSwitch.parse("pbh.api_token");
391388
if (token == null) {
392389
token = Main.getMainConfig().getString("server.token");
393390
}
@@ -737,7 +734,8 @@ private void registerModules() {
737734
moduleManager.register(PBHPushController.class);
738735
moduleManager.register(PBHLabController.class);
739736
moduleManager.register(PBHEasterEggController.class);
740-
737+
moduleManager.register(PBHUtilitiesController.class);
738+
moduleManager.register(BackgroundModule.class);
741739
}
742740

743741
public Map<Downloader, Map<Torrent, List<Peer>>> collectPeers() {

0 commit comments

Comments
 (0)