tmail-backend
tmail-backend copied to clipboard
Implement JMAP route to get content of the public asset
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
toJMAPRoutes
usingGuice
:
Multibinder.newSetBinder(binder, classOf[JMAPRoutes])
routes.addBinding().to(classOf[PublicAssetRoutes])
- Write integration tests.
Dod
- Tests pass.
- Documentation.