public IActionResult getVideoLink(ControlPanelForLoginDto controlPanelForLogin) { if (controlPanelForLogin.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } string url = $"{_rtmpPlaybackHost}/live/stream_{controlPanelForLogin.UserId}_{controlPanelForLogin.ItemId}.flv"; return(Ok(url)); }
public async Task <IActionResult> executeCommand(ControlPanelForLoginDto controlPanelForLogin) { PrivateKeyFile privateKeyFile; if (controlPanelForLogin.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } User user = await _repo.GetUser(controlPanelForLogin.UserId); try { var stream = await _cloudStorage.downloadStreamFromBlobContainer(user.SshBlobName); privateKeyFile = new PrivateKeyFile(stream); } catch (Exception ex) { return(BadRequest(ex.Message)); } using (var client = new SshClient(user.RaspHost, user.RaspUsername, privateKeyFile)) { try { var commandText = await this._getCommandAsync(controlPanelForLogin.CommandType, controlPanelForLogin.ItemId, controlPanelForLogin.UserId); if (String.IsNullOrEmpty(commandText)) { return(Ok("Missing script.")); } client.Connect(); SshCommand command = client.CreateCommand(commandText); this._executeCommand(controlPanelForLogin.CommandType, command); var result = command.Result + command.Error; if (String.IsNullOrEmpty(result) && controlPanelForLogin.IsRequireScript) { return(Ok("Missing message. Add print() to script item.")); } return(Ok(command.Result + command.Error)); } catch (SocketException ex) { return(BadRequest(ex.Message)); } } }