mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: Replace OpenWebTorrent service with WebTorrentData service
This commit is contained in:
parent
4616f69a29
commit
6b9f902b2c
2 changed files with 20 additions and 45 deletions
|
@ -1,45 +0,0 @@
|
||||||
import axios, { AxiosResponse } from "axios";
|
|
||||||
import { Agent } from "https";
|
|
||||||
|
|
||||||
type OpenWebTorrentResponse =
|
|
||||||
| {
|
|
||||||
seeds: number;
|
|
||||||
peers: number;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
error: {
|
|
||||||
code: number;
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const httpsAgent = new Agent({
|
|
||||||
rejectUnauthorized: false,
|
|
||||||
});
|
|
||||||
const axiosRef = axios.create({
|
|
||||||
baseURL: "https://checker.openwebtorrent.com",
|
|
||||||
httpsAgent,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const openWebTorrent = {
|
|
||||||
transformResponseError(response: AxiosResponse<OpenWebTorrentResponse>) {
|
|
||||||
if ("error" in response.data) {
|
|
||||||
throw new Error(response.data.error.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.data;
|
|
||||||
},
|
|
||||||
async getSeedersAndPeers(magnet: string) {
|
|
||||||
const endpoint = "/check";
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("magnet", magnet);
|
|
||||||
|
|
||||||
const response = await axiosRef.get(endpoint, { params });
|
|
||||||
const { seeds, peers } = this.transformResponseError(response);
|
|
||||||
|
|
||||||
return {
|
|
||||||
seeders: seeds,
|
|
||||||
peers: peers,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
20
src/main/services/web-torrent-data.ts
Normal file
20
src/main/services/web-torrent-data.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import WebTorrentHealth from "webtorrent-health";
|
||||||
|
|
||||||
|
type WebTorrentHealthData = {
|
||||||
|
seeds: number;
|
||||||
|
peers: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const webTorrentData = {
|
||||||
|
async getSeedersAndPeers(magnet: string) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
WebTorrentHealth(magnet, (err: Error, data: WebTorrentHealthData) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue