Skip to content

Commit

Permalink
Merge pull request #904 from PBH-BTN/master
Browse files Browse the repository at this point in the history
v7.3.2
  • Loading branch information
Ghost-chu authored Jan 13, 2025
2 parents d1e411f + 2512963 commit acda442
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 32 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.10.0
uses: docker/build-push-action@v6.11.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.10.0
uses: docker/build-push-action@v6.11.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.10.0
uses: docker/build-push-action@v6.11.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.10.0
uses: docker/build-push-action@v6.11.0
with:
context: .
file: ./Dockerfile-Release
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ dependency-reduced-pom.xml
PeerBanHelper.jar
*.pkg
install4j/output
install4j/project.install4j~
10 changes: 5 additions & 5 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.1</version>
<version>7.3.2</version>
<packaging>jar</packaging>

<name>PeerBanHelper</name>
Expand Down Expand Up @@ -258,7 +258,7 @@
<dependency>
<groupId>org.bspfsystems</groupId>
<artifactId>yamlconfiguration</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -398,7 +398,7 @@
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-mime4j-dom</artifactId>
<version>0.8.11</version>
<version>0.8.12</version>
<exclusions>
<exclusion>
<artifactId>commons-io</artifactId>
Expand All @@ -409,7 +409,7 @@
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-mime4j-core</artifactId>
<version>0.8.11</version>
<version>0.8.12</version>
<exclusions>
<exclusion>
<artifactId>commons-io</artifactId>
Expand All @@ -420,7 +420,7 @@
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-mime4j-storage</artifactId>
<version>0.8.11</version>
<version>0.8.12</version>
<exclusions>
<exclusion>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ private void runTestCode() {
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ private void performUpgrade() throws SQLException {
TableUtils.createTableIfNotExists(database.getDataSource(), AlertEntity.class);
v = 7;
}
if (v == 7) {
TableUtils.dropTable(getDataSource(), AlertEntity.class, true);
TableUtils.createTableIfNotExists(database.getDataSource(), AlertEntity.class);
v = 8;
}
version.setValue(String.valueOf(v));
metadata.update(version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ public Page<PeerBanCount> getBannedIps(Pageable pageable, String filter) throws
.selectRaw("ip, COUNT(*) AS count")
.groupBy("ip")
.orderByRaw("count DESC");
String[] args = new String[0];
if (filter != null) {
builder.setWhere(builder.where().like("ip", new SelectArg(filter + "%")));
builder.setWhere(builder.where().like("ip", new SelectArg()));
args = new String[]{filter + "%"};
}
List<PeerBanCount> mapped;
try (GenericRawResults<String[]> banLogs = builder
var queryBuilder = builder
.limit(pageable.getSize())
.offset(pageable.getZeroBasedPage() * pageable.getSize())
// .where().ge("banAt", twoWeeksAgo)
.queryRaw()) {
.offset(pageable.getZeroBasedPage() * pageable.getSize());
List<PeerBanCount> mapped;
try (GenericRawResults<String[]> banLogs = queryRaw(queryBuilder.prepareStatementString(), args)) {
var results = banLogs.getResults();
mapped = results.stream().map(arr -> new PeerBanCount(arr[0], Long.parseLong(arr[1]))).toList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ghostchu.peerbanhelper.database.table;

import com.ghostchu.peerbanhelper.alert.AlertLevel;
import com.ghostchu.peerbanhelper.database.TranslationComponentPersistener;
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import lombok.AllArgsConstructor;
Expand All @@ -26,8 +26,8 @@ public final class AlertEntity {
private AlertLevel level;
@DatabaseField(canBeNull = false, index = true)
private String identifier;
@DatabaseField(canBeNull = false, dataType = DataType.SERIALIZABLE)
@DatabaseField(canBeNull = false, persisterClass = TranslationComponentPersistener.class)
private TranslationComponent title;
@DatabaseField(canBeNull = false, dataType = DataType.SERIALIZABLE)
@DatabaseField(canBeNull = false, persisterClass = TranslationComponentPersistener.class)
private TranslationComponent content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public boolean isLoggedIn() {
}
return !info.getQt().isBlank();
} catch (Exception e) {
log.error("Failed to check login status", e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void handleInfo(Context ctx) throws SQLException {


private void handleBanHistory(Context ctx) throws SQLException {
String ip = IPAddressUtil.getIPAddress(ctx.pathParam("ip")).toString();
String ip = IPAddressUtil.getIPAddress(ctx.pathParam("ip")).toNormalizedString();
Pageable pageable = new Pageable(ctx);
var builder = historyDao.queryBuilder()
.orderBy("banAt", false);
Expand All @@ -168,7 +168,7 @@ private void handleBanHistory(Context ctx) throws SQLException {

private void handleAccessHistory(Context ctx) throws SQLException {
activeMonitoringModule.flush();
String ip = IPAddressUtil.getIPAddress(ctx.pathParam("ip")).toString();
String ip = IPAddressUtil.getIPAddress(ctx.pathParam("ip")).toNormalizedString();
Pageable pageable = new Pageable(ctx);
var builder = peerRecordDao.queryBuilder()
.orderBy("lastTimeSeen", false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ghostchu.peerbanhelper.util.json;

import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.google.gson.*;
import org.jetbrains.annotations.NotNull;

Expand All @@ -13,6 +14,7 @@ public class JsonUtil {
.setExclusionStrategies(new HiddenAnnotationExclusionStrategy())
.serializeNulls()
.registerTypeAdapter(Timestamp.class, TimestampTypeAdapter.INSTANCE)
.registerTypeAdapter(TranslationComponent.class, TranslationComponentTypeAdapter.INSTANCE)
.disableHtmlEscaping()
.create();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,72 @@
package com.ghostchu.peerbanhelper.util.json;

import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

import java.lang.reflect.Type;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static com.ghostchu.peerbanhelper.text.TextManager.tlUI;

public class TranslationComponentTypeAdapter implements JsonSerializer<TranslationComponent> {
public class TranslationComponentTypeAdapter extends TypeAdapter<TranslationComponent> {
public static final TranslationComponentTypeAdapter INSTANCE = new TranslationComponentTypeAdapter();

@Override
public JsonElement serialize(TranslationComponent ts, Type t, JsonSerializationContext jsc) {
return new JsonPrimitive(tlUI(ts));
public void write(JsonWriter out, TranslationComponent value) throws IOException {
out.beginObject();
out.name("key").value(value.getKey());
out.name("params");
out.beginArray(); // 开始 JSON 数组
// 遍历 params 数组并写入元素
for (Object param : value.getParams()) {
if (param instanceof TranslationComponent) {
// 如果是 TranslationComponent,递归调用 write 方法
TranslationComponentTypeAdapter.INSTANCE.write(out, (TranslationComponent) param);
} else {
out.value(param.toString());
}
}
out.endArray(); // 结束 JSON 数组
out.endObject(); // 结束 JSON 对象

// 特别注意嵌套里面不允许出现除了 TranslationComponent 以外的 JsonObject,否则必翻车
}

@Override
public TranslationComponent read(JsonReader in) throws IOException {
String key = null;
List<Object> params = new ArrayList<>();

in.beginObject(); // 开始读取 JSON 对象

while (in.hasNext()) { // 循环读取每个字段
String name = in.nextName();
if ("key".equals(name)) {
key = in.nextString(); // 读取 key 字段
} else if ("params".equals(name)) {
in.beginArray(); // 开始读取 JSON 数组
while (in.hasNext()) {
// 判断当前元素是字符串还是 TranslationComponent
if (in.peek() == JsonToken.STRING) {
params.add(in.nextString()); // 如果是字符串,直接添加到 params 列表
} else if (in.peek() == JsonToken.BEGIN_OBJECT) {
// 如果是对象,则递归读取 TranslationComponent
params.add(TranslationComponentTypeAdapter.INSTANCE.read(in));
} else {
in.skipValue(); // 跳过不需要的值
}
}
in.endArray(); // 结束数组读取
} else {
in.skipValue(); // 跳过不需要的字段
}
}

in.endObject(); // 结束 JSON 对象的读取

// 构造并返回 TranslationComponent 对象
return new TranslationComponent(key, params.toArray(new Object[0]));
}
}
2 changes: 2 additions & 0 deletions webui/src/stores/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ export const useEndpointStore = defineStore('endpoint', () => {
throw new IncorrectTokenError()
} else if (res.status === 303) {
throw new NeedInitError()
} else if (res.status === 401) {
throw new IncorrectTokenError()
}
},
getGlobalConfig,
Expand Down
2 changes: 1 addition & 1 deletion webui/src/views/banlist/components/banListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
</a-descriptions-item>
<a-descriptions-item :label="t('page.banlist.banlist.listItem.location')" :span="12">
<!-- 这里非常离奇,只要用了a-typography-text就会被下面一行覆盖,怀疑框架有毛病 -->
<a-tooltip :content="item.banMetadata.torrent.hash">
<a-tooltip :content="item.banMetadata.torrent.hash" position="bottom">
<a-typography-text style="margin-bottom: 0" :ellipsis="{ showTooltip: true }">
{{ item.banMetadata.torrent.name }}
</a-typography-text>
Expand Down

0 comments on commit acda442

Please sign in to comment.