diff --git a/.dockerignore b/.dockerignore index f6396e3..2cb72bf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -23,4 +23,5 @@ **/values.dev.yaml LICENSE README.md -**/creds.json \ No newline at end of file +**/creds.json +**/*.db \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6c32a64..246107e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ ImageBoardServerApp/wwwroot/img/dynamic *.db-wal Migrations/ /ImageBoardServerApp/Data/creds.json +/ImageBoardServerApp/Data/AppDbContext.cs ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. diff --git a/ImageBoardServerApp/Data/Repository/UsersRepository.cs b/ImageBoardServerApp/Data/Repository/UsersRepository.cs index 2c90eeb..be69eed 100644 --- a/ImageBoardServerApp/Data/Repository/UsersRepository.cs +++ b/ImageBoardServerApp/Data/Repository/UsersRepository.cs @@ -14,7 +14,7 @@ public static class UsersRepository .Include(user => user.Posts) .ToListAsync(); } - + public static async Task getUserByIdAsync(int userId) { await using var db = new AppDBContext(); @@ -27,6 +27,14 @@ public static class UsersRepository .FirstOrDefaultAsync(); } + public static async Task getUserByIdLiteAsync(int userId) + { + await using var db = new AppDBContext(); + return await db.Users + .Where(x => x.UserID == userId) + .FirstOrDefaultAsync(); + } + public static async Task getUserByEmailRawAsync(string email) { await using var db = new AppDBContext(); @@ -34,7 +42,7 @@ public static class UsersRepository .Where(user => user.Email == email) .FirstOrDefaultAsync(); } - + public static async Task getUserByEmailAsync(string email) { await using var db = new AppDBContext(); @@ -59,14 +67,14 @@ public static class UsersRepository return -1; } - + public static async Task updateUserAsync(UserData userToUpdate) { await using var db = new AppDBContext(); db.Users.Update(userToUpdate); return await db.SaveChangesAsync() >= 1; } - + public static async Task deleteUserAsync(int userId) { await using var db = new AppDBContext(); diff --git a/ImageBoardServerApp/ImageBoardServerApp.csproj b/ImageBoardServerApp/ImageBoardServerApp.csproj index 9b73911..c710d37 100644 --- a/ImageBoardServerApp/ImageBoardServerApp.csproj +++ b/ImageBoardServerApp/ImageBoardServerApp.csproj @@ -16,12 +16,13 @@ + - + diff --git a/ImageBoardServerApp/Pages/Basic/Index.razor b/ImageBoardServerApp/Pages/Basic/Index.razor index 73bffca..e4454fd 100644 --- a/ImageBoardServerApp/Pages/Basic/Index.razor +++ b/ImageBoardServerApp/Pages/Basic/Index.razor @@ -1,8 +1,9 @@ @page "/" +@using ImageBoardServerApp.Util @using ImageBoardServerApp.Data.Repository @inject AuthenticationStateProvider authStateProvider -

BulletBoard

+

BulletBoard @ver

This is a simple imageboard made in Razor Server.
@@ -12,7 +13,9 @@
Click here to learn more about free software.
+ Check out the project on Gitlab.
+
We're currently @amountOfUsers User(s), viewing @amountOfPosts Post(s) with @amountOfComments Comment(s).
Click here to: @@ -36,6 +39,8 @@ private int amountOfComments = -1; private int amountOfUsers = -1; + public string ver { get; set; } = TheManager.version; + protected override async Task OnParametersSetAsync() { var posts = await PostsRepository.getPostsAsync(); diff --git a/ImageBoardServerApp/Pages/Basic/ReportPage.razor b/ImageBoardServerApp/Pages/Basic/ReportPage.razor index 4cbcedd..433bb2d 100644 --- a/ImageBoardServerApp/Pages/Basic/ReportPage.razor +++ b/ImageBoardServerApp/Pages/Basic/ReportPage.razor @@ -55,6 +55,8 @@ { if (selectedItem == null || selectedItem == "none") return; + if (explaination == null) + return; var cauthStateProvder = (CustomAuthenticationStateProvider)authStateProvider; var user = await cauthStateProvder.GetAuthenticationStateAsync(); var usr = user.User; @@ -94,10 +96,13 @@ }; List submittedReports = foundusr.RecivedReports; - foreach (var r in submittedReports) + if (foundusr.RecivedReports != null) { - if (r.ReportedPostID == reportData.ReportedPostID && r.ReportedCommentID == reportData.ReportedCommentID) - return; + foreach (var r in submittedReports) + { + if (r.ReportedPostID == reportData.ReportedPostID && r.ReportedCommentID == reportData.ReportedCommentID) + return; + } } await ReportsRepository.createReportAsync(reportData); diff --git a/ImageBoardServerApp/Pages/Moderation/BanAndDeleteCommentsOrPosts.razor b/ImageBoardServerApp/Pages/Moderation/BanAndDeleteCommentsOrPosts.razor index 06258f7..87ca2a7 100644 --- a/ImageBoardServerApp/Pages/Moderation/BanAndDeleteCommentsOrPosts.razor +++ b/ImageBoardServerApp/Pages/Moderation/BanAndDeleteCommentsOrPosts.razor @@ -1,10 +1,53 @@ -@page "/sys/modtools/{targetuserid}/{type}/{targetid}" +@page "/sys/modtools/banandordel/{targetuserid}/{board}/{type}/{threadid}/{targetid}" +@using ImageBoardServerApp.Data.Repository @using System.ComponentModel.DataAnnotations +@inject NavigationManager navManager +@inject IJSRuntime js

- + +

+ [View Thread] +

+
+
+ @if (type == "op") + { + + } + else if (type == "comment") + { + + } + else + { +

This is not a valid type.

+ } +
+
+
+ + + +
+
+ Ban User: + 1h + + 2h + + 1d + + 1w + + 1m + + 1yr + +
+
@@ -14,14 +57,82 @@ @code { + public string timetoBan { get; set; } + public string reason { get; set; } + + public UserData user { get; set; } + public PostData post { get; set; } + public CommentData comment { get; set; } + + private async Task banTarget(int hours) + { + UserData ud = await UsersRepository.getUserByIdAsync(int.Parse(targetuserid)); + ud.TimeBanned = DateTimeOffset.Now.ToUnixTimeMilliseconds() + (hours * 3600000); + if (reason == "") + { + reason = "not specified"; + } + ud.BanReason = reason; + await UsersRepository.updateUserAsync(ud); + navManager.NavigateTo("/@board/", true, true); + } + + protected override async Task OnParametersSetAsync() + { + if (!int.TryParse(targetid, out _) || !int.TryParse(targetuserid, out _)) + { + navManager.NavigateTo("/sys/dead", true); + return; + } + + var targeti = int.Parse(targetid); + + var targetuseri = int.Parse(targetuserid); + + var u = await UsersRepository.getUserByIdAsync(targetuseri); + if (u == null) + { + navManager.NavigateTo("/sys/dead", true); + return; + } + + if (targetuseri != u.UserID) + { + navManager.NavigateTo("/sys/dead", true); + return; + } + + user = u; + + var isPost = type == "op"; + + if (isPost) + { + post = await PostsRepository.getPostByIdAsync(targeti); + } + else + { + comment = await CommentsRepository.getCommentByIdAsync(targeti); + } + await base.OnParametersSetAsync(); + } + [Parameter] [Required] public string targetuserid { get; set; } + [Parameter] + [Required] + public string threadid { get; set; } + [Parameter] [Required] public string type { get; set; } + [Parameter] + [Required] + public string board { get; set; } + [Parameter] [Required] public string targetid { get; set; } diff --git a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor index a865461..57a8e99 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/CommentForm.razor @@ -118,7 +118,7 @@ return; } int userID = foundusr.UserID; - if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned < 0) + if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned > 0) { foundusr.TimeBanned = -1; } @@ -127,7 +127,7 @@ { var dt = TheManager.ConvertToDateTime(foundusr.TimeBanned); hasErr = true; - postErr = "You are banned for " + foundusr.BanReason + " and may not comment until " + dt.Year + "." + dt.Month + "." + dt.Day + " " + dt.Hour + ":" + dt.Minute + "::" + dt.Second; + postErr = "You are banned for \"" + foundusr.BanReason + "\" and may not comment until " + dt.Year + "." + dt.Month + "." + dt.Day + " " + dt.Hour + ":" + dt.Minute + "::" + dt.Second; return; } foundusr.lastActionTimeStamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); diff --git a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor index af80dea..c47c642 100644 --- a/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor +++ b/ImageBoardServerApp/Shared/Components/Forms/PostForm.razor @@ -124,7 +124,7 @@ return; } int userID = foundusr.UserID; - if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned < 0) + if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - foundusr.TimeBanned > 0) { foundusr.TimeBanned = -1; } @@ -133,7 +133,7 @@ { var dt = TheManager.ConvertToDateTime(foundusr.TimeBanned); hasErr = true; - postErr = "You are banned for " + foundusr.BanReason + " and may not post until " + dt.Year + "." + dt.Month + "." + dt.Day + " " + dt.Hour + ":" + dt.Minute + "::" + dt.Second; + postErr = "You are banned for \"" + foundusr.BanReason + "\" and may not post until " + dt.Year + "." + dt.Month + "." + dt.Day + " " + dt.Hour + ":" + dt.Minute + "::" + dt.Second; return; } @@ -153,7 +153,6 @@ foundusr.LastUsedName = postUsername; await UsersRepository.updateUserAsync(foundusr); - //TODO Add check if data is image if (selectedFile == null || selectedFile.Size >= 512000 * 2 * 10) @@ -198,11 +197,11 @@ shouldAnon = postAnon }; int postId = await PostsRepository.createPostAsync(postToPost); + await TheManager.bumpThreads(board); if (postId != -1) { //Open post successfull NavigationManager.NavigateTo($"/{board.Tag}/thread/{postId}", true, true); - await TheManager.bumpThreads(board); Console.WriteLine("Post created"); } else diff --git a/ImageBoardServerApp/Shared/Components/ReportEntry.razor b/ImageBoardServerApp/Shared/Components/ReportEntry.razor index 5a6e7c5..6dcf677 100644 --- a/ImageBoardServerApp/Shared/Components/ReportEntry.razor +++ b/ImageBoardServerApp/Shared/Components/ReportEntry.razor @@ -18,28 +18,34 @@ Explaination: @report.ReportExlaination
Ban User: - 1d + 1h - 1w + 2h - 1m + 1d - 1yr + 1w + + 1m + + 1yr - 273,972.6 yrs
Ban Reporter: - 1d + 1h - 1w + 2h - 1m + 1d - 1yr + 1w + + 1m + + 1yr - 273,972.6 yrs
- Done + Done
@if (report.Type == "op") { @@ -52,23 +58,26 @@ @code { + [Parameter] [Required] public ReportData report { get; set; } - - + + private async Task banTarget(int days) { UserData user = report.UserReported; - user.TimeBanned = DateTimeOffset.Now.AddDays(days).ToUnixTimeMilliseconds(); + user.TimeBanned = DateTimeOffset.Now.ToUnixTimeMilliseconds() + (days * 3600000); + user.BanReason = report.ReportReason; await UsersRepository.updateUserAsync(user); await removeReport(); } - + private async Task banReporter(int days) { UserData user = report.UserReporter; - user.TimeBanned = DateTimeOffset.Now.AddDays(days).ToUnixTimeMilliseconds(); + user.TimeBanned = DateTimeOffset.Now.ToUnixTimeMilliseconds() + (days * 3600000); + user.BanReason = "misuse of the report system"; await UsersRepository.updateUserAsync(user); await removeReport(); } @@ -76,6 +85,7 @@ private async Task removeReport() { await ReportsRepository.deleteReportAsync(report.ReportID); - navigationManager.NavigateTo("/sys/reports", true, true); + navigationManager.NavigateTo("/sys/click/red/_sys_modmenu_reports", true, true); } + } \ No newline at end of file diff --git a/ImageBoardServerApp/Shared/NavMenu.razor b/ImageBoardServerApp/Shared/NavMenu.razor index a14512e..7f43c90 100644 --- a/ImageBoardServerApp/Shared/NavMenu.razor +++ b/ImageBoardServerApp/Shared/NavMenu.razor @@ -1,5 +1,4 @@ -@using ImageBoardServerApp.Util -@using ImageBoardServerApp.Data.Repository +@using ImageBoardServerApp.Data.Repository @inject AuthenticationStateProvider authStateProvider @inject NavigationManager navManager @@ -9,7 +8,7 @@ @@ -68,8 +67,6 @@ @code { - public string ver { get; set; } = TheManager.version; - private bool collapseNavMenu = true; private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; diff --git a/ImageBoardServerApp/Util/TheManager.cs b/ImageBoardServerApp/Util/TheManager.cs index 6fa795d..019c91d 100644 --- a/ImageBoardServerApp/Util/TheManager.cs +++ b/ImageBoardServerApp/Util/TheManager.cs @@ -6,7 +6,7 @@ namespace ImageBoardServerApp.Util; public class TheManager { - public static string version = "1.0.0-c1"; + public static string version = "v1.0.0-rc1"; private static long getDiff(PostData post) { @@ -38,14 +38,17 @@ public class TheManager public static async Task bumpThreads(BoardData board) { + Console.WriteLine("Bumping.."); List sortedThreads = await getPostList(board.Tag); if (sortedThreads.Count > board.maxThreads + 1) { - for (int i = board.maxThreads + 1; i >= sortedThreads.Count; ++i) + Console.WriteLine("Pruning.."); + foreach (var pd in sortedThreads.TakeLast(sortedThreads.Count() - board.maxThreads)) { - if (sortedThreads[i].IsSticky) + if (pd.IsSticky) continue; - await deleteThread(sortedThreads[i]); + Console.WriteLine($"Removing Post{pd.PostID}"); + await deleteThread(pd); } } } @@ -111,8 +114,8 @@ public class TheManager public static DateTime ConvertToDateTime(long timestamp) { - DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - DateTime date = unixEpoch.AddSeconds(timestamp); - return date; + DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + dateTime = dateTime.AddMilliseconds(timestamp).ToLocalTime(); + return dateTime; } } \ No newline at end of file