mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
Implement user profile and pastes retrieval features: add user.html and user.js for user display, create API endpoints for user data, and enhance UI with new styles and elements.
### Copilot Message
This commit is contained in:
@@ -259,6 +259,27 @@ namespace SharpbinV2.Server
|
|||||||
context.Response.Headers.Add("Content-Type", "text/html");
|
context.Response.Headers.Add("Content-Type", "text/html");
|
||||||
await context.Response.SendFileAsync("wwwroot/register.html");
|
await context.Response.SendFileAsync("wwwroot/register.html");
|
||||||
});
|
});
|
||||||
|
app.MapGet("/u/{username}", async (HttpContext context) =>
|
||||||
|
{
|
||||||
|
var username = context.Request.RouteValues["username"].ToString() ?? null;
|
||||||
|
if (string.IsNullOrEmpty(username))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
context.Response.Redirect("/error?error=400&message=Invalid username.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string html = File.ReadAllText("wwwroot/user.html");
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
context.Response.Headers.Add("Content-Type", "text/html");
|
||||||
|
context.Response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
|
context.Response.Headers.Add("Pragma", "no-cache");
|
||||||
|
context.Response.Headers.Add("Expires", "0");
|
||||||
|
|
||||||
|
|
||||||
|
context.Response.WriteAsync(html);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -905,6 +926,152 @@ namespace SharpbinV2.Server
|
|||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.MapGet("/api/users/uuid/{uuid}", async (HttpContext context) =>
|
||||||
|
{
|
||||||
|
var uuid = context.Request.RouteValues["uuid"].ToString() ?? null;
|
||||||
|
if (string.IsNullOrEmpty(uuid))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid UUID." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var user = await Database.UserFromUUID(uuid);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "User not found." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
await context.Response.WriteAsJsonAsync(new
|
||||||
|
{
|
||||||
|
success = true,
|
||||||
|
user = new
|
||||||
|
{
|
||||||
|
user.UID,
|
||||||
|
user.UUID,
|
||||||
|
user.Username,
|
||||||
|
user.DisplayName,
|
||||||
|
user.Created,
|
||||||
|
user.LastLogin
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
app.MapGet("/api/users/{username}", async (HttpContext context) =>
|
||||||
|
{
|
||||||
|
var username = context.Request.RouteValues["username"].ToString() ?? null;
|
||||||
|
if (string.IsNullOrEmpty(username))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid Username." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var user = await Database.UserFromUsername(username);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "User not found." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
await context.Response.WriteAsJsonAsync(new
|
||||||
|
{
|
||||||
|
success = true,
|
||||||
|
user = new
|
||||||
|
{
|
||||||
|
user.UID,
|
||||||
|
user.UUID,
|
||||||
|
user.Username,
|
||||||
|
user.DisplayName,
|
||||||
|
user.Created,
|
||||||
|
user.LastLogin
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
app.MapGet("/api/users/{uuid}/pastes", async (HttpContext context) =>
|
||||||
|
{
|
||||||
|
var uuid = context.Request.RouteValues["uuid"].ToString() ?? null;
|
||||||
|
if (string.IsNullOrEmpty(uuid))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid UUID." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var user = await Database.UserFromUUID(uuid);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "User not found." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var queries = context.Request.Query;
|
||||||
|
if (!queries.ContainsKey("page") && !queries.ContainsKey("limit"))
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "Missing required fields." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var page = queries.ContainsKey("page") ? Convert.ToInt32(queries["page"]) : 0;
|
||||||
|
var limit = queries.ContainsKey("limit") ? Convert.ToInt32(queries["limit"]) : 10;
|
||||||
|
if (page < 0 || limit <= 0 || limit > 25)
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid page or limit." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pages = await Database.EnumerateUserPastes(user) / limit;
|
||||||
|
if (page > pages)
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, message = "Page out of range.", pages });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using (var connection = new SqliteConnection(MainDatabaseConnection))
|
||||||
|
{
|
||||||
|
await connection.OpenAsync();
|
||||||
|
using (var command = connection.CreateCommand())
|
||||||
|
{
|
||||||
|
command.CommandText = "SELECT * FROM pastes WHERE AuthorUUID = @AuthorUUID AND Visibility NOT IN (1, 2) ORDER BY Created DESC LIMIT @Limit OFFSET @Offset;";
|
||||||
|
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
|
||||||
|
command.Parameters.AddWithValue("@Limit", limit);
|
||||||
|
command.Parameters.AddWithValue("@Offset", page * limit);
|
||||||
|
using (var reader = await command.ExecuteReaderAsync())
|
||||||
|
{
|
||||||
|
if (!reader.HasRows)
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = 400;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = false, error = true, message = "No pastes found." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pastes = new List<Paste>();
|
||||||
|
while (await reader.ReadAsync())
|
||||||
|
{
|
||||||
|
pastes.Add(new Paste
|
||||||
|
{
|
||||||
|
UUID = reader.GetString(1),
|
||||||
|
ID = reader.GetString(2),
|
||||||
|
Visibility = reader.GetInt32(3),
|
||||||
|
Title = reader.IsDBNull(4) ? null : reader.GetString(4),
|
||||||
|
AuthorUUID = reader.GetString(5),
|
||||||
|
Created = reader.GetInt64(7),
|
||||||
|
Edited = reader.GetInt64(8),
|
||||||
|
Size = reader.GetInt32(9),
|
||||||
|
TrueSize = reader.GetInt32(10),
|
||||||
|
Views = reader.GetInt32(11),
|
||||||
|
Syntax = reader.IsDBNull(12) ? null : reader.GetString(12)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Response.StatusCode = 200;
|
||||||
|
await context.Response.WriteAsJsonAsync(new { success = true, pastes, pages });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<!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">
|
||||||
@@ -14,7 +15,10 @@
|
|||||||
<link
|
<link
|
||||||
href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Noto+Sans+Mono:wght@100..900&display=swap"
|
href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Noto+Sans+Mono:wght@100..900&display=swap"
|
||||||
rel="stylesheet">
|
rel="stylesheet">
|
||||||
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="main-container">
|
<div class="main-container">
|
||||||
<h1 id="archive-header">Paste Archives</h1>
|
<h1 id="archive-header">Paste Archives</h1>
|
||||||
@@ -26,13 +30,14 @@
|
|||||||
<ol class="archive-list" id="archives">
|
<ol class="archive-list" id="archives">
|
||||||
</ol>
|
</ol>
|
||||||
<div class="paste-actions">
|
<div class="paste-actions">
|
||||||
<button id="previous-button">← Previous</button>
|
<button id="previous-button"><span id="previous-button-svg"></span></button>
|
||||||
<p id="paste-pages">0/0</p>
|
<p id="paste-pages">0/0</p>
|
||||||
<button id="next-button">Next →</button>
|
<button id="next-button"><span id="next-button-svg"></span></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="js/archive.js"></script>
|
<script src="js/archive.js"></script>
|
||||||
<script src="js/main.js"></script>
|
<script src="js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
.main-container {
|
.main-container {
|
||||||
max-width: 80%;
|
max-width: 80%;
|
||||||
|
max-height: 80vh;
|
||||||
margin: 2rem auto;
|
margin: 2rem auto;
|
||||||
|
margin-top: calc(2rem + 55px);
|
||||||
padding: 1.5rem;
|
padding: 1.5rem;
|
||||||
background-color: var(--neutral-900);
|
background-color: var(--neutral-900);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -123,7 +125,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.paste-actions button {
|
.paste-actions button {
|
||||||
padding: 0.6rem 1.2rem;
|
padding: 0.4rem 0.8rem;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
border: 1px solid var(--neutral-700);
|
border: 1px solid var(--neutral-700);
|
||||||
background-color: var(--neutral-800);
|
background-color: var(--neutral-800);
|
||||||
@@ -131,7 +133,7 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: all 0.2s ease;
|
transition: all 0.2s ease;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
min-width: 100px;
|
min-width: 75px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -183,7 +185,7 @@
|
|||||||
@media (max-width: 480px) {
|
@media (max-width: 480px) {
|
||||||
.main-container {
|
.main-container {
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
margin: 1rem;
|
max-width: 95%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#archive-header {
|
#archive-header {
|
||||||
@@ -203,3 +205,25 @@
|
|||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#next-button-svg {
|
||||||
|
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/></svg>');
|
||||||
|
color: white;
|
||||||
|
width: 1.5em;
|
||||||
|
height: 1.5em;
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
filter: invert(100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
#previous-button-svg {
|
||||||
|
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256l169.3-169.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z"/></svg>');
|
||||||
|
color: white;
|
||||||
|
width: 1.5em;
|
||||||
|
height: 1.5em;
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
filter: invert(100%);
|
||||||
|
}
|
||||||
@@ -228,3 +228,76 @@ code.hljs {
|
|||||||
0% { transform: rotate(0deg); }
|
0% { transform: rotate(0deg); }
|
||||||
100% { transform: rotate(360deg); }
|
100% { transform: rotate(360deg); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Minimal, clean style for paste information card */
|
||||||
|
.paste-information-card {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: none;
|
||||||
|
border-radius: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
padding: 0 0 8px 0;
|
||||||
|
margin: 0 0 8px 0;
|
||||||
|
border-bottom: 1px solid var(--neutral-700);
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.paste-info-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 1rem;
|
||||||
|
color: var(--neutral-100);
|
||||||
|
font-weight: 400;
|
||||||
|
background: none;
|
||||||
|
border-radius: 0;
|
||||||
|
padding: 0 6px;
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
.info-icon {
|
||||||
|
font-size: 1em;
|
||||||
|
opacity: 0.7;
|
||||||
|
margin-right: 2px;
|
||||||
|
}
|
||||||
|
#author-link {
|
||||||
|
color: var(--neutral-100);
|
||||||
|
text-decoration: underline dotted;
|
||||||
|
font-weight: 400;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
#author-link:hover {
|
||||||
|
color: #4ea1f7;
|
||||||
|
}
|
||||||
|
.paste-header h1#paste-title {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
color: var(--neutral-50);
|
||||||
|
letter-spacing: 0.2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-icon {
|
||||||
|
display: inline-block;
|
||||||
|
width: 1.1em;
|
||||||
|
height: 1.1em;
|
||||||
|
margin-right: 4px;
|
||||||
|
vertical-align: middle;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
.syntax-icon {
|
||||||
|
background: url('data:image/svg+xml;utf8,<svg fill="none" stroke="%23aaa" stroke-width="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M7 7l-4 3 4 3M13 7l4 3-4 3"/></svg>') no-repeat center/1em 1em;
|
||||||
|
}
|
||||||
|
.date-icon {
|
||||||
|
background: url('data:image/svg+xml;utf8,<svg fill="none" stroke="%23aaa" stroke-width="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><circle cx="10" cy="10" r="8"/><path d="M10 6v4l2 2"/></svg>') no-repeat center/1em 1em;
|
||||||
|
}
|
||||||
|
.size-icon {
|
||||||
|
background: url('data:image/svg+xml;utf8,<svg fill="none" stroke="%23aaa" stroke-width="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><rect x="4" y="3" width="12" height="14" rx="2"/><path d="M10 7v5m0 0l-2-2m2 2l2-2"/></svg>') no-repeat center/1em 1em;
|
||||||
|
}
|
||||||
|
.views-icon {
|
||||||
|
background: url('data:image/svg+xml;utf8,<svg fill="none" stroke="%23aaa" stroke-width="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><ellipse cx="10" cy="10" rx="8" ry="5"/><circle cx="10" cy="10" r="2.5"/></svg>') no-repeat center/1em 1em;
|
||||||
|
}
|
||||||
|
.author-icon {
|
||||||
|
background: url('data:image/svg+xml;utf8,<svg fill="none" stroke="%23aaa" stroke-width="2" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><circle cx="10" cy="7.5" r="3.5"/><path d="M3 17c0-3.3 3.1-6 7-6s7 2.7 7 6"/></svg>') no-repeat center/1em 1em;
|
||||||
|
}
|
||||||
@@ -0,0 +1,211 @@
|
|||||||
|
body, html {
|
||||||
|
height: 100%;
|
||||||
|
min-height: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
.main-container {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 2.5rem auto;
|
||||||
|
padding: 1.5rem 1.5rem 2.5rem 1.5rem;
|
||||||
|
background-color: var(--neutral-900);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 4px 20px rgba(0,0,0,0.18);
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
.user-header {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
.user-header h1 {
|
||||||
|
font-size: 2.1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--neutral-50);
|
||||||
|
margin: 0 0 0.2rem 0;
|
||||||
|
}
|
||||||
|
.user-header p {
|
||||||
|
color: var(--neutral-400);
|
||||||
|
font-size: 1rem;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.user-pastes-section {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
.archive-information {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 2fr 1fr 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
background-color: var(--neutral-800);
|
||||||
|
border-radius: 6px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--neutral-200);
|
||||||
|
border-bottom: 2px solid var(--neutral-700);
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.archive-information p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.archive-list {
|
||||||
|
list-style-type: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
width: 100%;
|
||||||
|
max-height: 70vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
border-radius: 6px;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: var(--neutral-700) var(--neutral-900);
|
||||||
|
}
|
||||||
|
.archive-list::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
.archive-list::-webkit-scrollbar-track {
|
||||||
|
background: var(--neutral-900);
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
.archive-list::-webkit-scrollbar-thumb {
|
||||||
|
background-color: var(--neutral-700);
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
.archive-list li {
|
||||||
|
margin: 0.75rem 0;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
.archive-list li:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
.archive-list li a {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 2fr 1fr 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
padding: 1rem 1.25rem;
|
||||||
|
background-color: var(--neutral-800);
|
||||||
|
color: var(--neutral-50);
|
||||||
|
text-decoration: none;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--neutral-700);
|
||||||
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
.archive-list li a:hover {
|
||||||
|
background-color: var(--neutral-750);
|
||||||
|
border-color: var(--neutral-600);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
.archive-list li a p {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.archive-list li a p:nth-child(2) {
|
||||||
|
padding-left: 1rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.archive-list li a p:nth-child(3){
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
#archive-title {
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--neutral-100);
|
||||||
|
}
|
||||||
|
#archive-date {
|
||||||
|
color: var(--neutral-300);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
#archive-syntax {
|
||||||
|
color: var(--neutral-300);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.user-pastes-throbber {
|
||||||
|
margin: 1.5rem auto;
|
||||||
|
}
|
||||||
|
.pastes-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1.2rem;
|
||||||
|
margin-top: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pastes-actions button:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
.pastes-actions span {
|
||||||
|
color: var(--neutral-300);
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.main-container {
|
||||||
|
max-width: 98vw;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
.archive-information,
|
||||||
|
.archive-list li a {
|
||||||
|
grid-template-columns: 3fr 2fr;
|
||||||
|
}
|
||||||
|
#archive-syntax {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.archive-information p:last-child {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.main-container {
|
||||||
|
padding: 1rem;
|
||||||
|
margin: 1rem;
|
||||||
|
}
|
||||||
|
.user-header h1 {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
.archive-list {
|
||||||
|
max-height: 60vh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#next-button-svg {
|
||||||
|
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/></svg>');
|
||||||
|
color: white;
|
||||||
|
width: 1.5em;
|
||||||
|
height: 1.5em;
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
filter: invert(100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
#previous-button-svg {
|
||||||
|
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256l169.3-169.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z"/></svg>');
|
||||||
|
color: white;
|
||||||
|
width: 1.5em;
|
||||||
|
height: 1.5em;
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: center;
|
||||||
|
filter: invert(100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pastes-actions button {
|
||||||
|
padding: 0.4rem 0.8rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--neutral-700);
|
||||||
|
background-color: var(--neutral-800);
|
||||||
|
color: var(--neutral-50);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
font-size: 1rem;
|
||||||
|
min-width: 75px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
@@ -33,8 +33,20 @@ document.addEventListener("DOMContentLoaded", async function () {
|
|||||||
|
|
||||||
function addInfo(paste) {
|
function addInfo(paste) {
|
||||||
document.getElementById("paste-title").innerText = paste.title;
|
document.getElementById("paste-title").innerText = paste.title;
|
||||||
document.getElementById("paste-date").innerText = convertUnixToLocal(paste.created);
|
document.getElementById("paste-date").innerText = `${convertUnixToLocal(paste.created)}`;
|
||||||
document.getElementById("paste-syntax").innerText = paste.syntax === "none" ? "" : paste.syntax || "";
|
document.getElementById("paste-syntax").innerText = paste.syntax;
|
||||||
|
document.getElementById("paste-size").innerText = paste.size === 0 ? "" : formatSize(paste.size);
|
||||||
|
document.getElementById("paste-author").innerText = paste.username;
|
||||||
|
document.getElementById("author-link").href = paste.username === "Anonymous" ? "" : `/u/${paste.username}`;
|
||||||
|
if (paste.username === "Anonymous") {
|
||||||
|
document.getElementById("author-link").innerText = "Anonymous";
|
||||||
|
document.getElementById("author-link").href = "";
|
||||||
|
document.getElementById("author-link").style.pointerEvents = "none";
|
||||||
|
document.getElementById("author-link").style.cursor = "not-allowed";
|
||||||
|
document.getElementById("author-link").style.color = "var(--text-color)";
|
||||||
|
document.getElementById("author-link").style.textDecoration = "none";
|
||||||
|
}
|
||||||
|
document.getElementById("paste-views").innerText = paste.views;
|
||||||
document.getElementById("info-throbber").style.display = "none";
|
document.getElementById("info-throbber").style.display = "none";
|
||||||
document.getElementById("copy-button").addEventListener("click", function () {
|
document.getElementById("copy-button").addEventListener("click", function () {
|
||||||
navigator.clipboard.writeText(window.location.href);
|
navigator.clipboard.writeText(window.location.href);
|
||||||
@@ -51,6 +63,7 @@ function addInfo(paste) {
|
|||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
|
showNotification("Paste downloaded!", "info", 2000);
|
||||||
});
|
});
|
||||||
document.getElementById("raw-button").addEventListener("click", function () {
|
document.getElementById("raw-button").addEventListener("click", function () {
|
||||||
window.location.href = `/raw/${paste.id}`;
|
window.location.href = `/raw/${paste.id}`;
|
||||||
@@ -112,3 +125,9 @@ async function decryptAES(content, password) {
|
|||||||
function convertUnixToLocal(unix) {
|
function convertUnixToLocal(unix) {
|
||||||
return new Date(unix * 1000).toLocaleString();
|
return new Date(unix * 1000).toLocaleString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatSize(bytes) {
|
||||||
|
if (bytes < 1024) return bytes + ' B';
|
||||||
|
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB';
|
||||||
|
return (bytes / (1024 * 1024)).toFixed(2) + ' MB';
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
let currentPage = 0;
|
||||||
|
const PAGE_SIZE = 25;
|
||||||
|
let totalPastes = 0;
|
||||||
|
let lastPage = false;
|
||||||
|
|
||||||
|
async function loadUserPastes(userData, page = 0) {
|
||||||
|
const pastesRes = await fetch(`/api/users/${userData.uuid}/pastes?limit=${PAGE_SIZE}&page=${page}`);
|
||||||
|
const data = await pastesRes.json();
|
||||||
|
let pastes = [];
|
||||||
|
if (pastesRes.ok) {
|
||||||
|
pastes = data.pastes || [];
|
||||||
|
totalPastes = data.total || 0;
|
||||||
|
lastPage = pastes.length < PAGE_SIZE;
|
||||||
|
}
|
||||||
|
const list = document.getElementById("user-pastes-list");
|
||||||
|
list.innerHTML = "";
|
||||||
|
if (!pastes.length) {
|
||||||
|
list.innerHTML = "<p style='color:var(--neutral-400)'>No pastes found.</p>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const paste of pastes) {
|
||||||
|
const li = document.createElement("li");
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = `/${paste.id}`;
|
||||||
|
link.innerHTML = `
|
||||||
|
<p>${paste.title}</p>
|
||||||
|
<p>${new Date(paste.created * 1000).toLocaleDateString()}</p>
|
||||||
|
<p>${paste.syntax || "Plaintext"}</p>
|
||||||
|
`;
|
||||||
|
li.appendChild(link);
|
||||||
|
list.appendChild(li);
|
||||||
|
}
|
||||||
|
document.getElementById("paste-pages").innerText = `${page + 1}/${data.pages + 1}`;
|
||||||
|
document.getElementById("next-button").disabled = page === 0;
|
||||||
|
document.getElementById("previous-button").disabled = lastPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", async function () {
|
||||||
|
const username = window.location.pathname.split("/")[2]
|
||||||
|
if (!username) {
|
||||||
|
window.location.href = "/error?code=404&message=User not found";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const userInfoRes = await fetch(`/api/users/${username}`);
|
||||||
|
if (!userInfoRes.ok) {
|
||||||
|
document.getElementById("user-name").innerText = "User not found";
|
||||||
|
document.getElementById("user-pastes-list").innerHTML = "<p style='color:var(--neutral-400)'>No user data.</p>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const user = await userInfoRes.json();
|
||||||
|
const userData = user.user ? user.user : user;
|
||||||
|
document.title = `${userData.username} - Sharpbin`;
|
||||||
|
document.getElementById("user-name").innerText = userData.username;
|
||||||
|
document.getElementById("user-uuid").innerText = userData.uuid;
|
||||||
|
|
||||||
|
await loadUserPastes(userData, 0);
|
||||||
|
currentPage = 0;
|
||||||
|
document.getElementById("user-prev-page").onclick = async function () {
|
||||||
|
if (currentPage > 0) {
|
||||||
|
currentPage--;
|
||||||
|
await loadUserPastes(userData, currentPage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.getElementById("user-next-page").onclick = async function () {
|
||||||
|
if (!lastPage) {
|
||||||
|
currentPage++;
|
||||||
|
await loadUserPastes(userData, currentPage);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
function formatSize(bytes) {
|
||||||
|
if (bytes < 1024) return bytes + ' B';
|
||||||
|
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB';
|
||||||
|
return (bytes / (1024 * 1024)).toFixed(2) + ' MB';
|
||||||
|
}
|
||||||
@@ -22,10 +22,13 @@
|
|||||||
<div class="main-container">
|
<div class="main-container">
|
||||||
<div class="paste-header">
|
<div class="paste-header">
|
||||||
<h1 id="paste-title">Title</h1>
|
<h1 id="paste-title">Title</h1>
|
||||||
<div class="paste-information">
|
<div class="paste-information-card">
|
||||||
<div id="info-throbber" class="throbber"></div>
|
<div id="info-throbber" class="throbber"></div>
|
||||||
<p id="paste-syntax">Syntax</p>
|
<div class="paste-info-item"><span class="info-icon syntax-icon"></span><span id="paste-syntax">Syntax</span></div>
|
||||||
<p id="paste-date">Date</p>
|
<div class="paste-info-item"><span class="info-icon date-icon"></span><span id="paste-date">Date</span></div>
|
||||||
|
<div class="paste-info-item"><span class="info-icon size-icon"></span><span id="paste-size">Size</span></div>
|
||||||
|
<div class="paste-info-item"><span class="info-icon views-icon"></span><span id="paste-views">Views</span></div>
|
||||||
|
<div class="paste-info-item"><span class="info-icon author-icon"></span><a id="author-link" href="#"><span id="paste-author">Author</span></a></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="paste-content">
|
<div class="paste-content">
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Loading - Sharpbin</title>
|
||||||
|
<link rel="preload" href="/css/style.css" as="style">
|
||||||
|
<link rel="preload" href="/css/user.css" as="style">
|
||||||
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
|
<link rel="stylesheet" href="/css/user.css">
|
||||||
|
<link rel="preload" href="/js/user.js" as="script">
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link
|
||||||
|
href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Noto+Sans+Mono:wght@100..900&display=swap"
|
||||||
|
rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="main-container">
|
||||||
|
<div class="user-header">
|
||||||
|
<h1 id="user-name">Loading...</h1>
|
||||||
|
<p id="user-uuid"></p>
|
||||||
|
</div>
|
||||||
|
<div class="user-pastes-section">
|
||||||
|
<div class="archive-information">
|
||||||
|
<p id="archive-title">Title</p>
|
||||||
|
<p id="archive-date">Date</p>
|
||||||
|
<p id="archive-syntax">Syntax</p>
|
||||||
|
</div>
|
||||||
|
<ul id="user-pastes-list" class="archive-list">
|
||||||
|
<div class="user-pastes-throbber throbber"></div>
|
||||||
|
</ul>
|
||||||
|
<div class="pastes-actions">
|
||||||
|
<button id="previous-button"><span id="previous-button-svg"></span></button>
|
||||||
|
<p id="paste-pages">0/0</p>
|
||||||
|
<button id="next-button"><span id="next-button-svg"></span></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<script src="/js/user.js"></script>
|
||||||
|
<script src="/js/main.js"></script>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user