commit 4f16f1b909d34425a1d6f35d7b12b42e1cd1b71e
parent 8738f816e72e8d1d897fc13029d7bdeae49680eb
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sat, 26 Oct 2024 13:44:57 +0200
feat: write JSON response in REST API
Diffstat:
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/api/new.php b/api/new.php
@@ -37,7 +37,12 @@
/* run authentification method. exit immediately if it fails */
$auth = auth_user($user, $token, -1);
if ($auth !== true) {
- exit("You could not be authenticated!");
+ exit(
+ "{" .
+ "\"status\": \"error\"," .
+ "\"message\": \"You could not be authenticated!\"" .
+ "}"
+ );
}
/* if category is unset, set it! */
@@ -72,10 +77,20 @@
);
if ($written === true) {
- echo "Written as " . $user . "/" . $category . "/" . $filename;
- exit();
+ exit(
+ "{" .
+ "\"status\": \"success\"," .
+ "\"message\": \"Note written to " .
+ $user . "/" . $category . "/" . $filename . "\"" .
+ "}"
+ );
} else {
- exit("Writing failed!" . $written);
+ exit(
+ "{" .
+ "\"status\": \"error\"," .
+ "\"message\": \"File could not be written for unknown reasons\"" .
+ "}"
+ );
}
?>