mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92f1ef1dbf | ||
|
|
553b1a12db | ||
|
|
bdcc3a1dc6 | ||
|
|
c28b9b92b1 | ||
|
|
0d5fd3bc5d | ||
|
|
ab04010c30 | ||
|
|
49f8911be2 | ||
|
|
eb21e6d662 | ||
|
|
233b338f9b | ||
|
|
c6d1100ff0 | ||
|
|
44228ad099 | ||
|
|
914f7b7a73 | ||
|
|
65ddb4b722 | ||
|
|
6ca6833b42 | ||
|
|
f816836b0f | ||
|
|
b2090e9b4b | ||
|
|
b2f5f34a06 | ||
|
|
2889921f12 | ||
|
|
878cebacb6 | ||
|
|
102bb57699 | ||
|
|
560ad071ab | ||
|
|
4791b32400 | ||
|
|
229e4a323e | ||
|
|
071434efc9 | ||
|
|
ab8a8d43df | ||
|
|
8a06024d0b | ||
|
|
f02e68b1d3 | ||
|
|
0e2aa78b5c | ||
|
|
1c73e8caa4 | ||
|
|
05cb8f0afc | ||
|
|
bca02028d7 | ||
|
|
c3ac47171f | ||
|
|
317ae52826 | ||
|
|
3951fd3260 | ||
|
|
79276573bc | ||
|
|
017abcfacc | ||
|
|
59fe4caa4d | ||
|
|
47aed18919 | ||
|
|
7221d99b68 | ||
|
|
cc7004d294 | ||
|
|
3be5f90220 | ||
|
|
2df77f3659 | ||
|
|
d76331b01e |
@@ -1,30 +0,0 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
@@ -0,0 +1,63 @@
|
||||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
||||
+65
-14
@@ -33,6 +33,10 @@ bld/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
p/
|
||||
privp/
|
||||
raw/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
@@ -66,7 +70,29 @@ artifacts/
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop6
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.vspscc
|
||||
@@ -178,7 +204,22 @@ PublishScripts/
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessar6
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
@@ -279,7 +320,18 @@ paket-files/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment i6
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
@@ -313,14 +365,13 @@ MigrationBackup/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# Database
|
||||
**/*.db
|
||||
**/*.wal
|
||||
**/*.db-wal
|
||||
**/*.db-shm
|
||||
**/*.sqlite
|
||||
|
||||
Data
|
||||
!SharpbinV3.Server/Data
|
||||
.idea
|
||||
/PasteBin/p
|
||||
/PasteBin/privp
|
||||
PasteBin/raw/2d48a001-383d-44fd-8553-4806c9de100d.txt
|
||||
PasteBin/p/2d48a001-383d-44fd-8553-4806c9de100d.html
|
||||
/PasteBin/pastes
|
||||
/PasteBin/pastes.sqlite
|
||||
*.sqlite-journal
|
||||
/PasteBin/logs.txt
|
||||
/PasteBin/config.json
|
||||
/PasteBin/.config
|
||||
|
||||
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.css": "tailwindcss"
|
||||
},
|
||||
"tailwindCSS.experimental.configFile": "SharpbinV3.Client/src/routes/layout.css"
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.2.0
|
||||
VisualStudioVersion = 17.10.35004.147
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpbinV3.Server", "SharpbinV3.Server.csproj", "{79A5E17C-498C-F55E-C79E-1F32E48383EF}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sharpbin", "PasteBin\Sharpbin.csproj", "{9C528C66-1818-4BF7-8AC2-EA22DDFE7FFC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -10,15 +11,15 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{79A5E17C-498C-F55E-C79E-1F32E48383EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{79A5E17C-498C-F55E-C79E-1F32E48383EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{79A5E17C-498C-F55E-C79E-1F32E48383EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{79A5E17C-498C-F55E-C79E-1F32E48383EF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9C528C66-1818-4BF7-8AC2-EA22DDFE7FFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9C528C66-1818-4BF7-8AC2-EA22DDFE7FFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9C528C66-1818-4BF7-8AC2-EA22DDFE7FFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9C528C66-1818-4BF7-8AC2-EA22DDFE7FFC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {98CE5484-B4BF-4C6B-9EEC-07F6E621F094}
|
||||
SolutionGuid = {F1C47634-0632-428A-B7BB-4AD87C3184AB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sharpbin
|
||||
{
|
||||
public class Compression
|
||||
{
|
||||
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 bool IsCompressed(byte[] data)
|
||||
{
|
||||
return data.Length >= 2 && data[0] == 0x1F && data[1] == 0x8B;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Sharpbin
|
||||
{
|
||||
public class Encryption
|
||||
{
|
||||
public static string EncryptString(string input, string password)
|
||||
{
|
||||
byte[] encryptedBytes;
|
||||
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.KeySize = 256;
|
||||
aes.Key = Encoding.UTF8.GetBytes(password.PadRight(32, ' '));
|
||||
aes.IV = new byte[16];
|
||||
|
||||
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
|
||||
{
|
||||
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
|
||||
cs.Write(inputBytes, 0, inputBytes.Length);
|
||||
}
|
||||
|
||||
encryptedBytes = ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
return Convert.ToBase64String(encryptedBytes);
|
||||
}
|
||||
public static string EncryptByteArray(byte[] bytes, string password)
|
||||
{
|
||||
byte[] encryptedBytes;
|
||||
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.KeySize = 256;
|
||||
aes.Key = Encoding.UTF8.GetBytes(password.PadRight(32, ' '));
|
||||
aes.IV = new byte[16];
|
||||
|
||||
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
|
||||
{
|
||||
cs.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
encryptedBytes = ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
return Convert.ToBase64String(encryptedBytes);
|
||||
}
|
||||
|
||||
public static string DecryptString(string input, string password)
|
||||
{
|
||||
byte[] encryptedBytes = Convert.FromBase64String(input);
|
||||
string decryptedText;
|
||||
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.KeySize = 256;
|
||||
aes.Key = Encoding.UTF8.GetBytes(password.PadRight(32, ' '));
|
||||
aes.IV = new byte[16];
|
||||
|
||||
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
|
||||
|
||||
using (var ms = new MemoryStream(encryptedBytes))
|
||||
{
|
||||
using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
|
||||
{
|
||||
using (var sr = new StreamReader(cs))
|
||||
{
|
||||
decryptedText = sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return decryptedText;
|
||||
}
|
||||
public static byte[] DecryptByteArray(byte[] input, string password)
|
||||
{
|
||||
byte[] decryptedBytes;
|
||||
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.KeySize = 256;
|
||||
aes.Key = Encoding.UTF8.GetBytes(password.PadRight(32, ' '));
|
||||
aes.IV = new byte[16];
|
||||
|
||||
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
|
||||
|
||||
using (var ms = new MemoryStream(input))
|
||||
{
|
||||
using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
|
||||
{
|
||||
decryptedBytes = new byte[ms.Length];
|
||||
cs.Read(decryptedBytes, 0, decryptedBytes.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return decryptedBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Org.BouncyCastle.Asn1.Cms;
|
||||
|
||||
namespace Sharpbin
|
||||
{
|
||||
public class Logging
|
||||
{
|
||||
public static async Task<Log> LogRequestAsync(HttpContext context)
|
||||
{
|
||||
Log log = new Log();
|
||||
log.Now = DateTime.Now;
|
||||
log.Method = context.Request.Method;
|
||||
log.Path = context.Request.Path;
|
||||
log.UserAgent = context.Request.Headers["User-Agent"];
|
||||
log.Referer = context.Request.Headers["Referer"];
|
||||
log.IP = context.Request.Headers["X-Forwarded-For"].ToString() ?? context.Connection.RemoteIpAddress.ToString();
|
||||
return log;
|
||||
}
|
||||
public static async Task LogError(string message)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine($"[ERROR - {DateTime.Now}] {message}");
|
||||
await File.AppendAllTextAsync("logs.log", $"[ERROR - {DateTime.Now}] {message}\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
public static async Task LogInfo(string message)
|
||||
{
|
||||
Console.WriteLine($"[INFO - {DateTime.Now}] {message}");
|
||||
await File.AppendAllTextAsync("logs.log", $"[INFO - {DateTime.Now}] {message}\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
public static async Task LogWarning(string message)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.ForegroundColor = ConsoleColor.Black;
|
||||
Console.WriteLine($"[WARNING - {DateTime.Now}] {message}");
|
||||
await File.AppendAllTextAsync("logs.log", $"[WARNING - {DateTime.Now}] {message}\n");
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
}
|
||||
public class Log
|
||||
{
|
||||
public DateTime Now { get; set; }
|
||||
public string Method { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string UserAgent { get; set; }
|
||||
public string Referer { get; set; }
|
||||
public string Body { get; set; }
|
||||
public string IP { get; set; }
|
||||
}
|
||||
}
|
||||
+2774
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:29219",
|
||||
"sslPort": 44358
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://*:5240"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "https://*:7220;http://*:5240"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="pastes\**" />
|
||||
<Content Remove="pastes\**" />
|
||||
<EmbeddedResource Remove="pastes\**" />
|
||||
<None Remove="pastes\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="assets\admin.html" />
|
||||
<None Remove="assets\admin\user.html" />
|
||||
<None Remove="assets\archives.html" />
|
||||
<None Remove="assets\banned.html" />
|
||||
<None Remove="assets\dash.html" />
|
||||
<None Remove="assets\error.html" />
|
||||
<None Remove="assets\login.html" />
|
||||
<None Remove="assets\paste.html" />
|
||||
<None Remove="assets\privatepaste.html" />
|
||||
<None Remove="assets\recent_pastes.html" />
|
||||
<None Remove="assets\signup.html" />
|
||||
<None Remove="assets\user.html" />
|
||||
<None Remove="pastes.sqlite" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="assets\admin.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\admin\user.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\archives.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\banned.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\index.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\privatepaste.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="pastes.sqlite">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.8" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="assets\dash.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\error.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\login.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\paste.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\recent_pastes.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\signup.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="assets\user.html">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="config.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,35 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
|
||||
namespace Sharpbin
|
||||
{
|
||||
public class Turnstile
|
||||
{
|
||||
public static async Task<bool> VerifyTurnstileToken(string token)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
JObject requestBody = new JObject
|
||||
{
|
||||
["secret"] = Program.cfTurnstileSecret,
|
||||
["response"] = token
|
||||
};
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri("https://challenges.cloudflare.com/turnstile/v0/siteverify"),
|
||||
Content = new StringContent(requestBody.ToString(), Encoding.UTF8, "application/json")
|
||||
};
|
||||
using (var response = await httpClient.SendAsync(request))
|
||||
{
|
||||
var jsonresponse = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||
if (jsonresponse["success"]?.ToString().ToLower() == "true")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"DetailedErrors": true,
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"Kestrel": {
|
||||
"EndPoints": {
|
||||
"Http": {
|
||||
"Url": "http://*:5240"
|
||||
}
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>dashboard</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
|
||||
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="dash-container">
|
||||
<div class="wrapper">
|
||||
<div class="idek-wrapper">
|
||||
<div class="account-info">
|
||||
<span id="username">Username: {username}</span>
|
||||
<span id="uuid">UUID: {uuid}</span>
|
||||
<span id="uid">UID: {uid}</span>
|
||||
<span id="creationdate">{creationdate}</span>
|
||||
<span id="lastlogindate">{lastlogindate}</span>
|
||||
<span id="type">Account Type: {type}</span>
|
||||
<span id="pastescount">Total Pastes: {totalpastes}</span>
|
||||
<span id="pasteSize">Total Pastes Size: {totalsize}</span>
|
||||
</div>
|
||||
<div class="pastes-wrapper">
|
||||
<h3>Your Pastes</h3>
|
||||
<div class="list-container">
|
||||
{pastes}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="idek-wrapper accounts">
|
||||
<div class="accounts-wrapper">
|
||||
<h3>Accounts</h3>
|
||||
<input type="text" placeholder="search" class="text-input" oninput="waitSearch()">
|
||||
<div class="list-container" onscroll="getUsers()">
|
||||
{accounts}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="notifcations-wrapper" id="notifications"></div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
let searchTimeout;
|
||||
function localizeDateTime(unixTimestamp) {
|
||||
const date = new Date(unixTimestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const creationdateElement = document.getElementById('creationdate');
|
||||
const lastlogindateElement = document.getElementById('lastlogindate');
|
||||
|
||||
const creationdateText = creationdateElement.innerText.trim();
|
||||
const lastlogindateText = lastlogindateElement.innerText.trim();
|
||||
|
||||
creationdateElement.innerText = "Creation Date: " + localizeDateTime(parseInt(creationdateText));
|
||||
lastlogindateElement.innerText = "Last Login Date: " + localizeDateTime(parseInt(lastlogindateText));
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
function createNotification(message) {
|
||||
const notificationWrapper = document.getElementById('notifications');
|
||||
const notificationDiv = document.createElement('div');
|
||||
notificationDiv.classList.add('notification-div');
|
||||
notificationDiv.id = 'notification';
|
||||
|
||||
const notificationText = document.createElement('h2');
|
||||
notificationText.id = 'notification-text';
|
||||
notificationText.innerText = message;
|
||||
|
||||
notificationDiv.appendChild(notificationText);
|
||||
notificationWrapper.appendChild(notificationDiv);
|
||||
|
||||
notificationDiv.style.animation = 'none';
|
||||
notificationDiv.style.display = 'none';
|
||||
notificationDiv.style.display = 'flex';
|
||||
notificationDiv.style.animation = 'hoverup 1s';
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.style.animation = 'hoverdown 1s';
|
||||
}, 4000);
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.remove();
|
||||
}, 4900);
|
||||
}
|
||||
function waitSearch() {
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(search, 200);
|
||||
}
|
||||
function search() {
|
||||
const input = document.querySelector('.text-input').value;
|
||||
const accountWrapper = document.querySelector('.accounts-wrapper');
|
||||
const accounts = accountWrapper.querySelectorAll('.list-a');
|
||||
if (input.length == 0){
|
||||
fetch(`/api/accounts/admin/get?html=true`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
offset: 0,
|
||||
})
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
const listContainer = accountWrapper.querySelector('.list-container');
|
||||
listContainer.innerHTML = data;
|
||||
})
|
||||
return;
|
||||
}
|
||||
fetch(`/api/accounts/admin/search?html=true`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
search: input
|
||||
})
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
const listContainer = accountWrapper.querySelector('.list-container');
|
||||
listContainer.innerHTML = data;
|
||||
})
|
||||
}
|
||||
function getUsers() {
|
||||
const accountWrapper = document.querySelector('.accounts-wrapper');
|
||||
const listContainer = accountWrapper.querySelector('.list-container');
|
||||
const accounts = accountWrapper.querySelectorAll('.list-a');
|
||||
const lastAccount = accounts[accounts.length - 1];
|
||||
const lastAccountUsername = lastAccount.querySelector('.list-item').innerText;
|
||||
const lastAccountUUID = lastAccount.querySelector('.list-item').getAttribute('data-uuid');
|
||||
var isScrolledDown = listContainer.scrollTop + listContainer.clientHeight >= listContainer.scrollHeight - 100;
|
||||
if (!isScrolledDown) {
|
||||
return;
|
||||
}
|
||||
fetch(`/api/accounts/admin/get?html=true`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
offset: accounts.length,
|
||||
})
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
if (data === '') {
|
||||
return;
|
||||
}
|
||||
if (listContainer.innerHTML.includes(data)) {
|
||||
return;
|
||||
}
|
||||
listContainer.innerHTML += data;
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
function isScrolledDown(element){
|
||||
var scrollPosition = element.scrollTop + element.clientHeight;
|
||||
var scrollHeight = element.scrollHeight;
|
||||
return scrollPosition >= scrollHeight;
|
||||
}
|
||||
|
||||
</script>
|
||||
<style>
|
||||
.list-container {
|
||||
max-height: 100%;
|
||||
overflow-y: scroll;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
.dash-container {
|
||||
display: flex;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
width: 80%;
|
||||
max-height: 100%;
|
||||
min-height: 20%;
|
||||
height: fit-content;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.idek-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.account-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #222222;
|
||||
width: 48%;
|
||||
padding: 20px;
|
||||
margin-right: 5px;
|
||||
border-radius: 5px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.pastes-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 48%;
|
||||
margin-left: 5px;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
background-color: #222222;
|
||||
max-height: 30vh;
|
||||
}
|
||||
|
||||
.accounts-wrapper {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
background-color: #222222;
|
||||
max-height: 40vh;
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.list-a {
|
||||
transition: 300ms;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: 90%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #2a2a2a;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
border: #3a3a3a00 2px solid;
|
||||
}
|
||||
|
||||
.list-a:hover {
|
||||
transition: background-color 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
list-style: none;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.text-input {
|
||||
transition: border 300ms;
|
||||
width: 90.2%;
|
||||
height: 1.2rem;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
border: #2a2a2a 2px solid;
|
||||
background-color: #2a2a2a;
|
||||
color: white;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
}
|
||||
|
||||
.text-input:focus {
|
||||
transition: border 300ms;
|
||||
outline: none;
|
||||
border: #333333 2px solid;
|
||||
}
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
.dash-container{
|
||||
height: 80%;
|
||||
margin-top: 6rem;
|
||||
}
|
||||
.container-wrapper {
|
||||
height: 90%;
|
||||
}.wrapper {
|
||||
height: 70%;
|
||||
max-height: 70%;
|
||||
}
|
||||
.idek-wrapper {
|
||||
flex-direction: column;
|
||||
}
|
||||
.accounts{
|
||||
max-height: 20%;
|
||||
}
|
||||
.account-info {
|
||||
width: 90%;
|
||||
margin: 0;
|
||||
}
|
||||
.pastes-wrapper {
|
||||
width: 90%;
|
||||
margin: 0;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.accounts-wrapper {
|
||||
width: 90%;
|
||||
margin: 0;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.list-container {
|
||||
max-height: 100%;
|
||||
overflow-y: scroll;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,687 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>{username}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="account-container">
|
||||
<div class="account-info">
|
||||
<h2>{username}</h2>
|
||||
<h3>UUID: {uuid}</h3>
|
||||
<h3>UID: {uid}</h3>
|
||||
<h3 id="creationdate">{creationdate}</h3>
|
||||
<h3 id="lastlogindate">{lastlogindate}</h3>
|
||||
<h3>Account Type: {type}</h3>
|
||||
<h3>Total Pastes: {totalpastes}</h3>
|
||||
<h3>Total Pastes Size: {totalsize}</h3>
|
||||
</div>
|
||||
<div class="collumn-2">
|
||||
<div class="action-wrapper">
|
||||
<h2 style="text-align: center;">Actions</h2>
|
||||
<div class="button-wrapper">
|
||||
<a onclick="banorunban()" class="button">{typeban}</a>
|
||||
<a onclick="changePassword()" class="button">change password</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pastes-wrapper">
|
||||
<h2 style="text-align: center;">Pastes</h2>
|
||||
<div class="pastes-container">
|
||||
{pastes}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="notifcations-wrapper" id="notifications">
|
||||
|
||||
</div>
|
||||
<div class="input-div" id="ban-div" style="display: none;">
|
||||
<button onclick="banorunban()" class="exit-button">X</button>
|
||||
<input type="date" id="ban-date" placeholder="{typeban} date">
|
||||
<input type="text" id="ban-reason" placeholder="{typeban} reason">
|
||||
<button id="ban-button" onclick="banAccount()">{typeban}</button>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
function localizeDateTime(unixTimestamp) {
|
||||
const date = new Date(unixTimestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const creationdateElement = document.getElementById('creationdate');
|
||||
const lastlogindateElement = document.getElementById('lastlogindate');
|
||||
|
||||
const creationdateText = creationdateElement.innerText.trim();
|
||||
const lastlogindateText = lastlogindateElement.innerText.trim();
|
||||
|
||||
creationdateElement.innerText = "Creation Date: " + localizeDateTime(parseInt(creationdateText));
|
||||
lastlogindateElement.innerText = "Last Login Date: " + localizeDateTime(parseInt(lastlogindateText));
|
||||
if ('{typeban}' == 'unban') {
|
||||
document.getElementById('ban-date').style.display = 'none';
|
||||
}
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
function banorunban() {
|
||||
const banDiv = document.getElementById('ban-div');
|
||||
console.log(banDiv.style.display);
|
||||
if (banDiv.style.display == 'none') {
|
||||
banDiv.style.animation = 'hoverup 1s';
|
||||
banDiv.style.display = 'flex';
|
||||
} else {
|
||||
banDiv.style.animation = 'hoverdown 1s';
|
||||
|
||||
setTimeout(() => {
|
||||
banDiv.style.transition = '200ms';
|
||||
banDiv.style.opacity = 0;
|
||||
|
||||
|
||||
}, 600);
|
||||
setTimeout(() => {
|
||||
banDiv.style.display = 'none';
|
||||
banDiv.style.opacity = 1;
|
||||
}, 1000);
|
||||
|
||||
}
|
||||
console.log(banDiv.style.display);
|
||||
}
|
||||
function banAccount() {
|
||||
let date = document.getElementById('ban-date').value;
|
||||
date = new Date(date).getTime() / 1000;
|
||||
let reason = document.getElementById('ban-reason').value;
|
||||
if (date == null || reason == null) {
|
||||
createNotification('Please fill out all fields');
|
||||
return;
|
||||
}
|
||||
if (date < new Date().getTime() / 1000) {
|
||||
createNotification('Please select a date in the future');
|
||||
return;
|
||||
}
|
||||
if ('{typeban}' == 'unban') {
|
||||
fetch('/api/accounts/admin/{typeban}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
uuid: '{uuid}',
|
||||
reason: `${reason}`
|
||||
})
|
||||
|
||||
}).then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.message != null) {
|
||||
createNotification(`${result.message} for ${reason}`);
|
||||
} else {
|
||||
createNotification(`Failed to {typeban} ${result.error}`);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
fetch('/api/accounts/admin/{typeban}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
uuid: '{uuid}',
|
||||
expiration: `${date}`,
|
||||
reason: `${reason}`
|
||||
})
|
||||
|
||||
}).then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.message != null) {
|
||||
createNotification(`${result.message} for ${reason}`);
|
||||
} else {
|
||||
createNotification(`Failed to {typeban} ${result.error}`);
|
||||
}
|
||||
})
|
||||
}
|
||||
console.log(date);
|
||||
banorunban();
|
||||
}
|
||||
function changePassword() {
|
||||
let password = prompt('Enter the new password');
|
||||
fetch('/api/accounts/admin/change-password', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
uuid: '{uuid}',
|
||||
password: `${password}`
|
||||
})
|
||||
|
||||
}).then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.message != null) {
|
||||
createNotification(`${result.message} to ${result.password}`);
|
||||
navigator.clipboard.writeText(result.password);
|
||||
} else {
|
||||
notification(`Failed to change password for ${result.error}`);
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
function createNotification(message) {
|
||||
const notificationWrapper = document.getElementById('notifications');
|
||||
const notificationDiv = document.createElement('div');
|
||||
notificationDiv.classList.add('notification-div');
|
||||
notificationDiv.id = 'notification';
|
||||
|
||||
const notificationText = document.createElement('h2');
|
||||
notificationText.id = 'notification-text';
|
||||
notificationText.innerText = message;
|
||||
|
||||
notificationDiv.appendChild(notificationText);
|
||||
notificationWrapper.appendChild(notificationDiv);
|
||||
|
||||
notificationDiv.style.animation = 'none';
|
||||
notificationDiv.style.display = 'none';
|
||||
notificationDiv.style.display = 'flex';
|
||||
notificationDiv.style.animation = 'hoverup 1s';
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.style.animation = 'hoverdown 1s';
|
||||
}, 4000);
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.remove();
|
||||
}, 4900);
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
.notifcations-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.exit-button {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 10px;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: #222222 2px solid;
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
cursor: pointer;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
}
|
||||
|
||||
#ban-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.input-div {
|
||||
z-index: 2;
|
||||
position: fixed;
|
||||
background-color: #121212;
|
||||
border-radius: 10px;
|
||||
width: fit-content;
|
||||
max-width: 50%;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: fit-content;
|
||||
padding: 60px;
|
||||
max-height: 50%;
|
||||
border: #181818 3px solid;
|
||||
}
|
||||
|
||||
input {
|
||||
transition: 300ms;
|
||||
width: 80%;
|
||||
max-width: 80%;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
transition: 300ms;
|
||||
outline: none;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
#ban-button {
|
||||
transition: 300ms;
|
||||
width: 80%;
|
||||
max-width: 80%;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
#ban-button:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
@keyframes hoverup {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
|
||||
25% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
50% {
|
||||
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes hoverdown {
|
||||
0% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateY(200%);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.notification-div {
|
||||
display: flex;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
color: white;
|
||||
background-color: #181818;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
h3 {
|
||||
word-break: keep-all;
|
||||
margin-top: -5px;
|
||||
}
|
||||
|
||||
.list-a {
|
||||
transition: background-color 300ms;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: 90%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #2a2a2a;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
border: #3a3a3a00 2px solid;
|
||||
}
|
||||
|
||||
.list-a:hover {
|
||||
transition: background-color 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.collumn-2 {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 48%;
|
||||
max-width: 48%;
|
||||
}
|
||||
|
||||
.pastes-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
width: calc(100% - 40px);
|
||||
max-width: 100%;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
height: fit-content;
|
||||
margin-top: 10px;
|
||||
height: 77.1%;
|
||||
max-height: 77.1%;
|
||||
}
|
||||
|
||||
.pastes-container {
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
position: relative;
|
||||
height: calc(100vh - 20px);
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.account-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
margin-top: 6rem;
|
||||
max-height: 100%;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.account-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #222222;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
width: fit-content;
|
||||
width: 48%;
|
||||
max-width: 48%;
|
||||
margin-right: 10px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.action-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
width: calc(100% - 40px);
|
||||
max-width: 100%;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
height: fit-content;
|
||||
max-height: 20%;
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
.button {
|
||||
text-decoration: none;
|
||||
transition: 300ms;
|
||||
width: fit-content;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #2a2a2a;
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
color: white;
|
||||
border: #2a2a2a00 2px solid;
|
||||
cursor: pointer;
|
||||
font-size: 1.2em;
|
||||
text-align: center;
|
||||
min-width: 80px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
.container-wrapper{
|
||||
height: 90%;
|
||||
}
|
||||
.account-container {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
max-height: 100%;
|
||||
}
|
||||
.account-info {
|
||||
margin-right: 0px;
|
||||
width: 90%;
|
||||
max-width: 100%;
|
||||
font-size: smaller !important;
|
||||
}
|
||||
.collumn-2 {
|
||||
margin-top: 10px;
|
||||
width: 90%;
|
||||
max-width: 100%;
|
||||
max-height: 48%;
|
||||
}
|
||||
.action-wrapper {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
max-height: 40%;
|
||||
}
|
||||
.button {
|
||||
width: 90%;
|
||||
max-width: 100%;
|
||||
margin: 0;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.pastes-wrapper {
|
||||
margin-top: 10px;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
max-height: calc(500px * 1.5);
|
||||
}
|
||||
.pastes-container {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
max-height: 20%;
|
||||
overflow-x: hidden;
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,376 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>archive</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="pastes-container">
|
||||
<h1>paste archive</h1>
|
||||
<input type="text" placeholder="search" class="text-input" oninput="search()">
|
||||
<div class="pastes-wrapper">
|
||||
{pastes}
|
||||
</div>
|
||||
<div class="buttons-wrapper">
|
||||
<a class="arrow-button" href="/archive?page={backpagenum}"><</a>
|
||||
<p>{currentpagenum}/{totalpages}</p>
|
||||
<a class="arrow-button" href="/archive?page={pagenum}">></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
let searchTimeout;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
|
||||
function search() {
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(searchPastes, 200);
|
||||
}
|
||||
|
||||
function searchPastes() {
|
||||
const searchInput = document.querySelector('.text-input');
|
||||
if (searchInput.value.length < 3 && searchInput.value.length != 0) {
|
||||
return;
|
||||
}
|
||||
else if (searchInput.value.length == 0) {
|
||||
fetch(`/api/pastes/search?html=true`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: ''
|
||||
})
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
const pastesWrapper = document.querySelector('.pastes-wrapper');
|
||||
if (data === '') {
|
||||
pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
json = JSON.parse(data);
|
||||
if (json.error != null) {
|
||||
pastesWrapper.innerHTML = `<h1>${json.error}</h1>`;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch {
|
||||
}
|
||||
|
||||
pastesWrapper.innerHTML = data;
|
||||
});
|
||||
return;
|
||||
}
|
||||
fetch(`/api/pastes/search?html=true`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: searchInput.value
|
||||
})
|
||||
})
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
const pastesWrapper = document.querySelector('.pastes-wrapper');
|
||||
if (data === '') {
|
||||
pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
json = JSON.parse(data);
|
||||
if (json.error != null) {
|
||||
pastesWrapper.innerHTML = `<h1>${json.error}</h1>`;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch {
|
||||
}
|
||||
pastesWrapper.innerHTML = data;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.pastes-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
min-height: 20%;
|
||||
border: #222222 2px solid;
|
||||
transition: height 300ms;
|
||||
}
|
||||
|
||||
.pastes-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
max-height: 70vh;
|
||||
}
|
||||
|
||||
|
||||
|
||||
li {
|
||||
transition: 300ms;
|
||||
list-style: none;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border: #22222200 2px solid;
|
||||
}
|
||||
|
||||
li:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.buttons-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.buttons-wrapper a {
|
||||
transition: 300ms;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: fit-content;
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
min-width: 20%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
border: #22222200 2px solid;
|
||||
}
|
||||
|
||||
.buttons-wrapper a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
.pastes-wrapper a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.text-input {
|
||||
transition: border 300ms;
|
||||
width: calc(100% - 44px);
|
||||
height: 1.2rem;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
margin-left: 12px;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
}
|
||||
|
||||
.text-input:focus {
|
||||
transition: border 300ms;
|
||||
outline: none;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.arrow-button {
|
||||
min-width: fit-content !important;
|
||||
padding-left: 1rem !important;
|
||||
padding-right: 1rem !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,217 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>Error {code}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
|
||||
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="error-container">
|
||||
<h1>Error {code}</h1>
|
||||
<h2>{message}</h2>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
function localizeDateTime(unixTimestamp) {
|
||||
const date = new Date(unixTimestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const dateElement = document.getElementById('unix-date');
|
||||
const time = localizeDateTime(parseInt(dateElement.innerText.trim()));
|
||||
dateElement.innerText = time;
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
</script>
|
||||
<style>
|
||||
body{
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
.container-wrapper{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
.error-container{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
.button{
|
||||
text-decoration: none;
|
||||
transition: 300ms;
|
||||
width: fit-content;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: #2a2a2a00 2px solid;
|
||||
cursor: pointer;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
.button:hover{
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
</html>
|
||||
@@ -0,0 +1,349 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>dashboard</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
|
||||
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="dash-container">
|
||||
<div class="wrapper">
|
||||
<div class="idek-wrapper">
|
||||
<div class="account-info">
|
||||
<span id="username">Username: {username}</span>
|
||||
<span id="uuid">UUID: {uuid}</span>
|
||||
<span id="uid">UID: {uid}</span>
|
||||
<span id="creationdate">{creationdate}</span>
|
||||
<span id="lastlogindate">{lastlogindate}</span>
|
||||
<span id="type">Account Type: {type}</span>
|
||||
<span id="pastescount">Total Pastes: {totalpastes}</span>
|
||||
<span id="pasteSize">Total Pastes Size: {totalsize}</span>
|
||||
</div>
|
||||
<div class="pastes-wrapper">
|
||||
<h3>Your Pastes</h3>
|
||||
{pastes}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="notifcations-wrapper" id="notifications">
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
function localizeDateTime(unixTimestamp) {
|
||||
const date = new Date(unixTimestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const creationdateElement = document.getElementById('creationdate');
|
||||
const lastlogindateElement = document.getElementById('lastlogindate');
|
||||
|
||||
const creationdateText = creationdateElement.innerText.trim();
|
||||
const lastlogindateText = lastlogindateElement.innerText.trim();
|
||||
|
||||
creationdateElement.innerText = "Creation Date: " + localizeDateTime(parseInt(creationdateText));
|
||||
lastlogindateElement.innerText = "Last Login Date: " + localizeDateTime(parseInt(lastlogindateText));
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
function createNotification(message) {
|
||||
const notificationWrapper = document.getElementById('notifications');
|
||||
const notificationDiv = document.createElement('div');
|
||||
notificationDiv.classList.add('notification-div');
|
||||
notificationDiv.id = 'notification';
|
||||
|
||||
const notificationText = document.createElement('h2');
|
||||
notificationText.id = 'notification-text';
|
||||
notificationText.innerText = message;
|
||||
|
||||
notificationDiv.appendChild(notificationText);
|
||||
notificationWrapper.appendChild(notificationDiv);
|
||||
|
||||
notificationDiv.style.animation = 'none';
|
||||
notificationDiv.style.display = 'none';
|
||||
notificationDiv.style.display = 'flex';
|
||||
notificationDiv.style.animation = 'hoverup 1s';
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.style.animation = 'hoverdown 1s';
|
||||
}, 4000);
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.remove();
|
||||
}, 4900);
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
.dash-container {
|
||||
display: flex;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
width: 80%;
|
||||
max-height: 80vh;
|
||||
height: 50%;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.idek-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.account-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #222222;
|
||||
width: 48%;
|
||||
height: calc(100% - 40px);
|
||||
padding: 20px;
|
||||
margin-right: 5px;
|
||||
border-radius: 5px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.pastes-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 48%;
|
||||
height: calc(100% - 40px);
|
||||
margin-left: 5px;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
background-color: #222222;
|
||||
max-height: 70vh;
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.list-a {
|
||||
transition: background-color 300ms;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #2a2a2a;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
border: #3a3a3a00 2px solid;
|
||||
}
|
||||
|
||||
.list-a:hover {
|
||||
transition: background-color 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
.dash-container{
|
||||
height: 80%;
|
||||
margin-top: 6rem;
|
||||
}
|
||||
.container-wrapper {
|
||||
height: 90%;
|
||||
}.wrapper {
|
||||
height: 70%;
|
||||
max-height: 70%;
|
||||
}
|
||||
.idek-wrapper {
|
||||
flex-direction: column;
|
||||
}
|
||||
.accounts{
|
||||
max-height: 20%;
|
||||
}
|
||||
.account-info {
|
||||
width: 90%;
|
||||
margin: 0;
|
||||
}
|
||||
.pastes-wrapper {
|
||||
width: 90%;
|
||||
margin: 0;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.list-container {
|
||||
max-height: 100%;
|
||||
overflow-y: scroll;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,209 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>Error {code}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
|
||||
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="error-container">
|
||||
<h1>Error {code}</h1>
|
||||
<h2>{message}</h2>
|
||||
<a href="/" class="button">home page</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
</script>
|
||||
<style>
|
||||
body{
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
.container-wrapper{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
.error-container{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
.button{
|
||||
text-decoration: none;
|
||||
transition: 300ms;
|
||||
width: fit-content;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: #2a2a2a00 2px solid;
|
||||
cursor: pointer;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
.button:hover{
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
</html>
|
||||
@@ -0,0 +1,419 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>create paste</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="creation-container">
|
||||
<h1>create paste</h1>
|
||||
<form id="createForm">
|
||||
<label for="pasteTitle" class="label">Title</label>
|
||||
<input type="text" id="pasteTitle" class="textinput" name="pasteTitle" maxlength="500">
|
||||
<label for="pasteContent" class="label">Content</label>
|
||||
<textarea id="pasteContent" class="textarea" name="pasteContent" required maxlength="500000"></textarea>
|
||||
<select for="pasteVisibility" id="pasteVisibility" class="textinput" name="pasteVisibility" required>
|
||||
<option value="Public">Public</option>
|
||||
<option value="Unlisted">Unlisted</option>
|
||||
<option value="Private">Private</option>
|
||||
</select>
|
||||
<label for="pastePassword" class="label" id="pastePasswordLabel">Paste Password</label>
|
||||
<input type="password" id="pastePassword" class="textinput" name="pastePassword" maxlength="500">
|
||||
<button type="submit" class="button">Create</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="notification-div" id="notification">
|
||||
<h2 id="notification-text"></h2>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
document.getElementById("pasteVisibility").value = "Public";
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("createForm").addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var textAreaContent = document.getElementById("pasteContent").value;
|
||||
var textTitleContent = document.getElementById("pasteTitle").value;
|
||||
var textVisibilityContent = document.getElementById("pasteVisibility").value;
|
||||
|
||||
var requestUrl = "/api/pastes/create";
|
||||
var fetchBody = {
|
||||
title: textTitleContent,
|
||||
content: textAreaContent,
|
||||
visibility: textVisibilityContent
|
||||
};
|
||||
if (textVisibilityContent == "Private") {
|
||||
fetchBody.password = document.getElementById("pastePassword").value;
|
||||
}
|
||||
fetch(requestUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(fetchBody)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.pasteId != null) {
|
||||
window.location.href = `/${result.pasteId}`;
|
||||
} else if (result.error != null) {
|
||||
notification(result.error);
|
||||
}
|
||||
})
|
||||
});
|
||||
document.getElementById("pasteVisibility").addEventListener("change", function (event) {
|
||||
var visibility = document.getElementById("pasteVisibility").value;
|
||||
if (visibility == "Private") {
|
||||
document.getElementById("pastePassword").style.display = "block";
|
||||
document.getElementById("pastePasswordLabel").style.display = "block";
|
||||
} else {
|
||||
document.getElementById("pastePassword").style.display = "none";
|
||||
document.getElementById("pastePasswordLabel").style.display = "none";
|
||||
}
|
||||
});
|
||||
function notification(message) {
|
||||
const notification = document.getElementById('notification');
|
||||
const notificationText = document.getElementById('notification-text');
|
||||
notificationText.innerText = message;
|
||||
notification.style.animation = 'none';
|
||||
notification.style.display = 'none';
|
||||
notification.style.display = 'flex';
|
||||
notification.style.animation = 'hoverup 1s';
|
||||
setTimeout(() => {
|
||||
|
||||
notification.style.animation = 'hoverdown 1s';
|
||||
}, 4000);
|
||||
setTimeout(() => {
|
||||
notification.style.display = 'none';
|
||||
}, 4900);
|
||||
|
||||
}
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
</script>
|
||||
<style>
|
||||
@keyframes hoverup {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
|
||||
25% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
50% {
|
||||
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes hoverdown {
|
||||
0% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateY(200%);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pastePassword {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#pastePasswordLabel {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.notification-div {
|
||||
position: fixed;
|
||||
display: none;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
color: white;
|
||||
background-color: #181818;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
#pasteContent {
|
||||
max-height: 500px;
|
||||
}
|
||||
|
||||
.creation-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
min-height: 20%;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
#createForm {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.textinput {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #282828;
|
||||
color: white;
|
||||
border: #2a2a2a 2px solid;
|
||||
box-sizing: border-box;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-size: 1.1em;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textinput:focus {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
min-width: 100%;
|
||||
max-width: 100%;
|
||||
min-height: auto;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #282828;
|
||||
color: white;
|
||||
border: #2a2a2a 2px solid;
|
||||
box-sizing: border-box;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-size: 1.08em;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textarea:focus {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.button {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: #2a2a2a00 2px solid;
|
||||
cursor: pointer;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,349 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
||||
<title>login</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="creation-container">
|
||||
<h1>login</h1>
|
||||
<form id="loginForm">
|
||||
<label for="usernameTitle" class="label">Username</label>
|
||||
<input type="text" id="usernameInput" class="textinput" name="pasteTitle" required maxlength="20">
|
||||
<label for="passwordTitle" class="label">Password</label>
|
||||
<input type="password" id="passwordInput" class="textinput" name="pasteTitle" required maxlength="50">
|
||||
<div id="cf-turnstile" class="cf-turnstile" data-sitekey="{sitekey}"></div>
|
||||
<button type="submit" class="button">Login</button>
|
||||
</form>
|
||||
<h3 id="error-message"></h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="notifcations-wrapper" id="notifications">
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
let isLoggingIn = false;
|
||||
document.getElementById("loginForm").addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var usernameContent = document.getElementById("usernameInput").value;
|
||||
var passwordContent = document.getElementById("passwordInput").value;
|
||||
var cf = turnstile.getResponse();
|
||||
|
||||
|
||||
if (isLoggingIn) {
|
||||
createNotification("Please wait for the login to finish.");
|
||||
return;
|
||||
}
|
||||
isLoggingIn = true;
|
||||
var requestUrl = "/api/accounts/login";
|
||||
fetch(requestUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: usernameContent,
|
||||
password: passwordContent,
|
||||
cf: cf
|
||||
})
|
||||
})
|
||||
|
||||
.then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
isLoggingIn = true;
|
||||
if (result.message != null) {
|
||||
window.location.href = "/";
|
||||
isLoggingIn = false;
|
||||
}
|
||||
else if (result.error != null) {
|
||||
const errorElement = document.getElementById("error-message");
|
||||
errorElement.innerText = result.error;
|
||||
errorElement.style.opacity = 1;
|
||||
|
||||
setTimeout(() => {
|
||||
errorElement.style.opacity = 0;
|
||||
}, 3000);
|
||||
isLoggingIn = false;
|
||||
turnstile.reset();
|
||||
}
|
||||
})
|
||||
});
|
||||
function createNotification(message) {
|
||||
const notificationWrapper = document.getElementById('notifications');
|
||||
const notificationDiv = document.createElement('div');
|
||||
notificationDiv.classList.add('notification-div');
|
||||
notificationDiv.id = 'notification';
|
||||
|
||||
const notificationText = document.createElement('h2');
|
||||
notificationText.id = 'notification-text';
|
||||
notificationText.innerText = message;
|
||||
|
||||
notificationDiv.appendChild(notificationText);
|
||||
notificationWrapper.appendChild(notificationDiv);
|
||||
|
||||
notificationDiv.style.animation = 'none';
|
||||
notificationDiv.style.display = 'none';
|
||||
notificationDiv.style.display = 'flex';
|
||||
notificationDiv.style.animation = 'hoverup 1s';
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.style.animation = 'hoverdown 1s';
|
||||
}, 4000);
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.remove();
|
||||
}, 4900);
|
||||
}
|
||||
document.getElementById("cf-turnstile").addEventListener("expired-callback", function () {
|
||||
createNotification("Please complete the captcha.");
|
||||
turnstile.reset();
|
||||
});
|
||||
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
.creation-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
min-height: 20%;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#loginForm {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#error-message {
|
||||
color: red;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
bottom: -0.1px;
|
||||
margin-bottom: -0.1px;
|
||||
top: 88%;
|
||||
transition: 300ms;
|
||||
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.textinput {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #282828;
|
||||
color: white;
|
||||
border: #2a2a2a 2px solid;
|
||||
box-sizing: border-box;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-size: 1.1em;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textinput:focus {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
min-width: 100%;
|
||||
max-width: 100%;
|
||||
min-height: auto;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #282828;
|
||||
color: white;
|
||||
border: #2a2a2a 2px solid;
|
||||
box-sizing: border-box;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-size: 1.08em;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textarea:focus {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.button {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: #2a2a2a00 2px solid;
|
||||
cursor: pointer;
|
||||
font-size: 1.2em;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
@keyframes hoverup {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
|
||||
25% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
50% {
|
||||
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes hoverdown {
|
||||
0% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateY(200%);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.notification-div {
|
||||
display: flex;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
color: white;
|
||||
background-color: #181818;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.notifcations-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,587 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
|
||||
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
|
||||
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
|
||||
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
|
||||
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
|
||||
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="paste-container">
|
||||
<h1 id="paste-title"></h1>
|
||||
<h3 class="uploader-text"><a id="uploader-username" class="user-a"></a> <a id="creationdate"></a> <a id="paste-size"></a>
|
||||
</h3>
|
||||
<div class="paste-wrapper">
|
||||
<p id="text"></p>
|
||||
</div>
|
||||
<div class="buttons-wrapper">
|
||||
<a href="/raw/{pasteid}">
|
||||
<button id="view-raw-button" class="button">view raw</button>
|
||||
</a>
|
||||
<button id="copy-button" class="button">copy</button>
|
||||
<button id="download-button" class="button">download</button>
|
||||
<button id="delete-button" class="button" style="display: none;">delete</button>
|
||||
<button id="edit-button" class="button" style="display: none;">edit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="notifcations-wrapper" id="notifications"></div>
|
||||
<div class="input-wrapper" id="input-wrapper">
|
||||
<div class="input-wrapper-container">
|
||||
<h2 id="input-message"></h2>
|
||||
<div>
|
||||
<button id="yes-button" class="button">Yes</button>
|
||||
<button id="no-button" class="button">No</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
info = "";
|
||||
editing = false;
|
||||
function localizeDateTime(unixTimestamp) {
|
||||
const date = new Date(unixTimestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
function authenticated() {
|
||||
fetch('/api/accounts/authenticated')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.message == "Authenticated") {
|
||||
if (info.uploader == data.username || data.type == "Admin") {
|
||||
document.getElementById('delete-button').style.display = 'block';
|
||||
document.getElementById('edit-button').style.display = 'block';
|
||||
}
|
||||
document.querySelectorAll("#login-signup-btn").forEach(element => {
|
||||
element.style.display = 'none';
|
||||
});
|
||||
document.getElementById('dash-btn').style.display = 'block';
|
||||
}else{
|
||||
document.querySelectorAll("#login-signup-btn").forEach(element => {
|
||||
element.style.display = 'block';
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function fetchInfo() {
|
||||
fetch('/api/pastes/info?id={pasteid}')
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
info = json;
|
||||
document.getElementById('uploader-username').innerText = json.uploader || 'Anonymous';
|
||||
document.getElementById('creationdate').innerText = localizeDateTime(json.date);
|
||||
document.getElementById('paste-size').innerText = json.size;
|
||||
document.getElementById('paste-size').title = `Compressed Size: ${json.compressedSize}`;
|
||||
document.getElementById('paste-title').innerText = json.title;
|
||||
document.getElementById('paste-title').title = json.title;
|
||||
if (json.title == "") {
|
||||
document.getElementById('paste-title').innerText = `Untitled ${json.uid}`;
|
||||
document.title = `Untitled ${json.uid}`;
|
||||
}
|
||||
if (json.uploader && json.uploader.startsWith("Anonymous") && json.uploader.length == 46) {
|
||||
document.getElementById('uploader-username').innerText = 'Anonymous';
|
||||
} else if (json.uploader) {
|
||||
document.getElementById('uploader-username').href = `/u/${json.uploader}`;
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error fetching paste info:', error));
|
||||
}
|
||||
document.getElementById("edit-button").addEventListener("click", function () {
|
||||
if (editing) {
|
||||
createInput('Are you sure you want to save this edit?');
|
||||
document.getElementById('yes-button').addEventListener("click", finalizeEdit);
|
||||
} else {
|
||||
editing = true;
|
||||
var editButton = document.getElementById('edit-button');
|
||||
editButton.innerText = 'save';
|
||||
var text = document.getElementById('text');
|
||||
var innertext = text.innerText;
|
||||
text.innerHTML = `<textarea class="textarea" id="edit-textarea" style="width: 100%; height: ${text.clientHeight}px;">${innertext}</textarea>`;
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
fetchInfo();
|
||||
authenticated();
|
||||
const creationdateElement = document.getElementById('creationdate');
|
||||
const creationdateText = creationdateElement.innerText.trim();
|
||||
const textElement = document.getElementById('text');
|
||||
creationdateElement.innerText = localizeDateTime(parseInt(creationdateText));
|
||||
textElement.innerText = "Loading...";
|
||||
fetch(`/raw/{pasteid}`)
|
||||
.then(response => response.body)
|
||||
.then(stream => {
|
||||
const reader = stream.getReader();
|
||||
let text = '';
|
||||
|
||||
const read = () => {
|
||||
return reader.read().then(({ done, value }) => {
|
||||
if (done) {
|
||||
textElement.innerText = text;
|
||||
return;
|
||||
}
|
||||
text += new TextDecoder().decode(value);
|
||||
return read();
|
||||
});
|
||||
};
|
||||
|
||||
return read();
|
||||
});
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
|
||||
document.getElementById("copy-button").addEventListener("click", function () {
|
||||
navigator.clipboard.writeText(document.querySelector(".paste-wrapper").innerText);
|
||||
});
|
||||
document.getElementById("download-button").addEventListener("click", function () {
|
||||
var element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(document.querySelector(".paste-wrapper").innerText));
|
||||
element.setAttribute('download', '{pasteid}.txt');
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
element.click();
|
||||
document.body.removeChild(element);
|
||||
});
|
||||
document.getElementById("delete-button").addEventListener("click", function () {
|
||||
createInput('Are you sure you want to delete this paste?');
|
||||
document.getElementById("yes-button").addEventListener("click", function () {
|
||||
fetch(`/api/pastes/delete?id={pasteid}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: '{pasteid}'
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.message != null) {
|
||||
createNotification(`Success: ${result.message}`);
|
||||
setTimeout(() => {
|
||||
const inputWrapper = document.getElementById('input-wrapper');
|
||||
inputWrapper.style.display = 'none';
|
||||
window.location.href = '/';
|
||||
}, 2000);
|
||||
} else {
|
||||
const inputWrapper = document.getElementById('input-wrapper');
|
||||
inputWrapper.style.display = 'none';
|
||||
createNotification(`Error: ${result.error}`);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
document.getElementById("no-button").addEventListener("click", function () {
|
||||
const inputWrapper = document.getElementById('input-wrapper');
|
||||
inputWrapper.style.display = 'none';
|
||||
});
|
||||
function createNotification(message) {
|
||||
const notificationWrapper = document.getElementById('notifications');
|
||||
const notificationDiv = document.createElement('div');
|
||||
notificationDiv.classList.add('notification-div');
|
||||
notificationDiv.id = 'notification';
|
||||
|
||||
const notificationText = document.createElement('h2');
|
||||
notificationText.id = 'notification-text';
|
||||
notificationText.innerText = message;
|
||||
|
||||
notificationDiv.appendChild(notificationText);
|
||||
notificationWrapper.appendChild(notificationDiv);
|
||||
|
||||
notificationDiv.style.animation = 'none';
|
||||
notificationDiv.style.display = 'none';
|
||||
notificationDiv.style.display = 'flex';
|
||||
notificationDiv.style.animation = 'hoverup 1s';
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.style.animation = 'hoverdown 1s';
|
||||
}, 4000);
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.remove();
|
||||
}, 4900);
|
||||
}
|
||||
function createInput(message) {
|
||||
const inputWrapper = document.getElementById('input-wrapper');
|
||||
const inputMessage = document.getElementById('input-message');
|
||||
inputMessage.innerText = message;
|
||||
inputWrapper.style.display = 'flex';
|
||||
}
|
||||
function finalizeEdit() {
|
||||
var textarea = document.getElementById('edit-textarea');
|
||||
var text = textarea.value;
|
||||
fetch(`/api/pastes/edit`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: '{pasteid}',
|
||||
text: text
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.message != null) {
|
||||
const inputWrapper = document.getElementById('input-wrapper');
|
||||
inputWrapper.style.display = 'none';
|
||||
document.getElementById('edit-button').innerText = "edit";
|
||||
createNotification(`Success: ${result.message}`);
|
||||
document.getElementById('text').innerText = text;
|
||||
document.getElementById('edit-textarea').remove();
|
||||
editing = false;
|
||||
} else {
|
||||
const inputWrapper = document.getElementById('input-wrapper');
|
||||
inputWrapper.style.display = 'none';
|
||||
document.getElementById('edit-button').innerText = "edit";
|
||||
createNotification(`Error: ${result.error}`);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</html>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap');
|
||||
|
||||
.textarea{
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: 500;
|
||||
max-width: 100%;
|
||||
min-width: 100%;
|
||||
background-color: #1d1d1d;
|
||||
color: white;
|
||||
border: none;
|
||||
}
|
||||
.textarea:focus{
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.input-wrapper{
|
||||
z-index: 100;
|
||||
display: none;
|
||||
position: absolute;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: white;
|
||||
backdrop-filter: blur(2.5px);
|
||||
}
|
||||
.input-wrapper-container{
|
||||
z-index: 101;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 50%;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
.paste-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
min-height: 20%;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.paste-wrapper {
|
||||
width: 95%;
|
||||
height: fit-content;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
background-color: #1d1d1d;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
margin-top: 10px;
|
||||
text-wrap: wrap;
|
||||
font-weight: 500;
|
||||
max-height: 80%;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.buttons-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.buttons-wrapper a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.button {
|
||||
transition: 300ms;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: 2px solid #33333300;
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
font-size: 1.05rem;
|
||||
padding: 10px;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: 625;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
.uploader-text {
|
||||
margin-top: -1.2rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.user-a:any-link {
|
||||
color: rgb(190, 190, 190);
|
||||
text-decoration: none;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
z-index: 999999;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@keyframes hoverup {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
|
||||
25% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
50% {
|
||||
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes hoverdown {
|
||||
0% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateY(200%);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.notification-div {
|
||||
display: flex;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
color: white;
|
||||
background-color: #181818;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 102;
|
||||
position: absolute;
|
||||
}
|
||||
.notifcations-wrapper{
|
||||
z-index: 101;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,643 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{pastetitle}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
|
||||
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
|
||||
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
|
||||
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
|
||||
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
|
||||
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="paste-container">
|
||||
<h1 id="paste-title" title="{pastetitleattribute}">{pastetitle}</h1>
|
||||
<h3 class="uploader-text"><a id="uploader-username" class="user-a"></a> <a id="creationdate"></a> <a id="paste-size"></a>
|
||||
</h3>
|
||||
<div class="paste-wrapper">
|
||||
<p id="text"></p>
|
||||
</div>
|
||||
<div class="buttons-wrapper">
|
||||
<a href="" id="view-raw-a">
|
||||
<button id="view-raw-button" class="button">view raw</button>
|
||||
</a>
|
||||
<button id="copy-button" class="button">copy</button>
|
||||
<button id="download-button" class="button">download</button>
|
||||
<button id="delete-button" class="button" style="display: none;">delete</button>
|
||||
<button id="edit-button" class="button" style="display: none;">edit</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="passwordDiv">
|
||||
<div class="inputDiv">
|
||||
<h1>This paste is password protected</h1>
|
||||
<input type="password" id="password" class="textinput" name="password" maxlength="500"
|
||||
placeholder="password">
|
||||
<button id="submitPassword" class="button-input">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="notification-div" id="notification">
|
||||
<h2 id="notification-text"></h2>
|
||||
</div>
|
||||
<div class="input-wrapper" id="input-wrapper">
|
||||
<div class="input-wrapper-container">
|
||||
<h2 id="input-message"></h2>
|
||||
<div>
|
||||
<button id="yes-button" class="button">Yes</button>
|
||||
<button id="no-button" class="button">No</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
info = "";
|
||||
editing = false;
|
||||
function authenticated() {
|
||||
fetch('/api/accounts/authenticated')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.message == "Authenticated") {
|
||||
if (info.uploader == data.username || data.type == "Admin") {
|
||||
document.getElementById('delete-button').style.display = 'block';
|
||||
//document.getElementById('edit-button').style.display = 'block';
|
||||
}
|
||||
document.querySelectorAll("#login-signup-btn").forEach(element => {
|
||||
element.style.display = 'none';
|
||||
});
|
||||
document.getElementById('dash-btn').style.display = 'block';
|
||||
}else{
|
||||
document.querySelectorAll("#login-signup-btn").forEach(element => {
|
||||
element.style.display = 'block';
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function fetchInfo() {
|
||||
fetch('/api/pastes/info?id={pasteid}')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const json = JSON.parse(data);
|
||||
info = json;
|
||||
document.getElementById('uploader-username').innerText = json.uploader;
|
||||
document.getElementById('creationdate').innerText = localizeDateTime(json.date);
|
||||
document.getElementById('paste-size').innerText = json.size;
|
||||
document.getElementById('paste-size').title = `Compressed Size: ${json.compressedSize}`;
|
||||
document.getElementById('paste-title').innerText = json.title;
|
||||
document.getElementById('paste-title').title = json.title;
|
||||
if (json.title == "") {
|
||||
document.getElementById('paste-title').innerText = `Untitled ${json.uid}`;
|
||||
document.title = `Untitled ${json.uid}`;
|
||||
}
|
||||
if (json.uploader.startsWith("Anonymous") && json.uploader.length == 46) {
|
||||
document.getElementById('uploader-username').innerText = 'Anonymous';
|
||||
} else {
|
||||
document.getElementById('uploader-username').href = `/u/${json.uploader}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
document.getElementById("edit-button").addEventListener("click", function () {
|
||||
if (editing) {
|
||||
createInput('Are you sure you want to save this edit?');
|
||||
document.getElementById('yes-button').removeEventListener("click", deletePaste);
|
||||
document.getElementById('yes-button').addEventListener("click", finalizeEdit);
|
||||
document.getElementById('yes-button').removeEventListener("click", finalizeEdit);
|
||||
} else {
|
||||
editing = true;
|
||||
var editButton = document.getElementById('edit-button');
|
||||
editButton.innerText = 'save';
|
||||
var text = document.getElementById('text');
|
||||
var innertext = text.innerText;
|
||||
text.innerHTML = `<textarea class="textarea" id="edit-textarea" style="width: 100%; height: ${text.clientHeight}px;">${innertext}</textarea>`;
|
||||
}
|
||||
});
|
||||
document.getElementById("submitPassword").addEventListener("click", function () {
|
||||
var password = document.getElementById("password").value;
|
||||
fetch(`/api/pastes/password/{pasteid}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
password: password
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.content != null) {
|
||||
const textElement = document.getElementById('text');
|
||||
textElement.innerText = result.content;
|
||||
document.querySelector(".passwordDiv").style.display = "none";
|
||||
const viewRawButton = document.getElementById('view-raw-a');
|
||||
viewRawButton.href = `/raw/{pasteid}?password=` + password;
|
||||
}
|
||||
else {
|
||||
notification(`Error: ${result.error}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
function localizeDateTime(unixTimestamp) {
|
||||
const date = new Date(unixTimestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
fetchInfo();
|
||||
authenticated();
|
||||
|
||||
const creationdateElement = document.getElementById('creationdate');
|
||||
const creationdateText = creationdateElement.innerText.trim();
|
||||
creationdateElement.innerText = localizeDateTime(parseInt(creationdateText));
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
document.getElementById("copy-button").addEventListener("click", function () {
|
||||
navigator.clipboard.writeText(document.querySelector(".paste-wrapper").innerText);
|
||||
});
|
||||
document.getElementById("download-button").addEventListener("click", function () {
|
||||
var element = document.createElement('a');
|
||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(document.querySelector(".paste-wrapper").innerText));
|
||||
element.setAttribute('download', '{pasteid}.txt');
|
||||
element.style.display = 'none';
|
||||
document.body.appendChild(element);
|
||||
element.click();
|
||||
document.body.removeChild(element);
|
||||
});
|
||||
document.getElementById("delete-button").addEventListener("click", function () {
|
||||
createInput('Are you sure you want to delete this paste?');
|
||||
document.getElementById('yes-button').removeEventListener("click", finalizeEdit);
|
||||
document.getElementById('yes-button').addEventListener("click", deletePaste);
|
||||
document.getElementById('yes-button').removeEventListener("click", deletePaste);
|
||||
});
|
||||
function deletePaste() {
|
||||
fetch(`/api/pastes/delete?id={pasteid}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: '{pasteid}'
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.message != null) {
|
||||
createNotification(`Success: ${result.message}`);
|
||||
setTimeout(() => {
|
||||
window.location.href = '/';
|
||||
}, 2000);
|
||||
} else {
|
||||
createNotification(`Error: ${result.error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
function finalizeEdit() {
|
||||
var textarea = document.getElementById('edit-textarea');
|
||||
var text = textarea.value;
|
||||
fetch(`/api/pastes/edit`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: '{pasteid}',
|
||||
text: text
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.message != null) {
|
||||
createNotification(`Success: ${result.message}`);
|
||||
document.getElementById('text').innerText = text;
|
||||
document.getElementById('edit-textarea').remove();
|
||||
editing = false;
|
||||
} else {
|
||||
createNotification(`Error: ${result.error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
document.getElementById("no-button").addEventListener("click", function () {
|
||||
const inputWrapper = document.getElementById('input-wrapper');
|
||||
inputWrapper.style.display = 'none';
|
||||
document.getElementById('yes-button').removeEventListener("click", finalizeEdit);
|
||||
document.getElementById('yes-button').removeEventListener("click", deletePaste);
|
||||
|
||||
});
|
||||
function notification(message) {
|
||||
const notification = document.getElementById('notification');
|
||||
const notificationText = document.getElementById('notification-text');
|
||||
notificationText.innerText = message;
|
||||
notification.style.animation = 'none';
|
||||
notification.style.display = 'none';
|
||||
notification.style.display = 'flex';
|
||||
notification.style.animation = 'hoverup 1s';
|
||||
setTimeout(() => {
|
||||
|
||||
notification.style.animation = 'hoverdown 1s';
|
||||
}, 4000);
|
||||
setTimeout(() => {
|
||||
notification.style.display = 'none';
|
||||
}, 4900);
|
||||
|
||||
}
|
||||
function createInput(message) {
|
||||
const inputWrapper = document.getElementById('input-wrapper');
|
||||
const inputMessage = document.getElementById('input-message');
|
||||
inputMessage.innerText = message;
|
||||
inputWrapper.style.display = 'flex';
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</html>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap');
|
||||
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
z-index: 100;
|
||||
display: none;
|
||||
position: absolute;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: white;
|
||||
backdrop-filter: blur(2.5px);
|
||||
}
|
||||
|
||||
.input-wrapper-container {
|
||||
z-index: 101;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 50%;
|
||||
border-radius: 5px;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
.button-input {
|
||||
transition: 300ms;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: 2px solid #33333300;
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
font-size: 1.05rem;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: 625;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
.button-input:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
.passwordDiv {
|
||||
z-index: 100;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
backdrop-filter: blur(8px);
|
||||
color: white;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.inputDiv {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.textinput {
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
border-radius: 5px;
|
||||
border: 2px solid #222222;
|
||||
background-color: #181818;
|
||||
padding: 10px;
|
||||
font-size: 1.05rem;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: 625;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.textinput:focus {
|
||||
outline: none;
|
||||
border: 2px solid #333333;
|
||||
}
|
||||
|
||||
.paste-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
min-height: 20%;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.paste-wrapper {
|
||||
width: 95%;
|
||||
height: fit-content;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
background-color: #1d1d1d;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
margin-top: 10px;
|
||||
text-wrap: wrap;
|
||||
font-weight: 500;
|
||||
max-height: 80%;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.buttons-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.buttons-wrapper a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.button {
|
||||
transition: 300ms;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: 2px solid #33333300;
|
||||
border-radius: 5px;
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
font-size: 1.05rem;
|
||||
padding: 10px;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: 625;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
.uploader-text {
|
||||
margin-top: -1.2rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.user-a {
|
||||
color: rgb(190, 190, 190);
|
||||
text-decoration: none;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
z-index: 999999;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@keyframes hoverup {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
|
||||
25% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
50% {
|
||||
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes hoverdown {
|
||||
0% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateY(200%);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.notification-div {
|
||||
position: fixed;
|
||||
display: none;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
color: white;
|
||||
background-color: #181818;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 102;
|
||||
position: absolute;
|
||||
}
|
||||
.notifcations-wrapper{
|
||||
z-index: 101;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,273 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>recent pastes</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
|
||||
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="pastes-container">
|
||||
<h1>recent pastes</h1>
|
||||
<div class="pastes-wrapper">
|
||||
{pastes}
|
||||
</div>
|
||||
<div class="buttons-wrapper">
|
||||
<a href="/">create paste</a>
|
||||
<a href="/archive">paste archives</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
.pastes-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
min-height: 20%;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.pastes-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 95%;
|
||||
padding: 20px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
max-height: 70vh;
|
||||
}
|
||||
|
||||
.pastes-wrapper a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
li {
|
||||
transition: 300ms;
|
||||
list-style: none;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
width: 90%;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border: #22222200 2px solid;
|
||||
}
|
||||
|
||||
li:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.buttons-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.buttons-wrapper a {
|
||||
transition: 300ms;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: fit-content;
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
min-width: 20%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
border: #22222200 2px solid;
|
||||
}
|
||||
|
||||
.buttons-wrapper a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,366 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
||||
<title>sign-up</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="creation-container">
|
||||
<h1>sign-up</h1>
|
||||
<form id="signupForm">
|
||||
<label for="usernameTitle" class="label" onforminput="">Username</label>
|
||||
<input type="text" id="usernameInput" class="textinput" name="pasteTitle" required maxlength="20" minlength="3">
|
||||
<label id="characterCount" for="characterCount" class="ccounter">0/20</label>
|
||||
<label for="passwordTitle" class="label" id="margin-top">Password</label>
|
||||
<input type="password" id="passwordInput" class="textinput" name="pasteTitle" required maxlength="50" minlength="8">
|
||||
<label id="passcharacterCount" for="characterCount" class="ccounter">0/50</label>
|
||||
<div id="cf-turnstile" class="cf-turnstile" data-sitekey="{sitekey}"></div>
|
||||
<button type="submit" class="button" id="button-margin-top">Sign-up</button>
|
||||
</form>
|
||||
<h3 id="error-message"></h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="notifcations-wrapper" id="notifications">
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
let isLoggingIn = false;
|
||||
|
||||
document.getElementById("signupForm").addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var usernameContent = document.getElementById("usernameInput").value;
|
||||
var passwordContent = document.getElementById("passwordInput").value;
|
||||
var cf = turnstile.getResponse();
|
||||
|
||||
if (isLoggingIn) {
|
||||
createNotification("Please wait for the login to finish.");
|
||||
return;
|
||||
}
|
||||
isLoggingIn = true;
|
||||
|
||||
var requestUrl = "/api/accounts/create";
|
||||
fetch(requestUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: usernameContent,
|
||||
password: passwordContent,
|
||||
cf: cf
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(obj => {
|
||||
const result = JSON.parse(obj);
|
||||
if (result.message != null) {
|
||||
window.location.href = "/";
|
||||
isLoggingIn = false;
|
||||
}
|
||||
else if (result.error != null) {
|
||||
const errorElement = document.getElementById("error-message");
|
||||
errorElement.innerText = result.error;
|
||||
errorElement.style.opacity = 1;
|
||||
|
||||
setTimeout(() => {
|
||||
errorElement.style.opacity = 0;
|
||||
}, 3000);
|
||||
isLoggingIn = false;
|
||||
|
||||
}
|
||||
})
|
||||
});
|
||||
document.getElementById("usernameInput").addEventListener("input", function (event) {
|
||||
var usernameContent = document.getElementById("usernameInput").value;
|
||||
var characterCount = usernameContent.length;
|
||||
document.getElementById("characterCount").innerText = `${characterCount}/20`;
|
||||
});
|
||||
document.getElementById("passwordInput").addEventListener("input", function (event) {
|
||||
var passwordContent = document.getElementById("passwordInput").value;
|
||||
var characterCount = passwordContent.length;
|
||||
document.getElementById("passcharacterCount").innerText = `${characterCount}/50`;
|
||||
});
|
||||
function createNotification(message) {
|
||||
const notificationWrapper = document.getElementById('notifications');
|
||||
const notificationDiv = document.createElement('div');
|
||||
notificationDiv.classList.add('notification-div');
|
||||
notificationDiv.id = 'notification';
|
||||
|
||||
const notificationText = document.createElement('h2');
|
||||
notificationText.id = 'notification-text';
|
||||
notificationText.innerText = message;
|
||||
|
||||
notificationDiv.appendChild(notificationText);
|
||||
notificationWrapper.appendChild(notificationDiv);
|
||||
|
||||
notificationDiv.style.animation = 'none';
|
||||
notificationDiv.style.display = 'none';
|
||||
notificationDiv.style.display = 'flex';
|
||||
notificationDiv.style.animation = 'hoverup 1s';
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.style.animation = 'hoverdown 1s';
|
||||
}, 4000);
|
||||
|
||||
setTimeout(() => {
|
||||
notificationDiv.remove();
|
||||
}, 4900);
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 98.7vh;
|
||||
}
|
||||
|
||||
.creation-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 80vh;
|
||||
min-height: 20%;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
#signupForm {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#error-message {
|
||||
color: red;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
bottom: -0.1px;
|
||||
margin-bottom: -0.1px;
|
||||
top: 61.8%;
|
||||
transition: 300ms;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.textinput {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #282828;
|
||||
color: white;
|
||||
border: #2a2a2a 2px solid;
|
||||
box-sizing: border-box;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-size: 1.1em;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textinput:focus {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
min-width: 100%;
|
||||
max-width: 100%;
|
||||
min-height: auto;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #282828;
|
||||
color: white;
|
||||
border: #2a2a2a 2px solid;
|
||||
box-sizing: border-box;
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-size: 1.08em;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.textarea:focus {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.button {
|
||||
transition: 300ms;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 10px 0;
|
||||
border-radius: 5px;
|
||||
border: none;
|
||||
background-color: #222222;
|
||||
color: white;
|
||||
border: #2a2a2a00 2px solid;
|
||||
cursor: pointer;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: 2px solid #3a3a3a;
|
||||
}
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.ccounter {
|
||||
align-self: flex-end;
|
||||
text-align: right;
|
||||
margin-top: -2.2rem;
|
||||
margin-right: 10px;
|
||||
font-size: 1.1em;
|
||||
color: #888888;
|
||||
}
|
||||
|
||||
#margin-top {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#button-margin-top {
|
||||
margin-top: 30px;
|
||||
}
|
||||
@keyframes hoverup {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(100%);
|
||||
}
|
||||
|
||||
25% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
50% {
|
||||
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes hoverdown {
|
||||
0% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateY(200%);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.notification-div {
|
||||
display: flex;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: fit-content;
|
||||
height: fit-content;
|
||||
color: white;
|
||||
background-color: #181818;
|
||||
border-radius: 5px;
|
||||
border: #222222 2px solid;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
margin-right: 10px;
|
||||
margin-bottom: 10px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.notifcations-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,348 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Mono:wght@100..900&display=swap" rel="stylesheet">
|
||||
<title>{username}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="nav-div">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
<div class="nav-hamburger-menu">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
|
||||
<path fill-rule="evenodd"
|
||||
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
|
||||
</svg>
|
||||
<div class="nav-buttons">
|
||||
<a href="/">home</a>
|
||||
<a href="/pastes">recent pastes</a>
|
||||
<a href="/archive">archive</a>
|
||||
{html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-wrapper">
|
||||
<div class="account-container">
|
||||
<div class="account-info">
|
||||
<h2>{username}</h2>
|
||||
<h3>UID: {uid}</h3>
|
||||
<h3 id="creationdate">{creationdate}</h3>
|
||||
<h3>Account Type: {type}</h3>
|
||||
<h3>Total Pastes: {totalpastes}</h3>
|
||||
<h3>Total Pastes Size: {totalsize}</h3>
|
||||
</div>
|
||||
<div class="collumn-2">
|
||||
<div class="pastes-wrapper">
|
||||
<h2 style="text-align: center;">Pastes</h2>
|
||||
<div class="pastes-container">
|
||||
{pastes}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
function localizeDateTime(unixTimestamp) {
|
||||
const date = new Date(unixTimestamp * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const creationdateElement = document.getElementById('creationdate');
|
||||
|
||||
const creationdateText = creationdateElement.innerText.trim();
|
||||
|
||||
creationdateElement.innerText = "Creation Date: " + localizeDateTime(parseInt(creationdateText));
|
||||
var mobile = window.mobileCheck();
|
||||
if (mobile) {
|
||||
document.querySelector('.nav-div').style.display = 'none';
|
||||
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
|
||||
}
|
||||
});
|
||||
document.getElementById("hamburger-button").addEventListener("click", function () {
|
||||
const nav = document.querySelector('.nav-buttons');
|
||||
if (nav.style.display == 'none' || nav.style.display == '') {
|
||||
nav.style.display = 'flex';
|
||||
} else {
|
||||
nav.style.display = 'none';
|
||||
}
|
||||
});
|
||||
window.mobileCheck = function () {
|
||||
let check = false;
|
||||
(function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera);
|
||||
return check;
|
||||
};
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #0d0d0d;
|
||||
height: calc(100vh - 20px);
|
||||
}
|
||||
|
||||
.container-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.account-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
width: 80%;
|
||||
padding: 20px;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
max-height: 100%;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.account-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #222222;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
width: fit-content;
|
||||
width: 48%;
|
||||
max-width: 48%;
|
||||
margin-right: 10px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
h3 {
|
||||
word-break: keep-all;
|
||||
margin-top: -5px;
|
||||
}
|
||||
|
||||
.list-a {
|
||||
transition: background-color 300ms;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
width: 90%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #2a2a2a;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
border: #3a3a3a00 2px solid;
|
||||
}
|
||||
|
||||
.list-a:hover {
|
||||
transition: background-color 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.collumn-2 {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 48%;
|
||||
max-width: 48%;
|
||||
}
|
||||
|
||||
.pastes-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
width: calc(100% - 52px);
|
||||
max-width: 100%;
|
||||
background-color: #222222;
|
||||
border-radius: 5px;
|
||||
padding: 26px;
|
||||
height: fit-content;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.pastes-container {
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.nav-div {
|
||||
top: 0;
|
||||
margin-top: 10px;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
background-color: #181818;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
top: 0;
|
||||
position: absolute;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 99vw;
|
||||
overflow-x: hidden;
|
||||
background-color: #181818;
|
||||
color: white;
|
||||
height: fit-content;
|
||||
overflow-y: auto;
|
||||
border: #222222 2px solid;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 2px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.nav-buttons a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a {
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
margin: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: #222222;
|
||||
transition: 300ms;
|
||||
border: #2a2a2a00 2px solid;
|
||||
}
|
||||
|
||||
.nav-div a:hover {
|
||||
transition: 300ms;
|
||||
background-color: #333333;
|
||||
border: #3a3a3a 2px solid;
|
||||
}
|
||||
@media screen and (max-width: 800px) {
|
||||
.nav-div {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-hamburger-menu {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-buttons a {
|
||||
display: block;
|
||||
}
|
||||
.container-wrapper{
|
||||
margin-top: calc(90% - 180px);
|
||||
padding-bottom: 50px;
|
||||
height: 90%;
|
||||
}
|
||||
.account-container {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
max-height: 100%;
|
||||
}
|
||||
.account-info {
|
||||
margin-right: 0px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
max-width: 100%;
|
||||
font-size: smaller !important;
|
||||
}
|
||||
.collumn-2 {
|
||||
margin-top: 10px;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
max-height: 48%;
|
||||
}
|
||||
.action-wrapper {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
max-height: 40%;
|
||||
}
|
||||
.button {
|
||||
width: 90%;
|
||||
max-width: 100%;
|
||||
margin: 0;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.pastes-wrapper {
|
||||
margin-top: 10px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
height: 97%;
|
||||
max-width: 100%;
|
||||
max-height: calc(500px * 1.5 - 260px);
|
||||
}
|
||||
.pastes-container {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
max-height: 90%;
|
||||
overflow-x: hidden;
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
############################################
|
||||
#### Sharpbin Linux installer ####
|
||||
############################################
|
||||
##
|
||||
## This is a semi completed script to install Sharpbin on Linux, however it does not set it as a system daemon/service, cause idk how to do that lol
|
||||
##
|
||||
|
||||
mkdir sharpbin
|
||||
cd sharpbin
|
||||
|
||||
curl -s "https://api.github.com/repos/whoswhip/Sharpbin/releases/latest" | jq -r '.assets[] | select(.name | test("sharpbin-linux-.*\\.tar$")) | .browser_download_url' | xargs -I {} curl -L -o sharpbin-linux.tar {}
|
||||
|
||||
tar -xvf sharpbin-linux.tar
|
||||
chmod +x Sharpbin
|
||||
|
||||
echo "Enter your cloudflare sitekey: "
|
||||
read sitekey
|
||||
echo "Enter your cloudflare secretkey: "
|
||||
read secretkey
|
||||
|
||||
|
||||
echo "{ \"CF_TurnstileSiteKey\": \"$sitekey\", \"CF_TurnstileSecret\": \"$secretkey\" }" > config.json
|
||||
@@ -1,67 +1,27 @@
|
||||
# SharpbinV3
|
||||
|
||||
Sharpbin is a [pastebin](https://en.wikipedia.org/wiki/Pastebin)-style website built with ASP.NET Core and SvelteKit.
|
||||
|
||||
A live instance is available at [sharpbin.cc](https://sharpbin.cc).
|
||||
|
||||
# Sharpbin
|
||||
Sharpbin is a Pastebin type website completely in C#, except for the frontend, being pure HTML & CSS.
|
||||
Sharpbin can be used for sharing large amounts of text.
|
||||
## Features
|
||||
- Account System
|
||||
- Standalone
|
||||
- Raw Text Serving
|
||||
- Admin Panel that includes banning users
|
||||
- Search feature for pastes
|
||||
- Recent Pastes and Paste Archives
|
||||
- Pastes can be deleted by an admin or the creator
|
||||
- User profile pages
|
||||
- Private encrypted pastes, sadly the encryption is server side, although client side may be soon!
|
||||
- Mobile Support
|
||||
- Captchas for logins and sign ups
|
||||
... And more to come!
|
||||
|
||||
- User authentication and account management.
|
||||
- Syntax highlighting for various programming languages.
|
||||
- Private pastes with client-side encryption.
|
||||
- Raw text serving for easy sharing and scripting.
|
||||
- Paste editing including content, syntax, title, and expiration.
|
||||
- Configurable paste expiration.
|
||||
- Server-side paste compression to save storage.
|
||||
- Captcha support via Cloudflare Turnstile.
|
||||
# Demo Website & Screenshots
|
||||
You can find the test website at https://bin.whoswhip.top , there is no removed functionality and is the exact same code in this repo.
|
||||
<div>
|
||||
<img src="https://github.com/user-attachments/assets/07a28669-3f93-4f79-a3a4-652feab0bbd2" style="width: 250px;">
|
||||
<img src="https://github.com/user-attachments/assets/638d5bab-c967-4856-8ec4-47f4d907aec4" style="width: 250px;">
|
||||
<img src="https://github.com/user-attachments/assets/972b82fa-38ca-41bd-9f65-c8d291bd32e4" style="width: 250px;">
|
||||
<img src="https://github.com/user-attachments/assets/72829045-97da-453b-89c1-ed901c7d840e" style="width: 250px;">
|
||||
|
||||
## Getting Started
|
||||
</div>
|
||||
|
||||
The easiest way to run SharpbinV3 is using Docker Compose.
|
||||
|
||||
1. Ensure Docker and Docker Compose are installed.
|
||||
2. Clone the repository.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/whoswhip/Sharpbin.git
|
||||
```
|
||||
|
||||
3. Run the following command in the root directory:
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
You can configure the application using environment variables. When using Docker Compose, these can be set in the `docker-compose.yml` file.
|
||||
|
||||
#### Backend (SharpbinV3.Server)
|
||||
|
||||
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=/app/data/sharpbin.db`).
|
||||
- `JwtSettings__Secret`: A secure string used for signing JWT tokens.
|
||||
- `AuthSettings__CF_Turnstile_SecretKey`: Your Cloudflare Turnstile secret key.
|
||||
- `AuthSettings__CF_Turnstile_SiteKey`: Your Cloudflare Turnstile site key.
|
||||
- `AuthSettings__Registration_Enabled`: Set to `true` by default, enables/disables registration.
|
||||
- `AuthSettings__First_User_Admin`: Gives the first user the admin role, it is recommended to disable this after use.
|
||||
- `AuthSettings__Admins_Require_2FA`: Enforces Admins to have 2FA when trying to do certain actions.
|
||||
- `PasteSettings__MaxTitleLength`: Max title length in characters.
|
||||
- `PasteSettings__MaxPasteSizeInBytes`: Max Paste Size set in bytes, the default is `1_048_576` (1MB)
|
||||
- `PasteSettings__EnablePasteCompression`: Enables/Disables server-side paste compression, `true` by default.
|
||||
- `PasteSettings__RequiresVerification`: Enables/Disables CAPTCHA verification when creating pastes, `true` by default.
|
||||
- `PasteSettings__View_HMAC_Secret`: Required to securely hash viewer identifiers
|
||||
- `PasteSettings__View_Internal_API_Key`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
|
||||
- `ASPNETCORE_ENVIRONMENT`: Set to `Production` or `Development`.
|
||||
|
||||
#### Frontend (SharpbinV3.Client)
|
||||
|
||||
- `VITE_API_URL`: The URL of the backend API (e.g., `http://localhost:8080`).
|
||||
- `VITE_ALLOWED_HOSTS`: A comma separated list of allowed hosts (e.g., `localhost,sharpbin.whoswhip.dev`)
|
||||
- `VIEW_INTERNAL_API_KEY`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
|
||||
|
||||
The frontend will be accessible at http://localhost:5173.
|
||||
|
||||
## Project Structure
|
||||
|
||||
- **[SharpbinV3.Server](SharpbinV3.Server/README.md)**: Backend API built with C# and ASP.NET Core. Refer to its README for server-side development and configuration.
|
||||
- **[SharpbinV3.Client](SharpbinV3.Client/README.md)**: Frontend application built with SvelteKit and TypeScript. Refer to its README for client-side development and setup.
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
node_modules
|
||||
|
||||
# Output
|
||||
.output
|
||||
.vercel
|
||||
.netlify
|
||||
.wrangler
|
||||
/.svelte-kit
|
||||
/build
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.test
|
||||
|
||||
# Vite
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
@@ -1 +0,0 @@
|
||||
engine-strict=true
|
||||
@@ -1,9 +0,0 @@
|
||||
# Package Managers
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
yarn.lock
|
||||
bun.lock
|
||||
bun.lockb
|
||||
|
||||
# Miscellaneous
|
||||
/static/
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100,
|
||||
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": "*.svelte",
|
||||
"options": {
|
||||
"parser": "svelte"
|
||||
}
|
||||
}
|
||||
],
|
||||
"tailwindStylesheet": "./src/routes/layout.css"
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.css": "tailwindcss"
|
||||
},
|
||||
"tailwindCSS.experimental.configFile": "src/routes/layout.css"
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM node:20-alpine as build
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
FROM node:20-alpine as runner
|
||||
WORKDIR /app
|
||||
COPY --from=build /app .
|
||||
RUN apk add --no-cache wget
|
||||
EXPOSE 5173
|
||||
CMD ["npm", "run", "preview", "--", "--host", "0.0.0.0", "--port", "5173"]
|
||||
@@ -1,53 +0,0 @@
|
||||
# SharpbinV3 Client
|
||||
|
||||
This is the SvelteKit frontend for SharpbinV3.
|
||||
|
||||
## Development Setup
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Node.js (v20 or newer recommended)
|
||||
- npm
|
||||
|
||||
### Installation
|
||||
|
||||
Install the project dependencies:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
### Environment Configuration
|
||||
|
||||
The application requires an environment variable to point to the backend API. Create a `.env` file in this directory or set the variable in your environment:
|
||||
|
||||
- `VITE_API_URL`: The URL of the backend API (e.g., `http://localhost:8080`).
|
||||
- `VITE_ALLOWED_HOSTS`: A comma separated list of allowed hosts (e.g., `localhost,sharpbin.whoswhip.dev`)
|
||||
- `VIEW_INTERNAL_API_KEY`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
|
||||
|
||||
### Running in Development
|
||||
|
||||
Start the development server with Hot Module Replacement (HMR):
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
The application will be available at http://localhost:5173.
|
||||
|
||||
## Script Reference
|
||||
|
||||
- `npm run dev`: Start the Vite development server.
|
||||
- `npm run build`: Create a production build of the application.
|
||||
- `npm run preview`: Locally preview the production build.
|
||||
- `npm run check`: Run type checking with svelte-check.
|
||||
- `npm run lint`: Run ESLint and Prettier checks.
|
||||
- `npm run format`: Format the codebase with Prettier.
|
||||
|
||||
## Tech Stack
|
||||
|
||||
- Svelte 5 with SvelteKit.
|
||||
- Tailwind CSS for styling.
|
||||
- Lucide Svelte for icons.
|
||||
- Highlight.js for syntax highlighting.
|
||||
- TypeScript for type safety.
|
||||
@@ -1,41 +0,0 @@
|
||||
import prettier from 'eslint-config-prettier';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { includeIgnoreFile } from '@eslint/compat';
|
||||
import js from '@eslint/js';
|
||||
import svelte from 'eslint-plugin-svelte';
|
||||
import { defineConfig } from 'eslint/config';
|
||||
import globals from 'globals';
|
||||
import ts from 'typescript-eslint';
|
||||
import svelteConfig from './svelte.config.js';
|
||||
|
||||
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
|
||||
|
||||
export default defineConfig(
|
||||
includeIgnoreFile(gitignorePath),
|
||||
js.configs.recommended,
|
||||
...ts.configs.recommended,
|
||||
...svelte.configs.recommended,
|
||||
prettier,
|
||||
...svelte.configs.prettier,
|
||||
{
|
||||
languageOptions: { globals: { ...globals.browser, ...globals.node } },
|
||||
|
||||
rules: {
|
||||
// typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.
|
||||
// see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
|
||||
'no-undef': 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
|
||||
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
extraFileExtensions: ['.svelte'],
|
||||
parser: ts.parser,
|
||||
svelteConfig
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Generated
-5010
File diff suppressed because it is too large
Load Diff
@@ -1,53 +0,0 @@
|
||||
{
|
||||
"name": "sharpbinv3.client",
|
||||
"private": true,
|
||||
"version": "3.0.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"format": "prettier --write .",
|
||||
"lint": "prettier --check . && eslint ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.4.0",
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@sveltejs/adapter-auto": "^7.0.0",
|
||||
"@sveltejs/kit": "^2.50.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
||||
"@tailwindcss/vite": "^4.1.17",
|
||||
"@types/jsdom": "^27.0.0",
|
||||
"@types/node": "^22",
|
||||
"@types/papaparse": "^5.5.2",
|
||||
"@types/qrcode": "^1.5.6",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-svelte": "^3.13.1",
|
||||
"globals": "^16.5.0",
|
||||
"prettier": "^3.7.4",
|
||||
"prettier-plugin-svelte": "^3.4.0",
|
||||
"prettier-plugin-tailwindcss": "^0.7.2",
|
||||
"svelte": "^5.48.3",
|
||||
"svelte-check": "^4.3.4",
|
||||
"tailwind-scrollbar": "^4.0.2",
|
||||
"tailwindcss": "^4.1.17",
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.48.1",
|
||||
"vite": "^7.2.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lucide/svelte": "^0.562.0",
|
||||
"@sveltejs/adapter-node": "^5.4.0",
|
||||
"dompurify": "^3.3.1",
|
||||
"hash-wasm": "^4.12.0",
|
||||
"highlight.js": "^11.8.0",
|
||||
"jsdom": "^27.4.0",
|
||||
"marked": "^17.0.1",
|
||||
"papaparse": "^5.5.3",
|
||||
"qrcode": "^1.5.4"
|
||||
}
|
||||
}
|
||||
Vendored
-32
@@ -1,32 +0,0 @@
|
||||
// See https://svelte.dev/docs/kit/types#app.d.ts
|
||||
// for information about these interfaces
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
// interface PageData {}
|
||||
// interface PageState {}
|
||||
// interface Platform {}
|
||||
}
|
||||
interface Window {
|
||||
turnstile?: {
|
||||
getResponse: () => string | null;
|
||||
render: (container: string | HTMLElement, options?: Record<string, unknown>) => string;
|
||||
reset: (widgetId?: string) => void;
|
||||
remove: (widgetId?: string) => void;
|
||||
};
|
||||
turnstileLoaded?: () => void;
|
||||
}
|
||||
var turnstile:
|
||||
| {
|
||||
getResponse: () => string | null;
|
||||
render: (container: string | HTMLElement, options?: Record<string, unknown>) => string;
|
||||
reset: (widgetId?: string) => void;
|
||||
remove: (widgetId?: string) => void;
|
||||
}
|
||||
| undefined;
|
||||
var turnstileLoaded: (() => void) | undefined;
|
||||
declare const __APP_VERSION__: string;
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -1,19 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
<div style="display: contents">%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +0,0 @@
|
||||
<svg width="275" height="275" viewBox="0 0 275 275" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M83 146.5H191M83 187H191M123.5 106L110 227.5M164 106L150.5 227.5" stroke="white" stroke-width="15" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M223.178 253.186C223.103 253.77 223.008 254.349 222.894 254.919C220.763 265.573 211.972 273.602 201.261 274.835C200.968 274.869 200.673 274.895 200.377 274.919C200.263 274.928 200.148 274.938 200.033 274.945C199.68 274.968 199.326 274.985 198.97 274.993L198.382 275H76.6182V260H198.382C203.412 260 207.659 256.263 208.3 251.274L230.949 75H44.0508L66.7002 251.274C67.3413 256.263 71.5881 260 76.6182 260V275C75.9889 275 75.3646 274.976 74.7461 274.93C74.41 274.905 74.0757 274.873 73.7432 274.835C62.839 273.582 53.9239 265.286 51.999 254.346C51.9316 253.962 51.8723 253.575 51.8223 253.186L27 60H248L223.178 253.186Z" fill="white"/>
|
||||
<path d="M0 42.5C0 38.3579 3.48458 35 7.78302 35H267.217C271.515 35 275 38.3579 275 42.5C275 46.6421 271.515 50 267.217 50H7.78302C3.48458 50 0 46.6421 0 42.5Z" fill="white"/>
|
||||
<path d="M159.811 0C174.139 0 185.755 11.9073 185.755 26.5957V35H88.2075V26.5957C88.2076 11.9073 99.8228 0 114.151 0H159.811ZM114.151 15C108.42 15 103.774 19.4772 103.774 25V35H170.189V25C170.189 19.4772 165.543 15 159.811 15H114.151Z" fill="white"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.3 KiB |
@@ -1,143 +0,0 @@
|
||||
<script lang="ts">
|
||||
interface Option {
|
||||
value: string | number;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export let options: Option[] = [];
|
||||
export let value: string | number = '';
|
||||
export let placeholder = 'Select...';
|
||||
export let searchable = false;
|
||||
export let displayValue: (val: string | number) => string = (val) => {
|
||||
return options.find((o) => o.value === val)?.label ?? String(val);
|
||||
};
|
||||
export let variant: string = '';
|
||||
|
||||
let isOpen = false;
|
||||
let searchQuery = '';
|
||||
let dropdownElement: HTMLDivElement;
|
||||
let dropdownListElement: HTMLDivElement;
|
||||
let dropdownMaxHeight = '12rem';
|
||||
|
||||
$: filteredOptions = searchable
|
||||
? options.filter(
|
||||
(opt) =>
|
||||
opt.label.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
String(opt.value).toLowerCase().includes(searchQuery.toLowerCase())
|
||||
)
|
||||
: options;
|
||||
|
||||
function handleSelect(selectedValue: string | number) {
|
||||
value = selectedValue;
|
||||
isOpen = false;
|
||||
searchQuery = '';
|
||||
}
|
||||
|
||||
function handleKeyDown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape') {
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
function toggleDropdown() {
|
||||
isOpen = !isOpen;
|
||||
if (isOpen) {
|
||||
setTimeout(() => {
|
||||
if (dropdownElement && dropdownListElement) {
|
||||
const rect = dropdownElement.getBoundingClientRect();
|
||||
const spaceBelow = window.innerHeight - rect.bottom - 8;
|
||||
const maxCap = 416;
|
||||
dropdownMaxHeight = Math.max(120, Math.min(spaceBelow, maxCap)) + 'px';
|
||||
}
|
||||
if (searchable) {
|
||||
const input = dropdownElement?.querySelector('input[type="text"]') as HTMLInputElement;
|
||||
input?.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
function handleClickOutside(event: MouseEvent) {
|
||||
if (dropdownElement && !dropdownElement.contains(event.target as Node)) {
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:click={handleClickOutside} />
|
||||
|
||||
<div bind:this={dropdownElement} class="relative mb-2 w-full" class:dropdown-sm={variant === 'sm'}>
|
||||
<button
|
||||
type="button"
|
||||
on:click={toggleDropdown}
|
||||
class="w-full rounded border border-neutral-700 bg-neutral-800 p-2 text-left transition-colors hover:bg-neutral-700"
|
||||
class:dropdown-sm-btn={variant === 'sm'}
|
||||
>
|
||||
{displayValue(value) || placeholder}
|
||||
</button>
|
||||
|
||||
{#if isOpen}
|
||||
<div
|
||||
class="absolute top-full z-50 mt-1 w-full rounded border border-neutral-700 bg-neutral-800 shadow-lg"
|
||||
class:dropdown-sm-list={variant === 'sm'}
|
||||
bind:this={dropdownListElement}
|
||||
style="max-height: {dropdownMaxHeight}; width: 100%;"
|
||||
>
|
||||
{#if searchable}
|
||||
<div style="position: sticky; top: 0; z-index: 1; background: inherit;">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search..."
|
||||
class="w-full border-b border-neutral-700 bg-neutral-800 p-2 outline-none"
|
||||
class:dropdown-sm-input={variant === 'sm'}
|
||||
bind:value={searchQuery}
|
||||
on:keydown={handleKeyDown}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="scrollbar-thin scrollbar-thumb-neutral-600 scrollbar-track-neutral-700" style="overflow-y: auto; max-height: calc({dropdownMaxHeight} - 3rem);">
|
||||
{#each filteredOptions as option (option.value)}
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => handleSelect(option.value)}
|
||||
class="w-full border-b border-neutral-700 px-3 py-2 text-left last:border-b-0 hover:bg-neutral-600"
|
||||
class:bg-neutral-700={value === option.value}
|
||||
class:dropdown-sm-option={variant === 'sm'}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.dropdown-sm {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.dropdown-sm-btn {
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.dropdown-sm-list {
|
||||
min-width: 160px;
|
||||
}
|
||||
.dropdown-sm-input {
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.dropdown-sm-option {
|
||||
padding-top: 0.15rem;
|
||||
padding-bottom: 0.15rem;
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
</style>
|
||||
@@ -1,14 +0,0 @@
|
||||
<div
|
||||
class="mb-5 max-h-10 w-full border-t border-neutral-800 pt-5 text-center text-sm text-neutral-500"
|
||||
>
|
||||
<a
|
||||
href="https://github.com/whoswhip/Sharpbin"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="text-neutral-400 underline hover:text-neutral-200"
|
||||
>
|
||||
Source Code
|
||||
</a>
|
||||
<span class="mx-1">•</span>
|
||||
v{__APP_VERSION__}
|
||||
</div>
|
||||
@@ -1,545 +0,0 @@
|
||||
<script lang="ts">
|
||||
import QRCode from 'qrcode';
|
||||
import { getRefreshToken, getToken, setTokens } from '$lib/utils/auth';
|
||||
import { parseTotpEnabled } from '$lib/utils/totp';
|
||||
import { tick } from 'svelte';
|
||||
import { extractError } from '$lib/utils/misc';
|
||||
|
||||
export let show = false;
|
||||
export let mode:
|
||||
| 'decrypt'
|
||||
| 'encrypt'
|
||||
| 'confirm'
|
||||
| 'prompt'
|
||||
| 'multiselect'
|
||||
| 'totp'
|
||||
| 'totpSetup'
|
||||
| 'report' = 'decrypt';
|
||||
export let title = '';
|
||||
export let message = '';
|
||||
export let error = '';
|
||||
export let placeholder = '';
|
||||
export let inputType = 'text';
|
||||
export let items: { label: string; value: unknown }[] = [];
|
||||
export let initialValue: unknown = null;
|
||||
export let totpActive: boolean | null = null;
|
||||
export let reportTarget: 'user' | 'paste' | null = null;
|
||||
export let reportTargetId: string | number | null = null;
|
||||
export let reportSiteKey: string | null = null;
|
||||
export let onConfirm: (value: unknown) => void;
|
||||
export let onCancel: () => void;
|
||||
export let confirmButtonText = '';
|
||||
|
||||
let inputValue: string | unknown[] | boolean = '';
|
||||
let totpSecret = '';
|
||||
let totpQr = '';
|
||||
let totpEnabled = false;
|
||||
let totpInitialized = false;
|
||||
let totpLoading = false;
|
||||
let totpError = '';
|
||||
let displayError = '';
|
||||
let reportTypes: string[] = [];
|
||||
let reportType = '';
|
||||
let reportInitialized = false;
|
||||
let reportLoading = false;
|
||||
let turnstileEl: HTMLDivElement | null = null;
|
||||
let turnstileWidgetId: string | null = null;
|
||||
|
||||
const titleMap = {
|
||||
decrypt: 'Enter password to decrypt',
|
||||
encrypt: 'Enter password to encrypt',
|
||||
confirm: 'Confirm action',
|
||||
multiselect: 'Select items',
|
||||
totpSetup: 'Set up two-factor authentication',
|
||||
totp: 'Enter TOTP code',
|
||||
report: 'Create Report',
|
||||
prompt: 'Input Required'
|
||||
};
|
||||
|
||||
const confirmLabelMap = {
|
||||
decrypt: 'Decrypt',
|
||||
encrypt: 'Encrypt',
|
||||
confirm: 'Confirm',
|
||||
multiselect: 'Confirm',
|
||||
totpSetup: totpEnabled ? 'Disable' : 'Enable',
|
||||
totp: 'Verify',
|
||||
report: 'Submit Report',
|
||||
prompt: 'Submit'
|
||||
};
|
||||
|
||||
$: displayError = error || totpError;
|
||||
|
||||
$: if (!show) resetModal();
|
||||
|
||||
$: if (show && mode === 'totpSetup' && !totpInitialized) {
|
||||
totpInitialized = true;
|
||||
if (totpActive !== null) {
|
||||
totpEnabled = totpActive;
|
||||
}
|
||||
initializeTotp();
|
||||
}
|
||||
|
||||
$: if (show && mode === 'report' && !reportInitialized) {
|
||||
reportInitialized = true;
|
||||
initializeReport();
|
||||
}
|
||||
|
||||
function resetModal() {
|
||||
inputValue =
|
||||
initialValue !== null
|
||||
? JSON.parse(JSON.stringify(initialValue))
|
||||
: mode === 'multiselect'
|
||||
? []
|
||||
: '';
|
||||
totpSecret = '';
|
||||
totpQr = '';
|
||||
totpEnabled = false;
|
||||
totpInitialized = false;
|
||||
totpLoading = false;
|
||||
totpError = '';
|
||||
reportTypes = [];
|
||||
reportType = '';
|
||||
reportInitialized = false;
|
||||
reportLoading = false;
|
||||
if (turnstileWidgetId && typeof window !== 'undefined' && window.turnstile?.remove) {
|
||||
window.turnstile.remove(turnstileWidgetId);
|
||||
}
|
||||
turnstileEl = null;
|
||||
turnstileWidgetId = null;
|
||||
}
|
||||
|
||||
function getCodeOrError(message: string) {
|
||||
if (typeof inputValue !== 'string') {
|
||||
totpError = message;
|
||||
return null;
|
||||
}
|
||||
const code = inputValue.trim();
|
||||
if (!code) {
|
||||
totpError = message;
|
||||
return null;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
function onCodeInput(e: Event) {
|
||||
if (!(e.target instanceof HTMLInputElement)) return;
|
||||
const sanitized = e.target.value.replace(/\D/g, '').slice(0, 6);
|
||||
e.target.value = sanitized;
|
||||
inputValue = sanitized;
|
||||
}
|
||||
|
||||
async function initializeTotp() {
|
||||
totpError = '';
|
||||
totpLoading = true;
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
totpError = 'You need to be logged in to manage TOTP.';
|
||||
totpLoading = false;
|
||||
return;
|
||||
}
|
||||
if (totpEnabled || parseTotpEnabled(token)) {
|
||||
totpEnabled = true;
|
||||
totpLoading = false;
|
||||
return;
|
||||
}
|
||||
const res = await fetch('/api/auth/totp/enroll', {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => null);
|
||||
totpError = extractError(data) || 'Failed to start TOTP enrollment.';
|
||||
totpLoading = false;
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
totpSecret = data.secret || '';
|
||||
if (data.otpauth) {
|
||||
totpQr = await QRCode.toDataURL(data.otpauth, { margin: 1, width: 300 });
|
||||
}
|
||||
totpLoading = false;
|
||||
}
|
||||
|
||||
async function initializeReport() {
|
||||
reportLoading = true;
|
||||
error = '';
|
||||
try {
|
||||
const res = await fetch('/api/report/options');
|
||||
if (!res.ok) {
|
||||
reportLoading = false;
|
||||
error = 'Failed to load report options.';
|
||||
return;
|
||||
}
|
||||
const data = (await res.json().catch(() => null)) || {};
|
||||
const types = data.types || data.Types || [];
|
||||
reportTypes = Array.isArray(types) ? types : [];
|
||||
reportType = reportTypes.includes(reportType) ? reportType : reportTypes[0] || '';
|
||||
reportLoading = false;
|
||||
if (reportSiteKey) {
|
||||
await tick();
|
||||
renderTurnstile();
|
||||
}
|
||||
} catch {
|
||||
reportLoading = false;
|
||||
error = 'Failed to load report options.';
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshTokens() {
|
||||
const token = getToken();
|
||||
const refreshToken = getRefreshToken();
|
||||
if (!token || !refreshToken) return null;
|
||||
console.log('Refreshing tokens after TOTP change...');
|
||||
const res = await fetch('/api/auth/refresh', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token, refreshToken })
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json();
|
||||
if (data.token?.token && data.token?.refreshToken && data.token?.success !== false) {
|
||||
setTokens(data.token.token, data.token.refreshToken);
|
||||
console.log('Tokens refreshed after TOTP change.');
|
||||
return data.token.token as string;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (mode === 'report') {
|
||||
await submitReport();
|
||||
return;
|
||||
}
|
||||
if (mode === 'totp') {
|
||||
if (!inputValue || typeof inputValue !== 'string') return;
|
||||
onConfirm(inputValue.trim());
|
||||
return;
|
||||
}
|
||||
if (mode === 'totpSetup') {
|
||||
await submitTotp();
|
||||
return;
|
||||
}
|
||||
onConfirm(mode === 'confirm' ? true : inputValue);
|
||||
}
|
||||
|
||||
function renderTurnstile() {
|
||||
if (!reportSiteKey || typeof window === 'undefined') return;
|
||||
const mount = () => {
|
||||
if (!turnstileEl || !window.turnstile) return;
|
||||
if (turnstileWidgetId && window.turnstile.remove) {
|
||||
window.turnstile.remove(turnstileWidgetId);
|
||||
}
|
||||
turnstileWidgetId = window.turnstile.render(turnstileEl, {
|
||||
sitekey: reportSiteKey,
|
||||
theme: 'dark',
|
||||
size: 'flexible',
|
||||
appearence: 'interaction-only'
|
||||
});
|
||||
};
|
||||
if (window.turnstile) {
|
||||
mount();
|
||||
return;
|
||||
}
|
||||
const existing = document.querySelector('script[data-turnstile="true"]');
|
||||
if (!existing) {
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
|
||||
script.async = true;
|
||||
script.defer = true;
|
||||
script.dataset.turnstile = 'true';
|
||||
script.onload = () => window.dispatchEvent(new Event('turnstile:loaded'));
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
const handler = () => {
|
||||
mount();
|
||||
window.removeEventListener('turnstile:loaded', handler);
|
||||
};
|
||||
window.addEventListener('turnstile:loaded', handler, { once: true });
|
||||
}
|
||||
|
||||
async function submitReport() {
|
||||
error = '';
|
||||
if (!reportTarget || reportTargetId === null) {
|
||||
error = 'Missing report target.';
|
||||
return;
|
||||
}
|
||||
if (typeof inputValue !== 'string') inputValue = '';
|
||||
const description = inputValue.trim();
|
||||
if (!description) {
|
||||
error = 'Description is required.';
|
||||
return;
|
||||
}
|
||||
if (description.length < 12) {
|
||||
error = 'Description must be at least 12 characters.';
|
||||
return;
|
||||
}
|
||||
if (description.length > 1000) {
|
||||
error = 'Description must be 1000 characters or less.';
|
||||
return;
|
||||
}
|
||||
const type = reportType || reportTypes[0] || '';
|
||||
if (!type) {
|
||||
error = 'Select a report type.';
|
||||
return;
|
||||
}
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
error = 'You need to be logged in to report.';
|
||||
return;
|
||||
}
|
||||
const body: Record<string, unknown> = { description, reportType: type };
|
||||
if (reportSiteKey) {
|
||||
if (typeof window === 'undefined' || !window.turnstile) {
|
||||
error = 'Verification unavailable.';
|
||||
return;
|
||||
}
|
||||
const verification = window.turnstile.getResponse();
|
||||
if (!verification) {
|
||||
error = 'Complete verification.';
|
||||
return;
|
||||
}
|
||||
body.VerificationToken = verification;
|
||||
}
|
||||
const targetId = encodeURIComponent(String(reportTargetId));
|
||||
const res = await fetch(`/api/${reportTarget}/${targetId}/report`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => null);
|
||||
error = extractError(data) || 'Failed to submit report.';
|
||||
if (reportSiteKey && typeof window !== 'undefined' && window.turnstile) {
|
||||
window.turnstile.reset();
|
||||
}
|
||||
return;
|
||||
}
|
||||
const data = await res.json().catch(() => null);
|
||||
if (reportSiteKey && typeof window !== 'undefined' && window.turnstile) {
|
||||
window.turnstile.reset();
|
||||
}
|
||||
onConfirm(data || { description, reportType: type });
|
||||
}
|
||||
|
||||
async function submitTotp() {
|
||||
if (totpEnabled) {
|
||||
await disableTotp();
|
||||
return;
|
||||
}
|
||||
if (!totpSecret) {
|
||||
totpError = 'Missing TOTP secret. Please reopen the modal.';
|
||||
return;
|
||||
}
|
||||
const code = getCodeOrError('Enter the TOTP code from your authenticator app.');
|
||||
if (!code) return;
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
totpError = 'You need to be logged in to enable TOTP.';
|
||||
return;
|
||||
}
|
||||
const res = await fetch('/api/auth/totp/enable', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({ secret: totpSecret, code: code })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => null);
|
||||
totpError = data?.message || 'Failed to enable TOTP.';
|
||||
return;
|
||||
}
|
||||
const newToken = await refreshTokens();
|
||||
totpEnabled = parseTotpEnabled(newToken || getToken());
|
||||
onConfirm({ enabled: totpEnabled, secret: totpSecret });
|
||||
}
|
||||
|
||||
async function disableTotp() {
|
||||
const code = getCodeOrError('Enter the TOTP code to disable two-factor authentication.');
|
||||
if (!code) return;
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
totpError = 'You need to be logged in to disable TOTP.';
|
||||
return;
|
||||
}
|
||||
const res = await fetch('/api/auth/totp/disable', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({ code: code })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => null);
|
||||
totpError = data?.message || 'Failed to disable TOTP.';
|
||||
return;
|
||||
}
|
||||
const newToken = await refreshTokens();
|
||||
totpEnabled = parseTotpEnabled(newToken || getToken());
|
||||
onConfirm({ enabled: totpEnabled });
|
||||
}
|
||||
|
||||
async function copySecret() {
|
||||
if (!totpSecret) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(totpSecret);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$: displayTitle = title || titleMap[mode];
|
||||
|
||||
$: confirmLabel = confirmButtonText || confirmLabelMap[mode];
|
||||
$: shouldShowInput =
|
||||
mode !== 'confirm' && mode !== 'multiselect' && mode !== 'totpSetup' && mode !== 'report';
|
||||
</script>
|
||||
|
||||
{#if show}
|
||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm">
|
||||
<form
|
||||
on:submit|preventDefault={handleSubmit}
|
||||
class="w-full max-w-md rounded bg-neutral-900 p-6"
|
||||
>
|
||||
<h2 class="mb-4 text-xl font-semibold text-white">
|
||||
{displayTitle}
|
||||
</h2>
|
||||
|
||||
{#if message}
|
||||
<p class="mb-4 text-neutral-300">
|
||||
{message}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if mode === 'totpSetup'}
|
||||
<div class="mb-4 space-y-3">
|
||||
<div
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-3 text-sm text-neutral-200"
|
||||
>
|
||||
{totpEnabled
|
||||
? 'Two-factor authentication is enabled. Enter a current 6-digit code to disable it.'
|
||||
: 'Scan the QR code with your authenticator app or copy the secret to add it manually.'}
|
||||
</div>
|
||||
{#if totpLoading}
|
||||
<p class="text-neutral-300">Preparing TOTP enrollment...</p>
|
||||
{:else}
|
||||
{#if !totpEnabled}
|
||||
{#if totpQr}
|
||||
<div class="flex justify-center">
|
||||
<img
|
||||
src={totpQr}
|
||||
alt="TOTP QR code"
|
||||
class="aspect-square w-full rounded bg-white object-contain p-2"
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{#if totpSecret}
|
||||
<div
|
||||
class="flex items-center gap-2 rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
>
|
||||
<span class="flex-1 truncate font-mono text-sm text-neutral-100"
|
||||
>{totpSecret}</span
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
on:click={copySecret}
|
||||
class="rounded bg-neutral-700 px-3 py-1 text-sm font-medium text-white transition-colors hover:bg-neutral-800"
|
||||
>
|
||||
Copy
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
<input
|
||||
type="text"
|
||||
bind:value={inputValue}
|
||||
placeholder="Enter the 6-digit code"
|
||||
maxlength="6"
|
||||
inputmode="numeric"
|
||||
pattern="[0-9]*"
|
||||
on:input={onCodeInput}
|
||||
class="w-full rounded border border-neutral-700 bg-neutral-800 p-2 text-white outline-none"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if mode === 'report'}
|
||||
<div class="mb-4 space-y-3">
|
||||
{#if reportLoading}
|
||||
<p class="text-neutral-300">Loading report options...</p>
|
||||
{:else}
|
||||
{#if reportTypes.length}
|
||||
<select
|
||||
bind:value={reportType}
|
||||
class="w-full rounded border border-neutral-700 bg-neutral-800 p-2 text-white outline-none"
|
||||
>
|
||||
{#each reportTypes as type, i (i)}
|
||||
<option value={type}>{type.replace(/([A-Z])/g, ' $1').trim()}</option>
|
||||
{/each}
|
||||
</select>
|
||||
{/if}
|
||||
<textarea
|
||||
bind:value={inputValue}
|
||||
maxlength="1000"
|
||||
placeholder={placeholder || 'Describe the issue'}
|
||||
class="h-28 w-full resize-none rounded border border-neutral-700 bg-neutral-800 p-2 text-white outline-none"
|
||||
></textarea>
|
||||
{#if reportSiteKey}
|
||||
<div class="cf-turnstile w-full" bind:this={turnstileEl}></div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{:else if shouldShowInput}
|
||||
<input
|
||||
type={inputType}
|
||||
bind:value={inputValue}
|
||||
class="mb-3 w-full rounded border border-neutral-700 bg-neutral-800 p-2 text-white outline-none"
|
||||
{placeholder}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if mode === 'multiselect'}
|
||||
<div
|
||||
class="mb-4 max-h-60 overflow-y-auto rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
>
|
||||
{#each items as item (item.label)}
|
||||
<label
|
||||
class="flex cursor-pointer items-center gap-2 rounded p-2 text-white hover:bg-neutral-700"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:group={inputValue}
|
||||
value={item.value}
|
||||
class="h-4 w-4 rounded border-neutral-600 bg-neutral-700 text-neutral-500"
|
||||
/>
|
||||
<span>{item.label}</span>
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if displayError}
|
||||
<div class="mb-3 rounded border border-red-900 bg-red-950 p-2 text-sm text-red-200">
|
||||
{displayError}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
class={`flex-1 cursor-pointer rounded px-4 py-2 font-semibold text-white transition-colors ${
|
||||
mode === 'confirm'
|
||||
? 'bg-red-900 hover:bg-red-800'
|
||||
: 'bg-neutral-700 hover:bg-neutral-800'
|
||||
}`}
|
||||
>
|
||||
{confirmLabel}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
on:click={onCancel}
|
||||
class="cursor-pointer rounded border border-neutral-700 px-4 py-2 text-white hover:bg-neutral-950"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,25 +0,0 @@
|
||||
<script lang="ts">
|
||||
import Modal from '$lib/components/Modal.svelte';
|
||||
import { cancelModal, confirmModal, modal } from '$lib/stores/modal';
|
||||
|
||||
$: state = $modal;
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
show={state.show}
|
||||
mode={state.mode}
|
||||
title={state.title}
|
||||
message={state.message}
|
||||
error={state.error}
|
||||
placeholder={state.placeholder}
|
||||
inputType={state.inputType}
|
||||
items={state.items}
|
||||
initialValue={state.initialValue}
|
||||
totpActive={state.totpActive}
|
||||
reportTarget={state.reportTarget}
|
||||
reportTargetId={state.reportTargetId}
|
||||
reportSiteKey={state.reportSiteKey}
|
||||
confirmButtonText={state.confirmButtonText}
|
||||
onConfirm={(value) => confirmModal(value)}
|
||||
onCancel={() => cancelModal()}
|
||||
/>
|
||||
@@ -1,158 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { user } from '$lib/stores/user';
|
||||
import { resolve } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import { clearTokens } from '$lib/utils/auth';
|
||||
import logo from '$lib/assets/favicon.svg';
|
||||
import type { PageData } from '../../routes/$types';
|
||||
import { slide } from 'svelte/transition';
|
||||
import { Menu, X } from '@lucide/svelte';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
function logout() {
|
||||
clearTokens();
|
||||
user.set(null);
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
let menuOpen = false;
|
||||
|
||||
let currentPath = page.url.pathname;
|
||||
let returnParam =
|
||||
currentPath !== '/' && !currentPath.startsWith('/login') && !currentPath.startsWith('/register')
|
||||
? `?return=${encodeURIComponent(page.url.pathname + page.url.search)}`
|
||||
: '';
|
||||
|
||||
function handleClickOutside(event: MouseEvent) {
|
||||
const navbar = document.getElementById('navbar');
|
||||
const mobileMenu = document.getElementById('mobile-menu');
|
||||
if (menuOpen && mobileMenu && navbar && !navbar.contains(event.target as Node)) {
|
||||
menuOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
document.addEventListener('click', handleClickOutside);
|
||||
return () => {
|
||||
document.removeEventListener('click', handleClickOutside);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="top-0 left-0 z-100 h-15 w-full bg-neutral-900" id="navbar">
|
||||
<div class="mx-auto hidden h-15 w-[95%] max-w-7xl items-center py-2 md:flex">
|
||||
<div>
|
||||
<a href={resolve('/')} class="text-xl font-bold text-white hover:text-neutral-300">Sharpbin</a
|
||||
>
|
||||
<a href={resolve('/recent')} class="ml-6 text-white hover:text-neutral-300">Recent Pastes</a>
|
||||
</div>
|
||||
{#if $user}
|
||||
<div class="ml-auto flex items-center space-x-4">
|
||||
{#if $user.roles.includes(1) || $user.roles.includes(255)}
|
||||
<a
|
||||
href={resolve('/reports')}
|
||||
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Reports</a
|
||||
>
|
||||
{/if}
|
||||
<a
|
||||
href={resolve(`/user/${$user.username}`)}
|
||||
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Profile</a
|
||||
>
|
||||
<button
|
||||
on:click={logout}
|
||||
class="cursor-pointer rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800"
|
||||
>Logout</button
|
||||
>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="ml-auto flex items-center space-x-4">
|
||||
<a
|
||||
href={resolve(`/login${returnParam}`)}
|
||||
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Login</a
|
||||
>
|
||||
<!-- eslint-disable svelte/no-navigation-without-resolve -->
|
||||
<a
|
||||
href={data.options?.registration_enabled ? resolve(`/register${returnParam}`) : '#'}
|
||||
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800 {data.options
|
||||
?.registration_enabled
|
||||
? ''
|
||||
: 'cursor-not-allowed bg-neutral-800 text-neutral-500!'}">Register</a
|
||||
>
|
||||
<!-- eslint-enable svelte/no-navigation-without-resolve -->
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="mx-auto flex h-15 w-[90%] max-w-7xl items-center py-2 md:hidden">
|
||||
<a href={resolve('/')} class="group">
|
||||
<img src={logo} alt="Sharpbin Logo" class="h-8 w-8 group-hover:opacity-80" />
|
||||
</a>
|
||||
<button
|
||||
class="ml-auto flex h-10 w-10 items-center justify-center rounded border border-neutral-700 bg-neutral-800 p-2 hover:bg-neutral-700 focus:outline-none"
|
||||
on:click={() => (menuOpen = !menuOpen)}
|
||||
aria-label="Toggle Menu"
|
||||
aria-expanded={menuOpen}
|
||||
>
|
||||
{#if menuOpen}
|
||||
<X class="pointer-events-none h-6 w-6 text-white" />
|
||||
{:else}
|
||||
<Menu class="pointer-events-none h-6 w-6 text-white" />
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
{#if menuOpen}
|
||||
<div
|
||||
class="mx-auto mb-2 w-full rounded-b border-b border-neutral-800 bg-neutral-900 px-2 py-3 md:hidden"
|
||||
id="mobile-menu"
|
||||
in:slide={{ duration: 180 }}
|
||||
out:slide={{ duration: 180 }}
|
||||
style="z-index:1000;position:relative;"
|
||||
>
|
||||
<a
|
||||
href={resolve('/recent')}
|
||||
class="block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
on:click={() => (menuOpen = false)}>Recent Pastes</a
|
||||
>
|
||||
{#if $user}
|
||||
{#if $user.roles.includes(1) || $user.roles.includes(255)}
|
||||
<a
|
||||
href={resolve('/reports')}
|
||||
class="mt-1 block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
on:click={() => (menuOpen = false)}>Reports</a
|
||||
>
|
||||
{/if}
|
||||
<a
|
||||
href={resolve(`/user/${$user.username}`)}
|
||||
class="mt-1 block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
on:click={() => (menuOpen = false)}>Profile</a
|
||||
>
|
||||
<button
|
||||
on:click={() => {
|
||||
logout();
|
||||
menuOpen = false;
|
||||
}}
|
||||
class="mt-1 w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
>Logout</button
|
||||
>
|
||||
{:else}
|
||||
<a
|
||||
href={resolve(`/login${returnParam}`)}
|
||||
class="mt-1 block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700"
|
||||
on:click={() => (menuOpen = false)}>Login</a
|
||||
>
|
||||
<!-- eslint-disable svelte/no-navigation-without-resolve -->
|
||||
<a
|
||||
href={data.options?.registration_enabled ? resolve(`/register${returnParam}`) : '#'}
|
||||
class="mt-1 block w-full rounded bg-neutral-800 px-3 py-2 text-center text-neutral-100 transition-colors hover:bg-neutral-700 {data
|
||||
.options?.registration_enabled
|
||||
? ''
|
||||
: 'cursor-not-allowed bg-neutral-900 text-neutral-500'}"
|
||||
on:click={() => (menuOpen = false)}>Register</a
|
||||
>
|
||||
<!-- eslint-enable svelte/no-navigation-without-resolve -->
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -1,183 +0,0 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
tooltip,
|
||||
dateToRelativeString,
|
||||
extractDateFromUUIDv7,
|
||||
formatNumber,
|
||||
formatBytes
|
||||
} from '$lib/utils/misc';
|
||||
import { resolve } from '$app/paths';
|
||||
import {
|
||||
Eye,
|
||||
FileBox,
|
||||
Code,
|
||||
User,
|
||||
History,
|
||||
Calendar,
|
||||
Timer,
|
||||
Lock,
|
||||
EyeOff,
|
||||
Globe
|
||||
} from '@lucide/svelte';
|
||||
import { syntaxes } from '$lib/consts';
|
||||
import type { Paste } from '$lib/types/paste';
|
||||
|
||||
export let paste: Paste;
|
||||
export let now: Date;
|
||||
export let showUser: boolean = true;
|
||||
export let compact: boolean = false;
|
||||
|
||||
const createdAt = extractDateFromUUIDv7(paste.uuid);
|
||||
const syntax = syntaxes[paste.syntax] ?? syntaxes['plaintext'];
|
||||
</script>
|
||||
|
||||
{#if compact}
|
||||
<a
|
||||
href={resolve(`/${paste.id}`)}
|
||||
class="flex flex-col gap-1 rounded border border-neutral-700 bg-neutral-800 px-4 py-3 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
>
|
||||
<div class="flex w-full flex-row justify-between">
|
||||
<span
|
||||
class="text-md w-fit max-w-full truncate font-semibold text-neutral-100 hover:text-white"
|
||||
use:tooltip={paste.title || 'Untitled Paste'}
|
||||
>
|
||||
{paste.title || 'Untitled Paste'}
|
||||
</span>
|
||||
<div
|
||||
class="flex items-center gap-2 text-sm text-neutral-400"
|
||||
use:tooltip={`${createdAt?.toLocaleString()} • ${dateToRelativeString(createdAt ?? new Date(), true, false, now)}`}
|
||||
>
|
||||
<Calendar class="h-4 w-4" />
|
||||
{#if createdAt}
|
||||
{#if createdAt.getTime() > Date.now() - 86_400_000}
|
||||
Created {dateToRelativeString(createdAt, true, false, now)}
|
||||
{:else}
|
||||
Created on {createdAt.toLocaleDateString()}
|
||||
{/if}
|
||||
{:else}
|
||||
Creation date unknown
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row justify-between text-sm text-neutral-400">
|
||||
<div>
|
||||
{#if showUser}
|
||||
<div class="flex items-center gap-2">
|
||||
<User class="h-4 w-4" />
|
||||
{paste.author?.username ?? 'Anonymous'}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex items-center gap-2">
|
||||
{#if paste.visibility === 0}
|
||||
<Globe class="h-4 w-4" />
|
||||
Public
|
||||
{:else if paste.visibility === 1}
|
||||
<EyeOff class="h-4 w-4" />
|
||||
Unlisted
|
||||
{:else}
|
||||
<Lock class="h-4 w-4" />
|
||||
Private
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex items-center gap-2">
|
||||
<Eye class="h-4 w-4" />
|
||||
|
||||
{formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
class="flex items-center gap-2"
|
||||
use:tooltip={paste.isCompressed ? `Compressed Size: ${formatBytes(paste.size)}` : ''}
|
||||
>
|
||||
<FileBox class="h-4 w-4" />
|
||||
{formatBytes(paste.trueSize)}
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<Code class="h-4 w-4" />
|
||||
{syntax.name}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{:else}
|
||||
<a
|
||||
href={resolve(`/${paste.id}`)}
|
||||
class="flex flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
>
|
||||
<span
|
||||
class="w-fit max-w-full truncate text-lg font-semibold text-neutral-100 hover:text-white"
|
||||
use:tooltip={paste.title || 'Untitled Paste'}
|
||||
>
|
||||
{paste.title || 'Untitled Paste'}
|
||||
</span>
|
||||
<div class="flex flex-row justify-between">
|
||||
<div>
|
||||
<div
|
||||
class="flex items-center gap-2 text-sm text-neutral-400"
|
||||
use:tooltip={`${createdAt?.toLocaleString()} • ${dateToRelativeString(createdAt ?? new Date(), true, false, now)}`}
|
||||
>
|
||||
<Calendar class="h-4 w-4" />
|
||||
<span>
|
||||
{#if createdAt}
|
||||
{#if createdAt.getTime() > Date.now() - 86_400_000}
|
||||
Created {dateToRelativeString(createdAt, true, false, now)}
|
||||
{:else}
|
||||
Created on {createdAt.toLocaleDateString()}
|
||||
{/if}
|
||||
{:else}
|
||||
Creation date unknown
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
{#if paste.expiresAt > 0}
|
||||
<div
|
||||
class="mt-1 flex items-center gap-2 text-sm text-neutral-400"
|
||||
use:tooltip={new Date(paste.expiresAt).toLocaleString()}
|
||||
>
|
||||
<Timer class="h-4 w-4" />
|
||||
<span>
|
||||
{paste.expiresAt > 0 && paste.expiresAt < Date.now()
|
||||
? `Expired ${dateToRelativeString(new Date(paste.expiresAt), true, false, now)}`
|
||||
: `Expires in ${dateToRelativeString(new Date(paste.expiresAt), true, false, now)}`}
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if showUser}
|
||||
<div class="mt-1 flex items-center gap-2 text-sm text-neutral-400">
|
||||
<User class="h-4 w-4" />
|
||||
<span>{paste.author?.username ?? 'Anonymous'}</span>
|
||||
</div>
|
||||
{/if}
|
||||
{#if paste.editedAt}
|
||||
<div
|
||||
class="mt-1 flex items-center gap-2 text-sm text-neutral-400"
|
||||
use:tooltip={new Date(paste.editedAt).toLocaleString()}
|
||||
>
|
||||
<History class="h-4 w-4" />
|
||||
<span>Edited {dateToRelativeString(new Date(paste.editedAt), true, false, now)}</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div>
|
||||
<div class="flex items-center gap-2 text-sm text-neutral-400">
|
||||
<Eye class="h-4 w-4" />
|
||||
<span>{formatNumber(paste.views)} View{paste.views !== 1 ? 's' : ''}</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-1 flex items-center gap-2 text-sm text-neutral-400"
|
||||
use:tooltip={paste.isCompressed ? `Compressed Size: ${formatBytes(paste.size)}` : ''}
|
||||
>
|
||||
<FileBox class="h-4 w-4" />
|
||||
<span>{formatBytes(paste.trueSize)}</span>
|
||||
</div>
|
||||
<div class="mt-1 flex items-center gap-2 text-sm text-neutral-400">
|
||||
<Code class="h-4 w-4" />
|
||||
<span>{syntax.name}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
{/if}
|
||||
@@ -1,218 +0,0 @@
|
||||
export type Syntax = {
|
||||
name: string;
|
||||
extension: string;
|
||||
};
|
||||
|
||||
export const syntaxes: Record<string, Syntax> = {
|
||||
plaintext: { name: 'Plain Text', extension: '' },
|
||||
abap: { name: 'ABAP', extension: '.abap' },
|
||||
'actionscript-3': { name: 'ActionScript 3', extension: '.as' },
|
||||
ada: { name: 'Ada', extension: '.adb' },
|
||||
apache: { name: 'Apache', extension: '.conf' },
|
||||
apex: { name: 'Apex', extension: '.cls' },
|
||||
apl: { name: 'APL', extension: '.apl' },
|
||||
applescript: { name: 'AppleScript', extension: '.applescript' },
|
||||
ara: { name: 'ARA', extension: '.ara' },
|
||||
asm: { name: 'Assembly', extension: '.asm' },
|
||||
astro: { name: 'Astro', extension: '.astro' },
|
||||
awk: { name: 'AWK', extension: '.awk' },
|
||||
ballerina: { name: 'Ballerina', extension: '.bal' },
|
||||
bat: { name: 'Batch', extension: '.bat' },
|
||||
berry: { name: 'Berry', extension: '.be' },
|
||||
bibtex: { name: 'BibTeX', extension: '.bib' },
|
||||
bicep: { name: 'Bicep', extension: '.bicep' },
|
||||
blade: { name: 'Blade', extension: '.blade.php' },
|
||||
c: { name: 'C', extension: '.c' },
|
||||
cadence: { name: 'Cadence', extension: '.cdc' },
|
||||
clarity: { name: 'Clarity', extension: '.clar' },
|
||||
clojure: { name: 'Clojure', extension: '.clj' },
|
||||
cmake: { name: 'CMake', extension: '.cmake' },
|
||||
cobol: { name: 'COBOL', extension: '.cob' },
|
||||
codeql: { name: 'CodeQL', extension: '.ql' },
|
||||
coffee: { name: 'CoffeeScript', extension: '.coffee' },
|
||||
cpp: { name: 'C++', extension: '.cpp' },
|
||||
crystal: { name: 'Crystal', extension: '.cr' },
|
||||
csharp: { name: 'C#', extension: '.cs' },
|
||||
css: { name: 'CSS', extension: '.css' },
|
||||
csv: { name: 'CSV', extension: '.csv' },
|
||||
cue: { name: 'CUE', extension: '.cue' },
|
||||
d: { name: 'D', extension: '.d' },
|
||||
dart: { name: 'Dart', extension: '.dart' },
|
||||
diff: { name: 'Diff', extension: '.diff' },
|
||||
docker: { name: 'Docker', extension: 'Dockerfile' },
|
||||
'dream-maker': { name: 'Dream Maker', extension: '.dm' },
|
||||
elixir: { name: 'Elixir', extension: '.ex' },
|
||||
elm: { name: 'Elm', extension: '.elm' },
|
||||
erb: { name: 'ERB', extension: '.erb' },
|
||||
erlang: { name: 'Erlang', extension: '.erl' },
|
||||
fish: { name: 'Fish', extension: '.fish' },
|
||||
fsharp: { name: 'F#', extension: '.fs' },
|
||||
gdresource: { name: 'Godot Resource', extension: '.tres' },
|
||||
gdscript: { name: 'GDScript', extension: '.gd' },
|
||||
gdshader: { name: 'Godot Shader', extension: '.gdshader' },
|
||||
gherkin: { name: 'Gherkin', extension: '.feature' },
|
||||
'git-commit': { name: 'Git Commit', extension: '' },
|
||||
'git-rebase': { name: 'Git Rebase', extension: '' },
|
||||
glsl: { name: 'GLSL', extension: '.glsl' },
|
||||
gnuplot: { name: 'Gnuplot', extension: '.gp' },
|
||||
go: { name: 'Go', extension: '.go' },
|
||||
graphql: { name: 'GraphQL', extension: '.graphql' },
|
||||
groovy: { name: 'Groovy', extension: '.groovy' },
|
||||
hack: { name: 'Hack', extension: '.hack' },
|
||||
haml: { name: 'Haml', extension: '.haml' },
|
||||
handlebars: { name: 'Handlebars', extension: '.hbs' },
|
||||
haskell: { name: 'Haskell', extension: '.hs' },
|
||||
hcl: { name: 'HCL', extension: '.hcl' },
|
||||
hjson: { name: 'HJSON', extension: '.hjson' },
|
||||
hlsl: { name: 'HLSL', extension: '.hlsl' },
|
||||
html: { name: 'HTML', extension: '.html' },
|
||||
ini: { name: 'INI', extension: '.ini' },
|
||||
java: { name: 'Java', extension: '.java' },
|
||||
javascript: { name: 'JavaScript', extension: '.js' },
|
||||
jison: { name: 'Jison', extension: '.jison' },
|
||||
json: { name: 'JSON', extension: '.json' },
|
||||
json5: { name: 'JSON5', extension: '.json5' },
|
||||
jsonc: { name: 'JSONC', extension: '.json' },
|
||||
jsonnet: { name: 'Jsonnet', extension: '.jsonnet' },
|
||||
jssm: { name: 'JSSM', extension: '.jssm' },
|
||||
jsx: { name: 'JSX', extension: '.jsx' },
|
||||
julia: { name: 'Julia', extension: '.jl' },
|
||||
kotlin: { name: 'Kotlin', extension: '.kt' },
|
||||
latex: { name: 'LaTeX', extension: '.tex' },
|
||||
less: { name: 'Less', extension: '.less' },
|
||||
liquid: { name: 'Liquid', extension: '.liquid' },
|
||||
lisp: { name: 'Lisp', extension: '.lisp' },
|
||||
logo: { name: 'Logo', extension: '.logo' },
|
||||
lua: { name: 'Lua', extension: '.lua' },
|
||||
makefile: { name: 'Makefile', extension: '.makefile' },
|
||||
markdown: { name: 'Markdown', extension: '.md' },
|
||||
marko: { name: 'Marko', extension: '.marko' },
|
||||
matlab: { name: 'MATLAB', extension: '.m' },
|
||||
mdx: { name: 'MDX', extension: '.mdx' },
|
||||
nginx: { name: 'Nginx', extension: '.conf' },
|
||||
nim: { name: 'Nim', extension: '.nim' },
|
||||
nix: { name: 'Nix', extension: '.nix' },
|
||||
'objective-c': { name: 'Objective-C', extension: '.m' },
|
||||
'objective-cpp': { name: 'Objective-C++', extension: '.mm' },
|
||||
ocaml: { name: 'OCaml', extension: '.ml' },
|
||||
pascal: { name: 'Pascal', extension: '.pas' },
|
||||
perl: { name: 'Perl', extension: '.pl' },
|
||||
php: { name: 'PHP', extension: '.php' },
|
||||
plsql: { name: 'PL/SQL', extension: '.sql' },
|
||||
postcss: { name: 'PostCSS', extension: '.pcss' },
|
||||
powerquery: { name: 'Power Query', extension: '.pq' },
|
||||
powershell: { name: 'PowerShell', extension: '.ps1' },
|
||||
prisma: { name: 'Prisma', extension: '.prisma' },
|
||||
prolog: { name: 'Prolog', extension: '.pl' },
|
||||
proto: { name: 'Protocol Buffers', extension: '.proto' },
|
||||
pug: { name: 'Pug', extension: '.pug' },
|
||||
puppet: { name: 'Puppet', extension: '.pp' },
|
||||
purescript: { name: 'PureScript', extension: '.purs' },
|
||||
python: { name: 'Python', extension: '.py' },
|
||||
r: { name: 'R', extension: '.r' },
|
||||
raku: { name: 'Raku', extension: '.raku' },
|
||||
razor: { name: 'Razor', extension: '.cshtml' },
|
||||
reg: { name: 'Registry', extension: '.reg' },
|
||||
rel: { name: 'Rel', extension: '.rel' },
|
||||
riscv: { name: 'RISC-V', extension: '.s' },
|
||||
rst: { name: 'reStructuredText', extension: '.rst' },
|
||||
ruby: { name: 'Ruby', extension: '.rb' },
|
||||
rust: { name: 'Rust', extension: '.rs' },
|
||||
sas: { name: 'SAS', extension: '.sas' },
|
||||
sass: { name: 'Sass', extension: '.sass' },
|
||||
scala: { name: 'Scala', extension: '.scala' },
|
||||
scheme: { name: 'Scheme', extension: '.scm' },
|
||||
scss: { name: 'SCSS', extension: '.scss' },
|
||||
shaderlab: { name: 'ShaderLab', extension: '.shader' },
|
||||
shell: { name: 'Shell', extension: '.sh' },
|
||||
smalltalk: { name: 'Smalltalk', extension: '.st' },
|
||||
solidity: { name: 'Solidity', extension: '.sol' },
|
||||
sparql: { name: 'SPARQL', extension: '.rq' },
|
||||
sql: { name: 'SQL', extension: '.sql' },
|
||||
'ssh-config': { name: 'SSH Config', extension: '' },
|
||||
stata: { name: 'Stata', extension: '.do' },
|
||||
stylus: { name: 'Stylus', extension: '.styl' },
|
||||
svelte: { name: 'Svelte', extension: '.svelte' },
|
||||
swift: { name: 'Swift', extension: '.swift' },
|
||||
'system-verilog': { name: 'SystemVerilog', extension: '.sv' },
|
||||
tasl: { name: 'TASL', extension: '.tasl' },
|
||||
tcl: { name: 'Tcl', extension: '.tcl' },
|
||||
tex: { name: 'TeX', extension: '.tex' },
|
||||
toml: { name: 'TOML', extension: '.toml' },
|
||||
tsx: { name: 'TSX', extension: '.tsx' },
|
||||
turtle: { name: 'Turtle', extension: '.ttl' },
|
||||
twig: { name: 'Twig', extension: '.twig' },
|
||||
typescript: { name: 'TypeScript', extension: '.ts' },
|
||||
v: { name: 'V', extension: '.v' },
|
||||
vb: { name: 'VB', extension: '.vb' },
|
||||
verilog: { name: 'Verilog', extension: '.v' },
|
||||
vhdl: { name: 'VHDL', extension: '.vhdl' },
|
||||
viml: { name: 'VimL', extension: '.vim' },
|
||||
vue: { name: 'Vue', extension: '.vue' },
|
||||
wasm: { name: 'WebAssembly', extension: '.wasm' },
|
||||
wenyan: { name: 'Wenyan', extension: '.wy' },
|
||||
xml: { name: 'XML', extension: '.xml' },
|
||||
xsl: { name: 'XSL', extension: '.xsl' },
|
||||
yaml: { name: 'YAML', extension: '.yaml' },
|
||||
zenscript: { name: 'ZenScript', extension: '.zs' }
|
||||
};
|
||||
|
||||
export const expiresOptions = [
|
||||
{ value: 0, label: 'Never Expire' },
|
||||
{ value: 30000, label: 'Expire in 5 Minutes' },
|
||||
{ value: 600000, label: 'Expire in 10 Minutes' },
|
||||
{ value: 1800000, label: 'Expire in 30 Minutes' },
|
||||
{ value: 3600000, label: 'Expire in 1 Hour' },
|
||||
{ value: 21600000, label: 'Expire in 6 Hours' },
|
||||
{ value: 43200000, label: 'Expire in 12 Hours' },
|
||||
{ value: 86400000, label: 'Expire in 1 Day' },
|
||||
{ value: 604800000, label: 'Expire in 1 Week' },
|
||||
{ value: 1209600000, label: 'Expire in 2 Weeks' },
|
||||
{ value: 2592000000, label: 'Expire in 1 Month' },
|
||||
{ value: 7776000000, label: 'Expire in 3 Months' },
|
||||
{ value: 15552000000, label: 'Expire in 6 Months' },
|
||||
{ value: 31536000000, label: 'Expire in 1 Year' },
|
||||
{ value: 63072000000, label: 'Expire in 2 Years' },
|
||||
{ value: 157680000000, label: 'Expire in 5 Years' },
|
||||
{ value: 315360000000, label: 'Expire in 10 Years' }
|
||||
];
|
||||
|
||||
export const roles = {
|
||||
0: 'User',
|
||||
1: 'Moderator',
|
||||
255: 'Administrator',
|
||||
403: 'Banned'
|
||||
};
|
||||
|
||||
export const trustedDomains = [
|
||||
'img.youtube.com',
|
||||
'i.ytimg.com',
|
||||
|
||||
'github.com',
|
||||
'githubusercontent.com',
|
||||
'avatars.githubusercontent.com',
|
||||
'camo.githubusercontent.com',
|
||||
'raw.githubusercontent.com',
|
||||
'github.githubassets.com',
|
||||
|
||||
'cdn.discordapp.com',
|
||||
'media.discordapp.net',
|
||||
|
||||
'i.redd.it',
|
||||
'v.redd.it',
|
||||
'external-preview.redd.it',
|
||||
'preview.redd.it',
|
||||
|
||||
'i.imgur.com',
|
||||
'imgur.com',
|
||||
|
||||
'pbs.twimg.com',
|
||||
'video.twimg.com',
|
||||
'twitter.com',
|
||||
'x.com',
|
||||
|
||||
'images.cloudflare.com',
|
||||
'cloudflare-ipfs.com',
|
||||
|
||||
'upload.wikimedia.org'
|
||||
];
|
||||
@@ -1 +0,0 @@
|
||||
// place files you want to import through the `$lib` alias in this folder.
|
||||
@@ -1,83 +0,0 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
type ModalMode =
|
||||
| 'decrypt'
|
||||
| 'encrypt'
|
||||
| 'confirm'
|
||||
| 'prompt'
|
||||
| 'multiselect'
|
||||
| 'totp'
|
||||
| 'totpSetup'
|
||||
| 'report';
|
||||
|
||||
type ModalItem = { label: string; value: unknown };
|
||||
|
||||
type ModalState = {
|
||||
show: boolean;
|
||||
mode: ModalMode;
|
||||
title: string;
|
||||
message: string;
|
||||
error: string;
|
||||
placeholder: string;
|
||||
inputType: string;
|
||||
items: ModalItem[];
|
||||
initialValue: unknown;
|
||||
totpActive: boolean | null;
|
||||
reportTarget: 'user' | 'paste' | null;
|
||||
reportTargetId: string | number | null;
|
||||
reportSiteKey: string | null;
|
||||
confirmButtonText: string;
|
||||
};
|
||||
|
||||
type ModalOpenOptions = Partial<Omit<ModalState, 'show'>> & {
|
||||
mode: ModalMode;
|
||||
cancelValue?: unknown;
|
||||
};
|
||||
|
||||
const initialState: ModalState = {
|
||||
show: false,
|
||||
mode: 'confirm',
|
||||
title: '',
|
||||
message: '',
|
||||
error: '',
|
||||
placeholder: '',
|
||||
inputType: 'text',
|
||||
items: [],
|
||||
initialValue: null,
|
||||
totpActive: null,
|
||||
reportTarget: null,
|
||||
reportTargetId: null,
|
||||
reportSiteKey: null,
|
||||
confirmButtonText: ''
|
||||
};
|
||||
|
||||
let resolver: ((value: unknown) => void) | null = null;
|
||||
let cancelValue: unknown = '';
|
||||
|
||||
export const modal = writable<ModalState>(initialState);
|
||||
|
||||
export function openModal<T = unknown>(options: ModalOpenOptions): Promise<T> {
|
||||
cancelValue = options.cancelValue ?? '';
|
||||
return new Promise<T>((resolve) => {
|
||||
resolver = resolve as (value: unknown) => void;
|
||||
modal.set({
|
||||
...initialState,
|
||||
...options,
|
||||
show: true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function confirmModal(value: unknown) {
|
||||
const resolve = resolver;
|
||||
resolver = null;
|
||||
modal.set(initialState);
|
||||
resolve?.(value);
|
||||
}
|
||||
|
||||
export function cancelModal() {
|
||||
const resolve = resolver;
|
||||
resolver = null;
|
||||
modal.set(initialState);
|
||||
resolve?.(cancelValue);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { browser } from '$app/environment';
|
||||
import type { AuthUser } from '$lib/types/user';
|
||||
|
||||
let initial: AuthUser | null = null;
|
||||
|
||||
if (browser) {
|
||||
try {
|
||||
const stored = localStorage.getItem('user');
|
||||
if (stored) {
|
||||
const parsed = JSON.parse(stored);
|
||||
if (parsed && 'user' in parsed && typeof parsed.user === 'object') {
|
||||
const { user: nestedUser, ...rest } = parsed;
|
||||
initial = { ...rest, ...nestedUser };
|
||||
} else {
|
||||
initial = parsed;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
|
||||
export const user = writable<AuthUser | null>(initial);
|
||||
|
||||
if (browser) {
|
||||
user.subscribe((val) => {
|
||||
if (val) localStorage.setItem('user', JSON.stringify(val));
|
||||
else localStorage.removeItem('user');
|
||||
});
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export interface Author {
|
||||
uid: number;
|
||||
uuid: string;
|
||||
username: string;
|
||||
visibility: 0 | 1 | 2;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
export interface Pagination {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
totalCount: number;
|
||||
totalPages: number;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import type { Author } from './author';
|
||||
|
||||
export interface Paste {
|
||||
id: string;
|
||||
uuid: string;
|
||||
title: string | null;
|
||||
size: number;
|
||||
trueSize: number;
|
||||
isCompressed: boolean;
|
||||
views: number;
|
||||
syntax: string;
|
||||
visibility: 0 | 1 | 2;
|
||||
expiresAt: number;
|
||||
editedAt: number | null;
|
||||
reportCount: number | null;
|
||||
author: Author | null;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import type { Pagination } from './pagination';
|
||||
|
||||
export interface Report {
|
||||
reportID: number;
|
||||
type: number;
|
||||
status: number;
|
||||
description: string | null;
|
||||
createdAt: number;
|
||||
updatedAt: number | null;
|
||||
reporterUUID: string;
|
||||
reporterUsername?: string | null;
|
||||
reporterDisplayName?: string | null;
|
||||
targetType: number;
|
||||
pastePID: number | null;
|
||||
pasteId?: string | null;
|
||||
pasteTitle?: string | null;
|
||||
userUUID: string | null;
|
||||
targetUsername?: string | null;
|
||||
targetDisplayName?: string | null;
|
||||
}
|
||||
|
||||
export interface ReportListResponse {
|
||||
reports: Report[];
|
||||
pagination: Pagination;
|
||||
}
|
||||
|
||||
export const reportTypeLabels = [
|
||||
'Spam',
|
||||
'Abuse',
|
||||
'InappropriateContent',
|
||||
'CopyrightViolation',
|
||||
'Fraud',
|
||||
'Other'
|
||||
] as const;
|
||||
|
||||
export const reportStatusLabels = ['Open', 'InProgress', 'Resolved', 'Closed'] as const;
|
||||
|
||||
export const reportTargetLabels = ['Paste', 'User'] as const;
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { Paste } from './paste';
|
||||
import type { Pagination } from './pagination';
|
||||
|
||||
export interface User {
|
||||
uid: number;
|
||||
uuid: string;
|
||||
username: string;
|
||||
displayName: string | null;
|
||||
email: string | null;
|
||||
lastLogin: number | null;
|
||||
roles: number[];
|
||||
visibility: 0 | 1 | 2;
|
||||
pastes: Paste[] | null;
|
||||
pagination: Pagination | null;
|
||||
}
|
||||
|
||||
export interface AuthUser extends User {
|
||||
totpEnabled: boolean;
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
import { browser } from '$app/environment';
|
||||
import type { Cookies } from '@sveltejs/kit';
|
||||
import { user } from '$lib/stores/user';
|
||||
|
||||
const TOKEN_KEY = 'token';
|
||||
const REFRESH_TOKEN_KEY = 'refreshToken';
|
||||
|
||||
export function getToken() {
|
||||
if (!browser) return null;
|
||||
return (
|
||||
document.cookie
|
||||
.split('; ')
|
||||
.find((c) => c.startsWith(`${TOKEN_KEY}=`))
|
||||
?.split('=')[1] || null
|
||||
);
|
||||
}
|
||||
|
||||
export function getRefreshToken() {
|
||||
if (!browser) return null;
|
||||
return (
|
||||
document.cookie
|
||||
.split('; ')
|
||||
.find((c) => c.startsWith(`${REFRESH_TOKEN_KEY}=`))
|
||||
?.split('=')[1] || null
|
||||
);
|
||||
}
|
||||
|
||||
export function setTokens(token: string, refreshToken: string) {
|
||||
if (!browser) return;
|
||||
console.log('Setting tokens');
|
||||
document.cookie = `${TOKEN_KEY}=${token}; path=/; secure; samesite=strict`;
|
||||
document.cookie = `${REFRESH_TOKEN_KEY}=${refreshToken}; path=/; secure; samesite=strict`;
|
||||
}
|
||||
|
||||
export function clearTokens() {
|
||||
if (!browser) return;
|
||||
console.log('Clearing tokens');
|
||||
document.cookie = `${TOKEN_KEY}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||
document.cookie = `${REFRESH_TOKEN_KEY}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||
user.set(null);
|
||||
}
|
||||
|
||||
export async function refreshTokenIfNeeded() {
|
||||
const token = getToken();
|
||||
const refreshToken = getRefreshToken();
|
||||
if (!token || !refreshToken) return;
|
||||
|
||||
const payload = JSON.parse(atob(token.split('.')[1]));
|
||||
const exp = payload.exp * 1000;
|
||||
const now = Date.now();
|
||||
|
||||
if (exp - now < 2 * 60 * 1000) {
|
||||
console.log('Refreshing token...');
|
||||
const res = await fetch('/api/auth/refresh', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token, refreshToken })
|
||||
});
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (data.success && data.token?.token && data.token?.refreshToken) {
|
||||
console.log('Token refreshed successfully');
|
||||
setTokens(data.token.token, data.token.refreshToken);
|
||||
} else {
|
||||
console.log('Invalid tokens received during refresh');
|
||||
clearTokens();
|
||||
}
|
||||
} else {
|
||||
console.log('Failed to refresh token');
|
||||
clearTokens();
|
||||
}
|
||||
}
|
||||
console.log('Token is still valid, no refresh needed');
|
||||
}
|
||||
|
||||
export function startTokenRefreshInterval() {
|
||||
if (!browser) return;
|
||||
setInterval(refreshTokenIfNeeded, 60 * 1000);
|
||||
}
|
||||
|
||||
export function getServerToken(cookies: Cookies) {
|
||||
return cookies.get('token');
|
||||
}
|
||||
|
||||
export function getServerRefreshToken(cookies: Cookies) {
|
||||
return cookies.get('refreshToken');
|
||||
}
|
||||
|
||||
export function setServerTokens(cookies: Cookies, token: string, refreshToken: string) {
|
||||
cookies.set('token', token, { path: '/', httpOnly: true, sameSite: 'strict', secure: true });
|
||||
cookies.set('refreshToken', refreshToken, {
|
||||
path: '/',
|
||||
httpOnly: true,
|
||||
sameSite: 'strict',
|
||||
secure: true
|
||||
});
|
||||
}
|
||||
|
||||
export function clearServerTokens(cookies: Cookies) {
|
||||
cookies.delete('token', { path: '/' });
|
||||
cookies.delete('refreshToken', { path: '/' });
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
import { argon2id } from 'hash-wasm';
|
||||
|
||||
function toBase64(bytes: Uint8Array): string {
|
||||
let binary = '';
|
||||
const chunkSize = 0x8000;
|
||||
for (let i = 0; i < bytes.length; i += chunkSize) {
|
||||
binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
|
||||
function fromBase64(data: string): Uint8Array {
|
||||
const binary = atob(data);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let i = 0; i < binary.length; i++) {
|
||||
bytes[i] = binary.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
export async function encryptAES(content: string, password: string): Promise<string> {
|
||||
const enc = new TextEncoder();
|
||||
const salt = window.crypto.getRandomValues(new Uint8Array(32));
|
||||
const memorySize = 65536;
|
||||
const iterations = 3;
|
||||
const parallelism = 1;
|
||||
|
||||
const keyMaterial = await argon2id({
|
||||
password,
|
||||
salt,
|
||||
iterations,
|
||||
memorySize,
|
||||
parallelism,
|
||||
hashLength: 32,
|
||||
outputType: 'binary'
|
||||
});
|
||||
|
||||
const key = await window.crypto.subtle.importKey(
|
||||
'raw',
|
||||
keyMaterial as unknown as BufferSource,
|
||||
{ name: 'AES-GCM' },
|
||||
false,
|
||||
['encrypt']
|
||||
);
|
||||
|
||||
const iv = window.crypto.getRandomValues(new Uint8Array(12));
|
||||
const encryptedContent = await window.crypto.subtle.encrypt(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
iv
|
||||
},
|
||||
key,
|
||||
enc.encode(content)
|
||||
);
|
||||
|
||||
const combined = new Uint8Array(salt.byteLength + iv.byteLength + encryptedContent.byteLength);
|
||||
combined.set(salt, 0);
|
||||
combined.set(iv, salt.byteLength);
|
||||
combined.set(new Uint8Array(encryptedContent), salt.byteLength + iv.byteLength);
|
||||
|
||||
return JSON.stringify({
|
||||
version: 4,
|
||||
kdf: 'Argon2id',
|
||||
memorySize,
|
||||
iterations,
|
||||
parallelism,
|
||||
algorithm: 'AES-GCM',
|
||||
saltLength: salt.byteLength,
|
||||
ivLength: iv.byteLength,
|
||||
data: toBase64(combined)
|
||||
});
|
||||
}
|
||||
|
||||
export function estimateEncryptedSize(content: string): number {
|
||||
const rawSize = new TextEncoder().encode(content).length;
|
||||
const combinedSize = rawSize + 60;
|
||||
const b64Size = Math.ceil(combinedSize / 3) * 4;
|
||||
return b64Size + 150;
|
||||
}
|
||||
|
||||
export async function decryptAES(result: string, password: string): Promise<string | null> {
|
||||
try {
|
||||
const enc = new TextEncoder();
|
||||
const parsed = JSON.parse(result);
|
||||
const combined = fromBase64(parsed.data);
|
||||
|
||||
const saltLength = parsed.saltLength || 16;
|
||||
const ivLength = parsed.ivLength || 12;
|
||||
const salt = combined.slice(0, saltLength);
|
||||
const iv = combined.slice(saltLength, saltLength + ivLength);
|
||||
const data = combined.slice(saltLength + ivLength);
|
||||
|
||||
let keyMaterial: ArrayBuffer | Uint8Array;
|
||||
|
||||
if (parsed.kdf === 'Argon2id') {
|
||||
keyMaterial = await argon2id({
|
||||
password,
|
||||
salt,
|
||||
iterations: parsed.iterations,
|
||||
memorySize: parsed.memorySize,
|
||||
parallelism: parsed.parallelism,
|
||||
hashLength: 32,
|
||||
outputType: 'binary'
|
||||
});
|
||||
} else {
|
||||
const baseKey = await window.crypto.subtle.importKey(
|
||||
'raw',
|
||||
enc.encode(password),
|
||||
{ name: 'PBKDF2' },
|
||||
false,
|
||||
['deriveBits', 'deriveKey']
|
||||
);
|
||||
const derivedKey = await window.crypto.subtle.deriveKey(
|
||||
{
|
||||
name: 'PBKDF2',
|
||||
salt,
|
||||
iterations: parsed.iterations,
|
||||
hash: parsed.hash
|
||||
},
|
||||
baseKey,
|
||||
{ name: 'AES-GCM', length: 256 },
|
||||
true,
|
||||
['encrypt', 'decrypt']
|
||||
);
|
||||
keyMaterial = await window.crypto.subtle.exportKey('raw', derivedKey);
|
||||
}
|
||||
|
||||
const key = await window.crypto.subtle.importKey(
|
||||
'raw',
|
||||
keyMaterial as unknown as BufferSource,
|
||||
{ name: 'AES-GCM' },
|
||||
false,
|
||||
['decrypt']
|
||||
);
|
||||
|
||||
const decryptedContent = await window.crypto.subtle.decrypt(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
iv
|
||||
},
|
||||
key,
|
||||
data
|
||||
);
|
||||
|
||||
return new TextDecoder().decode(decryptedContent);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
import { marked } from 'marked';
|
||||
import createDOMPurify from 'dompurify';
|
||||
import type { WindowLike } from 'dompurify';
|
||||
import { trustedDomains } from '$lib/consts';
|
||||
|
||||
const tagMap: Record<string, string> = {
|
||||
IMG: 'image',
|
||||
VIDEO: 'video',
|
||||
AUDIO: 'audio',
|
||||
IFRAME: 'iframe'
|
||||
};
|
||||
|
||||
export async function parseMarkdown(
|
||||
md: string,
|
||||
preventExternal: boolean = true,
|
||||
allowTrustedDomains: boolean = true
|
||||
): Promise<string> {
|
||||
const html = await marked.parse(md);
|
||||
let dom: WindowLike & { document: Document };
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
dom = window as unknown as WindowLike & { document: Document };
|
||||
} else if (import.meta.env.SSR) {
|
||||
const { JSDOM } = await import('jsdom');
|
||||
dom = new JSDOM('').window as unknown as WindowLike & { document: Document };
|
||||
} else {
|
||||
throw new Error('JSDOM should only be loaded on the server');
|
||||
}
|
||||
|
||||
const DOMPurify = createDOMPurify(dom);
|
||||
|
||||
if (preventExternal) {
|
||||
DOMPurify.addHook('afterSanitizeElements', (node) => {
|
||||
if (node.nodeType !== 1) return;
|
||||
const element = node as Element;
|
||||
|
||||
const tag = element.nodeName;
|
||||
if (tag === 'IMG' || tag === 'VIDEO' || tag === 'IFRAME' || tag === 'AUDIO') {
|
||||
const src = element.getAttribute('src');
|
||||
if (!src) return;
|
||||
|
||||
let hostname = 'external server';
|
||||
|
||||
try {
|
||||
hostname = new URL(src).hostname;
|
||||
} catch {
|
||||
//might be a relative url
|
||||
}
|
||||
|
||||
if (allowTrustedDomains && trustedDomains.includes(hostname)) return;
|
||||
|
||||
const placeholder = dom.document.createElement('span');
|
||||
placeholder.className = 'media-placeholder';
|
||||
placeholder.setAttribute(
|
||||
'style',
|
||||
'border: 1px solid #404040; padding: 1rem; margin: 1rem 0; border-radius: 0.5rem; background-color: #1e1e1e; text-align: center; display: block; font-style: normal; color: white; cursor: default; text-decoration: none; user-select: none;'
|
||||
);
|
||||
|
||||
const warning = dom.document.createElement('span');
|
||||
warning.textContent = `External ${tagMap[tag] || tag.toLowerCase()} hidden for privacy.`;
|
||||
warning.setAttribute(
|
||||
'style',
|
||||
'margin-bottom: 0.5rem; font-weight: bold; display: block; text-decoration: none;'
|
||||
);
|
||||
|
||||
const subWarning = dom.document.createElement('span');
|
||||
subWarning.textContent = `Loading this will expose your IP address to ${hostname}.`;
|
||||
subWarning.setAttribute(
|
||||
'style',
|
||||
'font-size: 0.75rem; color: #a3a3a3; margin-bottom: 1rem; display: block; text-decoration: none;'
|
||||
);
|
||||
|
||||
const button = dom.document.createElement('button');
|
||||
button.textContent = `Load ${tagMap[tag] || tag.toLowerCase()}`;
|
||||
button.className = 'load-media-btn';
|
||||
button.setAttribute('data-src', src);
|
||||
button.setAttribute('data-tag', tag.toLowerCase());
|
||||
button.setAttribute(
|
||||
'style',
|
||||
'background-color: #404040; color: white; padding: 0.25rem 0.75rem; border-radius: 0.25rem; cursor: pointer; text-decoration: none;'
|
||||
);
|
||||
|
||||
if (element.getAttribute('alt'))
|
||||
button.setAttribute('data-alt', element.getAttribute('alt') || '');
|
||||
if (element.getAttribute('title'))
|
||||
button.setAttribute('data-title', element.getAttribute('title') || '');
|
||||
if (element.getAttribute('width'))
|
||||
button.setAttribute('data-width', element.getAttribute('width') || '');
|
||||
if (element.getAttribute('height'))
|
||||
button.setAttribute('data-height', element.getAttribute('height') || '');
|
||||
|
||||
placeholder.appendChild(warning);
|
||||
placeholder.appendChild(subWarning);
|
||||
placeholder.appendChild(button);
|
||||
|
||||
const parent = element.parentNode;
|
||||
if (parent && parent.nodeName === 'A') {
|
||||
const anchor = parent as HTMLElement;
|
||||
button.setAttribute('data-href', anchor.getAttribute('href') || '');
|
||||
button.setAttribute('data-target', anchor.getAttribute('target') || '');
|
||||
anchor.parentNode?.replaceChild(placeholder, anchor);
|
||||
} else {
|
||||
element.parentNode?.replaceChild(placeholder, element);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return DOMPurify.sanitize(html);
|
||||
}
|
||||
@@ -1,286 +0,0 @@
|
||||
import { syntaxes } from '$lib/consts';
|
||||
|
||||
export function formatBytes(bytes: number, decimals = 2): string {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
const unit = 1024;
|
||||
const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
|
||||
const exponent = Math.floor(Math.log(bytes) / Math.log(unit));
|
||||
const value = bytes / Math.pow(unit, exponent);
|
||||
|
||||
const unitLabel = value === 1 && exponent === 0 ? 'Byte' : units[exponent];
|
||||
const formattedValue = Number.isInteger(value) ? value : value.toFixed(decimals);
|
||||
|
||||
return `${formattedValue} ${unitLabel}`;
|
||||
}
|
||||
|
||||
export function formatNumber(num: number): string {
|
||||
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
||||
export function extractDateFromUUIDv7(uuid?: string): Date | null {
|
||||
if (!uuid) return null;
|
||||
const hex = uuid.replace(/-/g, '');
|
||||
const timestampHex = hex.slice(0, 12);
|
||||
return new Date(parseInt(timestampHex, 16));
|
||||
}
|
||||
|
||||
export function isBinaryData(buffer: ArrayBuffer | Uint8Array): boolean {
|
||||
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
||||
|
||||
if (bytes.includes(0)) return true;
|
||||
|
||||
try {
|
||||
new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
||||
return false;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function extractError(resData: unknown): string | null {
|
||||
if (!resData || typeof resData !== 'object') return null;
|
||||
|
||||
const data = resData as { errors?: unknown; message?: unknown };
|
||||
|
||||
if (data.errors && typeof data.errors === 'object') {
|
||||
return Object.values(data.errors as Record<string, unknown>)
|
||||
.flat()
|
||||
.filter((v) => typeof v === 'string')
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
if (typeof data.message === 'string') {
|
||||
return data.message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function syntaxFromExtension(extension: string): string | null {
|
||||
const ext = extension.startsWith('.') ? extension.slice(1) : extension;
|
||||
for (const [key, value] of Object.entries(syntaxes)) {
|
||||
if (value.extension === `.${ext}`) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function dateToRelativeString(
|
||||
date: Date,
|
||||
useSuffix = true,
|
||||
full = false,
|
||||
nowArg?: Date,
|
||||
accuracy = 1
|
||||
): string {
|
||||
const now = nowArg ?? new Date();
|
||||
const isFuture = date > now;
|
||||
const suffix = useSuffix ? (isFuture ? 'from now' : 'ago') : '';
|
||||
const diff = Math.abs(now.getTime() - date.getTime());
|
||||
let seconds = Math.floor(diff / 1000);
|
||||
const units = [
|
||||
{ name: 'year', value: 365 * 24 * 60 * 60 },
|
||||
{ name: 'month', value: 30 * 24 * 60 * 60 },
|
||||
{ name: 'week', value: 7 * 24 * 60 * 60 },
|
||||
{ name: 'day', value: 24 * 60 * 60 },
|
||||
{ name: 'hour', value: 60 * 60 },
|
||||
{ name: 'minute', value: 60 },
|
||||
{ name: 'second', value: 1 }
|
||||
];
|
||||
if (!full) {
|
||||
for (const unit of units) {
|
||||
const count = Math.floor(seconds / unit.value);
|
||||
if (count > 0) {
|
||||
return `${count} ${unit.name}${count > 1 ? 's' : ''} ${suffix}`.trim();
|
||||
}
|
||||
}
|
||||
return `0 seconds ${suffix}`.trim();
|
||||
}
|
||||
const parts: string[] = [];
|
||||
let acc = 0;
|
||||
for (const unit of units) {
|
||||
if (acc >= accuracy) break;
|
||||
const count = Math.floor(seconds / unit.value);
|
||||
if (count > 0) {
|
||||
parts.push(`${count} ${unit.name}${count > 1 ? 's' : ''}`);
|
||||
seconds -= count * unit.value;
|
||||
acc++;
|
||||
}
|
||||
}
|
||||
if (parts.length === 0) parts.push('0 seconds');
|
||||
return `${parts.join(', ')} ${suffix}`.trim();
|
||||
}
|
||||
|
||||
export function tooltip(node: HTMLElement, text: string) {
|
||||
let currentText = text ?? '';
|
||||
let tooltipEl: HTMLDivElement | null = null;
|
||||
let caretEl: HTMLDivElement | null = null;
|
||||
let showTimeout: ReturnType<typeof setTimeout>;
|
||||
let hideTimeout: ReturnType<typeof setTimeout>;
|
||||
|
||||
function createTooltip() {
|
||||
if (!currentText || currentText.trim() === '') return;
|
||||
const el = document.createElement('div');
|
||||
el.className =
|
||||
'fixed z-50 rounded bg-neutral-800 px-2 py-1 text-sm text-white shadow-lg opacity-0 transition-opacity duration-150';
|
||||
el.style.maxWidth = '90%';
|
||||
el.style.wordBreak = 'break-word';
|
||||
|
||||
el.addEventListener('mouseover', () => {
|
||||
clearTimeout(hideTimeout);
|
||||
if (tooltipEl) tooltipEl.style.opacity = '1';
|
||||
});
|
||||
el.addEventListener('mouseout', mouseOut);
|
||||
|
||||
const lines = currentText.split('\n');
|
||||
if (lines.length > 1) {
|
||||
el.innerHTML = '';
|
||||
lines.forEach((line, index) => {
|
||||
const span = document.createElement('span');
|
||||
span.textContent = line;
|
||||
el.appendChild(span);
|
||||
if (index < lines.length - 1) el.appendChild(document.createElement('br'));
|
||||
});
|
||||
} else {
|
||||
el.textContent = currentText;
|
||||
}
|
||||
const caret = document.createElement('div');
|
||||
caret.style.position = 'absolute';
|
||||
caret.style.width = '0';
|
||||
caret.style.height = '0';
|
||||
caret.style.left = '50%';
|
||||
caret.style.transform = 'translateX(-50%)';
|
||||
caret.style.pointerEvents = 'none';
|
||||
caretEl = caret;
|
||||
el.appendChild(caret);
|
||||
document.body.appendChild(el);
|
||||
tooltipEl = el;
|
||||
}
|
||||
|
||||
function updateContent() {
|
||||
if (!tooltipEl) return;
|
||||
if (!currentText || currentText.trim() === '') {
|
||||
tooltipEl.remove();
|
||||
tooltipEl = null;
|
||||
caretEl = null;
|
||||
return;
|
||||
}
|
||||
const lines = currentText.split('\n');
|
||||
tooltipEl.innerHTML = '';
|
||||
if (lines.length > 1) {
|
||||
lines.forEach((line, index) => {
|
||||
const span = document.createElement('span');
|
||||
span.textContent = line;
|
||||
tooltipEl?.appendChild(span);
|
||||
if (index < lines.length - 1) tooltipEl?.appendChild(document.createElement('br'));
|
||||
});
|
||||
} else {
|
||||
tooltipEl.textContent = currentText;
|
||||
}
|
||||
if (!caretEl) {
|
||||
const caret = document.createElement('div');
|
||||
caret.style.position = 'absolute';
|
||||
caret.style.width = '0';
|
||||
caret.style.height = '0';
|
||||
caret.style.left = '50%';
|
||||
caret.style.transform = 'translateX(-50%)';
|
||||
caret.style.pointerEvents = 'none';
|
||||
caretEl = caret;
|
||||
tooltipEl.appendChild(caretEl);
|
||||
} else {
|
||||
tooltipEl.appendChild(caretEl);
|
||||
}
|
||||
}
|
||||
|
||||
function positionTooltip() {
|
||||
if (!tooltipEl || !caretEl) return;
|
||||
const rect = node.getBoundingClientRect();
|
||||
const tooltipRect = tooltipEl.getBoundingClientRect();
|
||||
let top = rect.top - tooltipRect.height - 8 + window.scrollY;
|
||||
let left = rect.left + rect.width / 2 - tooltipRect.width / 2 + window.scrollX;
|
||||
let caretOnTop = false;
|
||||
|
||||
if (top < window.scrollY) {
|
||||
top = rect.bottom + 8 + window.scrollY;
|
||||
caretOnTop = true;
|
||||
}
|
||||
if (left < 0) left = 8;
|
||||
if (left + tooltipRect.width > window.innerWidth)
|
||||
left = window.innerWidth - tooltipRect.width - 8;
|
||||
|
||||
tooltipEl.style.top = `${top}px`;
|
||||
tooltipEl.style.left = `${left}px`;
|
||||
tooltipEl.style.position = 'absolute';
|
||||
|
||||
caretEl.style.top = caretOnTop ? '-7px' : '';
|
||||
caretEl.style.bottom = caretOnTop ? '' : '-7px';
|
||||
caretEl.style.borderLeft = '7px solid transparent';
|
||||
caretEl.style.borderRight = '7px solid transparent';
|
||||
if (caretOnTop) {
|
||||
caretEl.style.borderBottom = '7px solid #27272a';
|
||||
caretEl.style.borderTop = '';
|
||||
} else {
|
||||
caretEl.style.borderTop = '7px solid #27272a';
|
||||
caretEl.style.borderBottom = '';
|
||||
}
|
||||
}
|
||||
|
||||
function mouseOver() {
|
||||
clearTimeout(hideTimeout);
|
||||
if (tooltipEl) tooltipEl.style.opacity = '1';
|
||||
showTimeout = setTimeout(() => {
|
||||
if (!tooltipEl) createTooltip();
|
||||
else updateContent();
|
||||
positionTooltip();
|
||||
requestAnimationFrame(() => {
|
||||
if (tooltipEl) tooltipEl.style.opacity = '1';
|
||||
});
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function mouseOut() {
|
||||
clearTimeout(showTimeout);
|
||||
if (tooltipEl) {
|
||||
tooltipEl.style.opacity = '0';
|
||||
hideTimeout = setTimeout(() => {
|
||||
if (tooltipEl) {
|
||||
tooltipEl.remove();
|
||||
tooltipEl = null;
|
||||
caretEl = null;
|
||||
}
|
||||
}, 150);
|
||||
}
|
||||
}
|
||||
|
||||
node.addEventListener('mouseover', mouseOver);
|
||||
node.addEventListener('mouseout', mouseOut);
|
||||
window.addEventListener('scroll', mouseOut, true);
|
||||
window.addEventListener('resize', mouseOut, true);
|
||||
|
||||
return {
|
||||
update(newText: string) {
|
||||
currentText = newText ?? '';
|
||||
if (!currentText || currentText.trim() === '') {
|
||||
if (tooltipEl) {
|
||||
tooltipEl.remove();
|
||||
tooltipEl = null;
|
||||
caretEl = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (tooltipEl) {
|
||||
updateContent();
|
||||
positionTooltip();
|
||||
}
|
||||
},
|
||||
destroy() {
|
||||
node.removeEventListener('mouseover', mouseOver);
|
||||
node.removeEventListener('mouseout', mouseOut);
|
||||
window.removeEventListener('scroll', mouseOut, true);
|
||||
window.removeEventListener('resize', mouseOut, true);
|
||||
if (tooltipEl) tooltipEl.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
export function parseTotpEnabled(tokenValue: string | null) {
|
||||
if (!tokenValue) return false;
|
||||
try {
|
||||
const payload = JSON.parse(atob(tokenValue.split('.')[1]));
|
||||
const flag = payload?.totp_enabled;
|
||||
if (typeof flag === 'string') return flag.toLowerCase() === 'true';
|
||||
return Boolean(flag);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function needsAdminTotp(totpEnabled: boolean, currentRoles: number[], nextRoles: number[]) {
|
||||
if (!totpEnabled) return false;
|
||||
const nextHasAdmin = nextRoles.includes(255);
|
||||
const alreadyAdmin = currentRoles.includes(255);
|
||||
return nextHasAdmin && !alreadyAdmin;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
|
||||
let status = page.status;
|
||||
let error = page.error;
|
||||
let message = error?.message || 'An unexpected error occurred.';
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{status} - Error - Sharpbin</title>
|
||||
<meta name="description" content="An error occurred while processing your request." />
|
||||
</svelte:head>
|
||||
|
||||
<main
|
||||
class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
|
||||
>
|
||||
<div
|
||||
class="w-[95%] max-w-7xl rounded border-2
|
||||
border-neutral-800 bg-neutral-900 p-6 text-center"
|
||||
>
|
||||
<h1 class="mb-4 text-4xl font-bold">Error {status}</h1>
|
||||
<p class="mb-2 text-lg">{message}</p>
|
||||
</div>
|
||||
</main>
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { LayoutServerLoad } from './$types';
|
||||
|
||||
export const load: LayoutServerLoad = async ({ fetch, url }) => {
|
||||
try {
|
||||
const res = await fetch('/api/auth/info');
|
||||
const pasteOptionsRes = await fetch('/api/paste/info');
|
||||
const options = await res.json();
|
||||
const pasteOptions = await pasteOptionsRes.json();
|
||||
return { options, pasteOptions, url: url.href };
|
||||
} catch {
|
||||
return { options: null, pasteOptions: null, url: url.href };
|
||||
}
|
||||
};
|
||||
@@ -1,65 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import './layout.css';
|
||||
import favicon from '$lib/assets/favicon.svg';
|
||||
import Navbar from '$lib/components/Navbar.svelte';
|
||||
import Footer from '$lib/components/Footer.svelte';
|
||||
import ModalHost from '$lib/components/ModalHost.svelte';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { startTokenRefreshInterval, getToken, refreshTokenIfNeeded } from '$lib/utils/auth';
|
||||
import { parseTotpEnabled } from '$lib/utils/totp';
|
||||
import { page } from '$app/state';
|
||||
import type { LayoutData } from './$types';
|
||||
|
||||
export let data: LayoutData;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
startTokenRefreshInterval();
|
||||
window.turnstileLoaded = () => {
|
||||
window.dispatchEvent(new CustomEvent('turnstile:loaded'));
|
||||
};
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
await refreshTokenIfNeeded();
|
||||
const token = getToken();
|
||||
if (!token) {
|
||||
user.set(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await fetch('/api/user/me', {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const me = await res.json();
|
||||
let userData = me;
|
||||
if (me && 'user' in me && typeof me.user === 'object') {
|
||||
const { user: nestedUser, ...rest } = me;
|
||||
userData = { ...rest, ...nestedUser };
|
||||
}
|
||||
user.set({ ...userData, totpEnabled: parseTotpEnabled(getToken()) });
|
||||
} else {
|
||||
user.set(null);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<link rel="icon" href={favicon} />
|
||||
{#if data.options?.cf_turnstile_site_key && (page.url.pathname === '/login' || page.url.pathname === '/register' || page.url.pathname === '/')}
|
||||
<script
|
||||
src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=turnstileLoaded"
|
||||
async
|
||||
defer
|
||||
></script>
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
<Navbar {data} />
|
||||
<!-- <div class="h-15 w-full"></div> -->
|
||||
<slot />
|
||||
<Footer />
|
||||
|
||||
<ModalHost />
|
||||
@@ -1,13 +0,0 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, url }) => {
|
||||
try {
|
||||
const optionsRes = await fetch('/api/paste/info');
|
||||
const authInfo = await fetch('/api/auth/info');
|
||||
const options = await optionsRes.json();
|
||||
const auth = await authInfo.json();
|
||||
return { options, auth, url: url.href };
|
||||
} catch {
|
||||
return { options: null, url: url.href };
|
||||
}
|
||||
};
|
||||
@@ -1,506 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
import { syntaxes, expiresOptions } from '$lib/consts';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { getToken } from '$lib/utils/auth';
|
||||
import { onMount } from 'svelte';
|
||||
import { fly, fade } from 'svelte/transition';
|
||||
import { encryptAES, estimateEncryptedSize } from '$lib/utils/encryption';
|
||||
import {
|
||||
formatBytes,
|
||||
formatNumber,
|
||||
isBinaryData,
|
||||
tooltip,
|
||||
syntaxFromExtension
|
||||
} from '$lib/utils/misc';
|
||||
import { parseMarkdown } from '$lib/utils/markdown';
|
||||
import Dropdown from '$lib/components/Dropdown.svelte';
|
||||
import { SvelteURLSearchParams } from 'svelte/reactivity';
|
||||
import { FileUp, X, Eye, EyeClosed, Dices } from '@lucide/svelte';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
let textArea: HTMLTextAreaElement;
|
||||
let markdownConatiner: HTMLDivElement;
|
||||
|
||||
let error = '';
|
||||
let title = '';
|
||||
let content = '';
|
||||
let selectedSyntax = data.options?.syntaxes?.[0];
|
||||
let expiresIn: number = 0;
|
||||
let selectedVisibility = data.options?.visibilities?.[0]?.value;
|
||||
let password = '';
|
||||
let passwordVisible = false;
|
||||
let anonymousUpload = false;
|
||||
let isDragging = false;
|
||||
let dragError = '';
|
||||
let previewMode = false;
|
||||
let renderedMarkdown = '';
|
||||
|
||||
$: currentByteSize =
|
||||
selectedVisibility === 2
|
||||
? estimateEncryptedSize(content)
|
||||
: new TextEncoder().encode(content).length;
|
||||
|
||||
$: if (selectedSyntax !== 'markdown') {
|
||||
previewMode = false;
|
||||
}
|
||||
|
||||
const MAX_HEIGHT = () => Math.floor((window.innerHeight - 120) * 0.6);
|
||||
|
||||
let previewHeight = 'auto';
|
||||
async function togglePreview(toPreview: boolean) {
|
||||
if (toPreview && !previewMode) {
|
||||
previewHeight = textArea?.style.height || 'auto';
|
||||
renderedMarkdown = await parseMarkdown(content, false);
|
||||
}
|
||||
previewMode = toPreview;
|
||||
requestAnimationFrame(() => resize(previewMode));
|
||||
}
|
||||
|
||||
function resize(markdown: boolean = false) {
|
||||
if ((!markdown && !textArea) || (markdown && !markdownConatiner)) return;
|
||||
|
||||
let h: number;
|
||||
let max: number;
|
||||
let element = markdown ? markdownConatiner : textArea;
|
||||
|
||||
if (!markdown) {
|
||||
textArea.style.height = 'auto';
|
||||
|
||||
h = textArea.scrollHeight;
|
||||
max = MAX_HEIGHT();
|
||||
} else {
|
||||
markdownConatiner.style.height = 'auto';
|
||||
|
||||
h = markdownConatiner.scrollHeight;
|
||||
max = MAX_HEIGHT();
|
||||
}
|
||||
|
||||
if (h > max) {
|
||||
element.style.height = max + 'px';
|
||||
element.style.overflowY = 'auto';
|
||||
} else {
|
||||
element.style.height = h + 'px';
|
||||
element.style.overflowY = 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
resize();
|
||||
const render = () => {
|
||||
if (
|
||||
window.turnstile &&
|
||||
data.options?.requiresVerification &&
|
||||
data.auth?.cf_turnstile_site_key
|
||||
) {
|
||||
window.turnstile.render('.cf-turnstile', {
|
||||
sitekey: data.auth.cf_turnstile_site_key,
|
||||
theme: 'dark',
|
||||
size: 'flexible',
|
||||
appearence: 'interaction-only'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (window.turnstile) {
|
||||
render();
|
||||
} else {
|
||||
window.addEventListener('turnstile:loaded', render, { once: true });
|
||||
}
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('turnstile:loaded', render);
|
||||
};
|
||||
});
|
||||
|
||||
const syntaxOptions =
|
||||
data.options?.syntaxes?.map((lang: string) => ({
|
||||
value: lang,
|
||||
label: syntaxes[lang]?.name ?? lang.charAt(0).toUpperCase() + lang.slice(1)
|
||||
})) ?? [];
|
||||
|
||||
const visibilityOptions =
|
||||
data.options?.visibilities?.map((visibility: { value: number; displayName: string }) => ({
|
||||
value: visibility.value,
|
||||
label: visibility.displayName
|
||||
})) ?? [];
|
||||
|
||||
async function handleSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
const params = new SvelteURLSearchParams({
|
||||
title: title.trim(),
|
||||
syntax: selectedSyntax,
|
||||
visibility: selectedVisibility.toString(),
|
||||
expiresAt: expiresIn > 0 ? (Date.now() + Number(expiresIn)).toString() : '0'
|
||||
});
|
||||
|
||||
if (
|
||||
data.options?.requiresVerification &&
|
||||
data.auth?.cf_turnstile_site_key &&
|
||||
window.turnstile
|
||||
) {
|
||||
const token = window.turnstile.getResponse();
|
||||
if (token) {
|
||||
params.append('token', token);
|
||||
}
|
||||
}
|
||||
|
||||
if (content.trim().length === 0) {
|
||||
error = 'Paste content cannot be empty.';
|
||||
setTimeout(() => {
|
||||
error = '';
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
let body = content;
|
||||
if (selectedVisibility === 2) {
|
||||
body = await encryptAES(content, password);
|
||||
}
|
||||
|
||||
if (
|
||||
data.options?.maxPasteSize &&
|
||||
new TextEncoder().encode(body).length > data.options.maxPasteSize
|
||||
) {
|
||||
error = `Paste exceeds the maximum size limit of ${formatBytes(data.options.maxPasteSize)}. ${selectedVisibility === 2 ? 'Encryption adds some overhead.' : ''}`;
|
||||
setTimeout(() => {
|
||||
error = '';
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
const url = `/api/paste/create?${params.toString()}`;
|
||||
const options: RequestInit = {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
body
|
||||
};
|
||||
|
||||
if ($user && !anonymousUpload) {
|
||||
const token = getToken();
|
||||
if (token) {
|
||||
options.headers = {
|
||||
...options.headers,
|
||||
Authorization: `Bearer ${token}`
|
||||
};
|
||||
}
|
||||
}
|
||||
const response = await fetch(url, options);
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
if (selectedVisibility === 2) {
|
||||
const passwordBase64 = btoa(password);
|
||||
window.location.href = `/${result.id}#${passwordBase64}`;
|
||||
return;
|
||||
}
|
||||
window.location.href = `/${result.id}`;
|
||||
} else {
|
||||
if (window.turnstile) {
|
||||
window.turnstile.reset();
|
||||
}
|
||||
if (response.status === 403) {
|
||||
error = 'You are banned from creating new pastes.';
|
||||
} else {
|
||||
const resData = await response.json();
|
||||
if (resData.errors) {
|
||||
const messages = Object.values(resData.errors).flat();
|
||||
error = messages.join('\n');
|
||||
} else {
|
||||
if (resData.message === 'Verification failed.') {
|
||||
if (window.turnstile) {
|
||||
window.turnstile.reset();
|
||||
}
|
||||
}
|
||||
error = resData.message || 'Registration failed. Please try again.';
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
error = '';
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Create a Paste - Sharpbin</title>
|
||||
<meta property="og:title" content="Create a Paste - Sharpbin" />
|
||||
<meta property="og:description" content="Create and share your pastes easily with Sharpbin." />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:url" content={data.url} />
|
||||
<meta property="og:site_name" content="Sharpbin" />
|
||||
</svelte:head>
|
||||
|
||||
<main
|
||||
class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
|
||||
>
|
||||
<div class="w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
<h1 class="mb-6 text-center text-4xl font-bold">Create a Paste</h1>
|
||||
<form class="mt-4" on:submit|preventDefault={handleSubmit}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Title (optional)"
|
||||
class="mb-4 w-full rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
bind:value={title}
|
||||
maxlength={data.options?.maxTitleLength ?? 500}
|
||||
/>
|
||||
<div>
|
||||
<div class="relative">
|
||||
{#if previewMode}
|
||||
<div
|
||||
class="markdown min-h-20 w-full overflow-y-auto rounded rounded-b-none border border-neutral-700 bg-neutral-800 p-2 transition-colors duration-200"
|
||||
style="height: {previewHeight}"
|
||||
bind:this={markdownConatiner}
|
||||
>
|
||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
||||
{@html renderedMarkdown}
|
||||
</div>
|
||||
{:else}
|
||||
<textarea
|
||||
placeholder="Your paste content here..."
|
||||
class="min-h-20 w-full resize-none overflow-hidden rounded rounded-b-none border border-neutral-700 bg-neutral-800 p-2 transition-colors duration-200"
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
minlength="1"
|
||||
bind:this={textArea}
|
||||
bind:value={content}
|
||||
on:input={() => resize()}
|
||||
on:change={() => resize()}
|
||||
on:focus={() => resize()}
|
||||
on:beforeinput={(e) => {
|
||||
if (!data.options?.maxPasteSize) return;
|
||||
|
||||
const futureSize =
|
||||
selectedVisibility === 2
|
||||
? estimateEncryptedSize(content + (e.data ?? ''))
|
||||
: new TextEncoder().encode(content + (e.data ?? '')).length;
|
||||
|
||||
if (
|
||||
futureSize > data.options.maxPasteSize &&
|
||||
(e.data?.length ?? Number.MAX_SAFE_INTEGER < content.length)
|
||||
) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}}
|
||||
on:dragenter={(e) => {
|
||||
e.preventDefault();
|
||||
isDragging = true;
|
||||
}}
|
||||
on:dragover={(e) => {
|
||||
e.preventDefault();
|
||||
isDragging = true;
|
||||
}}
|
||||
on:dragleave={(e) => {
|
||||
e.preventDefault();
|
||||
isDragging = false;
|
||||
}}
|
||||
on:drop={(e) => {
|
||||
requestAnimationFrame(() => resize());
|
||||
e.preventDefault();
|
||||
isDragging = false;
|
||||
|
||||
const file = e.dataTransfer?.files[0];
|
||||
if (!file) return;
|
||||
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = (e) => {
|
||||
const arrayBuffer = e.target?.result as ArrayBuffer;
|
||||
if (isBinaryData(new Uint8Array(arrayBuffer))) {
|
||||
content = '';
|
||||
dragError =
|
||||
'The dropped file appears to be binary and cannot be pasted as text.';
|
||||
setTimeout(() => {
|
||||
dragError = '';
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
const syntax = syntaxFromExtension(file.name.split('.').pop() || '');
|
||||
if (syntax && selectedSyntax !== syntax) {
|
||||
selectedSyntax = syntax;
|
||||
} else if (!syntax && selectedSyntax !== 'plaintext') {
|
||||
selectedSyntax = 'plaintext';
|
||||
}
|
||||
title = file.name;
|
||||
const decoder = new TextDecoder();
|
||||
content = decoder.decode(arrayBuffer);
|
||||
};
|
||||
|
||||
reader.readAsArrayBuffer(file);
|
||||
}}
|
||||
></textarea>
|
||||
{/if}
|
||||
{#if isDragging || (dragError && dragError !== '')}
|
||||
<div
|
||||
class="pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-md rounded-b-none border-2 border-dashed border-neutral-500 bg-neutral-800/70 text-center text-neutral-300"
|
||||
transition:fade={{ duration: 150 }}
|
||||
>
|
||||
<div class="relative flex h-full w-full items-center justify-center">
|
||||
{#if dragError && dragError !== ''}
|
||||
<div
|
||||
class="absolute flex flex-col items-center gap-4"
|
||||
transition:fly={{ y: -20, duration: 200 }}
|
||||
>
|
||||
<X class="h-12 w-12 text-red-500" />
|
||||
<p>{dragError}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="absolute flex flex-col items-center gap-4"
|
||||
transition:fly={{ y: -20, duration: 200 }}
|
||||
>
|
||||
<FileUp class="h-12 w-12" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="mt-1 flex">
|
||||
{#if selectedSyntax === 'markdown'}
|
||||
<div
|
||||
class="monospace mb-2 flex min-h-full w-36 items-center justify-between gap-1 rounded-bl border border-neutral-700 bg-neutral-800 p-1 text-sm text-neutral-400 md:h-8"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="h-full w-1/2 rounded-l transition-colors {previewMode
|
||||
? 'hover:bg-neutral-700'
|
||||
: 'bg-neutral-700 text-white'}"
|
||||
on:click={() => togglePreview(false)}
|
||||
>
|
||||
Code
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="h-full w-1/2 rounded-r transition-colors {!previewMode
|
||||
? 'hover:bg-neutral-700'
|
||||
: 'bg-neutral-700 text-white'}"
|
||||
on:click={() => togglePreview(true)}
|
||||
>
|
||||
Preview
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
<div
|
||||
class="monospace mb-2 flex h-fit min-h-12 items-center justify-between {selectedSyntax ===
|
||||
'markdown'
|
||||
? 'ml-auto w-[calc(100%-150px)] rounded-br'
|
||||
: 'w-full rounded-b'} border border-neutral-700 bg-neutral-800 p-1 pr-2 pl-2 text-sm text-neutral-400 md:h-8 md:min-h-8"
|
||||
>
|
||||
<div class="flex flex-col md:flex-row md:gap-2">
|
||||
<span>
|
||||
{content.split('\n').length} line{content.split('\n').length !== 1 ? 's' : ''}
|
||||
</span>
|
||||
<span class="hidden text-neutral-600 md:block">•</span>
|
||||
<span>{formatNumber(content.length)} char{content.length !== 1 ? 's' : ''}</span>
|
||||
</div>
|
||||
<div class="flex flex-col text-center md:flex-row md:gap-2">
|
||||
<span
|
||||
class="border-b border-neutral-600 md:border-0"
|
||||
class:text-red-500={currentByteSize > (data.options?.maxPasteSize ?? 0)}
|
||||
>
|
||||
{formatBytes(currentByteSize)}
|
||||
</span>
|
||||
<span class="hidden md:block">/</span>
|
||||
{formatBytes(data.options?.maxPasteSize ?? 0)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 md:gap-2">
|
||||
<Dropdown
|
||||
options={syntaxOptions}
|
||||
bind:value={selectedSyntax}
|
||||
placeholder="Select syntax..."
|
||||
searchable={true}
|
||||
/>
|
||||
<Dropdown
|
||||
options={expiresOptions}
|
||||
bind:value={expiresIn}
|
||||
placeholder="Select expiration..."
|
||||
/>
|
||||
<Dropdown
|
||||
options={visibilityOptions}
|
||||
bind:value={selectedVisibility}
|
||||
placeholder="Select visibility..."
|
||||
/>
|
||||
</div>
|
||||
{#if selectedVisibility === 2}
|
||||
<div class="mb-2 flex w-full">
|
||||
<input
|
||||
type={passwordVisible ? 'text' : 'password'}
|
||||
placeholder="Password for private paste"
|
||||
class="w-[calc(100%-100px)] rounded-l border border-neutral-700 bg-neutral-800 p-2"
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
minlength="6"
|
||||
bind:value={password}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="mr-1 ml-1 flex w-12.5 items-center justify-center border border-neutral-700 bg-neutral-800 p-2 text-neutral-400 hover:bg-neutral-700 active:bg-neutral-600"
|
||||
on:click={() => {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
const bytes = new Uint8Array(16);
|
||||
crypto.getRandomValues(bytes);
|
||||
password = Array.from(bytes, (b) => chars[b % chars.length]).join('');
|
||||
}}
|
||||
use:tooltip={'Generate Random Password'}
|
||||
>
|
||||
<Dices class="h-5 w-5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="flex w-12.5 items-center justify-center rounded-r border border-neutral-700 bg-neutral-800 p-2 text-neutral-400 hover:bg-neutral-700 active:bg-neutral-600"
|
||||
on:click={() => (passwordVisible = !passwordVisible)}
|
||||
>
|
||||
{#if passwordVisible}
|
||||
<EyeClosed class="h-5 w-5" />
|
||||
{:else}
|
||||
<Eye class="h-5 w-5" />
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
{#if $user}
|
||||
<label
|
||||
class="mb-2 flex w-full items-center gap-2 rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={anonymousUpload}
|
||||
class="h-4 w-4 rounded border-neutral-600 bg-neutral-700 text-neutral-500"
|
||||
/>
|
||||
<span>Upload anonymously</span>
|
||||
</label>
|
||||
{/if}
|
||||
{#if data.options?.requiresVerification && data.auth?.cf_turnstile_site_key}
|
||||
<div class="cf-turnstile mb-1 w-full" data-sitekey={data.auth.cf_turnstile_site_key}></div>
|
||||
{/if}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={$user?.roles && $user.roles.includes(403)}
|
||||
class="mb-2 w-full cursor-pointer rounded bg-neutral-700 px-4 py-2 font-semibold text-white transition-colors duration-200 hover:bg-neutral-800 active:bg-neutral-900 disabled:cursor-not-allowed disabled:bg-neutral-950/50 disabled:text-neutral-400"
|
||||
>Create Paste</button
|
||||
>
|
||||
{#if error}
|
||||
<div
|
||||
transition:fly={{ y: 40, duration: 300 }}
|
||||
class="mb-2 rounded border border-red-900 bg-red-950 p-2 text-sm text-red-200"
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
{/if}
|
||||
{#if $user?.roles && $user.roles.includes(403)}
|
||||
<div
|
||||
transition:fly={{ y: 40, duration: 300 }}
|
||||
class="mb-2 rounded border border-red-900 bg-red-950 p-2 text-sm text-red-200"
|
||||
>
|
||||
You are banned from creating new pastes.
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
@@ -1,71 +0,0 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import type { Paste } from '$lib/types/paste';
|
||||
import { getServerToken } from '$lib/utils/auth';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
|
||||
const apiKey =
|
||||
env.NODE_ENV === 'development'
|
||||
? 'cccdd42d9f2f648493e402f1da7c855ea798ad510e6bb9ea712dd7bed838e58'
|
||||
: (env.VIEW_INTERNAL_API_KEY ?? env.View_HMAC_Internal_API_Key ?? '');
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, url, cookies, parent }) => {
|
||||
const { id } = params;
|
||||
const parentData = await parent().catch(() => null);
|
||||
|
||||
const token = getServerToken(cookies);
|
||||
|
||||
const pasteRes = await fetch(`${apiUrl}/api/paste/${id}`, {
|
||||
headers: {
|
||||
Authorization: token ? `Bearer ${token}` : ''
|
||||
}
|
||||
});
|
||||
|
||||
if (pasteRes.status === 404) {
|
||||
throw error(pasteRes.status, 'Paste not found.');
|
||||
}
|
||||
|
||||
const viewed = await fetch(`${apiUrl}/api/paste/${id}/view`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Internal-API-Key': apiKey,
|
||||
Authorization: token ? `Bearer ${token}` : ''
|
||||
}
|
||||
});
|
||||
|
||||
const pasteData = await pasteRes.json();
|
||||
const paste = pasteData.paste as Paste;
|
||||
|
||||
if (viewed.status === 200) {
|
||||
const viewJson = await viewed.json();
|
||||
if (viewJson.success === true && viewJson.message !== 'View already recorded.') {
|
||||
pasteData.views += 1;
|
||||
}
|
||||
} else {
|
||||
console.error(
|
||||
`Failed to increment view count for paste ${id}, status code ${viewed.status}: ${await viewed.text()}`
|
||||
);
|
||||
if (apiKey === '') {
|
||||
console.error(
|
||||
'The API key for internal requests is not set. Please configure it in the environment variables.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const pasteContent = await fetch(`/api/paste/${id}/raw`);
|
||||
const pasteOptions = await fetch('/api/paste/info');
|
||||
const options = await pasteOptions.json();
|
||||
const content = await pasteContent.text();
|
||||
|
||||
return {
|
||||
paste,
|
||||
content,
|
||||
options,
|
||||
authOptions:
|
||||
parentData && typeof parentData === 'object' && parentData !== null && 'options' in parentData
|
||||
? (parentData as { options?: unknown }).options
|
||||
: null,
|
||||
url: url.href
|
||||
};
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
export const GET = () => {
|
||||
return json({ status: 'ok' });
|
||||
};
|
||||
@@ -1,122 +0,0 @@
|
||||
@import 'tailwindcss';
|
||||
@import 'highlight.js/styles/github-dark.css';
|
||||
@plugin 'tailwind-scrollbar';
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--color-neutral-950);
|
||||
}
|
||||
|
||||
body,
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
p,
|
||||
.sans-serif {
|
||||
font-family: 'IBM Plex Sans', sans-serif;
|
||||
}
|
||||
|
||||
pre,
|
||||
code,
|
||||
textarea,
|
||||
option,
|
||||
select,
|
||||
.monospace {
|
||||
font-family: 'Fira Code', monospace;
|
||||
}
|
||||
|
||||
input[type='text'],
|
||||
input[type='email'],
|
||||
input[type='password'],
|
||||
textarea,
|
||||
select {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.markdown > :first-child {
|
||||
margin-top: 0 !important;
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
.markdown h1 {
|
||||
font-size: 2.25rem;
|
||||
font-weight: 700;
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--color-neutral-700);
|
||||
padding-bottom: 0.3rem;
|
||||
}
|
||||
.markdown h2 {
|
||||
font-size: 1.875rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1.25rem;
|
||||
margin-bottom: 0.75rem;
|
||||
border-bottom: 1px solid var(--color-neutral-700);
|
||||
padding-bottom: 0.2rem;
|
||||
}
|
||||
.markdown h3 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.markdown p {
|
||||
margin-bottom: 1rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.markdown ul {
|
||||
list-style-type: disc;
|
||||
margin-left: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.markdown ol {
|
||||
list-style-type: decimal;
|
||||
margin-left: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.markdown li {
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
.markdown a {
|
||||
color: #3b82f6;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.markdown .load-media-btn:hover {
|
||||
background-color: #525252 !important;
|
||||
}
|
||||
.markdown pre {
|
||||
background-color: #1a1a1a;
|
||||
padding: 1rem;
|
||||
border-radius: 0.375rem;
|
||||
margin-bottom: 1rem;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.markdown code {
|
||||
background-color: #1a1a1a;
|
||||
padding: 0.2rem 0.4rem;
|
||||
border-radius: 0.25rem;
|
||||
font-family: monospace;
|
||||
}
|
||||
.markdown blockquote {
|
||||
border-left: 4px solid #404040;
|
||||
padding-left: 1rem;
|
||||
color: #a3a3a3;
|
||||
font-style: italic;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.markdown table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.markdown th,
|
||||
.markdown td {
|
||||
border: 1px solid #404040;
|
||||
padding: 0.5rem;
|
||||
text-align: left;
|
||||
}
|
||||
.markdown th {
|
||||
background-color: #2a2a2a;
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { setTokens, startTokenRefreshInterval } from '$lib/utils/auth';
|
||||
import { extractError } from '$lib/utils/misc';
|
||||
import { onMount } from 'svelte';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
let username = '';
|
||||
let password = '';
|
||||
let error = '';
|
||||
let totpEnabled = false;
|
||||
let totpCode = '';
|
||||
export let data: PageData;
|
||||
|
||||
onMount(() => {
|
||||
const render = () => {
|
||||
if (window.turnstile && data.options?.cf_turnstile_site_key) {
|
||||
window.turnstile.render('.cf-turnstile', {
|
||||
sitekey: data.options.cf_turnstile_site_key,
|
||||
theme: 'dark',
|
||||
size: 'flexible',
|
||||
appearence: 'interaction-only'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (window.turnstile) {
|
||||
render();
|
||||
} else {
|
||||
window.addEventListener('turnstile:loaded', render, { once: true });
|
||||
}
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('turnstile:loaded', render);
|
||||
};
|
||||
});
|
||||
|
||||
async function login() {
|
||||
const body: { username: string; password: string; token?: string; totpcode?: string } = {
|
||||
username,
|
||||
password
|
||||
};
|
||||
|
||||
if (data.options?.cf_turnstile_site_key && window.turnstile) {
|
||||
const token = window.turnstile.getResponse();
|
||||
if (token) {
|
||||
body.token = token;
|
||||
}
|
||||
}
|
||||
|
||||
if (totpEnabled && totpCode) {
|
||||
body.totpcode = totpCode;
|
||||
}
|
||||
|
||||
const res = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (data.token && data.refreshToken) {
|
||||
setTokens(data.token, data.refreshToken);
|
||||
startTokenRefreshInterval();
|
||||
}
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const returnUrl = urlParams.get('return');
|
||||
if (returnUrl) {
|
||||
window.location.href = returnUrl;
|
||||
return;
|
||||
}
|
||||
window.location.href = '/';
|
||||
} else {
|
||||
const resData = await res.json();
|
||||
if (window.turnstile) {
|
||||
window.turnstile.reset();
|
||||
}
|
||||
error = extractError(resData) || 'Login failed. Please try again.';
|
||||
if (error === 'TOTP code is required.') {
|
||||
totpEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Login - Sharpbin</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="Login to your Sharpbin account to manage your pastes and settings."
|
||||
/>
|
||||
</svelte:head>
|
||||
|
||||
<main
|
||||
class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
|
||||
>
|
||||
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
<h1 class="mb-6 text-center text-3xl font-bold">Login</h1>
|
||||
<form on:submit|preventDefault={login} class="space-y-4">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
bind:value={username}
|
||||
autocomplete="username"
|
||||
required
|
||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
bind:value={password}
|
||||
required
|
||||
autocomplete="current-password"
|
||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
{#if totpEnabled}
|
||||
<input
|
||||
type="text"
|
||||
placeholder="TOTP Code"
|
||||
bind:value={totpCode}
|
||||
maxlength="6"
|
||||
inputmode="numeric"
|
||||
pattern="[0-9]*"
|
||||
required
|
||||
on:input={(e) => {
|
||||
if (e.target instanceof HTMLInputElement) {
|
||||
e.target.value = e.target.value.replace(/\D/g, '').slice(0, 6);
|
||||
totpCode = e.target.value;
|
||||
}
|
||||
}}
|
||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
{/if}
|
||||
{#if data.options?.cf_turnstile_site_key}
|
||||
<div class="cf-turnstile w-full"></div>
|
||||
{/if}
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full cursor-pointer rounded bg-neutral-700 px-4 py-2 font-semibold text-white transition-colors duration-200 hover:bg-neutral-800 active:bg-neutral-900"
|
||||
>
|
||||
Login
|
||||
</button>
|
||||
{#if error}
|
||||
<div
|
||||
class="rounded border border-red-900 bg-red-950 p-2 text-sm whitespace-pre-line text-red-200"
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
<p class="mt-4 text-center text-sm text-neutral-400">
|
||||
Don't have an account? <a
|
||||
href={resolve('/register')}
|
||||
class="text-neutral-200 transition-colors duration-200 hover:text-white">Register</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
|
||||
const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
const { id } = params;
|
||||
|
||||
const res = await fetch(`${apiUrl}/api/paste/${id}/raw`);
|
||||
|
||||
if (res.status === 404) {
|
||||
return new Response('Paste not found', { status: 404 });
|
||||
}
|
||||
const content = await res.text();
|
||||
return new Response(content, {
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8'
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import type { Paste } from '$lib/types/paste';
|
||||
import { extractError } from '$lib/utils/misc';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch }) => {
|
||||
try {
|
||||
const res = await fetch('/api/paste/recent');
|
||||
if (!res.ok) {
|
||||
const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.';
|
||||
throw error(res.status, errorMsg);
|
||||
}
|
||||
const recentPastes: Paste[] = await res.json();
|
||||
return { recentPastes };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return { recentPastes: [] };
|
||||
}
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
import { onMount } from 'svelte';
|
||||
import Paste from '$lib/components/Paste.svelte';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
let now = new Date();
|
||||
|
||||
onMount(() => {
|
||||
const interval = setInterval(() => {
|
||||
now = new Date();
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Recent Pastes - Sharpbin</title>
|
||||
<meta name="description" content="Browse the most recent pastes shared on Sharpbin." />
|
||||
</svelte:head>
|
||||
|
||||
<main
|
||||
class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
|
||||
>
|
||||
<div class="w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
{#if data.recentPastes.length === 0}
|
||||
<p class="text-lg">No recent pastes available.</p>
|
||||
{:else}
|
||||
<h1 class="mb-4 text-3xl font-bold">Recent Pastes</h1>
|
||||
<div class="grid grid-cols-1 gap-4">
|
||||
{#each data.recentPastes as paste (paste.uuid)}
|
||||
<Paste {paste} {now} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</main>
|
||||
@@ -1,325 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { setTokens, startTokenRefreshInterval } from '$lib/utils/auth';
|
||||
import { extractError } from '$lib/utils/misc';
|
||||
import { Check, X, Eye, EyeClosed } from '@lucide/svelte';
|
||||
import { slide, fade } from 'svelte/transition';
|
||||
import { resolve } from '$app/paths';
|
||||
import { onMount } from 'svelte';
|
||||
import type { PageData } from './$types';
|
||||
|
||||
let username = '';
|
||||
let password = '';
|
||||
let confirmPassword = '';
|
||||
let email = '';
|
||||
let displayName = '';
|
||||
let error = '';
|
||||
|
||||
let passwordFocused = false;
|
||||
let showPassword = false;
|
||||
1;
|
||||
let passwordChecks = {
|
||||
minLength: false,
|
||||
maxLength: false,
|
||||
upper: false,
|
||||
lower: false,
|
||||
number: false
|
||||
};
|
||||
let passwordValid = false;
|
||||
let loading = false;
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
onMount(() => {
|
||||
const render = () => {
|
||||
if (
|
||||
window.turnstile &&
|
||||
data.options?.cf_turnstile_site_key &&
|
||||
data.options?.registration_enabled
|
||||
) {
|
||||
window.turnstile.render('.cf-turnstile', {
|
||||
sitekey: data.options.cf_turnstile_site_key,
|
||||
theme: 'dark',
|
||||
size: 'flexible',
|
||||
appearence: 'interaction-only'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (window.turnstile) {
|
||||
render();
|
||||
} else {
|
||||
window.addEventListener('turnstile:loaded', render, { once: true });
|
||||
}
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('turnstile:loaded', render);
|
||||
};
|
||||
});
|
||||
|
||||
function validatePassword(pw: string) {
|
||||
passwordChecks.minLength = pw.length >= 8;
|
||||
passwordChecks.maxLength = pw.length <= 128;
|
||||
passwordChecks.upper = /[A-Z]/.test(pw);
|
||||
passwordChecks.lower = /[a-z]/.test(pw);
|
||||
passwordChecks.number = /[0-9]/.test(pw);
|
||||
passwordValid =
|
||||
passwordChecks.minLength &&
|
||||
passwordChecks.maxLength &&
|
||||
passwordChecks.upper &&
|
||||
passwordChecks.lower &&
|
||||
passwordChecks.number;
|
||||
}
|
||||
|
||||
$: validatePassword(password);
|
||||
|
||||
async function register() {
|
||||
if (!passwordValid || password !== confirmPassword) return;
|
||||
loading = true;
|
||||
error = '';
|
||||
const body: Record<string, unknown> = { username, password, email, displayName };
|
||||
if (data.options?.cf_turnstile_site_key && window.turnstile) {
|
||||
const token = window.turnstile.getResponse();
|
||||
if (token) body.token = token;
|
||||
}
|
||||
const res = await fetch('/api/auth/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (data.token && data.refreshToken) {
|
||||
setTokens(data.token, data.refreshToken);
|
||||
startTokenRefreshInterval();
|
||||
goto(resolve('/'));
|
||||
} else {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const returnUrl = urlParams.get('return');
|
||||
if (returnUrl) {
|
||||
goto(resolve(`/login?return=${encodeURIComponent(returnUrl)}`));
|
||||
} else {
|
||||
goto(resolve('/login'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const resData = await res.json();
|
||||
if (window.turnstile) {
|
||||
window.turnstile.reset();
|
||||
}
|
||||
if (resData.errors) {
|
||||
const messages = Object.values(resData.errors).flat();
|
||||
error = messages.join('\n');
|
||||
} else {
|
||||
error = extractError(resData) || 'Registration failed. Please try again.';
|
||||
if (error === 'Verification failed.') {
|
||||
if (window.turnstile) {
|
||||
window.turnstile.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
loading = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Register - Sharpbin</title>
|
||||
<meta
|
||||
name="description"
|
||||
content="Create a new Sharpbin account to manage your pastes and settings."
|
||||
/>
|
||||
</svelte:head>
|
||||
|
||||
<main
|
||||
class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
|
||||
>
|
||||
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
<h1 class="mb-6 text-center text-3xl font-bold">Register</h1>
|
||||
{#if data.options?.registration_enabled === false}
|
||||
<div
|
||||
class="mb-4 rounded border border-yellow-600/80 bg-yellow-600/40 p-2 text-sm text-yellow-200"
|
||||
>
|
||||
Registration is currently disabled.
|
||||
</div>
|
||||
{/if}
|
||||
<form on:submit|preventDefault={register} class="space-y-4">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
bind:value={username}
|
||||
autocomplete="username"
|
||||
required
|
||||
disabled={loading || !data.options?.registration_enabled}
|
||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
<div>
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Email (optional)"
|
||||
bind:value={email}
|
||||
autocomplete="email"
|
||||
disabled={loading || !data.options?.registration_enabled}
|
||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Display Name (optional)"
|
||||
bind:value={displayName}
|
||||
autocomplete="name"
|
||||
disabled={loading || !data.options?.registration_enabled}
|
||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex w-full">
|
||||
<input
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
placeholder="Password"
|
||||
bind:value={password}
|
||||
required
|
||||
on:focus={() => (passwordFocused = true)}
|
||||
on:blur={() => (passwordFocused = false)}
|
||||
autocomplete="new-password"
|
||||
disabled={loading || !data.options?.registration_enabled}
|
||||
class="focus:bg-neutral-750 w-[calc(100%-40px)] rounded-l border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => (showPassword = !showPassword)}
|
||||
disabled={loading || !data.options?.registration_enabled}
|
||||
class="ml-2 flex w-10 items-center rounded-r border border-neutral-700 bg-neutral-800 p-2 transition-colors duration-200 hover:bg-neutral-700 focus:outline-none"
|
||||
>
|
||||
{#if showPassword}
|
||||
<EyeClosed class="h-5 w-5 text-neutral-400" />
|
||||
{:else}
|
||||
<Eye class="h-5 w-5 text-neutral-400" />
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{#if passwordFocused}
|
||||
<ul
|
||||
transition:slide
|
||||
class="space-y-2 rounded border border-neutral-700 bg-neutral-800 p-3 text-sm"
|
||||
>
|
||||
<li
|
||||
class="flex items-center gap-2 {passwordChecks.minLength
|
||||
? 'text-green-400'
|
||||
: 'text-red-400'}"
|
||||
>
|
||||
{#if passwordChecks.minLength}
|
||||
<Check class="h-4 w-4" />
|
||||
{:else}
|
||||
<X class="h-4 w-4" />
|
||||
{/if}
|
||||
At least 8 characters
|
||||
</li>
|
||||
<li
|
||||
class="flex items-center gap-2 {passwordChecks.maxLength
|
||||
? 'text-green-400'
|
||||
: 'text-red-400'}"
|
||||
>
|
||||
{#if passwordChecks.maxLength}
|
||||
<Check class="h-4 w-4" />
|
||||
{:else}
|
||||
<X class="h-4 w-4" />
|
||||
{/if}
|
||||
No more than 128 characters
|
||||
</li>
|
||||
<li
|
||||
class="flex items-center gap-2 {passwordChecks.upper
|
||||
? 'text-green-400'
|
||||
: 'text-red-400'}"
|
||||
>
|
||||
{#if passwordChecks.upper}
|
||||
<Check class="h-4 w-4" />
|
||||
{:else}
|
||||
<X class="h-4 w-4" />
|
||||
{/if}
|
||||
At least one uppercase letter
|
||||
</li>
|
||||
<li
|
||||
class="flex items-center gap-2 {passwordChecks.lower
|
||||
? 'text-green-400'
|
||||
: 'text-red-400'}"
|
||||
>
|
||||
{#if passwordChecks.lower}
|
||||
<Check class="h-4 w-4" />
|
||||
{:else}
|
||||
<X class="h-4 w-4" />
|
||||
{/if}
|
||||
At least one lowercase letter
|
||||
</li>
|
||||
<li
|
||||
class="flex items-center gap-2 {passwordChecks.number
|
||||
? 'text-green-400'
|
||||
: 'text-red-400'}"
|
||||
>
|
||||
{#if passwordChecks.number}
|
||||
<Check class="h-4 w-4" />
|
||||
{:else}
|
||||
<X class="h-4 w-4" />
|
||||
{/if}
|
||||
At least one number
|
||||
</li>
|
||||
</ul>
|
||||
{/if}
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Confirm Password"
|
||||
bind:value={confirmPassword}
|
||||
required
|
||||
autocomplete="new-password"
|
||||
disabled={loading || !data.options?.registration_enabled}
|
||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||
/>
|
||||
|
||||
{#if confirmPassword && password !== confirmPassword}
|
||||
<div
|
||||
transition:fade
|
||||
class="rounded border border-red-900 bg-red-950 p-2 text-sm text-red-200"
|
||||
>
|
||||
Passwords do not match.
|
||||
</div>
|
||||
{/if}
|
||||
{#if data.options?.cf_turnstile_site_key && data.options?.registration_enabled}
|
||||
<div class="cf-turnstile w-full"></div>
|
||||
{/if}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={!passwordValid ||
|
||||
password !== confirmPassword ||
|
||||
loading ||
|
||||
!data.options?.registration_enabled}
|
||||
class="w-full cursor-pointer rounded bg-neutral-700 px-4 py-2 font-semibold text-white transition-colors duration-200 hover:bg-neutral-800 active:bg-neutral-900"
|
||||
>
|
||||
{loading ? 'Registering...' : 'Register'}
|
||||
</button>
|
||||
{#if error}
|
||||
<div class="rounded border border-red-900 bg-red-950 p-2 text-sm text-red-200">
|
||||
{error}
|
||||
</div>
|
||||
{/if}
|
||||
</form>
|
||||
<p class="mt-4 text-center text-sm text-neutral-400">
|
||||
Already have an account? <a
|
||||
href={resolve('/login')}
|
||||
class="text-neutral-200 transition-colors duration-200 hover:text-white">Login</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
*:disabled {
|
||||
cursor: not-allowed;
|
||||
background-color: var(--color-neutral-800);
|
||||
color: var(--color-neutral-600) !important;
|
||||
border: none;
|
||||
}
|
||||
*:disabled::placeholder {
|
||||
color: var(--color-neutral-600) !important;
|
||||
}
|
||||
</style>
|
||||
@@ -1,43 +0,0 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { getServerToken } from '$lib/utils/auth';
|
||||
import type { Report } from '$lib/types/report';
|
||||
|
||||
const API_URL = env.VITE_API_URL ?? 'http://localhost:5050';
|
||||
|
||||
function decodeJwtRoles(token?: string | null): number[] {
|
||||
try {
|
||||
if (!token) return [];
|
||||
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
||||
const roles = payload?.role;
|
||||
if (Array.isArray(roles)) {
|
||||
return roles.map((r: string) => parseInt(r, 10)).filter((r: number) => !isNaN(r));
|
||||
}
|
||||
return [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, cookies, params, url }) => {
|
||||
const token = getServerToken(cookies);
|
||||
if (!token) throw error(401, 'Login required');
|
||||
const roles = decodeJwtRoles(token);
|
||||
const canEdit = roles.includes(1) || roles.includes(255);
|
||||
|
||||
const res = await fetch(`${API_URL}/api/report/${params.reportId}`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const { message } = await res.json().catch(() => ({}));
|
||||
throw error(res.status, message ?? 'Request failed');
|
||||
}
|
||||
|
||||
const report = (await res.json()) as Report;
|
||||
const optionsRes = await fetch(`${API_URL}/api/report/options`);
|
||||
const options = optionsRes.ok ? await optionsRes.json() : { types: [], statuses: [] };
|
||||
|
||||
return { report, url: url.href, canEdit, options };
|
||||
};
|
||||
@@ -1,165 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
import { resolve } from '$app/paths';
|
||||
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
|
||||
import { tooltip } from '$lib/utils/misc';
|
||||
import { getToken } from '$lib/utils/auth';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
const report = data.report;
|
||||
let saving = false;
|
||||
let saveError = '';
|
||||
const statusOptions = data.options?.statuses ?? [];
|
||||
const typeOptions = data.options?.types ?? [];
|
||||
let statusValue = reportStatusLabels[report.status] ?? '';
|
||||
let typeValue = reportTypeLabels[report.type] ?? '';
|
||||
|
||||
async function updateReport() {
|
||||
saveError = '';
|
||||
saving = true;
|
||||
const token = getToken();
|
||||
const res = await fetch(`/api/report/${report.reportID}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {})
|
||||
},
|
||||
body: JSON.stringify({ status: statusValue, type: typeValue })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const { message } = await res.json().catch(() => ({}));
|
||||
saveError = message ?? 'Failed to update report.';
|
||||
saving = false;
|
||||
return;
|
||||
}
|
||||
const updated = await res.json();
|
||||
report.status = updated.status ?? report.status;
|
||||
report.type = updated.type ?? report.type;
|
||||
report.updatedAt = updated.updatedAt ?? report.updatedAt;
|
||||
report.description = updated.description ?? report.description;
|
||||
saving = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Report #{report.reportID} - Sharpbin</title>
|
||||
</svelte:head>
|
||||
|
||||
<main
|
||||
class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
|
||||
>
|
||||
<div class="mx-auto w-[95%] max-w-4xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
<h1 class="mb-6 text-center text-3xl font-bold">Report #{report.reportID}</h1>
|
||||
<div class="space-y-4">
|
||||
<div class="flex flex-wrap items-center gap-3 text-neutral-300">
|
||||
<span class="rounded bg-neutral-800 px-3 py-1">
|
||||
{reportTypeLabels[report.type] ?? 'Other'}
|
||||
</span>
|
||||
<span class="rounded bg-neutral-800 px-3 py-1">
|
||||
{reportStatusLabels[report.status] ?? 'Open'}
|
||||
</span>
|
||||
<span class="rounded bg-neutral-800 px-3 py-1">
|
||||
{reportTargetLabels[report.targetType] ?? 'Unknown'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2 text-sm text-neutral-400">
|
||||
<div>
|
||||
Reporter:
|
||||
{#if report.reporterUsername}
|
||||
<a
|
||||
class="text-neutral-200 hover:text-white hover:underline"
|
||||
href={resolve(`/user/${report.reporterUsername}`)}
|
||||
use:tooltip={report.reporterUUID}
|
||||
>
|
||||
{report.reporterDisplayName || report.reporterUsername}
|
||||
</a>
|
||||
{:else}
|
||||
<span>{report.reporterUUID}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if report.pasteId}
|
||||
<div>
|
||||
Target Paste:
|
||||
<a
|
||||
class="text-neutral-200 hover:text-white hover:underline"
|
||||
href={resolve(`/${report.pasteId}`)}
|
||||
>
|
||||
{report.pasteTitle !== '' ? report.pasteTitle : report.pasteId}
|
||||
</a>
|
||||
</div>
|
||||
{/if}
|
||||
{#if report.userUUID}
|
||||
<div>
|
||||
Target User:
|
||||
{#if report.targetUsername}
|
||||
<a
|
||||
class="text-neutral-200 hover:text-white hover:underline"
|
||||
href={resolve(`/user/${report.targetUsername}`)}
|
||||
use:tooltip={report.userUUID}
|
||||
>
|
||||
{report.targetDisplayName || report.targetUsername}
|
||||
</a>
|
||||
{:else}
|
||||
<span>{report.userUUID}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div>Created: {new Date(report.createdAt * 1000).toLocaleString()}</div>
|
||||
{#if report.updatedAt}
|
||||
<div>Updated: {new Date(report.updatedAt * 1000).toLocaleString()}</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if data.canEdit}
|
||||
<div class="mt-4 space-y-3">
|
||||
<div class="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="text-sm text-neutral-400" for="report-update-type">Type</label>
|
||||
<select
|
||||
id="report-update-type"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
bind:value={typeValue}
|
||||
>
|
||||
{#each typeOptions as t (t)}
|
||||
<option value={t}>{t}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="text-sm text-neutral-400" for="report-update-status">Status</label>
|
||||
<select
|
||||
id="report-update-status"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
bind:value={statusValue}
|
||||
>
|
||||
{#each statusOptions as s (s)}
|
||||
<option value={s}>{s}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600 disabled:opacity-60"
|
||||
on:click={updateReport}
|
||||
disabled={saving}
|
||||
>
|
||||
{saving ? 'Saving...' : 'Update Report'}
|
||||
</button>
|
||||
{#if saveError}
|
||||
<span class="text-sm text-red-300">{saveError}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if report.description}
|
||||
<div class="rounded border border-neutral-700 bg-neutral-800 p-4 text-neutral-200">
|
||||
{report.description}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
@@ -1,71 +0,0 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { getServerToken } from '$lib/utils/auth';
|
||||
import type { ReportListResponse } from '$lib/types/report';
|
||||
import { extractError } from '$lib/utils/misc';
|
||||
|
||||
const API_URL = env.VITE_API_URL ?? 'http://localhost:5050';
|
||||
|
||||
function decodeJwtRoles(token?: string | null): number[] {
|
||||
try {
|
||||
if (!token) return [];
|
||||
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
||||
const roles = payload?.role;
|
||||
if (Array.isArray(roles)) {
|
||||
return roles.map((r: string) => parseInt(r, 10)).filter((r: number) => !isNaN(r));
|
||||
}
|
||||
return [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeTarget(value: string | null): 'all' | 'pastes' | 'users' {
|
||||
if (value === 'pastes' || value === 'users') return value;
|
||||
return 'all';
|
||||
}
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, cookies, url }) => {
|
||||
const token = getServerToken(cookies);
|
||||
if (!token) throw error(401, 'Login required');
|
||||
|
||||
const roles = decodeJwtRoles(token);
|
||||
if (!roles.includes(1) && !roles.includes(255)) {
|
||||
throw error(403, 'You do not have permission to view reports.');
|
||||
}
|
||||
|
||||
const target = normalizeTarget(url.searchParams.get('target'));
|
||||
const status = url.searchParams.get('status') ?? '';
|
||||
const type = url.searchParams.get('type') ?? '';
|
||||
const pasteId = url.searchParams.get('pasteId') ?? '';
|
||||
const userUuid = url.searchParams.get('userUuid') ?? '';
|
||||
const pageParam = Number(url.searchParams.get('page') ?? '1');
|
||||
const page = Number.isFinite(pageParam) ? Math.max(1, pageParam) : 1;
|
||||
|
||||
const query = new URLSearchParams({ page: String(page), pageSize: '20' });
|
||||
if (status) query.set('status', status);
|
||||
if (type) query.set('type', type);
|
||||
if ((target === 'pastes' || target === 'all') && pasteId) query.set('pasteId', pasteId);
|
||||
if ((target === 'users' || target === 'all') && userUuid) query.set('userUUID', userUuid);
|
||||
|
||||
const reportsRes = await fetch(`${API_URL}/api/report/${target}?${query.toString()}`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (!reportsRes.ok) {
|
||||
const json = await reportsRes.json().catch(() => ({}));
|
||||
throw error(reportsRes.status, extractError(json) ?? 'Request failed');
|
||||
}
|
||||
|
||||
const reports = (await reportsRes.json()) as ReportListResponse;
|
||||
|
||||
const optionsRes = await fetch(`${API_URL}/api/report/options`);
|
||||
const options = optionsRes.ok ? await optionsRes.json() : { types: [], statuses: [] };
|
||||
|
||||
return {
|
||||
reports,
|
||||
options,
|
||||
filters: { target, status, type, pasteId, userUuid, page }
|
||||
};
|
||||
};
|
||||
@@ -1,272 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
import { resolve } from '$app/paths';
|
||||
import { goto } from '$app/navigation';
|
||||
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
|
||||
import { tooltip } from '$lib/utils/misc';
|
||||
import { SvelteURLSearchParams } from 'svelte/reactivity';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
let target = data.filters.target;
|
||||
let status = data.filters.status;
|
||||
let type = data.filters.type ?? '';
|
||||
let pasteId = data.filters.pasteId;
|
||||
let userUuid = data.filters.userUuid;
|
||||
let mixedTarget = target === 'all' ? pasteId || userUuid : '';
|
||||
let inputTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const targets = [
|
||||
{ value: 'all', label: 'All' },
|
||||
{ value: 'pastes', label: 'Pastes' },
|
||||
{ value: 'users', label: 'Users' }
|
||||
];
|
||||
|
||||
const statuses = data.options?.statuses ?? [];
|
||||
const types = data.options?.types ?? [];
|
||||
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
function applyFilters(page = 1) {
|
||||
const params = new SvelteURLSearchParams();
|
||||
params.set('target', target);
|
||||
if (status) params.set('status', status);
|
||||
if (type) params.set('type', type);
|
||||
if (target === 'pastes' && pasteId.trim()) params.set('pasteId', pasteId.trim());
|
||||
if (target === 'users' && userUuid.trim()) params.set('userUuid', userUuid.trim());
|
||||
if (target === 'all' && pasteId.trim()) params.set('pasteId', pasteId.trim());
|
||||
if (target === 'all' && userUuid.trim()) params.set('userUuid', userUuid.trim());
|
||||
params.set('page', String(page));
|
||||
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
||||
goto(`?${params.toString()}`);
|
||||
}
|
||||
|
||||
function scheduleInputApply() {
|
||||
if (inputTimer) clearTimeout(inputTimer);
|
||||
inputTimer = setTimeout(() => applyFilters(1), 300);
|
||||
}
|
||||
|
||||
function handleTargetChange(value: string) {
|
||||
target = value as 'all' | 'pastes' | 'users';
|
||||
if (target === 'all') {
|
||||
mixedTarget = pasteId || userUuid;
|
||||
applyFilters(1);
|
||||
return;
|
||||
}
|
||||
if (target === 'pastes') {
|
||||
userUuid = '';
|
||||
mixedTarget = '';
|
||||
applyFilters(1);
|
||||
return;
|
||||
}
|
||||
pasteId = '';
|
||||
mixedTarget = '';
|
||||
applyFilters(1);
|
||||
}
|
||||
|
||||
function handleTargetInput(value: string) {
|
||||
if (target === 'pastes') {
|
||||
pasteId = value;
|
||||
userUuid = '';
|
||||
scheduleInputApply();
|
||||
return;
|
||||
}
|
||||
if (target === 'users') {
|
||||
userUuid = value;
|
||||
pasteId = '';
|
||||
scheduleInputApply();
|
||||
return;
|
||||
}
|
||||
mixedTarget = value;
|
||||
const trimmed = value.trim();
|
||||
if (uuidRegex.test(trimmed)) {
|
||||
userUuid = trimmed;
|
||||
pasteId = '';
|
||||
} else if (/^\d+$/.test(trimmed)) {
|
||||
pasteId = trimmed;
|
||||
userUuid = '';
|
||||
} else {
|
||||
pasteId = '';
|
||||
userUuid = '';
|
||||
}
|
||||
scheduleInputApply();
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Reports - Sharpbin</title>
|
||||
</svelte:head>
|
||||
|
||||
<main
|
||||
class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
|
||||
>
|
||||
<div class="mx-auto w-[95%] max-w-6xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
<h1 class="mb-6 text-center text-4xl font-bold">Reports</h1>
|
||||
<div class="mb-6 grid grid-cols-1 gap-4 md:grid-cols-5">
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="text-sm text-neutral-400" for="report-target">Target</label>
|
||||
<select
|
||||
id="report-target"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
bind:value={target}
|
||||
on:change={(e) => {
|
||||
if (e.currentTarget instanceof HTMLSelectElement) {
|
||||
handleTargetChange(e.currentTarget.value);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{#each targets as t (t.value)}
|
||||
<option value={t.value}>{t.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="text-sm text-neutral-400" for="report-status">Status</label>
|
||||
<select
|
||||
id="report-status"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
bind:value={status}
|
||||
on:change={() => applyFilters(1)}
|
||||
>
|
||||
<option value="">Any</option>
|
||||
{#each statuses as s (s)}
|
||||
<option value={s}>{s}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="text-sm text-neutral-400" for="report-type">Type</label>
|
||||
<select
|
||||
id="report-type"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
bind:value={type}
|
||||
on:change={() => applyFilters(1)}
|
||||
>
|
||||
<option value="">Any</option>
|
||||
{#each types as t (t)}
|
||||
<option value={t}>{t}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 md:col-span-2">
|
||||
<label class="text-sm text-neutral-400" for="report-target-id">
|
||||
{target === 'pastes'
|
||||
? 'Paste ID'
|
||||
: target === 'users'
|
||||
? 'User UUID'
|
||||
: 'Paste ID or User UUID'}
|
||||
</label>
|
||||
<input
|
||||
id="report-target-id"
|
||||
type="text"
|
||||
class="rounded border border-neutral-700 bg-neutral-800 p-2"
|
||||
placeholder={target === 'pastes'
|
||||
? 'Paste ID'
|
||||
: target === 'users'
|
||||
? 'User UUID'
|
||||
: 'Paste ID or User UUID'}
|
||||
value={target === 'pastes' ? pasteId : target === 'users' ? userUuid : mixedTarget}
|
||||
on:input={(e) => {
|
||||
if (e.currentTarget instanceof HTMLInputElement) {
|
||||
handleTargetInput(e.currentTarget.value);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if data.reports.reports.length > 0}
|
||||
<div class="space-y-3">
|
||||
{#each data.reports.reports as report (report.reportID)}
|
||||
<div
|
||||
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
role="link"
|
||||
tabindex="0"
|
||||
on:click={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
on:keydown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
goto(resolve(`/report/${report.reportID}`));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<span class="text-lg font-semibold text-neutral-100">
|
||||
Report #{report.reportID}
|
||||
</span>
|
||||
<span class="text-sm text-neutral-300">
|
||||
{reportTypeLabels[report.type] ?? 'Other'}
|
||||
· {reportStatusLabels[report.status] ?? 'Open'}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-sm text-neutral-400">
|
||||
<span>{reportTargetLabels[report.targetType] ?? 'Unknown'}</span>
|
||||
{#if report.pasteId}
|
||||
<a
|
||||
href={resolve(`/${report.pasteId}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
on:click|stopPropagation
|
||||
>
|
||||
{report.pasteTitle !== '' ? report.pasteTitle : report.pasteId}
|
||||
</a>
|
||||
{/if}
|
||||
{#if report.userUUID}
|
||||
{#if report.targetUsername}
|
||||
<a
|
||||
href={resolve(`/user/${report.targetUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.userUUID}
|
||||
on:click|stopPropagation
|
||||
>
|
||||
{report.targetDisplayName || report.targetUsername}
|
||||
</a>
|
||||
{:else}
|
||||
<span>{report.userUUID}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if report.reporterUsername}
|
||||
<a
|
||||
href={resolve(`/user/${report.reporterUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.reporterUUID}
|
||||
on:click|stopPropagation
|
||||
>
|
||||
{report.reporterDisplayName || report.reporterUsername}
|
||||
</a>
|
||||
{:else}
|
||||
<span>{report.reporterUUID}</span>
|
||||
{/if}
|
||||
<span>Created {new Date(report.createdAt * 1000).toLocaleString()}</span>
|
||||
</div>
|
||||
{#if report.description}
|
||||
<p class="text-sm text-neutral-300">{report.description}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-center text-neutral-400">No reports found.</p>
|
||||
{/if}
|
||||
|
||||
{#if data.reports.pagination.totalPages > 1}
|
||||
<div class="mt-6 flex items-center justify-center gap-4">
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
|
||||
on:click={() => applyFilters(data.reports.pagination.page - 1)}
|
||||
disabled={data.reports.pagination.page <= 1}
|
||||
>
|
||||
Prev
|
||||
</button>
|
||||
<span class="text-neutral-400">
|
||||
Page {data.reports.pagination.page} of {data.reports.pagination.totalPages}
|
||||
</span>
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
|
||||
on:click={() => applyFilters(data.reports.pagination.page + 1)}
|
||||
disabled={data.reports.pagination.page >= data.reports.pagination.totalPages}
|
||||
>
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</main>
|
||||
@@ -1,97 +0,0 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { getServerToken } from '$lib/utils/auth';
|
||||
import type { User } from '$lib/types/user';
|
||||
import type { Paste } from '$lib/types/paste';
|
||||
import type { Pagination } from '$lib/types/pagination';
|
||||
import type { Report, ReportListResponse } from '$lib/types/report';
|
||||
|
||||
const API_URL = env.VITE_API_URL ?? 'http://localhost:5050';
|
||||
|
||||
function decodeJwtRoles(token?: string | null): number[] {
|
||||
try {
|
||||
if (!token) return [];
|
||||
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
||||
const roles = payload?.role;
|
||||
if (Array.isArray(roles)) {
|
||||
return roles.map((r: string) => parseInt(r, 10)).filter((r: number) => !isNaN(r));
|
||||
}
|
||||
return [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function decodeJwtUuid(token?: string | null): string | null {
|
||||
try {
|
||||
if (!token) return null;
|
||||
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
||||
const uuid = payload?.uuid;
|
||||
return typeof uuid === 'string' ? uuid : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, cookies, url, parent }) => {
|
||||
const token = getServerToken(cookies);
|
||||
const { username } = params;
|
||||
const { options } = await parent();
|
||||
const jwtUuid = decodeJwtUuid(token);
|
||||
|
||||
const res = await fetch(`${API_URL}/api/user/${username}`, {
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : undefined
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const { message } = await res.json().catch(() => ({}));
|
||||
throw error(res.status, message ?? 'Request failed');
|
||||
}
|
||||
|
||||
const { user, pastes, pagination, reports, reportsPagination } = (await res.json()) as {
|
||||
user: User;
|
||||
pastes: Paste[];
|
||||
pagination: Pagination;
|
||||
reports?: Report[];
|
||||
reportsPagination?: Pagination;
|
||||
};
|
||||
|
||||
const isOwner = jwtUuid ? user.uuid === jwtUuid : false;
|
||||
let reportsTarget: ReportListResponse | null = null;
|
||||
let reportsSubmitted: ReportListResponse | null = null;
|
||||
const roles = token ? decodeJwtRoles(token) : [];
|
||||
const canModerate = roles.includes(255) || roles.includes(1);
|
||||
|
||||
if (isOwner && reports && reportsPagination) {
|
||||
reportsSubmitted = {
|
||||
reports,
|
||||
pagination: reportsPagination
|
||||
};
|
||||
}
|
||||
|
||||
if (token && canModerate && (!reportsSubmitted || !isOwner)) {
|
||||
const submittedRes = await fetch(`${API_URL}/api/user/${user.uuid}/reports/submitted`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
if (submittedRes.ok) reportsSubmitted = await submittedRes.json();
|
||||
}
|
||||
|
||||
if (token && !isOwner) {
|
||||
if (canModerate) {
|
||||
const r = await fetch(`${API_URL}/api/user/${user.uuid}/reports`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
if (r.ok) reportsTarget = await r.json();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
pastes: { pastes, pagination },
|
||||
reportsTarget,
|
||||
reportsSubmitted,
|
||||
url: url.href,
|
||||
authOptions: options
|
||||
};
|
||||
};
|
||||
@@ -1,594 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { goto } from '$app/navigation';
|
||||
import type { PageData } from './$types';
|
||||
import type { Pagination } from '$lib/types/pagination';
|
||||
import {
|
||||
User,
|
||||
CalendarDays,
|
||||
ShieldUser,
|
||||
Ban,
|
||||
File,
|
||||
AtSign,
|
||||
Pencil,
|
||||
Trash2,
|
||||
Clock,
|
||||
Hash,
|
||||
Flag
|
||||
} from '@lucide/svelte';
|
||||
import { extractDateFromUUIDv7, tooltip, dateToRelativeString } from '$lib/utils/misc';
|
||||
import { roles } from '$lib/consts';
|
||||
import { getToken } from '$lib/utils/auth';
|
||||
import { needsAdminTotp } from '$lib/utils/totp';
|
||||
import { openModal } from '$lib/stores/modal';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { onMount } from 'svelte';
|
||||
import Paste from '$lib/components/Paste.svelte';
|
||||
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
let currentPage = data.pastes?.pagination?.page ?? 1;
|
||||
let pagination: Pagination = data.pastes?.pagination ?? {
|
||||
page: 1,
|
||||
pageSize: 50,
|
||||
totalCount: 0,
|
||||
totalPages: 1
|
||||
};
|
||||
let pastes = data.pastes?.pastes ?? [];
|
||||
let loading = false;
|
||||
let isOwner = false;
|
||||
let modalError = '';
|
||||
let totpEnabled = false;
|
||||
let now = new Date();
|
||||
let interval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
$: isOwner = data.user && $user ? data.user?.uuid === $user.uuid : false;
|
||||
$: totpEnabled = Boolean($user?.totpEnabled);
|
||||
$: reportsSubmitted = data.reportsSubmitted;
|
||||
$: reportsTarget = data.reportsTarget;
|
||||
|
||||
const roleOptions = [
|
||||
{ label: 'Member', value: 0 },
|
||||
{ label: 'Moderator', value: 1 },
|
||||
{ label: 'Administrator', value: 255 },
|
||||
{ label: 'Banned', value: 403 }
|
||||
];
|
||||
|
||||
async function fetchPage(pageNum: number) {
|
||||
if (pageNum < 1 || pageNum > (pagination.totalPages || 1) || loading) return;
|
||||
loading = true;
|
||||
const token = getToken();
|
||||
const res = await fetch(`/api/user/${data.user?.username}?page=${pageNum}`, {
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {}
|
||||
});
|
||||
if (!res.ok) {
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
const json = await res.json();
|
||||
pastes = json.pastes ?? [];
|
||||
pagination = json.pagination ?? pagination;
|
||||
currentPage = pagination.page ?? pageNum;
|
||||
loading = false;
|
||||
}
|
||||
|
||||
async function handleUserUpdate(displayName?: string, selectedRoles?: number[]) {
|
||||
loading = true;
|
||||
modalError = '';
|
||||
const token = getToken();
|
||||
const currentRoles = data.user?.roles ?? [];
|
||||
const nextRoles = selectedRoles ?? currentRoles;
|
||||
let totpcode = '';
|
||||
if (needsAdminTotp(totpEnabled, currentRoles, nextRoles)) {
|
||||
totpcode = String(
|
||||
await openModal<string>({
|
||||
mode: 'totp',
|
||||
title: 'Admin role requires TOTP',
|
||||
placeholder: 'Enter 6-digit code',
|
||||
inputType: 'text',
|
||||
confirmButtonText: 'Continue',
|
||||
cancelValue: ''
|
||||
})
|
||||
).trim();
|
||||
if (!totpcode) {
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
const res = await fetch(`/api/user/uuid/${data.user?.uuid}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...(displayName !== undefined ? { displayName: displayName.trim() } : {}),
|
||||
...(selectedRoles !== undefined ? { roles: selectedRoles } : {}),
|
||||
...(totpcode ? { totpcode } : {})
|
||||
})
|
||||
});
|
||||
loading = false;
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
modalError = err.message || 'Failed to update display name';
|
||||
await openModal({
|
||||
mode: 'confirm',
|
||||
title: 'Error',
|
||||
message: modalError,
|
||||
confirmButtonText: 'OK',
|
||||
cancelValue: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
data.user!.displayName = displayName || data.user!.displayName;
|
||||
if (selectedRoles !== undefined) {
|
||||
data.user!.roles = selectedRoles;
|
||||
}
|
||||
modalError = '';
|
||||
}
|
||||
|
||||
async function handleDeleteAccount() {
|
||||
loading = true;
|
||||
modalError = '';
|
||||
const token = getToken();
|
||||
let totpcode = '';
|
||||
if (totpEnabled) {
|
||||
totpcode = String(
|
||||
await openModal<string>({
|
||||
mode: 'totp',
|
||||
title: 'Enter TOTP to delete',
|
||||
placeholder: 'Enter 6-digit code',
|
||||
inputType: 'text',
|
||||
confirmButtonText: 'Delete Account',
|
||||
cancelValue: ''
|
||||
})
|
||||
).trim();
|
||||
if (!totpcode) {
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
const res = await fetch(`/api/user/uuid/${data.user?.uuid}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
body: totpEnabled && totpcode ? JSON.stringify({ totpcode }) : undefined
|
||||
});
|
||||
loading = false;
|
||||
if (!res.ok) {
|
||||
const err = await res.json();
|
||||
modalError = err.message || 'Failed to delete account';
|
||||
await openModal({
|
||||
mode: 'confirm',
|
||||
title: 'Error',
|
||||
message: modalError,
|
||||
confirmButtonText: 'OK',
|
||||
cancelValue: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
function handleTotpConfirm(value: unknown) {
|
||||
if (value && typeof value === 'object' && 'enabled' in value) {
|
||||
totpEnabled = Boolean((value as { enabled?: boolean }).enabled);
|
||||
}
|
||||
user.update((u) => (u ? { ...u, totpEnabled } : u));
|
||||
modalError = '';
|
||||
}
|
||||
|
||||
async function openEditDisplayName() {
|
||||
const value = String(
|
||||
await openModal<string>({
|
||||
mode: 'prompt',
|
||||
title: 'Edit Display Name',
|
||||
placeholder: 'New Display Name',
|
||||
error: modalError,
|
||||
cancelValue: ''
|
||||
})
|
||||
).trim();
|
||||
if (!value) return;
|
||||
await handleUserUpdate(value);
|
||||
}
|
||||
|
||||
async function openEditRoles() {
|
||||
const value = await openModal({
|
||||
mode: 'multiselect',
|
||||
title: 'Edit User Roles',
|
||||
items: roleOptions,
|
||||
initialValue: data.user?.roles,
|
||||
cancelValue: null
|
||||
});
|
||||
if (!Array.isArray(value)) return;
|
||||
await handleUserUpdate(undefined, value as number[]);
|
||||
}
|
||||
|
||||
async function openDeleteAccount() {
|
||||
const ok = await openModal<boolean>({
|
||||
mode: 'confirm',
|
||||
title: 'Delete Account',
|
||||
message: `This action cannot be undone. ${isOwner ? 'All your' : "This user's"} pastes and account data will be permanently deleted.`,
|
||||
confirmButtonText: 'Delete Account',
|
||||
cancelValue: false
|
||||
});
|
||||
if (!ok) return;
|
||||
await handleDeleteAccount();
|
||||
}
|
||||
|
||||
async function openTotpSetup() {
|
||||
const result = await openModal({
|
||||
mode: 'totpSetup',
|
||||
title: 'Two-Factor Authentication',
|
||||
totpActive: totpEnabled,
|
||||
cancelValue: null
|
||||
});
|
||||
if (result) {
|
||||
handleTotpConfirm(result);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
interval = setInterval(() => {
|
||||
now = new Date();
|
||||
}, 1000);
|
||||
return () => {
|
||||
if (interval) clearInterval(interval);
|
||||
};
|
||||
});
|
||||
|
||||
$: reportSiteKey =
|
||||
(data as unknown as { authOptions?: { cf_turnstile_site_key?: string | null } }).authOptions
|
||||
?.cf_turnstile_site_key ?? null;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{data.user?.displayName || data.user?.username} - User Profile</title>
|
||||
|
||||
<meta
|
||||
property="og:title"
|
||||
content="{data.user?.displayName || data.user?.username} - User Profile"
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content="View the profile and {pagination.totalCount !== 0
|
||||
? pagination.totalCount
|
||||
: ''} paste{pagination.totalCount !== 1 ? 's' : ''} of {data.user?.displayName ||
|
||||
data.user?.username} on Sharpbin."
|
||||
/>
|
||||
<meta property="og:type" content="profile" />
|
||||
<meta property="og:url" content={data.url} />
|
||||
<meta property="og:site_name" content="Sharpbin" />
|
||||
<meta property="profile:username" content={data.user?.username} />
|
||||
</svelte:head>
|
||||
|
||||
<main
|
||||
class="flex min-h-[calc(100vh-120px)] w-full flex-col items-center justify-center pt-5 pb-5 text-white"
|
||||
>
|
||||
<div class="relative w-[95%] max-w-5xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||
<h1 class="flex items-center justify-center gap-4 text-center text-4xl font-bold">
|
||||
{#if data.user?.roles?.includes(403)}
|
||||
<span
|
||||
class="relative flex h-7 w-7 items-center justify-center overflow-hidden rounded-full"
|
||||
use:tooltip={roles[403]}
|
||||
>
|
||||
<User class="h-8 w-8 text-neutral-500" />
|
||||
<Ban class="absolute h-7 w-7 text-red-500" />
|
||||
</span>
|
||||
{:else if data.user?.roles?.includes(1) || data.user?.roles?.includes(255)}
|
||||
{#if data.user?.roles?.length}
|
||||
<span use:tooltip={roles[Math.max(...data.user.roles) as keyof typeof roles]}>
|
||||
<ShieldUser class="h-8 w-8 text-neutral-400" />
|
||||
</span>
|
||||
{/if}
|
||||
{:else}
|
||||
<span use:tooltip={'User'}>
|
||||
<User class="h-8 w-8 text-neutral-400" />
|
||||
</span>
|
||||
{/if}
|
||||
<span use:tooltip={data.user?.uuid || 'Unknown UUID'}>
|
||||
{data.user?.displayName || data.user?.username}
|
||||
</span>
|
||||
</h1>
|
||||
{#if data.user?.displayName && data.user?.displayName !== data.user?.username}
|
||||
<div class="mb-2 flex items-center justify-center">
|
||||
<AtSign class="mr-2 inline h-5 w-5 text-neutral-400" />
|
||||
<span class="text-neutral-400">{data.user?.username}</span>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="mb-2 flex flex-wrap items-center justify-center gap-4 text-sm">
|
||||
<div class="flex shrink-0 items-center">
|
||||
<CalendarDays class="mr-2 h-6 w-6 text-neutral-400" />
|
||||
<span
|
||||
class="text-neutral-400"
|
||||
use:tooltip={extractDateFromUUIDv7(data.user?.uuid)?.toLocaleString() ?? 'Unknown'}
|
||||
>
|
||||
Joined {extractDateFromUUIDv7(data.user?.uuid)?.toLocaleDateString() ?? 'Unknown'}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center">
|
||||
<File class="mr-2 h-6 w-6 text-neutral-400" />
|
||||
<span class="text-neutral-400"
|
||||
>{pagination.totalCount} paste{pagination.totalCount !== 1 ? 's' : ''}</span
|
||||
>
|
||||
</div>
|
||||
{#if reportsSubmitted}
|
||||
<div class="flex shrink-0 items-center">
|
||||
<Flag class="mr-2 h-6 w-6 text-neutral-400" />
|
||||
<span class="text-neutral-400"
|
||||
>{reportsSubmitted.pagination.totalCount} submitted report{reportsSubmitted.pagination
|
||||
.totalCount !== 1
|
||||
? 's'
|
||||
: ''}</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
{#if reportsTarget}
|
||||
<div class="flex shrink-0 items-center">
|
||||
<Flag class="mr-2 h-6 w-6 text-neutral-400" />
|
||||
<span class="text-neutral-400"
|
||||
>{reportsTarget.pagination.totalCount} report{reportsTarget.pagination.totalCount !== 1
|
||||
? 's'
|
||||
: ''}</span
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex shrink-0 items-center">
|
||||
<Hash class="mr-1 h-6 w-6 text-neutral-400" />
|
||||
<span class="text-neutral-400" use:tooltip={`User #${data.user?.uid}`}>
|
||||
{data.user?.uid}
|
||||
</span>
|
||||
</div>
|
||||
{#if isOwner && data.user?.lastLogin}
|
||||
<div class="flex shrink-0 items-center">
|
||||
<Clock class="mr-2 h-6 w-6 text-neutral-400" />
|
||||
<span
|
||||
class="text-neutral-400"
|
||||
use:tooltip={new Date(data.user?.lastLogin).toLocaleString()}
|
||||
>
|
||||
Last login {dateToRelativeString(new Date(data.user?.lastLogin), true, false, now)}
|
||||
</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if !isOwner && !$user?.roles?.some((r) => r === 403)}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="absolute top-0 right-0"
|
||||
on:click={() =>
|
||||
openModal({
|
||||
mode: 'report',
|
||||
title: 'Report User',
|
||||
reportTarget: 'user',
|
||||
reportTargetId: data.user?.uuid || '',
|
||||
reportSiteKey: reportSiteKey,
|
||||
confirmButtonText: 'Submit Report',
|
||||
cancelValue: null
|
||||
})}
|
||||
>
|
||||
<Flag class="m-4 h-6 w-6 cursor-pointer text-neutral-400 hover:text-amber-400" />
|
||||
</div>
|
||||
{/if}
|
||||
{#if isOwner || $user?.roles?.some((r) => r === 255 || r === 1)}
|
||||
<div class="mt-4 flex flex-wrap justify-center gap-2">
|
||||
<button
|
||||
on:click={openEditDisplayName}
|
||||
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600"
|
||||
>
|
||||
<Pencil class="h-4 w-4" />
|
||||
Edit Display Name
|
||||
</button>
|
||||
{#if isOwner}
|
||||
<button
|
||||
on:click={openTotpSetup}
|
||||
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600"
|
||||
>
|
||||
<ShieldUser class="h-4 w-4" />
|
||||
{totpEnabled ? 'Manage 2FA' : 'Enable 2FA'}
|
||||
</button>
|
||||
{/if}
|
||||
{#if $user?.roles?.some((r) => r === 255)}
|
||||
<button
|
||||
on:click={openEditRoles}
|
||||
class="flex items-center gap-2 rounded bg-neutral-700 px-4 py-2 text-sm font-medium transition-colors hover:bg-neutral-600"
|
||||
>
|
||||
<ShieldUser class="h-4 w-4" />
|
||||
Edit Roles
|
||||
</button>
|
||||
{/if}
|
||||
{#if isOwner || $user?.roles?.some((r) => r === 255)}
|
||||
<button
|
||||
on:click={openDeleteAccount}
|
||||
class="flex items-center gap-2 rounded bg-red-900 px-4 py-2 text-sm font-medium transition-colors hover:bg-red-800"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
Delete Account
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="mt-6 max-h-[60vh] space-y-4 overflow-y-auto">
|
||||
{#if pastes && pastes.length > 0}
|
||||
{#each pastes.slice().sort((a, b) => b.uuid.localeCompare(a.uuid)) as paste (paste.uuid)}
|
||||
<Paste {paste} {now} showUser={false} compact={true} />
|
||||
{/each}
|
||||
{:else}
|
||||
<p class="text-center text-neutral-400">
|
||||
{isOwner ? 'You have' : 'This user has'} not created any pastes yet.
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
{#if reportsSubmitted || reportsTarget}
|
||||
<div class="mt-6 space-y-6">
|
||||
{#if reportsSubmitted && reportsSubmitted.reports.length > 0}
|
||||
<div class="rounded border border-neutral-800 bg-neutral-900/60 p-4">
|
||||
<h2 class="mb-3 text-xl font-semibold text-neutral-200">Submitted Reports</h2>
|
||||
<div class="space-y-3">
|
||||
{#each reportsSubmitted.reports as report (report.reportID)}
|
||||
<div
|
||||
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
role="link"
|
||||
tabindex="0"
|
||||
on:click={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
on:keydown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
goto(resolve(`/report/${report.reportID}`));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<span class="text-lg font-semibold text-neutral-100">
|
||||
Report #{report.reportID}
|
||||
</span>
|
||||
<span class="text-sm text-neutral-300">
|
||||
{reportTypeLabels[report.type] ?? 'Other'}
|
||||
· {reportStatusLabels[report.status] ?? 'Open'}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-sm text-neutral-400">
|
||||
<span>{reportTargetLabels[report.targetType] ?? 'Unknown'}</span>
|
||||
{#if report.pasteId}
|
||||
<a
|
||||
href={resolve(`/${report.pasteId}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
on:click|stopPropagation
|
||||
>
|
||||
{report.pasteTitle !== '' ? report.pasteTitle : report.pasteId}
|
||||
</a>
|
||||
{/if}
|
||||
{#if report.userUUID}
|
||||
{#if report.targetUsername}
|
||||
<a
|
||||
href={resolve(`/user/${report.targetUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.userUUID}
|
||||
on:click|stopPropagation
|
||||
>
|
||||
{report.targetDisplayName || report.targetUsername}
|
||||
</a>
|
||||
{:else}
|
||||
<span>{report.userUUID}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
<span>
|
||||
Created {new Date(report.createdAt * 1000).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
{#if report.description}
|
||||
<p class="text-sm text-neutral-300">{report.description}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if reportsTarget && reportsTarget.reports.length > 0}
|
||||
<div class="rounded border border-neutral-800 bg-neutral-900/60 p-4">
|
||||
<h2 class="mb-3 text-xl font-semibold text-neutral-200">Reports About This User</h2>
|
||||
<div class="space-y-3">
|
||||
{#each reportsTarget.reports as report (report.reportID)}
|
||||
<div
|
||||
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
|
||||
role="link"
|
||||
tabindex="0"
|
||||
on:click={() => goto(resolve(`/report/${report.reportID}`))}
|
||||
on:keydown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
goto(resolve(`/report/${report.reportID}`));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<span class="text-lg font-semibold text-neutral-100">
|
||||
Report #{report.reportID}
|
||||
</span>
|
||||
<span class="text-sm text-neutral-300">
|
||||
{reportTypeLabels[report.type] ?? 'Other'}
|
||||
· {reportStatusLabels[report.status] ?? 'Open'}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-sm text-neutral-400">
|
||||
<span>{reportTargetLabels[report.targetType] ?? 'Unknown'}</span>
|
||||
{#if report.reporterUsername}
|
||||
<a
|
||||
href={resolve(`/user/${report.reporterUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.reporterUUID}
|
||||
on:click|stopPropagation
|
||||
>
|
||||
{report.reporterDisplayName || report.reporterUsername}
|
||||
</a>
|
||||
{:else}
|
||||
<span>{report.reporterUUID}</span>
|
||||
{/if}
|
||||
{#if report.pastePID}
|
||||
<a
|
||||
href={resolve(`/${report.pasteId ?? report.pastePID}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
on:click|stopPropagation
|
||||
>
|
||||
{report.pasteTitle ? report.pasteTitle : `Paste #${report.pastePID}`}
|
||||
</a>
|
||||
{/if}
|
||||
{#if report.userUUID}
|
||||
{#if report.targetUsername}
|
||||
<a
|
||||
href={resolve(`/user/${report.targetUsername}`)}
|
||||
class="text-neutral-300 hover:text-white"
|
||||
use:tooltip={report.userUUID}
|
||||
on:click|stopPropagation
|
||||
>
|
||||
{report.targetDisplayName || report.targetUsername}
|
||||
</a>
|
||||
{:else}
|
||||
<span>{report.userUUID}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
<span>
|
||||
Created {new Date(report.createdAt * 1000).toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
{#if report.description}
|
||||
<p class="text-sm text-neutral-300">{report.description}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if pagination.totalPages && pagination.totalPages > 1}
|
||||
<div class="mt-4 flex items-center justify-center gap-4">
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
|
||||
on:click={() => fetchPage(currentPage - 1)}
|
||||
disabled={currentPage === 1 || loading}
|
||||
>
|
||||
Prev
|
||||
</button>
|
||||
<span class="text-neutral-400">
|
||||
Page {currentPage} of {pagination.totalPages}
|
||||
</span>
|
||||
<button
|
||||
class="rounded bg-neutral-700 px-3 py-1 disabled:opacity-50"
|
||||
on:click={() => fetchPage(currentPage + 1)}
|
||||
disabled={currentPage === pagination.totalPages || loading}
|
||||
>
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
@@ -1,3 +0,0 @@
|
||||
# allow crawling everything by default
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@@ -1,18 +0,0 @@
|
||||
import adapter from '@sveltejs/adapter-node';
|
||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://svelte.dev/docs/kit/integrations
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
|
||||
kit: {
|
||||
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
|
||||
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
||||
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rewriteRelativeImportExtensions": true,
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler"
|
||||
}
|
||||
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
|
||||
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
|
||||
//
|
||||
// To make changes to top-level options such as include and exclude, we recommend extending
|
||||
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
import { readFileSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const file = fileURLToPath(new URL('package.json', import.meta.url));
|
||||
const json = readFileSync(file, 'utf8');
|
||||
const pkg = JSON.parse(json);
|
||||
|
||||
const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
|
||||
const allowedHosts = process.env.VITE_ALLOWED_HOSTS
|
||||
? process.env.VITE_ALLOWED_HOSTS.split(',')
|
||||
: ['localhost'];
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [tailwindcss(), sveltekit()],
|
||||
define: {
|
||||
__APP_VERSION__: JSON.stringify(pkg.version)
|
||||
},
|
||||
server: {
|
||||
host: true,
|
||||
proxy: {
|
||||
'/api': apiUrl
|
||||
},
|
||||
allowedHosts: allowedHosts
|
||||
},
|
||||
preview: {
|
||||
allowedHosts: allowedHosts
|
||||
}
|
||||
});
|
||||
@@ -1,2 +0,0 @@
|
||||
SharpbinV3
|
||||
.idea
|
||||
@@ -1,29 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace SharpbinV3.Server.Authorization
|
||||
{
|
||||
public sealed class NotBannedHandler(bool requireAuth = false) : AuthorizationHandler<NotBannedRequirement>
|
||||
{
|
||||
private readonly bool _requireAuth = requireAuth;
|
||||
|
||||
protected override Task HandleRequirementAsync(
|
||||
AuthorizationHandlerContext context,
|
||||
NotBannedRequirement requirement)
|
||||
{
|
||||
var isAuthenticated = context.User.Identity?.IsAuthenticated ?? false;
|
||||
|
||||
if (_requireAuth && !isAuthenticated)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var isBanned = context.User.Claims.Any(c =>
|
||||
(c.Type == ClaimTypes.Role || c.Type == "role") &&
|
||||
c.Value == "403");
|
||||
|
||||
if (!isBanned)
|
||||
context.Succeed(requirement);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace SharpbinV3.Server.Authorization
|
||||
{
|
||||
public class NotBannedRequirement : IAuthorizationRequirement
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SharpbinV3.Server.Data;
|
||||
using SharpbinV3.Server.Data.Entities;
|
||||
using SharpbinV3.Server.DTOs;
|
||||
using SharpbinV3.Server.DTOs.Auth;
|
||||
using SharpbinV3.Server.DTOs.User;
|
||||
using SharpbinV3.Server.Extensions;
|
||||
using SharpbinV3.Server.Services;
|
||||
using SharpbinV3.Server.Services.Verification;
|
||||
using SharpbinV3.Server.Services.Verification.Providers;
|
||||
using SharpbinV3.Server.Settings;
|
||||
using Bcrypt = BCrypt.Net.BCrypt;
|
||||
|
||||
namespace SharpbinV3.Server.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class AuthController(UserService userService, AuthService authService, IOptions<AuthSettings> options,
|
||||
VerificationService verification, TotpVerificationProvider totp, AppDbContext db) : ControllerBase
|
||||
{
|
||||
private readonly AuthService _authService = authService;
|
||||
private readonly UserService _userService = userService;
|
||||
private readonly VerificationService _verification = verification;
|
||||
private readonly TotpVerificationProvider _totp = totp;
|
||||
private readonly AppDbContext _db = db;
|
||||
|
||||
[HttpPost]
|
||||
[EnableRateLimiting("Strict")]
|
||||
[Route("register")]
|
||||
public async Task<IActionResult> Register([FromBody] RegisterUserDto request)
|
||||
{
|
||||
if (!options.Value.Registration_Enabled)
|
||||
return BadRequest(new { success = false, message = "Registration is disabled." });
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
if (!await _verification.VerifyAsync(new VerificationContext
|
||||
{
|
||||
Token = request.Token,
|
||||
Ip = HttpContext.GetRequestIP()
|
||||
}))
|
||||
return BadRequest(new { success = false, message = "Verification failed." });
|
||||
|
||||
var existingUser = await _userService.GetByUsername(request.Username);
|
||||
if (existingUser != null)
|
||||
return Conflict(new { success = false, message = "Username already exists." });
|
||||
if (!string.IsNullOrEmpty(request.Email))
|
||||
{
|
||||
var existingEmailUser = await _userService.GetByEmail(request.Email);
|
||||
if (existingEmailUser != null)
|
||||
return Conflict(new { success = false, message = "Email already in use." });
|
||||
}
|
||||
if (!string.IsNullOrEmpty(request.DisplayName) && request.DisplayName.Length > 26)
|
||||
return BadRequest(new { success = false, message = "Display name should not exceed 26 characters." });
|
||||
|
||||
var user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName);
|
||||
return Ok(new
|
||||
{
|
||||
message = "User registered successfully.",
|
||||
user = new UserResponseDto
|
||||
{
|
||||
UID = user.UID,
|
||||
UUID = user.UUID,
|
||||
Username = user.Username,
|
||||
DisplayName = user.DisplayName,
|
||||
Email = user.Email,
|
||||
Roles = user.Roles,
|
||||
Visibility = user.Visibility,
|
||||
LastLogin = user.LastLogin
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("login")]
|
||||
[EnableRateLimiting("Strict")]
|
||||
public async Task<IActionResult> Login([FromBody] LoginUserDto request)
|
||||
{
|
||||
if (string.IsNullOrEmpty(request.Username) && string.IsNullOrEmpty(request.Email))
|
||||
return BadRequest(new { success = false, message = "Username or email is required." });
|
||||
|
||||
if (!await _verification.VerifyAsync(new VerificationContext
|
||||
{
|
||||
Token = request.Token,
|
||||
Ip = HttpContext.GetRequestIP()
|
||||
}))
|
||||
return BadRequest(new { success = false, message = "Verification failed." });
|
||||
|
||||
User? user = null;
|
||||
if (!string.IsNullOrEmpty(request.Username))
|
||||
user = await _userService.GetByUsername(request.Username);
|
||||
if (user == null && !string.IsNullOrEmpty(request.Email))
|
||||
user = await _userService.GetByEmail(request.Email);
|
||||
|
||||
if (user == null || !Bcrypt.Verify(request.Password, user.PasswordHash))
|
||||
return BadRequest(new { success = false, message = "Invalid username/email or password." });
|
||||
|
||||
var totpEnabled = await _db.UserTotps.AnyAsync(t => t.UserUUID == user.UUID);
|
||||
if (totpEnabled)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.TotpCode))
|
||||
return BadRequest(new { success = false, message = "TOTP code is required." });
|
||||
var totpValid = await _totp.VerifyAsync(new VerificationContext
|
||||
{
|
||||
UserUUID = user.UUID,
|
||||
Code = request.TotpCode
|
||||
});
|
||||
if (!totpValid)
|
||||
return BadRequest(new { success = false, message = "Invalid TOTP code." });
|
||||
}
|
||||
var token = _authService.GenerateJWTToken(user);
|
||||
await _authService.UpdateLoginTime(user);
|
||||
var result = await token;
|
||||
return Ok(new LoginResponseDto
|
||||
{
|
||||
Success = true,
|
||||
Token = result.Token ?? string.Empty,
|
||||
RefreshToken = result.RefreshToken ?? string.Empty
|
||||
});
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("refresh")]
|
||||
[EnableRateLimiting("Sliding")]
|
||||
public async Task<IActionResult> RefreshToken([FromBody] RefreshTokenDto request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jwtResult = await _authService.RefreshJWTToken(request.Token, request.RefreshToken);
|
||||
return Ok(new TokenRefreshResponseDto
|
||||
{
|
||||
Success = jwtResult?.Success ?? false,
|
||||
Message = jwtResult?.Errors != null && jwtResult.Errors.Count > 0 ? string.Join("; ", jwtResult.Errors) : "Token refreshed successfully.",
|
||||
Token = jwtResult != null ? new TokenData
|
||||
{
|
||||
Token = jwtResult.Token,
|
||||
RefreshToken = jwtResult.RefreshToken
|
||||
} : null
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(new { success = false, message = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[EnableRateLimiting("NoLimit")]
|
||||
[Route("info")]
|
||||
public IActionResult GetSiteInfo()
|
||||
{
|
||||
var authSettings = options.Value;
|
||||
return Ok(new
|
||||
{
|
||||
cf_turnstile_site_key = string.IsNullOrEmpty(authSettings.CF_Turnstile_SiteKey) ? null : authSettings.CF_Turnstile_SiteKey,
|
||||
registration_enabled = authSettings.Registration_Enabled
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
[Route("totp/enroll")]
|
||||
public async Task<IActionResult> StartTotpEnrollment()
|
||||
{
|
||||
var user = await _authService.GetUserFromHttpContext(HttpContext);
|
||||
if (user is null) return BadRequest(new { success = false, message = "User not found." });
|
||||
|
||||
var secret = _totp.GenerateSecret();
|
||||
var secretBase32 = _totp.ToBase32(secret);
|
||||
var account = string.IsNullOrWhiteSpace(user.Email) ? user.Username : user.Email!;
|
||||
var uri = _totp.BuildOtpAuthUri("SharpbinV3", account, secretBase32);
|
||||
return Ok(new { success = true, secret = secretBase32, otpauth = uri });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
[Route("totp/enable")]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
public async Task<IActionResult> EnableTotp([FromBody] EnableTotpDto request)
|
||||
{
|
||||
var uuidClaim = User.Claims.FirstOrDefault(c => c.Type == "UUID")?.Value;
|
||||
if (string.IsNullOrEmpty(uuidClaim))
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var uuid = Guid.Parse(uuidClaim);
|
||||
if (string.IsNullOrWhiteSpace(request.Secret) || string.IsNullOrWhiteSpace(request.Code))
|
||||
return BadRequest(new { success = false, message = "Secret and code are required." });
|
||||
|
||||
if (!_totp.VerifyWithSecretBase32(request.Secret, request.Code))
|
||||
return BadRequest(new { success = false, message = "Invalid TOTP code." });
|
||||
|
||||
var secretBytes = _totp.FromBase32(request.Secret);
|
||||
var protectedBytes = _totp.Protect(secretBytes);
|
||||
var existing = await _db.UserTotps.FirstOrDefaultAsync(t => t.UserUUID == uuid);
|
||||
if (existing is null)
|
||||
{
|
||||
var entry = new UserTotp { UserUUID = uuid, EncryptedSecret = protectedBytes };
|
||||
_db.UserTotps.Add(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
existing.EncryptedSecret = protectedBytes;
|
||||
_db.UserTotps.Update(existing);
|
||||
}
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(new { success = true, message = "TOTP enabled." });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
[Route("totp/disable")]
|
||||
public async Task<IActionResult> DisableTotp([FromBody] DisableTotpDto dto)
|
||||
{
|
||||
var user = await _authService.GetUserFromHttpContext(HttpContext);
|
||||
if (user == null) return BadRequest(new { success = false, message = "User not found." });
|
||||
if (string.IsNullOrWhiteSpace(dto.Code))
|
||||
return BadRequest(new { success = false, message = "TOTP code is required." });
|
||||
var existing = await _db.UserTotps.FirstOrDefaultAsync(t => t.UserUUID == user.UUID);
|
||||
if (existing is null)
|
||||
return BadRequest(new { success = false, message = "TOTP is not enabled." });
|
||||
if (!_totp.VerifyAsync(new VerificationContext
|
||||
{
|
||||
UserUUID = user.UUID,
|
||||
Code = dto.Code
|
||||
}).Result)
|
||||
return BadRequest(new { success = false, message = "Invalid TOTP code." });
|
||||
|
||||
_db.UserTotps.Remove(existing);
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(new { success = true, message = "TOTP disabled." });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,430 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SharpbinV3.Server.Data.Entities;
|
||||
using SharpbinV3.Server.DTOs.Paste;
|
||||
using SharpbinV3.Server.DTOs.Report;
|
||||
using SharpbinV3.Server.DTOs.User;
|
||||
using SharpbinV3.Server.Extensions;
|
||||
using SharpbinV3.Server.Services;
|
||||
using SharpbinV3.Server.Services.Verification;
|
||||
using SharpbinV3.Server.Settings;
|
||||
|
||||
namespace SharpbinV3.Server.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PasteController(PasteService pasteService, VerificationService verificationService, AuthService authService,
|
||||
ReportService reportService, IOptions<PasteSettings> options, IOptions<AuthSettings> authSettings) : ControllerBase
|
||||
{
|
||||
private readonly PasteService _pasteService = pasteService;
|
||||
private readonly VerificationService _verificationService = verificationService;
|
||||
private readonly AuthService _authService = authService;
|
||||
private readonly ReportService _reportService = reportService;
|
||||
private readonly PasteSettings _pasteSettings = options.Value;
|
||||
private readonly AuthSettings _authSettings = authSettings.Value;
|
||||
|
||||
[HttpPost]
|
||||
[Route("create")]
|
||||
[Authorize(Policy = "NotBanned")]
|
||||
[EnableRateLimiting("Strict")]
|
||||
public async Task<IActionResult> CreatePaste(string title = "", string syntax = "plaintext", int visibility = 0, long expiresAt = 0, string? token = null)
|
||||
{
|
||||
if (!await _pasteService.ValidateExpiresAt(expiresAt))
|
||||
return BadRequest(new { success = false, message = "Invalid expiration time." });
|
||||
if (!await _pasteService.ValidateVisibility(visibility))
|
||||
return BadRequest(new { success = false, message = "Invalid visibility level. Must be between 0 and 2." });
|
||||
if (!await _pasteService.ValidateSyntax(syntax))
|
||||
return BadRequest(new { success = false, message = "Invalid syntax." });
|
||||
if (!await _pasteService.ValidateTitle(title))
|
||||
return BadRequest(new { success = false, message = $"Invalid title. Must be less than {_pasteSettings.MaxTitleLength} characters." });
|
||||
|
||||
string content = await new StreamReader(Request.Body).ReadToEndAsync();
|
||||
if (content.Length == 0)
|
||||
return BadRequest(new { success = false, message = "Paste content cannot be empty." });
|
||||
if (System.Text.Encoding.UTF8.GetByteCount(content) > _pasteSettings.MaxPasteSizeInBytes)
|
||||
return BadRequest(new { success = false, message = $"Paste size exceeds the maximum allowed size of {_pasteSettings.MaxPasteSizeInBytes} bytes." });
|
||||
|
||||
if (_pasteSettings.RequiresVerfication && !await _verificationService.VerifyAsync(new VerificationContext
|
||||
{
|
||||
Token = token,
|
||||
Ip = HttpContext.GetRequestIP()
|
||||
}))
|
||||
return BadRequest(new { success = false, message = "Verification failed." });
|
||||
|
||||
var user = await _authService.GetUserFromHttpContext(HttpContext);
|
||||
Paste paste = await _pasteService.Create(user, content, title, syntax, visibility, expiresAt, _pasteSettings.EnablePasteCompression);
|
||||
return Ok(new PasteCreatedResponseDto
|
||||
{
|
||||
ID = paste.ID,
|
||||
UUID = paste.UUID,
|
||||
IsCompressed = paste.IsCompressed,
|
||||
Size = paste.Size,
|
||||
TrueSize = paste.TrueSize,
|
||||
ExpiresAt = paste.ExpiresAt
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<IActionResult> GetPasteByID(string id)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null)
|
||||
return NotFound(new { success = false, message = "Paste not found" });
|
||||
var jwtUser = HttpContext.GetJwtUser();
|
||||
|
||||
int? reportCount = null;
|
||||
if (jwtUser != null && jwtUser.Roles.Any(r => r == 1 || r == 255))
|
||||
{
|
||||
var query = new ReportQuery
|
||||
{
|
||||
PastePID = paste.PID
|
||||
};
|
||||
reportCount = await _reportService.GetReportCount(query);
|
||||
}
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
paste = new PasteResponseDto
|
||||
{
|
||||
ID = paste.ID,
|
||||
UUID = paste.UUID,
|
||||
Title = paste.Title,
|
||||
Size = paste.Size,
|
||||
TrueSize = paste.TrueSize,
|
||||
IsCompressed = paste.IsCompressed,
|
||||
Views = paste.Views,
|
||||
Syntax = paste.Syntax,
|
||||
Visibility = paste.Visibility,
|
||||
ExpiresAt = paste.ExpiresAt,
|
||||
EditedAt = paste.EditedAt,
|
||||
ReportCount = reportCount,
|
||||
Author = paste.User != null && paste.User.Visibility == 0 ? new UserSimpleDto
|
||||
{
|
||||
UID = paste.User.UID,
|
||||
UUID = paste.User.UUID,
|
||||
Username = paste.User.Username,
|
||||
DisplayName = paste.User.DisplayName,
|
||||
Visibility = paste.User.Visibility,
|
||||
Roles = paste.User.Roles
|
||||
} : null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}/raw")]
|
||||
public async Task<IActionResult> GetRawPasteByID(string id)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null) return NotFound();
|
||||
if (paste.IsCompressed)
|
||||
Response.Headers.Append("Content-Encoding", "gzip");
|
||||
|
||||
return File(paste.Content, "text/plain; charset=utf-8");
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[Route("{id}")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> EditPaste(string id)
|
||||
{
|
||||
string content = await new StreamReader(Request.Body).ReadToEndAsync();
|
||||
if (content == null || id == null)
|
||||
return StatusCode(400, new { success = false, message = "Invalid request." });
|
||||
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null)
|
||||
return StatusCode(404, new { success = false, message = "Paste not found." });
|
||||
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var hasPrivilegedRole = user.Roles.Any(r => r == 1 || r == 255);
|
||||
if (paste.AuthorUUID != user.UUID && !hasPrivilegedRole)
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to edit this paste." });
|
||||
if (user.Roles.Contains(255) && !user.TotpEnabled && _authSettings.Admins_Require_2FA)
|
||||
return StatusCode(403, new { success = false, message = "2FA is required to perform this action." });
|
||||
|
||||
bool result = await _pasteService.EditText(paste, content);
|
||||
if (!result) return StatusCode(500, new { success = false, message = "An error occurred while editing the paste." });
|
||||
return Ok(new { message = "Paste edited successfully." });
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
[Route("{id}")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> ModifyPasteMetadata(string id, [FromBody] UpdatePasteDto request)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null)
|
||||
return NotFound(new { success = false, message = "Paste not found." });
|
||||
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var hasPrivilegedRole = user.Roles.Any(r => r == 1 || r == 255);
|
||||
|
||||
if (paste.AuthorUUID != user.UUID && !hasPrivilegedRole)
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to modify this paste." });
|
||||
if (user.Roles.Contains(255) && !user.TotpEnabled && _authSettings.Admins_Require_2FA)
|
||||
return StatusCode(403, new { success = false, message = "2FA is required to perform this action." });
|
||||
if (request.Title != null)
|
||||
paste.Title = request.Title;
|
||||
if (request.Syntax != null)
|
||||
paste.Syntax = request.Syntax;
|
||||
if (request.Visibility.HasValue)
|
||||
paste.Visibility = request.Visibility.Value;
|
||||
if (request.ExpiresAt.HasValue)
|
||||
paste.ExpiresAt = request.ExpiresAt.Value;
|
||||
|
||||
if (!await _pasteService.ValidateExpiresAt(paste.ExpiresAt))
|
||||
return BadRequest(new { success = false, message = "Invalid expiration time." });
|
||||
if (!await _pasteService.ValidateVisibility(paste.Visibility))
|
||||
return BadRequest(new { success = false, message = "Invalid visibility level. Must be between 0 and 2." });
|
||||
if (!await _pasteService.ValidateSyntax(paste.Syntax ?? "plaintext"))
|
||||
return BadRequest(new { success = false, message = "Invalid syntax." });
|
||||
if (!await _pasteService.ValidateTitle(paste.Title ?? ""))
|
||||
return BadRequest(new { success = false, message = $"Invalid title. Must be less than {_pasteSettings.MaxTitleLength} characters." });
|
||||
|
||||
var newPaste = await _pasteService.Edit(paste);
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = "Paste metadata updated successfully.",
|
||||
paste = new PasteResponseDto
|
||||
{
|
||||
ID = newPaste.ID,
|
||||
UUID = newPaste.UUID,
|
||||
Title = newPaste.Title,
|
||||
Size = newPaste.Size,
|
||||
TrueSize = newPaste.TrueSize,
|
||||
IsCompressed = newPaste.IsCompressed,
|
||||
Views = newPaste.Views,
|
||||
Syntax = newPaste.Syntax,
|
||||
Visibility = newPaste.Visibility,
|
||||
ExpiresAt = newPaste.ExpiresAt
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route("{id}")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> DeletePaste(string id)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null) return NotFound(new { success = false, message = "Paste not found." });
|
||||
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var hasPrivilegedRole = user.Roles.Any(r => r == 1 || r == 255);
|
||||
if (paste.AuthorUUID != user.UUID && !hasPrivilegedRole)
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to delete this paste." });
|
||||
if (user.Roles.Contains(255) && !user.TotpEnabled && _authSettings.Admins_Require_2FA)
|
||||
return StatusCode(403, new { success = false, message = "2FA is required to perform this action." });
|
||||
|
||||
bool result = await _pasteService.Delete(paste);
|
||||
if (!result) return StatusCode(500, new { success = false, message = "An error occurred while deleting the paste." });
|
||||
return Ok(new { success = true, message = "Paste deleted successfully." });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("{id}/view")]
|
||||
[Authorize(Policy = "NotBanned")]
|
||||
public async Task<IActionResult> RecordPasteView(string id)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null)
|
||||
return NotFound(new { success = false, message = "Paste not found." });
|
||||
|
||||
if (_pasteSettings.View_HMAC_Secret == null)
|
||||
return StatusCode(500, new { success = false, message = "View recording is not configured properly." });
|
||||
if (!string.IsNullOrWhiteSpace(_pasteSettings.View_Internal_API_Key)
|
||||
&& _pasteSettings.View_Internal_API_Key != Request.Headers["X-Internal-API-Key"])
|
||||
return Unauthorized(new { success = false, message = "Invalid API key." });
|
||||
|
||||
var result = await _pasteService.RecordView(paste, HttpContext);
|
||||
|
||||
if (result.paste is null && !result.alreadyExists)
|
||||
return StatusCode(500, new { success = false, message = "An error occurred while recording the paste view." });
|
||||
else if (result.alreadyExists)
|
||||
return Ok(new { success = true, message = "View already recorded." });
|
||||
|
||||
return Ok(new { success = true, message = "Paste view recorded." });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("{id}/report")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
public async Task<IActionResult> ReportPaste(string id, [FromBody] ReportDto request)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null)
|
||||
return NotFound(new { success = false, message = "Paste not found." });
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
Enum.TryParse<ReportType>(request.ReportType, true, out var reportType);
|
||||
if (!Enum.IsDefined(reportType))
|
||||
return BadRequest(new { success = false, message = "Invalid report type." });
|
||||
|
||||
if (!await _verificationService.VerifyAsync(new VerificationContext
|
||||
{
|
||||
Token = request.VerificationToken,
|
||||
Ip = HttpContext.GetRequestIP()
|
||||
}))
|
||||
return BadRequest(new { success = false, message = "Verification failed." });
|
||||
|
||||
|
||||
Report report = await _reportService.CreateReport(user.UUID, ReportTargetType.Paste, paste.PID, reportType, request.Description);
|
||||
if (report == null)
|
||||
return StatusCode(500, new { success = false, message = "An error occurred while reporting the paste." });
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = "Paste reported successfully.",
|
||||
report = new ReportResponseDto
|
||||
{
|
||||
ReportID = report.ReportID,
|
||||
Type = report.Type,
|
||||
Status = report.Status,
|
||||
Description = report.Description,
|
||||
CreatedAt = report.CreatedAt,
|
||||
UpdatedAt = report.UpdatedAt,
|
||||
ReporterUUID = report.ReporterUUID,
|
||||
TargetType = report.TargetType,
|
||||
UserUUID = report.UserUUID
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
[Route("{id}/report/{reportId}")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
public async Task<IActionResult> ModifyPasteReport(string id, int reportId, [FromBody] ReportDto request)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null)
|
||||
return NotFound(new { success = false, message = "Paste not found." });
|
||||
|
||||
var report = await _reportService.GetReportByID(reportId);
|
||||
if (report == null || report.TargetType != ReportTargetType.Paste || report.PastePID != paste.PID)
|
||||
return NotFound(new { success = false, message = "Report not found." });
|
||||
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var hasPrivilegedRole = user.Roles.Any(r => r == 1 || r == 255);
|
||||
if (report.ReporterUUID != user.UUID && !hasPrivilegedRole)
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to modify this report." });
|
||||
|
||||
Enum.TryParse<ReportType>(request.ReportType, true, out var reportType);
|
||||
if (!Enum.IsDefined(reportType))
|
||||
return BadRequest(new { success = false, message = "Invalid report type." });
|
||||
|
||||
report.Type = reportType;
|
||||
report.Description = request.Description;
|
||||
|
||||
var updatedReport = await _reportService.UpdateReport(report);
|
||||
if (updatedReport == null)
|
||||
return StatusCode(500, new { success = false, message = "An error occurred while updating the report." });
|
||||
|
||||
return Ok(new { success = true, message = "Report updated successfully." });
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route("{id}/report/{reportId}")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
public async Task<IActionResult> DeletePasteReport(string id, int reportId)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null)
|
||||
return NotFound(new { success = false, message = "Paste not found." });
|
||||
|
||||
var report = await _reportService.GetReportByID(reportId);
|
||||
if (report == null || report.TargetType != ReportTargetType.Paste || report.PastePID != paste.PID)
|
||||
return NotFound(new { success = false, message = "Report not found." });
|
||||
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var hasPrivilegedRole = user.Roles.Any(r => r == 1 || r == 255);
|
||||
if (report.ReporterUUID != user.UUID && !hasPrivilegedRole)
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to delete this report." });
|
||||
|
||||
if (user.Roles.Contains(255) && !user.TotpEnabled && _authSettings.Admins_Require_2FA)
|
||||
return StatusCode(403, new { success = false, message = "2FA is required to perform this action." });
|
||||
|
||||
bool result = await _reportService.DeleteReport(report);
|
||||
if (!result)
|
||||
return StatusCode(500, new { success = false, message = "An error occurred while deleting the report." });
|
||||
|
||||
return Ok(new { success = true, message = "Report deleted successfully." });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("recent")]
|
||||
public async Task<IActionResult> GetRecentPastes()
|
||||
{
|
||||
var results = await _pasteService.GetList(0, 50, true);
|
||||
return Ok(results.Select(p => new PasteResponseDto
|
||||
{
|
||||
ID = p.ID,
|
||||
UUID = p.UUID,
|
||||
Title = p.Title,
|
||||
Size = p.Size,
|
||||
TrueSize = p.TrueSize,
|
||||
IsCompressed = p.IsCompressed,
|
||||
Views = p.Views,
|
||||
Syntax = p.Syntax,
|
||||
Visibility = p.Visibility,
|
||||
ExpiresAt = p.ExpiresAt,
|
||||
EditedAt = p.EditedAt,
|
||||
Author = p.User != null && p.User.Visibility == 0 ? new UserSimpleDto
|
||||
{
|
||||
UID = p.User.UID,
|
||||
UUID = p.User.UUID,
|
||||
Username = p.User.Username,
|
||||
DisplayName = p.User.DisplayName,
|
||||
Visibility = p.User.Visibility,
|
||||
Roles = p.User.Roles
|
||||
} : null
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[EnableRateLimiting("NoLimit")]
|
||||
[Route("info")]
|
||||
public IActionResult GetCreatePasteOptions()
|
||||
{
|
||||
return Ok(new PasteOptionsDto
|
||||
{
|
||||
Syntaxes = _pasteSettings.ValidSyntaxLanguages,
|
||||
Visibilities =
|
||||
[
|
||||
new() { Value = 0, DisplayName = "Public" },
|
||||
new() { Value = 1, DisplayName = "Unlisted" },
|
||||
new() { Value = 2, DisplayName = "Private" }
|
||||
],
|
||||
MaxTitleLength = _pasteSettings.MaxTitleLength,
|
||||
MaxPasteSize = _pasteSettings.MaxPasteSizeInBytes,
|
||||
RequiresVerification = _pasteSettings.RequiresVerfication
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using SharpbinV3.Server.Data.Entities;
|
||||
using SharpbinV3.Server.DTOs.Report;
|
||||
using SharpbinV3.Server.Extensions;
|
||||
using SharpbinV3.Server.Services;
|
||||
|
||||
namespace SharpbinV3.Server.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ReportController(ReportService reportService) : Controller
|
||||
{
|
||||
[Route("{reportId:int}")]
|
||||
[HttpGet]
|
||||
[EnableRateLimiting("Sliding")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> GetReportById(int reportId)
|
||||
{
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user is null)
|
||||
return Unauthorized(new { success = false, message = "You must be logged in to view reports." });
|
||||
|
||||
var report = await reportService.GetReportByID(reportId);
|
||||
if (report is null)
|
||||
return NotFound(new { success = false, message = "Report not found." });
|
||||
|
||||
var hasPrivilegedRole = user.Roles.Any(r => r == 1 || r == 255);
|
||||
if (!hasPrivilegedRole && report.ReporterUUID != user.UUID)
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to view this report." });
|
||||
|
||||
var (Username, DisplayName) = await reportService.GetReporterInfo(report.ReporterUUID);
|
||||
|
||||
return Ok(new ReportResponseDto
|
||||
{
|
||||
ReportID = report.ReportID,
|
||||
Type = report.Type,
|
||||
Status = report.Status,
|
||||
Description = report.Description,
|
||||
CreatedAt = report.CreatedAt,
|
||||
UpdatedAt = report.UpdatedAt,
|
||||
ReporterUUID = report.ReporterUUID,
|
||||
ReporterUsername = Username,
|
||||
ReporterDisplayName = DisplayName,
|
||||
TargetType = report.TargetType,
|
||||
PasteId = report.Paste?.ID,
|
||||
PasteTitle = report.Paste?.Title,
|
||||
UserUUID = report.UserUUID,
|
||||
TargetUsername = report.User?.Username,
|
||||
TargetDisplayName = report.User?.DisplayName
|
||||
});
|
||||
}
|
||||
|
||||
[Route("{reportId:int}")]
|
||||
[HttpPatch]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> UpdateReport(int reportId, [FromBody] ReportUpdateDto request)
|
||||
{
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user is null)
|
||||
return Unauthorized(new { success = false, message = "You must be logged in to update reports." });
|
||||
if (!user.Roles.Contains(1) && !user.Roles.Contains(255))
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to update reports." });
|
||||
|
||||
var report = await reportService.GetReportByID(reportId);
|
||||
if (report is null)
|
||||
return NotFound(new { success = false, message = "Report not found." });
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Type))
|
||||
{
|
||||
Enum.TryParse<ReportType>(request.Type, true, out var reportType);
|
||||
if (!Enum.IsDefined(reportType))
|
||||
return BadRequest(new { success = false, message = "Invalid report type." });
|
||||
report.Type = reportType;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.Status))
|
||||
{
|
||||
Enum.TryParse<ReportStatus>(request.Status, true, out var reportStatus);
|
||||
if (!Enum.IsDefined(reportStatus))
|
||||
return BadRequest(new { success = false, message = "Invalid report status." });
|
||||
report.Status = reportStatus;
|
||||
}
|
||||
|
||||
if (request.Description != null)
|
||||
report.Description = request.Description;
|
||||
|
||||
report.UpdatedAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
var updated = await reportService.UpdateReport(report);
|
||||
var (Username, DisplayName) = await reportService.GetReporterInfo(updated.ReporterUUID);
|
||||
|
||||
return Ok(new ReportResponseDto
|
||||
{
|
||||
ReportID = updated.ReportID,
|
||||
Type = updated.Type,
|
||||
Status = updated.Status,
|
||||
Description = updated.Description,
|
||||
CreatedAt = updated.CreatedAt,
|
||||
UpdatedAt = updated.UpdatedAt,
|
||||
ReporterUUID = updated.ReporterUUID,
|
||||
ReporterUsername = Username,
|
||||
ReporterDisplayName = DisplayName,
|
||||
TargetType = updated.TargetType,
|
||||
PasteId = updated.Paste?.ID,
|
||||
PasteTitle = updated.Paste?.Title,
|
||||
UserUUID = updated.UserUUID,
|
||||
TargetUsername = updated.User?.Username,
|
||||
TargetDisplayName = updated.User?.DisplayName
|
||||
});
|
||||
}
|
||||
|
||||
[Route("options")]
|
||||
[HttpGet]
|
||||
public IActionResult GetReportOptions()
|
||||
{
|
||||
var validTypes = Enum.GetNames<ReportType>();
|
||||
var statuses = Enum.GetNames<ReportStatus>();
|
||||
return Ok(new ReportOptionsDto { Types = validTypes, Statuses = statuses });
|
||||
}
|
||||
|
||||
[Route("pastes")]
|
||||
[HttpGet]
|
||||
[EnableRateLimiting("Sliding")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> GetReportsForPastes([FromQuery] ReportQuery request)
|
||||
{
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user is null)
|
||||
return Unauthorized(new { success = false, message = "You must be logged in to view reports." });
|
||||
if (!user.Roles.Contains(1) && !user.Roles.Contains(255))
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to view pastes." });
|
||||
|
||||
var query = request with
|
||||
{
|
||||
Page = Math.Max(request.Page, 1),
|
||||
PageSize = Math.Clamp(request.PageSize, 1, 100),
|
||||
UserUUID = null
|
||||
};
|
||||
|
||||
var reports = await reportService.GetPasteReports(query);
|
||||
var totalCount = await reportService.GetReportCount(query);
|
||||
var totalPages = (int)Math.Ceiling(totalCount / (double)query.PageSize);
|
||||
return Ok(new
|
||||
{
|
||||
Reports = reports,
|
||||
Pagination = new
|
||||
{
|
||||
query.Page,
|
||||
query.PageSize,
|
||||
TotalCount = totalCount,
|
||||
TotalPages = totalPages
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Route("users")]
|
||||
[HttpGet]
|
||||
[EnableRateLimiting("Sliding")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> GetReportsForUsers([FromQuery] ReportQuery request)
|
||||
{
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user is null)
|
||||
return Unauthorized(new { success = false, message = "You must be logged in to view reports." });
|
||||
if (!user.Roles.Contains(1) && !user.Roles.Contains(255))
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to view users." });
|
||||
|
||||
var query = request with
|
||||
{
|
||||
Page = Math.Max(request.Page, 1),
|
||||
PageSize = Math.Clamp(request.PageSize, 1, 100),
|
||||
PastePID = null,
|
||||
PasteId = null
|
||||
};
|
||||
|
||||
var reports = await reportService.GetUserReports(query);
|
||||
var totalCount = await reportService.GetReportCount(query);
|
||||
var totalPages = (int)Math.Ceiling(totalCount / (double)query.PageSize);
|
||||
return Ok(new
|
||||
{
|
||||
Reports = reports,
|
||||
Pagination = new
|
||||
{
|
||||
query.Page,
|
||||
query.PageSize,
|
||||
TotalCount = totalCount,
|
||||
TotalPages = totalPages
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Route("all")]
|
||||
[HttpGet]
|
||||
[EnableRateLimiting("Sliding")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> GetAllReports(
|
||||
[FromQuery] Guid? reporterUuid,
|
||||
[FromQuery] ReportTargetType? targetType,
|
||||
[FromQuery] ReportType? type,
|
||||
[FromQuery] ReportStatus? status,
|
||||
[FromQuery] int page = 1,
|
||||
[FromQuery] int pageSize = 20)
|
||||
{
|
||||
var user = HttpContext.GetJwtUser();
|
||||
if (user is null)
|
||||
return Unauthorized(new { success = false, message = "You must be logged in to view reports." });
|
||||
if (!user.Roles.Contains(1) && !user.Roles.Contains(255))
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to view reports." });
|
||||
|
||||
var query = new ReportQuery
|
||||
{
|
||||
ReporterUUID = reporterUuid,
|
||||
TargetType = targetType,
|
||||
Type = type,
|
||||
Status = status,
|
||||
Page = Math.Max(page, 1),
|
||||
PageSize = Math.Clamp(pageSize, 1, 100)
|
||||
};
|
||||
|
||||
var reports = await reportService.GetReports(query);
|
||||
var totalCount = await reportService.GetReportCount(query);
|
||||
var totalPages = (int)Math.Ceiling(totalCount / (double)query.PageSize);
|
||||
return Ok(new
|
||||
{
|
||||
Reports = reports,
|
||||
Pagination = new
|
||||
{
|
||||
query.Page,
|
||||
query.PageSize,
|
||||
TotalCount = totalCount,
|
||||
TotalPages = totalPages
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,434 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SharpbinV3.Server.Data;
|
||||
using SharpbinV3.Server.Data.Entities;
|
||||
using SharpbinV3.Server.DTOs;
|
||||
using SharpbinV3.Server.DTOs.Paste;
|
||||
using SharpbinV3.Server.DTOs.Report;
|
||||
using SharpbinV3.Server.DTOs.User;
|
||||
using SharpbinV3.Server.Extensions;
|
||||
using SharpbinV3.Server.Services;
|
||||
using SharpbinV3.Server.Services.Verification;
|
||||
using SharpbinV3.Server.Services.Verification.Providers;
|
||||
using SharpbinV3.Server.Settings;
|
||||
|
||||
namespace SharpbinV3.Server.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class UserController(UserService userService, AppDbContext db, TotpVerificationProvider totp,
|
||||
VerificationService verificationService, ReportService reportServer, IOptions<AuthSettings> authSettings) : ControllerBase
|
||||
{
|
||||
private readonly UserService _userService = userService;
|
||||
private readonly AppDbContext _db = db;
|
||||
private readonly TotpVerificationProvider _totp = totp;
|
||||
private readonly VerificationService _verificationService = verificationService;
|
||||
private readonly ReportService _reportService = reportServer;
|
||||
private readonly AuthSettings _authSettings = authSettings.Value;
|
||||
|
||||
[HttpGet("{username}")]
|
||||
public async Task<IActionResult> GetByUsername(string username, [FromQuery] int page = 1)
|
||||
{
|
||||
var user = await _userService.GetByUsername(username, withPastes: true);
|
||||
return user == null ? NotFound(new { success = false, message = "User not found." }) : await BuildUserResponse(user, page);
|
||||
}
|
||||
|
||||
[HttpGet("uuid/{uuid}")]
|
||||
public async Task<IActionResult> GetByUUID(Guid uuid, [FromQuery] int page = 1)
|
||||
{
|
||||
var user = await _userService.GetByUUID(uuid, withPastes: true);
|
||||
return user == null ? NotFound(new { success = false, message = "User not found." }) : await BuildUserResponse(user, page);
|
||||
}
|
||||
|
||||
[HttpGet("me")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetMe([FromQuery] int page = 1)
|
||||
{
|
||||
var userUUID = HttpContext.User?.FindFirst("uuid")?.Value;
|
||||
if (userUUID is null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var user = await _userService.GetByUUID(Guid.Parse(userUUID), withPastes: true);
|
||||
return user == null ? NotFound(new { success = false, message = "User not found." }) : await BuildUserResponse(user, page);
|
||||
}
|
||||
|
||||
[HttpPatch("uuid/{uuid}")]
|
||||
[Authorize]
|
||||
[EnableRateLimiting("Strict")]
|
||||
public async Task<IActionResult> UpdateByUUID(Guid uuid, [FromBody] UpdateUserDto updatedUser)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
var jwtUser = HttpContext.GetJwtUser();
|
||||
if (jwtUser == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var user = await _userService.GetByUUID(uuid);
|
||||
if (user == null)
|
||||
return NotFound(new { success = false, message = "User not found." });
|
||||
|
||||
if ((user.Roles.Contains(255) && !jwtUser.Roles.Contains(255)) || (!jwtUser.Roles.Any(r => r == 1 || r == 255) && user.UUID != jwtUser.UUID))
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to modify this user." });
|
||||
|
||||
if (jwtUser.Roles.Contains(255) && !jwtUser.TotpEnabled && _authSettings.Admins_Require_2FA)
|
||||
return StatusCode(403, new { success = false, message = "2FA is required to perform this action." });
|
||||
|
||||
user.DisplayName = updatedUser.DisplayName ?? user.DisplayName;
|
||||
if (jwtUser.Roles.Any(r => r == 255) || user.UUID == jwtUser.UUID) // only admins or self
|
||||
{
|
||||
user.Email = updatedUser.Email ?? user.Email;
|
||||
user.Visibility = updatedUser.Visibility ?? user.Visibility;
|
||||
}
|
||||
if (jwtUser.Roles.Contains(255))
|
||||
{
|
||||
if (updatedUser.Roles.Contains(255) && jwtUser.TotpEnabled)
|
||||
{
|
||||
if (string.IsNullOrEmpty(updatedUser.TotpCode) || !await _totp.VerifyAsync(new VerificationContext
|
||||
{
|
||||
UserUUID = jwtUser.UUID,
|
||||
Code = updatedUser.TotpCode
|
||||
}))
|
||||
{
|
||||
return Unauthorized(new { message = "Invalid TOTP code." });
|
||||
}
|
||||
}
|
||||
user.Roles = updatedUser.Roles ?? user.Roles;
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(new { message = "User updated successfully." });
|
||||
}
|
||||
|
||||
[HttpDelete("uuid/{uuid}")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
public async Task<IActionResult> DeleteByUUID(Guid uuid, [FromBody] DeleteUserDto dto)
|
||||
{
|
||||
var jwtUser = HttpContext.GetJwtUser();
|
||||
if (jwtUser == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var user = await _userService.GetByUUID(uuid);
|
||||
if (user == null)
|
||||
return NotFound(new { success = false, message = "User not found." });
|
||||
|
||||
if (!jwtUser.Roles.Any(r => r == 255) && user.UUID != jwtUser.UUID)
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to delete this user." });
|
||||
if (jwtUser.Roles.Contains(255) && !jwtUser.TotpEnabled && _authSettings.Admins_Require_2FA)
|
||||
return StatusCode(403, new { success = false, message = "2FA is required to perform this action." });
|
||||
|
||||
if (jwtUser.TotpEnabled)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dto.TotpCode) || !await _totp.VerifyAsync(new VerificationContext
|
||||
{
|
||||
UserUUID = jwtUser.UUID,
|
||||
Code = dto.TotpCode
|
||||
}))
|
||||
{
|
||||
return Unauthorized(new { message = "Invalid TOTP code." });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(dto.Token) || !await _verificationService.VerifyAsync(new VerificationContext
|
||||
{
|
||||
Token = dto.Token,
|
||||
Ip = HttpContext.GetRequestIP()
|
||||
}))
|
||||
{
|
||||
return Unauthorized(new { message = "Invalid verification token." });
|
||||
}
|
||||
}
|
||||
|
||||
_db.Users.Remove(user);
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(new { message = "User deleted successfully." });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("{uuid}/report")]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> ReportUser(Guid uuid, [FromBody] ReportDto request)
|
||||
{
|
||||
var reporter = HttpContext.GetJwtUser();
|
||||
if (reporter == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var reportedUser = await _userService.GetByUUID(uuid);
|
||||
if (reportedUser == null)
|
||||
return NotFound(new { success = false, message = "User not found." });
|
||||
if (reportedUser.UUID == reporter.UUID)
|
||||
return BadRequest(new { success = false, message = "You cannot report yourself." });
|
||||
Enum.TryParse<ReportType>(request.ReportType, true, out var reportType);
|
||||
if (!Enum.IsDefined(reportType))
|
||||
return BadRequest(new { success = false, message = "Invalid report type." });
|
||||
|
||||
if (!await _verificationService.VerifyAsync(new VerificationContext
|
||||
{
|
||||
Token = request.VerificationToken,
|
||||
Ip = HttpContext.GetRequestIP()
|
||||
}))
|
||||
return Unauthorized(new { success = false, message = "Invalid verification token." });
|
||||
|
||||
Report report = await _reportService.CreateReport(reporter.UUID, ReportTargetType.User, uuid, reportType, request.Description);
|
||||
if (report == null)
|
||||
return StatusCode(500, new { success = false, message = "An error occurred while creating the report." });
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = "User reported successfully.",
|
||||
report = new ReportResponseDto
|
||||
{
|
||||
ReportID = report.ReportID,
|
||||
Type = report.Type,
|
||||
Status = report.Status,
|
||||
Description = report.Description,
|
||||
CreatedAt = report.CreatedAt,
|
||||
UpdatedAt = report.UpdatedAt,
|
||||
ReporterUUID = report.ReporterUUID,
|
||||
TargetType = report.TargetType,
|
||||
UserUUID = report.UserUUID
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPatch]
|
||||
[Route("{uuid}/report/{reportId}")]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> UpdateUserReport(Guid uuid, int reportId, [FromBody] ReportDto request)
|
||||
{
|
||||
var jwtUser = HttpContext.GetJwtUser();
|
||||
if (jwtUser == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var user = await _userService.GetByUUID(uuid);
|
||||
if (user == null)
|
||||
return NotFound(new { success = false, message = "User not found." });
|
||||
|
||||
var report = await _reportService.GetReportByID(reportId);
|
||||
if (report == null || report.UserUUID != user.UUID || report.ReporterUUID != jwtUser.UUID)
|
||||
return NotFound(new { success = false, message = "Report not found." });
|
||||
|
||||
Enum.TryParse<ReportType>(request.ReportType, true, out var reportType);
|
||||
if (!Enum.IsDefined(reportType))
|
||||
return BadRequest(new { success = false, message = "Invalid report type." });
|
||||
|
||||
report.Type = reportType;
|
||||
report.Description = request.Description ?? report.Description;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
return Ok(new { success = true, message = "Report updated successfully." });
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
[Route("{uuid}/report/{reportId}")]
|
||||
[EnableRateLimiting("Sensitive")]
|
||||
[Authorize(Policy = "AuthAndNotBanned")]
|
||||
public async Task<IActionResult> DeleteUserReport(Guid uuid, int reportId)
|
||||
{
|
||||
var jwtUser = HttpContext.GetJwtUser();
|
||||
if (jwtUser == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var user = await _userService.GetByUUID(uuid);
|
||||
if (user == null)
|
||||
return NotFound(new { success = false, message = "User not found." });
|
||||
|
||||
var report = await _reportService.GetReportByID(reportId);
|
||||
if (report == null || report.UserUUID != user.UUID || report.ReporterUUID != jwtUser.UUID)
|
||||
return NotFound(new { success = false, message = "Report not found." });
|
||||
|
||||
var result = await _reportService.DeleteReport(report);
|
||||
if (!result)
|
||||
return StatusCode(500, new { success = false, message = "An error occurred while deleting the report." });
|
||||
|
||||
return Ok(new { success = true, message = "Report deleted successfully." });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
[Route("{uuid}/reports")]
|
||||
public async Task<IActionResult> GetUserReports(Guid uuid, [FromQuery] ReportQuery request)
|
||||
{
|
||||
var jwtUser = HttpContext.GetJwtUser();
|
||||
if (jwtUser == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var user = await _userService.GetByUUID(uuid);
|
||||
if (user == null)
|
||||
return NotFound(new { success = false, message = "User not found." });
|
||||
|
||||
if (!jwtUser.Roles.Any(r => r == 1 || r == 255))
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to view this user's reports." });
|
||||
|
||||
var query = request with
|
||||
{
|
||||
UserUUID = user.UUID,
|
||||
Page = Math.Max(request.Page, 1),
|
||||
PageSize = Math.Clamp(request.PageSize, 1, 100)
|
||||
};
|
||||
var reports = await _reportService.GetUserReports(query);
|
||||
var totalCount = await _reportService.GetReportCount(query);
|
||||
var totalPages = (int)Math.Ceiling(totalCount / (double)query.PageSize);
|
||||
return Ok(new
|
||||
{
|
||||
Reports = reports,
|
||||
Pagination = new
|
||||
{
|
||||
query.Page,
|
||||
query.PageSize,
|
||||
TotalCount = totalCount,
|
||||
TotalPages = totalPages
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
[Route("{uuid}/reports/submitted")]
|
||||
public async Task<IActionResult> GetUserSubmittedReports(Guid uuid, [FromQuery] ReportQuery request)
|
||||
{
|
||||
var jwtUser = HttpContext.GetJwtUser();
|
||||
if (jwtUser == null)
|
||||
return Unauthorized(new { success = false, message = "Invalid token." });
|
||||
|
||||
var user = await _userService.GetByUUID(uuid);
|
||||
if (user == null)
|
||||
return NotFound(new { success = false, message = "User not found." });
|
||||
|
||||
var isOwner = user.UUID == jwtUser.UUID;
|
||||
var hasPrivilegedRole = jwtUser.Roles.Any(r => r == 1 || r == 255);
|
||||
if (!isOwner && !hasPrivilegedRole)
|
||||
return StatusCode(403, new { success = false, message = "You do not have permission to view this user's submitted reports." });
|
||||
|
||||
var query = request with
|
||||
{
|
||||
ReporterUUID = user.UUID,
|
||||
Page = Math.Max(request.Page, 1),
|
||||
PageSize = Math.Clamp(request.PageSize, 1, 100)
|
||||
};
|
||||
|
||||
var reports = await _reportService.GetReports(query);
|
||||
var totalCount = await _reportService.GetReportCount(query);
|
||||
var totalPages = (int)Math.Ceiling(totalCount / (double)query.PageSize);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
Reports = reports,
|
||||
Pagination = new
|
||||
{
|
||||
query.Page,
|
||||
query.PageSize,
|
||||
TotalCount = totalCount,
|
||||
TotalPages = totalPages
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<IActionResult> BuildUserResponse(User user, int page = 1)
|
||||
{
|
||||
var isAuthenticatedUser = HttpContext.User?.FindFirst("uuid")?.Value == user.UUID.ToString();
|
||||
var pasteQuery = _db.Pastes.AsNoTracking().Where(p => p.AuthorUUID == user.UUID);
|
||||
if (!isAuthenticatedUser)
|
||||
{
|
||||
if (user.Visibility == 2)
|
||||
return NotFound();
|
||||
else if (user.Visibility != 1)
|
||||
pasteQuery = pasteQuery.Where(p => p.Visibility == 0);
|
||||
}
|
||||
|
||||
if (page < 1)
|
||||
page = 1;
|
||||
const int pageSize = 50;
|
||||
var totalCount = await pasteQuery.CountAsync();
|
||||
var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
|
||||
var skip = (page - 1) * pageSize;
|
||||
|
||||
var pastes = await pasteQuery
|
||||
.OrderByDescending(p => p.UUID)
|
||||
.ThenByDescending(p => p.ID)
|
||||
.Skip(skip)
|
||||
.Take(pageSize)
|
||||
.Select(p => new PasteResponseDto
|
||||
{
|
||||
ID = p.ID,
|
||||
UUID = p.UUID,
|
||||
Title = p.Title,
|
||||
Syntax = p.Syntax,
|
||||
Size = p.Size,
|
||||
TrueSize = p.TrueSize,
|
||||
Views = p.Views,
|
||||
Visibility = p.Visibility,
|
||||
EditedAt = p.EditedAt,
|
||||
ExpiresAt = p.ExpiresAt
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var pagination = new
|
||||
{
|
||||
Page = page,
|
||||
PageSize = pageSize,
|
||||
TotalCount = totalCount,
|
||||
TotalPages = totalPages
|
||||
};
|
||||
|
||||
if (isAuthenticatedUser)
|
||||
{
|
||||
var reports = await _reportService.GetReports(new ReportQuery
|
||||
{
|
||||
ReporterUUID = user.UUID,
|
||||
Page = page,
|
||||
PageSize = pageSize
|
||||
});
|
||||
var reportsCount = await _reportService.GetReportCountByReporter(user.UUID);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
User = new UserResponseDto
|
||||
{
|
||||
UID = user.UID,
|
||||
Username = user.Username,
|
||||
UUID = user.UUID,
|
||||
DisplayName = user.DisplayName,
|
||||
Email = user.Email,
|
||||
LastLogin = user.LastLogin,
|
||||
Roles = user.Roles,
|
||||
Visibility = user.Visibility
|
||||
},
|
||||
Pastes = pastes,
|
||||
Reports = reports,
|
||||
Pagination = pagination,
|
||||
ReportsPagination = new
|
||||
{
|
||||
Page = page,
|
||||
PageSize = pageSize,
|
||||
TotalCount = reportsCount,
|
||||
TotalPages = (int)Math.Ceiling(reportsCount / (double)pageSize)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
User = new UserSimpleDto
|
||||
{
|
||||
UID = user.UID,
|
||||
Username = user.Username,
|
||||
UUID = user.UUID,
|
||||
DisplayName = user.DisplayName,
|
||||
Roles = user.Roles,
|
||||
Visibility = user.Visibility
|
||||
},
|
||||
Pastes = pastes,
|
||||
Pagination = pagination
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
namespace SharpbinV3.Server.DTOs.Auth
|
||||
{
|
||||
public class LoginResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Token { get; set; } = string.Empty;
|
||||
public string RefreshToken { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class TokenRefreshResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string? Message { get; set; }
|
||||
public TokenData? Token { get; set; }
|
||||
}
|
||||
|
||||
public class TokenData
|
||||
{
|
||||
public string? Token { get; set; }
|
||||
public string? RefreshToken { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace SharpbinV3.Server.DTOs.Auth
|
||||
{
|
||||
public class CreateJWT
|
||||
{
|
||||
public string? Token { get; set; }
|
||||
public string? RefreshToken { get; set; }
|
||||
public bool Success { get; set; }
|
||||
public List<string>? Errors { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace SharpbinV3.Server.DTOs.Auth
|
||||
{
|
||||
public class DisableTotpDto
|
||||
{
|
||||
public string Code { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace SharpbinV3.Server.DTOs.Auth
|
||||
{
|
||||
public sealed class EnableTotpDto
|
||||
{
|
||||
public string Secret { get; set; } = string.Empty;
|
||||
public string Code { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SharpbinV3.Server.DTOs.Auth
|
||||
{
|
||||
public class RefreshTokenDto
|
||||
{
|
||||
[Required]
|
||||
public required string Token { get; set; }
|
||||
[Required]
|
||||
public required string RefreshToken { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SharpbinV3.Server.DTOs.Auth
|
||||
{
|
||||
public class TurnstileResponseDto
|
||||
{
|
||||
[JsonPropertyName("success")]
|
||||
public bool Success { get; set; }
|
||||
[JsonPropertyName("error-codes")]
|
||||
public string[]? ErrorCodes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using SharpbinV3.Server.DTOs.User;
|
||||
|
||||
namespace SharpbinV3.Server.DTOs.Paste
|
||||
{
|
||||
public class PasteResponseDto
|
||||
{
|
||||
public string ID { get; set; } = string.Empty;
|
||||
public Guid UUID { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Syntax { get; set; }
|
||||
public long Size { get; set; }
|
||||
public long TrueSize { get; set; }
|
||||
public bool IsCompressed { get; set; }
|
||||
public int Views { get; set; }
|
||||
public int Visibility { get; set; }
|
||||
public long? EditedAt { get; set; }
|
||||
public long ExpiresAt { get; set; }
|
||||
public int? ReportCount { get; set; }
|
||||
public UserSimpleDto? Author { get; set; }
|
||||
}
|
||||
|
||||
public class PasteCreatedResponseDto
|
||||
{
|
||||
public string ID { get; set; } = string.Empty;
|
||||
public Guid UUID { get; set; }
|
||||
public bool IsCompressed { get; set; }
|
||||
public long Size { get; set; }
|
||||
public long TrueSize { get; set; }
|
||||
public long ExpiresAt { get; set; }
|
||||
}
|
||||
|
||||
public class PasteOptionsDto
|
||||
{
|
||||
public string[] Syntaxes { get; set; } = [];
|
||||
public List<PasteVisibilityOptionDto> Visibilities { get; set; } = [];
|
||||
public int MaxTitleLength { get; set; }
|
||||
public long MaxPasteSize { get; set; }
|
||||
public bool RequiresVerification { get; set; }
|
||||
}
|
||||
|
||||
public class PasteVisibilityOptionDto
|
||||
{
|
||||
public int Value { get; set; }
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user