diff --git a/config/examples/docker-compose/docker-compose-bot.yml b/config/examples/docker-compose/docker-compose-bot.yml index fdba88e..397b87e 100644 --- a/config/examples/docker-compose/docker-compose-bot.yml +++ b/config/examples/docker-compose/docker-compose-bot.yml @@ -45,6 +45,7 @@ services: - ./workdir/config/files_from_telegram_hdd:/home/torrent_files_hdd/ - ./workdir/config/files_from_telegram_low:/home/torrent_files_low/ - ./workdir/config/logs:/home/app/logs + - ./workdir/mediadata_hdd/mediadata:/home/app/tmp1 networks: bot_network_local: networks: diff --git a/config/examples/docker-compose/stop.sh b/config/examples/docker-compose/stop.sh index 20bd338..badfe92 100644 --- a/config/examples/docker-compose/stop.sh +++ b/config/examples/docker-compose/stop.sh @@ -1,27 +1,27 @@ #!/bin/bash stop_broker() { - /usr/bin/docker-compose -f /home/dima/media/docker-compose-broker.yml down --remove-orphans + /usr/bin/docker-compose -f /home/dima/media/docker-compose-broker.yml down } stop_media() { - /usr/bin/docker-compose -f /home/dima/media/docker-compose-media.yml down --remove-orphans + /usr/bin/docker-compose -f /home/dima/media/docker-compose-media.yml down } stop_bot() { - /usr/bin/docker-compose -f /home/dima/media/docker-compose-bot.yml down --remove-orphans + /usr/bin/docker-compose -f /home/dima/media/docker-compose-bot.yml down } stop_torrent() { - /usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent.yml down --remove-orphans + /usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent.yml down } stop_torrent_hdd() { - /usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent-hdd.yml down --remove-orphans + /usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent-hdd.yml down } stop_torrent_low() { - /usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent-low.yml down --remove-orphans + /usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent-low.yml down } keys_specified=false diff --git a/core/src/main/java/com/halushko/kinocat/core/Commands.java b/core/src/main/java/com/halushko/kinocat/core/Commands.java index 5b45990..1682136 100644 --- a/core/src/main/java/com/halushko/kinocat/core/Commands.java +++ b/core/src/main/java/com/halushko/kinocat/core/Commands.java @@ -23,5 +23,6 @@ interface Torrent { interface File { String SELECT_DESTINATION = "/start_"; + String SHOW_FREE_SPACE = "/space"; } } diff --git a/core/src/main/java/com/halushko/kinocat/core/Queues.java b/core/src/main/java/com/halushko/kinocat/core/Queues.java index d455bcf..eced973 100644 --- a/core/src/main/java/com/halushko/kinocat/core/Queues.java +++ b/core/src/main/java/com/halushko/kinocat/core/Queues.java @@ -31,5 +31,6 @@ interface Text { interface File { String CHOOSE_THE_DESTINATION = "FILE_CHOOSE_THE_DESTINATION"; String MOVE_TO_FOLDER = "FILE_MOVE_TO_FOLDER"; + String SHOW_FREE_SPACE = "FILE_SHOW_FREE_SPACE"; } } diff --git a/file/src/main/java/com/halushko/kinocat/file/CheckDiskFreeSpace.java b/file/src/main/java/com/halushko/kinocat/file/CheckDiskFreeSpace.java new file mode 100644 index 0000000..b2b22c7 --- /dev/null +++ b/file/src/main/java/com/halushko/kinocat/file/CheckDiskFreeSpace.java @@ -0,0 +1,60 @@ +package com.halushko.kinocat.file; + +import com.halushko.kinocat.core.Queues; +import com.halushko.kinocat.core.handlers.input.CliCommandExecutor; +import com.halushko.kinocat.core.rabbit.SmartJson; +import lombok.extern.slf4j.Slf4j; +import lombok.val; + +import java.util.List; + +@Slf4j +public class CheckDiskFreeSpace extends CliCommandExecutor { + @Override + protected String getResultString(List lines, SmartJson rabbitMessage) { + log.debug(String.format("[CheckDiskFreeSpace] df -h result:\n[%s]", String.join("\n", lines))); + log.debug(String.format("[CheckDiskFreeSpace] names:\n[%s]", String.join("\n", Constants.DEVICES.keySet()))); + log.debug(String.format("[CheckDiskFreeSpace] devices:\n[%s]", String.join("\n", Constants.DEVICES.values()))); + + StringBuilder sb = new StringBuilder("Вільного місця у сховищі:"); + for (val device : Constants.DEVICES.entrySet()) { + boolean storageIsFound = false; + for (String line : lines) { + if (line.matches(device.getValue() + ".*")) { + sb.append("\n").append(device.getKey()); + sb.append(": ").append(getSize(line)); + + log.debug(String.format("[CheckDiskFreeSpace] Folder [%s] is present in line [%s]", device.getKey(), line)); + storageIsFound = true; + break; + } + log.debug(String.format("[CheckDiskFreeSpace] Folder [%s] is NOT present in line [%s]", device.getKey(), line)); + } + if (!storageIsFound) { + sb.append("\n").append(device.getKey()).append(": не вказано Filesystem у налаштуваннях"); + } + } + + return sb.toString(); + } + + private static String getSize(String line) { + String size = line; + size = size.replaceAll("^\\S+\\s+\\S+\\s+\\S+\\s+", ""); + size = size.replaceAll("\\S+\\s+\\S+\\s*$", ""); + return size; + } + + @Override + protected String getQueue() { + return Queues.File.SHOW_FREE_SPACE; + } + + @Override + protected String[] getScript(SmartJson rabbitMessage) { + return new String[]{ + "/bin/df", + "-h" + }; + } +} diff --git a/file/src/main/java/com/halushko/kinocat/file/Constants.java b/file/src/main/java/com/halushko/kinocat/file/Constants.java index a57a491..47f7b25 100644 --- a/file/src/main/java/com/halushko/kinocat/file/Constants.java +++ b/file/src/main/java/com/halushko/kinocat/file/Constants.java @@ -9,8 +9,29 @@ public interface Constants { String EMPTY_SERVICE_DEFAULT_NAME = "main"; Map FOLDERS = new FoldersProcessor(System.getenv("TORRENT_IP")) .values.keySet().stream() - .collect(Collectors.toMap(key -> key, key -> String.format(PATH_TO_DESTINATION_FOLDER + "%s", !key.isEmpty() ? "_" + key : ""))); + .collect( + Collectors.toMap( + key -> key, + key -> String.format(PATH_TO_DESTINATION_FOLDER + "%s", !key.isEmpty() ? "_" + key : "") + ) + ); String NAME_LINE = "^\\s+Name:\\s+"; String SIZE_LINE = "^\\s+Total Size:\\s+"; + Map DEVICES = new DevicesProcessor(System.getenv("TORRENT_IP")) + .values.entrySet().stream() + .collect( + Collectors.toMap( + Map.Entry::getKey, + value -> value.getValue().get("folder") + ) + ) + .entrySet().stream() + .filter(x -> !x.getValue().isEmpty()) + .collect( + Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue + ) + ); } diff --git a/file/src/main/java/com/halushko/kinocat/file/DevicesProcessor.java b/file/src/main/java/com/halushko/kinocat/file/DevicesProcessor.java new file mode 100644 index 0000000..223457d --- /dev/null +++ b/file/src/main/java/com/halushko/kinocat/file/DevicesProcessor.java @@ -0,0 +1,32 @@ +package com.halushko.kinocat.file; + +import com.halushko.kinocat.core.JsonConstants; +import com.halushko.kinocat.core.prcessors.ServicesInfoProcessor; +import com.halushko.kinocat.core.prcessors.ValueProcessor; + +import java.util.ArrayList; +import java.util.List; + +public class DevicesProcessor extends ServicesInfoProcessor { + + public DevicesProcessor(String json) { + super(json); + } + + @Override + public ValueProcessor getNameProcessor() { + return new ValueProcessor(JsonConstants.WebKeys.KEY_NAME, Constants.EMPTY_SERVICE_DEFAULT_NAME); + } + + @Override + public List getServiceProcessors() { + return new ArrayList<>() {{ + this.add(new ValueProcessor("folder", "")); + }}; + } + + @Override + public String getUrlTemplate() { + return ""; + } +} diff --git a/file/src/main/java/com/halushko/kinocat/file/FoldersProcessor.java b/file/src/main/java/com/halushko/kinocat/file/FoldersProcessor.java index a0dc56a..a82133f 100644 --- a/file/src/main/java/com/halushko/kinocat/file/FoldersProcessor.java +++ b/file/src/main/java/com/halushko/kinocat/file/FoldersProcessor.java @@ -15,7 +15,7 @@ public FoldersProcessor(String json) { @Override public ValueProcessor getNameProcessor() { - return new ValueProcessor(JsonConstants.WebKeys.KEY_NAME, ""); + return new ValueProcessor(JsonConstants.WebKeys.KEY_NAME, Constants.EMPTY_SERVICE_DEFAULT_NAME); } @Override diff --git a/file/src/main/java/com/halushko/kinocat/file/Main.java b/file/src/main/java/com/halushko/kinocat/file/Main.java index 2126a0c..3f8ea4f 100644 --- a/file/src/main/java/com/halushko/kinocat/file/Main.java +++ b/file/src/main/java/com/halushko/kinocat/file/Main.java @@ -7,5 +7,6 @@ public static void main(String[] args) { new UserMessageHandler().run(); new PrintDestinations().run(); new MoveToDestinationFolder().run(); + new CheckDiskFreeSpace().run(); } } \ No newline at end of file diff --git a/file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java b/file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java index eb58710..9423c67 100644 --- a/file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java +++ b/file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java @@ -14,7 +14,7 @@ public class PrintDestinations extends CliCommandExecutor { @Override protected String getResultString(List lines, SmartJson rabbitMessage) { - log.debug(String.format("[getResultString] [%s]", String.join(", ", lines))); + log.debug(String.format("[PrintDestinations] [%s]", String.join(", ", lines))); String[] result = new String[4]; result[0] = "("; result[2] = ") "; @@ -32,9 +32,9 @@ protected String getResultString(List lines, SmartJson rabbitMessage) { Constants.FOLDERS.keySet().stream() .map(folder -> String.format("\n%s: %s%s_%s", - getServiceLable(folder), + folder, Commands.File.SELECT_DESTINATION, - getServiceLable(folder), + folder, fileName ) ) @@ -42,10 +42,6 @@ protected String getResultString(List lines, SmartJson rabbitMessage) { ); } - private static String getServiceLable(String folder) { - return folder.isEmpty() ? Constants.EMPTY_SERVICE_DEFAULT_NAME : folder; - } - @Override protected String getQueue() { return Queues.File.CHOOSE_THE_DESTINATION; diff --git a/text/src/main/java/com/halushko/kinocat/text/Constants.java b/text/src/main/java/com/halushko/kinocat/text/Constants.java index 232b9ce..dc1b4f1 100644 --- a/text/src/main/java/com/halushko/kinocat/text/Constants.java +++ b/text/src/main/java/com/halushko/kinocat/text/Constants.java @@ -86,5 +86,10 @@ public interface Constants { Queues.File.MOVE_TO_FOLDER, "<папка> <файл> обрати в яку папку буде завантаження" ); + + addValue(Commands.File.SHOW_FREE_SPACE, + Queues.File.SHOW_FREE_SPACE, + "відобразити вільне місце у сховищі" + ); }}; } diff --git a/versions.md b/versions.md index 52178df..8b7492a 100644 --- a/versions.md +++ b/versions.md @@ -23,8 +23,10 @@ - fix access of unauthorized users ### 1.19.1 - change search, remove it from /list -### 1.19.2 (alpha/beta) +### 1.19.2 (alpha) - add /downloads command +### 1.19.3 (beta) +- fix stop.sh script ## 1.20 Planning (_TODO_) - fix error `build_core / build_core The 'save-state' command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/` - add life update of the last message