Improvement to pastes archive, added navigator to the top of each page

This commit is contained in:
whoswhip
2024-08-19 03:45:06 -04:00
parent 7221d99b68
commit 47aed18919
6 changed files with 237 additions and 6 deletions
+37 -1
View File
@@ -3,6 +3,7 @@ using Microsoft.Data.Sqlite;
using System.Threading.RateLimiting;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Runtime.InteropServices;
class Program
{
@@ -33,6 +34,15 @@ class Program
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
options.QueueLimit = 2;
}));
builder.Services.AddRateLimiter(_ => _
.AddFixedWindowLimiter(policyName: "fixed-bigger", options =>
{
options.PermitLimit = 8;
options.Window = TimeSpan.FromSeconds(6);
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
options.QueueLimit = 4;
}));
var app = builder.Build();
// Configure the HTTP request pipeline.
@@ -156,6 +166,10 @@ class Program
{
continue;
}
if(paste.Title == "" || string.IsNullOrEmpty(paste.Title))
{
paste.Title = $"Untitled {reader.GetString(0)}";
}
pastes += $"<a href=\"/{paste.Id}\"><li>{paste.Title} {paste.Date} {ConvertToBytes(paste.Size)}</li></a>";
}
if(string.IsNullOrEmpty(pastes))
@@ -202,20 +216,40 @@ class Program
{
continue;
}
if (paste.Title == "" || string.IsNullOrEmpty(paste.Title))
{
paste.Title = $"Untitled {reader.GetString(0)}";
}
pastes += $"<a href=\"/{paste.Id}\"><li>{paste.Title} {paste.Date} {ConvertToBytes(paste.Size)}</li></a>";
}
var findCountCommand = connection.CreateCommand();
findCountCommand.CommandText = "SELECT COUNT(*) FROM pastes WHERE Visibility != 'Private'";
int totalPastes = Convert.ToInt32(await findCountCommand.ExecuteScalarAsync() );
int totalPages = (int)Math.Ceiling((double)totalPastes / pastesPerPage);
if (pageNumber > totalPages && totalPages != 0)
{
context.Response.Redirect($"/archive?page={totalPages}");
return;
}
if (string.IsNullOrEmpty(pastes))
{
pastes = "<h2>No pastes found</h1>";
html = html.Replace("</style>", "");
html = html.Replace("</html>", "");
html += ".buttons-wrapper{\r\n display: none !important;\r\n}";
html += "</style>\n</html>";
}
html = html.Replace("{pastes}", pastes);
html = html.Replace("{backpagenum}", $"{pageNumber - 1}");
html = html.Replace("{pagenum}", $"{pageNumber + 1}");
html = html.Replace("{currentpagenum}", $"{pageNumber}");
html = html.Replace("{totalpages}", $"{totalPages}");
context.Response.ContentType = "text/html";
await context.Response.WriteAsync(html);
return;
}
});
}).RequireRateLimiting("fixed-bigger");
#endregion
@@ -271,6 +305,8 @@ class Program
responseJson["pasteDate"] = paste.Date;
responseJson["pasteVisibility"] = paste.Visibility;
Console.WriteLine($"Created a {ConvertToBytes(paste.Size ?? string.Empty)} sized paste with the id of {paste.Id} at {paste.Date}");
await context.Response.WriteAsJsonAsync(responseJson.ToString());
return;
+47 -4
View File
@@ -7,6 +7,11 @@
<title>archive</title>
</head>
<body>
<div class="nav-div">
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
</div>
<div class="container-wrapper">
<div class="pastes-container">
<h1>paste archive</h1>
@@ -14,10 +19,9 @@
{pastes}
</div>
<div class="buttons-wrapper">
<a href="/archive?page={backpagenum}">back a page</a>
<a href="/">create paste</a>
<a href="/pastes">recent pastes</a>
<a href="/archive?page={pagenum}">next page</a>
<a class="arrow-button" href="/archive?page={backpagenum}"><</a>
<p>{currentpagenum}/{totalpages}</p>
<a class="arrow-button" href="/archive?page={pagenum}">></a>
</div>
</div>
</div>
@@ -119,5 +123,44 @@ li:hover{
background-color: #333333;
border: 2px solid #3a3a3a;
}
.nav-div{
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a{
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover{
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
.arrow-button{
min-width: fit-content !important;
padding-left: 1rem !important;
padding-right: 1rem !important;
}
</style>
</html>
+38
View File
@@ -7,6 +7,11 @@
<title>create paste</title>
</head>
<body>
<div class="nav-div">
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
</div>
<div class="container-wrapper">
<div class="error-container">
<h1>Error {code}</h1>
@@ -67,5 +72,38 @@ body{
background-color: #333333;
border: 2px solid #3a3a3a;
}
.nav-div{
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a{
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover{
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
</style>
</html>
+38
View File
@@ -7,6 +7,11 @@
<title>create paste</title>
</head>
<body>
<div class="nav-div">
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
</div>
<div class="container-wrapper">
<div class="creation-container">
<h1>create paste</h1>
@@ -152,5 +157,38 @@ body{
background-color: #333333;
border: 2px solid #3a3a3a;
}
.nav-div{
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a{
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover{
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
</style>
</html>
+39 -1
View File
@@ -7,6 +7,11 @@
<title>{pastetitle}</title>
</head>
<body>
<div class="nav-div">
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
</div>
<div class="container-wrapper">
<div class="paste-container">
<h1>{pastetitle}</h1>
@@ -53,7 +58,7 @@ body{
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
height: 98.7vh;
}
.paste-container{
display: flex;
@@ -115,5 +120,38 @@ body{
background-color: #333333;
border: 2px solid #3a3a3a;
}
.nav-div{
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a{
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover{
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
</style>
</html>
+38
View File
@@ -7,6 +7,11 @@
<title>recent pastes</title>
</head>
<body>
<div class="nav-div">
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
</div>
<div class="container-wrapper">
<div class="pastes-container">
<h1>recent pastes</h1>
@@ -117,5 +122,38 @@ li:hover{
background-color: #333333;
border: 2px solid #3a3a3a;
}
.nav-div{
top: 0;
margin-top: 10px;
position: absolute;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: fit-content;
background-color: #181818;
padding-left: 10px;
padding-right: 10px;
color: white;
border-radius: 5px;
height: fit-content;
overflow-y: auto;
border: #222222 2px solid;
}
.nav-div a{
text-decoration: none;
color: white;
padding: 10px;
margin: 10px;
border-radius: 5px;
background-color: #222222;
transition: 300ms;
border: #2a2a2a00 2px solid;
}
.nav-div a:hover{
transition: 300ms;
background-color: #333333;
border: #3a3a3a 2px solid;
}
</style>
</html>