public async Task <IActionResult> UploadVideo( [FromForm] string author, [FromForm] string name, [FromForm] string description, [FromForm] string tags, [FromForm] int nsfw, IFormFile video ) { if (video != null) { string id = GenericHelpers.GenerateId(); string extension = Path.GetExtension(video.FileName); string fileName = $"{id}{extension}"; using (var fileStream = new FileStream(Path.Combine(VideosConstants.VIDEOS_PATH, fileName), FileMode.Create)) { await video.CopyToAsync(fileStream); } //Grabs thumbnail from video using (var engine = new Engine()) { var mediaVideoFile = new MediaFile { Filename = Path.Combine(VideosConstants.VIDEOS_PATH, fileName) }; var mediaThumbFile = new MediaFile { Filename = Path.Combine(VideosConstants.THUMBS_PATH, $"{id}.jpg") }; engine.GetMetadata(mediaVideoFile); var options = new ConversionOptions { Seek = TimeSpan.FromSeconds(0) }; engine.GetThumbnail(mediaVideoFile, mediaThumbFile, options); } _context.Videos.Add(new Video { Id = id, Author = author, VideoFile = fileName, Name = name, Extension = extension, Description = description, UploadDate = DateTime.Now, Thumbnail = $"{id}.jpg", Tags = tags, Nsfw = nsfw == 0 ? false : true, }); _context.SaveChanges(); return(Ok()); } return(BadRequest()); }
public UserResponse CreateNew(string username, string password) { if (_context.Users.FirstOrDefault(x => x.Name == username) != null) { return(null); } var newUser = new User { Id = GenericHelpers.GenerateId(), Name = username, PasswordHash = ComputeSha256Hash(password), Role = "user" }; _context.Users.Add(newUser); _context.SaveChanges(); return(new UserResponse(newUser, GenerateToken(newUser))); }