Skip to content

Commit

Permalink
Merge pull request #395 from PBH-BTN/master
Browse files Browse the repository at this point in the history
v6.0.4
  • Loading branch information
Ghost-chu authored Aug 26, 2024
2 parents 54c63f8 + df468ed commit ee7c8fa
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 19 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,21 @@ client:
清除浏览器缓存。
### 无法下载 GeoIP 库 / 代理无效
打开 `data/config.yml` 文件,配置代理服务器:

```yaml
proxy:
# 代理服务器设置 Proxy server setting
# 注意:不支持需要密码验证的代理服务器 NOTE: Authentication required proxy servers are not supported
# 0 = 不使用代理 - No proxy
# 1 = 使用系统代理 - Use system proxy
# 2 = 使用 HTTP(s) 代理 - Use HTTP(s) proxy
# 3 = 使用 socks5 代理(可能无法使用) - Use socks5 proxy (may not work well)
setting: 0
```

### PeerBanHelper 运行在 Docker 里时,下载器 IP 地址怎么填,127.0.0.1 不管用

如果您的 Docker 容器和下载器运行在同一台服务器上,且使用 桥接 网络模式(默认就是桥接),那么您不能使用 127.0.0.1。
Expand Down
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>6.0.3</version>
<version>6.0.4</version>
<packaging>takari-jar</packaging>

<name>PeerBanHelper</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.ghostchu.peerbanhelper.text.TranslationComponent;
import com.ghostchu.peerbanhelper.torrent.Torrent;
import com.ghostchu.peerbanhelper.torrent.TorrentImpl;
import com.ghostchu.peerbanhelper.util.ByteUtil;
import com.ghostchu.peerbanhelper.util.HTTPUtil;
import com.ghostchu.peerbanhelper.util.json.JsonUtil;
import com.ghostchu.peerbanhelper.wrapper.BanMetadata;
Expand Down Expand Up @@ -187,10 +188,14 @@ public List<Peer> getPeers(Torrent torrent) {
PeerManagerRecord peerManagerRecord = JsonUtil.getGson().fromJson(resp.body(), PeerManagerRecord.class);
List<Peer> peersList = new ArrayList<>();
for (PeerRecord peer : peerManagerRecord.getPeers()) {
var peerId = new String(ByteUtil.hexToByteArray(peer.getPeerId()), StandardCharsets.ISO_8859_1);
if (peerId.length() > 8) {
peerId = peerId.substring(0, 8);
}
peersList.add(new PeerImpl(
new PeerAddress(peer.getIp(), peer.getPort()),
peer.getIp(),
peer.getPeerId(),
peerId,
peer.getClient(),
peer.getStats().getRtDownloadSpeed(),
peer.getStats().getTotalReceived(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ public List<Torrent> getTorrents() {
for (PBHActiveTorrentsResponse.ActiveTorrentsResponseDTO activeTorrent : this.client.getActiveTorrents().getActiveTorrents()) {
List<Peer> peers = new ArrayList<>();
for (PBHActiveTorrentsResponse.ActiveTorrentsResponseDTO.PeersDTO peer : activeTorrent.getPeers()) {
var peerId = StrUtil.toStringHex(peer.getPeerId());
if (peerId.length() > 8) {
peerId = peerId.substring(0, 8);
}
DelugePeer delugePeer = new DelugePeer(
new PeerAddress(peer.getIp(), peer.getPort()),
StrUtil.toStringHex(peer.getPeerId()),
peerId,
peer.getClientName(),
peer.getTotalDownload(),
peer.getPayloadDownSpeed(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ghostchu/peerbanhelper/ipdb/IPDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private CompletableFuture<Void> downloadFile(MutableRequest req, Path path, Stri
}
})
.exceptionally(e -> {
log.error(tlUI(Lang.IPDB_UPDATE_FAILED, "Java Exception"), e);
log.error(tlUI(Lang.IPDB_UPDATE_FAILED, databaseName, e.getMessage()), e);
File file = path.toFile();
if (file.exists()) {
file.delete(); // 删除下载不完整的文件
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/ghostchu/peerbanhelper/util/ByteUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.ghostchu.peerbanhelper.util;

import java.nio.ByteBuffer;

public class ByteUtil {
public static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte aByte : bytes) {
sb.append(String.format("%02x", aByte));
}
return sb.toString();
}

/**
* hex字符串转byte数组
*
* @param inHex 待转换的Hex字符串
* @return 转换后的byte数组结果
*/
public static byte[] hexToByteArray(String inHex) {
int hexlen = inHex.length();
byte[] result;
if (hexlen % 2 == 1) {
//奇数
hexlen++;
result = new byte[(hexlen / 2)];
inHex = "0" + inHex;
} else {
//偶数
result = new byte[(hexlen / 2)];
}
int j = 0;
ByteBuffer buffer = ByteBuffer.wrap(result);
for (int i = 0; i < hexlen; i += 2) {
buffer.put(hexToByte(inHex.substring(i, i + 2)));
}
return result;
}

/**
* Hex字符串转byte
*
* @param inHex 待转换的Hex字符串
* @return 转换后的byte
*/
public static byte hexToByte(String inHex) {
return (byte) Integer.parseInt(inHex, 16);
}

public static String filterUTF8(String in) {
return in.replace("\u0000", "");
}
}
4 changes: 2 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ proxy:
# 1 = 使用系统代理 - Use system proxy
# 2 = 使用 HTTP(s) 代理 - Use HTTP(s) proxy
# 3 = 使用 socks5 代理(可能无法使用) - Use socks5 proxy (may not work well)
setting: 0
setting: 1
# 代理服务器地址 - Proxy server host
host: "127.0.0.1"
# 代理服务器端口号 - Proxy server port
port: 7890
# 代理例外地址,使用 | 分隔不同条目 - Exception list, spilt with | symbol
non-proxy-hosts: "localhost|127.*|192.168.*|10.*|172.16.*|172.17.*|172.18.*|172.19.*|172.20.*|172.21.*|172.22.*|172.23.*|172.24.*|172.25.*|172.26.*|172.27.*|172.28.*|172.29.*|172.30.*|172.31.*"
non-proxy-hosts: "localhost|127.*|192.168.*|10.*|172.16.*|172.17.*|172.18.*|172.19.*|172.20.*|172.21.*|172.22.*|172.23.*|172.24.*|172.25.*|172.26.*|172.27.*|172.28.*|172.29.*|172.30.*|172.31.*|*.local|*.lan"

performance:
# 启用 Windows 平台上的 EcoQoS API以节约能源消耗,作为交换,程序运行速度将降低,定时任务可能推迟
Expand Down
1 change: 1 addition & 0 deletions webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@arco-design/web-vue": "^2.56.0",
"@dzangolab/flag-icon-css": "^3.4.5",
"@octokit/core": "^6.1.2",
"@octokit/request-error": "^6.1.4",
"@vueuse/core": "^11.0.1",
"compare-versions": "^6.1.1",
"copy-to-clipboard": "^3.3.3",
Expand Down
13 changes: 8 additions & 5 deletions webui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions webui/src/components/pageFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@

<script setup lang="ts">
import { useEndpointStore } from '@/stores/endpoint'
import { Button, Message, Notification } from '@arco-design/web-vue'
import { Button, Notification } from '@arco-design/web-vue'
import { computed, h, ref, watch } from 'vue'
import { compare } from 'compare-versions'
import { useI18n } from 'vue-i18n'
import plusModal from './plusModal.vue'
import { RequestError } from '@octokit/request-error'
const { t } = useI18n()
const version = __APP_VERSION__
Expand Down Expand Up @@ -87,7 +88,27 @@ watch(hasNewVersion, () => {
watch(
() => endpointStore.checkUpgradeError,
(error) => {
Message.error(`${t('settings.accessToken.error')},error:${error}`)
if (error instanceof RequestError) {
if (error?.message.includes('limit')) {
Notification.error({
title: t('settings.accessToken.error'),
content: t('settings.accessToken.error.limit'),
footer: () =>
h(
Button,
{
type: 'primary',
onClick: () => endpointStore.emmitter.emit('open-settings-modal')
},
() => t('settings.open')
)
})
}
} else
Notification.error({
title: t('settings.accessToken.error'),
content: error?.message ?? ''
})
}
)
Expand Down
6 changes: 6 additions & 0 deletions webui/src/components/pageHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ import { ref, computed } from 'vue'
import { useViewRoute } from '@/router'
import { useRoute } from 'vue-router'
import { useResponsiveState } from '@arco-design/web-vue/es/grid/hook/use-responsive-state'
import { useEndpointStore } from '@/stores/endpoint'
const { t, locale } = useI18n()
const { changeLocale } = useLocale()
const locales = [...LOCALE_OPTIONS]
Expand Down Expand Up @@ -191,6 +192,11 @@ const props = withDefaults(
disableMenu: false
}
)
const endpointStore = useEndpointStore()
endpointStore.emmitter.on('open-settings-modal', () => {
settingsModalRef.value?.showModal()
})
const [routers, currentName, goto] = useViewRoute()
const route = useRoute()
Expand Down
5 changes: 3 additions & 2 deletions webui/src/locale/en-US/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default {
'settings.navbar.theme.toLight': 'Click to use light mode',
'settings.navbar.theme.toDark': 'Click to use dark mode',
'settings.open': 'Goto Settings',
'settings.language': 'Language',
'settings.modal.title': 'Settings',
'settings.modal.endpointTips':
Expand All @@ -9,6 +10,6 @@ export default {
'settings.modal.accessTokenTips.here': 'here',
'settings.modal.pollInterval': 'Polling interval:',
'settings.endpoint.error': 'Cannot connect to the backend, please check the Endpoint settings',
'settings.accessToken.error':
'Failed to get version from Github server, Your IP address may reached the rate-limit (This message can safely ignored).'
'settings.accessToken.error': 'Failed to check update',
'settings.accessToken.error.limit': 'API Rate limit reached, try to set the token at settings.'
}
4 changes: 3 additions & 1 deletion webui/src/locale/zh-CN/settings.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export default {
'settings.navbar.theme.toLight': '点击切换为亮色模式',
'settings.navbar.theme.toDark': '点击切换为暗黑模式',
'settings.open': '前往设置',
'settings.language': '语言',
'settings.modal.title': '设置',
'settings.modal.endpointTips': '如果你无法访问PBH后端,可以尝试在此设置Endpoint',
'settings.modal.pollInterval': '轮询间隔:',
'settings.endpoint.error': '无法连接到后端,请检查Endpoint设置',
'settings.modal.accessTokenTips': '你可以在{here}填写 Github Access Token',
'settings.modal.accessTokenTips.here': '这里',
'settings.accessToken.error': '连接到 Github 检查 PBH 版本更新出错,可能当前 IP 地址已达到速率限制(此提示可安全忽略)'
'settings.accessToken.error': '检查 PBH 版本更新出错',
'settings.accessToken.error.limit': 'API 访问频率限制,请尝试在设置中填写 Token'
}
6 changes: 4 additions & 2 deletions webui/src/service/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export function getLatestVersion(token = useEndpointStore().accessToken) {
.then((res) => res.data)
}

export function getPBHPlusStatus(): Promise<CommonResponse<donateStatus>> {
const url = new URL(urlJoin(useEndpointStore().endpoint, '/api/pbhplus/status'), location.href)
export async function getPBHPlusStatus(): Promise<CommonResponse<donateStatus>> {
const endpointStore = useEndpointStore()
await endpointStore.serverAvailable
const url = new URL(urlJoin(endpointStore.endpoint, '/api/pbhplus/status'), location.href)
return fetch(url, { headers: getCommonHeader() }).then((res) => {
useEndpointStore().assertResponseLogin(res)
return res.json()
Expand Down
3 changes: 2 additions & 1 deletion webui/src/stores/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const useEndpointStore = defineStore('endpoint', () => {
const setAccessToken = async (value: string) => {
accessToken.value = value
try {
await serverAvailable.value
const latestRelease = await getLatestVersion()
latestVersion.value = {
tagName: latestRelease.tag_name,
Expand Down Expand Up @@ -161,7 +162,7 @@ export const useEndpointStore = defineStore('endpoint', () => {
// init
setEndpoint(endpoint.value, { retryOnNetWorkFail: true })

setTimeout(async () => getPlusStatus(), 1000)
setTimeout(async () => getPlusStatus())
setTimeout(async () => setAccessToken(accessToken.value), 3000)
return {
endpointSaved: readonly(endpoint),
Expand Down

0 comments on commit ee7c8fa

Please sign in to comment.