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

Commit

Permalink
Redirect to raw paste for certain useragents
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemmmy committed Jan 12, 2020
1 parent 15bdfca commit 0ae14e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Make a file called `config.json`, with the following properties:
"videoFiles": ["mp4","webm"],
"languagePackages": [
"language-lua"
]
],
"rawPasteAgents": "^(?:computercraft|curl|wget)"
}
```
- `logo` - Filenames of your logos images. Make sure to put them in /public.
Expand All @@ -59,6 +60,7 @@ Make a file called `config.json`, with the following properties:
- `audioFiles` Array of file extentions that shitty will treat as audio.
- `videoFiles` Array of file extentions that shitty will treat as video.
- `languagePackages` Array of npm package names containing atom language grammars.
- `rawPasteAgents` Regular expression (case-insensitive) matching agents to return raw pastes for (on `/paste` and `/edit`). Use `null` to disable.

## Custom names

Expand Down
3 changes: 2 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"videoFiles": ["mp4","webm"],
"languagePackages": [
"language-lua"
]
],
"rawPasteAgents": "^(?:computercraft|curl|wget)"
}
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ router.post("/rename", (req, res) => {
});
});

function shouldReturnRaw(req) {
return config.rawPasteAgents && new RegExp(config.rawPasteAgents, "i").test(req.get("User-Agent"));
}

router.post("/edit", (req, res) => {
if (typeof req.body.nonce === "undefined" || typeof req.body.file === "undefined" || typeof noncesLookup[req.body.nonce] === "undefined") return error(req, res, "No file specified.");

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

router.get("/paste/:file", (req, res) => {
if (shouldReturnRaw(req)) return res.redirect("/" + req.params.file);

const filename = sanitizeFilename(req.params.file);
const filePath = path.join(config.imagePath, filename);

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

router.get("/edit/:file", (req, res) => {
if (shouldReturnRaw(req)) return res.redirect("/" + req.params.file);

let editor = true;
if (!req.session || !req.session.authed) {
if (!req.body.password) editor = undefined;
Expand Down

0 comments on commit 0ae14e8

Please sign in to comment.