コード例 #1
0
        public async Task <IActionResult> Create([FromBody] SubscriptionFolderCreateRequest request)
        {
            var user = await userManager.GetUserAsync(User);

            subscriptionManager.CreateFolder(user, request.Name, request.ParentId);
            return(Ok(responseFactory.Success()));
        }
コード例 #2
0
        public async Task <IActionResult> ServerStatus()
        {
            var users = await userManager.GetUsersInRoleAsync(UserRoles.User);

            var admins = await userManager.GetUsersInRoleAsync(UserRoles.Admin);

            return(Ok(responseFactory.Success(new ServerStatusResponse()
            {
                Initialized = optionManager.GetGlobal(Options.Server_Initialized),
                HaveUsers = users.Count > 0,
                HaveAdmin = admins.Count > 0
            })));
        }
コード例 #3
0
        public async Task <IActionResult> Login([FromBody] UserLoginRequest login)
        {
            var user = await userManager.FindByNameAsync(login.Username);

            if (user != null && await userManager.CheckPasswordAsync(user, login.Password))
            {
                JwtSecurityToken token = await GenerateAuthToken(user, login.RememberMe);

                return(Ok(responseFactory.Success(new AuthResponse()
                {
                    Token = new JwtSecurityTokenHandler().WriteToken(token),
                    ValidTo = token.ValidTo
                })));
            }

            return(Unauthorized(responseFactory.Error("Invalid username or password.")));
        }
コード例 #4
0
        public async Task <IActionResult> Validate([FromBody] SubscriptionValidateRequest request)
        {
            try
            {
                string provider = null;

                if (request.Url != null)
                {
                    var url = new Uri(request.Url);
                    provider = await subscriptionManager.TestUrl(url);
                }

                if (request.Name != null)
                {
                    subscriptionManager.ValidateName(request.Name, request.ParentFolderId);
                }

                return(Ok(responseFactory.Success(new SubscriptionValidateResponse()
                {
                    ProviderName = provider,
                })));
            }
            catch (UriFormatException)
            {
                return(BadRequest(responseFactory.Error("Invalid URL format!")));
            }
            catch (ArgumentNullException)
            {
                return(BadRequest(responseFactory.Error("Missing URL argument!")));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(responseFactory.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                return(BadRequest(responseFactory.Error(ex.Message, ex.Message + "\n" + ex.StackTrace)));
            }
        }
コード例 #5
0
ファイル: VideoController.cs プロジェクト: cyberjacob/regard
        public async Task <IActionResult> List([FromBody] VideoListRequest request)
        {
            var user = await userManager.GetUserAsync(User);

            var query = videoManager.GetAll(user);

            // Apply filters
            if (request.Ids != null)
            {
                query = query.Where(x => request.Ids.Contains(x.Id));
            }

            if (request.SubscriptionId != null)
            {
                query = query.Where(x => x.SubscriptionId == request.SubscriptionId.Value);
            }

            if (request.SubscriptionFolderId != null)
            {
                var sub = subscriptionManager.GetFolder(user, request.SubscriptionFolderId.Value);
                if (sub == null)
                {
                    return(BadRequest(responseFactory.Error("Invalid subscription folder ID.")));
                }

                var validSubscriptionIds = subscriptionManager.GetSubscriptionsRecursive(sub).Select(x => x.Id).ToArray();
                query = query.Where(x => validSubscriptionIds.Contains(x.SubscriptionId));
            }

            if (request.IsWatched.HasValue)
            {
                query = query.Where(x => x.IsWatched == request.IsWatched.Value);
            }

            if (request.IsDownloaded.HasValue)
            {
                if (request.IsDownloaded.Value)
                {
                    query = query.Where(x => x.DownloadedPath != null);
                }
                else
                {
                    query = query.Where(x => x.DownloadedPath == null);
                }
            }

            // TODO: proper search
            if (request.Query != null)
            {
                query = query.Where(x => x.Name.ToLower().Contains(request.Query.ToLower()));
            }

            // Get the item count here, before applying the limit and offset
            int itemCount = query.Count();

            // Sorting, limit and offset
            query = query.OrderBy(request.Order)
                    .Skip(request.Offset ?? 0)
                    .Take(request.Limit ?? 50);

            // Obtain mime types
            var videos    = query.ToArray();
            var apiVideos = new List <ApiVideo>();

            foreach (var video in videos)
            {
                var apiVideo = modelFactory.ToApi(video);
                apiVideo.StreamMimeType = await videoStorage.GetMimeType(video);

                apiVideos.Add(apiVideo);
            }

            return(Ok(responseFactory.Success(new VideoListResponse
            {
                TotalCount = itemCount,
                Videos = apiVideos.ToArray(),
            })));
        }