Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serve exported files from datastore (#5942)
* Serve exported files from datastore * use access request * fetch job export properties from wk * Add token to link in frontend * changelog * Remove now-unused route
- Loading branch information
Showing
11 changed files
with
136 additions
and
30 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
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
49 changes: 49 additions & 0 deletions
49
...-datastore/app/com/scalableminds/webknossos/datastore/controllers/ExportsController.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,49 @@ | ||
package com.scalableminds.webknossos.datastore.controllers | ||
|
||
import java.nio.file.{Files, Path, Paths} | ||
|
||
import com.google.inject.Inject | ||
import com.scalableminds.util.tools.FoxImplicits | ||
import com.scalableminds.webknossos.datastore.DataStoreConfig | ||
import com.scalableminds.webknossos.datastore.services.{ | ||
DSRemoteWebKnossosClient, | ||
DataStoreAccessTokenService, | ||
UserAccessRequest | ||
} | ||
import play.api.libs.json.{Json, OFormat} | ||
import play.api.mvc.{Action, AnyContent} | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
case class JobExportProperties(jobId: String, runId: String, organizationName: String, exportFileName: String) { | ||
|
||
def fullPathIn(baseDir: Path): Path = | ||
baseDir.resolve(organizationName).resolve(".export").resolve(runId).resolve(exportFileName) | ||
} | ||
|
||
object JobExportProperties { | ||
implicit val jsonFormat: OFormat[JobExportProperties] = Json.format[JobExportProperties] | ||
} | ||
|
||
class ExportsController @Inject()(webKnossosClient: DSRemoteWebKnossosClient, | ||
accessTokenService: DataStoreAccessTokenService, | ||
config: DataStoreConfig)(implicit ec: ExecutionContext) | ||
extends Controller | ||
with FoxImplicits { | ||
|
||
private val dataBaseDir: Path = Paths.get(config.Datastore.baseFolder) | ||
|
||
def download(token: Option[String], jobId: String): Action[AnyContent] = Action.async { implicit request => | ||
accessTokenService.validateAccess(UserAccessRequest.downloadJobExport(jobId), token) { | ||
AllowRemoteOrigin { | ||
for { | ||
exportProperties <- webKnossosClient.getJobExportProperties(jobId) | ||
fullPath = exportProperties.fullPathIn(dataBaseDir) | ||
_ <- bool2Fox(Files.exists(fullPath)) ?~> "job.export.fileNotFound" | ||
} yield Ok.sendPath(fullPath, inline = false) | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
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