Allow database init from scratch; add pronoun plurality attribute

This commit is contained in:
Laura Hausmann 2022-02-04 05:55:27 +01:00
parent 59b3dc6f68
commit 294e50409c
Signed by: zotan
GPG key ID: D044E84C5BE01605
7 changed files with 88 additions and 13 deletions

View file

@ -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; }
}

View file

@ -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<Migration> _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<User>();
db.CreateTable<Invite>();
db.CreateTable<DbInfo>();
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<DbInfo>();
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}");

View file

@ -234,6 +234,26 @@ else {
</div>
</form>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" style="width:23ch">Pronoun (plurality)</span>
</div>
@if (user.PronounPlural) {
<input type="text" class="form-control" id="input-streamkey" value="@user.PronounSubject.FirstCharToUpper() (@user.Username) are live." disabled>
<div class="input-group-append">
<button class="btn btn-outline-primary" role="button" id="button-reset-streamkey" disabled>Plural</button>
<button onclick="ajax_and_reload('pronoun_singular')" class="btn btn-outline-primary" role="button" id="button-reset-streamkey">Singular</button>
</div>
}
else {
<input type="text" class="form-control" id="input-streamkey" value="@user.PronounSubject.FirstCharToUpper() (@user.Username) is live." disabled>
<div class="input-group-append">
<button onclick="ajax_and_reload('pronoun_plural')" class="btn btn-outline-primary" role="button" id="button-reset-streamkey">Plural</button>
<button class="btn btn-outline-primary" role="button" id="button-reset-streamkey" disabled>Singular</button>
</div>
}
</div>
<form method="POST">
<div class="form-group">
<label for="InputPassword">Change Password</label>

View file

@ -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);

View file

@ -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
};

View file

@ -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";
}
<div class="text-center">

View file

@ -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
```
<link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet" />
<style>
@ -128,8 +133,8 @@ player.fill(true);
</script>
```
### accompanying nginx config for VideoJS Player
```
location ~ ^/(.+)/(.+)$ {
rewrite ^/(.+)/(.+)$ /watch.php?stream=$1&profile=$2 last;