From 6401bf905daeb03ef9617402f6852631f28a4cab Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Fri, 29 Jun 2018 12:27:23 -0700 Subject: [PATCH] - handle upload of text tracks --- .../org/bigbluebutton/api/MeetingService.java | 22 +++++- .../bigbluebutton/api/RecordingService.java | 10 +-- .../util/RecordingMetadataReaderHelper.java | 4 +- .../api2/RecordingServiceGW.java | 2 +- .../api2/domain/TextTracks.scala | 19 ++++- .../api2/util/RecMetaXmlHelper.scala | 30 +++---- .../grails-app/conf/bigbluebutton.properties | 5 +- .../controllers/RecordingController.groovy | 78 +++++-------------- 8 files changed, 77 insertions(+), 93 deletions(-) diff --git a/bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java b/bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java index 9e6606e7af..955f3dd130 100755 --- a/bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java +++ b/bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java @@ -384,11 +384,29 @@ public class MeetingService implements MessageListener { return recordingService.getRecordingTextTracks(recordId); } - public String putRecordingTextTrack(String recordId, String kind, String lang, File file, String label, String origFilename) { - UploadedTrack track = new UploadedTrack(recordId, kind, lang, label, origFilename, file); + public String putRecordingTextTrack(String recordId, + String kind, + String lang, + File file, + String label, + String origFilename, + String trackId) { + + UploadedTrack track = new UploadedTrack(recordId, + kind, + lang, + label, + origFilename, + file, + trackId, + getCaptionTrackInboxDir()); return recordingService.putRecordingTextTrack(track); } + public String getCaptionTrackInboxDir() { + return recordingService.getCaptionTrackInboxDir(); + } + public String getRecordings2x(ArrayList idList, ArrayList states, Map metadataFilters) { return recordingService.getRecordings2x(idList, states, metadataFilters); } diff --git a/bbb-common-web/src/main/java/org/bigbluebutton/api/RecordingService.java b/bbb-common-web/src/main/java/org/bigbluebutton/api/RecordingService.java index 2ef18688a2..a54ddce524 100755 --- a/bbb-common-web/src/main/java/org/bigbluebutton/api/RecordingService.java +++ b/bbb-common-web/src/main/java/org/bigbluebutton/api/RecordingService.java @@ -149,11 +149,7 @@ public class RecordingService { } public String getRecordingTextTracks(String recordId) { - ArrayList recs = getAllRecordingsFor(recordId); - for (File id : recs) { - System.out.println("RECORDING FILE = " + id.getAbsolutePath()); - } - return recordingServiceHelper.getRecordingTextTracks(recordId, recs); + return recordingServiceHelper.getRecordingTextTracks(recordId, captionsDir); } public String putRecordingTextTrack(UploadedTrack track) { @@ -638,4 +634,8 @@ public class RecordingService { return baseDir; } + + public String getCaptionTrackInboxDir() { + return captionsDir + File.separatorChar + "inbox"; + } } diff --git a/bbb-common-web/src/main/java/org/bigbluebutton/api/util/RecordingMetadataReaderHelper.java b/bbb-common-web/src/main/java/org/bigbluebutton/api/util/RecordingMetadataReaderHelper.java index 527d8f1b33..283575c5c8 100755 --- a/bbb-common-web/src/main/java/org/bigbluebutton/api/util/RecordingMetadataReaderHelper.java +++ b/bbb-common-web/src/main/java/org/bigbluebutton/api/util/RecordingMetadataReaderHelper.java @@ -17,8 +17,8 @@ public class RecordingMetadataReaderHelper { private RecordingServiceGW recordingServiceGW; - public String getRecordingTextTracks(String recordId, ArrayList recs) { - return recordingServiceGW.getRecordingTextTracks(recordId, recs); + public String getRecordingTextTracks(String recordId, String captionsDir) { + return recordingServiceGW.getRecordingTextTracks(recordId, captionsDir); } public String putRecordingTextTrack(UploadedTrack track) { diff --git a/bbb-common-web/src/main/java/org/bigbluebutton/api2/RecordingServiceGW.java b/bbb-common-web/src/main/java/org/bigbluebutton/api2/RecordingServiceGW.java index 4d1a07b38e..b9c353d051 100755 --- a/bbb-common-web/src/main/java/org/bigbluebutton/api2/RecordingServiceGW.java +++ b/bbb-common-web/src/main/java/org/bigbluebutton/api2/RecordingServiceGW.java @@ -11,6 +11,6 @@ public interface RecordingServiceGW { String getRecordings2x(ArrayList recs); Option getRecordingMetadata(File xml); void saveRecordingMetadata(File xml, RecordingMetadata metadata); - String getRecordingTextTracks(String recordId, ArrayList file); + String getRecordingTextTracks(String recordId, String captionsDir); String putRecordingTextTrack(UploadedTrack track); } diff --git a/bbb-common-web/src/main/scala/org/bigbluebutton/api2/domain/TextTracks.scala b/bbb-common-web/src/main/scala/org/bigbluebutton/api2/domain/TextTracks.scala index a88ec7582e..f77c95467d 100755 --- a/bbb-common-web/src/main/scala/org/bigbluebutton/api2/domain/TextTracks.scala +++ b/bbb-common-web/src/main/scala/org/bigbluebutton/api2/domain/TextTracks.scala @@ -4,13 +4,24 @@ import java.io.File import java.util case class CaptionsDirPaths(captionsDir: String, inboxDir: String, statusDir: String) -case class UploadedTrack(recordId: String, kind: String, lang: String, label: String, origFilename: String, track: File) -case class UploadedTrackInfo(recordId: String, kind: String, lang: String, label: String, origFilename: String) +case class UploadedTrack(recordId: String, + kind: String, + lang: String, + label: String, + origFilename: String, + track: File, + trackId: String, + inboxDir: String) +case class UploadedTrackInfo(recordId: String, + kind: String, + lang: String, + label: String, + origFilename: String) case class Track(kind: String, lang: String, label: String, source: String, href: String) case class Tracks(tracks: util.ArrayList[Track]) case class GetRecTextTracksResult(returncode: String, tracks: Tracks) case class GetRecTextTracksResp(response: GetRecTextTracksResult) -case class GetRecTextTracksResultFailed(returncode: String, key: String, msg: String) +case class GetRecTextTracksResultFailed(returncode: String, messageKey: String, message: String) case class GetRecTextTracksRespFailed(response: GetRecTextTracksResultFailed) -case class PutRecTextTrackResult(returncode: String, recordId: String, key: String, msg: String) +case class PutRecTextTrackResult(returncode: String, recordId: String, messageKey: String, message: String) case class PutRecTextTrackResp(response: PutRecTextTrackResult) \ No newline at end of file diff --git a/bbb-common-web/src/main/scala/org/bigbluebutton/api2/util/RecMetaXmlHelper.scala b/bbb-common-web/src/main/scala/org/bigbluebutton/api2/util/RecMetaXmlHelper.scala index 3ece252c46..69c071a06b 100755 --- a/bbb-common-web/src/main/scala/org/bigbluebutton/api2/util/RecMetaXmlHelper.scala +++ b/bbb-common-web/src/main/scala/org/bigbluebutton/api2/util/RecMetaXmlHelper.scala @@ -184,25 +184,25 @@ class RecMetaXmlHelper extends RecordingServiceGW with LogHelper { } } - def getRecordingTextTracks(recordId: String, recs: util.ArrayList[File]):String = { + def getRecordingTextTracks(recordId: String, captionsDir: String):String = { val gson = new Gson() var returnResponse:String = "" - val captionsFilePath = CAPTIONS_DIR + File.separatorChar + recordId + File.separatorChar + CAPTIONS_FILE + val captionsFilePath = captionsDir + File.separatorChar + recordId + File.separatorChar + CAPTIONS_FILE readCaptionJsonFile(captionsFilePath, StandardCharsets.UTF_8) match { - case Some(captions) => println("Captions: \n" + captions) + case Some(captions) => val ctracks = gson.fromJson(captions, classOf[util.ArrayList[Track]]) val xtracks = Tracks(ctracks) val result1 = GetRecTextTracksResult(SUCCESS, xtracks) val response1 = GetRecTextTracksResp(result1) val respText1 = gson.toJson(response1) - println(respText1) + returnResponse = respText1 - case None => println("Captions file not found for " + recordId) + case None => val resFailed = GetRecTextTracksResultFailed(FAILED, "noCaptionsFound", "No captions found for " + recordId) val respFailed = GetRecTextTracksRespFailed(resFailed) val failedTxt = gson.toJson(respFailed) - println(failedTxt) + returnResponse = failedTxt } @@ -229,9 +229,6 @@ class RecMetaXmlHelper extends RecordingServiceGW with LogHelper { } } - val CAPTIONS_DIR = "/var/bigbluebutton/captions" - val INBOX_DIR = CAPTIONS_DIR + File.pathSeparator + "inbox" - val STATUS_DIR = "/var/bigbluebutton/recording/status/captioned" def saveTrackInfoFile(trackInfoJson:String, trackInfoFilePath: String):Boolean = { var result = false @@ -256,12 +253,7 @@ class RecMetaXmlHelper extends RecordingServiceGW with LogHelper { } def putRecordingTextTrack(track: UploadedTrack):String = { - val trackId = track.recordId + "-" + System.currentTimeMillis() - val tempTrackFilePath = INBOX_DIR + File.pathSeparator + trackId + "-track.txt" - val trackInfoFilePath = INBOX_DIR + File.pathSeparator + trackId + "-track.json" - val procTriggerPath = STATUS_DIR + File.pathSeparator + trackId + ".track" - - FileUtils.copyFile(track.track, new File(tempTrackFilePath)) + val trackInfoFilePath = track.inboxDir + File.separatorChar + track.trackId + "-track.json" val trackInfo = new UploadedTrackInfo(recordId = track.recordId, kind = track.kind, @@ -275,15 +267,15 @@ class RecMetaXmlHelper extends RecordingServiceGW with LogHelper { if (success) { val result = PutRecTextTrackResult(SUCCESS, track.recordId, - key = "upload_text_track_success", - msg = "Text track uploaded successfully") + messageKey = "upload_text_track_success", + message = "Text track uploaded successfully") val resp = PutRecTextTrackResp(result) gson.toJson(resp) } else { val result = PutRecTextTrackResult(FAILED, track.recordId, - key = "upload_text_track_failed", - msg = "Text track upload failed.") + messageKey = "upload_text_track_failed", + message = "Text track upload failed.") val resp = PutRecTextTrackResp(result) gson.toJson(resp) } diff --git a/bigbluebutton-web/grails-app/conf/bigbluebutton.properties b/bigbluebutton-web/grails-app/conf/bigbluebutton.properties index 12195b8572..083c01f48f 100755 --- a/bigbluebutton-web/grails-app/conf/bigbluebutton.properties +++ b/bigbluebutton-web/grails-app/conf/bigbluebutton.properties @@ -174,7 +174,7 @@ muteOnStart=false #---------------------------------------------------- # This URL is where the BBB client is accessible. When a user sucessfully # enters a name and password, she is redirected here to load the client. -bigbluebutton.web.serverURL=http://10.130.218.89 +bigbluebutton.web.serverURL=http://10.130.218.38 #---------------------------------------------------- @@ -211,7 +211,7 @@ defaultConfigURL=${bigbluebutton.web.serverURL}/client/conf/config.xml apiVersion=2.0 # Salt which is used by 3rd-party apps to authenticate api calls -securitySalt=3895c0fc987abdd47edf0352fea2a458 +securitySalt=330a8b08c3b4c61533e1d0c5ce1ac88f # Directory where we drop the .done file recordStatusDir=/var/bigbluebutton/recording/status/recorded @@ -223,6 +223,7 @@ redisPort=6379 # the get recording* api calls publishedDir=/var/bigbluebutton/published unpublishedDir=/var/bigbluebutton/unpublished +captionsDir=/var/bigbluebutton/captions # The directory where the pre-built configs are stored configDir=/var/bigbluebutton/configs diff --git a/bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/RecordingController.groovy b/bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/RecordingController.groovy index ee85edee95..1d051979d5 100755 --- a/bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/RecordingController.groovy +++ b/bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/RecordingController.groovy @@ -13,7 +13,7 @@ class RecordingController { def getRecordingTextTracks = { - String API_CALL = "publishRecordings" + String API_CALL = "getRecordingTextTracks" log.debug CONTROLLER_NAME + "#${API_CALL}" // BEGIN - backward compatibility @@ -22,12 +22,12 @@ class RecordingController { return } - if (StringUtils.isEmpty(params.recordId)) { + if (StringUtils.isEmpty(params.recordID)) { respondWithError("paramError", "Missing param recordID."); return } - String recordId = StringUtils.strip(params.recordId) + String recordId = StringUtils.strip(params.recordID) // Do we agree on the checksum? If not, complain. //if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) { @@ -35,35 +35,8 @@ class RecordingController { // return //} - /* - ApiErrors errors = new ApiErrors() - - // Do we have a checksum? If none, complain. - if (StringUtils.isEmpty(params.checksum)) { - errors.missingParamError("checksum"); - } - - // Do we have a recording id? If none, complain. - String recordId = params.recordID - if (StringUtils.isEmpty(recordId)) { - errors.missingParamError("recordID"); - } - - if (errors.hasErrors()) { - respondWithErrors(errors) - return - } - - // Do we agree on the checksum? If not, complain. - //if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) { - // errors.checksumError() - // respondWithErrors(errors) - // return - //} -*/ String result = meetingService.getRecordingTextTracks(recordId) - println("************* RESULT = " + result) response.addHeader("Cache-Control", "no-cache") withFormat { json { @@ -79,26 +52,8 @@ class RecordingController { render(contentType: "application/json") { response () { returncode = "FAILED" - key = errorKey - msg = errorMessage - } - } - } - } - } - - private void respondWithErrors(reqErrors) { - response.addHeader("Cache-Control", "no-cache") - withFormat { - json { - render(contentType: "application/json") { - response () { - returncode = "FAILED" - errors = array { - for (b in reqErrors.getErrors()) { - error key: b[0], msg: b[1] - } - } + messageKey = errorKey + messsage = errorMessage } } } @@ -114,12 +69,12 @@ class RecordingController { return } - if (StringUtils.isEmpty(params.recordId)) { + if (StringUtils.isEmpty(params.recordID)) { respondWithError("paramError", "Missing param recordID."); return } - String recordId = StringUtils.strip(params.recordId) + String recordId = StringUtils.strip(params.recordID) if (StringUtils.isEmpty(params.kind)) { respondWithError("paramError", "Missing param kind."); @@ -140,12 +95,18 @@ class RecordingController { captionsLabel = StringUtils.strip(params.label) } - def captionsFile = request.getFile('file') - if (captionsFile && !captionsFile.empty) { - def origFilename = captionsFile.getOriginalFilename() + def uploadedCaptionsFile = request.getFile('file') + if (uploadedCaptionsFile && !uploadedCaptionsFile.empty) { + def origFilename = uploadedCaptionsFile.getOriginalFilename() + def trackId = recordId + "-" + System.currentTimeMillis() + def captionsFilePath = meetingService.getCaptionTrackInboxDir() + File.separatorChar + trackId + "-track.txt" + def captionsFile = new File(captionsFilePath) + + uploadedCaptionsFile.transferTo(captionsFile) + String result = meetingService.putRecordingTextTrack(recordId, captionsKind, - captionsLang, captionsFile, captionsLabel, origFilename) - println("************* RESULT = " + result) + captionsLang, captionsFile, captionsLabel, origFilename, trackId) + response.addHeader("Cache-Control", "no-cache") withFormat { json { @@ -160,7 +121,8 @@ class RecordingController { render(contentType: "application/json") { response = { returncode = "FAILED" - message = "Failed to put recording text tracks." + messageKey = "empty_uploaded_text_track" + message = "Empty uploaded text track." } } }