-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
236 lines (208 loc) · 8.55 KB
/
index.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FileGuardian API Tester</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.container { margin-bottom: 20px; }
input, button { margin: 5px 0; padding: 5px; }
</style>
</head>
<body>
<h1>FileGuardian API Tester</h1>
<button onclick="clearOutput()">Clear</button>
<div class="container">
<h2>Create File</h2>
<input type="text" id="createFileName" placeholder="File Name">
<input type="number" id="createFileRisk" placeholder="Risk">
<button onclick="createFile()">Create File</button>
<pre id="createFileResponse"></pre>
</div>
<div class="container">
<h2>Get Files</h2>
<input type="number" id="riskOver" placeholder="Risk Over">
<input type="text" id="nameContains" placeholder="Name Contains">
<button onclick="getFiles()">Get Files</button>
<pre id="getFilesResponse"></pre>
</div>
<div class="container">
<h2>Get File by ID</h2>
<input type="number" id="getFileId" placeholder="File ID">
<button onclick="getFile()">Get File</button>
<pre id="getFileResponse"></pre>
</div>
<div class="container">
<h2>Get Top Shared Files</h2>
<input type="number" id="topFilesLimit" placeholder="Limit">
<button onclick="getTopFiles()">Get Top Shared Files</button>
<pre id="getTopFilesResponse"></pre>
</div>
<div class="container">
<h2>Share File</h2>
<input type="number" id="shareFileId" placeholder="File ID">
<input type="text" id="shareFileUsers" placeholder="User IDs (comma-separated)">
<input type="text" id="shareFileGroups" placeholder="Group IDs (comma-separated)">
<button onclick="shareFile()">Share File</button>
<pre id="shareFileResponse"></pre>
</div>
<div class="container">
<h2>Create Group</h2>
<input type="text" id="createGroupName" placeholder="Group Name">
<button onclick="createGroup()">Create Group</button>
<pre id="createGroupResponse"></pre>
</div>
<div class="container">
<h2>Get Groups</h2>
<button onclick="getGroups()">Get Groups</button>
<pre id="getGroupsResponse"></pre>
</div>
<div class="container">
<h2>Get Group by ID</h2>
<input type="number" id="getGroupId" placeholder="Group ID">
<button onclick="getGroup()">Get Group</button>
<pre id="getGroupResponse"></pre>
</div>
<div class="container">
<h2>Add Users to Group</h2>
<input type="number" id="groupIdToAddUsers" placeholder="Group ID">
<input type="text" id="userIdsToAdd" placeholder="User IDs (comma-separated)">
<button onclick="addUsersToGroup()">Add Users to Group</button>
<pre id="addUsersToGroupResponse"></pre>
</div>
<div class="container">
<h2>Create User</h2>
<input type="text" id="createUserName" placeholder="User Name">
<button onclick="createUser()">Create User</button>
<pre id="createUserResponse"></pre>
</div>
<div class="container">
<h2>Get Users</h2>
<button onclick="getUsers()">Get Users</button>
<pre id="getUsersResponse"></pre>
</div>
<div class="container">
<h2>Get User by ID</h2>
<input type="number" id="getUserId" placeholder="User ID">
<button onclick="getUser()">Get User</button>
<pre id="getUserResponse"></pre>
</div>
<script>
const apiUrl = 'http://localhost:5113/api';
function clearOutput() {
document.querySelectorAll('pre').forEach(pre => pre.textContent = '');
}
async function createFile() {
const name = document.getElementById('createFileName').value;
const risk = document.getElementById('createFileRisk').value;
const response = await fetch(`${apiUrl}/files`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name,
risk: parseInt(risk)
})
});
const data = await response.json();
document.getElementById('createFileResponse').textContent = JSON.stringify(data, null, 2);
}
async function getFiles() {
const riskOver = document.getElementById('riskOver').value;
const nameContains = document.getElementById('nameContains').value;
const response = await fetch(`${apiUrl}/files?riskOver=${riskOver}&nameContains=${nameContains}`);
const data = await response.json();
document.getElementById('getFilesResponse').textContent = JSON.stringify(data, null, 2);
}
async function getFile() {
const id = document.getElementById('getFileId').value;
const response = await fetch(`${apiUrl}/files/${id}`);
const data = await response.json();
document.getElementById('getFileResponse').textContent = JSON.stringify(data, null, 2);
}
async function getTopFiles() {
const limit = document.getElementById('topFilesLimit').value;
const response = await fetch(`${apiUrl}/files/top?limit=${limit}`);
const data = await response.json();
document.getElementById('getTopFilesResponse').textContent = JSON.stringify(data, null, 2);
}
async function shareFile() {
const id = document.getElementById('shareFileId').value;
const usersInput = document.getElementById('shareFileUsers').value;
const groupsInput = document.getElementById('shareFileGroups').value;
const users = usersInput ? usersInput.split(',').map(Number) : [];
const groups = groupsInput ? groupsInput.split(',').map(Number) : [];
const response = await fetch(`${apiUrl}/files/${id}/share`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ users, groups })
});
if (response.ok) {
document.getElementById('shareFileResponse').textContent = 'File shared successfully.';
} else {
const data = await response.json();
document.getElementById('shareFileResponse').textContent = JSON.stringify(data, null, 2);
}
}
async function createGroup() {
const name = document.getElementById('createGroupName').value;
const response = await fetch(`${apiUrl}/groups`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name })
});
const data = await response.json();
document.getElementById('createGroupResponse').textContent = JSON.stringify(data, null, 2);
}
async function getGroups() {
const response = await fetch(`${apiUrl}/groups`);
const data = await response.json();
document.getElementById('getGroupsResponse').textContent = JSON.stringify(data, null, 2);
}
async function getGroup() {
const id = document.getElementById('getGroupId').value;
const response = await fetch(`${apiUrl}/groups/${id}`);
const data = await response.json();
document.getElementById('getGroupResponse').textContent = JSON.stringify(data, null, 2);
}
async function addUsersToGroup() {
const id = document.getElementById('groupIdToAddUsers').value;
const userIds = document.getElementById('userIdsToAdd').value.split(',').map(Number);
const response = await fetch(`${apiUrl}/groups/${id}/users`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(userIds)
});
if (response.ok) {
document.getElementById('addUsersToGroupResponse').textContent = 'Users added to group successfully.';
} else {
const data = await response.json();
document.getElementById('addUsersToGroupResponse').textContent = JSON.stringify(data, null, 2);
}
}
async function createUser() {
const name = document.getElementById('createUserName').value;
const response = await fetch(`${apiUrl}/users`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name })
});
const data = await response.json();
document.getElementById('createUserResponse').textContent = JSON.stringify(data, null, 2);
}
async function getUsers() {
const response = await fetch(`${apiUrl}/users`);
const data = await response.json();
document.getElementById('getUsersResponse').textContent = JSON.stringify(data, null, 2);
}
async function getUser() {
const id = document.getElementById('getUserId').value;
const response = await fetch(`${apiUrl}/users/${id}`);
const data = await response.json();
document.getElementById('getUserResponse').textContent = JSON.stringify(data, null, 2);
}
</script>
</body>
</html>