airdcpp-web/airdcpp-apisocket-js

Search Instance Id not found

Closed this issue · 5 comments

I have search results from a query displayed along with an action to download the corresponding result.
I understand that the code to download a result looks something like:

export const downloadAirDCPPItem =
  (instanceId: string, resultId: string): void =>
  async (dispatch) => {
    await SocketService.connect("admin", "password", true);
    const searchInstance: SearchInstance = await SocketService.get(
      `search/${instanceId}`,
    );
    console.log(searchInstance); // <---- 404 not found
    await sleep(2000);
    const downloadResult = await SocketService.post(
      `search/${searchInstance.id}/results/${resultId}/download`,
    );
    dispatch({
      type: AIRDCPP_RESULT_DOWNLOAD_INITIATED,
      downloadResult: downloadResult,
    });
  };

However, I am a little confused with regards to the instance_id. Since my search is complete, and the socket is disconnected as part of a separate search method, I am reconnecting and getting the search instance using:

 const searchInstance: SearchInstance = await SocketService.get(
      `search/${instanceId}`,
    );

This results in (example):

"GET" – "search/1170449281" – "(no data)"

Is my understanding of search instance creation and teardown incorrect?

Are you able fetch the instance before you disconnect the socket?

This results in (example):

Looks like you only included the request, not the API response (it's on a different line)

I am an impatient man. I was passing in the wrong instance.id

The correct id was 235 in this response as a part of the search instance request:

2 – "SUCCEEDED"
Object
current_search_id: ""
expires_in: 1799996
id: 235
owner: "session:2450484948"
query: null
queue_time: 0
queued_count: 0
result_count: 0
searches_sent_ago: 0
[Log] 7 – "GET" – "search/235" – "(no data)" (main.bundle.js, line 9895)
[Log] 7 – "SUCCEEDED" – {current_search_id: "2705164071", expires_in: 1785767, id: 235, …} (main.bundle.js, line 9895)
{current_search_id: "2705164071", expires_in: 1785767, id: 235, owner: "session:2450484948", query: Object, …}Object

I was passing in 2705164071 from this response:

search_hub_searches_sent – "(entity 235)"
Object
query: {excluded: [], extensions: ["cbz", "cbr"], file_type: "any", max_size: null, min_size: null, …}
search_id: "2705164071"
sent: 1

Separately, is this a correct pattern:

export const downloadAirDCPPItem =
  (instanceId: string, resultId: string): void =>
  async (dispatch) => {
    await SocketService.connect("admin", "password", true);
    const searchInstance: SearchInstance = await SocketService.get(
      `search/${instanceId}`,
    );
    await sleep(2000);
    const downloadResult = await SocketService.post(
      `search/${searchInstance.id}/results/${resultId}/download`,
    );
    dispatch({
      type: AIRDCPP_RESULT_DOWNLOAD_INITIATED,
      downloadResult: downloadResult,
    });
    SocketService.disconnect(); // <--- disconnect 
  }

I guess it works. I see no reason for the 2 second sleep period though or why you are fetching the instance since you have the ID already.

Ah, just noticed it. Gonna remove and close this.