-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
143 lines (133 loc) · 4.71 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>embry</title>
<style>
body {
background-color: #0f0f0f;
color: #33ff33;
font-family: 'Courier New', Courier, monospace;
text-align: center;
padding: 20px;
}
.container {
display: inline-block;
text-align: left;
}
h1 {
font-size: 24px;
}
.file-input-container {
background-color: #1a1a1a;
border: 1px solid #33ff33;
color: #33ff33;
padding: 10px;
margin: 5px 0;
display: block;
cursor: pointer;
width: calc(100% - 22px);
}
.file-input-container:hover {
background-color: #262626;
}
input[type="file"] {
opacity: 0;
width: 0.1px;
height: 0.1px;
position: absolute;
}
button {
background-color: #1a1a1a;
border: 1px solid #33ff33;
color: #33ff33;
padding: 10px;
margin: 5px 0;
display: block;
width: 100%;
}
a {
color: #33ff33;
display: block;
margin: 5px 0;
}
@media (max-width: 600px) {
h1 {
font-size: 20px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>/embry</h1>
<label for="fileInput" class="file-input-container">Choose file</label>
<input id="fileInput" type="file">
<button id="uploadButton">Upload</button>
<div id="fileList"></div>
</div>
<script src="https://www.gstatic.com/firebasejs/8.5.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.5.0/firebase-storage.js"></script>
<script>
const firebaseConfig = {
apiKey: "AIzaSyDDBAnwNwDq_3DbUmARTVQU8YoRsU3ni_w",
authDomain: "embry-aafdf.firebaseapp.com",
projectId: "embry-aafdf",
storageBucket: "embry-aafdf.appspot.com",
messagingSenderId: "360618469732",
appId: "1:360618469732:web:7a587c818150dc7d8af271"
};
firebase.initializeApp(firebaseConfig);
const storageRef = firebase.storage().ref();
document.getElementById('uploadButton').addEventListener('click', function() {
const file = document.getElementById('fileInput').files[0];
if (file) { // Check if any file is selected
const fileRef = storageRef.child(`images/${file.name}`);
fileRef.put(file).then(function(snapshot) {
console.log('File uploaded successfully');
displayFileList();
}).catch(function(error) {
console.error('File upload error: ', error);
});
} else {
console.log('No file selected');
}
});
function displayFileList() {
const fileListDiv = document.getElementById('fileList');
fileListDiv.innerHTML = '';
storageRef.child('images').listAll().then(function(result) {
result.items.forEach(function(itemRef) {
itemRef.getDownloadURL().then(function(url) {
const a = document.createElement('a');
a.href = url;
a.download = itemRef.name;
a.textContent = 'Download ' + itemRef.name;
fileListDiv.appendChild(a);
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Delete';
deleteButton.onclick = function() {
deleteFile(itemRef.name);
};
fileListDiv.appendChild(deleteButton);
fileListDiv.appendChild(document.createElement('br'));
});
});
}).catch(function(error) {
console.error('Error listing files: ', error);
});
}
function deleteFile(fileName) {
const fileRef = storageRef.child(`images/${fileName}`);
fileRef.delete().then(function() {
console.log('File successfully deleted');
displayFileList();
}).catch(function(error) {
console.error('File deletion error: ', error);
});
}
displayFileList();
</script>
</body>
</html>