Skip to content

Commit

Permalink
新增字段 NEED_TAKE_ACTION #162
Browse files Browse the repository at this point in the history
若需要使某些下载器的封禁功能正常工作,PBH 可能需要使用特权身份启动/或者修改特定设置。
  • Loading branch information
Ghost-chu committed Jun 20, 2024
1 parent e9b46fb commit 3c2db06
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,16 @@ public void updateDownloader(@NotNull Downloader downloader, boolean updateBanLi
try {
if (!downloader.login()) {
log.warn(Lang.ERR_CLIENT_LOGIN_FAILURE_SKIP, downloader.getName(), downloader.getEndpoint());
downloader.setLastStatus(DownloaderLastStatus.ERROR);
downloader.setLastStatus(DownloaderLastStatus.ERROR, Lang.STATUS_TEXT_LOGIN_FAILED);
return;
} else {
downloader.setLastStatus(DownloaderLastStatus.HEALTHY);
downloader.setLastStatus(DownloaderLastStatus.HEALTHY, Lang.STATUS_TEXT_OK);
}
downloader.setBanList(BAN_LIST.keySet(), added, removed);
downloader.relaunchTorrentIfNeeded(needToRelaunch);
} catch (Throwable th) {
log.warn(Lang.ERR_UPDATE_BAN_LIST, downloader.getName(), downloader.getEndpoint(), th);
downloader.setLastStatus(DownloaderLastStatus.ERROR);
downloader.setLastStatus(DownloaderLastStatus.ERROR, Lang.STATUS_TEXT_EXCEPTION);
}
}

Expand Down Expand Up @@ -567,7 +567,7 @@ public Map<Torrent, List<Peer>> collectPeers(Downloader downloader) {
Map<Torrent, List<Peer>> peers = new ConcurrentHashMap<>();
if (!downloader.login()) {
log.warn(Lang.ERR_CLIENT_LOGIN_FAILURE_SKIP, downloader.getName(), downloader.getEndpoint());
downloader.setLastStatus(DownloaderLastStatus.ERROR);
downloader.setLastStatus(DownloaderLastStatus.ERROR, Lang.STATUS_TEXT_LOGIN_FAILED);
return Collections.emptyMap();
}
List<Torrent> torrents = downloader.getTorrents();
Expand All @@ -585,7 +585,7 @@ public Map<Torrent, List<Peer>> collectPeers(Downloader downloader) {
parallelReqRestrict.release();
}
}));
downloader.setLastStatus(DownloaderLastStatus.HEALTHY);
downloader.setLastStatus(DownloaderLastStatus.HEALTHY, Lang.STATUS_TEXT_OK);
}

return peers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@ public interface Downloader extends AutoCloseable {
*
* @param lastStatus 最后请求状态
*/
void setLastStatus(DownloaderLastStatus lastStatus);
void setLastStatus(DownloaderLastStatus lastStatus, String statusMessage);

/**
* 获取客户端状态描述说明
*
* @return 状态描述说明
*/
String getLastStatusMessage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum DownloaderLastStatus {
HEALTHY,
NEED_TAKE_ACTION,
ERROR,
UNKNOWN
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class QBittorrent implements Downloader {
private final Config config;
private DownloaderLastStatus lastStatus = DownloaderLastStatus.UNKNOWN;
private String name;
private String statusMessage;

public QBittorrent(String name, Config config) {
this.name = name;
Expand Down Expand Up @@ -331,8 +332,14 @@ public DownloaderLastStatus getLastStatus() {
}

@Override
public void setLastStatus(DownloaderLastStatus lastStatus) {
public void setLastStatus(DownloaderLastStatus lastStatus, String statusMessage) {
this.lastStatus = lastStatus;
this.statusMessage = statusMessage;
}

@Override
public String getLastStatusMessage() {
return statusMessage;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Transmission implements Downloader {
private final String blocklistUrl;
private final Config config;
private DownloaderLastStatus lastStatus = DownloaderLastStatus.UNKNOWN;
private String statusMessage;

/*
API 受限,实际实现起来意义不大
Expand Down Expand Up @@ -179,10 +180,17 @@ public DownloaderLastStatus getLastStatus() {
}

@Override
public void setLastStatus(DownloaderLastStatus lastStatus) {
public void setLastStatus(DownloaderLastStatus lastStatus, String statusMessage) {
this.lastStatus = lastStatus;
this.statusMessage = statusMessage;
}

@Override
public String getLastStatusMessage() {
return statusMessage;
}


@Override
public void close() {
client.shutdown();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/ghostchu/peerbanhelper/text/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,8 @@ public class Lang {
public static final String GUI_TITLE_LOADED = "PeerBanHelper (%s) - %s (%s)";
public static final String WEBVIEW_DISABLED_WEBKIT_NOT_INCLUDED = "未找到 JavaFx Web 模块,您正在使用精简构建,WebUI 选项卡未启用";
public static final String WEBVIEW_ENABLED = "已找到 JavaFx Web,WebUI 选项卡已启用";
public static final String STATUS_TEXT_OK = "当前工作正常";
public static final String STATUS_TEXT_LOGIN_FAILED = "尝试登陆到下载器失败";
public static final String STATUS_TEXT_EXCEPTION = "出现异常,请检查 PeerBanHelper 控制台";
public static final String STATUS_TEXT_NEED_PRIVILEGE = "权限不足,请求权限提升(以管理员/root身份运行)";
}

0 comments on commit 3c2db06

Please sign in to comment.