Skip to content

Commit

Permalink
Merge branch 'feat-attachments'
Browse files Browse the repository at this point in the history
  • Loading branch information
nymanjens committed Jan 4, 2025
2 parents d8b3b24 + f588e37 commit 54fd58e
Show file tree
Hide file tree
Showing 28 changed files with 439 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import scala.collection.immutable.Seq
import scala.collection.mutable
import scala.concurrent.Future
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
import scala.scalajs.js.typedarray.ArrayBuffer

final class FakeScalaJsApiClient extends ScalaJsApiClient {

Expand Down Expand Up @@ -62,6 +63,10 @@ final class FakeScalaJsApiClient extends ScalaJsApiClient {
upsertedUserPrototypes += userPrototype
}

def storeFileAndReturnHash(bytes: ArrayBuffer): Future[String] = {
???
}

// **************** Additional methods for tests ****************//
def addEntities[E <: Entity: EntityType](entities: E*): Unit = {
modificationsBuffer.addEntities(entities.toVector)
Expand Down
4 changes: 4 additions & 0 deletions app/js/shared/src/main/scala/app/api/ScalaJsApiClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ trait ScalaJsApiClient {
def executeDataQuery[E <: Entity](dbQuery: DbQuery[E]): Future[Seq[E]]
def executeCountQuery(dbQuery: DbQuery[_ <: Entity]): Future[Int]
def upsertUser(userPrototype: UserPrototype): Future[Unit]
def storeFileAndReturnHash(bytes: ArrayBuffer): Future[String]
}

object ScalaJsApiClient {
Expand Down Expand Up @@ -74,6 +75,9 @@ object ScalaJsApiClient {
override def upsertUser(userPrototype: UserPrototype) = {
WebsocketAutowireClient[ScalaJsApi].upsertUser(userPrototype).call()
}
override def storeFileAndReturnHash(bytes: ArrayBuffer): Future[String] = {
WebsocketAutowireClient[ScalaJsApi].storeFileAndReturnHash(TypedArrayBuffer.wrap(bytes)).call()
}

private object HttpPostAutowireClient extends autowire.Client[ByteBuffer, Pickler, Pickler] {
override def doCall(req: Request): Future[ByteBuffer] = {
Expand Down
20 changes: 20 additions & 0 deletions app/js/shared/src/main/scala/app/common/AttachmentFormatting.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.common

import app.models.accounting.Transaction.Attachment

object AttachmentFormatting {
def getUrl(attachment: Attachment): String = {
val typeEncoded = attachment.fileType.replace('/', '>')
f"/attachments/${attachment.contentHash}/$typeEncoded/${attachment.filename}"
}

def formatBytes(fileSizeBytes: Int): String = {
if (fileSizeBytes < 1024){
f"${fileSizeBytes}B"
} else if (fileSizeBytes< 1024*1024){
f"${fileSizeBytes/1024}kB"
} else {
f"${fileSizeBytes/1024/1024}MB"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ final class ClientAppModule(implicit
implicit private val localDatabaseHasBeenLoadedStore = fluxStoresModule.localDatabaseHasBeenLoadedStore
implicit private val userStore = fluxStoresModule.userStore
implicit private val databaseExplorerStoreFactory = fluxStoresModule.databaseExplorerStoreFactory
implicit private val attachmentStore = fluxStoresModule.attachmentStore

// Create other Flux modules
implicit private val reactAppModule = new app.flux.react.app.Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class Module(implicit
dispatcher: Dispatcher,
clock: Clock,
templateMatcher: TemplateMatcher,
attachmentStore: AttachmentStore,
) {

// Configuration of submodules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import app.flux.stores.GlobalMessagesStore
import app.flux.stores.InMemoryUserConfigStore
import app.flux.stores.entries.factories.LiquidationEntriesStoreFactory
import app.flux.stores.entries.factories.TagsStoreFactory
import app.flux.stores.AttachmentStore
import app.models.access.AppJsEntityAccess
import app.models.accounting.config.Config
import app.models.user.User
Expand All @@ -26,6 +27,7 @@ final class Module(implicit
clock: Clock,
liquidationEntriesStoreFactory: LiquidationEntriesStoreFactory,
pageHeader: PageHeader,
attachmentStore: AttachmentStore,
) {

implicit private lazy val transactionPanel: TransactionPanel = new TransactionPanel
Expand Down
Loading

0 comments on commit 54fd58e

Please sign in to comment.