From 53efb66774d8ef57f67e840f676b64899f2e3d54 Mon Sep 17 00:00:00 2001 From: Karasiq Date: Thu, 3 Sep 2020 10:38:52 +0300 Subject: [PATCH] Telegram instructions --- Readme.md | 13 +++++++++++++ .../src/main/resources/tgcloud/create_session | 4 ++++ .../main/resources/tgcloud/create_session.bat | 19 +++++++++++++++++++ .../main/resources/tgcloud/requirements.txt | 8 ++++---- .../storage/telegram/TelegramScripts.scala | 14 +++++++------- .../telegram/TelegramStoragePlugin.scala | 7 +++++-- 6 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 storage/telegram/src/main/resources/tgcloud/create_session create mode 100644 storage/telegram/src/main/resources/tgcloud/create_session.bat diff --git a/Readme.md b/Readme.md index aad1e68e..1c9d5fbf 100644 --- a/Readme.md +++ b/Readme.md @@ -81,6 +81,19 @@ shadowcloud.storage.gdrive.oauth.secrets.installed { } ``` +# How to configure Telegram (free+unlimited!) storage +1. You should have Python 3 installed on your system: https://www.python.org/downloads/ and also the pip package installer: https://pip.pypa.io/en/stable/installing/ +2. Install required packages with pip (executable can be `pip3` or `pip` depending on OS, on Windows it's most likely `pip`): + * Linux/MacOS: + ```bash + sudo pip3 install "Telethon>=1.14.0" "cryptg==0.2.post1" "Quart>=0.12.0" "Hypercorn>=0.9.5" "lz4==3.1.0" "pytz>=2020.1" + ``` + * Windows: + ```bash + pip install "Telethon>=1.14.0" "cryptg==0.2.post1" "Quart>=0.12.0" "Hypercorn>=0.9.5" "lz4==3.1.0" "pytz>=2020.1" + ``` +3. Create storage with `type=telegram` and follow instructions + # Plugins Full list of currently supported algorithms (some requires libsodium): ``` diff --git a/storage/telegram/src/main/resources/tgcloud/create_session b/storage/telegram/src/main/resources/tgcloud/create_session new file mode 100644 index 00000000..73682052 --- /dev/null +++ b/storage/telegram/src/main/resources/tgcloud/create_session @@ -0,0 +1,4 @@ +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "$DIR" +sudo pip3 install -r requirements.txt +python3 telegram_create_session.py diff --git a/storage/telegram/src/main/resources/tgcloud/create_session.bat b/storage/telegram/src/main/resources/tgcloud/create_session.bat new file mode 100644 index 00000000..f3872cfb --- /dev/null +++ b/storage/telegram/src/main/resources/tgcloud/create_session.bat @@ -0,0 +1,19 @@ +@echo off +cd /d "%~dp0" +set FOUND= +for %%e in (%PATHEXT%) do ( + for %%X in (pip%%e) do ( + if not defined FOUND ( + set "FOUND=%%~$PATH:X" + ) + ) + for %%X in (pip3%%e) do ( + if not defined FOUND ( + set "FOUND=%%~$PATH:X" + ) + ) +) + +set "PIP=%FOUND%" +"%PIP%" install -r requirements.txt +py telegram_create_session.py diff --git a/storage/telegram/src/main/resources/tgcloud/requirements.txt b/storage/telegram/src/main/resources/tgcloud/requirements.txt index c1adeede..40497c8f 100644 --- a/storage/telegram/src/main/resources/tgcloud/requirements.txt +++ b/storage/telegram/src/main/resources/tgcloud/requirements.txt @@ -1,6 +1,6 @@ -Telethon==1.14.0 +Telethon>=1.14.0 cryptg==0.2.post1 -Quart==0.12.0 -Hypercorn==0.9.5 -lz4==3.1.0 +Quart>=0.12.0 +Hypercorn>=0.9.5 +lz4>=3.1.0 pytz>=2020.1 diff --git a/storage/telegram/src/main/scala/com/karasiq/shadowcloud/storage/telegram/TelegramScripts.scala b/storage/telegram/src/main/scala/com/karasiq/shadowcloud/storage/telegram/TelegramScripts.scala index 3c4a7b2f..4440657a 100644 --- a/storage/telegram/src/main/scala/com/karasiq/shadowcloud/storage/telegram/TelegramScripts.scala +++ b/storage/telegram/src/main/scala/com/karasiq/shadowcloud/storage/telegram/TelegramScripts.scala @@ -1,17 +1,16 @@ package com.karasiq.shadowcloud.storage.telegram -import java.io.{InputStream, IOException} +import java.io.{IOException, InputStream} import java.nio.file._ import java.nio.file.attribute.BasicFileAttributes -import scala.util.Try - import akka.util.ByteString - import com.karasiq.shadowcloud.model.StorageId import com.karasiq.shadowcloud.storage.telegram.TelegramStorageConfig.Secrets import com.karasiq.shadowcloud.ui.UIProvider +import scala.util.Try + object TelegramScripts { def createSession(storageId: StorageId, secrets: Secrets, uiProvider: UIProvider): ByteString = { require(uiProvider.canBlock, "Please create session manually and paste it as base64 in storage config session key") @@ -19,10 +18,11 @@ object TelegramScripts { deleteDir(baseDir) extract(baseDir) writeSecrets(baseDir, secrets) + uiProvider.showNotification( - s"""Please run following command in $baseDir, then press OK - |Linux/MacOS: sudo pip3 install -r requirements.txt && python3 telegram_create_session.py - |Windows: pip3 install -r requirements.txt && py telegram_create_session.py + s"""Please execute the following action depending on your OS, then press OK + |Windows: Execute create_session.bat in $baseDir + |Linux/MacOS: Run in terminal: $baseDir/create_session |""".stripMargin ) val result = readSession(baseDir, secrets.entity) diff --git a/storage/telegram/src/main/scala/com/karasiq/shadowcloud/storage/telegram/TelegramStoragePlugin.scala b/storage/telegram/src/main/scala/com/karasiq/shadowcloud/storage/telegram/TelegramStoragePlugin.scala index b0cf3c0b..e70c17f6 100644 --- a/storage/telegram/src/main/scala/com/karasiq/shadowcloud/storage/telegram/TelegramStoragePlugin.scala +++ b/storage/telegram/src/main/scala/com/karasiq/shadowcloud/storage/telegram/TelegramStoragePlugin.scala @@ -16,8 +16,8 @@ import com.karasiq.shadowcloud.storage.props.StorageProps import com.karasiq.shadowcloud.storage.utils.StoragePluginBuilder import scala.collection.JavaConverters._ -import scala.concurrent.Await import scala.concurrent.duration._ +import scala.concurrent.{Await, Future} import scala.sys.ShutdownHookThread import scala.util.control.NonFatal import scala.util.{Random, Try} @@ -48,7 +48,10 @@ class TelegramStoragePlugin extends StoragePlugin { val session = Try(sc.sessions.getRawBlocking(storageId, "tgcloud-session")).toOption .orElse(props.rootConfig.optional(_.getString("session")).map(Base64.decode)) .filter(_.nonEmpty) - .getOrElse(TelegramScripts.createSession(storageId, config.secrets, sc.ui)) + .getOrElse { + val future = Future(TelegramScripts.createSession(storageId, config.secrets, sc.ui))(sc.ui.executionContext) + Await.result(future, 5 minutes) + } require(session.nonEmpty, "Session is empty") sc.sessions.setRawBlocking(storageId, "tgcloud-session", session)