Compare commits
2 Commits
8e5cdfbc62
...
afccb27bd4
| Author | SHA1 | Date | |
|---|---|---|---|
|
afccb27bd4
|
|||
|
6ed96780ab
|
@@ -56,7 +56,7 @@ builder.Services.AddRateLimiter(options =>
|
||||
};
|
||||
});
|
||||
|
||||
var serviceNames = new[] { "ring", "pass", "drive", "sphere", "develop", "insight" };
|
||||
var serviceNames = new[] { "ring", "pass", "drive", "sphere", "develop", "insight", "zone" };
|
||||
|
||||
var specialRoutes = new[]
|
||||
{
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
using Google.Api;
|
||||
|
||||
namespace DysonNetwork.Shared.Models;
|
||||
|
||||
public enum PublicationSiteMode
|
||||
{
|
||||
/// <summary>
|
||||
/// The fully managed mode which allow other server to handle all the requests
|
||||
/// Including the rendering, data fetching etc. /// Very easy to use and efficient.
|
||||
/// </summary>
|
||||
FullyManaged,
|
||||
|
||||
/// <summary>
|
||||
/// The self-managed mode allows user to upload their own site assets and use the Solar Network Pages
|
||||
/// as a static site hosting platform.
|
||||
/// </summary>
|
||||
SelfManaged
|
||||
}
|
||||
|
||||
public class SnPublicationSite : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
@@ -11,34 +27,36 @@ public class SnPublicationSite : ModelBase
|
||||
[MaxLength(4096)] public string Name { get; set; } = null!;
|
||||
[MaxLength(8192)] public string? Description { get; set; }
|
||||
|
||||
public PublicationSiteMode Mode { get; set; } = PublicationSiteMode.FullyManaged;
|
||||
public List<SnPublicationPage> Pages { get; set; } = [];
|
||||
|
||||
|
||||
public Guid PublisherId { get; set; }
|
||||
[NotMapped] public SnPublisher Publisher { get; set; } = null!;
|
||||
public Guid AccountId { get; set; }
|
||||
// Preloaded via the remote services
|
||||
[NotMapped] public SnAccount? Account { get; set; }
|
||||
}
|
||||
|
||||
public abstract class PublicationPagePresets
|
||||
public enum PublicationPageType
|
||||
{
|
||||
// Will told the Isolated Island to render according to prebuilt pages by us
|
||||
public const string Landing = "landing"; // Some kind of the mixed version of the profile and the posts
|
||||
public const string Profile = "profile";
|
||||
public const string Posts = "posts";
|
||||
|
||||
// Will told the Isolated Island to render according to the blocks to use custom stuff
|
||||
public const string Custom = "custom";
|
||||
/// <summary>
|
||||
/// The HTML page type allows user adding a custom HTML page in the fully managed mode.
|
||||
/// </summary>
|
||||
HtmlPage,
|
||||
/// <summary>
|
||||
/// The redirect mode allows user to create a shortcut for their own link.
|
||||
/// such as example.solian.page/rickroll -- DyZ 301 -> youtube.com/...
|
||||
/// </summary>
|
||||
Redirect
|
||||
}
|
||||
|
||||
public class SnPublicationPage : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
[MaxLength(8192)] public string Preset { get; set; } = PublicationPagePresets.Landing;
|
||||
public PublicationPageType Type { get; set; } = PublicationPageType.HtmlPage;
|
||||
[MaxLength(8192)] public string Path { get; set; } = "/";
|
||||
[Column(TypeName = "jsonb")] public Dictionary<string, object?> Config { get; set; } = new();
|
||||
|
||||
|
||||
public Guid SiteId { get; set; }
|
||||
[JsonIgnore] public SnPublicationSite Site { get; set; } = null!;
|
||||
}
|
||||
@@ -108,4 +108,16 @@ public class RemotePublisherService(PublisherService.PublisherServiceClient publ
|
||||
};
|
||||
return await IsPublisherMember(publisherId.ToString(), accountId.ToString(), protoRole, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<SnPublisher?> GetPublisherByName(string name, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await GetPublisher(name: name, cancellationToken: cancellationToken);
|
||||
}
|
||||
catch (Grpc.Core.RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
DysonNetwork.Zone/.gitignore
vendored
2
DysonNetwork.Zone/.gitignore
vendored
@@ -33,3 +33,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
|
||||
SiteData
|
||||
|
||||
150
DysonNetwork.Zone/Migrations/20251120134237_AddSiteMode.Designer.cs
generated
Normal file
150
DysonNetwork.Zone/Migrations/20251120134237_AddSiteMode.Designer.cs
generated
Normal file
@@ -0,0 +1,150 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DysonNetwork.Zone;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using NodaTime;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DysonNetwork.Zone.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppDatabase))]
|
||||
[Migration("20251120134237_AddSiteMode")]
|
||||
partial class AddSiteMode
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.11")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationPage", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Dictionary<string, object>>("Config")
|
||||
.IsRequired()
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("config");
|
||||
|
||||
b.Property<Instant>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Instant?>("DeletedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("deleted_at");
|
||||
|
||||
b.Property<string>("Path")
|
||||
.IsRequired()
|
||||
.HasMaxLength(8192)
|
||||
.HasColumnType("character varying(8192)")
|
||||
.HasColumnName("path");
|
||||
|
||||
b.Property<Guid>("SiteId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("site_id");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("type");
|
||||
|
||||
b.Property<Instant>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_publication_pages");
|
||||
|
||||
b.HasIndex("SiteId")
|
||||
.HasDatabaseName("ix_publication_pages_site_id");
|
||||
|
||||
b.ToTable("publication_pages", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationSite", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("AccountId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("account_id");
|
||||
|
||||
b.Property<Instant>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Instant?>("DeletedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("deleted_at");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(8192)
|
||||
.HasColumnType("character varying(8192)")
|
||||
.HasColumnName("description");
|
||||
|
||||
b.Property<int>("Mode")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("mode");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4096)
|
||||
.HasColumnType("character varying(4096)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<Guid>("PublisherId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("publisher_id");
|
||||
|
||||
b.Property<string>("Slug")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4096)
|
||||
.HasColumnType("character varying(4096)")
|
||||
.HasColumnName("slug");
|
||||
|
||||
b.Property<Instant>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_publication_sites");
|
||||
|
||||
b.ToTable("publication_sites", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationPage", b =>
|
||||
{
|
||||
b.HasOne("DysonNetwork.Shared.Models.SnPublicationSite", "Site")
|
||||
.WithMany("Pages")
|
||||
.HasForeignKey("SiteId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_publication_pages_publication_sites_site_id");
|
||||
|
||||
b.Navigation("Site");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationSite", b =>
|
||||
{
|
||||
b.Navigation("Pages");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
52
DysonNetwork.Zone/Migrations/20251120134237_AddSiteMode.cs
Normal file
52
DysonNetwork.Zone/Migrations/20251120134237_AddSiteMode.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DysonNetwork.Zone.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddSiteMode : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "preset",
|
||||
table: "publication_pages");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "mode",
|
||||
table: "publication_sites",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "type",
|
||||
table: "publication_pages",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "mode",
|
||||
table: "publication_sites");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "type",
|
||||
table: "publication_pages");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "preset",
|
||||
table: "publication_pages",
|
||||
type: "character varying(8192)",
|
||||
maxLength: 8192,
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,16 +50,14 @@ namespace DysonNetwork.Zone.Migrations
|
||||
.HasColumnType("character varying(8192)")
|
||||
.HasColumnName("path");
|
||||
|
||||
b.Property<string>("Preset")
|
||||
.IsRequired()
|
||||
.HasMaxLength(8192)
|
||||
.HasColumnType("character varying(8192)")
|
||||
.HasColumnName("preset");
|
||||
|
||||
b.Property<Guid>("SiteId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("site_id");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("type");
|
||||
|
||||
b.Property<Instant>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
@@ -97,6 +95,10 @@ namespace DysonNetwork.Zone.Migrations
|
||||
.HasColumnType("character varying(8192)")
|
||||
.HasColumnName("description");
|
||||
|
||||
b.Property<int>("Mode")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("mode");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4096)
|
||||
|
||||
@@ -47,10 +47,9 @@ using (var scope = app.Services.CreateScope())
|
||||
if (!app.Environment.IsDevelopment())
|
||||
app.UseExceptionHandler("/Error");
|
||||
|
||||
app.ConfigureAppMiddleware(builder.Configuration);
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.ConfigureAppMiddleware(builder.Configuration);
|
||||
app.MapRazorPages();
|
||||
|
||||
app.UseSwaggerManifest("DysonNetwork.Zone");
|
||||
|
||||
@@ -3,7 +3,7 @@ using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PublicationPagePresets = DysonNetwork.Shared.Models.PublicationPagePresets;
|
||||
using Models = DysonNetwork.Shared.Models;
|
||||
|
||||
namespace DysonNetwork.Zone.Publication;
|
||||
|
||||
@@ -14,15 +14,33 @@ public class PublicationSiteController(
|
||||
RemotePublisherService publisherService
|
||||
) : ControllerBase
|
||||
{
|
||||
[HttpGet("{slug}")]
|
||||
public async Task<ActionResult<SnPublicationSite>> GetSite(string slug)
|
||||
[HttpGet("{pubName}/{slug}")]
|
||||
public async Task<ActionResult<SnPublicationSite>> GetSite(string pubName, string slug)
|
||||
{
|
||||
var site = await publicationService.GetSiteBySlug(slug);
|
||||
var site = await publicationService.GetSiteBySlug(slug, pubName);
|
||||
if (site == null)
|
||||
return NotFound();
|
||||
return Ok(site);
|
||||
}
|
||||
|
||||
[HttpGet("{pubName}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<List<SnPublicationSite>>> ListSitesForPublisher([FromRoute] string pubName)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
var publisher = await publisherService.GetPublisherByName(pubName);
|
||||
if (publisher == null) return NotFound();
|
||||
|
||||
if (!await publisherService.IsMemberWithRole(publisher.Id, accountId, Models.PublisherMemberRole.Viewer))
|
||||
return Forbid();
|
||||
|
||||
var sites = await publicationService.GetSitesByPublisherIds([publisher.Id]);
|
||||
return Ok(sites);
|
||||
}
|
||||
|
||||
[HttpGet("me")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<List<SnPublicationSite>>> ListOwnedSites()
|
||||
@@ -39,20 +57,24 @@ public class PublicationSiteController(
|
||||
return Ok(sites);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpPost("{pubName}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<SnPublicationSite>> CreateSite([FromBody] PublicationSiteRequest request)
|
||||
public async Task<ActionResult<SnPublicationSite>> CreateSite([FromRoute] string pubName, [FromBody] PublicationSiteRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
var publisher = await publisherService.GetPublisherByName(pubName);
|
||||
if (publisher == null) return NotFound();
|
||||
|
||||
var site = new SnPublicationSite
|
||||
{
|
||||
Mode = request.Mode,
|
||||
Slug = request.Slug,
|
||||
Name = request.Name,
|
||||
Description = request.Description,
|
||||
PublisherId = request.PublisherId,
|
||||
PublisherId = publisher.Id,
|
||||
AccountId = accountId
|
||||
};
|
||||
|
||||
@@ -64,27 +86,30 @@ public class PublicationSiteController(
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
return Forbid();
|
||||
return StatusCode(403, ex.Message);
|
||||
}
|
||||
|
||||
return Ok(site);
|
||||
}
|
||||
|
||||
[HttpPatch("{id:guid}")]
|
||||
[HttpPatch("{pubName}/{id:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<SnPublicationSite>> UpdateSite(Guid id, [FromBody] PublicationSiteRequest request)
|
||||
public async Task<ActionResult<SnPublicationSite>> UpdateSite([FromRoute] string pubName, Guid id, [FromBody] PublicationSiteRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
var publisher = await publisherService.GetPublisherByName(pubName);
|
||||
if (publisher == null) return NotFound();
|
||||
|
||||
var site = await publicationService.GetSiteById(id);
|
||||
if (site == null)
|
||||
if (site == null || site.PublisherId != publisher.Id)
|
||||
return NotFound();
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
|
||||
site.Mode = request.Mode;
|
||||
site.Slug = request.Slug;
|
||||
site.Name = request.Name;
|
||||
site.Description = request.Description ?? site.Description;
|
||||
@@ -101,14 +126,20 @@ public class PublicationSiteController(
|
||||
return Ok(site);
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
[HttpDelete("{pubName}/{id:guid}")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> DeleteSite(Guid id)
|
||||
public async Task<IActionResult> DeleteSite([FromRoute] string pubName, Guid id)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
var publisher = await publisherService.GetPublisherByName(pubName);
|
||||
if (publisher == null) return NotFound();
|
||||
|
||||
var site = await publicationService.GetSiteById(id);
|
||||
if (site == null || site.PublisherId != publisher.Id)
|
||||
return NotFound();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -122,7 +153,7 @@ public class PublicationSiteController(
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("{slug}/page")]
|
||||
[HttpGet("site/{slug}/page")]
|
||||
public async Task<ActionResult<SnPublicationPage>> RenderPage(string slug, [FromQuery] string path = "/")
|
||||
{
|
||||
var page = await publicationService.RenderPage(slug, path);
|
||||
@@ -131,15 +162,21 @@ public class PublicationSiteController(
|
||||
return Ok(page);
|
||||
}
|
||||
|
||||
[HttpGet("{siteId:guid}/pages")]
|
||||
[HttpGet("{pubName}/{siteSlug}/pages")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<List<SnPublicationPage>>> ListPagesForSite(Guid siteId)
|
||||
public async Task<ActionResult<List<SnPublicationPage>>> ListPagesForSite([FromRoute] string pubName, [FromRoute] string siteSlug)
|
||||
{
|
||||
var pages = await publicationService.GetPagesForSite(siteId);
|
||||
var site = await publicationService.GetSiteBySlug(siteSlug);
|
||||
if (site == null) return NotFound();
|
||||
|
||||
var publisher = await publisherService.GetPublisherByName(pubName);
|
||||
if (publisher == null || site.PublisherId != publisher.Id) return NotFound();
|
||||
|
||||
var pages = await publicationService.GetPagesForSite(site.Id);
|
||||
return Ok(pages);
|
||||
}
|
||||
|
||||
[HttpGet("page/{id:guid}")]
|
||||
[HttpGet("pages/{id:guid}")]
|
||||
public async Task<ActionResult<SnPublicationPage>> GetPage(Guid id)
|
||||
{
|
||||
var page = await publicationService.GetPageById(id);
|
||||
@@ -148,21 +185,27 @@ public class PublicationSiteController(
|
||||
return Ok(page);
|
||||
}
|
||||
|
||||
[HttpPost("{siteId:guid}/pages")]
|
||||
[HttpPost("{pubName}/{siteSlug}/pages")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<SnPublicationPage>> CreatePage(Guid siteId, [FromBody] PublicationPageRequest request)
|
||||
public async Task<ActionResult<SnPublicationPage>> CreatePage([FromRoute] string pubName, [FromRoute] string siteSlug, [FromBody] PublicationPageRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
||||
return Unauthorized();
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
|
||||
var site = await publicationService.GetSiteBySlug(siteSlug);
|
||||
if (site == null) return NotFound();
|
||||
|
||||
var publisher = await publisherService.GetPublisherByName(pubName);
|
||||
if (publisher == null || site.PublisherId != publisher.Id) return NotFound();
|
||||
|
||||
var page = new SnPublicationPage
|
||||
{
|
||||
Preset = request.Preset ?? PublicationPagePresets.Landing,
|
||||
Type = request.Type,
|
||||
Path = request.Path ?? "/",
|
||||
Config = request.Config ?? new(),
|
||||
SiteId = siteId
|
||||
Config = request.Config ?? new Dictionary<string, object?>(),
|
||||
SiteId = site.Id
|
||||
};
|
||||
|
||||
try
|
||||
@@ -181,7 +224,7 @@ public class PublicationSiteController(
|
||||
return Ok(page);
|
||||
}
|
||||
|
||||
[HttpPatch("page/{id:guid}")]
|
||||
[HttpPatch("pages/{id:guid}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<SnPublicationPage>> UpdatePage(Guid id, [FromBody] PublicationPageRequest request)
|
||||
{
|
||||
@@ -194,7 +237,7 @@ public class PublicationSiteController(
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
|
||||
if (request.Preset != null) page.Preset = request.Preset;
|
||||
page.Type = request.Type;
|
||||
if (request.Path != null) page.Path = request.Path;
|
||||
if (request.Config != null) page.Config = request.Config;
|
||||
|
||||
@@ -210,7 +253,7 @@ public class PublicationSiteController(
|
||||
return Ok(page);
|
||||
}
|
||||
|
||||
[HttpDelete("page/{id:guid}")]
|
||||
[HttpDelete("pages/{id:guid}")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> DeletePage(Guid id)
|
||||
{
|
||||
@@ -233,16 +276,15 @@ public class PublicationSiteController(
|
||||
|
||||
public class PublicationSiteRequest
|
||||
{
|
||||
public PublicationSiteMode Mode { get; set; }
|
||||
[MaxLength(4096)] public string Slug { get; set; } = null!;
|
||||
[MaxLength(4096)] public string Name { get; set; } = null!;
|
||||
[MaxLength(8192)] public string? Description { get; set; }
|
||||
|
||||
public Guid PublisherId { get; set; }
|
||||
}
|
||||
|
||||
public class PublicationPageRequest
|
||||
{
|
||||
[MaxLength(8192)] public string? Preset { get; set; }
|
||||
public PublicationPageType Type { get; set; }
|
||||
[MaxLength(8192)] public string? Path { get; set; }
|
||||
public Dictionary<string, object?>? Config { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using DysonNetwork.Shared.Auth;
|
||||
using DysonNetwork.Shared.Data;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -9,24 +10,30 @@ namespace DysonNetwork.Zone.Publication;
|
||||
public class PublicationSiteService(
|
||||
AppDatabase db,
|
||||
RemotePublisherService publisherService,
|
||||
RemoteAccountService remoteAccounts
|
||||
RemoteAccountService remoteAccounts,
|
||||
RemotePublisherService remotePublishers
|
||||
)
|
||||
{
|
||||
public async Task<SnPublicationSite?> GetSiteById(Guid id)
|
||||
{
|
||||
return await db.PublicationSites
|
||||
.Include(s => s.Pages)
|
||||
.ThenInclude(p => p.Site)
|
||||
.Include(s => s.Publisher)
|
||||
.FirstOrDefaultAsync(s => s.Id == id);
|
||||
}
|
||||
|
||||
public async Task<SnPublicationSite?> GetSiteBySlug(string slug)
|
||||
public async Task<SnPublicationSite?> GetSiteBySlug(string slug, string? pubName = null)
|
||||
{
|
||||
Guid? pubId = null;
|
||||
if (pubName != null)
|
||||
{
|
||||
var pub = await remotePublishers.GetPublisherByName(pubName);
|
||||
if (pub == null) throw new InvalidOperationException("Publisher not found.");
|
||||
pubId = pub.Id;
|
||||
}
|
||||
|
||||
return await db.PublicationSites
|
||||
.If(pubId.HasValue, q => q.Where(s => s.PublisherId == pubId.Value))
|
||||
.Include(s => s.Pages)
|
||||
.ThenInclude(p => p.Site)
|
||||
.Include(s => s.Publisher)
|
||||
.FirstOrDefaultAsync(s => s.Slug == slug);
|
||||
}
|
||||
|
||||
@@ -34,8 +41,6 @@ public class PublicationSiteService(
|
||||
{
|
||||
return await db.PublicationSites
|
||||
.Include(s => s.Pages)
|
||||
.ThenInclude(p => p.Site)
|
||||
.Include(s => s.Publisher)
|
||||
.Where(s => publisherIds.Contains(s.PublisherId))
|
||||
.ToListAsync();
|
||||
}
|
||||
@@ -45,7 +50,7 @@ public class PublicationSiteService(
|
||||
var perk = (await remoteAccounts.GetAccount(accountId)).PerkSubscription;
|
||||
var perkLevel = perk is not null ? PerkSubscriptionPrivilege.GetPrivilegeFromIdentifier(perk.Identifier) : 0;
|
||||
|
||||
var maxSite = (perkLevel) switch
|
||||
var maxSite = perkLevel switch
|
||||
{
|
||||
1 => 2,
|
||||
2 => 3,
|
||||
@@ -100,7 +105,6 @@ public class PublicationSiteService(
|
||||
{
|
||||
return await db.PublicationPages
|
||||
.Include(p => p.Site)
|
||||
.ThenInclude(s => s.Publisher)
|
||||
.FirstOrDefaultAsync(p => p.Id == id);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,8 @@
|
||||
"KnownProxies": ["127.0.0.1", "::1"],
|
||||
"Swagger": {
|
||||
"PublicBasePath": "/zone"
|
||||
},
|
||||
"Sites": {
|
||||
"BasePath": "/SiteData"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user