mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
archive page has now been created
This commit is contained in:
@@ -168,6 +168,55 @@ class Program
|
||||
return;
|
||||
}
|
||||
}).RequireRateLimiting("fixed");
|
||||
app.MapGet("/archive", async (HttpContext context) =>
|
||||
{
|
||||
var html = File.ReadAllText("assets\\archives.html");
|
||||
var page = context.Request?.Query["page"].ToString();
|
||||
|
||||
int pageNumber;
|
||||
if (!int.TryParse(page, out pageNumber) || pageNumber <= 0)
|
||||
{
|
||||
pageNumber = 1;
|
||||
}
|
||||
int pastesPerPage = 50;
|
||||
int skipCount = (pageNumber - 1) * pastesPerPage;
|
||||
|
||||
using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = $"SELECT * FROM pastes WHERE Visibility != 'Private' ORDER BY UID DESC LIMIT {pastesPerPage} OFFSET {skipCount}";
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
string pastes = string.Empty;
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
var paste = new Paste
|
||||
{
|
||||
Title = reader.GetString(1),
|
||||
Date = reader.GetString(2),
|
||||
Size = reader.GetString(3),
|
||||
Visibility = reader.GetString(4),
|
||||
Id = reader.GetString(5),
|
||||
};
|
||||
if(paste.Visibility == "Private" || paste.Visibility == "Unlisted")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
pastes += $"<a href=\"/{paste.Id}\"><li>{paste.Title} {paste.Date} {ConvertToBytes(paste.Size)}</li></a>";
|
||||
}
|
||||
if (string.IsNullOrEmpty(pastes))
|
||||
{
|
||||
pastes = "<h2>No pastes found</h1>";
|
||||
}
|
||||
html = html.Replace("{pastes}", pastes);
|
||||
html = html.Replace("{backpagenum}", $"{pageNumber - 1}");
|
||||
html = html.Replace("{pagenum}", $"{pageNumber + 1}");
|
||||
context.Response.ContentType = "text/html";
|
||||
await context.Response.WriteAsync(html);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>archive</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-wrapper">
|
||||
<div class="pastes-container">
|
||||
<h1>paste archive</h1>
|
||||
<div class="pastes-wrapper">
|
||||
{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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<style>
|
||||
body{
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
.container-wrapper{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
}
|
||||
.pastes-container{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
min-height: 20%;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
.pastes-wrapper{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 95%;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
max-height: 70vh;
|
||||
}
|
||||
.pastes-wrapper a{
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
li{
|
||||
transition: 300ms;
|
||||
list-style: none;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
width: 90%;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border: #22222200 2px solid;
|
||||
}
|
||||
li:hover{
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
.buttons-wrapper{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
}
|
||||
.buttons-wrapper a{
|
||||
transition: 300ms;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: fit-content;
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
min-width: 20%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
border: #22222200 2px solid;
|
||||
}
|
||||
.buttons-wrapper a:hover{
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
</style>
|
||||
</html>
|
||||
Reference in New Issue
Block a user