Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.pasteRawAgents && config.pasteRawAgents.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
Loading