Example #1
0
        public async Task <ActionResult> PostAsync()
        {
            // get raw log text
            string input = this.Request.Form["input"].FirstOrDefault();

            if (string.IsNullOrWhiteSpace(input))
            {
                return(this.View("Index", this.GetModel(null, uploadError: "The log file seems to be empty.")));
            }

            // upload log
            input = this.GzipHelper.CompressString(input);
            SavePasteResult result = await this.Pastebin.PostAsync($"SMAPI log {DateTime.UtcNow:s}", input);

            // handle errors
            if (!result.Success)
            {
                return(this.View("Index", this.GetModel(result.ID, uploadError: $"Pastebin error: {result.Error ?? "unknown error"}")));
            }

            // redirect to view
            UriBuilder uri = new UriBuilder(new Uri(this.Config.LogParserUrl));

            uri.Path = uri.Path.TrimEnd('/') + '/' + result.ID;
            return(this.Redirect(uri.Uri.ToString()));
        }
Example #2
0
        public async Task <ActionResult> PostAsync(JsonValidatorRequestModel request)
        {
            if (request == null)
            {
                return(this.View("Index", new JsonValidatorModel(this.SectionUrl, null, null, this.SchemaFormats).SetUploadError("The request seems to be invalid.")));
            }

            // normalize schema name
            string schemaName = this.NormalizeSchemaName(request.SchemaName);

            // get raw log text
            string input = request.Content;

            if (string.IsNullOrWhiteSpace(input))
            {
                return(this.View("Index", new JsonValidatorModel(this.SectionUrl, null, schemaName, this.SchemaFormats).SetUploadError("The JSON file seems to be empty.")));
            }

            // upload log
            input = this.GzipHelper.CompressString(input);
            SavePasteResult result = await this.Pastebin.PostAsync($"JSON validator {DateTime.UtcNow:s}", input);

            // handle errors
            if (!result.Success)
            {
                return(this.View("Index", new JsonValidatorModel(this.SectionUrl, result.ID, schemaName, this.SchemaFormats).SetUploadError($"Pastebin error: {result.Error ?? "unknown error"}")));
            }

            // redirect to view
            UriBuilder uri = new UriBuilder(new Uri(this.SectionUrl));

            uri.Path = $"{uri.Path.TrimEnd('/')}/{schemaName}/{result.ID}";
            return(this.Redirect(uri.Uri.ToString()));
        }