feat: The posts are now sorted
fix: modmenu now checks for the permission, you now have to be 18yo to access the boards, images now get deleted when deleting threads / posts, fixed grammar error in the register page, other fixed which i forget
This commit is contained in:
parent
f0fbb11824
commit
dcc7634f5e
13 changed files with 219 additions and 88 deletions
|
@ -27,6 +27,9 @@ public static class UsersRepository
|
|||
return await db.Users
|
||||
.Where(user => user.Email == email)
|
||||
.Include(user => user.SubmittedReports)
|
||||
.Include(user => user.Posts)
|
||||
.Include(user => user.Comments)
|
||||
.Include(user => user.RecivedReports)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
|
|
83
ImageBoardServerApp/Data/TheManager.cs
Normal file
83
ImageBoardServerApp/Data/TheManager.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
using ImageBoardServerApp.Data.Repository;
|
||||
|
||||
namespace ImageBoardServerApp.Data;
|
||||
|
||||
public class TheManager
|
||||
{
|
||||
|
||||
private static long getDiff(PostData post)
|
||||
{
|
||||
return (DateTimeOffset.Now.ToUnixTimeMilliseconds() - post.CreatedAt);
|
||||
}
|
||||
|
||||
private static long getValue(long num)
|
||||
{
|
||||
return num < 0 ? num * -1 : num;
|
||||
}
|
||||
|
||||
public static long getBumpValue(PostData post)
|
||||
{
|
||||
return getValue( 10 * 60000 - getDiff(post)) + getDiff(post) / post.Comments.Count;
|
||||
}
|
||||
|
||||
public static async Task<List<PostData>> getPostList(string boardTag)
|
||||
{
|
||||
List<PostData> threads = await PostsRepository.getPostsByBoardAsync(boardTag);
|
||||
return threads.OrderBy(getBumpValue).ToList();
|
||||
}
|
||||
|
||||
public static async Task bumpThreads(BoardData board)
|
||||
{
|
||||
List<PostData> sortedThreads = await getPostList(board.Tag);
|
||||
if (sortedThreads.Count > board.maxThreads + 1)
|
||||
{
|
||||
for (int i = board.maxThreads + 1; i >= sortedThreads.Count; ++i)
|
||||
{
|
||||
await deleteThread(sortedThreads[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task deleteThread(PostData post)
|
||||
{
|
||||
foreach(var c in post.Comments)
|
||||
{
|
||||
if (c.Image != null)
|
||||
{
|
||||
deleteImage(c.Image);
|
||||
}
|
||||
}
|
||||
|
||||
deleteImage(post.Image);
|
||||
|
||||
await PostsRepository.deletePostAsync(post.PostID);
|
||||
}
|
||||
|
||||
public static async Task deleteComment(CommentData comment)
|
||||
{
|
||||
if (comment.Image != null)
|
||||
{
|
||||
deleteImage(comment.Image);
|
||||
}
|
||||
|
||||
await CommentsRepository.deleteCommentAsync(comment.CommentID);
|
||||
}
|
||||
|
||||
public static void deleteImage(ImageData imageData)
|
||||
{
|
||||
string path = $"./wwwroot{imageData.ImageLocation}";
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
Console.WriteLine("The file was not found.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("An error occurred: " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue