Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 3171146

Browse files
author
Rmlyy
committed
Optimizations
1 parent 4d3aa25 commit 3171146

11 files changed

+114
-91
lines changed

.env

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
PORT=8720
33

44
# Application URL (( Don't put the last / ))
5-
URL=https://yourdomain.com
5+
URL=http://localhost:8720
66

77
# Secret key
8-
SECRET=verysecretkey
8+
SECRET=yoursecretkey
99

1010
# Application Name
1111
NAME=Uploader v1.0

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
package-lock.json
2+
uploads
3+
package-lock.json
4+
.env

README.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
# Uploader v1.0
2-
3-
Simple to use Uploader with Discord Embed, ShareX & Flameshot support.
1+
# Table of contents
2+
1. [Introduction](#introduction)
3+
2. [Features](#features)
4+
3. [Prerequisites](#prerequisites)
5+
4. [Installation](#installation)
6+
5. [Configure ShareX](#configure-sharex)
7+
6. [Configure Flameshot](#configure-flameshot)
8+
7. [Upgrading](#upgrading)
9+
8. [Demo](#demo)
10+
9. [Support](#support)
11+
10. [Donate](#donate)
412
***
513

6-
## Features:
14+
## Introduction
15+
This is a simple to use, configurable & customizable uploader with Discord Embed, ShareX, Flameshot support, and many more [features](#features).
16+
17+
## Features
718
* Customizable
819
* ShareX Support
920
* Flameshot Support
@@ -20,8 +31,8 @@ Simple to use Uploader with Discord Embed, ShareX & Flameshot support.
2031
* Node.JS v14 recommended or v14+
2132
* (Optional) a web server
2233

23-
## Installation:
24-
**NOTE:** The installation guide was written assuming the host OS is Debian 10.
34+
## Installation
35+
**NOTE:** The installation guide was written assuming the host OS is Ubuntu 20.04.
2536

2637
1. Clone the repository
2738
`$ git clone https://github.com/Rmlyy/Uploader.git`
@@ -33,7 +44,7 @@ Simple to use Uploader with Discord Embed, ShareX & Flameshot support.
3344
4.1 Change URL
3445
`URL=https://yourdomain.com` Change the URL to your domain or IP Address. **Don't put the last /**
3546
4.2 Change the secret key
36-
`SECRET=verysecretkey` It is highly recommended to change the secret key so others can't upload to your server.
47+
`SECRET=yoursecretkey` It is highly recommended to change the secret key so others can't upload to your server.
3748
5. Run it
3849
`node app.js`
3950
You can use something like `screen` or `pm2` to keep the server running.
@@ -121,17 +132,23 @@ Make sure you have the `proxy_http` module enabled: `a2enmod proxy_http`
121132
ProxyPass "/" "http://localhost:8720"
122133
</VirtualHost>
123134
```
124-
7. Configure ShareX
125-
7.1 [Download ShareX example config](https://rmly.dev/uploader/config.sxcu)
126-
7.2 Import the config
127-
7.3 Change "Request URL" to your domain
128-
7.4 Change secret key value to your secret key
135+
## Configure ShareX
136+
1. [Download the ShareX example config](https://dl.rmly.dev/config.sxcu)
137+
2. Import the config
138+
3. Change "Request URL" to your domain
139+
4. Change secret key value to your secret key
129140

130141
## Configure Flameshot
131142
For Flameshot users on Linux, you can use [this shell script](https://gist.github.com/Rmlyy/3d712dd1d5ed75416746f7657b3819fb).
132143

144+
### Upgrading
145+
To upgrade, simply replace all the old files and directories (except the uploads directory if you want to keep your uploads) with the new files, and then restart the server.
146+
147+
### Demo
148+
A live version of this uploader is hosted at [https://i.rmly.dev](https://i.rmly.dev), however, there isn't any possibility to test the upload at the moment, it is best if you try it on your own.
149+
133150
## Support
134-
Need help? Feel free to join [my discord server](https://discord.rmly.dev) or [email me](mailto:rmly@rmly.dev).
151+
Need help? Feel free to join [my discord server](https://discord.rmly.dev) or [email me](mailto:hello@rmly.dev).
135152

136153
## Donate
137154
You can donate [here](https://rmly.dev/donate) to support this project. Thanks!

env.example

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Listening port
2+
PORT=8720
3+
4+
# Application URL (( Don't put the last / ))
5+
URL=https://yourdomain.com
6+
7+
# Secret key
8+
SECRET=yoursecretkey
9+
10+
# Application Name
11+
NAME=Uploader v1.0
12+
13+
# Application Headers
14+
IMAGE_HEADER=${name}, ${size}, ${width}x${height}
15+
TEXT_HEADER=${name}, ${size}, ${words} words
16+
UNCATEGORIZED_HEADER=${name}, ${size}
17+
18+
# Statistics
19+
STATISTICS=${total} uploads with a size of ${size}
20+
21+
# Discord Embeds / Twitter Cards
22+
## Image Card
23+
IMAGE_CARD_TITLE=${name} (${size}, ${width}x${height})
24+
IMAGE_CARD_DESCRIPTION=Uploaded at ${uploadedAt}
25+
26+
## Text Card
27+
TEXT_CARD_TITLE=${name} (${size}, ${words} words)
28+
TEXT_CARD_DESCRIPTION=Uploaded at ${uploadedAt}
29+
30+
## Uncategorized Card / Video Card
31+
UNCATEGORIZED_CARD_TITLE=${name} ${size}
32+
UNCATEGORIZED_CARD_DESCRIPTION=Uploaded at ${uploadedAt}
33+
34+
# Set to random for a random color or enter your preferred color in HEX format
35+
CARD_COLOR=random

routes/delete.js

+11-25
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
1-
const express = require('express')
2-
const router = express.Router()
3-
4-
const fs = require('fs')
1+
const router = require('express').Router()
52
const path = require('path')
3+
const fs = require('fs')
4+
const getPath = require('../utils/path')
65

76
router.get('/:file', (req, res) => {
87
const { file } = req.params
98
const { key } = req.query
10-
const imagesPath = `${path.dirname(require.main.filename)}/uploads/images/${file}`
11-
const textPath = `${path.dirname(require.main.filename)}/uploads/text/${file}`
12-
const videosPath = `${path.dirname(require.main.filename)}/uploads/videos/${file}`
13-
const uncategorizedPath = `${path.dirname(require.main.filename)}/uploads/uncategorized/${file}`
14-
let finalPath
15-
16-
if (fs.existsSync(imagesPath)) {
17-
finalPath = imagesPath
18-
} else if (fs.existsSync(textPath)) {
19-
finalPath = textPath
20-
} else if (fs.existsSync(videosPath)) {
21-
finalPath = videosPath
22-
} else if (fs.existsSync(uncategorizedPath)) {
23-
finalPath = uncategorizedPath
24-
} else return res.status(404).render('404')
259

26-
const fileData = require(`../uploads/data/${file}.json`)
10+
if (getPath(file)) {
11+
const fileData = require(`../uploads/data/${file}.json`)
2712

28-
if (fileData.key === key) {
29-
fs.unlinkSync(finalPath)
30-
fs.unlinkSync(`${path.dirname(require.main.filename)}/uploads/data/${file}.json`)
31-
res.send('File sucessfully deleted.')
32-
} else return res.status(401).send('Invalid deletion key.')
13+
if (fileData.key === key) {
14+
fs.unlinkSync(getPath(file))
15+
fs.unlinkSync(`${path.dirname(require.main.filename)}/uploads/data/${file}.json`)
16+
res.send('File sucessfully deleted.')
17+
} else res.status(401).send('Invalid deletion key.')
18+
} else res.status(404).render('404')
3319
})
3420

3521
module.exports = router

routes/dl.js

+6-22
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
const express = require('express')
2-
const router = express.Router()
3-
4-
const fs = require('fs')
5-
const path = require('path')
1+
const router = require('express').Router()
2+
const path = require('../utils/path')
63

74
router.get('/:file', (req, res) => {
85
const { file } = req.params
9-
const imagesPath = `${path.dirname(require.main.filename)}/uploads/images/${file}`
10-
const textPath = `${path.dirname(require.main.filename)}/uploads/text/${file}`
11-
const videosPath = `${path.dirname(require.main.filename)}/uploads/videos/${file}`
12-
const uncategorizedPath = `${path.dirname(require.main.filename)}/uploads/uncategorized/${file}`
13-
let finalPath
14-
15-
if (fs.existsSync(imagesPath)) {
16-
finalPath = imagesPath
17-
} else if (fs.existsSync(textPath)) {
18-
finalPath = textPath
19-
} else if (fs.existsSync(videosPath)) {
20-
finalPath = videosPath
21-
} else if (fs.existsSync(uncategorizedPath)) {
22-
finalPath = uncategorizedPath
23-
} else return res.status(404).render('404')
246

25-
res.set("Content-Disposition", `attachment;filename=${file}`)
26-
res.sendFile(finalPath)
7+
if (path(file)) {
8+
res.set("Content-Disposition", `attachment;filename=${file}`)
9+
res.sendFile(path(file))
10+
} else res.status(404).render('404')
2711
})
2812

2913
module.exports = router

routes/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const express = require('express')
2-
const router = express.Router()
1+
const router = require('express').Router()
32

43
const template = require('string-placeholder')
54
const totalUploads = require('../utils/totalUploads')

routes/raw.js

+4-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
const express = require('express')
2-
const router = express.Router()
3-
4-
const fs = require('fs')
5-
const path = require('path')
1+
const router = require('express').Router()
2+
const path = require('../utils/path')
63

74
router.get('/:file', (req, res) => {
85
const { file } = req.params
9-
const imagesPath = `${path.dirname(require.main.filename)}/uploads/images/${file}`
10-
const textPath = `${path.dirname(require.main.filename)}/uploads/text/${file}`
11-
const videosPath = `${path.dirname(require.main.filename)}/uploads/videos/${file}`
12-
const uncategorizedPath = `${path.dirname(require.main.filename)}/uploads/uncategorized/${file}`
13-
let finalPath
14-
15-
if (fs.existsSync(imagesPath)) {
16-
finalPath = imagesPath
17-
} else if (fs.existsSync(textPath)) {
18-
finalPath = textPath
19-
} else if (fs.existsSync(videosPath)) {
20-
finalPath = videosPath
21-
} else if (fs.existsSync(uncategorizedPath)) {
22-
finalPath = uncategorizedPath
23-
} else return res.status(404).render('404')
246

25-
res.sendFile(finalPath)
7+
if (path(file)) res.sendFile(path(file))
8+
else res.status(404).render('404')
269
})
2710

2811
module.exports = router

routes/upload.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const express = require('express')
1+
const router = require('express').Router()
22
const path = require('path')
33
const fs = require('fs')
4-
const router = express.Router()
54

65
router.post('/', (req, res) => {
76
const { secret, onlyURL } = req.query
@@ -17,7 +16,7 @@ router.post('/', (req, res) => {
1716

1817
const generateString = require('../utils/generateString')
1918
const fileName = `${generateString(5)}${path.extname(file.name)}`
20-
const deletionKey = generateString(32)
19+
const deletionKey = generateString(8)
2120
const date = new Date()
2221

2322
let uploadPath

routes/view.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const express = require('express')
2-
const router = express.Router()
1+
const router = require('express').Router()
32

43
const fs = require('fs')
54
const path = require('path')

utils/path.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const path = require('path')
2+
const fs = require('fs')
3+
4+
module.exports = function(file) {
5+
const imagesPath = `${path.dirname(require.main.filename)}/uploads/images/${file}`
6+
const textPath = `${path.dirname(require.main.filename)}/uploads/text/${file}`
7+
const videosPath = `${path.dirname(require.main.filename)}/uploads/videos/${file}`
8+
const uncategorizedPath = `${path.dirname(require.main.filename)}/uploads/uncategorized/${file}`
9+
10+
if (fs.existsSync(imagesPath)) {
11+
return imagesPath
12+
} else if (fs.existsSync(textPath)) {
13+
return textPath
14+
} else if (fs.existsSync(videosPath)) {
15+
return videosPath
16+
} else if (fs.existsSync(uncategorizedPath)) {
17+
return uncategorizedPath
18+
} else return false
19+
}

0 commit comments

Comments
 (0)