🔌 Working UI integration airdcpp-socket

This commit is contained in:
2021-08-14 23:40:03 -07:00
parent a20da523b2
commit 7c8ee36505
4 changed files with 80 additions and 34 deletions

View File

@@ -1,5 +1,4 @@
import { Socket } from "airdcpp-apisocket";
import WebSocket from "ws";
const options = {
url: "wss://sab.rishighan.com/api/v1/",
@@ -13,7 +12,7 @@ const options = {
],
};
const APISocket = Socket(options, WebSocket as any);
const APISocket = Socket(options, window.WebSocket as any);
type SocketType = typeof APISocket;
export { SocketType as APISocket };

View File

@@ -1,42 +1,58 @@
import SocketService from "../SearchService";
export const foo = SocketService.connect("admin", "password");
interface SearchInstance {
current_search_id: string;
expires_in: number;
id: number;
owner: string;
query: Record<string, unknown>;
queue_time: number;
queued_count: number;
result_count: number;
searches_sent_ago: number;
import SocketService from "../DcppSearchService";
import {
SearchQuery,
SearchInstance,
PriorityEnum,
SearchResponse,
} from "threetwo-ui-typings";
import SearchConstants from "../../constants/search.service";
interface SearchData {
query: Pick<SearchQuery, "pattern"> & Partial<Omit<SearchQuery, "pattern">>;
hub_urls: string[] | undefined | null;
priority: PriorityEnum;
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
foo.then(async (data) => {
const instance: SearchInstance = await SocketService.post("search");
await sleep(10000);
// foo.then(async (data) => {
// const instance: SearchInstance = await SocketService.post("search");
// await sleep(10000);
const searchInfo = await SocketService.post(
// const searchInfo = await SocketService.post(
// `search/${instance.id}/hub_search`,
// {
// query: {
// pattern: "H.P. Lovecraft",
// file_type: "compressed",
// extensions: ["cbz", "cbr"],
// },
// hub_urls: [
// "nmdcs://piter.feardc.net:411",
// "dchub://dc.rutrack.net",
// "dchub://dc.elitedc.ru",
// ],
// priority: 1,
// },
// );
// await sleep(10000);
// const results = await SocketService.get(`search/${instance.id}/results/0/5`);
// console.log(results);
// });
export const search = async (data: SearchData) => {
await SocketService.connect("admin", "password");
await sleep(10000);
const instance: SearchInstance = await SocketService.post("search");
await SocketService.post<SearchResponse>(
`search/${instance.id}/hub_search`,
{
query: {
pattern: "H.P. Lovecraft",
file_type: "compressed",
extensions: ["cbz", "cbr"],
},
hub_urls: [
"nmdcs://piter.feardc.net:411",
"dchub://dc.rutrack.net",
"dchub://dc.elitedc.ru",
],
priority: 1,
},
data,
);
await sleep(10000);
const results = await SocketService.get(`search/${instance.id}/results/0/5`);
console.log(results);
});
console.log("ASDASDASDASDASDASDA", results);
SocketService.disconnect();
return results;
};