public ActionResult GetItem(string fileId)
        {
            try
            {
                GetFileResponse payload = _indexService.GetFile(fileId);
                if (payload == null)
                {
                    return(Responses.NotFoundError(this, $"file {fileId} not found. Id is invalid, or has been deleted."));
                }

                if (payload.Content == null)
                {
                    throw new Exception($"File {fileId} has no content.");
                }

                return(File(payload.Content, "application/octet-stream", payload.FileName));
            }
            catch (InvalidFileIdentifierException)
            {
                return(Responses.InvalidFileId());
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "An unexpected error occurred.");
                return(Responses.UnexpectedError());
            }
        }
        public ActionResult GetArchive(string packageId)
        {
            Stream archiveStream = null;

            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                _indexService.PurgeOldArchives();
                archiveStream = _indexService.GetPackageAsArchive(packageId);

                sw.Stop();
                _log.LogInformation($"Archive generation for package {packageId} took {0} seconds", sw.Elapsed.TotalSeconds);

                return(File(archiveStream, "application/octet-stream", $"{packageId}.zip"));
            }
            catch (PackageNotFoundException)
            {
                return(Responses.NotFoundError(this, $"Package ${packageId} not found."));
            }
            catch (Exception ex)
            {
                if (archiveStream != null)
                {
                    archiveStream.Close();
                }

                _log.LogError(ex, "Unexpected error");
                return(Responses.UnexpectedError());
            }
        }
Exemple #3
0
        public ActionResult DeletePackage(string packageId)
        {
            try
            {
                _indexService.DeletePackage(packageId);
                _packageListCache.Clear();

                return(new JsonResult(new
                {
                    success = new
                    {
                        description = "Package deleted"
                    }
                }));
            }
            catch (PackageNotFoundException)
            {
                return(Responses.NotFoundError(this, $"Package "));
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "An unexpected error occurred.");
                return(Responses.UnexpectedError());
            }
        }
Exemple #4
0
        public ActionResult AddTag(string tag, string packageId)
        {
            try
            {
                tag = HttpUtility.UrlDecode(tag);
                _tagsService.AddTag(packageId, tag);

                return(new JsonResult(new
                {
                    success = new
                    {
                        description = $"Tag {tag} was added to package {packageId}"
                    }
                }));
            }
            catch (PackageNotFoundException)
            {
                return(Responses.NotFoundError(this, $"Package ${packageId} not found."));
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "An unexpected error occurred.");
                return(Responses.UnexpectedError());
            }
        }
        public ActionResult GetArchiveStatus(string packageId)
        {
            try
            {
                _indexService.PurgeOldArchives();

                return(new JsonResult(new
                {
                    success = new
                    {
                        status = _indexService.GetPackageArchiveStatus(packageId)
                    }
                }));
            }
            catch (PackageNotFoundException)
            {
                return(Responses.NotFoundError(this, $"Package ${packageId} not found."));
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "Unexpected error");
                return(Responses.UnexpectedError());
            }
        }
Exemple #6
0
        public ActionResult GetPackage(string packageId)
        {
            try
            {
                Manifest manifest = _indexService.GetManifest(packageId);
                if (manifest == null)
                {
                    return(Responses.NotFoundError(this, $"Package ${packageId} does not exist"));
                }

                return(new JsonResult(new
                {
                    success = new
                    {
                        package = manifest
                    }
                }));
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "An unexpected error occurred.");
                return(Responses.UnexpectedError());
            }
        }