-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes_backend.php
executable file
·133 lines (116 loc) · 3.96 KB
/
routes_backend.php
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
if (!isset($router)) die("Do not call this directly!");
use Data\Comments;
use Data\Medals\MedalsBeatmaps;
use Data\OsekaiUsers;
use Data\Post\Edit;
use Data\Post\Gallery;
use Data\Votes;
if (!function_exists('json_validate')) {
/**
* Validates a JSON string.
*
* @param string $json The JSON string to validate.
* @param int $depth Maximum depth. Must be greater than zero.
* @param int $flags Bitmask of JSON decode options.
* @return bool Returns true if the string is a valid JSON, otherwise false.
*/
function json_validate($json, $depth = 512, $flags = 0)
{
if (!is_string($json)) {
return false;
}
try {
json_decode($json, false, $depth, $flags | JSON_THROW_ON_ERROR);
return true;
} catch (JsonException $e) {
return false;
}
}
}
$router->post("/api/usersettings/set", function () {
if (!checkPermRequirement("account.edit"))
return;
if (requireLogin()) {
$value = $_POST['value'];
if (json_validate($value)) $value = json_decode($value, true);
echo Data\Settings::ApiSet($_POST['key'], $value)->ReturnJson();
}
});
/// =====================
/// Medals
/// =====================
$router->all("/api/medals/get_all", function () {
echo \Data\Medals::GetAll()->ReturnJson();
});
$router->all("/api/medals/{id}/save", function ($id) {
if (!requireLogin()) return;
if (!OsekaiUsers::HasPermission("medal.edit", false)) {
echo "no perms";
exit;
}
echo \Data\Medals::Save($id, $_REQUEST)->ReturnJson();
});
/// =====================
/// Medals Beatmaps
/// =====================
$router->all("/api/medals/beatmaps/{id}/delete", function ($id) {
if (!requireLogin()) return;
echo MedalsBeatmaps::Delete($id)->ReturnJson();
});
$router->all("/api/medals/beatmaps/{id}/admindelete", function ($id) {
if (!requireLogin()) return;
echo MedalsBeatmaps::AdminDelete($id)->ReturnJson();
});
$router->all("/api/medals/{id}/beatmaps", function ($id) {
echo MedalsBeatmaps::GetBeatmaps($id)->ReturnJson();
});
$router->all("/api/medals/beatmaps/{id}/report", function ($id) {
echo MedalsBeatmaps::ReportBeatmap($id, $_POST)->ReturnJson();
});
$router->all("/api/medals/{id}/packs", function ($id) {
echo MedalsBeatmaps::GetPacks($id)->ReturnJson();
});
$router->all("/api/medals/{id}/beatmap/add", function ($id) {
if (!requireLogin()) return;
echo MedalsBeatmaps::AddBeatmap($_POST['url'], $id, $_POST['note'])->ReturnJson();
});
/// =====================
/// Comments
/// =====================
$router->all("/api/comments/post", function ($id) {
if (!requireLogin()) return;
echo Comments::Post($_POST['id'], $_POST['table'], $_POST['text'])->ReturnJson();
});
$router->all("/api/comments/{id}/report", function ($id) {
echo Comments::Report($id, $_POST)->ReturnJson();
});
$router->all("/api/comments/{id}/delete", function ($id) {
if (!requireLogin()) return;
echo Comments::Delete($id)->ReturnJson();
});
$router->all("/api/comments/{id}/admindelete", function ($id) {
if (!requireLogin()) return;
echo Comments::AdminDelete($id)->ReturnJson();
});
$router->all("/api/comments/{id}/pin", function ($id) {
if (!requireLogin()) return;
echo Comments::Pin($id)->ReturnJson();
});
$router->all("/api/comments/{ref}/{section}/get", function ($ref, $section) {
echo Data\Comments::Get($section, $ref, $_POST['ParentID'])->ReturnJson();
});
$router->all("/api/comments/{ref}/{section}/send", function ($ref, $section) {
if (!requireLogin()) return;
$replyingTo = null;
if (isset($_REQUEST['replyingTo'])) {
$replyingTo = $_REQUEST['replyingTo'];
}
echo json_encode(Data\Comments::Post($section, $ref, $_REQUEST['content'], $replyingTo));
});
/// =====================
/// Voting
/// =====================
$router->all("/api/vote/{target}/{id}", function ($target, $id) {
echo Votes::Vote($target, $id)->ReturnJson();
});