public IActionResult OnPrismicPublish(PrismicWebhookDto dto) { if (string.IsNullOrEmpty(_prismicWebhookSecretKey)) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } if (ModelState.IsValid) { if (_prismicWebhookSecretKey.Equals(dto.Secret, StringComparison.Ordinal)) { if (!string.IsNullOrEmpty(dto.MasterRef)) { _cacheProvider.SetMasterRef(new PrismicRef() { Id = "master", Ref = dto.MasterRef, Label = "Master", IsMasterRef = true }); } else { _cacheProvider.ClearMasterRef(); } return(Ok()); } return(Unauthorized()); } return(BadRequest()); }
public async Task <PrismicRef> GetMasterRef() { var cachedRef = _prismicCacheProvider.GetMasterRef(); if (cachedRef != null) { return(cachedRef); } _logger.LogInformation("Querying for master ref"); var response = await _httpClient.GetAsync(_prismicApiUrl); if (response.IsSuccessStatusCode) { var resultDto = JsonConvert.DeserializeObject <PrismicRefDto>(await response.Content.ReadAsStringAsync()); var masterRef = resultDto?.Refs?.SingleOrDefault(x => x.IsMasterRef); _prismicCacheProvider.SetMasterRef(masterRef); return(masterRef); } return(null); }