mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
Improvement to pastes archive, added navigator to the top of each page
This commit is contained in:
+37
-1
@@ -3,6 +3,7 @@ using Microsoft.Data.Sqlite;
|
|||||||
using System.Threading.RateLimiting;
|
using System.Threading.RateLimiting;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
@@ -33,6 +34,15 @@ class Program
|
|||||||
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
|
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
|
||||||
options.QueueLimit = 2;
|
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();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
@@ -156,6 +166,10 @@ class Program
|
|||||||
{
|
{
|
||||||
continue;
|
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>";
|
pastes += $"<a href=\"/{paste.Id}\"><li>{paste.Title} {paste.Date} {ConvertToBytes(paste.Size)}</li></a>";
|
||||||
}
|
}
|
||||||
if(string.IsNullOrEmpty(pastes))
|
if(string.IsNullOrEmpty(pastes))
|
||||||
@@ -202,20 +216,40 @@ class Program
|
|||||||
{
|
{
|
||||||
continue;
|
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>";
|
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))
|
if (string.IsNullOrEmpty(pastes))
|
||||||
{
|
{
|
||||||
pastes = "<h2>No pastes found</h1>";
|
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("{pastes}", pastes);
|
||||||
html = html.Replace("{backpagenum}", $"{pageNumber - 1}");
|
html = html.Replace("{backpagenum}", $"{pageNumber - 1}");
|
||||||
html = html.Replace("{pagenum}", $"{pageNumber + 1}");
|
html = html.Replace("{pagenum}", $"{pageNumber + 1}");
|
||||||
|
html = html.Replace("{currentpagenum}", $"{pageNumber}");
|
||||||
|
html = html.Replace("{totalpages}", $"{totalPages}");
|
||||||
context.Response.ContentType = "text/html";
|
context.Response.ContentType = "text/html";
|
||||||
await context.Response.WriteAsync(html);
|
await context.Response.WriteAsync(html);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
}).RequireRateLimiting("fixed-bigger");
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -271,6 +305,8 @@ class Program
|
|||||||
responseJson["pasteDate"] = paste.Date;
|
responseJson["pasteDate"] = paste.Date;
|
||||||
responseJson["pasteVisibility"] = paste.Visibility;
|
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());
|
await context.Response.WriteAsJsonAsync(responseJson.ToString());
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,11 @@
|
|||||||
<title>archive</title>
|
<title>archive</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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="container-wrapper">
|
||||||
<div class="pastes-container">
|
<div class="pastes-container">
|
||||||
<h1>paste archive</h1>
|
<h1>paste archive</h1>
|
||||||
@@ -14,10 +19,9 @@
|
|||||||
{pastes}
|
{pastes}
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons-wrapper">
|
<div class="buttons-wrapper">
|
||||||
<a href="/archive?page={backpagenum}">back a page</a>
|
<a class="arrow-button" href="/archive?page={backpagenum}"><</a>
|
||||||
<a href="/">create paste</a>
|
<p>{currentpagenum}/{totalpages}</p>
|
||||||
<a href="/pastes">recent pastes</a>
|
<a class="arrow-button" href="/archive?page={pagenum}">></a>
|
||||||
<a href="/archive?page={pagenum}">next page</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -119,5 +123,44 @@ li:hover{
|
|||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
border: 2px solid #3a3a3a;
|
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>
|
</style>
|
||||||
</html>
|
</html>
|
||||||
@@ -7,6 +7,11 @@
|
|||||||
<title>create paste</title>
|
<title>create paste</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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="container-wrapper">
|
||||||
<div class="error-container">
|
<div class="error-container">
|
||||||
<h1>Error {code}</h1>
|
<h1>Error {code}</h1>
|
||||||
@@ -67,5 +72,38 @@ body{
|
|||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
border: 2px solid #3a3a3a;
|
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>
|
</style>
|
||||||
</html>
|
</html>
|
||||||
@@ -7,6 +7,11 @@
|
|||||||
<title>create paste</title>
|
<title>create paste</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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="container-wrapper">
|
||||||
<div class="creation-container">
|
<div class="creation-container">
|
||||||
<h1>create paste</h1>
|
<h1>create paste</h1>
|
||||||
@@ -152,5 +157,38 @@ body{
|
|||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
border: 2px solid #3a3a3a;
|
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>
|
</style>
|
||||||
</html>
|
</html>
|
||||||
@@ -7,6 +7,11 @@
|
|||||||
<title>{pastetitle}</title>
|
<title>{pastetitle}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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="container-wrapper">
|
||||||
<div class="paste-container">
|
<div class="paste-container">
|
||||||
<h1>{pastetitle}</h1>
|
<h1>{pastetitle}</h1>
|
||||||
@@ -53,7 +58,7 @@ body{
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100vh;
|
height: 98.7vh;
|
||||||
}
|
}
|
||||||
.paste-container{
|
.paste-container{
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -115,5 +120,38 @@ body{
|
|||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
border: 2px solid #3a3a3a;
|
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>
|
</style>
|
||||||
</html>
|
</html>
|
||||||
@@ -7,6 +7,11 @@
|
|||||||
<title>recent pastes</title>
|
<title>recent pastes</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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="container-wrapper">
|
||||||
<div class="pastes-container">
|
<div class="pastes-container">
|
||||||
<h1>recent pastes</h1>
|
<h1>recent pastes</h1>
|
||||||
@@ -117,5 +122,38 @@ li:hover{
|
|||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
border: 2px solid #3a3a3a;
|
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>
|
</style>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user