diff --git a/ClassTranscribeServer/Controllers/MediaController.cs b/ClassTranscribeServer/Controllers/MediaController.cs index 9a98125..6421560 100644 --- a/ClassTranscribeServer/Controllers/MediaController.cs +++ b/ClassTranscribeServer/Controllers/MediaController.cs @@ -57,10 +57,10 @@ public async Task> GetMedia(string id) return new ChallengeResult(); } - + var playlist = await _context.Playlists.FindAsync(media.PlaylistId); //unused var v = await _context.Videos.FindAsync(media.VideoId); var user = await _userUtils.GetUser(User); - + var restrict = (bool?) playlist.getOptionsAsJson()[ "restrictRoomStream"] ?? false; var mediaDTO = new MediaDTO { Id = media.Id, @@ -71,6 +71,7 @@ public async Task> GetMedia(string id) SourceType = media.SourceType, Duration = media.Video.Duration, PublishStatus = media.PublishStatus, + Options = media.getOptionsAsJson(), Transcriptions = media.Video.Transcriptions .Select(t => new TranscriptionDTO { @@ -84,7 +85,7 @@ public async Task> GetMedia(string id) { Id = media.Video.Id, Video1Path = media.Video.ProcessedVideo1?.Path != null ? media.Video.ProcessedVideo1.Path : media.Video.Video1?.Path, - Video2Path = media.Video.ProcessedVideo2?.Path != null ? media.Video.ProcessedVideo2.Path : media.Video.Video2?.Path, + Video2Path = restrict ? null: media.Video.ProcessedVideo2?.Path != null ? media.Video.ProcessedVideo2.Path : media.Video.Video2?.Path, ASLPath = media.Video.ASLVideo?.Path, TaskLog = media.Video.TaskLog }, @@ -158,6 +159,44 @@ public async Task PutJsonMetaData(JObject jsonMetaData, string id return NoContent(); } +// PUT: api/Media/5 + [HttpPut("Option/{id}/{option}/{type}/{value}")] + [Authorize] + public async Task PutMediaOption(string id, string option, string type,string value) + { + if(id == null) return BadRequest("id not specified"); + if(type == null || ! "|int|bool|string|".Contains($"|{type}|")) { + return BadRequest("type must be int|bool|string"); + } + if(value == null) return BadRequest("value not specified"); + + Media media = await _context.Medias.FindAsync(id); + JObject theOptions = media.getOptionsAsJson(); + if (media == null) + { + return NotFound(); + } + if(type == "int") { + try { + theOptions[option] = Int32.Parse(value); + } catch (FormatException) { + return BadRequest($"Unable to parse '{value}' as int"); + } + } else if(type == "bool") { + try { + theOptions[option] = Boolean.Parse(value); + } catch (FormatException) { + return BadRequest($"Unable to parse '{value}' as bool"); + } + } else if(type == "string") { + theOptions[option] = value; + } else { + return BadRequest("Invalid type");// should never happen + } + media.setOptionsAsJson(theOptions); + await _context.SaveChangesAsync(); + return NoContent(); + } // POST: api/ASLVideo [DisableRequestSizeLimit] @@ -200,7 +239,9 @@ public async Task> PostASLVideo(IFormFile aSLVideo, [FromFor var subdir = CommonUtils.ToCourseOfferingSubDirectory(_context, media); var filerecord = await FileRecord.GetNewFileRecordAsync(filePath, Path.GetExtension(filePath), subdir); - video.ASLVideo = filerecord; + await _context.FileRecords.AddAsync(filerecord); + await _context.SaveChangesAsync(); + video.ASLVideoId = filerecord.Id; await _context.SaveChangesAsync(); return Ok(); } diff --git a/ClassTranscribeServer/Controllers/PlaylistsController.cs b/ClassTranscribeServer/Controllers/PlaylistsController.cs index a66ad31..6ecdffd 100644 --- a/ClassTranscribeServer/Controllers/PlaylistsController.cs +++ b/ClassTranscribeServer/Controllers/PlaylistsController.cs @@ -131,11 +131,18 @@ public async Task>> GetPlaylists2(string o { return Unauthorized(new { Reason = "Insufficient Permission", AccessType = offering.AccessType }); } - var temp = await _context.Playlists + + var playLists = await _context.Playlists .Where(p => p.OfferingId == offeringId) .OrderBy(p => p.Index) .ThenBy(p => p.CreatedAt).ToListAsync(); - var playlists = temp.Select(p => new PlaylistDTO + + var hideRoomVideos = new Dictionary(); + foreach (var p in playLists) { + var restrict = (bool?) p.getOptionsAsJson()[ "restrictRoomStream"] ?? false; + hideRoomVideos.Add(p.Id, restrict); + }; + var playlistDTOs = playLists.Select(p => new PlaylistDTO { Id = p.Id, CreatedAt = p.CreatedAt, @@ -165,7 +172,7 @@ public async Task>> GetPlaylists2(string o { Id = m.Video.Id, Video1Path = m.Video.ProcessedVideo1?.Path != null ? m.Video.ProcessedVideo1.Path : m.Video.Video1?.Path, - Video2Path = m.Video.ProcessedVideo2?.Path != null ? m.Video.ProcessedVideo2.Path : m.Video.Video2?.Path, + Video2Path = hideRoomVideos[p.Id] ? null : ( m.Video.ProcessedVideo2?.Path != null ? m.Video.ProcessedVideo2.Path : m.Video.Video2?.Path), ASLPath = m.Video.ProcessedASLVideo?.Path != null ? m.Video.ProcessedASLVideo.Path : m.Video.ASLVideo?.Path, TaskLog = m.Video.TaskLog }, @@ -182,7 +189,7 @@ public async Task>> GetPlaylists2(string o }).ToList() }).ToList() }).ToList(); - return playlists; + return playlistDTOs; } [HttpGet("SearchForMedia/{offeringId}/{query}")] @@ -233,13 +240,9 @@ public async Task> GetPlaylist(string id) var partialWatchHistories = user !=null ? await _context.WatchHistories.Where(w => w.ApplicationUserId == user.Id && mediaIds.Contains(w.MediaId)).ToListAsync() : null; // In memory transformation into DTO resut - var ignore = new MediaDTO() - { - - }; - - - + var hideRoomVideos = new Dictionary(); + var restrict = (bool?) p.getOptionsAsJson()[ "restrictRoomStream"] ?? false; + List mediasDTO = mediaList.Select(m => new MediaDTO { Id = m.Id, @@ -255,10 +258,10 @@ public async Task> GetPlaylist(string id) SceneDetectReady = m.Video != null && m.Video.HasSceneObjectData(), Ready = m.Video == null ? false : "NoError" == m.Video.TranscriptionStatus , Video = m.Video == null ? null : new VideoDTO - { + { Id = m.Video.Id, - Video1Path = m.Video.Video1?.Path, - Video2Path = m.Video.Video2?.Path, + Video1Path = m.Video.ProcessedVideo1?.Path != null ? m.Video.ProcessedVideo1.Path : m.Video.Video1?.Path, + Video2Path = restrict ? null : ( m.Video.ProcessedVideo2?.Path != null ? m.Video.ProcessedVideo2.Path : m.Video.Video2?.Path), ASLPath = m.Video.ProcessedASLVideo?.Path != null ? m.Video.ProcessedASLVideo.Path : m.Video.ASLVideo?.Path, TaskLog = m.Video.TaskLog }, diff --git a/TaskEngine/Tasks/DownloadMediaTask.cs b/TaskEngine/Tasks/DownloadMediaTask.cs index 0bb27df..616a3d6 100644 --- a/TaskEngine/Tasks/DownloadMediaTask.cs +++ b/TaskEngine/Tasks/DownloadMediaTask.cs @@ -7,6 +7,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using static ClassTranscribeDatabase.CommonUtils; @@ -145,9 +146,23 @@ protected override async Task OnConsume(string mediaId, TaskParameters taskParam public async Task