-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.html
382 lines (379 loc) · 13.3 KB
/
panel.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html>
<head>
<title>Image Manager</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<style>
html, body {
height: 98%;
width: 99%;
padding: 5px;
}
details {
font-size: 40px;
display: flex;
overflow: hidden;
user-select: none;
}
details .file {
max-width: 70%;
box-shadow: 0px 0px 30px 0px;
margin: 10px;
max-height: 500px;
}
details div {
max-width: 50%;
box-shadow: 0px 0px 20px 0px;
margin: 10px;
border-radius: 10px;
padding: 0px 0px 0px 10px;
}
.folder {
margin-left: 10px;
font-size: 30px;
}
/* Board Menu Styles */
#board-menu {
position: fixed;
z-index: 10000;
width: 15%;
background: #1b1a1a;
border-radius: 10px;
transform: scale(0);
transform-origin: top left;
box-shadow: 0px 0px 10px 0px;
}
#board-menu.visible {
transform: scale(1);
transition: transform 200ms ease-in-out;
}
#board-menu .item {
padding: 8px 10px;
font-size: 20px;
color: #eee;
cursor: pointer;
border-radius: inherit;
position: relative;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
}
[disabled] {
opacity: 0.5;
background: #1b1a1a!important;
}
#board-menu .item:hover {
background: #343434;
}
#board-menu .item:after{
content: "";
background: #737373;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-left: -20px!important;
margin-top: -120%;
opacity: 0;
transition: all 0.8s;
}
#board-menu .item:active:after{
padding: 0;
margin: 0;
opacity: 1;
transition: 0s;
}/* Global Styles */
#editor {
scale: 0;
width: 50%;
height: 50%;
position: fixed;
top: 30%;
left: 30%;
box-shadow: 0px 0px 20px 0px;
border-radius: 10px;
transition: scale 1s;
background: white;
}
#editor-name {
left: 50%;
position: absolute;
}
#editor-save {
float: right;
margin: 5px;
}
#editor textarea {
width: 98%;
height: 88%;
border-radius: 10px;
padding: 5px;
}
</style>
</head>
<body>
<h1>List of files stored on the server</h1>
<hr>
<input id="search" placeholder="Search File...">
<div id="editor">
<b id="editor-name"></b>
<button id="editor-save">Save</button>
<textarea id="editor-value"></textarea>
</div>
<div id="board-menu">
<div id="board-name" class="item" disabled></div>
<hr style="margin: 0px;scale: 0.5;">
<div id="board-visit" class="item">Visit</div>
<div id="board-rename" class="item">Rename</div>
<div id="board-copy" class="item">Copy Link</div>
<div id="board-delete" class="item" style="color:red;">Delete</div>
</div>
<script>
const normalizePozition = (mouseX, mouseY) => {
const scope = document.querySelector("body");
const contextMenu = document.getElementById("board-menu");
let {
left: scopeOffsetX,
top: scopeOffsetY,
} = scope.getBoundingClientRect();
scopeOffsetX = scopeOffsetX < 0 ? 0 : scopeOffsetX;
scopeOffsetY = scopeOffsetY < 0 ? 0 : scopeOffsetY;
const scopeX = mouseX - scopeOffsetX;
const scopeY = mouseY - scopeOffsetY;
// ? check if the element will go out of bounds
const outOfBoundsOnX =
scopeX + contextMenu.clientWidth > scope.clientWidth;
const outOfBoundsOnY =
scopeY + contextMenu.clientHeight > scope.clientHeight;
let normalizedX = mouseX;
let normalizedY = mouseY;
// ? normalize on X
if (outOfBoundsOnX) {
normalizedX =
scopeOffsetX + scope.clientWidth - contextMenu.clientWidth;
}
// ? normalize on Y
if (outOfBoundsOnY) {
normalizedY =
scopeOffsetY + scope.clientHeight - contextMenu.clientHeight;
}
return { normalizedX, normalizedY };
};
jQuery(document).ready(function($) {
function getAll() {
let key = localStorage.getItem("key");
if (!key) {
key = prompt("Admin Key:");
}
fetch(window.location.href, { method: "get", headers: { "type": "getAllFiles", "key": key } })
.then(res => {
if (res.status == 403) {
localStorage.setItem("key", "");
return getAll();
} else if (res.status == 200) {
localStorage.setItem("key", key);
return res.json();
}
})
.then(out => {
const data = out.folders
const types = out.types
console.log(out)
let fold;
for (var type of Object.keys(types)) {
const typ = document.createElement("details")
typ.id = type
typ.innerHTML = `<summary>${type.toUpperCase()}</summary>`
document.body.appendChild(typ)
for (var folder of types[type]) {
const fo = document.createElement("details")
fo.id = folder
fo.classList.add("folder")
fo.innerHTML = `<summary>${folder.toUpperCase()}</summary>`
document.getElementById(type).appendChild(fo)
console.log(data[types[type]])
for (var item of data[folder]) {
if (type === "image") {
fold = document.createElement("img");
fold.src = window.location.href.replace(window.location.pathname, "/" + item)
} else if (type === "video" || type === "audio") {
fold = document.createElement("video")
fold.innerHTML = `<source src="${window.location.href.replace(window.location.pathname, "/" + item)}" type="${type}/${item.split(".").pop()}">`
fold.controls = true
} else if (type === "text") {
fold = document.createElement("div");
fold.innerHTML = item
} else {
fold = document.createElement("div");
fold.innerHTML = item
}
fold.title = item
fold.id = type + "-" + item
fold.classList.add("file")
document.getElementById(folder).appendChild(fold);
}
}
}
// for (let type of Object.keys(data)) {
// const cat = document.createElement("details")
// cat.id = type
// cat.innerHTML = `<summary>${type.toUpperCase()} <i id="${type}-count">(${data[type].length})</i></summary>`
// document.body.appendChild(cat)
// if (["png", "jpg", "jpeg", "gif", "svg", "ico", "webp", "tiff"].includes(type)) {
// for (var img of data[type]) {
// var image = document.createElement("img");
// image.src = window.location.href.replace(window.location.pathname, "/" + img)
// image.title = img
// image.id = "image-" + img
// image.classList.add("file")
// document.getElementById(type).appendChild(image);
// }
// } else if (type === "txt") {
// for (var txt of data[type]) {
// var text = document.createElement("div");
// text.innerHTML = txt
// text.title = txt
// text.id = "text-" + txt
// text.classList.add("file")
// document.getElementById(type).appendChild(text);
// }
// } else if (["mp4"].includes(type)) {
// for (var vid of data[type]) {
// var video = document.createElement("video")
// video.innerHTML = `<source src="${window.location.href.replace(window.location.pathname, "/" + vid)}" type="video/${vid.split(".").pop()}">`
// video.title = vid
// video.controls = true
// video.id = "video-" + vid
// video.classList.add("file")
// document.getElementById(type).appendChild(video);
// }
// } else if (["mp3"].includes(type)) {
// for (var au of data[type]) {
// var audio = document.createElement("audio")
// audio.innerHTML = `<source src="${window.location.href.replace(window.location.pathname, "/" + au)}" type="audio/${au.split(".").pop()}">`
// audio.title = au
// audio.controls = true
// audio.id = "audio-" + au
// audio.classList.add("file")
// document.getElementById(type).appendChild(audio);
// }
// }
// }
})
.catch(error => {
console.error(error);
});
}
getAll();
function board(event) {
const el = $(event.target).attr("id");
const file_name = el.replace(el.split("-")[0] + "-","")
let type;
if (el.startsWith("image-")) {
type = "image"
} else if (el.startsWith("text-")) {
type = "text"
} else {
return;
}
event.preventDefault();
event.stopPropagation();
const contextMenu = document.getElementById("board-menu");
const { clientX: mouseX, clientY: mouseY } = event;
const { normalizedX, normalizedY } = normalizePozition(mouseX, mouseY);
contextMenu.classList.remove("visible");
contextMenu.style.top = `${normalizedY}px`;
contextMenu.style.left = `${normalizedX}px`;
contextMenu.classList.add("visible");
$("#board-name").html(file_name)
$("#board-visit").off("click")
$("#board-visit").click(function() {
document.getElementById("board-menu").classList.remove("visible");
if (type == "image") {
window.open(window.location.href.replace(window.location.pathname, "/" + file_name))
} else if (type == "text") {
fetch(window.location.href.replace(window.location.pathname, "/" + file_name)).then(res => res.text()).then(data => {
document.getElementById("editor-value").innerHTML = data
})
setTimeout(function() {
document.getElementById("editor").style.scale = 1;
document.getElementById("editor-name").innerHTML = file_name
},500)
}
})
$("#board-rename").off("click")
$("#board-rename").click(function() {
const name = prompt("Rename " + el + " to:")
fetch(window.location.href, { method: "get", headers: { "type": "renameFile", "key": localStorage.getItem("key"),"file":file_name, "rename":name } })
.then(res => {
if (res.status == 403) {
localStorage.setItem("key", "");
return location.refresh();
} else if (res.status == 200) {
const reid = document.getElementById(el);
reid.id = type + "-" + name
document.getElementById("board-menu").classList.remove("visible");
alert("Rename " + file_name + " to: " + name)
}
})
})
$("#board-copy").off("click")
$("#board-copy").click(function() {
navigator.clipboard.writeText(window.location.href.replace(window.location.pathname, "/" + file_name))
})
$("#board-delete").off("click")
$("#board-delete").click(function() {
const del = confirm("Delete " + file_name + "?")
if (!del) return;
fetch(window.location.href, { method: "get", headers: { "type": "deleteFile", "key": localStorage.getItem("key"),"file":file_name} })
.then(res => {
if (res.status == 403) {
localStorage.setItem("key", "");
return location.refresh();
} else if (res.status == 200) {
const reid = document.getElementById(el);
reid.remove()
document.getElementById("board-menu").classList.remove("visible");
}
})
})
}
$("body").on("contextmenu", function(event) {
board(event)
})
let pressTimer;
$("body").on("mousedown", function(event) {
pressTimer = setTimeout(function() {
board(event)
}, 1000);
});
$("body").on("mouseup", function() {
clearTimeout(pressTimer);
});
$("body").on("click", (e) => {
const contextMenu = document.getElementById("board-menu");
const editor = document.getElementById("editor");
if (e.target.offsetParent != contextMenu) {
contextMenu.classList.remove("visible");
}
if (e.target.offsetParent != editor && editor.style.scale == 1) {
editor.style.scale = 0
}
});
$("#editor-save").click(function() {
fetch(window.location.href, {"method":"post","headers":{"type":"editFile","key":localStorage.getItem("key"),"file":document.getElementById("editor-name").innerHTML,"body":document.getElementById("editor-value").value.replaceAll("\n","\\n")}})
})
$(window).on('scroll', function() {
document.getElementById("board-menu").classList.remove("visible");
});
$("#search").on("input", function() {
const name = $(this).val()
$(".file").show().filter(function() {
return $(this).attr("title").toLowerCase().trim().indexOf(name) == -1;
}).hide();
})
})
</script>
</body>
</html>