mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
Change Log 9/5/2024
- Search feature added to archives
This commit is contained in:
@@ -1175,6 +1175,83 @@ class Program
|
|||||||
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Paste deleted" }.ToString());
|
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Paste deleted" }.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}).RequireRateLimiting("fixed");
|
||||||
|
app.MapPost("/api/pastes/search", async (HttpContext context) =>
|
||||||
|
{
|
||||||
|
var log = await Logging.LogRequestAsync(context);
|
||||||
|
var parameters = context.Request.Query;
|
||||||
|
string requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync();
|
||||||
|
if (string.IsNullOrEmpty(requestBody))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
context.Response.ContentType = "application/json";
|
||||||
|
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var data = JObject.Parse(requestBody);
|
||||||
|
var query = SanitizeInput(data["query"]?.ToString() ?? "");
|
||||||
|
Console.WriteLine($"erm: {query}");
|
||||||
|
if (string.IsNullOrEmpty(query) || string.IsNullOrWhiteSpace(query))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
context.Response.ContentType = "application/json";
|
||||||
|
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
var command = connection.CreateCommand();
|
||||||
|
command.CommandText = "SELECT * FROM pastes WHERE Title LIKE @Query";
|
||||||
|
command.Parameters.AddWithValue("@Query", $"%{query}%");
|
||||||
|
var reader = await command.ExecuteReaderAsync();
|
||||||
|
JArray pastes = new JArray();
|
||||||
|
string pastesHTML = string.Empty;
|
||||||
|
while (await reader.ReadAsync())
|
||||||
|
{
|
||||||
|
var paste = new Paste
|
||||||
|
{
|
||||||
|
Title = reader.GetString(1),
|
||||||
|
UnixDate = long.Parse(reader.GetString(2)),
|
||||||
|
Size = reader.GetString(3),
|
||||||
|
Visibility = reader.GetString(4),
|
||||||
|
Id = reader.GetString(5),
|
||||||
|
};
|
||||||
|
var difference = GetTimeDifference(DateTimeOffset.FromUnixTimeSeconds(paste.UnixDate ?? 0), DateTimeOffset.FromUnixTimeSeconds(DateTimeOffset.Now.ToUnixTimeSeconds()));
|
||||||
|
if (paste.Visibility == "Private" || paste.Visibility == "Unlisted")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(parameters["html"]))
|
||||||
|
{
|
||||||
|
JObject pasteJson = new JObject();
|
||||||
|
pasteJson["title"] = paste.Title;
|
||||||
|
pasteJson["id"] = paste.Id;
|
||||||
|
pasteJson["size"] = ConvertToBytes(paste.Size);
|
||||||
|
pasteJson["date"] = difference;
|
||||||
|
pasteJson["visibility"] = paste.Visibility;
|
||||||
|
pastes.Add(pasteJson);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pastesHTML += $"<a title=\"{paste.Title}\" href=\"/{paste.Id}\"><li>{paste.Title} {difference}</li></a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
if (string.IsNullOrEmpty(parameters["html"]))
|
||||||
|
{
|
||||||
|
context.Response.ContentType = "application/json";
|
||||||
|
await context.Response.WriteAsJsonAsync(pastes.ToString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.ContentType = "text/html";
|
||||||
|
await context.Response.WriteAsync(pastesHTML);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}).RequireRateLimiting("fixed");
|
}).RequireRateLimiting("fixed");
|
||||||
app.MapPost("/api/accounts/create", async (HttpContext context) =>
|
app.MapPost("/api/accounts/create", async (HttpContext context) =>
|
||||||
{
|
{
|
||||||
|
|||||||
+202
-136
@@ -1,11 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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">
|
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||||
<title>archive</title>
|
<title>archive</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="nav-div">
|
<div class="nav-div">
|
||||||
<a href="/">home</a>
|
<a href="/">home</a>
|
||||||
@@ -13,155 +15,219 @@
|
|||||||
<a href="/archive">archive</a>
|
<a href="/archive">archive</a>
|
||||||
{html}
|
{html}
|
||||||
</div>
|
</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>
|
||||||
|
<input type="text" placeholder="search" class="text-input" oninput="search()">
|
||||||
<div class="pastes-wrapper">
|
<div class="pastes-wrapper">
|
||||||
{pastes}
|
{pastes}
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons-wrapper">
|
<div class="buttons-wrapper">
|
||||||
<a class="arrow-button" href="/archive?page={backpagenum}"><</a>
|
<a class="arrow-button" href="/archive?page={backpagenum}"><</a>
|
||||||
<p>{currentpagenum}/{totalpages}</p>
|
<p>{currentpagenum}/{totalpages}</p>
|
||||||
<a class="arrow-button" href="/archive?page={pagenum}">></a>
|
<a class="arrow-button" href="/archive?page={pagenum}">></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
<script>
|
||||||
|
let searchTimeout;
|
||||||
|
|
||||||
|
function search() {
|
||||||
|
clearTimeout(searchTimeout);
|
||||||
|
searchTimeout = setTimeout(searchPastes, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchPastes() {
|
||||||
|
const searchInput = document.querySelector('.text-input');
|
||||||
|
if (searchInput.value.length < 3) return;
|
||||||
|
fetch(`/api/pastes/search?html=true`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
query: searchInput.value
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(data => {
|
||||||
|
const pastesWrapper = document.querySelector('.pastes-wrapper');
|
||||||
|
if (data === '') {
|
||||||
|
pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pastesWrapper.innerHTML = data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<style>
|
<style>
|
||||||
body{
|
.text-input {
|
||||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
transition: border 300ms;
|
||||||
font-weight: bold;
|
width: 90.62%;
|
||||||
display: flex;
|
height: 1.2rem;
|
||||||
flex-direction: column;
|
padding: 10px;
|
||||||
justify-content: center;
|
margin: 10px;
|
||||||
align-items: center;
|
border-radius: 5px;
|
||||||
background-color: #0d0d0d;
|
border: #222222 2px solid;
|
||||||
overflow-y: hidden;
|
background-color: #222222;
|
||||||
}
|
color: white;
|
||||||
.container-wrapper{
|
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||||
display: flex;
|
}
|
||||||
flex-direction: column;
|
.text-input:focus {
|
||||||
justify-content: center;
|
transition: border 300ms;
|
||||||
align-items: center;
|
outline: none;
|
||||||
width: 100%;
|
border: #3a3a3a 2px solid;
|
||||||
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;
|
|
||||||
}
|
|
||||||
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
transition: height 300ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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: 100%;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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>
|
||||||
Reference in New Issue
Block a user