Code cleanup, 2022 edition
This commit is contained in:
parent
a5f66216c9
commit
b3ed309192
|
@ -1,8 +1,8 @@
|
|||
using LinqToDB.Mapping;
|
||||
|
||||
namespace RTMPDash.DataModels.Tables {
|
||||
namespace RTMPDash.DataModels.Tables;
|
||||
|
||||
[Table(Name = "Invites")]
|
||||
public class Invite {
|
||||
[Column(Name = "Code"), PrimaryKey, NotNull] public string Code { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public class ContentModel : PageModel {
|
||||
public void OnGet() { }
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public class CreditsModel : PageModel {
|
||||
public void OnGet() { }
|
||||
}
|
||||
}
|
|
@ -2,7 +2,8 @@ using System.Diagnostics;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel {
|
||||
public string RequestId { get; set; }
|
||||
|
@ -13,4 +14,3 @@ namespace RTMPDash.Pages {
|
|||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public class IndexModel : PageModel {
|
||||
public void OnGet() { }
|
||||
}
|
||||
}
|
|
@ -8,17 +8,15 @@ using Microsoft.AspNetCore.Http;
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using RTMPDash.DataModels;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public class LoginModel : PageModel {
|
||||
public void OnPost() {
|
||||
if (!Request.HasFormContentType
|
||||
|| string.IsNullOrWhiteSpace(Request.Form["user"])
|
||||
|| string.IsNullOrWhiteSpace(Request.Form["pass"]))
|
||||
if (!Request.HasFormContentType || string.IsNullOrWhiteSpace(Request.Form["user"]) || string.IsNullOrWhiteSpace(Request.Form["pass"]))
|
||||
return;
|
||||
|
||||
using var db = new AppDb.DbConn();
|
||||
var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString()
|
||||
&& p.Password == Request.Form["pass"].ToString().Sha256());
|
||||
var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString() && p.Password == Request.Form["pass"].ToString().Sha256());
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
|
@ -55,8 +53,7 @@ namespace RTMPDash.Pages {
|
|||
|
||||
public static string UrlEncode(this string plainText) => HttpUtility.UrlEncode(plainText);
|
||||
|
||||
public static string Delimit(this string input, int max) =>
|
||||
input.PadRight(max, ' ').Substring(0, max).TrimEnd();
|
||||
public static string Delimit(this string input, int max) => input.PadRight(max, ' ').Substring(0, max).TrimEnd();
|
||||
|
||||
public static string Bash(this string cmd) {
|
||||
var escapedArgs = cmd.Replace("\"", "\\\"");
|
||||
|
@ -76,4 +73,3 @@ namespace RTMPDash.Pages {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public class LogoutModel : PageModel {
|
||||
public void OnGet() {
|
||||
HttpContext.Session.Clear();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public class PrivacyModel : PageModel {
|
||||
public void OnGet() { }
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public class StatsModel : PageModel {
|
||||
public void OnGet() { }
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public class ProfileModel : PageModel {
|
||||
public new string User { get; set; }
|
||||
|
||||
|
@ -8,4 +9,3 @@ namespace RTMPDash.Pages {
|
|||
User = user;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"anonymousAuthentication": true
|
||||
},
|
||||
"profiles": {
|
||||
"RTMPDash": {
|
||||
|
|
|
@ -14,6 +14,60 @@
|
|||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="Areas\Identity\Pages\_ViewStart.cshtml"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\css\dark-mode.css"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\css\site.css"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\favicon.ico"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\js\dark-mode-switch.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\js\site.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-grid.css"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-grid.css.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-grid.min.css"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-grid.min.css.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-reboot.css"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-reboot.css.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-reboot.min.css"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap-reboot.min.css.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap.css"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap.css.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap.min.css"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\css\bootstrap.min.css.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.js.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.min.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\js\bootstrap.bundle.min.js.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\js\bootstrap.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\js\bootstrap.js.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\js\bootstrap.min.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\dist\js\bootstrap.min.js.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\bootstrap\LICENSE"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation-unobtrusive\jquery.validate.unobtrusive.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation-unobtrusive\jquery.validate.unobtrusive.min.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation-unobtrusive\LICENSE.txt"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\dist\additional-methods.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\dist\additional-methods.min.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\dist\jquery.validate.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\dist\jquery.validate.min.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery-validation\LICENSE.md"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery\dist\jquery.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery\dist\jquery.min.js"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery\dist\jquery.min.map"/>
|
||||
<_ContentIncludedByDefault Remove="wwwroot\lib\jquery\LICENSE.txt"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="wwwroot\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Remove="wwwroot\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="wwwroot\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="wwwroot\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,7 +5,8 @@ using Microsoft.Extensions.Configuration;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace RTMPDash {
|
||||
namespace RTMPDash;
|
||||
|
||||
public class Startup {
|
||||
public Startup(IConfiguration configuration) => Configuration = configuration;
|
||||
|
||||
|
@ -62,4 +63,3 @@ namespace RTMPDash {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,33 +4,26 @@ using System.Net;
|
|||
using System.Xml.Serialization;
|
||||
using RTMPDash.DataModels;
|
||||
|
||||
namespace RTMPDash {
|
||||
namespace RTMPDash;
|
||||
|
||||
public static class StreamUtils {
|
||||
private static readonly XmlSerializer Serializer = new(typeof(StatsObject));
|
||||
|
||||
public static bool IsLive(string user, StatsObject stats) => stats.Server.Applications
|
||||
.First(p => p.Name == "ingress")
|
||||
.MethodLive.Streams.Any(p => p.Name == user);
|
||||
public static bool IsLive(string user, StatsObject stats) => stats.Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.Any(p => p.Name == user);
|
||||
|
||||
public static bool IsLive(string user, string target, StatsObject stats) => stats.Server.Applications
|
||||
.First(p => p.Name == "ingress")
|
||||
public static bool IsLive(string user, string target, StatsObject stats) => stats.Server.Applications.First(p => p.Name == "ingress")
|
||||
.MethodLive.Streams
|
||||
.Any(p => p.Name == user && p.Clients.Any(c => c.Address == target.Replace("rtmp://", "")));
|
||||
|
||||
public static long GetClientTime(string user, StatsObject stats) =>
|
||||
long.Parse(stats.Server.Applications.First(p => p.Name == "ingress")
|
||||
.MethodLive.Streams.First(p => p.Name == user)
|
||||
.Time);
|
||||
long.Parse(stats.Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.First(p => p.Name == user).Time);
|
||||
|
||||
public static int CountLiveRestreams(string user, StatsObject stats) {
|
||||
var db = new AppDb.DbConn();
|
||||
var dbUser = db.Users.First(p => p.Username == user);
|
||||
return dbUser.RestreamTargets.Split(",")
|
||||
.Count(target => stats.Server.Applications.First(p => p.Name == "ingress")
|
||||
.MethodLive.Streams
|
||||
.Any(p => p.Name == user
|
||||
&& p.Clients.Any(c => c.Address
|
||||
== target.Replace("rtmp://", ""))));
|
||||
.MethodLive.Streams.Any(p => p.Name == user && p.Clients.Any(c => c.Address == target.Replace("rtmp://", ""))));
|
||||
}
|
||||
|
||||
public static int CountLiveRestreams(string user, string privateAccesskey, StatsObject stats) {
|
||||
|
@ -38,17 +31,10 @@ namespace RTMPDash {
|
|||
var dbUser = db.Users.First(p => p.Username == user);
|
||||
return dbUser.RestreamTargets.Split(",")
|
||||
.Count(target => stats.Server.Applications.First(p => p.Name == "ingress")
|
||||
.MethodLive.Streams
|
||||
.Any(p => p.Name == privateAccesskey
|
||||
&& p.Clients.Any(c => c.Address
|
||||
== target.Replace("rtmp://", ""))));
|
||||
.MethodLive.Streams.Any(p => p.Name == privateAccesskey && p.Clients.Any(c => c.Address == target.Replace("rtmp://", ""))));
|
||||
}
|
||||
|
||||
|
||||
public static List<string> ListLiveUsers() => GetStatsObject()
|
||||
.Server.Applications.First(p => p.Name == "ingress")
|
||||
.MethodLive.Streams.Select(p => p.Name)
|
||||
.ToList();
|
||||
public static List<string> ListLiveUsers() => GetStatsObject().Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.Select(p => p.Name).ToList();
|
||||
|
||||
public static StatsObject GetStatsObject() {
|
||||
var obj = (StatsObject)Serializer.Deserialize(new WebClient().OpenRead("http://127.0.0.1:8080")!);
|
||||
|
@ -151,4 +137,3 @@ namespace RTMPDash {
|
|||
[XmlElement(ElementName = "channels", IsNullable = true)] public string Channels { get; set; }
|
||||
[XmlElement(ElementName = "sample_rate", IsNullable = true)] public string SampleRate { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue