Skip to content

Commit

Permalink
Fix yandex captcha challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
Karasiq committed Sep 3, 2020
1 parent 4114326 commit 0aec46d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions core/src/main/scala/com/karasiq/shadowcloud/ShadowCloud.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.karasiq.shadowcloud

import java.util.UUID
import java.util.concurrent.Executors

import akka.Done
import akka.actor.{ActorContext, ActorRef, ActorSystem, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider}
Expand Down Expand Up @@ -182,6 +183,7 @@ class ShadowCloudExtension(_actorSystem: ExtendedActorSystem) extends Extension
object ui extends UIProvider with PasswordProvider {
private[this] lazy val passProvider: PasswordProvider = provInstantiator.getInstance(config.ui.passwordProvider)
private[this] lazy val uiProvider: UIProvider = provInstantiator.getInstance(config.ui.uiProvider)
def executionContext = executionContexts.ui

override def askPassword(id: String): String =
passProvider.askPassword(id)
Expand Down Expand Up @@ -270,6 +272,7 @@ class ShadowCloudExtension(_actorSystem: ExtendedActorSystem) extends Extension
val metadata = _actorSystem.dispatchers.lookup(SCDispatchers.metadata)
val metadataBlocking = _actorSystem.dispatchers.lookup(SCDispatchers.metadataBlocking)
val cryptography = _actorSystem.dispatchers.lookup(SCDispatchers.cryptography)
val ui = ExecutionContext.fromExecutorService(Executors.newSingleThreadExecutor())
}

private[this] object lifecycleHooks extends LifecycleHook {
Expand All @@ -285,6 +288,7 @@ class ShadowCloudExtension(_actorSystem: ExtendedActorSystem) extends Extension
def shutdown(): Unit = instances.foreach { hook
log.debug("Executing shutdown hook: {}", hook)
Try(hook.shutdown()).failed.foreach(actorSystem.log.error(_, "Shutdown hook error"))
executionContexts.ui.shutdownNow()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ class YandexStoragePlugin extends StoragePlugin {
val log = Logging(system, context.self)
val sc = ShadowCloud()
val api = new YandexWebApi(solveCaptcha = { imageUrl
sc.ui.showNotification(s"Yandex captcha required for $storageId: $imageUrl")
if (Desktop.isDesktopSupported) Desktop.getDesktop.browse(new URI(imageUrl))
Future.fromTry(Try(sc.ui.askPassword("Yandex captcha")))
Future {
sc.ui.showNotification(s"Yandex captcha required for $storageId: $imageUrl")
if (Desktop.isDesktopSupported) Desktop.getDesktop.browse(new URI(imageUrl))
sc.ui.askPassword("Yandex captcha")
}(sc.ui.executionContext)
}, passChallenge = { url
if (Desktop.isDesktopSupported) Desktop.getDesktop.browse(new URI(url))
Future {
if (Desktop.isDesktopSupported) Desktop.getDesktop.browse(new URI(url))
sc.ui.showNotification(
s"Yandex verification required for $storageId: $url\n" +
"Please complete the verification and then press OK"
)
Done
}
}(sc.ui.executionContext)
})

implicit val session: YandexSession = {
def create() = Await.result(api.createSession(props.credentials.login, props.credentials.password), 10 seconds)
def create() = Await.result(api.createSession(props.credentials.login, props.credentials.password), 5 minutes)

Try(sc.sessions.getBlocking[YandexSession](storageId, "yad-session"))
.map { implicit session
Expand Down

0 comments on commit 0aec46d

Please sign in to comment.