fixed md, added sxcu files
This commit is contained in:
parent
faa48935bc
commit
bc515ac8e8
|
@ -1,3 +1,3 @@
|
|||
server/uploads/* linguist-vendored
|
||||
src/server/uploads/* linguist-vendored
|
||||
.github/* linguist-vendored
|
||||
server/views/* linguist-vendored
|
||||
src/server/views/* linguist-vendored
|
|
@ -1,3 +1,3 @@
|
|||
/node_modules
|
||||
config.real.json
|
||||
package-lock.json
|
||||
src/node_modules
|
||||
src/config.real.json
|
||||
src/package-lock.json
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"Version": "12.4.0",
|
||||
"Name": "Images_and_Files",
|
||||
"DestinationType": "ImageUploader, FileUploader",
|
||||
"RequestMethod": "POST",
|
||||
"RequestURL": "http://[YOUR_DOMAIN]/api/files",
|
||||
"Body": "MultipartFormData",
|
||||
"Arguments": {
|
||||
"key": "YOUR_PASSWORD"
|
||||
},
|
||||
"FileFormName": "fdata"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"Version": "12.4.0",
|
||||
"Name": "Text",
|
||||
"DestinationType": "TextUploader",
|
||||
"RequestMethod": "POST",
|
||||
"RequestURL": "http://[YOUR_DOMAIN]/api/paste",
|
||||
"Body": "MultipartFormData",
|
||||
"Arguments": {
|
||||
"key": "YOUR_PASSWORD"
|
||||
},
|
||||
"FileFormName": "fdata"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"Version": "12.4.0",
|
||||
"Name": "URL_Shortener",
|
||||
"DestinationType": "URLShortener",
|
||||
"RequestMethod": "POST",
|
||||
"RequestURL": "http://[YOUR_DOMAIN]/api/shortener",
|
||||
"Headers": {
|
||||
"url": "$input$"
|
||||
},
|
||||
"Body": "MultipartFormData",
|
||||
"Arguments": {
|
||||
"key": "YOUR_PASSWORD"
|
||||
},
|
||||
"FileFormName": "fdata"
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
const path = require("path")
|
||||
const formidable = require("formidable")
|
||||
const fs = require("fs-extra")
|
||||
const ejs = require("ejs")
|
||||
async function paste(req, res) {
|
||||
res.setHeader("Content-Type", "text/text")
|
||||
let fileName = this.randomToken(5) // 916,132,832 possible file names
|
||||
let form = new formidable.IncomingForm()
|
||||
form.parse(req, (err, fields, files) => {
|
||||
let userIP = req.headers["x-forwarded-for"] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress
|
||||
if (!this.auth(this.c.key, fields.key, this.c)) {
|
||||
res.statusCode = 401
|
||||
res.write("Unauthorized");
|
||||
res.end();
|
||||
return this.log.warning(`Unauthorized User | File Upload | ${userIP}`)
|
||||
}
|
||||
this.db.get("files")
|
||||
.push({path: `/${fileName}`, ip: userIP, views: 0})
|
||||
.write();
|
||||
let oldpath = files.fdata.path
|
||||
let newpath = `${__dirname}/../uploads/${fileName+files.fdata.name.toString().match(/(\.)+([a-zA-Z0-9]+)+/g, "").toString()}`;
|
||||
if (!this.c.paste.allowed.includes(files.fdata.name.substring(files.fdata.name.lastIndexOf(".") + 1, files.fdata.name.length))) {
|
||||
res.statusCode = 415
|
||||
res.write(`http://${req.headers.host}/ERR_ILLEGAL_FILE_TYPE`)
|
||||
return res.end()
|
||||
} else {
|
||||
if (Math.round((files.fdata.size / 1024) / 1000) > this.c.paste.max_upload_size) {
|
||||
if (this.monitorChannel !== null) this.bot.createMessage(this.monitorChannel, `\`\`\`MARKDOWN\n[FAILED PASTE][USER]\n[FILE](${files.fdata.name})\n[SIZE](${Math.round(files.fdata.size/1024)}KB)\n[TYPE](${files.fdata.type})\n[IP](${userIP})\n\n[ERROR](ERR_FILE_TOO_BIG)\`\`\``)
|
||||
res.statusCode = 413
|
||||
res.write(`http://${req.headers.host}/ERR_FILE_TOO_BIG`)
|
||||
return res.end()
|
||||
} else {
|
||||
let lv = this.log.verbose
|
||||
let le = this.log.error
|
||||
fs.move(oldpath, newpath, err => {
|
||||
fs.readFile(newpath, "utf-8", function read(err, data) {
|
||||
let stream = fs.createWriteStream(`${__dirname}/../uploads/${fileName}.html`)
|
||||
stream.once("open", fd => {
|
||||
let cleaned = data.replace(/>/g, ">")
|
||||
cleaned = cleaned.replace(/</g, "<")
|
||||
ejs.renderFile(`${__dirname}/../views/paste.ejs`, {
|
||||
ogDesc: data.match(/.{1,297}/g)[0],
|
||||
pData: data
|
||||
}, {}, (err, str) => {
|
||||
stream.write(str)
|
||||
})
|
||||
stream.end()
|
||||
fs.unlink(newpath, err => {
|
||||
if (err) return //le(err)
|
||||
});
|
||||
//lv(`New Paste: http://${req.headers.host}/${fileName} | IP: ${userIP}`)
|
||||
let insecure = `http://${req.headers.host}/${fileName}`
|
||||
let secure = `https://${req.headers.host}/${fileName}`
|
||||
res.write(req.secure ? secure : insecure)
|
||||
//if (this.monitorChannel !== null) this.bot.createMessage(this.monitorChannel, `\`\`\`MARKDOWN\n[NEW PASTE]\n[IP](${userIP})\n\`\`\`\nhttp://${req.headers.host}/${fileName}`)
|
||||
return res.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
module.exports = paste
|
|
@ -1,30 +1,27 @@
|
|||
{
|
||||
"key": "",
|
||||
"public": false,
|
||||
"maxUploadSize": 50,
|
||||
"markdown": true,
|
||||
"port": 80,
|
||||
"secure": true,
|
||||
"securePort": 443,
|
||||
"ratelimit": 1000,
|
||||
"allowed":[
|
||||
"png", "jpg", "gif", "mp4", "mp3", "jpeg", "tiff", "bmp", "ico", "psd", "eps", "raw", "cr2", "nef", "sr2", "orf", "svg", "wav", "webm", "aac", "flac", "ogg", "wma", "m4a", "gifv"
|
||||
],
|
||||
"admin":{
|
||||
"key": "admin pass key goes here",
|
||||
"maxUploadSize": 1024,
|
||||
"allowed": [
|
||||
"png", "jpg", "gif", "mp4", "mp3","jpeg", "tiff", "bmp", "ico", "psd", "eps", "raw", "cr2", "nef", "sr2", "orf", "svg", "wav", "webm", "aac", "flac", "ogg", "wma", "m4a", "gifv", "html"
|
||||
]
|
||||
},
|
||||
"paste": {
|
||||
"maxUploadSize": 20,
|
||||
"allowed": [
|
||||
"js", "php", "html", "txt", "lua", "json", "yml", "go", "cr", "bat", "css", "cs", "java", "py", "less", "c", "cpp", "ini", "pl", "sql", "rb", "md"
|
||||
]
|
||||
},
|
||||
"discordToken": "Discord Token Here (required if you want API monitoring through Discord)",
|
||||
"discordAdminIDs": ["discord IDs of people who can run commands go here", "Like this"],
|
||||
"discordChannelID": "the channel you're trying to send api monitor updates to",
|
||||
"prefix": "enter prefix for bot commands here"
|
||||
{
|
||||
"key": "",
|
||||
"public": false,
|
||||
"maxUploadSize": 50,
|
||||
"markdown": true,
|
||||
"port": 80,
|
||||
"secure": true,
|
||||
"securePort": 443,
|
||||
"ratelimit": 1000,
|
||||
"allowed":[
|
||||
"png", "jpg", "gif", "mp4", "mp3", "jpeg", "tiff", "bmp", "ico", "psd", "eps", "raw", "cr2", "nef", "sr2", "orf", "svg", "wav", "webm", "aac", "flac", "ogg", "wma", "m4a", "gifv"
|
||||
],
|
||||
"admin":{
|
||||
"key": "admin pass key goes here",
|
||||
"maxUploadSize": 1024,
|
||||
"allowed": [
|
||||
"png", "jpg", "gif", "mp4", "mp3","jpeg", "tiff", "bmp", "ico", "psd", "eps", "raw", "cr2", "nef", "sr2", "orf", "svg", "wav", "webm", "aac", "flac", "ogg", "wma", "m4a", "gifv", "html"
|
||||
]
|
||||
},
|
||||
"paste": {
|
||||
"maxUploadSize": 20
|
||||
},
|
||||
"discordToken": "Discord Token Here (required if you want API monitoring through Discord)",
|
||||
"discordAdminIDs": ["discord IDs of people who can run commands go here", "Like this"],
|
||||
"discordChannelID": "the channel you're trying to send api monitor updates to",
|
||||
"prefix": "enter prefix for bot commands here"
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
if which node > /dev/null
|
||||
then
|
||||
echo "\x1b[32mNode is already installed, skipping...\x1b[0m"
|
||||
else
|
||||
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
|
||||
sudo apt-get install -y nodejs
|
||||
fi
|
||||
npm i
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sharexapi",
|
||||
"version": "3.5.0",
|
||||
"version": "4.0.0",
|
||||
"description": "ShareX API made in Nodejs. Includes images, videos, code, text, and url shortening",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.18.3",
|
|
@ -4,7 +4,7 @@ const fs = require("fs-extra")
|
|||
const Remarkable = require("remarkable")
|
||||
const ejs = require("ejs")
|
||||
const md = new Remarkable("full", {
|
||||
html: true,
|
||||
html: false,
|
||||
linkify: true,
|
||||
typographer: true
|
||||
})
|
|
@ -0,0 +1,58 @@
|
|||
const path = require("path")
|
||||
const formidable = require("formidable")
|
||||
const fs = require("fs-extra")
|
||||
const ejs = require("ejs")
|
||||
async function paste(req, res) {
|
||||
res.setHeader("Content-Type", "text/text")
|
||||
let fileName = this.randomToken(5) // 916,132,832 possible file names
|
||||
let form = new formidable.IncomingForm()
|
||||
form.parse(req, (err, fields, files) => {
|
||||
let userIP = req.headers["x-forwarded-for"] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress
|
||||
if (!this.auth(this.c.key, fields.key, this.c)) {
|
||||
res.statusCode = 401
|
||||
res.write("Unauthorized");
|
||||
res.end();
|
||||
return this.log.warning(`Unauthorized User | File Upload | ${userIP}`)
|
||||
}
|
||||
this.db.get("files")
|
||||
.push({
|
||||
path: `/${fileName}`,
|
||||
ip: userIP,
|
||||
views: 0
|
||||
})
|
||||
.write();
|
||||
let oldpath = files.fdata.path
|
||||
let newpath = `${__dirname}/../uploads/${fileName+files.fdata.name.toString().match(/(\.)+([a-zA-Z0-9]+)+/g, "").toString()}`;
|
||||
if (Math.round((files.fdata.size / 1024) / 1000) > this.c.paste.max_upload_size) {
|
||||
if (this.monitorChannel !== null) this.bot.createMessage(this.monitorChannel, `\`\`\`MARKDOWN\n[FAILED PASTE][USER]\n[FILE](${files.fdata.name})\n[SIZE](${Math.round(files.fdata.size/1024)}KB)\n[TYPE](${files.fdata.type})\n[IP](${userIP})\n\n[ERROR](ERR_FILE_TOO_BIG)\`\`\``)
|
||||
res.statusCode = 413
|
||||
res.write(`http://${req.headers.host}/ERR_FILE_TOO_BIG`)
|
||||
return res.end()
|
||||
} else {
|
||||
fs.move(oldpath, newpath, err => {
|
||||
fs.readFile(newpath, "utf-8", function read(err, data) {
|
||||
let stream = fs.createWriteStream(`${__dirname}/../uploads/${fileName}.html`)
|
||||
stream.once("open", fd => {
|
||||
let cleaned = data.replace(/>/g, ">")
|
||||
cleaned = cleaned.replace(/</g, "<")
|
||||
ejs.renderFile(`${__dirname}/../views/paste.ejs`, {
|
||||
ogDesc: data.match(/.{1,297}/g)[0],
|
||||
pData: data
|
||||
}, {}, (err, str) => {
|
||||
stream.write(str)
|
||||
})
|
||||
stream.end()
|
||||
fs.unlink(newpath, err => {
|
||||
if (err) return
|
||||
});
|
||||
let insecure = `http://${req.headers.host}/${fileName}`
|
||||
let secure = `https://${req.headers.host}/${fileName}`
|
||||
res.write(req.secure ? secure : insecure)
|
||||
return res.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
module.exports = paste
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
Loading…
Reference in New Issue