Compare commits

..

No commits in common. "c50fc079fd4541622d1cf42e6022f8267b510a81" and "f84fd9e53683f907b0b76c5ffca40110677641bc" have entirely different histories.

22 changed files with 64 additions and 897 deletions

View file

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

View file

@ -10,7 +10,6 @@
<div class="card-body">
<h2 class="card-title line-clamp-1">@Article.Title</h2>
<small>
@Article.Author.Name
@Article.PublishDate.ToString("d")
@if (Article.Status is not ArticleStatus.Published) {
<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">
</figure>
<div class="card-body sm:border-l-2 border-current">
<h2 class="card-title">@Localizer["AboutAuthor_Title"]</h2>
<h2 class="card-title">About The Author</h2>
<h3><strong>@Article.Author.Name</strong></h3>
<p>
@Article.Author.AboutTheAuthor
@ -90,8 +90,6 @@
}
</div>
@AdditionalContent
<template id="copyButtonTemplate">
<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">
@ -122,6 +120,4 @@
[Parameter]
public required Article Article { get; set; }
private MarkupString Content => new(Article.BodyHtml);
[Parameter]
public RenderFragment? AdditionalContent { get; set; }
}

View file

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

View file

@ -87,10 +87,7 @@
<div class="bg-base-200 p-4 h-full flex flex-col gap-4 w-48 lg:w-64">
<NavMenu />
@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>
}
<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>

View file

@ -4,7 +4,6 @@
@using Wave.Data
@using System.Security.Claims
@using System.Globalization
@using System.Net
@using Microsoft.AspNetCore.Identity
@using Microsoft.Extensions.Options
@using Wave.Services
@ -54,15 +53,7 @@
<ErrorBoundary>
<ChildContent>
@if (GetArticle(HttpContext.User) is {} article) {
<ArticleComponent Article="@article">
<AdditionalContent>
@if (Recommendations.Count > 0) {
<h2 class="text-3xl my-6">@Localizer["Recommendations_Title"]</h2>
<ArticleCardList Articles="Recommendations" />
}
</AdditionalContent>
</ArticleComponent>
<ArticleComponent Article="@article"/>
<div class="flex gap-2 mt-3 flex-wrap">
@if (article.AllowedToEdit(HttpContext.User)) {
@ -165,7 +156,6 @@
public HttpContext HttpContext { get; set; } = default!;
private List<ApplicationUser> Reviewers { get; } = [];
private List<Article> Recommendations { get; } = [];
private Article GetArticle(ClaimsPrincipal principal) {
if (Article.AllowedToRead(principal)) return Article!;
@ -191,53 +181,13 @@
a.PublishDate.Date == date.Date
&& (slug != null && a.Slug == slug || a.Title.ToLower() == title));
}
if (Article is null) {
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
}
}
protected override async Task OnInitializedAsync() {
if (Article is null) return;
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));
}
Reviewers.AddRange([
.. await UserManager.GetUsersInRoleAsync("Reviewer"),
.. await UserManager.GetUsersInRoleAsync("Admin")
]);
}
private async Task SubmitForReview() {

View file

@ -27,8 +27,8 @@
<a class="btn btn-primary" href="/">@Localizer["NotFound_BackToHome_Label"]</a>
} else {
<h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["Title"] - @Category.Name</h1>
<ArticleCardList Articles="Category.Articles.Where(a => !a.IsDeleted && a.PublishDate <= DateTimeOffset.Now).ToList()" />
<ArticleCardList Articles="Category.Articles" />
}
@code {
@ -42,13 +42,22 @@
protected override async Task OnInitializedAsync() {
await using var context = await ContextFactory.CreateDbContextAsync();
string category = WebUtility.UrlDecode(CategoryName);
if (Category != null) return;
var now = DateTimeOffset.UtcNow;
// 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>()
.IgnoreAutoIncludes()
.Include(c => c.Articles).ThenInclude(a => a.Categories)
.Include(c => c.Articles).ThenInclude(a => a.Author)
.AsSplitQuery()
.IgnoreAutoIncludes().IgnoreQueryFilters()
.Include(c => c.Articles.Where(a => !a.IsDeleted && a.PublishDate <= now))
.ThenInclude(a => a.Author)
.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,7 +3,6 @@
@using System.Diagnostics.CodeAnalysis
@using System.Net
@using System.Security.Claims
@using Humanizer
@using Microsoft.AspNetCore.Identity
@using Microsoft.EntityFrameworkCore
@using Wave.Services
@ -35,18 +34,6 @@
@bind-Value="@Model.Title" placeholder="@Localizer["Title_Placeholder"]" autocomplete="off"/>
</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">
@if (Article.Status is not ArticleStatus.Published || Article.PublishDate >= DateTimeOffset.UtcNow) {
<InputText class="input input-bordered w-full" maxlength="64"
@ -66,6 +53,13 @@
type="datetime-local" readonly value="@Article.PublishDate.ToString("yyyy-MM-dd\\THH:mm:ss")"/>
}
</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>
<AdvancedMarkdownEditor Title="@Model.Title" MarkdownCallback="() => Model.Body">
@ -162,9 +156,7 @@
Model.Slug ??= article.Slug;
Model.Body ??= article.Body;
Model.PublishDate ??= article.PublishDate.LocalDateTime;
if (Model.Categories?.Length < 1) {
Model.Categories = article.Categories.Select(c => c.Id).ToArray();
}
Model.Categories ??= article.Categories.Select(c => c.Id).ToArray();
Article = article;
await InvokeAsync(StateHasChanged);
}
@ -218,6 +210,7 @@
await context.Set<ArticleCategory>().IgnoreQueryFilters().IgnoreAutoIncludes()
.Where(ac => ac.Article.Id == Article.Id).LoadAsync();
Model.Categories ??= [];
context.Update(Article);
var existingImages = await context.Set<Article>()
@ -287,7 +280,12 @@
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) {
Article.Images.Add(image);
await InvokeAsync(StateHasChanged);
@ -308,7 +306,7 @@
[Required(AllowEmptyStrings = false)]
public string? Body { get; set; }
public Guid[]? Categories { get; set; } = [];
public Guid[]? Categories { get; set; }
public DateTimeOffset? PublishDate { get; set; }
}

View file

@ -89,17 +89,20 @@
private ApplicationUser? User { get; set; }
protected override async Task OnInitializedAsync() {
if (User is not null) return;
await using var context = await ContextFactory.CreateDbContextAsync();
// Find user
if (Id is not null) {
var now = DateTimeOffset.UtcNow;
User = await context.Users
.IgnoreAutoIncludes()
.Include(u => u.Links)
.Include(u => u.Articles).ThenInclude(a => a.Categories)
.AsSplitQuery()
.IgnoreAutoIncludes().IgnoreQueryFilters()
.Include(u => u.Articles.Where(a => !a.IsDeleted && a.PublishDate <= now))
.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

View file

@ -1,10 +1,9 @@
@using Wave.Data
@using System.Net
@using System.Text.RegularExpressions
<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" />
@Regex.Replace(Link.Url.Host, @"(www\.|.de|.com)", "", RegexOptions.Compiled | RegexOptions.IgnoreCase)
@(Link.Url.Host.LastIndexOf('.') > -1 ? Link.Url.Host[..Link.Url.Host.LastIndexOf('.')] : Link.Url.Host)
</a>
@code {

View file

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

View file

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

View file

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

View file

@ -325,11 +325,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.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")

View file

@ -1,716 +0,0 @@
// <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

@ -1,26 +0,0 @@
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,10 +167,4 @@
<data name="Image_CopyLink" xml:space="preserve">
<value>Link Kopieren</value>
</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>

View file

@ -167,10 +167,4 @@
<data name="Image_CopyLink" xml:space="preserve">
<value>Copy Link</value>
</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>

View file

@ -98,15 +98,15 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Author" xml:space="preserve">
<value>Autor:in</value>
</data>
<data name="Author" xml:space="preserve">
<value>Autor*in</value>
</data>
<data name="ModifiedOn" xml:space="preserve">
<value>Geändert</value>
</data>
<data name="Reviewer" xml:space="preserve">
<value>Rezensent:in</value>
</data>
<data name="Reviewer" xml:space="preserve">
<value>Rezensent*in</value>
</data>
<data name="NotFound_Title" xml:space="preserve">
<value>Artikel nicht gefunden</value>
</data>
@ -152,10 +152,4 @@
<data name="Review_Reviewer_Any" xml:space="preserve">
<value>Jeder</value>
</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>

View file

@ -152,10 +152,4 @@
<data name="Review_Reviewer_Any" xml:space="preserve">
<value>Anyone</value>
</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>

View file

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

File diff suppressed because one or more lines are too long