Skip to content
Open
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ PORT=3000
# Comma-separated list of API keys
API_KEYS=key1,key2,key3

# Enable the web upload page (default: false)
ENABLE_UPLOAD_PAGE=false

# This is the maximum file size that can be uploaded and the max file name length. '-1' is unlimited file size, not recommended.
FILE_NAME_LENGTH=10
FILE_MAX_SIZE_MB=30
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
CLAUDE.md
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ We also recommend forking the project and deploying your forked version to avoid
- [ ] Advertising support
- [ ] NSFW detection and filtering

### Web Upload Page
The built-in web upload page at `/upload` is disabled by default. To enable it, set the following in your `.env`:
```
ENABLE_UPLOAD_PAGE=true
```

### S3 Compatible Storage
For the s3 compatbile storage engine, we recommend using Contabo Object Storage. It's a cheap (2,50/mth for 250GB with unlimited bandwidth at 80mbps) and really easy to set up. Just make an account, get the object storage, make a bucket and fill in the details in the `.env` and it _just works_.

Expand Down
31 changes: 30 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ const port = process.env.PORT;
const hosterEmail = process.env.HOSTER_EMAIL;

app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'", "https://cdn.jsdelivr.net"],
imgSrc: ["'self'", "data:", "https:"],
connectSrc: ["'self'"],
fontSrc: ["'self'", "https://cdn.jsdelivr.net"],
},
},
}));
app.use(fileRoutes);
app.use(helmet());

const s3 = require("./engines/s3.engine");
const local = require("./engines/local.engine");
Expand Down Expand Up @@ -57,6 +69,23 @@ app.get("/", async (req, res) => {
});
});

const enableUploadPage = process.env.ENABLE_UPLOAD_PAGE === "true";

app.get("/upload", (req, res) => {
if (!enableUploadPage) {
return res.status(404).send("Upload page is disabled.");
}
res.render("upload");
});

app.get("/api/config", (req, res) => {
res.json({
maxFileSize: parseInt(process.env.FILE_MAX_SIZE_MB, 10) * 1024 * 1024,
maxFileSizeMB: parseInt(process.env.FILE_MAX_SIZE_MB, 10),
fileNameLength: parseInt(process.env.FILE_NAME_LENGTH, 10) || 10,
});
});

app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"scripts": {
"dev": "node index.js",
"test": "jest"
},
"jest": {
Expand Down
Loading