예제 #1
0
        public async Task <IActionResult> Create([FromBody] SubscriptionCreateRequest request)
        {
            try
            {
                var url  = new Uri(request.Url);
                var user = await userManager.GetUserAsync(User);

                var result = await subscriptionManager.Create(user, url, request.ParentFolderId);

                return(Ok(responseFactory.Success(modelFactory.ToApi(result))));
            }
            catch (UriFormatException)
            {
                return(BadRequest(responseFactory.Error("Invalid URL format!")));
            }
        }
예제 #2
0
        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(),
            })));
        }