diff --git a/app/controllers/ApplicationController.scala b/app/controllers/ApplicationController.scala index 3485dddc0..ca0aa029f 100644 --- a/app/controllers/ApplicationController.scala +++ b/app/controllers/ApplicationController.scala @@ -12,7 +12,7 @@ import helper.PlayFormHelpers.formErrorsLog import helper.ScalatagsHelpers.writeableOf_Modifier import helper.StringHelper.NonEmptyTrimmedString import helper.TwirlImports.toHtml -import java.nio.file.{Files, Path} +import java.nio.file.Path import java.time.{LocalDate, ZonedDateTime} import java.util.UUID import javax.inject.{Inject, Singleton} @@ -1276,7 +1276,7 @@ case class ApplicationController @Inject() ( IO.blocking( eventService.log(EventType.FileNotFound, s"Le fichier $fileId n'existe pas") ).as(NotFound("Nous n'avons pas trouvé ce fichier")) - case Some((path, metadata)) => + case Some(metadata) => val applicationId = metadata.attached match { case FileMetadata.Attached.Application(id) => id case FileMetadata.Attached.Answer(applicationId, _) => applicationId @@ -1322,7 +1322,7 @@ case class ApplicationController @Inject() ( applicationId = applicationId.some ) ) >> - sendFile(path, metadata) + sendFile(metadata) case FileMetadata.Status.Expired => IO.blocking( eventService.log( @@ -1374,9 +1374,9 @@ case class ApplicationController @Inject() ( .unsafeToFuture() } - private def sendFile(localPath: Path, metadata: FileMetadata)(implicit - request: RequestWithUserData[_] - ): IO[Result] = { + private def sendFile( + metadata: FileMetadata + )(implicit request: RequestWithUserData[_]): IO[Result] = { val fileResult = (fileExists: Boolean) => IO( if (fileExists) @@ -1392,14 +1392,6 @@ case class ApplicationController @Inject() ( fileName = Some(metadata.filename) ).withHeaders(CACHE_CONTROL -> "no-store") ) - else if (Files.exists(localPath)) - // TODO: this branch is legacy and should be removed - Ok.sendPath( - localPath, - `inline` = false, - fileName = (_: Path) => Some(metadata.filename) - ).withHeaders(CACHE_CONTROL -> "no-store") - .asRight else NotFound("Nous n'avons pas trouvé ce fichier").asRight ) diff --git a/app/modules/AppConfig.scala b/app/modules/AppConfig.scala index 2d0586c88..2596efb0e 100644 --- a/app/modules/AppConfig.scala +++ b/app/modules/AppConfig.scala @@ -2,7 +2,6 @@ package modules import com.typesafe.config.{Config, ConfigFactory} import helper.{Crypto, UUIDHelper} -import java.nio.file.{Files, Path, Paths} import java.util.UUID import javax.inject.{Inject, Singleton} import play.api.Configuration @@ -39,16 +38,6 @@ class AppConfig @Inject() (configuration: Configuration) { val featureAutoAddExpert: Boolean = configuration.get[Boolean]("app.features.autoAddExpert") - val filesPath: String = configuration.get[String]("app.filesPath") - - val filesDirectory: Path = { - val dir = Paths.get(filesPath) - if (!Files.isDirectory(dir)) { - val _ = Files.createDirectories(dir) - } - dir - } - val filesExpirationInDays: Int = configuration.get[Int]("app.filesExpirationInDays") val filesOvhS3AccessKey: String = configuration.get[String]("app.filesOvhS3AccessKey") diff --git a/app/services/FileService.scala b/app/services/FileService.scala index efab292c1..b4efc1c46 100644 --- a/app/services/FileService.scala +++ b/app/services/FileService.scala @@ -14,7 +14,7 @@ import helper.Crypto import helper.StringHelper.normalizeNFKC import io.laserdisc.pure.s3.tagless.{Interpreter => S3Interpreter} import java.net.URI -import java.nio.file.{Files, Path => NioPath, Paths} +import java.nio.file.{Files, Path => NioPath} import java.time.{Instant, ZonedDateTime} import java.time.temporal.ChronoUnit.DAYS import java.util.UUID @@ -105,11 +105,6 @@ class FileService @Inject() ( result.map(_.map { case (_, metadata) => metadata }).value } - def fileMetadata(fileId: UUID): IO[Either[Error, Option[(NioPath, FileMetadata)]]] = - byId(fileId).map( - _.map(_.map(metadata => (Paths.get(s"${config.filesPath}/$fileId"), metadata))) - ) - /** This is the "official" way to check https://stackoverflow.com/a/56038360 * * The AWS library throws software.amazon.awssdk.services.s3.model.NoSuchKeyException when the @@ -273,7 +268,7 @@ class FileService @Inject() ( private val fieldsInSelect: String = tableFields.mkString(", ") - private def byId(fileId: UUID): IO[Either[Error, Option[FileMetadata]]] = + def fileMetadata(fileId: UUID): IO[Either[Error, Option[FileMetadata]]] = IO.blocking( db.withConnection { implicit connection => SQL(s"""SELECT $fieldsInSelect FROM file_metadata WHERE id = {fileId}::uuid""") @@ -371,7 +366,7 @@ class FileService @Inject() ( s"Début de la suppression des fichiers avant $beforeDate" ) ) >> - deleteBefore(beforeDate).both(legacyDeleteExpiredFiles).map { case (result, _) => result } + deleteBefore(beforeDate) } private def deleteBefore(beforeDate: Instant): IO[Either[Error, Unit]] = @@ -383,10 +378,7 @@ class FileService @Inject() ( Stream .emits(files) .evalMap { metadata => - val delete = ovhS3.delete(bucket, s3fileName(metadata.id)) - val deleteLegacy = - FsFiles[IO].deleteIfExists(FsPath(config.filesPath) / metadata.id.toString) - val deletion = delete.both(deleteLegacy) >> + val deletion = ovhS3.delete(bucket, s3fileName(metadata.id)) >> updateStatus(metadata.id, FileMetadata.Status.Expired).flatMap( _.fold( e => IO.blocking(eventService.logErrorNoRequest(e)), @@ -410,22 +402,6 @@ class FileService @Inject() ( ) ) - private def legacyDeleteExpiredFiles = IO { - val dir = new java.io.File(config.filesPath) - if (dir.exists() && dir.isDirectory) { - val fileToDelete = dir - .listFiles() - .filter(_.isFile) - .filter { file => - val instant = Files.getLastModifiedTime(file.toPath).toInstant - instant - .plus(config.filesExpirationInDays.toLong + 1, DAYS) - .isBefore(Instant.now()) - } - fileToDelete.foreach(_.delete()) - } - } - def wipeFilenames(retentionInMonths: Long): Future[Either[Error, Int]] = Future( Try( diff --git a/conf/application.conf b/conf/application.conf index e2661e786..e92dc019f 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -71,7 +71,6 @@ app.passwordSessionDurationInSeconds = 2592000 app.passwordSessionDurationInSeconds = ${?APP_PASSWORD_SESSION_DURATION_IN_SECONDS} app.passwordRecoveryTokenExpirationInMinutes = 15 app.passwordRecoveryTokenExpirationInMinutes = ${?PASSWORD_RECOVERY_TOKEN_EXPIRATION_IN_MINUTES} -app.filesPath = ${?FILES_PATH} app.filesExpirationInDays = 7 app.filesExpirationInDays = ${?FILES_EXPIRATION_IN_DAYS} app.filesOvhS3AccessKey = ${?FILES_OVH_S3_ACCESS_KEY}