-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_cdn.html
More file actions
80 lines (72 loc) · 1.94 KB
/
test_cdn.html
File metadata and controls
80 lines (72 loc) · 1.94 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Swetrix CDN test</title>
<script>
const uri = 'http://localhost:5006/file'
const token = 'test12345'
</script>
<script type="application/javascript">
function sendFile(file, filename) {
const xhr = new XMLHttpRequest()
const fd = new FormData()
xhr.open('POST', uri, true)
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
alert(xhr.responseText)
}
}
fd.append('file', file)
fd.append('token', token)
if (filename) {
fd.append('filename', filename)
}
xhr.send(fd)
}
function deleteFile() {
fetch(uri, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
token,
filename: document.getElementById('deleteFilename').value
})
})
.then(response => response.json())
.then(console.log)
}
function uploadFile() {
const fileInput = document.getElementById('fileInput')
const filename = document.getElementById('filename').value
if (fileInput.files.length === 0) {
alert('Please select a file to upload')
return
}
const file = fileInput.files[0]
sendFile(file, filename)
}
</script>
<style>
body {
padding: 0 10px;
}
</style>
</head>
<body>
<div>
<h2>Upload file test</h2>
<input type="text" id="filename" placeholder="Enter the filename to upload (optional)">
<br><br>
<input type="file" id="fileInput">
<br><br>
<input type="button" value="Upload" onclick="uploadFile()">
</div>
<div style="margin-top: 30px">
<h2>Delete file test</h2>
<input type="text" id="deleteFilename" placeholder="Enter the filename to delete">
<input type="button" value="Delete" onclick="deleteFile()">
</div>
</body>
</html>