Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 0ae14e8

Browse files
committed
Redirect to raw paste for certain useragents
1 parent 15bdfca commit 0ae14e8

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Make a file called `config.json`, with the following properties:
3636
"videoFiles": ["mp4","webm"],
3737
"languagePackages": [
3838
"language-lua"
39-
]
39+
],
40+
"rawPasteAgents": "^(?:computercraft|curl|wget)"
4041
}
4142
```
4243
- `logo` - Filenames of your logos images. Make sure to put them in /public.
@@ -59,6 +60,7 @@ Make a file called `config.json`, with the following properties:
5960
- `audioFiles` Array of file extentions that shitty will treat as audio.
6061
- `videoFiles` Array of file extentions that shitty will treat as video.
6162
- `languagePackages` Array of npm package names containing atom language grammars.
63+
- `rawPasteAgents` Regular expression (case-insensitive) matching agents to return raw pastes for (on `/paste` and `/edit`). Use `null` to disable.
6264

6365
## Custom names
6466

config.example.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
"videoFiles": ["mp4","webm"],
2828
"languagePackages": [
2929
"language-lua"
30-
]
30+
],
31+
"rawPasteAgents": "^(?:computercraft|curl|wget)"
3132
}

index.js

+8
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,10 @@ router.post("/rename", (req, res) => {
541541
});
542542
});
543543

544+
function shouldReturnRaw(req) {
545+
return config.rawPasteAgents && new RegExp(config.rawPasteAgents, "i").test(req.get("User-Agent"));
546+
}
547+
544548
router.post("/edit", (req, res) => {
545549
if (typeof req.body.nonce === "undefined" || typeof req.body.file === "undefined" || typeof noncesLookup[req.body.nonce] === "undefined") return error(req, res, "No file specified.");
546550

@@ -566,6 +570,8 @@ router.post("/edit", (req, res) => {
566570
});
567571

568572
router.get("/paste/:file", (req, res) => {
573+
if (shouldReturnRaw(req)) return res.redirect("/" + req.params.file);
574+
569575
const filename = sanitizeFilename(req.params.file);
570576
const filePath = path.join(config.imagePath, filename);
571577

@@ -597,6 +603,8 @@ router.get("/paste/:file", (req, res) => {
597603
});
598604

599605
router.get("/edit/:file", (req, res) => {
606+
if (shouldReturnRaw(req)) return res.redirect("/" + req.params.file);
607+
600608
let editor = true;
601609
if (!req.session || !req.session.authed) {
602610
if (!req.body.password) editor = undefined;

0 commit comments

Comments
 (0)