Refactor & code cleanup

This commit is contained in:
Laura Hausmann 2022-11-26 13:23:58 +01:00
parent 9c9dd44d81
commit f18811741c
Signed by: zotan
GPG Key ID: D044E84C5BE01605
26 changed files with 87 additions and 62 deletions

View File

@ -1,13 +1,15 @@
using LinqToDB;
using LinqToDB.Data;
using zotanpw_web.database;
using zotanpw_web.database.Tables;
using zotanpw.Backend.database;
using zotanpw.Backend.database.Tables;
namespace zotanpw_web;
namespace zotanpw.Backend;
public static class Migrations {
private const int DbVer = 1;
// ReSharper disable once CollectionNeverUpdated.Local
// ReSharper disable once InconsistentNaming
private static readonly List<Migration> _migrations = new();
public static void RunMigrations() {
@ -87,4 +89,4 @@ public static class Migrations {
db.Execute(_sql);
}
}
}
}

View File

@ -1,14 +1,13 @@
using LinqToDB.Data;
using Microsoft.AspNetCore.StaticFiles;
using zotanpw_web;
using zotanpw_web.database;
using zotanpw.Backend;
using zotanpw.Backend.database;
DataConnection.DefaultSettings = new Database.Settings();
Migrations.RunMigrations();
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddSession(options => {
options.IdleTimeout = TimeSpan.MaxValue;
@ -25,10 +24,8 @@ builder.Services.AddControllers();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) {
app.UseExceptionHandler("/error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

View File

@ -1,6 +1,6 @@
using System.Reflection;
namespace zotanpw_web;
namespace zotanpw.Backend;
public static class Utils {
public static readonly string Version =

View File

@ -1,9 +1,9 @@
using LinqToDB;
using LinqToDB.Configuration;
using LinqToDB.Data;
using zotanpw_web.database.Tables;
using zotanpw.Backend.database.Tables;
namespace zotanpw_web.database;
namespace zotanpw.Backend.database;
public class Database {
private class ConnectionStringSettings : IConnectionStringSettings {

View File

@ -2,7 +2,7 @@ using LinqToDB.Mapping;
#pragma warning disable CS8618
namespace zotanpw_web.database.Tables;
namespace zotanpw.Backend.database.Tables;
[Table(Name = "AlbumHistory")]
public class AlbumHistoryEntry {

View File

@ -1,6 +1,6 @@
using LinqToDB.Mapping;
namespace zotanpw_web.database.Tables;
namespace zotanpw.Backend.database.Tables;
[Table(Name = "DbInfo")]
public class DbInfo {

View File

@ -2,7 +2,7 @@ using LinqToDB.Mapping;
#pragma warning disable CS8618
namespace zotanpw_web.database.Tables;
namespace zotanpw.Backend.database.Tables;
[Table(Name = "PlaylistHistory")]
public class PlaylistHistoryEntry {

View File

@ -1,6 +1,6 @@
using LinqToDB.Mapping;
namespace zotanpw_web.database.Tables;
namespace zotanpw.Backend.database.Tables;
[Table(Name = "Travelynx")]
public class TravelynxInfo {

View File

@ -1,13 +1,15 @@
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
using Microsoft.AspNetCore.Mvc;
using zotanpw.Pages.blog;
using J = System.Text.Json.Serialization.JsonPropertyNameAttribute;
namespace zotanpw_web.Pages.blog;
namespace zotanpw.Controllers;
[ApiController, Route("/blog/feed.json")]
public class JsonFeed : Controller {
public static readonly JsonFeedObject Feedobj = new JsonFeedObject {
Items = BlogModel.Posts.Take(10).Select(post => new JsonFeedItem(post.Shorthand, $"https://zotan.pw/blog/{post.Shorthand}", post.Title, post.Content,
post.PublishedOn.ToDateTime(TimeOnly.MinValue).ToString("yyyy-MM-ddT00:00:00Z")))
private static readonly JsonFeedObject Feedobj = new() {
Items = BlogModel.Posts.Take(10)
.Select(post => new JsonFeedItem(post.Shorthand, $"https://zotan.pw/blog/{post.Shorthand}", post.Title, post.Content,
post.PublishedOn.ToDateTime(TimeOnly.MinValue).ToString("yyyy-MM-ddT00:00:00Z")))
.ToList()
};
@ -17,6 +19,8 @@ public class JsonFeed : Controller {
return Feedobj;
}
// Auto-generated JSON mapping
// ReSharper disable All
public class JsonFeedObject {
[J("version")] public string Version => "https://jsonfeed.org/version/1.1";
[J("language")] public string Language => "en";

View File

@ -1,9 +1,9 @@
using LinqToDB;
using Microsoft.AspNetCore.Mvc;
using zotanpw_web.database;
using zotanpw_web.database.Tables;
using zotanpw.Backend.database;
using zotanpw.Backend.database.Tables;
namespace zotanpw_web.PlaybackHistory;
namespace zotanpw.Controllers.PlaybackHistory;
[ApiController, Route("/np/log")]
public class LogPlayback : Controller {
@ -38,4 +38,4 @@ public class LogPlayback : Controller {
Response.StatusCode = 403;
return null!;
}
}
}

View File

@ -1,8 +1,11 @@
namespace zotanpw_web.PlaybackHistory;
// Auto-generated JSON mapping
// ReSharper disable All
namespace zotanpw.Controllers.PlaybackHistory;
public class LogPlaybackRequest {
public string? Artist { get; set; }
public string? Title { get; set; }
public string? Source { get; set; }
public string? Link { get; set; }
}
}

View File

@ -1,16 +1,16 @@
using LinqToDB;
using Microsoft.AspNetCore.Mvc;
using zotanpw_web.database;
using zotanpw_web.database.Tables;
using zotanpw.Backend.database;
using zotanpw.Backend.database.Tables;
namespace zotanpw_web.Travelynx;
namespace zotanpw.Controllers.Travelynx;
[ApiController, Route("/travelynx")]
public class Travelynx : Controller {
private static readonly string TravelynxSecret = System.IO.File.ReadAllLines(".bearer_token")[0];
[HttpPost]
public TravelynxInfo Update([FromBody] WebhookRequest rq) {
public TravelynxInfo Update([FromBody] TravelynxWebhookRequest rq) {
var token = Request.Headers.Authorization;
if (token == TravelynxSecret) {
var db = new Database.DbConn();

View File

@ -1,6 +1,9 @@
namespace zotanpw_web.Travelynx;
// Auto-generated JSON mapping
// ReSharper disable All
public class WebhookRequest {
namespace zotanpw.Controllers.Travelynx;
public class TravelynxWebhookRequest {
public string? Reason { get; set; }
public Status? Status { get; set; }
}

View File

@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Mvc;
namespace zotanpw_web.well_known;
namespace zotanpw.Controllers.well_known;
[ApiController, Route("/.well-known/pronouns")]
public class Pronouns : Controller {
[HttpGet]
public string Get() => "she/they\n";
}
}

View File

@ -2,7 +2,7 @@ using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace zotanpw_web.Pages;
namespace zotanpw.Pages;
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), IgnoreAntiforgeryToken]
public class ErrorModel : PageModel {

View File

@ -1,5 +1,5 @@
@page
@using zotanpw_web.database
@using zotanpw.Backend.database
@model IndexModel
@{
ViewData["title"] = "home";
@ -154,4 +154,4 @@
@section postfooter {
<img src="/files/help.svg" height="450rem" title="Designed by someone I love, ~fr2">
}
}

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace zotanpw_web.Pages;
namespace zotanpw.Pages;
public class IndexModel : PageModel {
private readonly ILogger<IndexModel> _logger;

View File

@ -1,5 +1,5 @@
@page "/np"
@using zotanpw_web.database
@using zotanpw.Backend.database
@model NowPlayingModel
@{
@ -25,4 +25,4 @@
</td>
</tr>
}
</table>
</table>

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace zotanpw_web.Pages;
namespace zotanpw.Pages;
public class NowPlayingModel : PageModel {
public void OnGet() { }

View File

@ -1,4 +1,5 @@
<!DOCTYPE html>
@using zotanpw.Backend
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
@ -52,4 +53,4 @@
@await RenderSectionAsync("postfooter", false)
</div>
</body>
</html>
</html>

View File

@ -1,3 +1,2 @@
@using zotanpw_web
@namespace zotanpw_web.Pages
@namespace zotanpw.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace zotanpw_web.Pages.blog;
namespace zotanpw.Pages.blog;
public class BlogModel : PageModel {
public static readonly List<BlogPost> Posts = new();

View File

@ -1,4 +1,5 @@
@page "/blog/{post}"
@using zotanpw.Backend
@{
if (string.IsNullOrWhiteSpace((string)RouteData.Values["post"]!)) {

View File

@ -7,14 +7,21 @@ date: 2022-11-20
I cannot and likely will never be able to comprehend the hate that so many people feel for what we are.
But thats not what matters today. What matters today is that were still fighting, were still here, and well keep building each other up when were feeling down. And well continue to fight, together. As a community. Because if theres one thing I want, is to not have to light more candles next year.
But thats not what matters today. What matters today is that were still fighting, were still here, and well keep
building each other up when were feeling down. And well continue to fight, together. As a community. Because if
theres one thing I want, is to not have to light more candles next year.
Today is trans day of remembrance, trans day of resistance, trans day of revenge, whatever you want to call it. Because we must never lose sight of what weve lost, and never lose sight of what were fighting for. A better future for trans people everywhere. Because we shouldnt just get to survive, we should get to thrive, even in this godforsaken world thats falling apart.
Today is trans day of remembrance, trans day of resistance, trans day of revenge, whatever you want to call it. Because
we must never lose sight of what weve lost, and never lose sight of what were fighting for. A better future for trans
people everywhere. Because we shouldnt just get to survive, we should get to thrive, even in this godforsaken world
thats falling apart.
So lets stick together and keep going. Keep being there for each other. Keep being the community thats become the first place that truly felt like home to me, the first place that I've ever truly felt safe in.
So lets stick together and keep going. Keep being there for each other. Keep being the community thats become the
first place that truly felt like home to me, the first place that I've ever truly felt safe in.
[#np](/np) Amethystium - Transience - Epilogue
In the last year too many trans lives ended early. I feel like this track carries the emotion of grief I am feeling today.
In the last year too many trans lives ended early. I feel like this track carries the emotion of grief I am feeling
today.
And now, [#np](/np) Left at London - t.i.a.p.f.y.h.
And now, [#np](/np) Left at London - t.i.a.p.f.y.h.

View File

@ -1,4 +1,6 @@
## zotan.pw-web
The source code powering my website and blog engine.
Likely not useful without substantial modification, but open source to simplify deployment and allow people to take inspiration.
Likely not useful without substantial modification, but open source to simplify deployment and allow people to take
inspiration.

View File

@ -4,25 +4,31 @@
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>zotanpw_web</RootNamespace>
<RootNamespace>zotanpw</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="linq2db" Version="4.3.0" />
<PackageReference Include="Markdig" Version="0.30.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0" />
<PackageReference Include="System.Data.SQLite" Version="1.0.115" />
<PackageReference Include="YamlDotNet" Version="12.0.2" />
<PackageReference Include="linq2db" Version="4.3.0"/>
<PackageReference Include="Markdig" Version="0.30.4"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.0"/>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.0"/>
<PackageReference Include="System.Data.SQLite" Version="1.0.115"/>
<PackageReference Include="YamlDotNet" Version="12.0.2"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Pages\blog\posts" />
<Folder Include="Pages\blog\posts"/>
</ItemGroup>
<ItemGroup>
<None Remove=".gitignore"/>
<None Remove=".bearer_token"/>
<None Remove="database.db"/>
</ItemGroup>
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec Command="git describe --long --always --dirty --exclude=* --abbrev=8" ConsoleToMSBuild="True" IgnoreExitCode="False">
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput" />
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput"/>
</Exec>
</Target>