diff --git a/config/examples/docker-compose/docker-compose-bot_debug.yml b/config/examples/docker-compose/docker-compose-bot_debug.yml index 2d35aec..a7599e6 100644 --- a/config/examples/docker-compose/docker-compose-bot_debug.yml +++ b/config/examples/docker-compose/docker-compose-bot_debug.yml @@ -1,16 +1,16 @@ version: '3.7' services: -# torrent_debug: -# image: halushko/cinema-torrent:beta -# env_file: -# - constants.env -# restart: always -# container_name: "torrent_debug" -# volumes: -# - ./workdir/config/transmission:/home/app/transmission_config -# - ./workdir/config/logs:/home/app/logs -# network_mode: host + torrent_debug: + image: halushko/cinema-torrent:beta + env_file: + - constants.env + restart: always + container_name: "torrent_debug" + volumes: + - ./workdir/config/transmission:/home/app/transmission_config + - ./workdir/config/logs:/home/app/logs + network_mode: host bot_debug: image: halushko/cinema-bot:beta env_file: diff --git a/config/examples/docker-compose/docker-compose-torrent-hdd.yml b/config/examples/docker-compose/docker-compose-torrent-hdd.yml index 359ba48..5da4e1f 100644 --- a/config/examples/docker-compose/docker-compose-torrent-hdd.yml +++ b/config/examples/docker-compose/docker-compose-torrent-hdd.yml @@ -10,7 +10,7 @@ services: - TZ=Etc/UTC volumes: - ./workdir/config/transmission_hdd:/config - - ./workdir/mediadata_hdd:/downloads/complete + - ./workdir/mediadata/hdd/mediadata:/downloads/complete - ./workdir/config/files_from_telegram_hdd:/watch ports: - 9092:9091 diff --git a/config/examples/etc/systemd/services/bot-down.service b/config/examples/etc/systemd/services/bot-down.service index 34fe37c..6b79af6 100644 --- a/config/examples/etc/systemd/services/bot-down.service +++ b/config/examples/etc/systemd/services/bot-down.service @@ -1,7 +1,7 @@ [Unit] Description=Shut down Bot Requires=docker.service -After=message-broker.service +After=mount-hdd.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/create_services.sh b/config/examples/etc/systemd/services/create_services.sh index b6f3771..ea01a38 100644 --- a/config/examples/etc/systemd/services/create_services.sh +++ b/config/examples/etc/systemd/services/create_services.sh @@ -16,6 +16,7 @@ systemctl stop torrent-pull.service systemctl stop torrent-hdd.service systemctl stop torrent-hdd-down.service systemctl stop torrent-hdd-pull.service +systemctl stop mount-hdd.service systemctl disable bot.service systemctl disable bot-debug-down.service @@ -33,6 +34,7 @@ systemctl disable torrent-pull.service systemctl disable torrent-hdd.service systemctl disable torrent-hdd-down.service systemctl disable torrent-hdd-pull.service +systemctl disable mount-hdd.service cp -f *.service /etc/systemd/system @@ -51,4 +53,5 @@ systemctl enable torrent-down.service systemctl enable torrent-pull.service systemctl enable torrent-hdd.service systemctl enable torrent-hdd-down.service -systemctl enable torrent-hdd-pull.service \ No newline at end of file +systemctl enable torrent-hdd-pull.service +systemctl enable mount-hdd.service \ No newline at end of file diff --git a/config/examples/etc/systemd/services/media-server-down.service b/config/examples/etc/systemd/services/media-server-down.service index 1fa2d10..e660a7a 100644 --- a/config/examples/etc/systemd/services/media-server-down.service +++ b/config/examples/etc/systemd/services/media-server-down.service @@ -1,7 +1,7 @@ [Unit] Description=Media server down Requires=docker.service -After=docker.service +After=mount-hdd.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/message-broker-down.service b/config/examples/etc/systemd/services/message-broker-down.service index be80fee..07148ce 100644 --- a/config/examples/etc/systemd/services/message-broker-down.service +++ b/config/examples/etc/systemd/services/message-broker-down.service @@ -1,7 +1,7 @@ [Unit] Description=Message brocker Service Requires=docker.service -After=docker.service +After=mount-hdd.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/mount-hdd.service b/config/examples/etc/systemd/services/mount-hdd.service new file mode 100644 index 0000000..92368ba --- /dev/null +++ b/config/examples/etc/systemd/services/mount-hdd.service @@ -0,0 +1,14 @@ +[Unit] +Description=Mount HDD disc +Requires=docker.service +After=docker.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=mount -t ntfs /dev/sdb1 /home/dima/media/workdir/mediadata/hdd/ +#ExecStop=umount /dev/sdb1 +TimeoutStartSec=0 + +[Install] +WantedBy=default.target diff --git a/config/examples/etc/systemd/services/torrent-hdd-down.service b/config/examples/etc/systemd/services/torrent-hdd-down.service index 4bcd34c..2e5dc87 100644 --- a/config/examples/etc/systemd/services/torrent-hdd-down.service +++ b/config/examples/etc/systemd/services/torrent-hdd-down.service @@ -1,7 +1,7 @@ [Unit] Description=Torent client Service Requires=docker.service -After=docker.service +After=mount-hdd.service [Service] Type=oneshot diff --git a/file/src/main/java/com/halushko/kinocat/file/UserMessageHandler.java b/file/src/main/java/com/halushko/kinocat/file/UserMessageHandler.java index e3834a5..2a2a672 100644 --- a/file/src/main/java/com/halushko/kinocat/file/UserMessageHandler.java +++ b/file/src/main/java/com/halushko/kinocat/file/UserMessageHandler.java @@ -12,11 +12,23 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; import static com.halushko.kinocat.core.rabbit.SmartJson.KEYS.*; @Slf4j public class UserMessageHandler extends InputMessageHandler { - private static final String FILE_URL_PREFIX = String.format("%s%s/", "https://api.telegram.org/file/bot", System.getenv("BOT_TOKEN")); + private final static String FILE_URL_PREFIX = String.format("%s%s/", "https://api.telegram.org/file/bot", System.getenv("BOT_TOKEN")); + + @SuppressWarnings("unchecked") + private final static Set folders = new LinkedHashSet<>() {{ + new SmartJson(System.getenv("TORRENT_IP")) + .convertToList() + .stream() + .map((x -> (Map) x)) + .forEach(x -> add(String.valueOf(x.getOrDefault("name", "default")))); + }}; @Override protected String getDeliverCallbackPrivate(SmartJson rabbitMessage) { @@ -41,9 +53,12 @@ protected void handleTorrent(SmartJson rm) throws MalformedURLException { long userId = rm.getUserId(); String fileName = String.format("%s%s", rm.getValue(FILE_ID), ".torrent"); String message = rm.getValue(TEXT); - - File localFile = "hdd".equalsIgnoreCase(message) ? new File("/home/torrent_files_hdd/" + fileName) : new File("/home/torrent_files/" + fileName); - + if(message == null || message.trim().isEmpty()) { + message = ""; + } else if(folders.contains(message.trim())){ + message = "_" + message.trim(); + } + File localFile = new File(String.format("/home/torrent_files%s/%s", message, fileName)); try (InputStream is = fileUrl.openStream()) { FileUtils.copyInputStreamToFile(is, localFile); } catch (IOException e) { diff --git a/torrent/src/main/java/com/halushko/kinocat/torrent/requests/common/TransmissionWebApiExecutor.java b/torrent/src/main/java/com/halushko/kinocat/torrent/requests/common/TransmissionWebApiExecutor.java index e3c4603..2ebb41a 100644 --- a/torrent/src/main/java/com/halushko/kinocat/torrent/requests/common/TransmissionWebApiExecutor.java +++ b/torrent/src/main/java/com/halushko/kinocat/torrent/requests/common/TransmissionWebApiExecutor.java @@ -81,7 +81,7 @@ protected final String getDeliverCallbackPrivate(SmartJson message) { output.append(printResult(chatId, sb.toString())); } else { log.debug("[getDeliverCallbackPrivate] Result is empty"); - output.append(printResult(chatId, "Нажаль результат запиту порожній")); + output.append(printResult(chatId, String.format("%s: Нажаль результат запиту порожній", session.getKey()))); } } else { String errorText = String.format("Server: %s result of request is: %s", session.getKey(), responceBody);