mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
feat: Replace OpenWebTorrent service with WebTorrentData service
This commit is contained in:
parent
4616f69a29
commit
6b9f902b2c
@ -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…
Reference in New Issue
Block a user