Allow database init from scratch; add pronoun plurality attribute
This commit is contained in:
parent
59b3dc6f68
commit
294e50409c
|
@ -1,6 +1,6 @@
|
||||||
using LinqToDB.Mapping;
|
using LinqToDB.Mapping;
|
||||||
|
|
||||||
namespace RTMPDash.DataModels.Tables;
|
namespace RTMPDash.DataModels.Tables;
|
||||||
|
|
||||||
[Table(Name = "Users")]
|
[Table(Name = "Users")]
|
||||||
public class User {
|
public class User {
|
||||||
|
@ -17,4 +17,5 @@ public class User {
|
||||||
[Column(Name = "RestreamUrls")] public string RestreamUrls { get; set; }
|
[Column(Name = "RestreamUrls")] public string RestreamUrls { get; set; }
|
||||||
[Column(Name = "IsPrivate")] public bool IsPrivate { get; set; }
|
[Column(Name = "IsPrivate")] public bool IsPrivate { get; set; }
|
||||||
[Column(Name = "PrivateAccessKey")] public string PrivateAccessKey { get; set; }
|
[Column(Name = "PrivateAccessKey")] public string PrivateAccessKey { get; set; }
|
||||||
|
[Column(Name = "PronounPlural")] public bool PronounPlural { get; set; }
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ using LinqToDB;
|
||||||
using LinqToDB.Data;
|
using LinqToDB.Data;
|
||||||
using RTMPDash.DataModels;
|
using RTMPDash.DataModels;
|
||||||
using RTMPDash.DataModels.Tables;
|
using RTMPDash.DataModels.Tables;
|
||||||
|
using RTMPDash.Pages;
|
||||||
|
|
||||||
namespace RTMPDash;
|
namespace RTMPDash;
|
||||||
|
|
||||||
|
@ -13,22 +14,55 @@ namespace RTMPDash;
|
||||||
* *
|
* *
|
||||||
*/
|
*/
|
||||||
public static class Migrations {
|
public static class Migrations {
|
||||||
public const int DbVer = 1;
|
public const int DbVer = 2;
|
||||||
|
|
||||||
private static readonly List<Migration> _migrations = new() {
|
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() {
|
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.CreateTable<DbInfo>();
|
||||||
db.InsertWithIdentity(new DbInfo { DbVer = 0 });
|
db.InsertWithIdentity(new DbInfo { DbVer = 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
var dbinfo = db.DbInfo.First();
|
var dbinfo = db.DbInfo.First();
|
||||||
var ccolor = Console.ForegroundColor;
|
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine($"Database version: {db.DbInfo.ToList().First().DbVer}");
|
Console.WriteLine($"Database version: {db.DbInfo.ToList().First().DbVer}");
|
||||||
|
|
|
@ -234,6 +234,26 @@ else {
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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">
|
<form method="POST">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="InputPassword">Change Password</label>
|
<label for="InputPassword">Change Password</label>
|
||||||
|
|
|
@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using RTMPDash.DataModels;
|
using RTMPDash.DataModels;
|
||||||
|
|
||||||
namespace RTMPDash.Pages;
|
namespace RTMPDash.Pages;
|
||||||
|
|
||||||
public class DashboardModel : PageModel {
|
public class DashboardModel : PageModel {
|
||||||
public void OnGet() { }
|
public void OnGet() { }
|
||||||
|
@ -68,6 +68,20 @@ public class DashboardModel : PageModel {
|
||||||
Response.Redirect("/Dashboard");
|
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") {
|
if (Request.Form["action"] == "streamkey_reset") {
|
||||||
user!.StreamKey = Guid.NewGuid().ToString();
|
user!.StreamKey = Guid.NewGuid().ToString();
|
||||||
db.Update(user);
|
db.Update(user);
|
||||||
|
|
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using RTMPDash.DataModels;
|
using RTMPDash.DataModels;
|
||||||
using RTMPDash.DataModels.Tables;
|
using RTMPDash.DataModels.Tables;
|
||||||
|
|
||||||
namespace RTMPDash.Pages;
|
namespace RTMPDash.Pages;
|
||||||
|
|
||||||
public class RegisterModel : PageModel {
|
public class RegisterModel : PageModel {
|
||||||
public void OnPost() {
|
public void OnPost() {
|
||||||
|
@ -39,6 +39,7 @@ public class RegisterModel : PageModel {
|
||||||
StreamKey = Guid.NewGuid().ToString(),
|
StreamKey = Guid.NewGuid().ToString(),
|
||||||
PronounSubject = "they",
|
PronounSubject = "they",
|
||||||
PronounPossessive = "their",
|
PronounPossessive = "their",
|
||||||
|
PronounPlural = true,
|
||||||
AllowRestream = true
|
AllowRestream = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
if (live) {
|
if (live) {
|
||||||
stream = stats.Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.FirstOrDefault(p => p.Name == user.Username);
|
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">
|
<div class="text-center">
|
||||||
|
|
13
README.md
13
README.md
|
@ -5,14 +5,16 @@
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
- Adjust all the `const`'s in Program.cs
|
- Adjust all the `const`'s in Program.cs
|
||||||
- Copy example.db to app.db
|
- Install [nginx-mod-rtmp](https://git.zotan.services/zotan/nginx-mod-rtmp) (arch
|
||||||
- Create yourself a user using `sqlite3`
|
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
|
- Configure nginx-mod-rtmp, example config below
|
||||||
- Install and start `redis` for persistent sessions
|
- Install and start `redis` for persistent sessions
|
||||||
- Start RTMPDash, example systemd unit below
|
- 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
|
## Further setup
|
||||||
|
|
||||||
- Customize privacy policy to your environment if you plan on hosting it publicly
|
- Customize privacy policy to your environment if you plan on hosting it publicly
|
||||||
- Set up player, example code below
|
- Set up player, example code below
|
||||||
|
|
||||||
|
@ -57,6 +59,7 @@ rtmp {
|
||||||
```
|
```
|
||||||
|
|
||||||
### RTMPdash example systemd unit (development)
|
### RTMPdash example systemd unit (development)
|
||||||
|
|
||||||
```
|
```
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=RTMPDash
|
Description=RTMPDash
|
||||||
|
@ -82,6 +85,7 @@ WantedBy=multi-user.target
|
||||||
```
|
```
|
||||||
|
|
||||||
## RTMPdash example systemd unit (production)
|
## RTMPdash example systemd unit (production)
|
||||||
|
|
||||||
```
|
```
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=RTMPDash
|
Description=RTMPDash
|
||||||
|
@ -107,6 +111,7 @@ WantedBy=multi-user.target
|
||||||
```
|
```
|
||||||
|
|
||||||
### VideoJS Player example code
|
### VideoJS Player example code
|
||||||
|
|
||||||
```
|
```
|
||||||
<link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet" />
|
<link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet" />
|
||||||
<style>
|
<style>
|
||||||
|
@ -128,8 +133,8 @@ player.fill(true);
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### accompanying nginx config for VideoJS Player
|
### accompanying nginx config for VideoJS Player
|
||||||
|
|
||||||
```
|
```
|
||||||
location ~ ^/(.+)/(.+)$ {
|
location ~ ^/(.+)/(.+)$ {
|
||||||
rewrite ^/(.+)/(.+)$ /watch.php?stream=$1&profile=$2 last;
|
rewrite ^/(.+)/(.+)$ /watch.php?stream=$1&profile=$2 last;
|
||||||
|
|
Loading…
Reference in a new issue