@@ -142,93 +142,80 @@ class UploadController(
142142 assetVersion : Int
143143 ): Action [MultipartFormData [Files .TemporaryFile ]] =
144144 LookupPermissions (parse.multipartFormData) { implicit req =>
145- if (! req.permissions.addSubtitles) {
146- Unauthorized (
147- s " User ${req.user.email} is not authorised to upload subtitle asset "
148- )
149- } else {
150- log.info(
151- s " Request to upload subtitle file under atom= $atomId assetVersion= $assetVersion"
152- )
153- val result = for {
154- file <- req.body.file(" subtitle-file" )
155- upload <- uploadDecorator.getUpload(s " $atomId- $assetVersion" )
156- } yield try {
157- val subtitleSource = SubtitleFileUploadCommand (
158- upload,
159- file,
160- stores,
161- req.user,
162- awsConfig
163- ).process()
164-
165- // add subtitle file to upload asset's list of sources
166- val rerunUpload =
167- UploadBuilder .buildForSubtitleChange(upload, Some (subtitleSource))
168-
169- // reprocessing will also save the upload to the DB, but saving it here first improves UI responsiveness
170- saveUploadToDb(rerunUpload)
171-
172- processSubtitleChange(rerunUpload)
173-
174- log.info(
175- s " Upload being reprocessed after subtitle upload ${upload.id}"
176- )
177- Ok (Json .toJson(rerunUpload))
178- } catch {
179- commandExceptionAsResult
180- }
145+ log.info(
146+ s " Request to upload subtitle file under atom= $atomId assetVersion= $assetVersion"
147+ )
148+ val result = for {
149+ file <- req.body.file(" subtitle-file" )
150+ upload <- uploadDecorator.getUpload(s " $atomId- $assetVersion" )
151+ } yield try {
152+ val subtitleSource = SubtitleFileUploadCommand (
153+ upload,
154+ file,
155+ stores,
156+ req.user,
157+ awsConfig
158+ ).process()
159+
160+ // add subtitle file to upload asset's list of sources
161+ val rerunUpload =
162+ UploadBuilder .buildForSubtitleChange(upload, Some (subtitleSource))
163+
164+ // reprocessing will also save the upload to the DB, but saving it here first improves UI responsiveness
165+ saveUploadToDb(rerunUpload)
166+
167+ processSubtitleChange(rerunUpload)
181168
182- result.getOrElse (
183- BadRequest
169+ log.info (
170+ s " Upload being reprocessed after subtitle upload ${upload.id} "
184171 )
172+ Ok (Json .toJson(rerunUpload))
173+ } catch {
174+ commandExceptionAsResult
185175 }
176+
177+ result.getOrElse(
178+ BadRequest
179+ )
186180 }
187181
188182 def deleteSubtitleFile (
189183 atomId : String ,
190184 assetVersion : Int
191185 ): Action [AnyContent ] =
192186 LookupPermissions { implicit req =>
193- if (! req.permissions.addSubtitles) {
194- Unauthorized (
195- s " User ${req.user.email} is not authorised to upload subtitle asset "
196- )
197- } else {
198- log.info(
199- s " Request to delete subtitle file under atom= $atomId assetVersion= $assetVersion"
200- )
201- uploadDecorator.getUpload(s " $atomId- $assetVersion" ) match {
202- case Some (upload) =>
203- try {
204- SubtitleFileDeleteCommand (
205- upload,
206- stores,
207- req.user,
208- awsConfig
209- ).process()
210-
211- // remove subtitle files from upload asset's list of sources
212- val rerunUpload =
213- UploadBuilder .buildForSubtitleChange(upload, None )
214-
215- // reprocessing will also save the upload to the DB, but saving it here first improves UI responsiveness
216- saveUploadToDb(rerunUpload)
217-
218- processSubtitleChange(rerunUpload)
219-
220- log.info(
221- s " Upload being reprocessed after subtitle deletion ${upload.id}"
222- )
223- Ok (Json .toJson(rerunUpload))
224- } catch {
225- commandExceptionAsResult
226- }
227- case _ =>
228- NotFound
229- }
187+ log.info(
188+ s " Request to delete subtitle file under atom= $atomId assetVersion= $assetVersion"
189+ )
190+ uploadDecorator.getUpload(s " $atomId- $assetVersion" ) match {
191+ case Some (upload) =>
192+ try {
193+ SubtitleFileDeleteCommand (
194+ upload,
195+ stores,
196+ req.user,
197+ awsConfig
198+ ).process()
199+
200+ // remove subtitle files from upload asset's list of sources
201+ val rerunUpload =
202+ UploadBuilder .buildForSubtitleChange(upload, None )
203+
204+ // reprocessing will also save the upload to the DB, but saving it here first improves UI responsiveness
205+ saveUploadToDb(rerunUpload)
206+
207+ processSubtitleChange(rerunUpload)
208+
209+ log.info(
210+ s " Upload being reprocessed after subtitle deletion ${upload.id}"
211+ )
212+ Ok (Json .toJson(rerunUpload))
213+ } catch {
214+ commandExceptionAsResult
215+ }
216+ case _ =>
217+ NotFound
230218 }
231-
232219 }
233220
234221 @ tailrec
0 commit comments