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

Commit 2b80b4f

Browse files
committed
Redirect to raw paste for certain useragents
1 parent 15bdfca commit 2b80b4f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,13 @@ router.post("/edit", (req, res) => {
565565
});
566566
});
567567

568+
function shouldReturnRaw(req) {
569+
return config.rawPasteAgents && new RegExp(config.rawPasteAgents, "i").test(req.headers["user-agent"]);
570+
}
571+
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)