This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from actorapp/server/files
Server/files
- Loading branch information
Showing
35 changed files
with
282 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
actor-server/actor-core/src/main/scala/im/actor/server/file/FileStorageExtension.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package im.actor.server.file | ||
|
||
import akka.actor._ | ||
import im.actor.config.ActorConfig | ||
import im.actor.serialization.ActorSerializer | ||
|
||
import scala.util.{ Failure, Success, Try } | ||
|
||
trait FileStorageExtension extends Extension { | ||
val fsAdapter: FileStorageAdapter | ||
} | ||
|
||
class FileStorageExtensionImpl(system: ActorSystem) extends FileStorageExtension { | ||
|
||
ActorSerializer.register( | ||
80001 → classOf[FileLocation], | ||
80002 → classOf[AvatarImage], | ||
80003 → classOf[Avatar], | ||
80004 → classOf[S3UploadKey] | ||
) | ||
|
||
override val fsAdapter = init() | ||
|
||
def init(): FileStorageAdapter = | ||
(for { | ||
fqcn ← Try(ActorConfig.load().getString("modules.files.adapter")) | ||
_ = system.log.debug("File adapter is: {}", fqcn) | ||
clazz ← Try(Class.forName(fqcn).asSubclass(classOf[FileStorageAdapter])) | ||
} yield clazz.getDeclaredConstructor(classOf[ActorSystem]).newInstance(system)) match { | ||
case Success(adapter) ⇒ adapter | ||
case Failure(e) ⇒ throw new RuntimeException("Failed to initialize FileStorageAdapter", e) | ||
} | ||
} | ||
|
||
object FileStorageExtension extends ExtensionId[FileStorageExtensionImpl] with ExtensionIdProvider { | ||
override def lookup = FileStorageExtension | ||
|
||
override def createExtension(system: ExtendedActorSystem) = new FileStorageExtensionImpl(system) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
actor-server/actor-core/src/main/scala/im/actor/server/file/UploadKey.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package im.actor.server.file | ||
|
||
trait UploadKey { | ||
val key: String | ||
def toByteArray: Array[Byte] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
actor-server/actor-core/src/main/scala/im/actor/server/file/s3/S3StorageAdapterConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package im.actor.server.file.s3 | ||
|
||
import com.github.kxbmap.configs._ | ||
import com.typesafe.config.{ ConfigFactory, Config } | ||
|
||
import scala.util.Try | ||
|
||
case class S3StorageAdapterConfig(bucketName: String, key: String, secret: String) | ||
|
||
object S3StorageAdapterConfig { | ||
def load(config: Config): Try[S3StorageAdapterConfig] = { | ||
for { | ||
bucketName ← config.get[Try[String]]("default-bucket") | ||
key ← config.get[Try[String]]("access-key") | ||
secret ← config.get[Try[String]]("secret-key") | ||
} yield S3StorageAdapterConfig(bucketName, key, secret) | ||
} | ||
|
||
def load: Try[S3StorageAdapterConfig] = { | ||
val config = ConfigFactory.load().getConfig("services.aws.s3") | ||
load(config) | ||
} | ||
} |
Oops, something went wrong.