Esempio n. 1
0
        public async Task <IActionResult> Index()
        {
            var log = new Log();

            log.HostName  = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
            log.When      = DateTime.Now;
            log.LogText   = "Status endpoint hit";
            log.IpAddress = log.HostName;
            _context.Logs.Add(log);
            _context.SaveChanges();

            _logger.LogInformation("Status being requested");

            var config = new ConfigurationBuilder().AddEnvironmentVariables().Build();

            if (String.IsNullOrEmpty(config["SECRET_PASSWORD"]))
            {
                return(new BadRequestResult());
            }

            var settings = _context.Settings.FirstOrDefault();

            if (settings == null)
            {
                var newSettings = new Settings()
                {
                    MessageOfTheDay = "Ultima DMR wita!",
                    RelativeUoUri   = "uo.zip",
                    UoSizeInKb      = 800000
                };
                _context.Settings.Add(newSettings);
                await _context.SaveChangesAsync();

                settings = newSettings;
            }

            var responseMessage = new UpdatePayload()
            {
                FullUltimaOnlineDownloadPath       = $"{config["URL_BASE"]}/api/download/uo",
                FullUltimaOnlineDownloadWeightInKb = settings.UoSizeInKb,
                MessageOfTheDay = settings.MessageOfTheDay
            };

            var files = _context.UpdateFiles.Select(p => new UpdateFileInfo()
            {
                AssociatedMessage = p.AssociatedMessage, Name = p.Name, Revision = p.Revision, SizeInKb = p.SizeInKb,
                RequiresUnzip     = p.RequiresUnzip, Uri = UrlHelper.GetFullUrl(p.RelativeUri, p.Revision), TargetName = p.TargetName
            });

            responseMessage.UpdateFiles = files.ToList();
            return(new JsonResult(responseMessage));
        }
Esempio n. 2
0
        public IActionResult DownloadUltima()
        {
            var log = new Log();

            log.HostName  = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
            log.When      = DateTime.Now;
            log.LogText   = "Full ultima download endpoint hit";
            log.IpAddress = log.HostName;
            _context.Logs.Add(log);
            _context.SaveChanges();

            _logger.LogInformation("Ultima full download being requested");

            var uo = Path.Combine(Constants.DataDirectory, "uo.zip");

            if (!System.IO.File.Exists(uo))
            {
                return(BadRequest("No Ultima Online found!"));
            }

            var fileContents = new FileStream(uo, FileMode.Open);

            return(File(fileContents, "application/octet-stream"));
        }