This commit is contained in:
split / May 2022-12-26 21:13:55 -08:00
parent cacde42e71
commit 20da6f3020
4 changed files with 145 additions and 4 deletions

View file

@ -1,6 +1,6 @@
{
"name": "monofile",
"version": "1.1.0",
"version": "1.1.1",
"description": "",
"main": "index.js",
"scripts": {

134
pages/clone.html Normal file
View file

@ -0,0 +1,134 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>monofile</title>
<meta name="application-name" content="monofile">
<meta name="description" content="Discord-based filesharing">
<style>
* {
font-family: sans-serif;
}
h1,h2 {
text-align:center;
}
#content {
position:fixed;
left:50%;
top:50%;
transform:translate(-50%,-50%);
background-color:white;
width:450px;
/*height:100%;*/
}
body {
background-color: darkgray;
}
#btnContainer {
width:calc( 100% - 50px );
height:50px;
position:relative;
left:50%;
transform:translate(-50%,0);
}
#uploadButton {
width:100%;
height:100%;
background-color: #66AAFF;
color:black;
font-weight:bold;
border:none;
position:absolute;
left:0px;
top:0px;
font-size:20px;
}
#uploadButton:hover {
border: 1px solid gray;
}
.note {
padding:5px;
position:relative;
width:calc( 100% - 60px );
left:25px;
border:1px solid #AAAAAAFF;
border-radius: 8px;
background-color: #AAAAAA66;
}
@media only screen and (max-width: 450px) {
#content {
position:fixed;
left:0%;
top:0%;
transform:translate(0%,0%);
background-color:white;
width:100%;
height:100%;
}
}
</style>
</head>
<body>
<input type="text" id="CopyTB" value="" readonly style="opacity:0;width:10px;height:0%;">
<div id="content">
<h1>
monofile
</h1>
<h2><em>Discord-based file sharing</em></h2>
<div class="note" style="border-color:#FFAAAAFF;background-color:#FFAAAA66">
Before sharing files, please remember:
<ul>
<li>Do NOT share sensitive information via monofile</li>
<li>Do NOT share illegal content via monofile</li>
<li>The owner of this instance reserves the right to remove your files</li>
</ul>
</div>
<div style="width:100%;height:25px"></div>
<div id="btnContainer"><button id="uploadButton">Input a URL</button></div>
<p style="font-family:monospace;position:relative;width:calc( 100% - 50px );left:25px;text-align: center;">
Max filesize on instance: $MaxInstanceFilesize
</p>
<p style="font-family:monospace;position:relative;width:calc( 100% - 50px );left:25px;text-align: center;font-size:12px;color:gray;">made by nbitzz — <a style="color:gray;font-family:monospace;font-size:12px;" href="https://github.com/nbitzz/monofile">github</a><a style="color:gray;font-family:monospace;font-size:12px;" href="/">upload a file...</a></p>
<div style="width:100%;height:25px"></div>
</div>
</body>
<script>
let updateBtnTxt = (btntxt) => {document.getElementById("btnContainer").innerHTML = `<div class="note" style="width:calc( 100% - 10px );height:calc( 100% - 10px );position:absolute;left:0px;top:0px;"><p style="font-family:monospace;position:relative;width:calc( 100% - 50px );left:25px;text-align: center;">${btntxt}</p></div>`}
document.getElementById("uploadButton").addEventListener("click",() => {
let ask = prompt("Input a URL to clone.")
if (ask) {
updateBtnTxt("Requesting clone. Please wait.")
let xmlhttp = new XMLHttpRequest()
xmlhttp.addEventListener("error",function(e) {
updateBtnTxt(`Upload failed.<br/>${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.<br/><a style="color:blue;font-family:monospace;" href="javascript:document.getElementById('CopyTB').focus();document.getElementById('CopyTB').select();document.execCommand('copy');document.getElementById('CopyTB').blur();">Copy URL</a> <a style="color:blue;font-family:monospace;" href="javascript:prompt('This is your download URL.', document.getElementById('CopyTB').value);null">View URL</a>`)
} else {
updateBtnTxt(`Upload failed.<br/>${xmlhttp.responseText}`)
}
})
xmlhttp.open("POST","/clone")
xmlhttp.send(ask)
}
})
</script>
</html>

View file

@ -95,7 +95,7 @@
<p style="font-family:monospace;position:relative;width:calc( 100% - 50px );left:25px;text-align: center;">
Max filesize on instance: $MaxInstanceFilesize
</p>
<p style="font-family:monospace;position:relative;width:calc( 100% - 50px );left:25px;text-align: center;font-size:12px;color:gray;">made by nbitzz — <a style="color:gray;font-family:monospace;font-size:12px;" href="https://github.com/nbitzz/monofile">github</a></p>
<p style="font-family:monospace;position:relative;width:calc( 100% - 50px );left:25px;text-align: center;font-size:12px;color:gray;">made by nbitzz — <a style="color:gray;font-family:monospace;font-size:12px;" href="https://github.com/nbitzz/monofile">github</a><a style="color:gray;font-family:monospace;font-size:12px;" href="/clone">clone from url...</a></p>
<div style="width:100%;height:25px"></div>
</div>
</body>
@ -124,7 +124,7 @@
xmlhttp.addEventListener("load",function() {
if (xmlhttp.status == 200) {
document.getElementById("CopyTB").value = `https://${location.hostname}/download/${xmlhttp.responseText}`
updateBtnTxt(`Upload complete.<br/><a style="color:blue;font-family:monospace;" href="javascript:document.getElementById('CopyTB').focus();document.getElementById('CopyTB').select();document.execCommand('copy');">Copy URL</a> <a style="color:blue;font-family:monospace;" href="javascript:prompt('This is your download URL.', document.getElementById('CopyTB').value);null">View URL</a>`)
updateBtnTxt(`Upload complete.<br/><a style="color:blue;font-family:monospace;" href="javascript:document.getElementById('CopyTB').focus();document.getElementById('CopyTB').select();document.execCommand('copy');document.getElementById('CopyTB').blur();">Copy URL</a> <a style="color:blue;font-family:monospace;" href="javascript:prompt('This is your download URL.', document.getElementById('CopyTB').value);null">View URL</a>`)
} else {
updateBtnTxt(`Upload failed.<br/>${xmlhttp.responseText}`)
}

View file

@ -107,6 +107,13 @@ app.get("/", function(req,res) {
})
})
app.get("/clone", function(req,res) {
fs.readFile(__dirname+"/../pages/clone.html",(err,buf) => {
if (err) {res.sendStatus(500);console.log(err);return}
res.send(buf.toString().replace("$MaxInstanceFilesize",`${(config.maxDiscordFileSize*config.maxDiscordFiles)/1048576}MB`))
})
})
app.post("/upload",multerSetup.single('file'),async (req,res) => {
if (req.file) {
uploadFile({name:req.file.originalname,mime:req.file.mimetype},req.file.buffer)
@ -120,7 +127,7 @@ app.post("/upload",multerSetup.single('file'),async (req,res) => {
app.post("/clone",(req,res) => {
axios.get(req.body,{responseType:"blob"}).then((data:AxiosResponse) => {
uploadFile({name:req.body.split("/")[req.body.split("/").length],mime:data.headers["content-type"]},Buffer.from(data.data))
uploadFile({name:req.body.split("/")[req.body.split("/").length] || "generic",mime:data.headers["content-type"]},Buffer.from(data.data))
.then((uID) => res.send(uID))
.catch((stat) => {res.status(stat.status);res.send(`[err] ${stat.message}`)})
}).catch((err) => {