Esempio n. 1
0
        public StatusWithMessage PurgeStaticFiles([FromBody] PurgeStaticFilesRequestModel model)
        {
            if (!model.StaticFiles.HasAny())
            {
                return(new StatusWithMessage(false, "There were not static files selected to purge"));
            }

            var currentDomainIsValid = _umbracoFlareDomainService.GetAllowedCloudflareDomains().Count(x => x.Equals(model.CurrentDomain)) > 0;

            if (!currentDomainIsValid)
            {
                return(new StatusWithMessage(false, "The current domain is not valid, please check if the domain is a valid zone in your cloudflare account."));
            }

            var fullUrlsToPurge = new List <string>();
            var allFilePaths    = _cloudflareService.GetFilePaths(model.StaticFiles);

            foreach (var filePath in allFilePaths)
            {
                var extension = Path.GetExtension(filePath);

                if (ApplicationConstants.AllowedFileExtensions.Contains(extension))
                {
                    var urls = UmbracoFlareUrlHelper.GetFullUrlForPurgeStaticFiles(filePath, model.CurrentDomain, true);
                    fullUrlsToPurge.AddRange(urls);
                }
            }

            var result = _cloudflareService.PurgePages(fullUrlsToPurge);

            return(!result.Success ? result : new StatusWithMessage(true, $"{fullUrlsToPurge.Count()} static files were purged successfully."));
        }