Small API Improvements

This commit is contained in:
Lncvrt committed 2025-03-02 13:11:20 -07:00
1 parent b5aa0fd219
commit c2fb61afaa
18 files changed
+43 -73

No files matched your search

+4 -6
View File
@@ -2,10 +2,10 @@
require '../config/config.php';
require '../incl/main.php';
$old_displayname = isset($_POST['olddisplayname']) ? $_POST['olddisplayname'] : '';
$new_displayname = isset($_POST['newdisplayname']) ? $_POST['newdisplayname'] : '';
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$old_displayname = $_POST['olddisplayname'] ?? '';
$new_displayname = $_POST['newdisplayname'] ?? '';
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ??'';
if (empty($username) || empty($old_displayname) || empty($new_displayname) || empty($password)) {
http_response_code(400);
@@ -17,7 +17,6 @@ if (strlen($new_displayname) < 3 || strlen($new_displayname) > 32) {
http_response_code(400);
header('Content-Type: application/json');
die(json_encode(['success' => 'false', 'responsae' => 'New Display Name must be between 3 and 32 characters']));
exit;
}
$conn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
@@ -56,7 +55,6 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode(['success' => 'false', 'response' => 'User not found']));
}
$stmt->close();
$conn->close();
?>
+3 -4
View File
@@ -2,9 +2,9 @@
require '../config/config.php';
require '../incl/main.php';
$username = isset($_POST['username']) ? $_POST['username'] : '';
$old_password = isset($_POST['oldpassword']) ? $_POST['oldpassword'] : '';
$new_password = isset($_POST['newpassword']) ? $_POST['newpassword'] : '';
$username = $_POST['username'] ?? '';
$old_password = $_POST['oldpassword'] ?? '';
$new_password = $_POST['newpassword'] ?? '';
if (empty($username) || empty($old_password) || empty($new_password)) {
http_response_code(400);
@@ -57,7 +57,6 @@ if ($result->num_rows > 0) {
http_response_code(404);
die(json_encode(['success' => 'false', 'response' => 'User not found']));
}
$stmt->close();
$conn->close();
?>
+3 -4
View File
@@ -2,9 +2,9 @@
require '../config/config.php';
require '../incl/main.php';
$old_username = isset($_POST['oldusername']) ? $_POST['oldusername'] : '';
$new_username = isset($_POST['newusername']) ? $_POST['newusername'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$old_username = $_POST['oldusername'] ?? '';
$new_username = $_POST['newusername'] ?? '';
$password = $_POST['password'] ?? '';
if (empty($old_username) || empty($new_username) || empty($password)) {
http_response_code(400);
@@ -54,7 +54,6 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode(['success' => 'false', 'response' => 'User not found']));
}
$stmt->close();
$conn->close();
?>
+1 -4
View File
@@ -14,7 +14,7 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$apikey = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
$apikey = $_SERVER['HTTP_KEY'] ?? '';
if (isset($apikey) && empty($apikey)) {
$response = [
@@ -47,7 +47,4 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode($response));
}
$stmt->close();
$conn->close();
?>
+1 -4
View File
@@ -23,7 +23,7 @@ function generateRandomString($length) {
return $randomString;
}
$session = isset($_COOKIE['session']) ? $_COOKIE['session'] : '';
$session = $_COOKIE['session'] ?? '';
if (isset($session) && empty($session)) {
$response = [
@@ -64,7 +64,4 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode($response));
}
$stmt->close();
$conn->close();
?>
+1 -1
View File
@@ -15,7 +15,7 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$session = isset($_COOKIE['session']) ? $_COOKIE['session'] : '';
$session = $_COOKIE['session'] ?? '';
$stmt = $conn->prepare("SELECT * FROM users WHERE session = ?");
$stmt->bind_param("s", $session);
+1 -4
View File
@@ -14,7 +14,7 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$session = isset($_COOKIE['session']) ? $_COOKIE['session'] : '';
$session = $_COOKIE['session'] ?? '';
if (isset($session) && empty($session)) {
$response = [
@@ -51,7 +51,4 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode($response));
}
$stmt->close();
$conn->close();
?>
+1 -1
View File
@@ -14,7 +14,7 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$session = isset($_COOKIE['session']) ? $_COOKIE['session'] : '';
$session = $_COOKIE['session'] ?? '';
if (isset($session) && empty($session)) {
$response = [
+1 -1
View File
@@ -14,7 +14,7 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$key = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
$key = $_SERVER['HTTP_KEY'] ?? '';
$stmt = $conn->prepare("SELECT * FROM users WHERE api_key = ?");
$stmt->bind_param("s", $key);
+7 -11
View File
@@ -15,12 +15,12 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$apiKey = isset($_POST['key']) ? $_POST['key'] : null;
$session = isset($_COOKIE['session']) ? $_COOKIE['session'] : null;
$country = isset($_POST['country']) ? $_POST['country'] : null;
$timezone = isset($_POST['timezone']) ? $_POST['timezone'] : null;
$dateformat = isset($_POST['dateformat']) ? $_POST['dateformat'] : null;
$timeformat = isset($_POST['timeformat']) ? $_POST['timeformat'] : null;
$apiKey = $_POST['key'] ?? null;
$session = $_COOKIE['session'] ?? null;
$country = $_POST['country'] ?? null;
$timezone = $_POST['timezone'] ?? null;
$dateformat = $_POST['dateformat'] ?? null;
$timeformat = $_POST['timeformat'] ?? null;
$query = "UPDATE users SET ";
$params = [];
@@ -31,7 +31,6 @@ if ($country !== null) {
if (!in_array($country, $countries)) {
$country = null;
die('{"success": false, "response": "Invalid country" }');
return;
}
$query .= "country = ?, ";
@@ -141,7 +140,4 @@ if ($stmt->execute()) {
header('Content-Type: application/json');
die(json_encode($response));
}
$stmt->close();
$stmt->close();
$conn->close();
?>
+2 -3
View File
@@ -18,8 +18,8 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$key = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
$session = isset($_COOKIE['session']) ? $_COOKIE['session'] : '';
$key = $_SERVER['HTTP_KEY'] ?? '';
$session = $_COOKIE['session'] ?? '';
if (!empty($key)) {
$sql = "SELECT uid FROM users WHERE api_key = ?";
@@ -88,5 +88,4 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
echo json_encode($response);
?>
+7 -6
View File
@@ -15,12 +15,12 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$apiKey = isset($_POST['key']) ? $_POST['key'] : null;
$session = isset($_COOKIE['session']) ? $_COOKIE['session'] : null;
$password = null;//isset($_POST['password']) ? $_POST['password'] : null;
$spoiler = isset($_POST['spoiler']) ? $_POST['spoiler'] : null;
$filename = isset($_POST['filename']) ? $_POST['filename'] : null;
$fileId = isset($_POST['fileId']) ? $_POST['fileId'] : null;
$apiKey = $_POST['key'] ?? null;
$session = $_COOKIE['session'] ?? null;
$password = null;//$_POST['password'] ?? null;
$spoiler = $_POST['spoiler'] ?? null;
$filename = $_POST['filename'] ?? null;
$fileId = $_POST['fileId'] ?? null;
$query = "UPDATE uploads SET ";
$params = [];
@@ -87,3 +87,4 @@ if ($password !== null || $filename !== null) {
header('Content-Type: application/json');
die(json_encode($response));
?>
+2 -5
View File
@@ -15,8 +15,8 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$apikey = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
$fileid = isset($_SERVER['HTTP_FILEID']) ? $_SERVER['HTTP_FILEID'] : '';
$apikey = $_SERVER['HTTP_KEY'] ?? '';
$fileid = $_SERVER['HTTP_FILEID'] ?? '';
if (empty($apikey) || empty($fileid)) {
$response = [
@@ -82,7 +82,4 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode($response));
}
$stmt->close();
$conn->close();
?>
+1 -4
View File
@@ -14,7 +14,7 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$apikey = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
$apikey = $_SERVER['HTTP_KEY'] ?? '';
$stmt = $conn->prepare("SELECT uid FROM users WHERE api_key = ?");
$stmt->bind_param("s", $apikey);
@@ -60,7 +60,4 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode($response));
}
$stmt->close();
$conn->close();
?>
+2 -5
View File
@@ -15,8 +15,8 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$apikey = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
$uid = isset($_SERVER['HTTP_UID']) ? $_SERVER['HTTP_UID'] : '';
$apikey = $_SERVER['HTTP_KEY'] ?? '';
$uid = $_SERVER['HTTP_UID'] ?? '';
if (empty($apikey)) {
$response = [
@@ -89,7 +89,4 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode($response));
}
$stmt->close();
$conn->close();
?>
+1 -3
View File
@@ -4,7 +4,7 @@ require '../incl/main.php';
$ip = $_SERVER['REMOTE_ADDR'];
$token = isset($_POST['captcha_token']) ? $_POST['captcha_token'] : '';
$token = $_POST['captcha_token'] ?? '';
$url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
@@ -130,8 +130,6 @@ if ($result->num_rows > 0) {
header('Content-Type: application/json');
die(json_encode($response));
}
$stmt->close();
$conn->close();
?>
+4 -6
View File
@@ -4,7 +4,7 @@ require '../incl/main.php';
$ip = $_SERVER['REMOTE_ADDR'];
$token = isset($_POST['captcha_token']) ? $_POST['captcha_token'] : '';
$token = $_POST['captcha_token'] ?? '';
$url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
@@ -62,10 +62,10 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$request_username = isset($_POST['username']) ? $_POST['username'] : '';
$request_username = $_POST['username'] ?? '';
$request_displayname = (isset($_POST['displayname']) && !empty($_POST['displayname'])) ? $_POST['displayname'] : $request_username;
$request_password = isset($_POST['password']) ? $_POST['password'] : '';
$request_email = isset($_POST['email']) ? $_POST['email'] : '';
$request_password = $_POST['password'] ?? '';
$request_email = $_POST['email'] ?? '';
if (empty($request_username) || empty($request_password) || empty($request_email)) {
$response = [
@@ -235,8 +235,6 @@ if ($result->num_rows > 0) {
http_response_code(200);
echo json_encode($response);
}
$stmt->close();
$conn->close();
?>
+1 -1
View File
@@ -27,7 +27,7 @@ if ($conn->connect_error) {
die(json_encode($response));
}
$key = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
$key = $_SERVER['HTTP_KEY'] ?? '';
if ($_COOKIE['session']) {
$sql = "SELECT uid FROM users WHERE session = ?";