mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 08:43:48 +03:00
chore: use resumeDownload()
This commit is contained in:
parent
1458314df6
commit
86d3f7ac81
@ -79,7 +79,7 @@ export class DownloadManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.startSeedDownload(game);
|
this.resumeDownload(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [nextQueueItem] = await downloadQueueRepository.find({
|
const [nextQueueItem] = await downloadQueueRepository.find({
|
||||||
@ -168,10 +168,4 @@ export class DownloadManager {
|
|||||||
this.currentDownloader = game.downloader;
|
this.currentDownloader = game.downloader;
|
||||||
this.downloadingGameId = game.id;
|
this.downloadingGameId = game.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async startSeedDownload(game: Game) {
|
|
||||||
if (game) {
|
|
||||||
await PythonInstance.startSeeding(game);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -62,12 +62,13 @@ export class PythonInstance {
|
|||||||
|
|
||||||
public static async getStatus() {
|
public static async getStatus() {
|
||||||
if (this.downloadingGameId === -1) return null;
|
if (this.downloadingGameId === -1) return null;
|
||||||
console.log("getting status");
|
|
||||||
|
|
||||||
const response = await this.rpc.get<LibtorrentPayload | null>("/status");
|
const response = await this.rpc.get<LibtorrentPayload | null>("/status");
|
||||||
|
|
||||||
if (response.data === null) return null;
|
if (response.data === null) return null;
|
||||||
|
|
||||||
|
console.log(response.data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
progress,
|
progress,
|
||||||
@ -105,7 +106,7 @@ export class PythonInstance {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (progress === 1 && !isCheckingFiles) {
|
if (progress === 1 && !isCheckingFiles && status !== LibtorrentStatus.Seeding) {
|
||||||
this.downloadingGameId = -1;
|
this.downloadingGameId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,21 +176,6 @@ export class PythonInstance {
|
|||||||
.then((response) => response.data);
|
.then((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async startSeeding(game: Game) {
|
|
||||||
if (!this.pythonProcess) {
|
|
||||||
this.spawn();
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.rpc
|
|
||||||
.post("/action", {
|
|
||||||
action: "start-seeding",
|
|
||||||
game_id: game.id,
|
|
||||||
magnet: game.uri,
|
|
||||||
save_path: game.downloadPath,
|
|
||||||
} as StartDownloadPayload)
|
|
||||||
.catch(() => {});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async handleRpcError(_error: unknown) {
|
private static async handleRpcError(_error: unknown) {
|
||||||
await this.rpc.get("/healthcheck").catch(() => {
|
await this.rpc.get("/healthcheck").catch(() => {
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@ -106,7 +106,7 @@ class TorrentDownloader:
|
|||||||
params = {'url': magnet, 'save_path': save_path, 'trackers': self.trackers}
|
params = {'url': magnet, 'save_path': save_path, 'trackers': self.trackers}
|
||||||
torrent_handle = self.session.add_torrent(params)
|
torrent_handle = self.session.add_torrent(params)
|
||||||
self.torrent_handles[game_id] = torrent_handle
|
self.torrent_handles[game_id] = torrent_handle
|
||||||
torrent_handle.set_flags(lt.torrent_flags.auto_managed)
|
torrent_handle.set_flags(lt.torrent_flags.auto_managed, lt.torrent_flags.seed_mode)
|
||||||
torrent_handle.resume()
|
torrent_handle.resume()
|
||||||
|
|
||||||
self.downloading_game_id = game_id
|
self.downloading_game_id = game_id
|
||||||
@ -151,24 +151,16 @@ class TorrentDownloader:
|
|||||||
'gameId': self.downloading_game_id,
|
'gameId': self.downloading_game_id,
|
||||||
'progress': status.progress,
|
'progress': status.progress,
|
||||||
'downloadSpeed': status.download_rate,
|
'downloadSpeed': status.download_rate,
|
||||||
|
'uploadSpeed': status.upload_rate,
|
||||||
'numPeers': status.num_peers,
|
'numPeers': status.num_peers,
|
||||||
'numSeeds': status.num_seeds,
|
'numSeeds': status.num_seeds,
|
||||||
'status': status.state,
|
'status': status.state,
|
||||||
'bytesDownloaded': status.progress * info.total_size() if info else status.all_time_download,
|
'bytesDownloaded': status.progress * info.total_size() if info else status.all_time_download,
|
||||||
}
|
}
|
||||||
|
|
||||||
if status.progress == 1:
|
# if status.progress == 1:
|
||||||
torrent_handle.pause()
|
# torrent_handle.pause()
|
||||||
self.session.remove_torrent(torrent_handle)
|
# self.session.remove_torrent(torrent_handle)
|
||||||
self.downloading_game_id = -1
|
# self.downloading_game_id = -1
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def start_seeding(self, game_id: int, magnet: str, save_path: str):
|
|
||||||
print("seed log 1")
|
|
||||||
params = {'url': magnet, 'save_path': save_path, 'trackers': self.trackers}
|
|
||||||
torrent_handle = self.session.add_torrent(params)
|
|
||||||
self.torrent_handles[game_id] = torrent_handle
|
|
||||||
torrent_handle.set_flags(lt.torrent_flags.seed_mode)
|
|
||||||
torrent_handle.resume()
|
|
||||||
print("seed log 2")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user