Пример #1
0
        public IActionResult Index(string id)
        {
            _logger.LogTrace("User Index: {Id}", id);

            id = id.Trim(new[] { ' ', '@' }).ToLowerInvariant();

            // Ensure valid username
            // https://help.twitter.com/en/managing-your-account/twitter-username-rules
            TwitterUser user = null;

            if (!string.IsNullOrWhiteSpace(id) && UserRegexes.TwitterAccount.IsMatch(id) && id.Length <= 15)
            {
                user = _twitterUserService.GetUser(id);
            }

            var acceptHeaders = Request.Headers["Accept"];

            if (acceptHeaders.Any())
            {
                var r = acceptHeaders.First();
                if (r.Contains("application/activity+json"))
                {
                    if (user == null)
                    {
                        return(NotFound());
                    }
                    var apUser     = _userService.GetUser(user);
                    var jsonApUser = JsonConvert.SerializeObject(apUser);
                    return(Content(jsonApUser, "application/activity+json; charset=utf-8"));
                }
            }

            if (user == null)
            {
                return(View("UserNotFound"));
            }

            var displayableUser = new DisplayTwitterUser
            {
                Name            = user.Name,
                Description     = user.Description,
                Acct            = user.Acct.ToLowerInvariant(),
                Url             = user.Url,
                ProfileImageUrl = user.ProfileImageUrl,
                Protected       = user.Protected,

                InstanceHandle = $"@{user.Acct.ToLowerInvariant()}@{_instanceSettings.Domain}"
            };

            return(View(displayableUser));
        }
        public IActionResult Index(string id)
        {
            id = id.Trim(new[] { ' ', '@' }).ToLowerInvariant();
            var user = _twitterUserService.GetUser(id);

            var acceptHeaders = Request.Headers["Accept"];

            if (acceptHeaders.Any())
            {
                var r = acceptHeaders.First();
                if (r.Contains("application/activity+json"))
                {
                    if (user == null)
                    {
                        return(NotFound());
                    }
                    var apUser     = _userService.GetUser(user);
                    var jsonApUser = JsonConvert.SerializeObject(apUser);
                    return(Content(jsonApUser, "application/activity+json; charset=utf-8"));
                }
            }

            if (user == null)
            {
                return(View("UserNotFound"));
            }

            var displayableUser = new DisplayTwitterUser
            {
                Name            = user.Name,
                Description     = user.Description,
                Acct            = user.Acct.ToLowerInvariant(),
                Url             = user.Url,
                ProfileImageUrl = user.ProfileImageUrl,
                Protected       = user.Protected,

                InstanceHandle = $"@{user.Acct.ToLowerInvariant()}@{_instanceSettings.Domain}"
            };

            return(View(displayableUser));
        }