diff options
Diffstat (limited to 'cmnext-cli/src/Model')
-rw-r--r-- | cmnext-cli/src/Model/CMNextStoreExtensions.cs | 31 | ||||
-rw-r--r-- | cmnext-cli/src/Model/Channels/ChannelFeed.cs | 46 | ||||
-rw-r--r-- | cmnext-cli/src/Model/Channels/ChannelMeta.cs | 52 | ||||
-rw-r--r-- | cmnext-cli/src/Model/Channels/ChannelStore.cs | 95 | ||||
-rw-r--r-- | cmnext-cli/src/Model/Content/ContentMeta.cs | 46 | ||||
-rw-r--r-- | cmnext-cli/src/Model/ICMNextEntity.cs | 29 | ||||
-rw-r--r-- | cmnext-cli/src/Model/ICMNextIndex.cs | 31 | ||||
-rw-r--r-- | cmnext-cli/src/Model/ICMNextStore.cs | 39 | ||||
-rw-r--r-- | cmnext-cli/src/Model/Posts/PostMeta.cs | 106 |
9 files changed, 475 insertions, 0 deletions
diff --git a/cmnext-cli/src/Model/CMNextStoreExtensions.cs b/cmnext-cli/src/Model/CMNextStoreExtensions.cs new file mode 100644 index 0000000..482afc4 --- /dev/null +++ b/cmnext-cli/src/Model/CMNextStoreExtensions.cs @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +using System.Threading; +using System.Threading.Tasks; + + +namespace CMNext.Cli.Model +{ + internal static class CMNextStoreExtensions + { + + } +}
\ No newline at end of file diff --git a/cmnext-cli/src/Model/Channels/ChannelFeed.cs b/cmnext-cli/src/Model/Channels/ChannelFeed.cs new file mode 100644 index 0000000..da1f2f4 --- /dev/null +++ b/cmnext-cli/src/Model/Channels/ChannelFeed.cs @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +using System.Text.Json.Serialization; + + +namespace CMNext.Cli.Model.Channels +{ + public sealed class ChannelFeed + { + [JsonPropertyName("url")] + public string Url { get; set; } = string.Empty; + + [JsonPropertyName("path")] + public string Path { get; set; } = string.Empty; + + [JsonPropertyName("image")] + public string? ImagePath { get; set; } + + [JsonPropertyName("description")] + public string? Description { get; set; } + + [JsonPropertyName("author")] + public string? Author { get; set; } + + [JsonPropertyName("contact")] + public string? Contact { get; set; } + } +}
\ No newline at end of file diff --git a/cmnext-cli/src/Model/Channels/ChannelMeta.cs b/cmnext-cli/src/Model/Channels/ChannelMeta.cs new file mode 100644 index 0000000..d0e626d --- /dev/null +++ b/cmnext-cli/src/Model/Channels/ChannelMeta.cs @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +using System; + +using System.Text.Json.Serialization; + + +namespace CMNext.Cli.Model.Channels +{ + + public sealed class ChannelMeta : INamedEntity + { + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("date")] + public long Date { get; set; } + + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + [JsonPropertyName("path")] + public string Path { get; set; } = string.Empty; + + [JsonPropertyName("index")] + public string IndexFileName { get; set; } = string.Empty; + + [JsonPropertyName("content")] + public string ContentDir { get; set; } = string.Empty; + + [JsonPropertyName("feed")] + public ChannelFeed? Feed { get; set; } + } +}
\ No newline at end of file diff --git a/cmnext-cli/src/Model/Channels/ChannelStore.cs b/cmnext-cli/src/Model/Channels/ChannelStore.cs new file mode 100644 index 0000000..5d930fa --- /dev/null +++ b/cmnext-cli/src/Model/Channels/ChannelStore.cs @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +using System.Threading; +using System.Threading.Tasks; +using System.Text.Json.Serialization; + +using CMNext.Cli.Site; + +using VNLib.Net.Rest.Client.Construction; +using System.Linq; + + +namespace CMNext.Cli.Model.Channels +{ + public sealed class ChannelStore(SiteManager site) : ICMNextStore<ChannelMeta> + { + + ///<inheritdoc/> + public async Task CreateAsync(ChannelMeta entity, CancellationToken cancellation) + { + CMNextSiteAdapter cmSite = await site.GetAdapterAsync(); + + await cmSite.BeginRequest(new CreateChannelRequest(entity)) + .ExecAsync(cancellation); + } + + ///<inheritdoc/> + public async Task<ChannelMeta?> GetAsync(string id, CancellationToken cancellation) + { + ChannelMeta[] all = await ListAsync(cancellation); + return all.FirstOrDefault(c => c.Id == id); + } + + ///<inheritdoc/> + public async Task<ChannelMeta[]> ListAsync(CancellationToken cancellation) + { + CMNextSiteAdapter cmSite = await site.GetAdapterAsync(); + + ChannelMeta[]? index = await cmSite + .BeginRequest(new ListChannelRequest()) + .ExecAsync(cancellation) + .AsJson<ChannelMeta[]>(); + + return index ?? []; + } + + ///<inheritdoc/> + public async Task DeleteAsync(string id, CancellationToken cancellation) + { + CMNextSiteAdapter cmSite = await site.GetAdapterAsync(); + + await cmSite.BeginRequest(new DeleteChannelRequest(id)) + .ExecAsync(cancellation); + } + + ///<inheritdoc/> + public async Task UpdateAsync(ChannelMeta entity, CancellationToken cancellation) + { + CMNextSiteAdapter cmSite = await site.GetAdapterAsync(); + + await cmSite.BeginRequest(new SetChannelRequest(entity)) + .ExecAsync(cancellation); + } + + private sealed class ChannelIndex : ICMNextIndex<ChannelMeta> + { + [JsonPropertyName("date")] + public long Date { get; set; } + + [JsonPropertyName("records")] + public ChannelMeta[] Records { get; set; } = []; + + [JsonPropertyName("version")] + public string Version { get; set; } = "0.0.0"; + } + } +}
\ No newline at end of file diff --git a/cmnext-cli/src/Model/Content/ContentMeta.cs b/cmnext-cli/src/Model/Content/ContentMeta.cs new file mode 100644 index 0000000..ff25da3 --- /dev/null +++ b/cmnext-cli/src/Model/Content/ContentMeta.cs @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +using System.Text.Json.Serialization; + + +namespace CMNext.Cli.Model.Content +{ + internal class ContentMeta : ICMNextEntity + { + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("date")] + public long Date { get; set; } + + [JsonPropertyName("path")] + public string Path { get; set; } = string.Empty; + + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + [JsonPropertyName("content_type")] + public string ContentType { get; set; } = string.Empty; + + [JsonPropertyName("length")] + public long Length { get; set; } + } +}
\ No newline at end of file diff --git a/cmnext-cli/src/Model/ICMNextEntity.cs b/cmnext-cli/src/Model/ICMNextEntity.cs new file mode 100644 index 0000000..1611451 --- /dev/null +++ b/cmnext-cli/src/Model/ICMNextEntity.cs @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +namespace CMNext.Cli.Model +{ + public interface ICMNextEntity + { + string Id { get; } + + long Date { get; } + } +}
\ No newline at end of file diff --git a/cmnext-cli/src/Model/ICMNextIndex.cs b/cmnext-cli/src/Model/ICMNextIndex.cs new file mode 100644 index 0000000..c25fc7c --- /dev/null +++ b/cmnext-cli/src/Model/ICMNextIndex.cs @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +namespace CMNext.Cli.Model +{ + public interface ICMNextIndex<T> where T : ICMNextEntity + { + long Date { get; } + + T[] Records { get; } + + string Version { get; } + } +}
\ No newline at end of file diff --git a/cmnext-cli/src/Model/ICMNextStore.cs b/cmnext-cli/src/Model/ICMNextStore.cs new file mode 100644 index 0000000..9cf3163 --- /dev/null +++ b/cmnext-cli/src/Model/ICMNextStore.cs @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +using System.Threading; +using System.Threading.Tasks; + + +namespace CMNext.Cli.Model +{ + public interface ICMNextStore<T> where T : ICMNextEntity + { + Task<T[]> ListAsync(CancellationToken cancellation); + + Task<T?> GetAsync(string id, CancellationToken cancellation); + + Task DeleteAsync(string id, CancellationToken cancellation); + + Task CreateAsync(T entity, CancellationToken cancellation); + + Task UpdateAsync(T entity, CancellationToken cancellation); + } +}
\ No newline at end of file diff --git a/cmnext-cli/src/Model/Posts/PostMeta.cs b/cmnext-cli/src/Model/Posts/PostMeta.cs new file mode 100644 index 0000000..ce8c0a2 --- /dev/null +++ b/cmnext-cli/src/Model/Posts/PostMeta.cs @@ -0,0 +1,106 @@ +/* +* Copyright (c) 2024 Vaughn Nugent +* +* Package: CMNext.Cli +* File: Program.cs +* +* CMNext.Cli is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published +* by the Free Software Foundation, either version 2 of the License, +* or (at your option) any later version. +* +* CMNext.Cli is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CMNext.Cli. If not, see http://www.gnu.org/licenses/. +*/ + +using CMNext.Cli.Site; + +using System; + +using System.Text.Json.Serialization; +using System.Threading; +using System.Threading.Tasks; + +using VNLib.Net.Rest.Client.Construction; + + +namespace CMNext.Cli.Model.Posts +{ + public sealed class PostStore(CMNextSiteAdapter Site, string ChannelId) : ICMNextStore<PostMeta> + { + public async Task DeleteAsync(string id, CancellationToken cancellation) + { + await Site.BeginRequest(new DeletePostMetaRequest(ChannelId, id)) + .ExecAsync(cancellation); + } + + public Task CreateAsync(PostMeta entity, CancellationToken cancellation) + { + return Site.BeginRequest(new CreatePostMetaRequest(ChannelId, entity)) + .ExecAsync(cancellation); + } + + public Task<PostMeta?> GetAsync(string id, CancellationToken cancellation) + { + return Site.BeginRequest(new GetPostMetaRequest(ChannelId, id)) + .ExecAsync(cancellation) + .AsJson<PostMeta>()!; + } + + public async Task<PostMeta[]> ListAsync(CancellationToken cancellation) + { + PostMeta[]? index = await Site + .BeginRequest(new ListPostMetaRequest(ChannelId)) + .ExecAsync(cancellation) + .AsJson<PostMeta[]>(); + + //As long as the server is real, this should error or return a valid index. + return index ?? []; + } + + public Task UpdateAsync(PostMeta entity, CancellationToken cancellation) + { + return Site.BeginRequest(new SetPostMetaRequest(ChannelId, entity)) + .ExecAsync(cancellation); + } + } + + public class PostMeta : ICMNextEntity + { + [JsonPropertyName("id")] + public string Id { get; } + + [JsonPropertyName("date")] + public long Date { get; } + + [JsonPropertyName("created")] + public long Created { get; } + + [JsonPropertyName("title")] + public string? Title { get; set; } + + [JsonPropertyName("summary")] + public string? Description { get; set; } + + [JsonPropertyName("tags")] + public string[]? Tags { get; set; } + + [JsonPropertyName("image")] + public string? Image { get; set; } + + [JsonPropertyName("html_description")] + public string? HtmlDescription { get; set; } + + /// <summary> + /// Gets a value that an existing post is in podcast mode, and + /// stores a copy of the post's HTML description on the entity + /// record itself. + /// </summary> + public bool PodcastMode => Id != null && !string.IsNullOrWhiteSpace(HtmlDescription); + } +}
\ No newline at end of file |