Skip to content

Commit

Permalink
Add choose of the folder option
Browse files Browse the repository at this point in the history
  • Loading branch information
galushko committed Feb 21, 2024
1 parent d01bad0 commit df24b91
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.halushko.kinocat.core.rabbit.SmartJson;
import lombok.extern.slf4j.Slf4j;
import lombok.val;

import java.io.BufferedReader;
import java.io.InputStreamReader;
Expand All @@ -14,7 +15,7 @@ public abstract class CliCommandExecutor extends InputMessageHandler {
@Override
protected String getDeliverCallbackPrivate(SmartJson rabbitMessage) {
long userId = rabbitMessage.getUserId();
String script = getScript(rabbitMessage);
val script = getScript(rabbitMessage);
log.debug("[ExternalCliCommandExecutor] userId:{}, script:{}", userId, script);

try {
Expand All @@ -32,9 +33,9 @@ protected String getResultString(List<String> lines, SmartJson rabbitMessage) {
return lines == null ? "" : String.join("\n", lines);
}

protected List<String> executeViaCLI(String script) {
protected List<String> executeViaCLI(String[] script) {
// String command = String.format("sh %s%s", "/home/app/", script);
log.debug("[executeViaCLI] Execute script: {}", script);
log.debug("[executeViaCLI] Execute script: [{}]", String.join(", ", script));
List<String> result = new ArrayList<>();

ProcessBuilder processBuilder = new ProcessBuilder(script);
Expand All @@ -60,7 +61,7 @@ protected List<String> executeViaCLI(String script) {
return result;
}

protected String getScript(SmartJson rabbitMessage){
return rabbitMessage.getText();
protected String[] getScript(SmartJson rabbitMessage){
return new String[] {rabbitMessage.getText()};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ protected String getQueue() {
}

@Override
protected String getScript(SmartJson rabbitMessage) {
protected String[] getScript(SmartJson rabbitMessage) {
List<Object> arguments = rabbitMessage.getSubMessage(SmartJsonKeys.COMMAND_ARGUMENTS).convertToList();
String folder = (String) arguments.get(0);
String file = (String) arguments.get(1);

return String.format("bash -c \"mv -f %s/%s.torrent %s/%s.torrent\"",
Constants.PATH_TO_UNAPPROVED_FOLDER,
file,
Constants.FOLDERS.get(folder),
UUID.randomUUID()
);
return new String[]{
"/bin/bash",
"-c",
String.format("\"mv -f %s/%s.torrent %s/%s.torrent\"",
Constants.PATH_TO_UNAPPROVED_FOLDER.replaceAll("\\s+", "\\\\ "),
file.replaceAll("\\s+", "\\\\ "),
Constants.FOLDERS.get(folder).replaceAll("\\s+", "\\\\ "),
UUID.randomUUID()
)
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ protected String getQueue() {
}

@Override
protected String getScript(SmartJson rabbitMessage) {
return String.format("bash -c \"/usr/bin/transmission-show %s\"", rabbitMessage.getValue(SmartJsonKeys.FILE_PATH));
protected String[] getScript(SmartJson rabbitMessage) {
return new String[]{
"/bin/bash",
"-c",
String.format("\"/usr/bin/transmission-show %s\"", rabbitMessage.getValue(SmartJsonKeys.FILE_PATH).replaceAll("\\s+", "\\\\ "))
};
}
}

0 comments on commit df24b91

Please sign in to comment.