public StatusWithMessage PurgeCacheForUrls([FromBody] PurgeUrlsRequestModel model) { if (!model.Urls.HasAny()) { return(new StatusWithMessage(false, "You must provide urls to clear the cache for.")); } 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 builtUrls = new List <string>(); builtUrls.AddRange(UmbracoFlareUrlHelper.MakeFullUrlsWithDomain(model.Urls, model.CurrentDomain, true)); var urlsWithWildCards = builtUrls.Where(x => x.Contains('*')); var willCardsUrls = !urlsWithWildCards.HasAny() ? builtUrls : _umbracoFlareDomainService.GetAllUrlsForWildCardUrls(urlsWithWildCards); builtUrls.AddRangeUnique(willCardsUrls); var result = _cloudflareService.PurgePages(builtUrls); return(!result.Success ? result : new StatusWithMessage(true, $"{builtUrls.Count()} urls purged successfully.")); }
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.")); }
public StatusWithMessage PurgePages(IEnumerable <string> urls) { if (!urls.HasAny()) { return(new StatusWithMessage(false, "There were not valid urls to purge, please check if the domain is a valid zone in your cloudflare account")); } var currentDomain = UmbracoFlareUrlHelper.GetCurrentDomain(); var websiteZone = _umbracoFlareDomainService.GetZoneFilteredByDomain(currentDomain); if (websiteZone == null) { return(new StatusWithMessage(false, $"Could not retrieve the zone from cloudflare with the domain of {currentDomain}")); } var apiResult = _cloudflareApiClient.PurgeCache(websiteZone.Id, urls, false); return(apiResult ? new StatusWithMessage(true, "The values were purged successfully") : new StatusWithMessage(false, "There was an error from the Cloudflare API. Please check the logs to see the issue.")); }
public IEnumerable <string> GetUrlsForNode(int contentId, string currentDomain, bool includeDescendants = false) { var content = _umbracoHelperWrapper.TypedContent(contentId); var urls = new List <string>(); if (!content.HasValue()) { return(urls); } if (includeDescendants) { urls.AddRange(content.DescendantsOrSelf().Select( descendantContent => UmbracoFlareUrlHelper.MakeFullUrlWithDomain(descendantContent.Url, currentDomain, true)) ); } else { urls.Add(UmbracoFlareUrlHelper.MakeFullUrlWithDomain(content.Url, currentDomain, true)); } return(urls); }