🔧 WIP AirDCPP sockets
This commit is contained in:
@@ -59,12 +59,13 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
||||
onSubmit={() =>
|
||||
getDCPPSearchResults({
|
||||
query: {
|
||||
pattern: "wolverine",
|
||||
pattern: "Iron Man - V1 194",
|
||||
// file_type: "compressed",
|
||||
extensions: ["cbz", "cbr"],
|
||||
},
|
||||
hub_urls: [
|
||||
"adcs://novosibirsk.dc-dev.club:7111/?kp=SHA256/4XFHJFFBFEI2RS75FPRPPXPZMMKPXR764ABVVCC2QGJPQ34SDZGA",
|
||||
"dc.fly-server.ru",
|
||||
],
|
||||
priority: 1,
|
||||
})
|
||||
|
||||
@@ -19,15 +19,41 @@ function sleep(ms: number): Promise<NodeJS.Timeout> {
|
||||
|
||||
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>(
|
||||
`${SearchConstants.INSTANCES_URL}/${instance.id}/hub_search`,
|
||||
const unsubscribe = await SocketService.addListener(
|
||||
"search",
|
||||
"search_hub_searches_sent",
|
||||
(searchInfo) => {
|
||||
onSearchSent(data, instance, unsubscribe, searchInfo);
|
||||
},
|
||||
instance.id,
|
||||
);
|
||||
|
||||
const searchQueueInfo = await SocketService.post(
|
||||
`search/${instance.id}/hub_search`,
|
||||
data,
|
||||
);
|
||||
await sleep(10000);
|
||||
const results = await SocketService.get(`search/${instance.id}/results/0/20`);
|
||||
console.log("results", results);
|
||||
SocketService.disconnect();
|
||||
return results;
|
||||
};
|
||||
|
||||
const onSearchSent = async (item, instance, unsubscribe, searchInfo): any => {
|
||||
// Collect the results for 5 seconds
|
||||
await sleep(5000);
|
||||
|
||||
// Get only the first result (results are sorted by relevance)
|
||||
const results = await SocketService.get(
|
||||
`search/${instance.id}/results/0/100`,
|
||||
);
|
||||
|
||||
if (results.length > 0) {
|
||||
// We have results, download the best one
|
||||
console.log("SASAAAA", results);
|
||||
// const result = results[0];
|
||||
// SocketService.post(`search/${instance.id}/results/${result.id}/download`, {
|
||||
// priority: Utils.toApiPriority(item.priority),
|
||||
// target_directory: item.target_directory,
|
||||
// });
|
||||
}
|
||||
return results;
|
||||
// Remove listener for this search instance
|
||||
unsubscribe();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user