-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.php
More file actions
executable file
·66 lines (58 loc) · 1.64 KB
/
Copy pathget.php
File metadata and controls
executable file
·66 lines (58 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// Include private functions
require_once 'private.php';
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
global $secret_key;
$name = isset($_GET['name']) ? trim($_GET['name']) : '';
$key = isset($_GET['key']) ? $_GET['key'] : 'default';
$isEdit = isset($_GET['edit']) ? $_GET['edit'] : '';
if (empty($name)) {
http_response_code(400);
echo json_encode([
"error_code" => 1,
"error_message" => "Need \"name\" parameter."
]);
exit;
}
// Get consolidated data
$storageData = getStorageData($key, $secret_key);
if (!isset($storageData[$name])) {
http_response_code(404);
echo json_encode([
"error_code" => 2,
"error_message" => "Data not found."
]);
exit;
}
$content = $storageData[$name];
// Check if content is a valid JSON string
$decodedContent = json_decode($content, true);
if (json_last_error() === JSON_ERROR_NONE) {
// If valid JSON, return as is
http_response_code(200);
if ($isEdit) {
http_response_code(200);
echo json_encode([
"error_code" => 0,
"content" => $content
]);
exit;
} else {
echo json_encode($decodedContent);
}
} else {
// If not valid JSON, return it as a string
http_response_code(200);
echo json_encode([
"error_code" => 0,
"content" => $content
]);
}
exit;
}
http_response_code(405);
echo json_encode([
"error_code" => 3,
"error_message" => "Method not allowed."
]);
?>