Split code into classes to make the codebase look cleaner

Added a new favicon/icon
Add more checks before uploading a paste, changed alert to use the showNotification function
Added password modal for private pastes instead of using alert
Fix a paste page navigation in dashboard
Improve auth css
This commit is contained in:
whoswhip
2025-05-23 18:54:29 -04:00
parent 2126c3a078
commit 73743399f1
17 changed files with 1027 additions and 491 deletions
+16
View File
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "C#: SharpbinV2.Server Start",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/SharpbinV2.Server.csproj"
}
]
}
+55
View File
@@ -0,0 +1,55 @@
namespace SharpbinV2.Server
{
public class User
{
public int? UID { get; set; }
public string? UUID { get; set; }
public int? Type { get; set; }
public string? Email { get; set; }
public string? Username { get; set; }
public string? DisplayName { get; set; }
public string? Password { get; set; }
public long? Created { get; set; }
public long? LastLogin { get; set; }
}
public class Paste
{
public string? UUID { get; set; }
public string? ID { get; set; }
public int? Visibility { get; set; }
public string? Title { get; set; }
public string? AuthorUUID { get; set; }
public string? FilePath { get; set; }
public long? Created { get; set; }
public long? Edited { get; set; }
public int? Size { get; set; }
public int? TrueSize { get; set; }
public int? Views { get; set; }
public string? Syntax { get; set; }
}
public class Session
{
public string? UUID { get; set; }
public string? UserUUID { get; set; }
public string? Token { get; set; }
public long? Created { get; set; }
public long? Expirary { get; set; }
public string? Ip { get; set; }
public string? UserAgent { get; set; }
}
public class RequestDetails
{
public string? Ip { get; set; }
public string? UserAgent { get; set; }
public string? Token { get; set; }
}
public class View
{
public string? UUID { get; set; }
public string? PasteUUID { get; set; }
public string? UserUUID { get; set; }
public string? IP { get; set; }
public string? UserAgent { get; set; }
public long? Created { get; set; }
}
}
+73
View File
@@ -0,0 +1,73 @@
using System.IO.Compression;
using System.Text;
namespace SharpbinV2.Server
{
public class Compression
{
// Taken from old branch
public static async Task<byte[]> CompressString(string text)
{
byte[] compressedBytes;
using (var ms = new MemoryStream())
{
using (var cs = new GZipStream(ms, CompressionMode.Compress))
{
byte[] inputBytes = Encoding.UTF8.GetBytes(text);
await cs.WriteAsync(inputBytes, 0, inputBytes.Length);
}
compressedBytes = ms.ToArray();
}
return compressedBytes;
}
public static async Task<string> DecompressByteArrayToString(byte[] compressedBytes)
{
string decompressedText;
using (var ms = new MemoryStream(compressedBytes))
{
using (var cs = new GZipStream(ms, CompressionMode.Decompress))
{
using (var sr = new StreamReader(cs))
{
decompressedText = await sr.ReadToEndAsync();
}
}
}
return decompressedText;
}
public static async Task<byte[]> DecompressByteArray(byte[] compressedBytes)
{
byte[] decompressedBytes;
using (var ms = new MemoryStream(compressedBytes))
{
using (var cs = new GZipStream(ms, CompressionMode.Decompress))
{
using (var msDecompressed = new MemoryStream())
{
await cs.CopyToAsync(msDecompressed);
decompressedBytes = msDecompressed.ToArray();
}
}
}
return decompressedBytes;
}
public static async Task<bool> ShouldCompress(string text, int sizeThreshold = 512, double ratioThreshold = 0.8)
{
if (string.IsNullOrEmpty(text))
return false;
byte[] inputBytes = Encoding.UTF8.GetBytes(text);
if (inputBytes.Length < sizeThreshold)
return false;
byte[] compressedBytes = await CompressString(text).ConfigureAwait(false);
double compressionRatio = (double)compressedBytes.Length / inputBytes.Length;
return compressionRatio < ratioThreshold;
}
public static bool IsCompressed(byte[] data)
{
return data.Length >= 2 && data[0] == 0x1F && data[1] == 0x8B;
}
}
}
+283
View File
@@ -0,0 +1,283 @@
using Microsoft.Data.Sqlite;
namespace SharpbinV2.Server
{
public class Database
{
public static async Task<User> UserFromUsername(string username)
{
if (string.IsNullOrEmpty(username))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM users WHERE Username = @Username;";
command.Parameters.AddWithValue("@Username", username);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return new User
{
UID = reader.GetInt32(0),
UUID = reader.GetString(1),
Type = reader.GetInt32(2),
Email = reader.IsDBNull(3) ? null : reader.GetString(3),
Username = reader.GetString(4),
DisplayName = reader.IsDBNull(5) ? null : reader.GetString(5),
Password = reader.GetString(6),
Created = reader.GetInt64(7),
LastLogin = reader.GetInt64(8)
};
}
}
}
}
public static async Task<User> UserFromUUID(string uuid)
{
if (string.IsNullOrEmpty(uuid))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM users WHERE UUID = @UUID;";
command.Parameters.AddWithValue("@UUID", uuid);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return new User
{
UID = reader.GetInt32(0),
UUID = reader.GetString(1),
Type = reader.GetInt32(2),
Email = reader.IsDBNull(3) ? null : reader.GetString(3),
Username = reader.GetString(4),
DisplayName = reader.IsDBNull(5) ? null : reader.GetString(5),
Password = reader.GetString(6),
Created = reader.GetInt64(7),
LastLogin = reader.GetInt64(8)
};
}
}
}
}
public static async Task<User> UserFromEmail(string email)
{
if (string.IsNullOrEmpty(email))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM users WHERE Email = @Email;";
command.Parameters.AddWithValue("@Email", email);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return new User
{
UID = reader.GetInt32(0),
UUID = reader.GetString(1),
Type = reader.GetInt32(2),
Email = reader.IsDBNull(3) ? null : reader.GetString(3),
Username = reader.GetString(4),
DisplayName = reader.IsDBNull(5) ? null : reader.GetString(5),
Password = reader.GetString(6),
Created = reader.GetInt64(7),
LastLogin = reader.GetInt64(8)
};
}
}
}
}
public static async Task<User> UserFromToken(string token)
{
if (string.IsNullOrEmpty(token))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM sessions WHERE Token = @Token;";
command.Parameters.AddWithValue("@Token", token);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return await UserFromUUID(reader.GetString(1));
}
}
}
}
public static async Task<int> EnumeratePastes()
{
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT COUNT(*) FROM pastes;";
return Convert.ToInt32(await command.ExecuteScalarAsync());
}
}
}
public static async Task<int> EnumerateUserPastes(User user)
{
if (user == null)
return 0;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT COUNT(*) FROM pastes WHERE AuthorUUID = @AuthorUUID;";
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
return Convert.ToInt32(await command.ExecuteScalarAsync());
}
}
}
public static async Task<Paste> GetPasteFromID(string id)
{
if (string.IsNullOrEmpty(id))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM pastes WHERE ID = @ID;";
command.Parameters.AddWithValue("@ID", id);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return 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),
FilePath = reader.GetString(6),
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)
};
}
}
}
}
public static async Task<bool> HasAlreadyViewedFromRqDetails(RequestDetails details)
{
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM views WHERE Ip = @Ip AND UserAgent = @UserAgent;";
command.Parameters.AddWithValue("@Ip", Program.HMAC256HASH(details.Ip));
command.Parameters.AddWithValue("@UserAgent", details.UserAgent);
using (var reader = await command.ExecuteReaderAsync())
{
return reader.HasRows;
}
}
}
}
public static async Task<bool> HasAlreadyViewedFromUserDetails(User user)
{
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM views WHERE UserUUID = @UserUUID;";
command.Parameters.AddWithValue("@UserUUID", user.UUID);
using (var reader = await command.ExecuteReaderAsync())
{
return reader.HasRows;
}
}
}
}
public static async Task AddViewToPaste(User user, Paste paste, RequestDetails details)
{
if (paste == null || details == null)
return;
var _user = user ?? new User { UUID = "0" };
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO views (UserUUID, PasteUUID, Ip, UserAgent, Created) VALUES (@UserUUID, @PasteUUID, @Ip, @UserAgent, @Created);";
command.Parameters.AddWithValue("@UserUUID", _user.UUID);
command.Parameters.AddWithValue("@PasteUUID", paste.UUID);
command.Parameters.AddWithValue("@Ip", Program.HMAC256HASH(details.Ip));
command.Parameters.AddWithValue("@UserAgent", details.UserAgent);
command.Parameters.AddWithValue("@Created", DateTimeOffset.UtcNow.ToUnixTimeSeconds());
await command.ExecuteNonQueryAsync();
command.CommandText = "UPDATE pastes SET Views = Views + 1 WHERE UUID = @UUID;";
command.Parameters.AddWithValue("@UUID", paste.UUID);
await command.ExecuteNonQueryAsync();
}
await connection.CloseAsync();
}
}
public static async Task<List<Paste>> PastesFromUser(User user)
{
if (user == null)
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM pastes WHERE AuthorUUID = @AuthorUUID;";
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
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),
FilePath = reader.GetString(6),
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)
});
}
return pastes;
}
}
}
}
}
}
+30
View File
@@ -0,0 +1,30 @@
namespace SharpbinV2.Server
{
public class Logging
{
public Logging()
{
if (!Directory.Exists("logs"))
Directory.CreateDirectory("logs");
}
public void LogInfo(string message)
{
Console.WriteLine($"[{DateTime.Now} INFO] {message}");
File.AppendAllText($"logs/{DateTime.Now.ToString("yyyy-MM-dd")}.log", $"[{DateTime.Now} INFO] {message}\n");
}
public void LogWarning(string message)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[{DateTime.Now} WARNING] {message}");
File.AppendAllText($"logs/{DateTime.Now.ToString("yyyy-MM-dd")}.log", $"[{DateTime.Now} WARNING] {message}\n");
Console.ResetColor();
}
public void LogError(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[{DateTime.Now} ERROR] {message}");
File.AppendAllText($"logs/{DateTime.Now.ToString("yyyy-MM-dd")}.log", $"[{DateTime.Now} ERROR] {message}\n");
Console.ResetColor();
}
}
}
+126 -433
View File
@@ -1,22 +1,16 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.RateLimiting;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Logging.Configuration;
using Microsoft.Extensions.Logging.EventSource;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Threading.RateLimiting;
using System.Text; using System.Text;
using Bcrypt = BCrypt.Net.BCrypt; using Bcrypt = BCrypt.Net.BCrypt;
using System.IO.Compression;
using System.Threading.Tasks;
using System.Security.Cryptography; using System.Security.Cryptography;
using UAParser;
namespace SharpbinV2.Server namespace SharpbinV2.Server
{ {
class Program class Program
{ {
public static string MainDatabaseConnection = "Data Source=data.db"; public static string MainDatabaseConnection = "Data Source=data.db";
public static long MaxFileSize = 1_000_000; // 1MB public static long MaxFileSize = 1_048_576; // 1MB
public static string[] ValidSyntaxLanguages = public static string[] ValidSyntaxLanguages =
{ {
"none", "none",
@@ -489,15 +483,16 @@ namespace SharpbinV2.Server
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid token." }); await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid token." });
return; return;
} }
var cleanuser = new User var cleanuser = new
{ {
UID = user.UID, user.UID,
UUID = user.UUID, user.UUID,
Username = user.Username, user.Username,
Email = user.Email, user.Email,
DisplayName = user.DisplayName, user.DisplayName,
Created = user.Created, user.Created,
LastLogin = user.LastLogin user.LastLogin,
user.Type,
}; };
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new { success = true, user = cleanuser }); await context.Response.WriteAsJsonAsync(new { success = true, user = cleanuser });
@@ -745,10 +740,10 @@ namespace SharpbinV2.Server
await context.Response.WriteAsJsonAsync(new { success = false, message = "No pastes found." }); await context.Response.WriteAsJsonAsync(new { success = false, message = "No pastes found." });
return; return;
} }
var pastes = new List<Paste>(); var pastes = new List<object>();
while (await reader.ReadAsync()) while (await reader.ReadAsync())
{ {
pastes.Add(new Paste pastes.Add(new
{ {
UUID = reader.GetString(1), UUID = reader.GetString(1),
ID = reader.GetString(2), ID = reader.GetString(2),
@@ -925,6 +920,86 @@ namespace SharpbinV2.Server
} }
return; return;
}); });
app.MapGet("/api/pastes/{pasteid}/views", async (HttpContext context) =>
{
var requestdetails = GetRequestDetails(context);
var pasteid = context.Request.RouteValues["pasteid"].ToString() ?? null;
if (string.IsNullOrEmpty(pasteid))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid Paste ID." });
return;
}
if (string.IsNullOrEmpty(requestdetails.Token))
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Not authorized. Please provide a token." });
return;
}
var user = await Database.UserFromToken(requestdetails.Token);
if (user == null)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid token." });
return;
}
var paste = await Database.GetPasteFromID(pasteid);
if (paste == null)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "Paste not found." });
return;
}
if (paste.AuthorUUID != user.UUID)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "You are not the author of this paste." });
return;
}
using (var connection = new SqliteConnection(MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM views WHERE PasteUUID = @PasteUUID;";
command.Parameters.AddWithValue("@PasteUUID", paste.UUID);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
{
context.Response.StatusCode = 400;
await context.Response.WriteAsJsonAsync(new { success = false, message = "No views found." });
return;
}
var views = new List<object>();
var uaparser = Parser.GetDefault();
int viewcount = 0;
while (await reader.ReadAsync())
{
viewcount++;
string useragent = reader.GetString(3);
var clientInfo = uaparser.Parse(useragent);
views.Add(new
{
PasteUUID = reader.GetString(1),
Created = reader.GetInt64(4),
UserAgent = new
{
browser = clientInfo.UA.Family,
platform = clientInfo.OS.Family,
device = clientInfo.Device.Family,
}
});
}
context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new { success = true, views, viewcount });
}
}
}
});
app.MapGet("/api/users/uuid/{uuid}", async (HttpContext context) => app.MapGet("/api/users/uuid/{uuid}", async (HttpContext context) =>
{ {
@@ -1072,6 +1147,16 @@ namespace SharpbinV2.Server
} }
}); });
app.MapGet("/api/site/info", async (HttpContext context) =>
{
context.Response.StatusCode = 200;
var info = new
{
MaxFileSize
};
await context.Response.WriteAsJsonAsync(new { success = true, info });
});
#endregion #endregion
@@ -1221,6 +1306,27 @@ namespace SharpbinV2.Server
Created INTEGER NOT NULL Created INTEGER NOT NULL
);"; );";
await command.ExecuteNonQueryAsync(); await command.ExecuteNonQueryAsync();
command.CommandText = @"CREATE TABLE IF NOT EXISTS punishments (
UID INTEGER NOT NULL UNIQUE,
UUID TEXT NOT NULL UNIQUE,
Type INTEGER NOT NULL DEFAULT 0,
Reason TEXT,
Created INTEGER NOT NULL,
Expirary INTEGER NOT NULL,
PRIMARY KEY(UID AUTOINCREMENT)
);";
await command.ExecuteNonQueryAsync();
command.CommandText = @"CREATE TABLE IF NOT EXISTS passwordresets (
UID INTEGER NOT NULL UNIQUE,
UUID TEXT NOT NULL UNIQUE,
USERUUID TEXT NOT NULL UNIQUE,
URL TEXT NOT NULL UNIQUE,
Token TEXT NOT NULL UNIQUE,
Created INTEGER NOT NULL,
Expirary INTEGER NOT NULL,
PRIMARY KEY(UID AUTOINCREMENT)
);";
await command.ExecuteNonQueryAsync();
await connection.CloseAsync(); await connection.CloseAsync();
} }
} }
@@ -1241,311 +1347,8 @@ namespace SharpbinV2.Server
} }
} }
class Database
{
public static async Task<User> UserFromUsername(string username)
{
if (string.IsNullOrEmpty(username))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM users WHERE Username = @Username;";
command.Parameters.AddWithValue("@Username", username);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return new User
{
UID = reader.GetInt32(0),
UUID = reader.GetString(1),
Type = reader.GetInt32(2),
Email = reader.IsDBNull(3) ? null : reader.GetString(3),
Username = reader.GetString(4),
DisplayName = reader.IsDBNull(5) ? null : reader.GetString(5),
Password = reader.GetString(6),
Created = reader.GetInt64(7),
LastLogin = reader.GetInt64(8)
};
}
}
}
}
public static async Task<User> UserFromUUID(string uuid)
{
if (string.IsNullOrEmpty(uuid))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM users WHERE UUID = @UUID;";
command.Parameters.AddWithValue("@UUID", uuid);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return new User
{
UID = reader.GetInt32(0),
UUID = reader.GetString(1),
Type = reader.GetInt32(2),
Email = reader.IsDBNull(3) ? null : reader.GetString(3),
Username = reader.GetString(4),
DisplayName = reader.IsDBNull(5) ? null : reader.GetString(5),
Password = reader.GetString(6),
Created = reader.GetInt64(7),
LastLogin = reader.GetInt64(8)
};
}
}
}
}
public static async Task<User> UserFromEmail(string email)
{
if (string.IsNullOrEmpty(email))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM users WHERE Email = @Email;";
command.Parameters.AddWithValue("@Email", email);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return new User
{
UID = reader.GetInt32(0),
UUID = reader.GetString(1),
Type = reader.GetInt32(2),
Email = reader.IsDBNull(3) ? null : reader.GetString(3),
Username = reader.GetString(4),
DisplayName = reader.IsDBNull(5) ? null : reader.GetString(5),
Password = reader.GetString(6),
Created = reader.GetInt64(7),
LastLogin = reader.GetInt64(8)
};
}
}
}
}
public static async Task<User> UserFromToken(string token)
{
if (string.IsNullOrEmpty(token))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM sessions WHERE Token = @Token;";
command.Parameters.AddWithValue("@Token", token);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return await UserFromUUID(reader.GetString(1));
}
}
}
}
public static async Task<int> EnumeratePastes()
{
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT COUNT(*) FROM pastes;";
return Convert.ToInt32(await command.ExecuteScalarAsync());
}
}
}
public static async Task<int> EnumerateUserPastes(User user)
{
if (user == null)
return 0;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT COUNT(*) FROM pastes WHERE AuthorUUID = @AuthorUUID;";
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
return Convert.ToInt32(await command.ExecuteScalarAsync());
}
}
}
public static async Task<Paste> GetPasteFromID(string id)
{
if (string.IsNullOrEmpty(id))
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM pastes WHERE ID = @ID;";
command.Parameters.AddWithValue("@ID", id);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
await reader.ReadAsync();
return 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),
FilePath = reader.GetString(6),
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)
};
}
}
}
}
public static async Task<bool> HasAlreadyViewedFromRqDetails(RequestDetails details)
{
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM views WHERE Ip = @Ip AND UserAgent = @UserAgent;";
command.Parameters.AddWithValue("@Ip", Program.HMAC256HASH(details.Ip));
command.Parameters.AddWithValue("@UserAgent", details.UserAgent);
using (var reader = await command.ExecuteReaderAsync())
{
return reader.HasRows;
}
}
}
}
public static async Task<bool> HasAlreadyViewedFromUserDetails(User user)
{
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM views WHERE UserUUID = @UserUUID;";
command.Parameters.AddWithValue("@UserUUID", user.UUID);
using (var reader = await command.ExecuteReaderAsync())
{
return reader.HasRows;
}
}
}
}
public static async Task AddViewToPaste(User user, Paste paste, RequestDetails details)
{
if (paste == null || details == null)
return;
var _user = user ?? new User { UUID = "0" };
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO views (UserUUID, PasteUUID, Ip, UserAgent, Created) VALUES (@UserUUID, @PasteUUID, @Ip, @UserAgent, @Created);";
command.Parameters.AddWithValue("@UserUUID", _user.UUID);
command.Parameters.AddWithValue("@PasteUUID", paste.UUID);
command.Parameters.AddWithValue("@Ip", Program.HMAC256HASH(details.Ip));
command.Parameters.AddWithValue("@UserAgent", details.UserAgent);
command.Parameters.AddWithValue("@Created", DateTimeOffset.UtcNow.ToUnixTimeSeconds());
await command.ExecuteNonQueryAsync();
command.CommandText = "UPDATE pastes SET Views = Views + 1 WHERE UUID = @UUID;";
command.Parameters.AddWithValue("@UUID", paste.UUID);
await command.ExecuteNonQueryAsync();
}
await connection.CloseAsync();
}
}
public static async Task <List<Paste>> PastesFromUser(User user)
{
if (user == null)
return null;
using (var connection = new SqliteConnection(Program.MainDatabaseConnection))
{
await connection.OpenAsync();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM pastes WHERE AuthorUUID = @AuthorUUID;";
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
using (var reader = await command.ExecuteReaderAsync())
{
if (!reader.HasRows)
return null;
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),
FilePath = reader.GetString(6),
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)
});
}
return pastes;
}
}
}
}
}
public class Logging
{
public Logging()
{
if (!Directory.Exists("logs"))
Directory.CreateDirectory("logs");
}
public void LogInfo(string message)
{
Console.WriteLine($"[{DateTime.Now} INFO] {message}");
File.AppendAllText($"logs/{DateTime.Now.ToString("yyyy-MM-dd")}.log", $"[{DateTime.Now} INFO] {message}\n");
}
public void LogWarning(string message)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[{DateTime.Now} WARNING] {message}");
File.AppendAllText($"logs/{DateTime.Now.ToString("yyyy-MM-dd")}.log", $"[{DateTime.Now} WARNING] {message}\n");
Console.ResetColor();
}
public void LogError(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[{DateTime.Now} ERROR] {message}");
File.AppendAllText($"logs/{DateTime.Now.ToString("yyyy-MM-dd")}.log", $"[{DateTime.Now} ERROR] {message}\n");
Console.ResetColor();
}
}
/// <summary> /// <summary>
/// https://dusted.codes/dotenv-in-dotnet /// https://dusted.codes/dotenv-in-dotnet
@@ -1570,114 +1373,4 @@ namespace SharpbinV2.Server
} }
} }
} }
public class Compression
{
// Taken from old branch
public static async Task<byte[]> CompressString(string text)
{
byte[] compressedBytes;
using (var ms = new MemoryStream())
{
using (var cs = new GZipStream(ms, CompressionMode.Compress))
{
byte[] inputBytes = Encoding.UTF8.GetBytes(text);
await cs.WriteAsync(inputBytes, 0, inputBytes.Length);
}
compressedBytes = ms.ToArray();
}
return compressedBytes;
}
public static async Task<string> DecompressByteArrayToString(byte[] compressedBytes)
{
string decompressedText;
using (var ms = new MemoryStream(compressedBytes))
{
using (var cs = new GZipStream(ms, CompressionMode.Decompress))
{
using (var sr = new StreamReader(cs))
{
decompressedText = await sr.ReadToEndAsync();
}
}
}
return decompressedText;
}
public static async Task<byte[]> DecompressByteArray(byte[] compressedBytes)
{
byte[] decompressedBytes;
using (var ms = new MemoryStream(compressedBytes))
{
using (var cs = new GZipStream(ms, CompressionMode.Decompress))
{
using (var msDecompressed = new MemoryStream())
{
await cs.CopyToAsync(msDecompressed);
decompressedBytes = msDecompressed.ToArray();
}
}
}
return decompressedBytes;
}
public static async Task<bool> ShouldCompress(string text, int sizeThreshold = 512, double ratioThreshold = 0.8)
{
if (string.IsNullOrEmpty(text))
return false;
byte[] inputBytes = Encoding.UTF8.GetBytes(text);
if (inputBytes.Length < sizeThreshold)
return false;
byte[] compressedBytes = await CompressString(text).ConfigureAwait(false);
double compressionRatio = (double)compressedBytes.Length / inputBytes.Length;
return compressionRatio < ratioThreshold;
}
public static bool IsCompressed(byte[] data)
{
return data.Length >= 2 && data[0] == 0x1F && data[1] == 0x8B;
}
}
class User
{
public int? UID { get; set; }
public string? UUID { get; set; }
public int? Type { get; set; }
public string? Email { get; set; }
public string? Username { get; set; }
public string? DisplayName { get; set; }
public string? Password { get; set; }
public long? Created { get; set; }
public long? LastLogin { get; set; }
}
class Paste
{
public string? UUID { get; set; }
public string? ID { get; set; }
public int? Visibility { get; set; }
public string? Title { get; set; }
public string? AuthorUUID { get; set; }
public string? FilePath { get; set; }
public long? Created { get; set; }
public long? Edited { get; set; }
public int? Size { get; set; }
public int? TrueSize { get; set; }
public int? Views { get; set; }
public string? Syntax { get; set; }
}
class Session
{
public string? UUID { get; set; }
public string? UserUUID { get; set; }
public string? Token { get; set; }
public long? Created { get; set; }
public long? Expirary { get; set; }
public string? Ip { get; set; }
public string? UserAgent { get; set; }
}
class RequestDetails
{
public string? Ip { get; set; }
public string? UserAgent { get; set; }
public string? Token { get; set; }
}
} }
+2 -1
View File
@@ -11,10 +11,11 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.5" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" /> <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="UAParser" Version="3.1.47" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+10 -1
View File
@@ -3,6 +3,7 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
min-height: 100vh; min-height: 100vh;
min-width: 100%;
padding: 20px; padding: 20px;
background-color: var(--neutral-950); background-color: var(--neutral-950);
} }
@@ -13,7 +14,7 @@
padding: 30px; padding: 30px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
width: 100%; width: 100%;
max-width: 450px; max-width: 650px;
border: 1px solid var(--neutral-800); border: 1px solid var(--neutral-800);
} }
@@ -131,10 +132,18 @@
} }
@media (max-width: 480px) { @media (max-width: 480px) {
.auth-container {
padding: 0px;
}
.auth-form-container { .auth-form-container {
padding: 20px; padding: 20px;
max-width: 100%;
border-radius: 0;
} }
.auth-title { .auth-title {
font-size: 1.6rem; font-size: 1.6rem;
} }
+54 -28
View File
@@ -14,7 +14,8 @@ body {
gap: 25px; gap: 25px;
} }
.account-info, .paste-list { .account-info,
.paste-list {
width: 48%; width: 48%;
border-radius: 8px; border-radius: 8px;
padding: 25px; padding: 25px;
@@ -34,12 +35,14 @@ body {
flex-direction: column; flex-direction: column;
} }
.account-info:hover, .paste-list:hover { .account-info:hover,
.paste-list:hover {
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
border-color: var(--neutral-700); border-color: var(--neutral-700);
} }
.account-info h1, .paste-list h1 { .account-info h1,
.paste-list h1 {
margin-bottom: 25px; margin-bottom: 25px;
color: var(--neutral-100); color: var(--neutral-100);
text-align: center; text-align: center;
@@ -126,6 +129,12 @@ body {
color: var(--neutral-300); color: var(--neutral-300);
font-size: 0.9rem; font-size: 0.9rem;
text-align: center; text-align: center;
overflow: hidden !important;
text-overflow: clip !important;
white-space: nowrap !important;
max-width: 80px;
text-align: left;
margin-right: -70px !important;
} }
#paste-syntax { #paste-syntax {
@@ -134,20 +143,7 @@ body {
text-align: right; text-align: right;
} }
@media (max-width: 768px) {
#pastes li a {
grid-template-columns: 3fr 2fr;
}
#paste-syntax {
display: none;
}
}
@media (max-width: 576px) {
#pastes li a {
padding: 0.7rem 0.8rem;
}
}
.paste-actions { .paste-actions {
display: flex; display: flex;
@@ -220,7 +216,8 @@ body {
padding: 15px; padding: 15px;
} }
.account-info, .paste-list { .account-info,
.paste-list {
padding: 20px; padding: 20px;
} }
} }
@@ -231,7 +228,8 @@ body {
gap: 20px; gap: 20px;
} }
.account-info, .paste-list { .account-info,
.paste-list {
width: 100%; width: 100%;
} }
} }
@@ -241,23 +239,27 @@ body {
padding: 10px; padding: 10px;
} }
.account-info, .paste-list { .account-info,
.paste-list {
padding: 15px; padding: 15px;
} }
.account-info h1, .paste-list h1 { .account-info h1,
.paste-list h1 {
font-size: 1.5rem; font-size: 1.5rem;
} }
#pastes li { #pastes li {
flex-direction: column; flex-direction: column;
align-items: flex-start; align-items: flex-start;
grid-template-columns: 1fr;
} }
#pastes li span { #pastes li span {
margin-top: 5px; margin-top: 5px;
font-size: 0.8rem; font-size: 0.8rem;
} }
} }
.logout-modal-overlay { .logout-modal-overlay {
@@ -266,31 +268,35 @@ body {
left: 0; left: 0;
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
background: rgba(0,0,0,0.5); background: rgba(0, 0, 0, 0.5);
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
z-index: 2000; z-index: 2000;
} }
.logout-modal-box { .logout-modal-box {
background: var(--neutral-900); background: var(--neutral-900);
color: var(--neutral-100); color: var(--neutral-100);
padding: 2rem 2.5rem; padding: 2rem 2.5rem;
border-radius: 10px; border-radius: 10px;
box-shadow: 0 8px 32px rgba(0,0,0,0.25); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
text-align: center; text-align: center;
min-width: 300px; min-width: 300px;
max-width: 90vw; max-width: 90vw;
} }
.logout-modal-box h2 { .logout-modal-box h2 {
margin-bottom: 1rem; margin-bottom: 1rem;
font-size: 1.4rem; font-size: 1.4rem;
color: var(--neutral-50); color: var(--neutral-50);
} }
.logout-modal-box p { .logout-modal-box p {
margin-bottom: 2rem; margin-bottom: 2rem;
color: var(--neutral-300); color: var(--neutral-300);
} }
.logout-modal-box button { .logout-modal-box button {
margin: 0 0.5rem; margin: 0 0.5rem;
padding: 0.7rem 1.5rem; padding: 0.7rem 1.5rem;
@@ -301,17 +307,21 @@ body {
font-size: 1rem; font-size: 1rem;
transition: background 0.2s, color 0.2s; transition: background 0.2s, color 0.2s;
} }
#confirm-logout { #confirm-logout {
background: #e74c3c; background: #e74c3c;
color: #fff; color: #fff;
} }
#confirm-logout:hover { #confirm-logout:hover {
background: #c0392b; background: #c0392b;
} }
#cancel-logout { #cancel-logout {
background: var(--neutral-700); background: var(--neutral-700);
color: #fff; color: #fff;
} }
#cancel-logout:hover { #cancel-logout:hover {
background: var(--neutral-600); background: var(--neutral-600);
} }
@@ -327,15 +337,17 @@ body {
font-weight: 500; font-weight: 500;
cursor: pointer; cursor: pointer;
transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s; transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
box-shadow: 0 2px 8px rgba(0,0,0,0.08); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
letter-spacing: 0.5px; letter-spacing: 0.5px;
} }
#logout-button:hover { #logout-button:hover {
background-color: var(--neutral-600); background-color: var(--neutral-600);
color: var(--neutral-10); color: var(--neutral-10);
transform: translateY(-2px); transform: translateY(-2px);
box-shadow: 0 4px 16px rgba(0,0,0,0.13); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.13);
} }
#logout-button:active { #logout-button:active {
background-color: var(--neutral-800); background-color: var(--neutral-800);
color: var(--neutral-200); color: var(--neutral-200);
@@ -353,16 +365,18 @@ body {
font-weight: 500; font-weight: 500;
cursor: pointer; cursor: pointer;
transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s; transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.2s;
box-shadow: 0 2px 8px rgba(0,0,0,0.08); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
letter-spacing: 0.5px; letter-spacing: 0.5px;
margin-top: 10px; margin-top: 10px;
} }
#delete-account-button:hover { #delete-account-button:hover {
background-color: #c0392b; background-color: #c0392b;
color: #fff; color: #fff;
transform: translateY(-2px); transform: translateY(-2px);
box-shadow: 0 4px 16px rgba(0,0,0,0.13); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.13);
} }
#delete-account-button:active { #delete-account-button:active {
background-color: #a93226; background-color: #a93226;
color: #fff; color: #fff;
@@ -376,31 +390,35 @@ body {
left: 0; left: 0;
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
background: rgba(0,0,0,0.5); background: rgba(0, 0, 0, 0.5);
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
z-index: 2100; z-index: 2100;
} }
.delete-modal-box { .delete-modal-box {
background: var(--neutral-900); background: var(--neutral-900);
color: var(--neutral-100); color: var(--neutral-100);
padding: 2rem 2.5rem; padding: 2rem 2.5rem;
border-radius: 10px; border-radius: 10px;
box-shadow: 0 8px 32px rgba(0,0,0,0.25); box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
text-align: center; text-align: center;
min-width: 320px; min-width: 320px;
max-width: 95vw; max-width: 95vw;
} }
.delete-modal-box h2 { .delete-modal-box h2 {
margin-bottom: 1rem; margin-bottom: 1rem;
font-size: 1.4rem; font-size: 1.4rem;
color: #e74c3c; color: #e74c3c;
} }
.delete-modal-box p { .delete-modal-box p {
margin-bottom: 1.2rem; margin-bottom: 1.2rem;
color: var(--neutral-300); color: var(--neutral-300);
} }
.delete-modal-box input { .delete-modal-box input {
margin-bottom: 0.7rem; margin-bottom: 0.7rem;
width: 90%; width: 90%;
@@ -413,9 +431,11 @@ body {
outline: none; outline: none;
transition: border 0.2s; transition: border 0.2s;
} }
.delete-modal-box input:focus { .delete-modal-box input:focus {
border: 1.5px solid #e74c3c; border: 1.5px solid #e74c3c;
} }
.delete-modal-box button { .delete-modal-box button {
margin: 0 0.5rem; margin: 0 0.5rem;
padding: 0.7rem 1.5rem; padding: 0.7rem 1.5rem;
@@ -426,13 +446,16 @@ body {
font-size: 1rem; font-size: 1rem;
transition: background 0.2s, color 0.2s; transition: background 0.2s, color 0.2s;
} }
#confirm-delete-account { #confirm-delete-account {
background: #e74c3c; background: #e74c3c;
color: #fff; color: #fff;
} }
#confirm-delete-account:hover { #confirm-delete-account:hover {
background: #c0392b; background: #c0392b;
} }
#confirm-delete-account:disabled { #confirm-delete-account:disabled {
background: var(--neutral-800); background: var(--neutral-800);
color: var(--neutral-500); color: var(--neutral-500);
@@ -441,13 +464,16 @@ body {
box-shadow: none; box-shadow: none;
transform: none; transform: none;
} }
#cancel-delete-account { #cancel-delete-account {
background: var(--neutral-700); background: var(--neutral-700);
color: #fff; color: #fff;
} }
#cancel-delete-account:hover { #cancel-delete-account:hover {
background: var(--neutral-600); background: var(--neutral-600);
} }
#delete-error { #delete-error {
color: #e74c3c; color: #e74c3c;
font-size: 1rem; font-size: 1rem;
+200 -6
View File
@@ -8,12 +8,24 @@
} }
#blur { #blur {
z-index: 999; z-index: 50;
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
pointer-events: auto;
}
#notification-container {
position: fixed;
z-index: 10001;
top: 24px;
left: 0;
right: 0;
margin: 0 auto;
width: fit-content;
pointer-events: none;
} }
.paste-information { .paste-information {
@@ -55,7 +67,7 @@
#paste-content { #paste-content {
padding: 10px; padding: 10px;
max-width: 100%; max-width: 100%;
max-height: 20vh; max-height: 50vh;
overflow-y: scroll; overflow-y: scroll;
overflow-wrap: break-word; overflow-wrap: break-word;
word-wrap: break-word; word-wrap: break-word;
@@ -103,6 +115,7 @@ button:active {
.hljs-ln-numbers { .hljs-ln-numbers {
border-right: 1px solid var(--neutral-700); border-right: 1px solid var(--neutral-700);
padding-right: 8px !important; padding-right: 8px !important;
padding-left: 8px !important;
text-align: center; text-align: center;
user-select: none; user-select: none;
} }
@@ -122,9 +135,10 @@ pre code.hljs {
code.hljs { code.hljs {
padding: 3px 5px padding: 3px 5px
} }
.hljs { .hljs {
color: #c9d1d9; color: #c9d1d9;
background: var(--neutral-900); background: #1e1e1e;
} }
.hljs-doctag, .hljs-doctag,
@@ -225,11 +239,15 @@ code.hljs {
} }
@keyframes spin { @keyframes spin {
0% { transform: rotate(0deg); } 0% {
100% { transform: rotate(360deg); } transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
} }
/* Minimal, clean style for paste information card */
.paste-information-card { .paste-information-card {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
@@ -244,6 +262,7 @@ code.hljs {
border-bottom: 1px solid var(--neutral-700); border-bottom: 1px solid var(--neutral-700);
min-width: 0; min-width: 0;
} }
.paste-info-item { .paste-info-item {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -256,20 +275,24 @@ code.hljs {
padding: 0 6px; padding: 0 6px;
transition: none; transition: none;
} }
.info-icon { .info-icon {
font-size: 1em; font-size: 1em;
opacity: 0.7; opacity: 0.7;
margin-right: 2px; margin-right: 2px;
} }
#author-link { #author-link {
color: var(--neutral-100); color: var(--neutral-100);
text-decoration: underline dotted; text-decoration: underline dotted;
font-weight: 400; font-weight: 400;
transition: color 0.2s; transition: color 0.2s;
} }
#author-link:hover { #author-link:hover {
color: #4ea1f7; color: #4ea1f7;
} }
.paste-header h1#paste-title { .paste-header h1#paste-title {
font-size: 1.5rem; font-size: 1.5rem;
font-weight: 600; font-weight: 600;
@@ -286,18 +309,189 @@ code.hljs {
vertical-align: middle; vertical-align: middle;
opacity: 0.7; opacity: 0.7;
} }
.syntax-icon { .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; 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 { .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; 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 { .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; 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 { .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; 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 { .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; 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;
} }
#password-modal-bg {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
z-index: 101;
}
#password-modal {
background: var(--neutral-900);
padding: 2em 2.5em 1.5em 2.5em;
border-radius: 12px;
box-shadow: 0 4px 32px #000a;
display: flex;
flex-direction: column;
align-items: center;
min-width: 320px;
border: 1px solid var(--neutral-800);
font-family: inherit;
color: white;
}
#password-modal .modal-title {
font-weight: bold;
font-size: 1.2em;
margin-bottom: 0.5em;
letter-spacing: 0.5px;
color: white
}
#password-modal label {
margin-bottom: 1em;
color: white;
font-size: 1em;
text-align: center;
}
#password-modal input[type="password"] {
margin-bottom: 1em;
padding: 0.7em 1em;
width: 100%;
border-radius: 6px;
border: 1px solid var(--neutral-900);
background: var(--neutral-800);
color: white;
font-size: 1em;
outline: none;
box-sizing: border-box;
transition: border-color 0.2s;
}
#password-modal input[type="password"]:focus {
border-color: var(--neutral-700);
}
#password-modal .modal-btn-row {
display: flex;
justify-content: space-between;
width: 100%;
gap: 0.5em;
}
#password-modal button {
padding: 0.5em 1.5em;
border-radius: 4px;
border: none;
font-weight: bold;
font-size: 1em;
cursor: pointer;
transition: background 0.2s;
}
#password-modal button:first-child {
background: var(--neutral-700);
border: 1px solid var(--neutral-600);
color: #fff;
}
#password-modal button:first-child:hover {
background: var(--neutral-600);
border: 1px solid var(--neutral-500);
}
#password-modal button:last-child {
background: var(--neutral-700);
border: 1px solid var(--neutral-600);
color: #fff;
}
#password-modal button:last-child:hover {
background: var(--neutral-600);
border: 1px solid var(--neutral-500);
}
.has-true-size-tooltip {
position: relative;
cursor: pointer;
}
.true-size-tooltip {
position: absolute;
left: 50%;
bottom: 120%;
transform: translateX(-50%);
background: var(--neutral-900, #23272e);
color: var(--neutral-50, #fff);
padding: 6px 14px;
border-radius: 6px;
font-size: 0.95em;
white-space: nowrap;
box-shadow: 0 2px 8px #0007;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s;
z-index: 200;
border: 1px solid var(--neutral-700, #444);
}
.has-true-size-tooltip:hover .true-size-tooltip {
opacity: 1;
}
@media (max-width: 768px) {
.main-container {
max-height: 100% !important;
}
#password-modal-bg {
padding: 1em;
}
#password-modal {
padding: 1.5em 2em 1em 2em;
min-width: auto;
}
#paste-content {
word-break: break-all;
}
}
@media (max-width: 480px) {
.paste-actions {
display: flex;
justify-content: space-between;
}
.paste-actions button {
width: 30%;
margin: 0;
margin-right: 2.5px;
margin-left: 2.5px;
}
.paste-information-card {
flex-direction: column;
align-items: flex-start;
gap: 4px;
}
}
+40 -3
View File
@@ -1,38 +1,45 @@
body, html { body,
html {
height: 100%; height: 100%;
min-height: 100%; min-height: 100%;
box-sizing: border-box; box-sizing: border-box;
} }
.main-container { .main-container {
max-width: 600px; max-width: 600px;
margin: 2.5rem auto; margin: 2.5rem auto;
padding: 1.5rem 1.5rem 2.5rem 1.5rem; padding: 1.5rem 1.5rem 2.5rem 1.5rem;
background-color: var(--neutral-900); background-color: var(--neutral-900);
border-radius: 10px; border-radius: 10px;
box-shadow: 0 4px 20px rgba(0,0,0,0.18); box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
width: 100%; width: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: stretch; align-items: stretch;
} }
.user-header { .user-header {
text-align: center; text-align: center;
margin-bottom: 2rem; margin-bottom: 2rem;
} }
.user-header h1 { .user-header h1 {
font-size: 2.1rem; font-size: 2.1rem;
font-weight: 700; font-weight: 700;
color: var(--neutral-50); color: var(--neutral-50);
margin: 0 0 0.2rem 0; margin: 0 0 0.2rem 0;
} }
.user-header p { .user-header p {
color: var(--neutral-400); color: var(--neutral-400);
font-size: 1rem; font-size: 1rem;
margin: 0; margin: 0;
} }
.user-pastes-section { .user-pastes-section {
margin-top: 0; margin-top: 0;
} }
.archive-information { .archive-information {
display: grid; display: grid;
grid-template-columns: 2fr 1fr 1fr; grid-template-columns: 2fr 1fr 1fr;
@@ -46,9 +53,11 @@ body, html {
border-bottom: 2px solid var(--neutral-700); border-bottom: 2px solid var(--neutral-700);
width: 100%; width: 100%;
} }
.archive-information p { .archive-information p {
margin: 0; margin: 0;
} }
.archive-list { .archive-list {
list-style-type: none; list-style-type: none;
margin: 0; margin: 0;
@@ -60,24 +69,30 @@ body, html {
scrollbar-width: thin; scrollbar-width: thin;
scrollbar-color: var(--neutral-700) var(--neutral-900); scrollbar-color: var(--neutral-700) var(--neutral-900);
} }
.archive-list::-webkit-scrollbar { .archive-list::-webkit-scrollbar {
width: 8px; width: 8px;
} }
.archive-list::-webkit-scrollbar-track { .archive-list::-webkit-scrollbar-track {
background: var(--neutral-900); background: var(--neutral-900);
border-radius: 6px; border-radius: 6px;
} }
.archive-list::-webkit-scrollbar-thumb { .archive-list::-webkit-scrollbar-thumb {
background-color: var(--neutral-700); background-color: var(--neutral-700);
border-radius: 6px; border-radius: 6px;
} }
.archive-list li { .archive-list li {
margin: 0.75rem 0; margin: 0.75rem 0;
transition: transform 0.2s ease; transition: transform 0.2s ease;
} }
.archive-list li:hover { .archive-list li:hover {
transform: translateY(-2px); transform: translateY(-2px);
} }
.archive-list li a { .archive-list li a {
display: grid; display: grid;
grid-template-columns: 2fr 1fr 1fr; grid-template-columns: 2fr 1fr 1fr;
@@ -91,41 +106,50 @@ body, html {
border: 1px solid var(--neutral-700); border: 1px solid var(--neutral-700);
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
} }
.archive-list li a:hover { .archive-list li a:hover {
background-color: var(--neutral-750); background-color: var(--neutral-750);
border-color: var(--neutral-600); border-color: var(--neutral-600);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
} }
.archive-list li a p { .archive-list li a p {
margin: 0; margin: 0;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.archive-list li a p:nth-child(2) { .archive-list li a p:nth-child(2) {
padding-left: 1rem; padding-left: 1rem;
text-align: center; text-align: center;
} }
.archive-list li a p:nth-child(3){
.archive-list li a p:nth-child(3) {
text-align: right; text-align: right;
} }
#archive-title { #archive-title {
font-weight: 500; font-weight: 500;
color: var(--neutral-100); color: var(--neutral-100);
} }
#archive-date { #archive-date {
color: var(--neutral-300); color: var(--neutral-300);
font-size: 0.9rem; font-size: 0.9rem;
text-align: center; text-align: center;
} }
#archive-syntax { #archive-syntax {
color: var(--neutral-300); color: var(--neutral-300);
font-size: 0.9rem; font-size: 0.9rem;
text-align: right; text-align: right;
} }
.user-pastes-throbber { .user-pastes-throbber {
margin: 1.5rem auto; margin: 1.5rem auto;
} }
.pastes-actions { .pastes-actions {
display: flex; display: flex;
justify-content: center; justify-content: center;
@@ -138,11 +162,13 @@ body, html {
opacity: 0.5; opacity: 0.5;
cursor: not-allowed; cursor: not-allowed;
} }
.pastes-actions span { .pastes-actions span {
color: var(--neutral-300); color: var(--neutral-300);
font-size: 1.1rem; font-size: 1.1rem;
font-weight: 500; font-weight: 500;
} }
@media (max-width: 768px) { @media (max-width: 768px) {
.main-container { .main-container {
max-width: 98vw; max-width: 98vw;
@@ -150,29 +176,40 @@ body, html {
padding: 0.5rem; padding: 0.5rem;
border-radius: 0; border-radius: 0;
} }
.archive-list li a p:last-child {
display: none;
}
.archive-information, .archive-information,
.archive-list li a { .archive-list li a {
grid-template-columns: 3fr 2fr; grid-template-columns: 3fr 2fr;
} }
#archive-syntax { #archive-syntax {
display: none; display: none;
} }
.archive-information p:last-child { .archive-information p:last-child {
display: none; display: none;
} }
} }
@media (max-width: 480px) { @media (max-width: 480px) {
.main-container { .main-container {
padding: 1rem; padding: 1rem;
margin: 1rem; margin: 1rem;
} }
.user-header h1 { .user-header h1 {
font-size: 1.5rem; font-size: 1.5rem;
} }
.archive-list { .archive-list {
max-height: 60vh; max-height: 60vh;
} }
} }
#next-button-svg { #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>'); 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; color: white;
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

+1 -1
View File
@@ -20,7 +20,7 @@
<form class="create-form" id="create-form"> <form class="create-form" id="create-form">
<input type="text" name="title" id="title" placeholder="Title" maxlength="500"> <input type="text" name="title" id="title" placeholder="Title" maxlength="500">
<textarea name="content" id="content" placeholder="Content"></textarea> <textarea name="content" id="content" placeholder="Content"></textarea>
<label id="syntax-label" style="">Syntax Highlighting -</label> <label id="syntax-label">Syntax Highlighting -</label>
<select name="syntax" id="syntax"> <select name="syntax" id="syntax">
<option value="none">None</option> <option value="none">None</option>
<option value="AutoHotkey">AutoHotkey</option> <option value="AutoHotkey">AutoHotkey</option>
+23 -1
View File
@@ -1,6 +1,9 @@
const siteInfo = [];
document.addEventListener("DOMContentLoaded", async function () { document.addEventListener("DOMContentLoaded", async function () {
var visibility = document.getElementById("visibility"); var visibility = document.getElementById("visibility");
visibility.value = "0"; visibility.value = "0";
getSiteInfo();
}); });
@@ -13,11 +16,20 @@ document.getElementById("create-form").addEventListener("submit", async function
var password = document.getElementById("password").value; var password = document.getElementById("password").value;
var syntax = document.getElementById("syntax").value; var syntax = document.getElementById("syntax").value;
if (content.length > siteInfo.maxFileSize) {
showNotification("Content exceeds maximum size.", "error");
return;
}
if (content.length === 0) {
showNotification("Content cannot be empty.", "error");
return;
}
if (visibility === "2" && password !== "" && password.length >= 6) { if (visibility === "2" && password !== "" && password.length >= 6) {
content = await encryptAES(content, password); content = await encryptAES(content, password);
} }
else if (visibility === "2") { else if (visibility === "2") {
alert("Password must be at least 6 characters long"); showNotification("Password must be at least 6 characters long.", "error");
return; return;
} }
@@ -42,6 +54,16 @@ function changeVisibility() {
} }
} }
function getSiteInfo() {
fetch("/api/site/info")
.then(response => response.json())
.then(data => {
siteInfo = data.info;
var content = document.getElementById("content")
content.setAttribute("maxlength", siteInfo.maxFileSize);
});
}
async function encryptAES(content, password) { async function encryptAES(content, password) {
const enc = new TextEncoder(); const enc = new TextEncoder();
const keyMaterial = await window.crypto.subtle.importKey( const keyMaterial = await window.crypto.subtle.importKey(
+2 -1
View File
@@ -66,6 +66,7 @@ const navbarHTML = `
} }
.nav-link { .nav-link {
background-color: #171717;
color: rgba(255, 255, 255, 0.85); color: rgba(255, 255, 255, 0.85);
text-decoration: none; text-decoration: none;
font-size: 1.1rem; font-size: 1.1rem;
@@ -217,7 +218,7 @@ function showNotification(message, type = 'info', duration = 3000) {
position: fixed; position: fixed;
bottom: 32px; bottom: 32px;
right: 32px; right: 32px;
z-index: 2000; z-index: 1000;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: flex-end; align-items: flex-end;
+98 -2
View File
@@ -14,14 +14,99 @@ document.addEventListener("DOMContentLoaded", async function () {
const [content, info] = await Promise.all([contentPromise, infoPromise]); const [content, info] = await Promise.all([contentPromise, infoPromise]);
const paste = info.paste; const paste = info.paste;
function showPasswordModal(errorMsg = "") {
return new Promise((resolve, reject) => {
const oldModal = document.getElementById("password-modal-bg");
if (oldModal) oldModal.remove();
const modalBg = document.createElement("div");
modalBg.id = "password-modal-bg";
const modal = document.createElement("div");
modal.id = "password-modal";
const title = document.createElement("div");
title.innerText = "Private Paste";
title.className = "modal-title";
const label = document.createElement("label");
label.innerText = "Enter the password to view this paste:";
label.htmlFor = "password-input";
const input = document.createElement("input");
input.type = "password";
input.id = "password-input";
input.autocomplete = "current-password";
if (errorMsg) {
showNotification(errorMsg, "error", 3000);
}
const btnRow = document.createElement("div");
btnRow.className = "modal-btn-row";
const okBtn = document.createElement("button");
okBtn.innerText = "Unlock";
const cancelBtn = document.createElement("button");
cancelBtn.innerText = "Cancel";
btnRow.appendChild(cancelBtn);
btnRow.appendChild(okBtn);
modal.appendChild(title);
modal.appendChild(label);
modal.appendChild(input);
modal.appendChild(btnRow);
modalBg.appendChild(modal);
document.body.appendChild(modalBg);
input.focus();
function cleanup() {
if (modalBg.parentNode) modalBg.parentNode.removeChild(modalBg);
}
okBtn.onclick = () => {
resolve(input.value);
};
cancelBtn.onclick = () => {
cleanup();
reject(new Error("User cancelled"));
};
input.addEventListener("keydown", e => {
if (e.key === "Enter") {
okBtn.click();
} else if (e.key === "Escape") {
cancelBtn.click();
}
});
modalBg.addEventListener("click", e => {
if (e.target === modalBg) {
cancelBtn.click();
}
});
});
}
if (paste.visibility === 2) { if (paste.visibility === 2) {
const password = prompt("Enter the password"); let success = false;
let lastError = "";
while (!success) {
try { try {
const password = await showPasswordModal(lastError);
const decrypted = await decryptAES(content, password); const decrypted = await decryptAES(content, password);
blur2.dataset.decrypted = "true"; blur2.dataset.decrypted = "true";
addContent(decrypted, paste.syntax); addContent(decrypted, paste.syntax);
document.getElementById("password-modal-bg")?.remove();
success = true;
} catch (error) { } catch (error) {
alert("Failed to decrypt, invalid password, or invalid data."); if (error.message === "User cancelled") {
document.getElementById("password-modal-bg")?.remove();
break;
}
lastError = "Failed to decrypt, invalid password, or invalid data.";
}
} }
} else { } else {
blur2.dataset.decrypted = "true"; blur2.dataset.decrypted = "true";
@@ -36,6 +121,16 @@ function addInfo(paste) {
document.getElementById("paste-date").innerText = `${convertUnixToLocal(paste.created)}`; document.getElementById("paste-date").innerText = `${convertUnixToLocal(paste.created)}`;
document.getElementById("paste-syntax").innerText = paste.syntax; document.getElementById("paste-syntax").innerText = paste.syntax;
document.getElementById("paste-size").innerText = paste.size === 0 ? "" : formatSize(paste.size); document.getElementById("paste-size").innerText = paste.size === 0 ? "" : formatSize(paste.size);
if (paste.size !== paste.trueSize && paste.trueSize) {
const sizeElem = document.getElementById("paste-size");
sizeElem.classList.add("has-true-size-tooltip");
let tooltip = document.createElement("div");
tooltip.className = "true-size-tooltip";
tooltip.innerText = `True size: ${formatSize(paste.trueSize)}`;
sizeElem.appendChild(tooltip);
sizeElem.onmouseenter = () => { tooltip.style.opacity = 1; };
sizeElem.onmouseleave = () => { tooltip.style.opacity = 0; };
}
document.getElementById("paste-author").innerText = paste.username; document.getElementById("paste-author").innerText = paste.username;
document.getElementById("author-link").href = paste.username === "Anonymous" ? "" : `/u/${paste.username}`; document.getElementById("author-link").href = paste.username === "Anonymous" ? "" : `/u/${paste.username}`;
if (paste.username === "Anonymous") { if (paste.username === "Anonymous") {
@@ -81,6 +176,7 @@ function addContent(content, syntax) {
code.classList.add("language-" + syntax === "plaintext" ? "none" : syntax); code.classList.add("language-" + syntax === "plaintext" ? "none" : syntax);
if (syntax !== "plaintext" && syntax !== "none" && syntax !== "" && syntax !== null) { if (syntax !== "plaintext" && syntax !== "none" && syntax !== "" && syntax !== null) {
hljs.highlightElement(code); hljs.highlightElement(code);
document.getElementById("paste-content").style.padding = "0px"
} }
hljs.lineNumbersBlock(code); hljs.lineNumbersBlock(code);
document.getElementById("content-throbber").style.display = "none"; document.getElementById("content-throbber").style.display = "none";
+2 -2
View File
@@ -55,13 +55,13 @@ document.addEventListener("DOMContentLoaded", async function () {
await loadUserPastes(userData, 0); await loadUserPastes(userData, 0);
currentPage = 0; currentPage = 0;
document.getElementById("user-prev-page").onclick = async function () { document.getElementById("previous-button").onclick = async function () {
if (currentPage > 0) { if (currentPage > 0) {
currentPage--; currentPage--;
await loadUserPastes(userData, currentPage); await loadUserPastes(userData, currentPage);
} }
}; };
document.getElementById("user-next-page").onclick = async function () { document.getElementById("next-button").onclick = async function () {
if (!lastPage) { if (!lastPage) {
currentPage++; currentPage++;
await loadUserPastes(userData, currentPage); await loadUserPastes(userData, currentPage);