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 18, 2023
1 parent 08fb9c2 commit e71c4ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected void getDeliverCallbackPrivate(SmartJson rabbitMessage) {
log.debug("[UserMessageHandler] Command {} found", text);
SmartJson message = new SmartJson(userId, command.getFinalCommand());
message.addValue("ARG", command.getArguments());
message.addValue("SCRIPT", command.getScript());
RabbitUtils.postMessage(message, command.getQueue());
}
log.debug("[UserMessageHandler] Finish DeliverCallbackPrivate for {}", getQueue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
public class CommonTorrentEntity {
public final String id;
private final double percentDone;
private final String status;
private final int status;
public final String name;
private final long totalSize;

public CommonTorrentEntity(Map<String, Object> map){
val torrent = new SmartJson(map);
this.status = getStatusIcon(torrent.getValue("status"));
String status = torrent.getValue("status");
this.status = status.isEmpty() ? -1 : Integer.parseInt(status);
this.name = torrent.getValue("name");
String percentDone = torrent.getValue("percentDone");
this.percentDone = percentDone.isEmpty() ? 0.0 : Double.parseDouble(percentDone);
Expand Down Expand Up @@ -56,8 +57,8 @@ protected String getGigabytesLeft() {
: " % (" + Math.round((totalSize - (long) (totalSize * percentDone)) / 1000000.0) / 1000.0 + " Gb left)";
}

protected String getStatusIcon(String status) {
return switch (status != null ? Integer.parseInt(status) : -1) {
protected String getStatusIcon() {
return switch (status) {
case 0 -> "⏸";
case 1 -> "\uD83D\uDD51♾";
case 2 -> "♾";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public TorrentCommands() {
@Override
protected void executeRequest(SmartJson message) {
long chatId = message.getUserId();
String requestBodyFormat = ResourceReader.readResourceContent(String.format("transmission_requests/%s", message.getText().split(" ")[0]));
String torrentId = message.getValue("ARG");
String requestBodyFormat = ResourceReader.readResourceContent(String.format("transmission_requests/%s", message.getValue("SCRIPT")));
String requestBody = String.format(requestBodyFormat, torrentId);
log.debug("[executeRequest] Request body:\n{}", requestBody);

Expand Down

0 comments on commit e71c4ce

Please sign in to comment.