public object Get() { string staticContentUuid = Context.Request.Query[Defines.IDENTIFIER]; if (string.IsNullOrEmpty(staticContentUuid)) { return(NotFound()); } StaticContentId id = new StaticContentId(staticContentUuid); Site site = id.SiteId == null ? null : SiteHelper.GetSite(id.SiteId.Value); List <MimeMap> mappings = MimeMapHelper.GetMimeMaps(site, id.Path); // Set HTTP header for total count this.Context.Response.SetItemsCount(mappings.Count()); Fields fields = Context.Request.GetFields(); return(new { mime_maps = mappings.Select(m => MimeMapHelper.ToJsonModelRef(m, site, id.Path, fields)) }); }
public object Get(string id) { StaticContentId staticContentId = new StaticContentId(id); Site site = staticContentId.SiteId == null ? null : SiteHelper.GetSite(staticContentId.SiteId.Value); if (staticContentId.SiteId != null && site == null) { return(NotFound()); } return(StaticContentHelper.ToJsonModel(site, staticContentId.Path)); }
public static object ToJsonModelRef(Site site, string path) { var section = GetSection(site, path); StaticContentId id = new StaticContentId(site?.Id, path, section.IsLocallyStored); var obj = new { id = id.Uuid, scope = site == null ? string.Empty : site.Name + path }; return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj, false)); }
public void Delete(string id) { StaticContentId staticContentId = new StaticContentId(id); Context.Response.StatusCode = (int)HttpStatusCode.NoContent; Site site = (staticContentId.SiteId != null) ? SiteHelper.GetSite(staticContentId.SiteId.Value) : null; if (site == null) { return; } StaticContentSection section = StaticContentHelper.GetSection(site, staticContentId.Path, ManagementUnit.ResolveConfigScope()); section.RevertToParent(); ManagementUnit.Current.Commit(); }
internal static object ToJsonModel(Site site, string path) { var section = GetSection(site, path); StaticContentId id = new StaticContentId(site?.Id, path, section.IsLocallyStored); var obj = new { id = id.Uuid, scope = site == null ? string.Empty : site.Name + path, metadata = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective), client_cache = CacheToJsonModel(section.ClientCache), default_doc_footer = section.DefaultDocFooter, is_doc_footer_file_name = section.IsDocFooterFileName, enable_doc_footer = section.EnableDocFooter, website = SiteHelper.ToJsonModelRef(site) }; return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj)); }
public object Post([FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } if (model.static_content == null) { throw new ApiArgumentException("static_content"); } if (!(model.static_content is JObject)) { throw new ApiArgumentException("static_content"); } string staticContentUuid = DynamicHelper.Value(model.static_content.id); if (staticContentUuid == null) { throw new ApiArgumentException("static_content.id"); } // Get the feature id StaticContentId staticContentId = new StaticContentId(staticContentUuid); Site site = staticContentId.SiteId == null ? null : SiteHelper.GetSite(staticContentId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); StaticContentSection section = StaticContentHelper.GetSection(site, staticContentId.Path, configPath); // Create mime map MimeMap mimeMap = MimeMapHelper.CreateMimeMap(model, section); // Add it to the config file MimeMapHelper.AddMimeMap(mimeMap, section); // Save changes ManagementUnit.Current.Commit(); // Show new mime map return(MimeMapHelper.ToJsonModel(mimeMap, site, staticContentId.Path)); }
public async Task Delete(string id) { StaticContentId staticContentId = new StaticContentId(id); Context.Response.StatusCode = (int)HttpStatusCode.NoContent; Site site = (staticContentId.SiteId != null) ? SiteHelper.GetSite(staticContentId.SiteId.Value) : null; if (site != null) { StaticContentSection section = StaticContentHelper.GetSection(site, staticContentId.Path, ManagementUnit.ResolveConfigScope()); section.RevertToParent(); ManagementUnit.Current.Commit(); } if (staticContentId.SiteId == null && StaticContentHelper.IsFeatureEnabled()) { await StaticContentHelper.SetFeatureEnabled(false); } }
public object Patch(string id, [FromBody] dynamic model) { StaticContentId staticContentId = new StaticContentId(id); Site site = staticContentId.SiteId == null ? null : SiteHelper.GetSite(staticContentId.SiteId.Value); if (staticContentId.SiteId != null && site == null) { return(NotFound()); } // Check for config_scope string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);; StaticContentSection section = StaticContentHelper.GetSection(site, staticContentId.Path, configPath); StaticContentHelper.UpdateFeatureSettings(model, section); ManagementUnit.Current.Commit(); return(StaticContentHelper.ToJsonModel(site, staticContentId.Path)); }