🔌 Working UI integration airdcpp-socket
This commit is contained in:
@@ -10,6 +10,7 @@ import { isNil, isUndefined, map, isEmpty } from "lodash";
|
|||||||
import { IExtractedComicBookCoverFile, RootState } from "threetwo-ui-typings";
|
import { IExtractedComicBookCoverFile, RootState } from "threetwo-ui-typings";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { comicinfoAPICall } from "../actions/comicinfo.actions";
|
import { comicinfoAPICall } from "../actions/comicinfo.actions";
|
||||||
|
import { search } from "../services/api/SearchApi";
|
||||||
import { Form, Field } from "react-final-form";
|
import { Form, Field } from "react-final-form";
|
||||||
|
|
||||||
interface ISearchProps {}
|
interface ISearchProps {}
|
||||||
@@ -40,6 +41,10 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
|||||||
[dispatch],
|
[dispatch],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getDCPPSearchResults = useCallback((searchQuery) => {
|
||||||
|
search(searchQuery);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const comicVineSearchResults = useSelector(
|
const comicVineSearchResults = useSelector(
|
||||||
(state: RootState) => state.comicInfo.searchResults,
|
(state: RootState) => state.comicInfo.searchResults,
|
||||||
);
|
);
|
||||||
@@ -51,7 +56,22 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
|||||||
<h1 className="title">Search</h1>
|
<h1 className="title">Search</h1>
|
||||||
|
|
||||||
<Form
|
<Form
|
||||||
onSubmit={getCVSearchResults}
|
onSubmit={() =>
|
||||||
|
getDCPPSearchResults({
|
||||||
|
query: {
|
||||||
|
pattern: "Old Man Logan",
|
||||||
|
// file_type: "any",
|
||||||
|
// extensions: ["iso"],
|
||||||
|
},
|
||||||
|
hub_urls: [
|
||||||
|
"nmdcs://piter.feardc.net:411",
|
||||||
|
"dchub://dc.fly-server.ru",
|
||||||
|
"dchub://dc.elitedc.ru",
|
||||||
|
"dchub://dc.kcahdep.online",
|
||||||
|
],
|
||||||
|
priority: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
initialValues={{
|
initialValues={{
|
||||||
...formData,
|
...formData,
|
||||||
}}
|
}}
|
||||||
|
|||||||
11
src/client/constants/search.service.ts
Normal file
11
src/client/constants/search.service.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
const MODULE_URL = "search";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
MODULE_URL: MODULE_URL,
|
||||||
|
INSTANCES_URL: MODULE_URL,
|
||||||
|
|
||||||
|
SEARCH_TYPES_URL: MODULE_URL + "/types",
|
||||||
|
SEARCH_TYPES_UPDATED: "search_types_updated",
|
||||||
|
|
||||||
|
DEFAULT_SEARCH_TYPE: "any",
|
||||||
|
};
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Socket } from "airdcpp-apisocket";
|
import { Socket } from "airdcpp-apisocket";
|
||||||
import WebSocket from "ws";
|
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
url: "wss://sab.rishighan.com/api/v1/",
|
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;
|
type SocketType = typeof APISocket;
|
||||||
export { SocketType as APISocket };
|
export { SocketType as APISocket };
|
||||||
|
|
||||||
@@ -1,42 +1,58 @@
|
|||||||
import SocketService from "../SearchService";
|
import SocketService from "../DcppSearchService";
|
||||||
export const foo = SocketService.connect("admin", "password");
|
import {
|
||||||
interface SearchInstance {
|
SearchQuery,
|
||||||
current_search_id: string;
|
SearchInstance,
|
||||||
expires_in: number;
|
PriorityEnum,
|
||||||
id: number;
|
SearchResponse,
|
||||||
owner: string;
|
} from "threetwo-ui-typings";
|
||||||
query: Record<string, unknown>;
|
import SearchConstants from "../../constants/search.service";
|
||||||
queue_time: number;
|
|
||||||
queued_count: number;
|
interface SearchData {
|
||||||
result_count: number;
|
query: Pick<SearchQuery, "pattern"> & Partial<Omit<SearchQuery, "pattern">>;
|
||||||
searches_sent_ago: number;
|
hub_urls: string[] | undefined | null;
|
||||||
|
priority: PriorityEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
foo.then(async (data) => {
|
// foo.then(async (data) => {
|
||||||
const instance: SearchInstance = await SocketService.post("search");
|
// const instance: SearchInstance = await SocketService.post("search");
|
||||||
await sleep(10000);
|
// 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`,
|
`search/${instance.id}/hub_search`,
|
||||||
{
|
data,
|
||||||
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);
|
await sleep(10000);
|
||||||
const results = await SocketService.get(`search/${instance.id}/results/0/5`);
|
const results = await SocketService.get(`search/${instance.id}/results/0/5`);
|
||||||
console.log(results);
|
console.log("ASDASDASDASDASDASDA", results);
|
||||||
});
|
SocketService.disconnect();
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user