Esempio n. 1
0
        public IActionResult Create([FromBody] Report report)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (report.ExpiresAt == default(DateTime))
            {
                report.ExpiresAt = DateTime.UtcNow.AddDays(30);
            }

            report.ID        = idGenerator.GetNewId();
            report.AppName   = report.AppName.Trim();
            report.AppURL    = report.AppURL?.Trim();
            report.CreatedAt = DateTime.UtcNow;

            foreach (var fields in report.Fields)
            {
                foreach (var field in fields)
                {
                    FormatField(field);
                }
            }

            reportStore.Save(report);

            var protocol = "http";

            if (configAccessor.Value.TlsSupported)
            {
                protocol += "s";
            }

            return(Json(new
            {
#if RELEASE
                ReportURL = $"{protocol}://{configAccessor.Value.FQD}/r/{report.ID}"
#else
                ReportURL = $"{protocol}://{Request.Host}/r/{report.ID}"
#endif
            }));
Esempio n. 2
0
        public Task Invoke(HttpContext context, IReportStore reports)
        {
            var req       = context.Request;
            var pathSplit = req.Path.ToString().Split("/");

            if (req.Method == "GET" && reportBasePaths.Contains(pathSplit[1]))
            {
                Task.Run(() =>
                {
                    var id = pathSplit[2];
                    var r  = reports.Get(id);

                    r.Views++;

                    reports.Save(r);
                });
            }

            return(nextMiddleware(context));
        }