コード例 #1
0
        public ObjectResult List()
        {
            var list = repository.FindAllUnarchived().ToList();

            logger.LogInformation($"Listing {list.Count} items");
            return(Ok(list));
        }
コード例 #2
0
        public ObjectResult TorrentDone([FromServices] IControllerHelperService helper, string hash)
        {
            logger.LogInformation("TorrentDone: " + hash);
            if (!helper.IsLocalCall(HttpContext))
            {
                logger.LogWarning("Request not sent from the server");
                return(StatusCode(403, null));
            }

            var item = repository.FindAllUnarchived().FirstOrDefault(x => x.Hash == hash);

            if (item == null)
            {
                logger.LogInformation(hash + ": note found");
                return(StatusCode(404, DownloadItemActionError.ItemNotFound));
            }

            var authorizationResult = authorizationService.AuthorizeAsync(User, item, DownloadItemPolicies.TorrentDonePolicy).Result;

            if (!authorizationResult.Succeeded)
            {
                var requirement = authorizationResult.Failure.FailedRequirements.First() as DownloadItemBaseRequirement;
                return(StatusCode(requirement.HttpCode, requirement.Error));
            }

            torrentDaemonService.StopTorrent(hash);
            _ = dispatcher.Broadcast(new ItemDownloaded(item.Id));

            return(StatusCode(200, new { Processed = true }));
        }