Skip to content

Commit

Permalink
Merge pull request #920 from PBH-BTN/master
Browse files Browse the repository at this point in the history
v7.3.3
  • Loading branch information
Ghost-chu authored Jan 19, 2025
2 parents acda442 + f3ed673 commit 8c3cf52
Show file tree
Hide file tree
Showing 55 changed files with 1,138 additions and 226 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/jvm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
type=raw,ci
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v6.11.0
uses: docker/build-push-action@v6.12.0
with:
context: .
file: ./Dockerfile
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
type=raw,ci
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v6.11.0
uses: docker/build-push-action@v6.12.0
with:
context: .
file: ./Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/jvm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
type=raw,latest
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v6.11.0
uses: docker/build-push-action@v6.12.0
with:
context: .
file: ./Dockerfile
Expand Down Expand Up @@ -195,7 +195,7 @@ jobs:
type=raw,latest
type=sha
- name: Build and push Aliyun ACR
uses: docker/build-push-action@v6.11.0
uses: docker/build-push-action@v6.12.0
with:
context: .
file: ./Dockerfile-Release
Expand Down
13 changes: 9 additions & 4 deletions git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ fi
# 如果有修改,进入 webui 目录
cd webui || exit 1

# 执行 prettier 格式化
pnpm prettier --write src/
# 去除CHANGED_FILES的webui/前缀
CHANGED_FILES=$(echo "$CHANGED_FILES" | sed 's/webui\///g')

# 对有改动的文件执行 prettier 格式化
echo "$CHANGED_FILES" | xargs -P 4 pnpm prettier --write

if [ $? -ne 0 ]; then
echo "Prettier formatting failed."
exit 1
fi

# 执行 eslint 检查
pnpm eslint . --ignore-pattern 'dist/*' --fix
# 对有改动的文件执行 eslint 检查
echo "$CHANGED_FILES" | xargs -P 4 pnpm eslint --cache --ignore-pattern 'dist/*' --fix

if [ $? -ne 0 ]; then
echo "ESLint check failed."
exit 1
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.ghostchu.peerbanhelper</groupId>
<artifactId>peerbanhelper</artifactId>
<version>7.3.2</version>
<version>7.3.3</version>
<packaging>jar</packaging>

<name>PeerBanHelper</name>
Expand Down Expand Up @@ -432,13 +432,13 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.79</version>
<version>1.80</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpg-jdk18on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpg-jdk18on</artifactId>
<version>1.79</version>
<version>1.80</version>
</dependency>
<dependency>
<groupId>com.vdurmont</groupId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/ghostchu/peerbanhelper/BuildMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public final class BuildMeta {
private String compileTime = "Unknown";

public void loadBuildMeta(YamlConfiguration configuration) {
this.version = configuration.getString("maven.version");
this.branch = configuration.getString("git.branch");
this.version = ExternalSwitch.parse("pbh.buildmeta.maven.version", configuration.getString("maven.version"));
this.branch = ExternalSwitch.parse("pbh.buildmeta.git.branch", configuration.getString("git.branch"));
this.commit = configuration.getString("git.commit.id.commit-id");
this.abbrev = configuration.getString("git.commit.id.abbrev");
this.os = System.getProperty("os.name");
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/com/ghostchu/peerbanhelper/ExternalSwitch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.ghostchu.peerbanhelper;

import org.jetbrains.annotations.Nullable;

import java.util.Locale;

public class ExternalSwitch {
public static String parse(String args, @Nullable String def) {
var value = System.getProperty(args);
if (value == null)
value = System.getenv(args.replace(".", "_").replace("-", "_").toUpperCase(Locale.ROOT));
if (value == null)
return def;
return value;
}

public static boolean parseBoolean(String args, boolean def) {
var value = parse(args, null);
if (value == null)
return def;
return Boolean.parseBoolean(value);
}

public static int parseInt(String args, int def) {
var value = parse(args, null);
if (value == null)
return def;
return Integer.parseInt(value);
}

public static long parseLong(String args, long def) {
var value = parse(args, null);
if (value == null)
return def;
return Long.parseLong(value);
}

public static double parseDouble(String args, double def) {
var value = parse(args, null);
if (value == null)
return def;
return Double.parseDouble(value);
}

public static float parseFloat(String args, float def) {
var value = parse(args, null);
if (value == null)
return def;
return Float.parseFloat(value);
}

public static short parseShort(String args, short def) {
var value = parse(args, null);
if (value == null)
return def;
return Short.parseShort(value);
}

public static byte parseByte(String args, byte def) {
var value = parse(args, null);
if (value == null)
return def;
return Byte.parseByte(value);
}

public static char parseChar(String args, char def) {
var value = parse(args, null);
if (value == null)
return def;
return value.charAt(0);
}

public static String parse(String args) {
return parse(args, null);
}

public static boolean parseBoolean(String args) {
return parseBoolean(args, false);
}

public static int parseInt(String args) {
return parseInt(args, 0);
}

public static long parseLong(String args) {
return parseLong(args, 0);
}

public static double parseDouble(String args) {
return parseDouble(args, 0);
}

public static float parseFloat(String args) {
return parseFloat(args, 0);
}

public static short parseShort(String args) {
return parseShort(args, (short) 0);
}

public static byte parseByte(String args) {
return parseByte(args, (byte) 0);
}

public static char parseChar(String args) {
return parseChar(args, '\u0000');
}
}
26 changes: 13 additions & 13 deletions src/main/java/com/ghostchu/peerbanhelper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class Main {
@Getter
private static long startupAt = System.currentTimeMillis();
private static String userAgent;
public static final int PBH_BTN_PROTOCOL_IMPL_VERSION = 8;
public static final int PBH_BTN_PROTOCOL_IMPL_VERSION = 10;
public static final String PBH_BTN_PROTOCOL_READABLE_VERSION = "0.0.3";

public static void main(String[] args) {
Expand All @@ -112,7 +112,7 @@ public static void main(String[] args) {
log.info("Current system language tag: {}", defLocaleTag);
DEF_LOCALE = mainConfig.getString("language");
if (DEF_LOCALE == null || DEF_LOCALE.equalsIgnoreCase("default")) {
DEF_LOCALE = System.getenv("PBH_USER_LOCALE");
DEF_LOCALE = ExternalSwitch.parse("PBH_USER_LOCALE");
if (DEF_LOCALE == null) {
DEF_LOCALE = defLocaleTag;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ public static void setupLogback() {
}

try {
var targetLevel = System.getProperty("pbh.log.level");
var targetLevel = ExternalSwitch.parse("pbh.log.level");
if (targetLevel != null) {
var rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) rootLogger;
Expand Down Expand Up @@ -230,7 +230,7 @@ private static void setupProxySettings() {
private static void setupConfDirectory(String[] args) {
String osName = System.getProperty("os.name");
String root = "data";
if ("true".equalsIgnoreCase(System.getProperty("pbh.usePlatformConfigLocation"))) {
if (ExternalSwitch.parseBoolean("pbh.usePlatformConfigLocation")) {
if (osName.contains("Windows")) {
root = new File(System.getenv("LOCALAPPDATA"), "PeerBanHelper").getAbsolutePath();
} else {
Expand All @@ -243,20 +243,20 @@ private static void setupConfDirectory(String[] args) {
root = dataDirectory.resolve("PeerBanHelper").toAbsolutePath().toString();
}
}
if (System.getProperty("pbh.datadir") != null) {
root = System.getProperty("pbh.datadir");
if (ExternalSwitch.parse("pbh.datadir") != null) {
root = ExternalSwitch.parse("pbh.datadir");
}

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

private static void initGUI(String[] args) {
String guiType = "swing";
if (!Desktop.isDesktopSupported() || System.getProperty("pbh.nogui") != null || Arrays.stream(args).anyMatch(arg -> arg.equalsIgnoreCase("nogui"))) {
if (!Desktop.isDesktopSupported() || ExternalSwitch.parse("pbh.nogui") != null || Arrays.stream(args).anyMatch(arg -> arg.equalsIgnoreCase("nogui"))) {
guiType = "console";
} else if (Arrays.stream(args).anyMatch(arg -> arg.equalsIgnoreCase("swing"))) {
guiType = "swing";
Expand All @@ -354,7 +354,7 @@ public static String getUserAgent() {
if (userAgent != null) return userAgent;
String userAgentTemplate = "PeerBanHelper/%s (%s; %s,%s,%s) BTN-Protocol/%s BTN-Protocol-Version/%s";
var osMXBean = ManagementFactory.getOperatingSystemMXBean();
String release = System.getProperty("pbh.release");
String release = ExternalSwitch.parse("pbh.release");
if (release == null) {
release = "unknown";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.ghostchu.peerbanhelper.lab.Laboratory;
import com.ghostchu.peerbanhelper.metric.BasicMetrics;
import com.ghostchu.peerbanhelper.module.*;
import com.ghostchu.peerbanhelper.module.impl.background.BackgroundModule;
import com.ghostchu.peerbanhelper.module.impl.rule.*;
import com.ghostchu.peerbanhelper.module.impl.webapi.*;
import com.ghostchu.peerbanhelper.peer.Peer;
Expand Down Expand Up @@ -197,14 +198,13 @@ public void start() throws SQLException {

@SneakyThrows
private void runTestCode() {
if (!"LiveDebug".equalsIgnoreCase(System.getProperty("pbh.release"))) {
if (!"LiveDebug".equalsIgnoreCase(ExternalSwitch.parse("pbh.release"))) {
return;
}
// run some junky test code here
// ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory
// .getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
// root.setLevel(ch.qos.logback.classic.Level.TRACE);

}


Expand Down Expand Up @@ -384,10 +384,7 @@ private void saveBanList() {
}

private void registerHttpServer() {
String token = System.getenv("PBH_API_TOKEN");
if (token == null) {
token = System.getProperty("pbh.api_token");
}
String token = ExternalSwitch.parse("pbh.api_token");
if (token == null) {
token = Main.getMainConfig().getString("server.token");
}
Expand Down Expand Up @@ -737,7 +734,8 @@ private void registerModules() {
moduleManager.register(PBHPushController.class);
moduleManager.register(PBHLabController.class);
moduleManager.register(PBHEasterEggController.class);

moduleManager.register(PBHUtilitiesController.class);
moduleManager.register(BackgroundModule.class);
}

public Map<Downloader, Map<Torrent, List<Peer>>> collectPeers() {
Expand Down
Loading

0 comments on commit 8c3cf52

Please sign in to comment.