Compare commits

...

10 commits

22 changed files with 897 additions and 64 deletions

View file

@ -40,7 +40,7 @@
private async Task ProfilePictureChanged(string tempFilePath) { private async Task ProfilePictureChanged(string tempFilePath) {
if (User is null) return; if (User is null) return;
var guid = await ImageService.StoreImageAsync(tempFilePath); var guid = await ImageService.StoreImageAsync(tempFilePath, enforceSize:true);
if (!guid.HasValue) throw new ApplicationException("Processing Image failed."); if (!guid.HasValue) throw new ApplicationException("Processing Image failed.");
Guid? imageToDelete = null; Guid? imageToDelete = null;

View file

@ -10,6 +10,7 @@
<div class="card-body"> <div class="card-body">
<h2 class="card-title line-clamp-1">@Article.Title</h2> <h2 class="card-title line-clamp-1">@Article.Title</h2>
<small> <small>
@Article.Author.Name
@Article.PublishDate.ToString("d") @Article.PublishDate.ToString("d")
@if (Article.Status is not ArticleStatus.Published) { @if (Article.Status is not ArticleStatus.Published) {
<span class="badge badge-sm badge-warning ml-2">@Article.Status.Humanize()</span> <span class="badge badge-sm badge-warning ml-2">@Article.Status.Humanize()</span>

View file

@ -59,7 +59,7 @@
<img class="sm:max-h-56" src="/api/user/pfp/@Article.Author.Id?size=400" alt="" width="400" loading="async"> <img class="sm:max-h-56" src="/api/user/pfp/@Article.Author.Id?size=400" alt="" width="400" loading="async">
</figure> </figure>
<div class="card-body sm:border-l-2 border-current"> <div class="card-body sm:border-l-2 border-current">
<h2 class="card-title">About The Author</h2> <h2 class="card-title">@Localizer["AboutAuthor_Title"]</h2>
<h3><strong>@Article.Author.Name</strong></h3> <h3><strong>@Article.Author.Name</strong></h3>
<p> <p>
@Article.Author.AboutTheAuthor @Article.Author.AboutTheAuthor
@ -90,6 +90,8 @@
} }
</div> </div>
@AdditionalContent
<template id="copyButtonTemplate"> <template id="copyButtonTemplate">
<button class="btn btn-sm btn-accent btn-square absolute top-2 right-2" title="copy"> <button class="btn btn-sm btn-accent btn-square absolute top-2 right-2" title="copy">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
@ -120,4 +122,6 @@
[Parameter] [Parameter]
public required Article Article { get; set; } public required Article Article { get; set; }
private MarkupString Content => new(Article.BodyHtml); private MarkupString Content => new(Article.BodyHtml);
[Parameter]
public RenderFragment? AdditionalContent { get; set; }
} }

View file

@ -3,7 +3,7 @@
@using System.ComponentModel @using System.ComponentModel
@using System.ComponentModel.DataAnnotations @using System.ComponentModel.DataAnnotations
<label class="form-control w-full"> <label class="form-control w-full" @attributes="AdditionalAttributes">
<div class="label"> <div class="label">
@if (Label is not null) { @if (Label is not null) {
@Label @Label
@ -32,6 +32,8 @@
public required RenderFragment ChildContent { get; set; } public required RenderFragment ChildContent { get; set; }
[Parameter] [Parameter]
public Expression<Func<object?>>? For { get; set; } public Expression<Func<object?>>? For { get; set; }
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object>? AdditionalAttributes { get; set; }
private string GetDisplayName() { private string GetDisplayName() {
if (For is null) return string.Empty; if (For is null) return string.Empty;

View file

@ -87,7 +87,10 @@
<div class="bg-base-200 p-4 h-full flex flex-col gap-4 w-48 lg:w-64"> <div class="bg-base-200 p-4 h-full flex flex-col gap-4 w-48 lg:w-64">
<NavMenu /> <NavMenu />
<a aria-hidden="true" tabindex="-1" class="absolute left-2 right-2 bottom-2 text-center text-slate-400" href="https://github.com/miawinter98/wave/releases/">@Version</a>
@if (Customizations.Value.HideVersion is not true) {
<a aria-hidden="true" tabindex="-1" class="absolute left-2 right-2 bottom-2 text-center text-slate-400" href="https://github.com/miawinter98/wave/releases/">@Version</a>
}
</div> </div>
</div> </div>
</div> </div>

View file

@ -4,6 +4,7 @@
@using Wave.Data @using Wave.Data
@using System.Security.Claims @using System.Security.Claims
@using System.Globalization @using System.Globalization
@using System.Net
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.Extensions.Options @using Microsoft.Extensions.Options
@using Wave.Services @using Wave.Services
@ -53,7 +54,15 @@
<ErrorBoundary> <ErrorBoundary>
<ChildContent> <ChildContent>
@if (GetArticle(HttpContext.User) is {} article) { @if (GetArticle(HttpContext.User) is {} article) {
<ArticleComponent Article="@article"/> <ArticleComponent Article="@article">
<AdditionalContent>
@if (Recommendations.Count > 0) {
<h2 class="text-3xl my-6">@Localizer["Recommendations_Title"]</h2>
<ArticleCardList Articles="Recommendations" />
}
</AdditionalContent>
</ArticleComponent>
<div class="flex gap-2 mt-3 flex-wrap"> <div class="flex gap-2 mt-3 flex-wrap">
@if (article.AllowedToEdit(HttpContext.User)) { @if (article.AllowedToEdit(HttpContext.User)) {
@ -156,6 +165,7 @@
public HttpContext HttpContext { get; set; } = default!; public HttpContext HttpContext { get; set; } = default!;
private List<ApplicationUser> Reviewers { get; } = []; private List<ApplicationUser> Reviewers { get; } = [];
private List<Article> Recommendations { get; } = [];
private Article GetArticle(ClaimsPrincipal principal) { private Article GetArticle(ClaimsPrincipal principal) {
if (Article.AllowedToRead(principal)) return Article!; if (Article.AllowedToRead(principal)) return Article!;
@ -181,13 +191,53 @@
a.PublishDate.Date == date.Date a.PublishDate.Date == date.Date
&& (slug != null && a.Slug == slug || a.Title.ToLower() == title)); && (slug != null && a.Slug == slug || a.Title.ToLower() == title));
} }
if (Article is null) {
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
} }
protected override async Task OnInitializedAsync() { protected override async Task OnInitializedAsync() {
Reviewers.AddRange([ if (Article is null) return;
.. await UserManager.GetUsersInRoleAsync("Reviewer"),
.. await UserManager.GetUsersInRoleAsync("Admin") if (Article.Status != ArticleStatus.Published) {
]); Reviewers.AddRange([
.. await UserManager.GetUsersInRoleAsync("Reviewer"),
.. await UserManager.GetUsersInRoleAsync("Admin")
]);
} else {
var primaryCategories = Article.Categories.Where(c => c.Color == CategoryColors.Primary).ToArray();
await using var context = await ContextFactory.CreateDbContextAsync();
const int featuredArticleCount = 3;
// See if we can find 3 articles with the same primary category
if (primaryCategories.Length > 0) {
foreach (var category in primaryCategories) {
Recommendations.AddRange(await context.Set<Article>()
.Include(a => a.Author)
.Include(a => a.Categories)
.OrderByDescending(a => a.PublishDate).ThenBy(a => a.Id)
.Where(a => a.Categories.Contains(category) && a.Id != Article.Id)
.Take(featuredArticleCount - Recommendations.Count)
.ToListAsync());
if (Recommendations.Count >= featuredArticleCount) break;
}
}
// Fill up with the newest articles of possible
if (Recommendations.Count < featuredArticleCount) {
Recommendations.AddRange(await context.Set<Article>()
.Include(a => a.Author)
.Include(a => a.Categories)
.OrderByDescending(a => a.PublishDate).ThenBy(a => a.Id)
.Where(a => a.Id != Article.Id)
.Take(featuredArticleCount - Recommendations.Count).ToListAsync());
}
Recommendations.Sort((a1, a2) => a2.PublishDate.CompareTo(a1.PublishDate));
}
} }
private async Task SubmitForReview() { private async Task SubmitForReview() {

View file

@ -27,8 +27,8 @@
<a class="btn btn-primary" href="/">@Localizer["NotFound_BackToHome_Label"]</a> <a class="btn btn-primary" href="/">@Localizer["NotFound_BackToHome_Label"]</a>
} else { } else {
<h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["Title"] - @Category.Name</h1> <h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["Title"] - @Category.Name</h1>
<ArticleCardList Articles="Category.Articles" /> <ArticleCardList Articles="Category.Articles.Where(a => !a.IsDeleted && a.PublishDate <= DateTimeOffset.Now).ToList()" />
} }
@code { @code {
@ -42,22 +42,13 @@
protected override async Task OnInitializedAsync() { protected override async Task OnInitializedAsync() {
await using var context = await ContextFactory.CreateDbContextAsync(); await using var context = await ContextFactory.CreateDbContextAsync();
string category = WebUtility.UrlDecode(CategoryName); string category = WebUtility.UrlDecode(CategoryName);
var now = DateTimeOffset.UtcNow; if (Category != null) return;
// First load Category with simple chain and manual filters, as to minimize
// filter redundancy and query complexity (category -> Articles -> Author is linear)
Category = await context.Set<Category>() Category = await context.Set<Category>()
.IgnoreAutoIncludes().IgnoreQueryFilters() .IgnoreAutoIncludes()
.Include(c => c.Articles.Where(a => !a.IsDeleted && a.PublishDate <= now)) .Include(c => c.Articles).ThenInclude(a => a.Categories)
.ThenInclude(a => a.Author) .Include(c => c.Articles).ThenInclude(a => a.Author)
.AsSplitQuery()
.FirstOrDefaultAsync(c => c.Name == category); .FirstOrDefaultAsync(c => c.Name == category);
// Load all the other categories missing on the articles, by loading all relevant
// articles ID with their categories, so EF can map them to the already loaded entries
// (again manual filter to minimize redundancy)
await context.Set<Article>()
.IgnoreAutoIncludes().IgnoreQueryFilters()
.Where(a => !a.IsDeleted && a.PublishDate <= now && a.Categories.Contains(Category!))
.Select(a => new {
a.Id, a.Categories
}).LoadAsync();
} }
} }

View file

@ -3,6 +3,7 @@
@using System.Diagnostics.CodeAnalysis @using System.Diagnostics.CodeAnalysis
@using System.Net @using System.Net
@using System.Security.Claims @using System.Security.Claims
@using Humanizer
@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Identity
@using Microsoft.EntityFrameworkCore @using Microsoft.EntityFrameworkCore
@using Wave.Services @using Wave.Services
@ -34,6 +35,18 @@
@bind-Value="@Model.Title" placeholder="@Localizer["Title_Placeholder"]" autocomplete="off"/> @bind-Value="@Model.Title" placeholder="@Localizer["Title_Placeholder"]" autocomplete="off"/>
</InputLabelComponent> </InputLabelComponent>
<InputLabelComponent class="row-span-3" LabelText="@Localizer["Categories_Label"]" For="() => Model.Categories">
<InputSelect class="select select-bordered w-full" @bind-Value="@Model.Categories" multiple size="10">
@foreach (var group in Categories.GroupBy(c => c.Color)) {
<optgroup class="font-bold not-italic my-3" label="@group.Key.Humanize()">
@foreach (var category in group) {
<option value="@category.Id" selected="@Model.Categories?.Contains(category.Id)">@category.Name</option>
}
</optgroup>
}
</InputSelect>
</InputLabelComponent>
<InputLabelComponent LabelText="@Localizer["Slug_Label"]" For="() => Model.Slug"> <InputLabelComponent LabelText="@Localizer["Slug_Label"]" For="() => Model.Slug">
@if (Article.Status is not ArticleStatus.Published || Article.PublishDate >= DateTimeOffset.UtcNow) { @if (Article.Status is not ArticleStatus.Published || Article.PublishDate >= DateTimeOffset.UtcNow) {
<InputText class="input input-bordered w-full" maxlength="64" <InputText class="input input-bordered w-full" maxlength="64"
@ -53,13 +66,6 @@
type="datetime-local" readonly value="@Article.PublishDate.ToString("yyyy-MM-dd\\THH:mm:ss")"/> type="datetime-local" readonly value="@Article.PublishDate.ToString("yyyy-MM-dd\\THH:mm:ss")"/>
} }
</InputLabelComponent> </InputLabelComponent>
<InputLabelComponent LabelText="@Localizer["Categories_Label"]" For="() => Model.Categories">
<select class="select select-bordered w-full h-32" @onchange="CategorySelectionChanged" multiple>
@foreach (var category in Categories) {
<option value="@category.Id" selected="@Model.Categories?.Contains(category.Id)">@category.Name</option>
}
</select>
</InputLabelComponent>
</div> </div>
<AdvancedMarkdownEditor Title="@Model.Title" MarkdownCallback="() => Model.Body"> <AdvancedMarkdownEditor Title="@Model.Title" MarkdownCallback="() => Model.Body">
@ -156,7 +162,9 @@
Model.Slug ??= article.Slug; Model.Slug ??= article.Slug;
Model.Body ??= article.Body; Model.Body ??= article.Body;
Model.PublishDate ??= article.PublishDate.LocalDateTime; Model.PublishDate ??= article.PublishDate.LocalDateTime;
Model.Categories ??= article.Categories.Select(c => c.Id).ToArray(); if (Model.Categories?.Length < 1) {
Model.Categories = article.Categories.Select(c => c.Id).ToArray();
}
Article = article; Article = article;
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
} }
@ -210,7 +218,6 @@
await context.Set<ArticleCategory>().IgnoreQueryFilters().IgnoreAutoIncludes() await context.Set<ArticleCategory>().IgnoreQueryFilters().IgnoreAutoIncludes()
.Where(ac => ac.Article.Id == Article.Id).LoadAsync(); .Where(ac => ac.Article.Id == Article.Id).LoadAsync();
Model.Categories ??= [];
context.Update(Article); context.Update(Article);
var existingImages = await context.Set<Article>() var existingImages = await context.Set<Article>()
@ -280,12 +287,7 @@
throw new ApplicationException("You do not have permissions to edit this article"); throw new ApplicationException("You do not have permissions to edit this article");
} }
private void CategorySelectionChanged(ChangeEventArgs args) {
string[]? selected = (string[]?) args.Value;
Model.Categories = selected?.Select(Guid.Parse).ToArray();
}
private async Task ImageAdded(ArticleImage image) { private async Task ImageAdded(ArticleImage image) {
Article.Images.Add(image); Article.Images.Add(image);
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
@ -306,7 +308,7 @@
[Required(AllowEmptyStrings = false)] [Required(AllowEmptyStrings = false)]
public string? Body { get; set; } public string? Body { get; set; }
public Guid[]? Categories { get; set; } public Guid[]? Categories { get; set; } = [];
public DateTimeOffset? PublishDate { get; set; } public DateTimeOffset? PublishDate { get; set; }
} }

View file

@ -89,20 +89,17 @@
private ApplicationUser? User { get; set; } private ApplicationUser? User { get; set; }
protected override async Task OnInitializedAsync() { protected override async Task OnInitializedAsync() {
if (User is not null) return;
await using var context = await ContextFactory.CreateDbContextAsync(); await using var context = await ContextFactory.CreateDbContextAsync();
// Find user // Find user
if (Id is not null) { if (Id is not null) {
var now = DateTimeOffset.UtcNow;
User = await context.Users User = await context.Users
.IgnoreAutoIncludes().IgnoreQueryFilters() .IgnoreAutoIncludes()
.Include(u => u.Articles.Where(a => !a.IsDeleted && a.PublishDate <= now)) .Include(u => u.Links)
.Include(u => u.Articles).ThenInclude(a => a.Categories)
.AsSplitQuery()
.FirstOrDefaultAsync(u => u.Id == Id.ToString()); .FirstOrDefaultAsync(u => u.Id == Id.ToString());
await context.Set<Article>()
.Where(a => a.Author.Id == Id.ToString())
.Select(a => new {
a.Id, a.Categories
}).LoadAsync();
} }
// Validate access to user // Validate access to user

View file

@ -1,9 +1,10 @@
@using Wave.Data @using Wave.Data
@using System.Net @using System.Net
@using System.Text.RegularExpressions
<a href="@Link.UrlString" rel="me" target="_blank" title="@Link.Url.Host" @attributes="AdditionalAttributes"> <a href="@Link.UrlString" rel="me" target="_blank" title="@Link.Url.Host" @attributes="AdditionalAttributes">
<img src="@("/api/proxy/favicon/" + WebUtility.UrlEncode(Link.Url.Host))" alt="" width="32" height="32" class="w-5 h-5" loading="async" /> <img src="@("/api/proxy/favicon/" + WebUtility.UrlEncode(Link.Url.Host))" alt="" width="32" height="32" class="w-5 h-5" loading="async" />
@(Link.Url.Host.LastIndexOf('.') > -1 ? Link.Url.Host[..Link.Url.Host.LastIndexOf('.')] : Link.Url.Host) @Regex.Replace(Link.Url.Host, @"(www\.|.de|.com)", "", RegexOptions.Compiled | RegexOptions.IgnoreCase)
</a> </a>
@code { @code {

View file

@ -55,7 +55,11 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
article.Property(a => a.BodyPlain).HasDefaultValue(""); article.Property(a => a.BodyPlain).HasDefaultValue("");
article.HasQueryFilter(a => !a.IsDeleted && a.Status >= ArticleStatus.Published && a.PublishDate <= DateTimeOffset.UtcNow); article.Property(a => a.CanBePublic)
.HasComputedColumnSql(
$"\"{nameof(Article.IsDeleted)}\" = false AND \"{nameof(Article.Status)}\" = {(int)ArticleStatus.Published}", true);
article.HasQueryFilter(a => a.CanBePublic && a.PublishDate <= DateTimeOffset.UtcNow);
article.ToTable("Articles"); article.ToTable("Articles");
}); });
@ -74,7 +78,8 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
articleCategory => { articleCategory => {
articleCategory.HasKey(ac => ac.Id); articleCategory.HasKey(ac => ac.Id);
articleCategory.ToTable("ArticleCategories"); articleCategory.ToTable("ArticleCategories");
articleCategory.HasQueryFilter(ac => !ac.Article.IsDeleted); articleCategory.HasQueryFilter(ac =>
ac.Article.CanBePublic && ac.Article.PublishDate <= DateTimeOffset.UtcNow);
}); });
category.ToTable("Categories"); category.ToTable("Categories");
@ -95,7 +100,7 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
newsletter.Property(a => a.DistributionDateTime) newsletter.Property(a => a.DistributionDateTime)
.HasConversion(dateTimeOffsetUtcConverter); .HasConversion(dateTimeOffsetUtcConverter);
newsletter.HasQueryFilter(n => !n.Article.IsDeleted); newsletter.HasQueryFilter(n => n.Article.CanBePublic && n.Article.PublishDate <= DateTimeOffset.UtcNow);
newsletter.ToTable("Newsletter"); newsletter.ToTable("Newsletter");
}); });
builder.Entity<EmailSubscriber>(subscriber => { builder.Entity<EmailSubscriber>(subscriber => {

View file

@ -16,6 +16,9 @@ public class Article : ISoftDelete {
public Guid Id { get; set; } public Guid Id { get; set; }
public bool IsDeleted { get; set; } public bool IsDeleted { get; set; }
// Computed
public bool CanBePublic { get; set; }
[MaxLength(256)] [MaxLength(256)]
public required string Title { get; set; } public required string Title { get; set; }
public required string Body { get; set; } public required string Body { get; set; }

View file

@ -7,6 +7,7 @@ public class Customization {
public string DefaultTheme { get; set; } = ""; public string DefaultTheme { get; set; } = "";
public string DefaultLanguage { get; set; } = ""; public string DefaultLanguage { get; set; } = "";
public bool DefaultNarrowReader { get; set; } = false; public bool DefaultNarrowReader { get; set; } = false;
public bool HideVersion { get; set; } = false;
public string LogoLink { get; set; } = ""; public string LogoLink { get; set; } = "";
public string IconLink { get; set; } = ""; public string IconLink { get; set; } = "";
public string Footer { get; set; } = ""; public string Footer { get; set; } = "";

View file

@ -325,6 +325,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("text") .HasColumnType("text")
.HasDefaultValue(""); .HasDefaultValue("");
b.Property<bool>("CanBePublic")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("boolean")
.HasComputedColumnSql("\"IsDeleted\" = false AND \"Status\" = 2", true);
b.Property<DateTimeOffset>("CreationDate") b.Property<DateTimeOffset>("CreationDate")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")

View file

@ -0,0 +1,716 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Wave.Data;
#nullable disable
namespace Wave.Data.Migrations.postgres
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240419191448_Article_CanBePublic_Computed")]
partial class Article_CanBePublic_Computed
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:CollationDefinition:default-case-insensitive", "und-u-kf-upper-ks-level1,und-u-kf-upper-ks-level1,icu,False")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Wave.Data.ApiClaim", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ApiKeyKey")
.HasColumnType("character varying(128)");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Value")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.HasKey("Id");
b.HasIndex("ApiKeyKey");
b.ToTable("ApiClaim");
});
modelBuilder.Entity("Wave.Data.ApiKey", b =>
{
b.Property<string>("Key")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("OwnerName")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.HasKey("Key");
b.ToTable("ApiKey");
});
modelBuilder.Entity("Wave.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AboutTheAuthor")
.IsRequired()
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("Biography")
.IsRequired()
.HasMaxLength(4096)
.HasColumnType("character varying(4096)");
b.Property<string>("BiographyHtml")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("ContactEmail")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("ContactPhone")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("ContactPhoneBusiness")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("ContactWebsite")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("FullName")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Wave.Data.Article", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<string>("BodyHtml")
.IsRequired()
.HasColumnType("text");
b.Property<string>("BodyPlain")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("");
b.Property<bool>("CanBePublic")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("boolean")
.HasComputedColumnSql("\"IsDeleted\" = false AND \"Status\" = 2", true);
b.Property<DateTimeOffset>("CreationDate")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("now()");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<DateTimeOffset>("LastModified")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("now()");
b.Property<DateTimeOffset>("PublishDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("ReviewerId")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasDefaultValue("");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.HasIndex("ReviewerId");
b.ToTable("Articles", (string)null);
});
modelBuilder.Entity("Wave.Data.ArticleCategory", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.Property<Guid>("CategoryId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ArticleId");
b.HasIndex("CategoryId");
b.ToTable("ArticleCategories", (string)null);
});
modelBuilder.Entity("Wave.Data.ArticleImage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid?>("ArticleId")
.HasColumnType("uuid");
b.Property<string>("ImageDescription")
.IsRequired()
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.HasKey("Id");
b.HasIndex("ArticleId");
b.ToTable("Images", (string)null);
});
modelBuilder.Entity("Wave.Data.Category", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Color")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(25);
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.UseCollation("default-case-insensitive");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Categories", (string)null);
});
modelBuilder.Entity("Wave.Data.EmailNewsletter", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DistributionDateTime")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsSend")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("ArticleId")
.IsUnique();
b.ToTable("Newsletter", (string)null);
});
modelBuilder.Entity("Wave.Data.EmailSubscriber", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Email")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.UseCollation("default-case-insensitive");
b.Property<string>("Language")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(8)
.HasColumnType("character varying(8)")
.HasDefaultValue("en-US");
b.Property<DateTimeOffset?>("LastMailOpened")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("LastMailReceived")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("UnsubscribeReason")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("Unsubscribed")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("Email")
.IsUnique();
b.HasIndex("Unsubscribed");
b.ToTable("NewsletterSubscribers", (string)null);
});
modelBuilder.Entity("Wave.Data.ProfilePicture", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ApplicationUserId")
.HasColumnType("text");
b.Property<Guid>("ImageId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ApplicationUserId")
.IsUnique();
b.ToTable("ProfilePictures", (string)null);
});
modelBuilder.Entity("Wave.Data.UserLink", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ApplicationUserId")
.HasColumnType("text");
b.Property<string>("UrlString")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("character varying(1024)");
b.HasKey("Id");
b.HasIndex("ApplicationUserId");
b.ToTable("UserLink");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Wave.Data.ApiClaim", b =>
{
b.HasOne("Wave.Data.ApiKey", null)
.WithMany("ApiClaims")
.HasForeignKey("ApiKeyKey")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Wave.Data.Article", b =>
{
b.HasOne("Wave.Data.ApplicationUser", "Author")
.WithMany("Articles")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Wave.Data.ApplicationUser", "Reviewer")
.WithMany()
.HasForeignKey("ReviewerId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("Author");
b.Navigation("Reviewer");
});
modelBuilder.Entity("Wave.Data.ArticleCategory", b =>
{
b.HasOne("Wave.Data.Article", "Article")
.WithMany()
.HasForeignKey("ArticleId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("Wave.Data.Category", "Category")
.WithMany()
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.Navigation("Article");
b.Navigation("Category");
});
modelBuilder.Entity("Wave.Data.ArticleImage", b =>
{
b.HasOne("Wave.Data.Article", null)
.WithMany("Images")
.HasForeignKey("ArticleId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Wave.Data.EmailNewsletter", b =>
{
b.HasOne("Wave.Data.Article", "Article")
.WithOne()
.HasForeignKey("Wave.Data.EmailNewsletter", "ArticleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Article");
});
modelBuilder.Entity("Wave.Data.ProfilePicture", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithOne("ProfilePicture")
.HasForeignKey("Wave.Data.ProfilePicture", "ApplicationUserId")
.OnDelete(DeleteBehavior.SetNull);
});
modelBuilder.Entity("Wave.Data.UserLink", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany("Links")
.HasForeignKey("ApplicationUserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Wave.Data.ApiKey", b =>
{
b.Navigation("ApiClaims");
});
modelBuilder.Entity("Wave.Data.ApplicationUser", b =>
{
b.Navigation("Articles");
b.Navigation("Links");
b.Navigation("ProfilePicture");
});
modelBuilder.Entity("Wave.Data.Article", b =>
{
b.Navigation("Images");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Wave.Data.Migrations.postgres;
/// <inheritdoc />
public partial class Article_CanBePublic_Computed : Migration {
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) {
migrationBuilder.AddColumn<bool>(
name: "CanBePublic",
table: "Articles",
type: "boolean",
nullable: false,
computedColumnSql: "\"IsDeleted\" = false AND \"Status\" = 2",
stored: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) {
migrationBuilder.DropColumn(
name: "CanBePublic",
table: "Articles");
}
}

View file

@ -167,4 +167,10 @@
<data name="Image_CopyLink" xml:space="preserve"> <data name="Image_CopyLink" xml:space="preserve">
<value>Link Kopieren</value> <value>Link Kopieren</value>
</data> </data>
<data name="Slug_Label" xml:space="preserve">
<value>Artikel URL (autogeneriert)</value>
</data>
<data name="Slug_Placeholder" xml:space="preserve">
<value>mein-neues-kaesekuchenrezept</value>
</data>
</root> </root>

View file

@ -167,4 +167,10 @@
<data name="Image_CopyLink" xml:space="preserve"> <data name="Image_CopyLink" xml:space="preserve">
<value>Copy Link</value> <value>Copy Link</value>
</data> </data>
<data name="Slug_Label" xml:space="preserve">
<value>Article Url Part (autogenerated)</value>
</data>
<data name="Slug_Placeholder" xml:space="preserve">
<value>my-new-cheese-cake-recipe</value>
</data>
</root> </root>

View file

@ -98,15 +98,15 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="Author" xml:space="preserve"> <data name="Author" xml:space="preserve">
<value>Autor*in</value> <value>Autor:in</value>
</data> </data>
<data name="ModifiedOn" xml:space="preserve"> <data name="ModifiedOn" xml:space="preserve">
<value>Geändert</value> <value>Geändert</value>
</data> </data>
<data name="Reviewer" xml:space="preserve"> <data name="Reviewer" xml:space="preserve">
<value>Rezensent*in</value> <value>Rezensent:in</value>
</data> </data>
<data name="NotFound_Title" xml:space="preserve"> <data name="NotFound_Title" xml:space="preserve">
<value>Artikel nicht gefunden</value> <value>Artikel nicht gefunden</value>
</data> </data>
@ -152,4 +152,10 @@
<data name="Review_Reviewer_Any" xml:space="preserve"> <data name="Review_Reviewer_Any" xml:space="preserve">
<value>Jeder</value> <value>Jeder</value>
</data> </data>
<data name="AboutAuthor_Title" xml:space="preserve">
<value>Über die verfassende Person</value>
</data>
<data name="Recommendations_Title" xml:space="preserve">
<value>Das könnte Sie auch interessieren</value>
</data>
</root> </root>

View file

@ -152,4 +152,10 @@
<data name="Review_Reviewer_Any" xml:space="preserve"> <data name="Review_Reviewer_Any" xml:space="preserve">
<value>Anyone</value> <value>Anyone</value>
</data> </data>
<data name="AboutAuthor_Title" xml:space="preserve">
<value>About the Author</value>
</data>
<data name="Recommendations_Title" xml:space="preserve">
<value>This might also interest you</value>
</data>
</root> </root>

View file

@ -13,15 +13,16 @@ public class ImageService(ILogger<ImageService> logger) {
return File.Exists(path) ? path : null; return File.Exists(path) ? path : null;
} }
public async Task<byte[]> GetResized(string path, int size) { public async Task<byte[]> GetResized(string path, int size, bool enforceSize = false, CancellationToken cancellation = default) {
var image = new MagickImage(path); var image = new MagickImage(path);
image.Resize(new MagickGeometry(size)); image.Resize(new MagickGeometry(size));
if (enforceSize) image.Extent(new MagickGeometry(size), Gravity.Center, MagickColors.Black);
using var memory = new MemoryStream(); using var memory = new MemoryStream();
await image.WriteAsync(memory); await image.WriteAsync(memory, cancellation);
return memory.ToArray(); return memory.ToArray();
} }
public async ValueTask<Guid?> StoreImageAsync(string temporaryPath, int size = 800, public async ValueTask<Guid?> StoreImageAsync(string temporaryPath, int size = 800, bool enforceSize = false,
CancellationToken cancellation = default) { CancellationToken cancellation = default) {
if (File.Exists(temporaryPath) is not true) return null; if (File.Exists(temporaryPath) is not true) return null;
@ -33,6 +34,7 @@ public class ImageService(ILogger<ImageService> logger) {
// Jpeg with 90% compression should look decent // Jpeg with 90% compression should look decent
image.Resize(new MagickGeometry(size)); // this preserves aspect ratio image.Resize(new MagickGeometry(size)); // this preserves aspect ratio
if (enforceSize) image.Extent(new MagickGeometry(size), Gravity.Center, MagickColors.Black);
image.Format = MagickFormat.Jpeg; image.Format = MagickFormat.Jpeg;
image.Quality = 90; image.Quality = 90;

File diff suppressed because one or more lines are too long