Skip to content

Commit

Permalink
Merge pull request #701 from PBH-BTN/master
Browse files Browse the repository at this point in the history
7.1.2
  • Loading branch information
Gaojianli authored Nov 7, 2024
2 parents 7a312a2 + b941c11 commit 24304b1
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 30 deletions.
2 changes: 1 addition & 1 deletion 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.1.1</version>
<version>7.1.2</version>
<packaging>jar</packaging>

<name>PeerBanHelper</name>
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/ghostchu/peerbanhelper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ public static void setupLogback() {
appender.start(); // 启动 appender
}

try{
try {
var targetLevel = System.getProperty("pbh.log.level");
if(targetLevel != null) {
if (targetLevel != null) {
var rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) rootLogger;
logbackLogger.setLevel(Level.toLevel(targetLevel));
}
}catch (Throwable ignored){}
} catch (Throwable ignored) {
}
}

public static ReloadResult reloadModule() {
Expand Down Expand Up @@ -221,8 +222,14 @@ private static void setupConfDirectory(String[] args) {
logsDirectory = new File(dataDirectory, "logs");
configDirectory = new File(dataDirectory, "config");
pluginDirectory = new File(dataDirectory, "plugins");
libraryDirectory = new File(dataDirectory, "libraries");
debugDirectory = new File(dataDirectory, "debug");
if (System.getProperty("pbh.configdir") != null) {
configDirectory = new File(System.getProperty("pbh.configdir"));
}
if (System.getProperty("pbh.logsdir") != null) {
logsDirectory = new File(System.getProperty("pbh.logsdir"));
}
// other directories aren't allowed to change by user to keep necessary structure
}

private static YamlConfiguration loadConfiguration(File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public double getProgress() {

@Override
public long getSize() {
return size;
return totalSize;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ private void handleLogs(Context ctx) throws SQLException {
private void handleBans(Context ctx) {
long limit = Long.parseLong(Objects.requireNonNullElse(ctx.queryParam("limit"), "-1"));
long lastBanTime = Long.parseLong(Objects.requireNonNullElse(ctx.queryParam("lastBanTime"), "-1"));
var banResponseList = getBanResponseStream(locale(ctx), lastBanTime, limit);
boolean ignoreBanForDisconnect = Boolean.parseBoolean(Objects.requireNonNullElse(ctx.queryParam("ignoreBanForDisconnect"), "true"));
var banResponseList = getBanResponseStream(locale(ctx), lastBanTime, limit, ignoreBanForDisconnect);
ctx.json(new StdResp(true, null, banResponseList.toList()));
}

Expand All @@ -110,10 +111,14 @@ public void onDisable() {
}


private @NotNull Stream<BanResponse> getBanResponseStream(String locale, long lastBanTime, long limit) {
private @NotNull Stream<BanResponse> getBanResponseStream(String locale, long lastBanTime, long limit, boolean ignoreBanForDisconnect) {
var banResponseList = getServer().getBannedPeers()
.entrySet()
.stream()
.filter(b -> {
if(!ignoreBanForDisconnect) return true;
return !b.getValue().isBanForDisconnect();
})
.map(entry -> new BanResponse(entry.getKey().getAddress().toString(), new BakedBanMetadata(locale, entry.getValue())))
.sorted((o1, o2) -> Long.compare(o2.getBanMetadata().getBanAt(), o1.getBanMetadata().getBanAt()));
if (lastBanTime > 0) {
Expand Down
28 changes: 17 additions & 11 deletions webui/src/components/autoUpdateBtn.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<template>
<a-popover>
<a-popover :popup-container="container">
<a-button
ref="autoUpdateBtn"
class="auto-update-btn"
:class="{
loading: loadingStatus === 'loading' || loadingHolding,
'loading-holding': loadingStatus === 'idle' && loadingHolding
}"
:type="autoUpdate.autoUpdate ? 'primary' : 'outline'"
:shape="'circle'"
@click="() => autoUpdate.refresh()"
>
<icon-sync />
<icon-sync
id="spin"
:class="{
loading: loadingStatus === 'loading' || loadingHolding,
'loading-holding': loadingStatus === 'idle' && loadingHolding
}"
/>
</a-button>
<template #title>
<a-space>
Expand All @@ -27,17 +29,19 @@
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { useAutoUpdate } from '@/stores/autoUpdate'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
const { t, d } = useI18n()
const autoUpdate = useAutoUpdate()
const autoUpdateBtn = ref()
const loadingHolding = ref(false)
let eventAbortController: AbortController
const container = ref<HTMLElement>()
onMounted(() => {
container.value = window.document.querySelector('body') as HTMLElement
eventAbortController = new AbortController()
autoUpdateBtn.value.$el.addEventListener(
'animationstart',
Expand Down Expand Up @@ -71,10 +75,12 @@ const loadingStatus = computed(() => autoUpdate.status)
.auto-update-btn,
.auto-update-btn:hover {
font-size: 16px;
&.loading {
animation: whirl 0.25s linear infinite;
&.loading-holding {
animation-iteration-count: 1;
#spin {
&.loading {
animation: whirl 0.25s linear infinite;
&.loading-holding {
animation-iteration-count: 1;
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions webui/src/views/charts/components/banTrends.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ const chartOptions = ref({
tooltip: {
trigger: 'axis'
},
grid: {
left: '15%'
},
series: [
{
data: [] as [Date, number][],
Expand Down
3 changes: 3 additions & 0 deletions webui/src/views/charts/components/traffic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ const chartOptions = ref({
min: 'dataMin',
minInterval: 3600 * 24 * 1000
},
grid: {
left: '15%'
},
yAxis: {
type: 'value',
axisLabel: {
Expand Down
6 changes: 4 additions & 2 deletions webui/src/views/dashboard/components/clientStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
]"
>
<!-- 骨架屏 -->
<a-col v-if="!data || data?.length === 0 || loading" :xs="24" :sm="12" :md="8" :lg="6">
<a-col v-if="!data || data?.length === 0 || firstLoading" :xs="24" :sm="12" :md="8" :lg="6">
<a-card hoverable :header-style="{ height: 'auto' }">
<template #title>
<a-skeleton :animation="true">
Expand Down Expand Up @@ -82,12 +82,14 @@ import torrentList from './torrentList.vue'
const { t } = useI18n()
const endpointState = useEndpointStore()
const data = ref<Downloader[]>()
const { refresh, loading } = useRequest(
const firstLoading = ref(true)
const { refresh } = useRequest(
getDownloaders,
{
cacheKey: () => `${endpointState.endpoint}-downloader`,
onSuccess: (res) => {
data.value = res.data
firstLoading.value = false
}
},
[useAutoUpdatePlugin]
Expand Down
7 changes: 6 additions & 1 deletion webui/src/views/data-view/ipList/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
placeholder="192.168.1.1...."
class="searchBox"
:loading="loading"
@search="run"
@search="handleSearch"
/>
</div>
<div class="result-container center">
Expand Down Expand Up @@ -231,6 +231,11 @@ onMounted(() => {
run(searchInput.value)
}
})
const handleSearch = (value: string) => {
if (value) {
run(value)
}
}
</script>

<style scoped>
Expand Down
21 changes: 13 additions & 8 deletions webui/src/views/settings/components/info/components/logViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<a-space>
<a-switch v-model="showThreadName" />{{ t('page.settings.tab.info.log.showThread') }}
</a-space>
<a-space v-if="enableAutoRefresh">
<a-switch v-model="autoScroll" />{{ t('page.settings.tab.info.log.autoScorll') }}
</a-space>
</a-space>
<a-list
ref="logList"
Expand Down Expand Up @@ -49,15 +52,15 @@
</template>
<script setup lang="ts">
import { LogLevel, type Log } from '@/api/model/log'
import { GetHistoryLogs } from '@/service/logger'
import { GetHistoryLogs, StreamLogger } from '@/service/logger'
import { getColor } from '@/utils/color'
import { List, Message } from '@arco-design/web-vue'
import { computed, onBeforeUnmount, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRequest } from 'vue-request'
import { StreamLogger } from '@/service/logger'
import { List, Message } from '@arco-design/web-vue'
import { getColor } from '@/utils/color'
const { t, d } = useI18n()
const hideBanWave = ref(false)
const autoScroll = ref(false)
const logBuffer = reactive([] as Log[])
const { loading } = useRequest(GetHistoryLogs, {
onSuccess: (data) => {
Expand All @@ -82,10 +85,12 @@ const changeAutoRefresh = async (enable: boolean | string | number) => {
(newLog) => {
logBuffer.push(newLog)
console.log('scroll to', logBuffer.length - 1)
logList.value?.scrollIntoView({
index: logBuffer.length - 1,
align: 'bottom'
} as ScrollIntoViewOptions)
if (autoScroll.value) {
logList.value?.scrollIntoView({
index: logBuffer.length - 1,
align: 'bottom'
} as ScrollIntoViewOptions)
}
},
(err) => {
Message.error(err.message)
Expand Down
1 change: 1 addition & 0 deletions webui/src/views/settings/components/info/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default {
'page.settings.tab.info.log.enableAutoRefresh': 'Auto Refresh',
'page.settings.tab.info.log.hideBanWave': 'Hide check logs from Ban Wave',
'page.settings.tab.info.log.showThread': 'Show Thread Name',
'page.settings.tab.info.log.autoScorll': 'Auto Scroll to Latest',

'page.settings.tab.info.downloadHeap':
'Start downloading heap dump file, this will take some time'
Expand Down
1 change: 1 addition & 0 deletions webui/src/views/settings/components/info/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default {
'page.settings.tab.info.log.enableAutoRefresh': '自动刷新',
'page.settings.tab.info.log.hideBanWave': '隐藏来自 Ban Wave 的检查日志',
'page.settings.tab.info.log.showThread': '显示线程名',
'page.settings.tab.info.log.autoScorll': '自动滚动到最新',

'page.settings.tab.info.downloadHeap': '开始下载堆转储文件,这需要一段时间'
}

0 comments on commit 24304b1

Please sign in to comment.