🔧 Adding corrected AirDCPP integration

1. Search event listeners
2. Reducer refactoring
This commit is contained in:
2021-09-02 08:18:58 -07:00
parent c02b512e1c
commit 3fc22c74ef
5 changed files with 52 additions and 29 deletions

View File

@@ -28,7 +28,7 @@
"@types/socket.io": "^3.0.2", "@types/socket.io": "^3.0.2",
"@types/socket.io-client": "^3.0.0", "@types/socket.io-client": "^3.0.0",
"@types/through2": "^2.0.36", "@types/through2": "^2.0.36",
"airdcpp-apisocket": "^2.4.2", "airdcpp-apisocket": "^2.4.4",
"array-sort-by": "^1.2.1", "array-sort-by": "^1.2.1",
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",
"better-docs": "^2.3.2", "better-docs": "^2.3.2",

View File

@@ -33,44 +33,62 @@ export const search = (data: SearchData) => async (dispatch) => {
} }
const instance: SearchInstance = await SocketService.post("search"); 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( 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", "search_hub_searches_sent",
async (searchInfo) => { async (searchInfo) => {
await sleep(5000); await sleep(5000);
// The search can now be considered to be "complete" // 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) // Check the number of received results (in real use cases we should know that even without calling the API)
const currentInstance = await SocketService.get( const currentInstance = await SocketService.get(
`search/${instance.id}`, `search/${instance.id}`,
); );
if (currentInstance.result_count === 0) { if (currentInstance.result_count === 0) {
console.log("ASDASDASDASDD");
// ...nothing was received, show an informative message to the user // ...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 // If there's an "in progress" indicator in the UI, that could also be disabled here
dispatch({
type: AIRDCPP_HUB_SEARCHES_SENT,
searchInfo,
instance,
});
}, },
); instance.id,
await SocketService.post<SearchResponse>(
`search/${instance.id}/hub_search`,
data,
); );
await sleep(10000); // Finally, perform the actual search
const results = await SocketService.get( await SocketService.post(`search/${instance.id}/hub_search`, data);
`search/${instance.id}/results/0/125`,
);
dispatch({
type: AIRDCPP_SEARCH_RESULTS_RECEIVED,
results,
});
} catch (error) { } catch (error) {
console.log("ERO", error); console.log("ERO", error);
throw error; throw error;

View File

@@ -42,7 +42,9 @@ export const AcquisitionPanel = (
// pattern: "Templier T2.cbr", // pattern: "Templier T2.cbr",
extensions: ["cbz", "cbr"], extensions: ["cbz", "cbr"],
}, },
hub_urls: ["nmdcs://piter.feardc.net:411"], hub_urls: [
"adcs://novosibirsk.dc-dev.club:7111/?kp=SHA256/4XFHJFFBFEI2RS75FPRPPXPZMMKPXR764ABVVCC2QGJPQ34SDZGA",
],
priority: 5, priority: 5,
}; };
@@ -115,7 +117,9 @@ export const AcquisitionPanel = (
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{map(airDCPPSearchResults, ({ name, type, slots, users, id }) => { <tr><td>
{JSON.stringify(airDCPPSearchResults)}</td></tr>
{/* {map(airDCPPSearchResults, ({ name, type, slots, users, id }) => {
return ( return (
<tr key={id}> <tr key={id}>
<td> <td>
@@ -168,7 +172,7 @@ export const AcquisitionPanel = (
</td> </td>
</tr> </tr>
); );
})} })} */}
</tbody> </tbody>
</table> </table>
)} )}

View File

@@ -20,9 +20,10 @@ const initialState = {
function airdcppReducer(state = initialState, action) { function airdcppReducer(state = initialState, action) {
switch (action.type) { switch (action.type) {
case AIRDCPP_SEARCH_RESULTS_RECEIVED: case AIRDCPP_SEARCH_RESULTS_RECEIVED:
console.log("Badan", action)
return { return {
...state, ...state,
searchResults: action.results, searchResults: action.groupedResult.result,
isAirDCPPSearchInProgress: false, isAirDCPPSearchInProgress: false,
}; };
case AIRDCPP_SEARCH_IN_PROGRESS: case AIRDCPP_SEARCH_IN_PROGRESS:

View File

@@ -2275,10 +2275,10 @@ aggregate-error@^3.0.0:
clean-stack "^2.0.0" clean-stack "^2.0.0"
indent-string "^4.0.0" indent-string "^4.0.0"
airdcpp-apisocket@^2.4.2: airdcpp-apisocket@^2.4.4:
version "2.4.2" version "2.4.4"
resolved "https://registry.npmjs.org/airdcpp-apisocket/-/airdcpp-apisocket-2.4.2.tgz" resolved "https://registry.yarnpkg.com/airdcpp-apisocket/-/airdcpp-apisocket-2.4.4.tgz#94c3b8082022982557b8cad2fc77a670709f0b2c"
integrity sha512-OxrrYe/iNOfle4RhqgaoUNJrgc7LDWCK+WhMQyfprDRxRqkvgPDuWjOavlmf89cAMIgwJ7x5DESpJKWvNGaS/w== integrity sha512-Xn0kWSVdLJwPpOoHcdI2wzzfzZW2jTpuyZR2wCNs2UIlZhO+FTwMf3QQfNCt5gYTOld9LaiCEulxFuXDA8qrLA==
dependencies: dependencies:
chalk "^4.1.2" chalk "^4.1.2"
events "^3.3.0" events "^3.3.0"