Hot fixes, changed every single writeasjsonasync to writeasync cause it would bug some other stuff,fixed the authentication api which for some reason redirected to lost paste????

This commit is contained in:
whoswhip
2024-10-19 00:46:19 -04:00
parent bdcc3a1dc6
commit eb542342c9
7 changed files with 116 additions and 117 deletions
+97 -97
View File
@@ -5,7 +5,7 @@ using Newtonsoft.Json.Linq;
using System.Data; using System.Data;
using System.Text; using System.Text;
using Sharpbin; using Sharpbin;
using System.Reflection;
class Program class Program
{ {
@@ -1015,7 +1015,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
else if (await IsLoggedInAsync(context.Request.Cookies["token"])) else if (await IsLoggedInAsync(context.Request.Cookies["token"]))
@@ -1025,7 +1025,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
} }
@@ -1038,14 +1038,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1057,7 +1057,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
var user = new User(); var user = new User();
@@ -1073,7 +1073,7 @@ class Program
{ {
context.Response.StatusCode = 404; context.Response.StatusCode = 404;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "User not found" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "User not found" }.ToString());
return; return;
} }
user = new User user = new User
@@ -1091,14 +1091,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "User is already banned" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "User is already banned" }.ToString());
return; return;
} }
if (user.Type == 255) if (user.Type == 255)
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Cannot ban an admin" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Cannot ban an admin" }.ToString());
return; return;
} }
var banUserCommand = connection.CreateCommand(); var banUserCommand = connection.CreateCommand();
@@ -1118,7 +1118,7 @@ class Program
await Logging.LogInfo($"Account {user.Username}({user.UUID}) has been banned by {loggedInUser.Username}({loggedInUser.UUID}) for {reason}"); await Logging.LogInfo($"Account {user.Username}({user.UUID}) has been banned by {loggedInUser.Username}({loggedInUser.UUID}) for {reason}");
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "User banned" }.ToString()); await context.Response.WriteAsync(new JObject { ["message"] = "User banned" }.ToString());
return; return;
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
app.MapPost("/api/accounts/admin/unban", async (HttpContext context) => app.MapPost("/api/accounts/admin/unban", async (HttpContext context) =>
@@ -1128,7 +1128,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
else if (await IsLoggedInAsync(context.Request.Cookies["token"])) else if (await IsLoggedInAsync(context.Request.Cookies["token"]))
@@ -1138,7 +1138,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
} }
@@ -1151,14 +1151,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1168,14 +1168,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
var user = await UnbanUUIDAsync(uuid); var user = await UnbanUUIDAsync(uuid);
await Logging.LogInfo($"Account {user.Username}({user.UUID}) has been unbanned by {loggedInUser.Username}({loggedInUser.UUID}) for {reason}"); await Logging.LogInfo($"Account {user.Username}({user.UUID}) has been unbanned by {loggedInUser.Username}({loggedInUser.UUID}) for {reason}");
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "User unbanned" }.ToString()); await context.Response.WriteAsync(new JObject { ["message"] = "User unbanned" }.ToString());
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
app.MapPost("/api/accounts/admin/change-password", async (HttpContext context) => app.MapPost("/api/accounts/admin/change-password", async (HttpContext context) =>
{ {
@@ -1184,7 +1184,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
else if (await IsLoggedInAsync(context.Request.Cookies["token"])) else if (await IsLoggedInAsync(context.Request.Cookies["token"]))
@@ -1194,7 +1194,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
} }
@@ -1207,14 +1207,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1228,7 +1228,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
var user = new User(); var user = new User();
@@ -1244,7 +1244,7 @@ class Program
{ {
context.Response.StatusCode = 404; context.Response.StatusCode = 404;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "User not found" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "User not found" }.ToString());
return; return;
} }
user = new User user = new User
@@ -1271,7 +1271,7 @@ class Program
await Logging.LogInfo($"Account {user.Username}({user.UUID}) has had their password changed by {loggedInUser.Username}({loggedInUser.UUID})"); await Logging.LogInfo($"Account {user.Username}({user.UUID}) has had their password changed by {loggedInUser.Username}({loggedInUser.UUID})");
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Password changed", ["password"] = newPassword }.ToString()); await context.Response.WriteAsync(new JObject { ["message"] = "Password changed", ["password"] = newPassword }.ToString());
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
app.MapPost("/api/accounts/admin/get", async (HttpContext context) => app.MapPost("/api/accounts/admin/get", async (HttpContext context) =>
{ {
@@ -1281,7 +1281,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
else if (await IsLoggedInAsync(context.Request.Cookies["token"])) else if (await IsLoggedInAsync(context.Request.Cookies["token"]))
@@ -1291,7 +1291,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
} }
@@ -1304,14 +1304,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1368,7 +1368,7 @@ class Program
else else
{ {
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(usersJson.ToString()); await context.Response.WriteAsync(usersJson.ToString());
} }
}).RequireRateLimiting("fixed-bigger"); }).RequireRateLimiting("fixed-bigger");
app.MapPost("/api/accounts/admin/search", async (HttpContext context) => app.MapPost("/api/accounts/admin/search", async (HttpContext context) =>
@@ -1379,7 +1379,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
else if (await IsLoggedInAsync(context.Request.Cookies["token"])) else if (await IsLoggedInAsync(context.Request.Cookies["token"]))
@@ -1389,7 +1389,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
} }
@@ -1402,14 +1402,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1465,7 +1465,7 @@ class Program
else else
{ {
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(usersJson.ToString()); await context.Response.WriteAsync(usersJson.ToString());
} }
}).RequireRateLimiting("fixed-bigger"); ; }).RequireRateLimiting("fixed-bigger"); ;
@@ -1487,7 +1487,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No content uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No content uploaded" }.ToString());
return; return;
} }
if (!string.IsNullOrEmpty(user.UUID)) if (!string.IsNullOrEmpty(user.UUID))
@@ -1506,7 +1506,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "User is banned" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "User is banned" }.ToString());
return; return;
} }
} }
@@ -1523,7 +1523,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1535,21 +1535,21 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Content or Title is too long" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Content or Title is too long" }.ToString());
return; return;
} }
if (visibility != "Public" && visibility != "Unlisted" && visibility != "Private") if (visibility != "Public" && visibility != "Unlisted" && visibility != "Private")
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid visibility" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid visibility" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(content) || string.IsNullOrWhiteSpace(content)) if (string.IsNullOrEmpty(content) || string.IsNullOrWhiteSpace(content))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
var paste = new Paste(); var paste = new Paste();
@@ -1561,14 +1561,14 @@ class Program
{ {
context.Response.StatusCode = 500; context.Response.StatusCode = 500;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Failed to create paste" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Failed to create paste" }.ToString());
return; return;
} }
if (!File.Exists($"pastes/{privatePaste.Id}.txt")) if (!File.Exists($"pastes/{privatePaste.Id}.txt"))
{ {
context.Response.StatusCode = 500; context.Response.StatusCode = 500;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Failed to create paste" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Failed to create paste" }.ToString());
return; return;
} }
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
@@ -1582,7 +1582,7 @@ class Program
Log _log = await Logging.LogRequestAsync(context); Log _log = await Logging.LogRequestAsync(context);
await Logging.LogInfo($"Private Paste created, {ConvertToBytes(privatePaste.Size ?? string.Empty)}, {privatePaste.Id} by {uploaderUUID}"); await Logging.LogInfo($"Private Paste created, {ConvertToBytes(privatePaste.Size ?? string.Empty)}, {privatePaste.Id} by {uploaderUUID}");
await context.Response.WriteAsJsonAsync(_responseJson.ToString()); await context.Response.WriteAsync(_responseJson.ToString());
return; return;
} }
else else
@@ -1595,7 +1595,7 @@ class Program
{ {
context.Response.StatusCode = 500; context.Response.StatusCode = 500;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Failed to create paste" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Failed to create paste" }.ToString());
return; return;
} }
@@ -1614,7 +1614,7 @@ class Program
await Logging.LogInfo($"Paste created, {ConvertToBytes(paste.Size ?? string.Empty)}, {paste.Id} by {uploaderUUID}"); await Logging.LogInfo($"Paste created, {ConvertToBytes(paste.Size ?? string.Empty)}, {paste.Id} by {uploaderUUID}");
await context.Response.WriteAsJsonAsync(responseJson.ToString()); await context.Response.WriteAsync(responseJson.ToString());
return; return;
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
@@ -1626,14 +1626,14 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
if (user.State != 0) if (user.State != 0)
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "User is banned/suspended" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "User is banned/suspended" }.ToString());
return; return;
} }
string requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync(); string requestBody = await new StreamReader(context.Request.Body).ReadToEndAsync();
@@ -1641,7 +1641,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
try try
@@ -1652,7 +1652,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1663,7 +1663,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
@@ -1679,7 +1679,7 @@ class Program
{ {
context.Response.StatusCode = 404; context.Response.StatusCode = 404;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Paste not found" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Paste not found" }.ToString());
return; return;
} }
var paste = new Paste var paste = new Paste
@@ -1694,7 +1694,7 @@ class Program
{ {
context.Response.StatusCode = 501; context.Response.StatusCode = 501;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Editing private pastes has not been implemented." }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Editing private pastes has not been implemented." }.ToString());
return; return;
} }
@@ -1705,7 +1705,7 @@ class Program
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Paste edited" }.ToString()); await context.Response.WriteAsync(new JObject { ["message"] = "Paste edited" }.ToString());
}); });
app.MapPost("/api/pastes/delete", async (HttpContext context) => app.MapPost("/api/pastes/delete", async (HttpContext context) =>
{ {
@@ -1716,14 +1716,14 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
try try
@@ -1734,7 +1734,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1743,7 +1743,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
using (var connection = new SqliteConnection("Data Source=pastes.sqlite")) using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
@@ -1759,7 +1759,7 @@ class Program
{ {
context.Response.StatusCode = 404; context.Response.StatusCode = 404;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Paste not found" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Paste not found" }.ToString());
return; return;
} }
string UUID = reader.GetString(6); string UUID = reader.GetString(6);
@@ -1778,7 +1778,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
@@ -1790,7 +1790,7 @@ class Program
File.Delete($"pastes/{id}.txt"); File.Delete($"pastes/{id}.txt");
await Logging.LogInfo($"Paste {id} deleted by {user.Username}({user.UUID})"); await Logging.LogInfo($"Paste {id} deleted by {user.Username}({user.UUID})");
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Paste deleted" }.ToString()); await context.Response.WriteAsync(new JObject { ["message"] = "Paste deleted" }.ToString());
} }
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
@@ -1803,7 +1803,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
try try
@@ -1814,7 +1814,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
var data = JObject.Parse(requestBody); var data = JObject.Parse(requestBody);
@@ -1883,7 +1883,7 @@ class Program
if (string.IsNullOrEmpty(parameters["html"])) if (string.IsNullOrEmpty(parameters["html"]))
{ {
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(pastesArray.ToString()); await context.Response.WriteAsync(pastesArray.ToString());
} }
else else
{ {
@@ -1938,7 +1938,7 @@ class Program
if (string.IsNullOrEmpty(parameters["html"])) if (string.IsNullOrEmpty(parameters["html"]))
{ {
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(pastes.ToString()); await context.Response.WriteAsync(pastes.ToString());
} }
else else
{ {
@@ -1957,14 +1957,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request" }.ToString());
return; return;
} }
if (!File.Exists($"pastes/{id}.txt")) if (!File.Exists($"pastes/{id}.txt"))
{ {
context.Response.StatusCode = 404; context.Response.StatusCode = 404;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Paste not found" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Paste not found" }.ToString());
return; return;
} }
@@ -1980,7 +1980,7 @@ class Program
{ {
context.Response.StatusCode = 404; context.Response.StatusCode = 404;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Paste not found" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Paste not found" }.ToString());
return; return;
} }
var paste = new Paste var paste = new Paste
@@ -2018,7 +2018,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
try try
@@ -2029,7 +2029,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
var data = JObject.Parse(body); var data = JObject.Parse(body);
@@ -2039,14 +2039,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
if (!File.Exists($"pastes/{pasteId}.txt")) if (!File.Exists($"pastes/{pasteId}.txt"))
{ {
context.Response.StatusCode = 404; context.Response.StatusCode = 404;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Paste not found" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Paste not found" }.ToString());
return; return;
} }
using (var connection = new SqliteConnection("Data Source=pastes.sqlite")) using (var connection = new SqliteConnection("Data Source=pastes.sqlite"))
@@ -2061,7 +2061,7 @@ class Program
{ {
context.Response.StatusCode = 404; context.Response.StatusCode = 404;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Paste not found" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Paste not found" }.ToString());
return; return;
} }
var paste = new PrivatePaste var paste = new PrivatePaste
@@ -2078,7 +2078,7 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid password" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid password" }.ToString());
return; return;
} }
} }
@@ -2087,7 +2087,7 @@ class Program
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["content"] = decryptedText }.ToString()); await context.Response.WriteAsync(new JObject { ["content"] = decryptedText }.ToString());
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
app.MapPost("/api/accounts/create", async (HttpContext context) => app.MapPost("/api/accounts/create", async (HttpContext context) =>
{ {
@@ -2101,7 +2101,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
Log log = await Logging.LogRequestAsync(context); Log log = await Logging.LogRequestAsync(context);
@@ -2112,21 +2112,21 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Already logged in" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Already logged in" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
if (!requestBody.Contains("username") || !requestBody.Contains("password") || context.Request.ContentType != "application/json") if (!requestBody.Contains("username") || !requestBody.Contains("password") || context.Request.ContentType != "application/json")
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
@@ -2138,7 +2138,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid Cloudflare Turnstile Token" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid Cloudflare Turnstile Token" }.ToString());
return; return;
} }
bool cfValid = await Turnstile.VerifyTurnstileToken(cfToken); bool cfValid = await Turnstile.VerifyTurnstileToken(cfToken);
@@ -2146,7 +2146,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid Cloudflare Turnstile Token" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid Cloudflare Turnstile Token" }.ToString());
return; return;
} }
@@ -2155,14 +2155,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password length" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid username or password length" }.ToString());
return; return;
} }
if (username.IndexOfAny(disallowed) != -1) if (username.IndexOfAny(disallowed) != -1)
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid characters in username" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid characters in username" }.ToString());
return; return;
} }
string token = string.Empty; string token = string.Empty;
@@ -2182,7 +2182,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Username already exists" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Username already exists" }.ToString());
return; return;
} }
else if (!reader.HasRows && !reader.IsClosed) else if (!reader.HasRows && !reader.IsClosed)
@@ -2226,7 +2226,7 @@ class Program
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await Logging.LogInfo($"Account {username} has been created"); await Logging.LogInfo($"Account {username} has been created");
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Account created" }.ToString()); await context.Response.WriteAsync(new JObject { ["message"] = "Account created" }.ToString());
}).RequireRateLimiting("fixed"); }).RequireRateLimiting("fixed");
@@ -2241,7 +2241,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid JSON" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid JSON" }.ToString());
return; return;
} }
Log log = await Logging.LogRequestAsync(context); Log log = await Logging.LogRequestAsync(context);
@@ -2250,21 +2250,21 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Already logged in" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Already logged in" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(requestBody)) if (string.IsNullOrEmpty(requestBody))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "No data uploaded" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "No data uploaded" }.ToString());
return; return;
} }
if (!requestBody.Contains("username") || !requestBody.Contains("password") || context.Request.ContentType != "application/json") if (!requestBody.Contains("username") || !requestBody.Contains("password") || context.Request.ContentType != "application/json")
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid request body" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid request body" }.ToString());
return; return;
} }
@@ -2276,7 +2276,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid Cloudflare Turnstile Token" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid Cloudflare Turnstile Token" }.ToString());
return; return;
} }
bool cfValid = await Turnstile.VerifyTurnstileToken(cfToken); bool cfValid = await Turnstile.VerifyTurnstileToken(cfToken);
@@ -2284,14 +2284,14 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid Cloudflare Turnstile Token" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid Cloudflare Turnstile Token" }.ToString());
return; return;
} }
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid username or password" }.ToString());
return; return;
} }
@@ -2310,7 +2310,7 @@ class Program
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid username or password" }.ToString());
return; return;
} }
if (BCrypt.Net.BCrypt.Verify(password, reader.GetString(3))) if (BCrypt.Net.BCrypt.Verify(password, reader.GetString(3)))
@@ -2346,25 +2346,25 @@ class Program
context.Response.StatusCode = 200; context.Response.StatusCode = 200;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await Logging.LogInfo($"Account {username} has logged in"); await Logging.LogInfo($"Account {username} has logged in");
await context.Response.WriteAsJsonAsync(new JObject { ["message"] = "Logged in" }.ToString()); await context.Response.WriteAsync(new JObject { ["message"] = "Logged in" }.ToString());
return; return;
} }
else else
{ {
context.Response.StatusCode = 400; context.Response.StatusCode = 400;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Invalid username or password" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Invalid username or password" }.ToString());
} }
} }
})).RequireRateLimiting("fixed"); })).RequireRateLimiting("fixed");
app.MapGet("/api/accounts/authenticated", (async (HttpContext context) => app.MapGet("/api/accounts/authenticate", (async (HttpContext context) =>
{ {
var token = context.Request.Cookies["token"] ?? context.Request.Headers["Authorization"]; var token = context.Request.Cookies["token"] ?? context.Request.Headers["Authorization"];
if (string.IsNullOrEmpty(token) || string.IsNullOrWhiteSpace(token)) if (string.IsNullOrEmpty(token) || string.IsNullOrWhiteSpace(token))
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
@@ -2373,14 +2373,14 @@ class Program
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
if (user.UUID == null) if (user.UUID == null)
{ {
context.Response.StatusCode = 401; context.Response.StatusCode = 401;
context.Response.ContentType = "application/json"; context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new JObject { ["error"] = "Unauthorized" }.ToString()); await context.Response.WriteAsync(new JObject { ["error"] = "Unauthorized" }.ToString());
return; return;
} }
+3 -3
View File
@@ -153,7 +153,7 @@
}).then(response => response.json()) }).then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.message != null) { if (result.message != null) {
createNotification(`${result.message} for ${reason}`); createNotification(`${result.message} for ${reason}`);
} else { } else {
@@ -174,7 +174,7 @@
}).then(response => response.json()) }).then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.message != null) { if (result.message != null) {
createNotification(`${result.message} for ${reason}`); createNotification(`${result.message} for ${reason}`);
} else { } else {
@@ -199,7 +199,7 @@
}).then(response => response.json()) }).then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.message != null) { if (result.message != null) {
createNotification(`${result.message} to ${result.password}`); createNotification(`${result.message} to ${result.password}`);
navigator.clipboard.writeText(result.password); navigator.clipboard.writeText(result.password);
+4 -5
View File
@@ -84,11 +84,10 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); if (obj.pasteId != null) {
if (result.pasteId != null) { window.location.href = `/${obj.pasteId}`;
window.location.href = `/${result.pasteId}`; } else if (obj.error != null) {
} else if (result.error != null) { notification(obj.error);
notification(result.error);
} }
}) })
}); });
+1 -1
View File
@@ -63,7 +63,7 @@
.then(response => response.json()) .then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
isLoggingIn = true; isLoggingIn = true;
if (result.message != null) { if (result.message != null) {
window.location.href = "/"; window.location.href = "/";
+5 -5
View File
@@ -67,8 +67,8 @@
const date = new Date(unixTimestamp * 1000); const date = new Date(unixTimestamp * 1000);
return date.toLocaleString(); return date.toLocaleString();
} }
function authenticated() { function authenticate() {
fetch('/api/accounts/authenticated') fetch('/api/accounts/authenticate')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
if (data.message == "Authenticated") { if (data.message == "Authenticated") {
@@ -126,7 +126,7 @@
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
fetchInfo(); fetchInfo();
authenticated(); authenticate();
const creationdateElement = document.getElementById('creationdate'); const creationdateElement = document.getElementById('creationdate');
const creationdateText = creationdateElement.innerText.trim(); const creationdateText = creationdateElement.innerText.trim();
const textElement = document.getElementById('text'); const textElement = document.getElementById('text');
@@ -197,7 +197,7 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.message != null) { if (result.message != null) {
createNotification(`Success: ${result.message}`); createNotification(`Success: ${result.message}`);
setTimeout(() => { setTimeout(() => {
@@ -265,7 +265,7 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.message != null) { if (result.message != null) {
const inputWrapper = document.getElementById('input-wrapper'); const inputWrapper = document.getElementById('input-wrapper');
inputWrapper.style.display = 'none'; inputWrapper.style.display = 'none';
+5 -5
View File
@@ -74,8 +74,8 @@
<script> <script>
info = ""; info = "";
editing = false; editing = false;
function authenticated() { function authenticate() {
fetch('/api/accounts/authenticated') fetch('/api/accounts/authenticate')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
if (data.message == "Authenticated") { if (data.message == "Authenticated") {
@@ -145,7 +145,7 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.content != null) { if (result.content != null) {
const textElement = document.getElementById('text'); const textElement = document.getElementById('text');
textElement.innerText = result.content; textElement.innerText = result.content;
@@ -219,7 +219,7 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.message != null) { if (result.message != null) {
createNotification(`Success: ${result.message}`); createNotification(`Success: ${result.message}`);
setTimeout(() => { setTimeout(() => {
@@ -245,7 +245,7 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.message != null) { if (result.message != null) {
createNotification(`Success: ${result.message}`); createNotification(`Success: ${result.message}`);
document.getElementById('text').innerText = text; document.getElementById('text').innerText = text;
+1 -1
View File
@@ -65,7 +65,7 @@
}) })
.then(response => response.json()) .then(response => response.json())
.then(obj => { .then(obj => {
const result = JSON.parse(obj); const result = obj;
if (result.message != null) { if (result.message != null) {
window.location.href = "/"; window.location.href = "/";
isLoggingIn = false; isLoggingIn = false;