tmail-backend icon indicating copy to clipboard operation
tmail-backend copied to clipboard

Implement JMAP route to get content of the public asset

Open vttranlina opened this issue 9 months ago • 1 comments

Why

Epic: https://github.com/linagora/tmail-backend/issues/1027 When a client (e.g., web browser, mobile app) requests the content of a public asset, the Tmail JMAP server needs to serve that content.

How

  • Create a new PublicAssetRoutes class with the following implementation:
class PublicAssetRoutes(publicAssetRepository: PublicAssetRepository,
                        blobResolvers: BlobResolvers) extends JMAPRoutes {

  override def routes(): Stream[JMAPRoute] = Stream.of(
    JMAPRoute.builder()
      .endpoint(new Endpoint(HttpMethod.GET, s"/publicAsset/{$accountId}/{$assetId}"))
      .action((request, response) => getAsset(request, response))
      .corsHeaders())

  private def getAsset(request: HttpServerRequest, response: HttpServerResponse): SMono[Unit] = {
    // checking if accountId and assetId are existing
    // if not, return 404
    // else, using blobResolvers to get the blob of the asset
    // then apply the blob to the response
  }
}

Note that this is a public endpoint, so authentication is not required.

  • Bind PublicAssetRoutes to JMAPRoutes using Guice:
Multibinder.newSetBinder(binder, classOf[JMAPRoutes])
    routes.addBinding().to(classOf[PublicAssetRoutes])
  • Write integration tests.

Dod

  • Tests pass.
  • Documentation.

Ref: LinagoraServicesDiscoveryRoutes

DownloadRoutes

vttranlina avatar May 15 '24 09:05 vttranlina