From 294e50409cc851906660e074c97eeb7b38de0930 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 4 Feb 2022 05:55:27 +0100 Subject: [PATCH] Allow database init from scratch; add pronoun plurality attribute --- DataModels/Tables/User.cs | 3 ++- Migrations.cs | 44 ++++++++++++++++++++++++++++++++++----- Pages/Dashboard.cshtml | 20 ++++++++++++++++++ Pages/Dashboard.cshtml.cs | 16 +++++++++++++- Pages/Register.cshtml.cs | 3 ++- Pages/profile.cshtml | 2 +- README.md | 13 ++++++++---- 7 files changed, 88 insertions(+), 13 deletions(-) diff --git a/DataModels/Tables/User.cs b/DataModels/Tables/User.cs index 7644938..f910c03 100644 --- a/DataModels/Tables/User.cs +++ b/DataModels/Tables/User.cs @@ -1,6 +1,6 @@ using LinqToDB.Mapping; -namespace RTMPDash.DataModels.Tables; +namespace RTMPDash.DataModels.Tables; [Table(Name = "Users")] public class User { @@ -17,4 +17,5 @@ public class User { [Column(Name = "RestreamUrls")] public string RestreamUrls { get; set; } [Column(Name = "IsPrivate")] public bool IsPrivate { get; set; } [Column(Name = "PrivateAccessKey")] public string PrivateAccessKey { get; set; } + [Column(Name = "PronounPlural")] public bool PronounPlural { get; set; } } \ No newline at end of file diff --git a/Migrations.cs b/Migrations.cs index 88bd309..20a092d 100644 --- a/Migrations.cs +++ b/Migrations.cs @@ -5,6 +5,7 @@ using LinqToDB; using LinqToDB.Data; using RTMPDash.DataModels; using RTMPDash.DataModels.Tables; +using RTMPDash.Pages; namespace RTMPDash; @@ -13,22 +14,55 @@ namespace RTMPDash; * * */ public static class Migrations { - public const int DbVer = 1; + public const int DbVer = 2; private static readonly List _migrations = new() { - new Migration(1, "ALTER TABLE Users ADD IsPrivate INTEGER DEFAULT 0 NOT NULL"), new Migration(1, "ALTER TABLE Users ADD PrivateAccessKey TEXT") + new Migration(1, "ALTER TABLE Users ADD IsPrivate INTEGER DEFAULT 0 NOT NULL"), + new Migration(1, "ALTER TABLE Users ADD PrivateAccessKey TEXT"), + new Migration(2, "ALTER TABLE Users ADD PronounPlural INTEGER DEFAULT 0 NOT NULL"), + new Migration(2, "UPDATE Users SET PronounPlural = 1 WHERE PronounSubject = 'they'") }; public static void RunMigrations() { - using var db = new AppDb.DbConn(); + using var db = new AppDb.DbConn(); + var ccolor = Console.ForegroundColor; - if (db.DataProvider.GetSchemaProvider().GetSchema(db).Tables.All(t => t.TableName != "DbInfo")) { + if (!db.DataProvider.GetSchemaProvider().GetSchema(db).Tables.Any()) { + Console.ForegroundColor = ConsoleColor.DarkCyan; + Console.Write("Running migration: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("Initialize Database"); + + db.CreateTable(); + db.CreateTable(); + db.CreateTable(); + db.InsertWithIdentity(new DbInfo { DbVer = DbVer }); + var password = Convert.ToBase64String(Guid.NewGuid().ToByteArray())[..12]; + db.InsertWithIdentity(new User { + Username = "admin", + Password = password.Sha256(), + StreamKey = Guid.NewGuid().ToString(), + PronounSubject = "they", + PronounPossessive = "their", + PronounPlural = true, + AllowRestream = true + }); + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("The user "); + Console.ForegroundColor = ConsoleColor.DarkMagenta; + Console.Write("admin "); + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("has been created with the password "); + Console.ForegroundColor = ConsoleColor.DarkMagenta; + Console.WriteLine(password); + Console.WriteLine(); + } + else if (db.DataProvider.GetSchemaProvider().GetSchema(db).Tables.All(t => t.TableName != "DbInfo")) { db.CreateTable(); db.InsertWithIdentity(new DbInfo { DbVer = 0 }); } var dbinfo = db.DbInfo.First(); - var ccolor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Database version: {db.DbInfo.ToList().First().DbVer}"); diff --git a/Pages/Dashboard.cshtml b/Pages/Dashboard.cshtml index 9e881c7..5a31803 100644 --- a/Pages/Dashboard.cshtml +++ b/Pages/Dashboard.cshtml @@ -234,6 +234,26 @@ else { +
+
+ Pronoun (plurality) +
+ @if (user.PronounPlural) { + +
+ + +
+ } + else { + +
+ + +
+ } +
+
diff --git a/Pages/Dashboard.cshtml.cs b/Pages/Dashboard.cshtml.cs index 3f0490f..32d879d 100644 --- a/Pages/Dashboard.cshtml.cs +++ b/Pages/Dashboard.cshtml.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.RazorPages; using RTMPDash.DataModels; -namespace RTMPDash.Pages; +namespace RTMPDash.Pages; public class DashboardModel : PageModel { public void OnGet() { } @@ -68,6 +68,20 @@ public class DashboardModel : PageModel { Response.Redirect("/Dashboard"); } + if (Request.Form["action"] == "pronoun_plural") { + var target = string.IsNullOrWhiteSpace(Request.Form["value"]) ? "their" : Request.Form["value"].ToString(); + user!.PronounPlural = true; + db.Update(user); + Response.Redirect("/Dashboard"); + } + + if (Request.Form["action"] == "pronoun_singular") { + var target = string.IsNullOrWhiteSpace(Request.Form["value"]) ? "their" : Request.Form["value"].ToString(); + user!.PronounPlural = false; + db.Update(user); + Response.Redirect("/Dashboard"); + } + if (Request.Form["action"] == "streamkey_reset") { user!.StreamKey = Guid.NewGuid().ToString(); db.Update(user); diff --git a/Pages/Register.cshtml.cs b/Pages/Register.cshtml.cs index 7b3b2c1..ca8d3e4 100644 --- a/Pages/Register.cshtml.cs +++ b/Pages/Register.cshtml.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using RTMPDash.DataModels; using RTMPDash.DataModels.Tables; -namespace RTMPDash.Pages; +namespace RTMPDash.Pages; public class RegisterModel : PageModel { public void OnPost() { @@ -39,6 +39,7 @@ public class RegisterModel : PageModel { StreamKey = Guid.NewGuid().ToString(), PronounSubject = "they", PronounPossessive = "their", + PronounPlural = true, AllowRestream = true }; diff --git a/Pages/profile.cshtml b/Pages/profile.cshtml index bfabe65..e51378d 100644 --- a/Pages/profile.cshtml +++ b/Pages/profile.cshtml @@ -15,7 +15,7 @@ if (live) { stream = stats.Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.FirstOrDefault(p => p.Name == user.Username); } - var pronounAdditional = user.PronounSubject == "they" ? "are" : "is"; // TODO make this configurable too + var pronounAdditional = user.PronounPlural ? "are" : "is"; }
diff --git a/README.md b/README.md index 52f2f05..8108fbc 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,16 @@ ## Installation - Adjust all the `const`'s in Program.cs -- Copy example.db to app.db -- Create yourself a user using `sqlite3` -- Install [nginx-mod-rtmp](https://git.zotan.services/zotan/nginx-mod-rtmp) (arch package: `aur/nginx-mod-rtmp-lhaus-git`) +- Install [nginx-mod-rtmp](https://git.zotan.services/zotan/nginx-mod-rtmp) (arch + package: `aur/nginx-mod-rtmp-lhaus-git`) - Configure nginx-mod-rtmp, example config below - Install and start `redis` for persistent sessions - Start RTMPDash, example systemd unit below +- The admin user is output to stdout on first startup, if RTMPdash started with the systemd unit it will be in the + journal ## Further setup + - Customize privacy policy to your environment if you plan on hosting it publicly - Set up player, example code below @@ -57,6 +59,7 @@ rtmp { ``` ### RTMPdash example systemd unit (development) + ``` [Unit] Description=RTMPDash @@ -82,6 +85,7 @@ WantedBy=multi-user.target ``` ## RTMPdash example systemd unit (production) + ``` [Unit] Description=RTMPDash @@ -107,6 +111,7 @@ WantedBy=multi-user.target ``` ### VideoJS Player example code + ```