Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/examples/docker-compose/docker-compose-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions config/examples/docker-compose/stop.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/halushko/kinocat/core/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ interface Torrent {

interface File {
String SELECT_DESTINATION = "/start_";
String SHOW_FREE_SPACE = "/space";
}
}
1 change: 1 addition & 0 deletions core/src/main/java/com/halushko/kinocat/core/Queues.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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<String> 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"
};
}
}
23 changes: 22 additions & 1 deletion file/src/main/java/com/halushko/kinocat/file/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,29 @@ public interface Constants {
String EMPTY_SERVICE_DEFAULT_NAME = "main";
Map<String, String> 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<String, String> 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
)
);
}
32 changes: 32 additions & 0 deletions file/src/main/java/com/halushko/kinocat/file/DevicesProcessor.java
Original file line number Diff line number Diff line change
@@ -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<ValueProcessor> getServiceProcessors() {
return new ArrayList<>() {{
this.add(new ValueProcessor("folder", ""));
}};
}

@Override
public String getUrlTemplate() {
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions file/src/main/java/com/halushko/kinocat/file/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public static void main(String[] args) {
new UserMessageHandler().run();
new PrintDestinations().run();
new MoveToDestinationFolder().run();
new CheckDiskFreeSpace().run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class PrintDestinations extends CliCommandExecutor {
@Override
protected String getResultString(List<String> 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] = ") ";
Expand All @@ -32,20 +32,16 @@ protected String getResultString(List<String> 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
)
)
.collect(Collectors.joining(""))
);
}

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;
Expand Down
5 changes: 5 additions & 0 deletions text/src/main/java/com/halushko/kinocat/text/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,10 @@ public interface Constants {
Queues.File.MOVE_TO_FOLDER,
"<папка> <файл> обрати в яку папку буде завантаження"
);

addValue(Commands.File.SHOW_FREE_SPACE,
Queues.File.SHOW_FREE_SPACE,
"відобразити вільне місце у сховищі"
);
}};
}
4 changes: 3 additions & 1 deletion versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down