2021-07-26 14:29:46 -04:00
< a href = "https://github.com/orhun/rustypaste" > < img src = "img/rustypaste_logo.png" width = "500" > < / a >
2023-05-16 21:32:54 -04:00
[![GitHub Release ](https://img.shields.io/github/v/release/orhun/rustypaste?style=flat&labelColor=823213&color=2c2c2c&logo=GitHub&logoColor=white )](https://github.com/orhun/rustypaste/releases)
[![Crate Release ](https://img.shields.io/crates/v/rustypaste?style=flat&labelColor=823213&color=2c2c2c&logo=Rust&logoColor=white )](https://crates.io/crates/rustypaste/)
[![Coverage ](https://img.shields.io/codecov/c/gh/orhun/rustypaste?style=flat&labelColor=823213&color=2c2c2c&logo=Codecov&logoColor=white )](https://codecov.io/gh/orhun/rustypaste)
[![Continuous Integration ](https://img.shields.io/github/actions/workflow/status/orhun/rustypaste/ci.yml?branch=master&style=flat&labelColor=823213&color=2c2c2c&logo=GitHub%20Actions&logoColor=white )](https://github.com/orhun/rustypaste/actions?query=workflow%3A%22Continuous+Integration%22)
[![Continuous Deployment ](https://img.shields.io/github/actions/workflow/status/orhun/rustypaste/cd.yml?style=flat&labelColor=823213&color=2c2c2c&logo=GitHub%20Actions&logoColor=white&label=deploy )](https://github.com/orhun/rustypaste/actions?query=workflow%3A%22Continuous+Deployment%22)
[![Docker Builds ](https://img.shields.io/github/actions/workflow/status/orhun/rustypaste/docker.yml?style=flat&labelColor=823213&color=2c2c2c&label=docker&logo=Docker&logoColor=white )](https://hub.docker.com/r/orhunp/rustypaste)
[![Documentation ](https://img.shields.io/docsrs/rustypaste?style=flat&labelColor=823213&color=2c2c2c&logo=Rust&logoColor=white )](https://docs.rs/rustypaste/)
2021-07-26 14:29:46 -04:00
**Rustypaste** is a minimal file upload/pastebin service.
```sh
$ echo "some text" > awesome.txt
2021-07-27 09:20:01 -04:00
$ curl -F "file=@awesome.txt" https://paste.site.com
https://paste.site.com/safe-toad.txt
2021-07-26 14:29:46 -04:00
2021-07-27 09:20:01 -04:00
$ curl https://paste.site.com/safe-toad.txt
2021-07-26 14:29:46 -04:00
some text
```
2023-05-14 12:03:53 -04:00
The public instance is available at [https://rustypaste.shuttleapp.rs ](https://rustypaste.shuttleapp.rs ) 🚀
2021-07-26 14:29:46 -04:00
## Features
2021-11-07 08:06:57 -05:00
- File upload & URL shortening & upload from URL
2021-07-26 14:29:46 -04:00
- supports basic HTTP authentication
- random file names (optional)
- pet name (e.g. `capital-mosquito.txt` )
- alphanumeric string (e.g. `yB84D2Dv.txt` )
2021-08-27 14:12:18 -04:00
- supports expiring links
2023-05-14 16:55:47 -04:00
- auto-expiration of files (optional)
2022-03-23 04:38:32 -04:00
- auto-deletion of expired files (optional)
2021-08-27 14:12:18 -04:00
- supports one shot links (can only be viewed once)
2021-07-26 14:29:46 -04:00
- guesses MIME types
2021-08-09 16:12:51 -04:00
- supports overriding and blacklisting
2023-01-31 12:56:04 -05:00
- supports forcing to download via `?download=true`
2021-10-12 12:35:06 -04:00
- no duplicate uploads (optional)
2021-07-26 14:29:46 -04:00
- Single binary
2021-07-27 06:25:47 -04:00
- [binary releases ](https://github.com/orhun/rustypaste/releases )
2021-11-07 08:06:57 -05:00
- Simple configuration
- supports hot reloading
2021-07-26 14:29:46 -04:00
- Easy to deploy
- [docker images ](https://hub.docker.com/r/orhunp/rustypaste )
- No database
- filesystem is used
- Self-hosted
- _centralization is bad!_
- Written in Rust
- _blazingly fast!_
2021-09-18 18:49:59 -04:00
## Installation
### From crates.io
```sh
cargo install rustypaste
```
2022-03-13 14:13:31 -04:00
### Arch Linux
```sh
pacman -S rustypaste
```
2023-05-17 05:28:39 -04:00
### Alpine Linux
`rustypaste` is available for [Alpine Edge ](https://pkgs.alpinelinux.org/packages?name=rustypaste&branch=edge ). It can be installed via [apk ](https://wiki.alpinelinux.org/wiki/Alpine_Package_Keeper ) after enabling the [testing repository ](https://wiki.alpinelinux.org/wiki/Repositories ).
```sh
apk add rustypaste
```
2021-09-18 18:49:59 -04:00
### Binary releases
2023-05-17 05:28:39 -04:00
See the available binaries on the [releases ](https://github.com/orhun/rustypaste/releases/ ) page.
2021-09-18 18:49:59 -04:00
### Build from source
```sh
git clone https://github.com/orhun/rustypaste.git
cd rustypaste/
cargo build --release
```
2022-03-23 09:41:09 -04:00
#### Testing
2023-05-17 05:29:40 -04:00
##### Unit tests
2022-03-23 09:41:09 -04:00
```sh
cargo test -- --test-threads 1
```
2023-05-17 05:29:40 -04:00
##### Test Fixtures
```sh
./fixtures/test-fixtures.sh
```
2021-07-26 14:29:46 -04:00
## Usage
2021-09-18 18:46:50 -04:00
The standalone command line tool (`rpaste`) is available [here ](https://github.com/orhun/rustypaste-cli ).
2021-07-26 14:29:46 -04:00
### CLI
```sh
function rpaste() {
2022-03-11 16:03:37 -05:00
curl -F "file=@$1" -H "Authorization: < auth_token > " "< server_address > "
2021-07-26 14:29:46 -04:00
}
```
**\*** consider reading authorization headers from a file. (e.g. `-H @rpaste_auth` )
```sh
# upload a file
$ rpaste x.txt
# paste from stdin
$ rpaste -
```
2021-08-27 14:12:18 -04:00
#### Expiration
```sh
2021-09-18 18:27:14 -04:00
$ curl -F "file=@x.txt" -H "expire:10min" "< server_address > "
2021-08-27 14:12:18 -04:00
```
(supported units: `ns` , `us` , `ms` , `sec` , `min` , `hours` , `days` , `weeks` , `months` , `years` )
2021-11-06 16:55:55 -04:00
#### One shot
2021-08-26 16:13:32 -04:00
```sh
2021-09-18 18:27:14 -04:00
$ curl -F "oneshot=@x.txt" "< server_address > "
2021-08-26 16:13:32 -04:00
```
2021-11-06 16:55:55 -04:00
#### URL shortening
2021-08-04 10:49:57 -04:00
```sh
2021-09-18 18:27:14 -04:00
$ curl -F "url=https://example.com/some/long/url" "< server_address > "
2021-08-04 10:49:57 -04:00
```
2021-11-07 09:25:42 -05:00
#### Paste file from remote URL
2021-11-06 16:55:55 -04:00
```sh
$ curl -F "remote=https://example.com/file.png" "< server_address > "
```
2022-03-17 04:53:16 -04:00
#### Cleaning up expired files
2022-03-23 04:38:32 -04:00
Configure `delete_expired_files` to set an interval for deleting the expired files automatically.
On the other hand, following script can be used as [cron ](https://en.wikipedia.org/wiki/Cron ) for cleaning up the expired files manually:
2022-03-17 04:53:16 -04:00
```sh
#!/bin/env sh
now=$(date +%s)
find upload/ -maxdepth 2 -type f -iname "*.[0-9]*" |
while read -r filename; do
[ "$(( ${filename##*.} / 1000 - "${now}" ))" -lt 0 ] & & rm -v "${filename}"
done
```
2021-07-26 14:29:46 -04:00
### Server
To start the server:
```sh
$ rustypaste
```
If the configuration file is not found in the current directory, specify it via `CONFIG` environment variable:
```sh
$ CONFIG="$HOME/.rustypaste.toml" rustypaste
```
To enable basic HTTP auth, set the `AUTH_TOKEN` environment variable (via `.env` ):
```sh
2021-07-27 08:48:21 -04:00
$ echo "AUTH_TOKEN=$(openssl rand -base64 16)" > .env
2021-07-26 14:29:46 -04:00
$ rustypaste
```
See [config.toml ](./config.toml ) for configuration options.
#### Docker
Following command can be used to run a container which is built from the [Dockerfile ](./Dockerfile ) in this repository:
```sh
$ docker run --rm -d \
-v "$(pwd)/upload/":/app/upload \
2021-08-09 16:27:35 -04:00
-v "$(pwd)/config.toml":/app/config.toml \
2021-07-26 14:29:46 -04:00
--env-file "$(pwd)/.env" \
-e "RUST_LOG=debug" \
-p 8000:8000 \
--name rustypaste \
orhunp/rustypaste
```
- uploaded files go into `./upload` (on the host machine)
- set the `AUTH_TOKEN` via `-e` or `--env-file` to enable auth
You can build this image using `docker build -t rustypaste .` command.
If you want to run the image using [docker compose ](https://docs.docker.com/compose/ ), simply run `docker-compose up -d` . (see [docker-compose.yml ](./docker-compose.yml ))
#### Nginx
Example server configuration with reverse proxy:
```nginx
server {
listen 80;
location / {
2021-07-27 09:16:31 -04:00
proxy_pass http://localhost:8000/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "sameorigin";
add_header X-Content-Type-Options "nosniff";
2021-07-26 14:29:46 -04:00
}
}
```
If you get a `413 Request Entity Too Large` error during upload, set the max body size in `nginx.conf` :
```nginx
http {
# ...
client_max_body_size 100M;
}
```
### Contributing
Pull requests are welcome!
2022-05-16 03:28:57 -04:00
Consider submitting your ideas via [issues ](https://github.com/orhun/rustypaste/issues/new ) first and check out the [existing issues ](https://github.com/orhun/rustypaste/issues ).
2021-07-26 14:38:15 -04:00
#### License
< sup >
All code is licensed under < a href = "LICENSE" > The MIT License< / a > .
< / sup >