From 3ef9eeaf4c9868155216dc86c515c6192961023b Mon Sep 17 00:00:00 2001
From: stringsplit <77242831+nbitzz@users.noreply.github.com>
Date: Thu, 29 Dec 2022 17:12:44 -0800
Subject: [PATCH] this code actually sucks ass god bless anyone who reads this
1.2.1 i'll need to clean this shit up lmao
---
.vscode/tasks.json | 2 +-
README.md | 9 ++-
assets/script/clone_file.js | 30 +++++++
assets/script/upload_file.js | 37 +++++++++
pages/{upload.html => base.html} | 117 ++++++++++++++++-----------
pages/clone.html | 135 -------------------------------
src/index.ts | 73 ++++++++++++-----
src/lib/SlashCommandManager.ts | 95 ----------------------
8 files changed, 199 insertions(+), 299 deletions(-)
create mode 100644 assets/script/clone_file.js
create mode 100644 assets/script/upload_file.js
rename pages/{upload.html => base.html} (59%)
delete mode 100644 pages/clone.html
delete mode 100644 src/lib/SlashCommandManager.ts
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 005ad9c..eacc6c8 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -12,7 +12,7 @@
},
{
"type": "shell",
- "command":"npx tsc\nnode ./out/index.js\ndel ./server_out/* -Recurse",
+ "command":"npx tsc\nnode ./out/index.js\ndel ./out/* -Recurse",
"group": {
"kind": "build",
"isDefault": true
diff --git a/README.md b/README.md
index 6ffa716..42019f8 100644
--- a/README.md
+++ b/README.md
@@ -17,10 +17,11 @@ TOKEN=KILL-YOURSELF.NOW
- [X] 1.1.2 fix file cloning with binary data
- [X] 1.1.3 display current version on pages
- [X] 1.1.4 serve /assets as static files & make /server endpoint
-- [ ] 1.2.0 add simple moderation tools
-- [ ] 1.2.1 prevent cloning of local/private ip addresses
-- [ ] 1.3.0 allow custom file ids
-- [ ] 1.4.0 accounts??? maybe?? (this probably won't happen)
+- [X] 1.2.0 add file parameters section + custom ids
+- [ ] 1.2.1 clean up this shitty code
+- [ ] 1.2.2 add id locks, allowing you to set a key for a file that allows you to overwrite the file in the future
+- [ ] 1.2.3 prevent cloning of local/private ip addresses
+- [ ] 1.3.0 add simple moderation tools
- [ ] 2.0.0 rewrite using theUnfunny's code as a base/rewrite using monofile-core
also todo: monofile-core (written in eris)
diff --git a/assets/script/clone_file.js b/assets/script/clone_file.js
new file mode 100644
index 0000000..5b31f64
--- /dev/null
+++ b/assets/script/clone_file.js
@@ -0,0 +1,30 @@
+document.getElementById("uploadButton").addEventListener("click",() => {
+ let ask = prompt("Input a URL to clone.")
+
+ if (ask) {
+ let opt = getOptionsForUploading()
+ updateBtnTxt("Requesting clone. Please wait.")
+
+ let xmlhttp = new XMLHttpRequest()
+
+ xmlhttp.addEventListener("error",function(e) {
+ updateBtnTxt(`Upload failed.
${e.toString()}`)
+ console.error(e)
+ })
+
+ xmlhttp.addEventListener("load",function() {
+ if (xmlhttp.status == 200) {
+ document.getElementById("CopyTB").value = `https://${location.hostname}/download/${xmlhttp.responseText}`
+ updateBtnTxt(`Upload complete.
Copy URL View URL`)
+ } else {
+ updateBtnTxt(`Upload failed.
${xmlhttp.responseText}`)
+ }
+ })
+
+ xmlhttp.open("POST","/clone")
+ xmlhttp.send(JSON.stringify({
+ url: ask,
+ ...opt
+ }))
+ }
+})
\ No newline at end of file
diff --git a/assets/script/upload_file.js b/assets/script/upload_file.js
new file mode 100644
index 0000000..9bf54c3
--- /dev/null
+++ b/assets/script/upload_file.js
@@ -0,0 +1,37 @@
+let FileUpload = document.createElement("input")
+FileUpload.setAttribute("type","file")
+
+document.getElementById("uploadButton").addEventListener("click",() => FileUpload.click())
+
+FileUpload.addEventListener("input",() => {
+ if (FileUpload.files[0]) {
+ let opt = getOptionsForUploading()
+ let file = FileUpload.files[0]
+
+ updateBtnTxt("Uploading file. This may take a while, so stay put.")
+
+ let xmlhttp = new XMLHttpRequest()
+
+ xmlhttp.addEventListener("error",function(e) {
+ updateBtnTxt(`Upload failed.
${e.toString()}`)
+ console.error(e)
+ })
+
+ xmlhttp.addEventListener("load",function() {
+ if (xmlhttp.status == 200) {
+ document.getElementById("CopyTB").value = `https://${location.hostname}/download/${xmlhttp.responseText}`
+ updateBtnTxt(`Upload complete.
Copy URL View URL`)
+ } else {
+ updateBtnTxt(`Upload failed.
${xmlhttp.responseText}`)
+ }
+ })
+
+ let fd = new FormData()
+ fd.append('file',file)
+
+ xmlhttp.open("POST","/upload")
+ xmlhttp.setRequestHeader("monofile-upload-id",opt.uploadId)
+ xmlhttp.send(fd)
+
+ }
+})
\ No newline at end of file
diff --git a/pages/upload.html b/pages/base.html
similarity index 59%
rename from pages/upload.html
rename to pages/base.html
index c132c51..a495e1d 100644
--- a/pages/upload.html
+++ b/pages/base.html
@@ -37,31 +37,70 @@
left:50%;
transform:translate(-50%,0);
}
- #uploadButton {
- width:100%;
- height:100%;
- background-color: #66AAFF;
+
+ button {
color:black;
font-weight:bold;
border:none;
position:absolute;
- left:0px;
- top:0px;
font-size:20px;
}
- #uploadButton:hover {
+
+ button:hover {
border: 1px solid gray;
}
+
+ #uploadButton {
+ width:calc( 100% - 50px );
+ height:100%;
+ background-color: #66AAFF;
+ left:0px;
+ top:0px;
+ }
+
+ #optionsButton {
+ width:50px;
+ height:100%;
+ background-color: #AAAAAA;
+ left:calc( 100% - 50px );
+ top:0px;
+ font-size:15px;
+ }
+
.note {
padding:5px;
position:relative;
- width:calc( 100% - 60px );
+ width:calc( 100% - 62px );
left:25px;
border:1px solid #AAAAAAFF;
border-radius: 8px;
background-color: #AAAAAA66;
}
+ /* this is horrible css lmao */
+
+ #options > input {
+ font-family:monospace;
+ width:250px;
+ font-size:14px;
+ border: 1px solid #777777;
+ background-color:#AAAAAA;
+ outline:none;
+ text-align:center;
+ }
+
+ #options {
+ height:30px;
+ display:none;
+ }
+
+ #customId {
+ position:absolute;
+ left:50%;
+ top:50%;
+ transform:translate(-50%,-50%)
+ }
+
@media only screen and (max-width: 450px) {
#content {
position:fixed;
@@ -92,53 +131,41 @@
Max filesize on instance: $MaxInstanceFilesize
-made by nbitzz — github — clone from url...
+made by nbitzz — github — $otherText