Skip to content

Commit

Permalink
Telegram instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Karasiq committed Sep 3, 2020
1 parent 0aec46d commit 53efb66
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
```
Expand Down
4 changes: 4 additions & 0 deletions storage/telegram/src/main/resources/tgcloud/create_session
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions storage/telegram/src/main/resources/tgcloud/create_session.bat
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions storage/telegram/src/main/resources/tgcloud/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
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")
val baseDir = Paths.get(sys.props("user.home"), s"tgcloud-temp-$storageId")
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 53efb66

Please sign in to comment.