🔧 Adding corrected AirDCPP integration
1. Search event listeners 2. Reducer refactoring
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
"@types/socket.io": "^3.0.2",
|
||||
"@types/socket.io-client": "^3.0.0",
|
||||
"@types/through2": "^2.0.36",
|
||||
"airdcpp-apisocket": "^2.4.2",
|
||||
"airdcpp-apisocket": "^2.4.4",
|
||||
"array-sort-by": "^1.2.1",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"better-docs": "^2.3.2",
|
||||
|
||||
@@ -33,44 +33,62 @@ export const search = (data: SearchData) => async (dispatch) => {
|
||||
}
|
||||
const instance: SearchInstance = await SocketService.post("search");
|
||||
|
||||
// We want to get notified about every new result in order to make the user experience better
|
||||
await SocketService.addListener(
|
||||
`search/${instance.id}`,
|
||||
`search`,
|
||||
"search_result_added",
|
||||
async (groupedResult) => {
|
||||
// ...add the received result in the UI
|
||||
// (it's probably a good idea to have some kind of throttling for the UI updates as there can be thousands of results)
|
||||
|
||||
dispatch({
|
||||
type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
|
||||
groupedResult,
|
||||
});
|
||||
},
|
||||
instance.id,
|
||||
);
|
||||
|
||||
// We also want to update the existing items in our list when new hits arrive for the previously listed files/directories
|
||||
await SocketService.addListener(
|
||||
`search`,
|
||||
"search_result_updated",
|
||||
async (groupedResult) => {
|
||||
// ...update properties of the existing result in the UI
|
||||
},
|
||||
instance.id,
|
||||
);
|
||||
|
||||
// We need to show something to the user in case the search won't yield any results so that he won't be waiting forever)
|
||||
// Wait for 5 seconds for any results to arrive after the searches were sent to the hubs
|
||||
await SocketService.addListener(
|
||||
`search`,
|
||||
"search_hub_searches_sent",
|
||||
async (searchInfo) => {
|
||||
await sleep(5000);
|
||||
|
||||
// The search can now be considered to be "complete"
|
||||
dispatch({
|
||||
type: AIRDCPP_HUB_SEARCHES_SENT,
|
||||
searchInfo,
|
||||
instance,
|
||||
});
|
||||
|
||||
// Check the number of received results (in real use cases we should know that even without calling the API)
|
||||
const currentInstance = await SocketService.get(
|
||||
`search/${instance.id}`,
|
||||
);
|
||||
if (currentInstance.result_count === 0) {
|
||||
console.log("ASDASDASDASDD");
|
||||
// ...nothing was received, show an informative message to the user
|
||||
}
|
||||
|
||||
// If there's an "in progress" indicator in the UI, that could also be disabled here
|
||||
dispatch({
|
||||
type: AIRDCPP_HUB_SEARCHES_SENT,
|
||||
searchInfo,
|
||||
instance,
|
||||
});
|
||||
},
|
||||
);
|
||||
await SocketService.post<SearchResponse>(
|
||||
`search/${instance.id}/hub_search`,
|
||||
data,
|
||||
instance.id,
|
||||
);
|
||||
|
||||
await sleep(10000);
|
||||
const results = await SocketService.get(
|
||||
`search/${instance.id}/results/0/125`,
|
||||
);
|
||||
|
||||
dispatch({
|
||||
type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
|
||||
results,
|
||||
});
|
||||
// Finally, perform the actual search
|
||||
await SocketService.post(`search/${instance.id}/hub_search`, data);
|
||||
} catch (error) {
|
||||
console.log("ERO", error);
|
||||
throw error;
|
||||
|
||||
@@ -42,7 +42,9 @@ export const AcquisitionPanel = (
|
||||
// pattern: "Templier T2.cbr",
|
||||
extensions: ["cbz", "cbr"],
|
||||
},
|
||||
hub_urls: ["nmdcs://piter.feardc.net:411"],
|
||||
hub_urls: [
|
||||
"adcs://novosibirsk.dc-dev.club:7111/?kp=SHA256/4XFHJFFBFEI2RS75FPRPPXPZMMKPXR764ABVVCC2QGJPQ34SDZGA",
|
||||
],
|
||||
priority: 5,
|
||||
};
|
||||
|
||||
@@ -115,7 +117,9 @@ export const AcquisitionPanel = (
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{map(airDCPPSearchResults, ({ name, type, slots, users, id }) => {
|
||||
<tr><td>
|
||||
{JSON.stringify(airDCPPSearchResults)}</td></tr>
|
||||
{/* {map(airDCPPSearchResults, ({ name, type, slots, users, id }) => {
|
||||
return (
|
||||
<tr key={id}>
|
||||
<td>
|
||||
@@ -168,7 +172,7 @@ export const AcquisitionPanel = (
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
})} */}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
|
||||
@@ -20,9 +20,10 @@ const initialState = {
|
||||
function airdcppReducer(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case AIRDCPP_SEARCH_RESULTS_RECEIVED:
|
||||
console.log("Badan", action)
|
||||
return {
|
||||
...state,
|
||||
searchResults: action.results,
|
||||
searchResults: action.groupedResult.result,
|
||||
isAirDCPPSearchInProgress: false,
|
||||
};
|
||||
case AIRDCPP_SEARCH_IN_PROGRESS:
|
||||
|
||||
@@ -2275,10 +2275,10 @@ aggregate-error@^3.0.0:
|
||||
clean-stack "^2.0.0"
|
||||
indent-string "^4.0.0"
|
||||
|
||||
airdcpp-apisocket@^2.4.2:
|
||||
version "2.4.2"
|
||||
resolved "https://registry.npmjs.org/airdcpp-apisocket/-/airdcpp-apisocket-2.4.2.tgz"
|
||||
integrity sha512-OxrrYe/iNOfle4RhqgaoUNJrgc7LDWCK+WhMQyfprDRxRqkvgPDuWjOavlmf89cAMIgwJ7x5DESpJKWvNGaS/w==
|
||||
airdcpp-apisocket@^2.4.4:
|
||||
version "2.4.4"
|
||||
resolved "https://registry.yarnpkg.com/airdcpp-apisocket/-/airdcpp-apisocket-2.4.4.tgz#94c3b8082022982557b8cad2fc77a670709f0b2c"
|
||||
integrity sha512-Xn0kWSVdLJwPpOoHcdI2wzzfzZW2jTpuyZR2wCNs2UIlZhO+FTwMf3QQfNCt5gYTOld9LaiCEulxFuXDA8qrLA==
|
||||
dependencies:
|
||||
chalk "^4.1.2"
|
||||
events "^3.3.0"
|
||||
|
||||
Reference in New Issue
Block a user