✨ Site mode
This commit is contained in:
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)
|
||||
|
||||
@@ -4,7 +4,6 @@ using DysonNetwork.Shared.Registry;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Models = DysonNetwork.Shared.Models;
|
||||
using PublicationPagePresets = DysonNetwork.Shared.Models.PublicationPagePresets;
|
||||
|
||||
namespace DysonNetwork.Zone.Publication;
|
||||
|
||||
@@ -15,10 +14,10 @@ public class PublicationSiteController(
|
||||
RemotePublisherService publisherService
|
||||
) : ControllerBase
|
||||
{
|
||||
[HttpGet("site/{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);
|
||||
@@ -71,6 +70,7 @@ public class PublicationSiteController(
|
||||
|
||||
var site = new SnPublicationSite
|
||||
{
|
||||
Mode = request.Mode,
|
||||
Slug = request.Slug,
|
||||
Name = request.Name,
|
||||
Description = request.Description,
|
||||
@@ -106,12 +106,10 @@ public class PublicationSiteController(
|
||||
if (publisher == null) return NotFound();
|
||||
|
||||
var site = await publicationService.GetSiteById(id);
|
||||
if (site == null)
|
||||
return NotFound();
|
||||
|
||||
if (site.PublisherId != publisher.Id)
|
||||
if (site == null || site.PublisherId != publisher.Id)
|
||||
return NotFound();
|
||||
|
||||
site.Mode = request.Mode;
|
||||
site.Slug = request.Slug;
|
||||
site.Name = request.Name;
|
||||
site.Description = request.Description ?? site.Description;
|
||||
@@ -204,7 +202,7 @@ public class PublicationSiteController(
|
||||
|
||||
var page = new SnPublicationPage
|
||||
{
|
||||
Preset = request.Preset ?? PublicationPagePresets.Landing,
|
||||
Type = request.Type,
|
||||
Path = request.Path ?? "/",
|
||||
Config = request.Config ?? new Dictionary<string, object?>(),
|
||||
SiteId = site.Id
|
||||
@@ -239,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;
|
||||
|
||||
@@ -278,6 +276,7 @@ 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; }
|
||||
@@ -285,7 +284,7 @@ public class PublicationSiteController(
|
||||
|
||||
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,7 +10,8 @@ namespace DysonNetwork.Zone.Publication;
|
||||
public class PublicationSiteService(
|
||||
AppDatabase db,
|
||||
RemotePublisherService publisherService,
|
||||
RemoteAccountService remoteAccounts
|
||||
RemoteAccountService remoteAccounts,
|
||||
RemotePublisherService remotePublishers
|
||||
)
|
||||
{
|
||||
public async Task<SnPublicationSite?> GetSiteById(Guid id)
|
||||
@@ -19,9 +21,18 @@ public class PublicationSiteService(
|
||||
.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)
|
||||
.FirstOrDefaultAsync(s => s.Slug == slug);
|
||||
}
|
||||
@@ -39,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,
|
||||
|
||||
@@ -13,5 +13,8 @@
|
||||
"KnownProxies": ["127.0.0.1", "::1"],
|
||||
"Swagger": {
|
||||
"PublicBasePath": "/zone"
|
||||
},
|
||||
"Sites": {
|
||||
"BasePath": "/SiteData"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user