Skip to content

Commit

Permalink
Move torrent client to the separate service
Browse files Browse the repository at this point in the history
  • Loading branch information
galushko committed Oct 19, 2023
1 parent 4291872 commit ee146eb
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.halushko.kinocat.core.files.ResourceReader;
import com.halushko.kinocat.core.rabbit.RabbitUtils;
import com.halushko.kinocat.core.rabbit.SmartJson;
import com.halushko.kinocat.core.web.ApiResponce;
import com.halushko.kinocat.core.web.InputMessageHandlerApiRequest;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand All @@ -23,16 +24,23 @@ protected final void getDeliverCallbackPrivate(SmartJson message) {
log.debug("[executeRequest] Message:\n{}", message.getRabbitMessageText());
long chatId = message.getUserId();
if (sessionIdValue == null) {
//new session
val responce = send("", "Content-Type", "application/json");
String sessionIdKey = "X-Transmission-Session-Id";
this.sessionIdValue = responce.getHeader(sessionIdKey);
}
String arguments = message.getValue("ARG");
String requestBodyFormat = ResourceReader.readResourceContent(String.format("transmission_requests/%s", message.getValue("SCRIPT")));
String requestBody = String.format(requestBodyFormat, (Object[]) arguments.split(" "));
log.debug("[executeRequest] Request body:\n{}", requestBody);

val responce = send(requestBody, "Content-Type", "application/json", sessionIdKey, sessionIdValue);
ApiResponce responce = send(requestBody, "Content-Type", "application/json", sessionIdKey, sessionIdValue);
if(responce.getHeader("Content-Type").contains("409: Conflict")){
//expired session
this.sessionIdValue = responce.getHeader(sessionIdKey);
responce = send(requestBody, "Content-Type", "application/json", sessionIdKey, sessionIdValue);
}


String bodyJson = responce.getBody();
log.debug("[executeRequest] Responce body:\n{}", bodyJson);
val json = new SmartJson(bodyJson);
Expand Down

0 comments on commit ee146eb

Please sign in to comment.