docs(example): add information about using HTML form (#51)

* docs(readme): add information about using html form

* chore(example): improve HTML form example

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
This commit is contained in:
Chris Jones 2023-05-30 18:21:15 -04:00 committed by GitHub
parent 1a9163639c
commit 1a89589669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 138 additions and 0 deletions

View File

@ -3,6 +3,7 @@
/.github/
/upload/
/shuttle/
/examples/
# Files
.gitignore

View File

@ -204,6 +204,15 @@ $ rustypaste
See [config.toml](./config.toml) for configuration options.
#### HTML Form
It is possible to use an HTML form for uploading files. To do so, you need to update two fields in your `config.toml`:
- Set the `landing_page_content_type` to `text/html; charset=utf-8`.
- Update the `landing_page` field with your HTML form.
For an example, see [examples/html_form.toml](./examples/html_form.toml)
#### Docker
Following command can be used to run a container which is built from the [Dockerfile](./Dockerfile) in this repository:

128
examples/html_form.toml Normal file
View File

@ -0,0 +1,128 @@
[config]
refresh_rate = "1s"
[server]
address = "127.0.0.1:8000"
#url = "https://rustypaste.shuttleapp.rs"
#workers=4
max_content_length = "10MB"
upload_path = "./upload"
timeout = "30s"
expose_version = false
landing_page = """
<html lang="en">
<head>
<title>rustypaste</title>
<meta charset="utf-8" />
<style>
body {
background-color: #f2f2f2;
font-family: arial, sans-serif;
margin: 0;
padding: 0;
}
pre {
background-color: #333;
color: #fff;
font-size: 18px;
margin: 0;
overflow: auto;
padding: 20px;
white-space: pre-wrap;
}
h2 {
color: #333;
font-size: 24px;
margin-top: 40px;
}
form {
margin: 20px 0;
}
input[type="url"],
input[type="file"] {
border: none;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
font-family: arial, sans-serif;
font-size: 18px;
margin-right: 10px;
padding: 10px;
width: 400px;
}
input[type="submit"] {
background-color: #333;
border: none;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
color: #fff;
cursor: pointer;
font-family: arial, sans-serif;
font-size: 18px;
padding: 10px 20px;
transition: background-color 0.2s ease-in-out;
}
input[type="submit"]:hover {
background-color: #444;
}
</style>
</head>
<body>
<pre>
the server administrator might remove any pastes that they do not personally
want to host.
by default, pastes expire every hour.
</pre
>
<h2>share url</h2>
<form action="/" method="post" enctype="multipart/form-data">
<input type="url" name="url" />
<input type="submit" value="share" />
</form>
<h2>share file from url</h2>
<form action="/" method="post" enctype="multipart/form-data">
<input type="url" name="remote" />
<input type="submit" value="share" />
</form>
<h2>share file</h2>
<form action="/" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="share" />
</form>
<h2>share one-time file</h2>
<form action="/" method="post" enctype="multipart/form-data">
<input type="file" name="oneshot" />
<input type="submit" value="share" />
</form>
</body>
</html>
"""
landing_page_content_type = "text/html; charset=utf-8"
[paste]
random_url = { enabled = true, type = "petname", words = 2, separator = "-" }
#random_url = { enabled = true, type = "alphanumeric", length = 8 }
default_extension = "txt"
mime_override = [
{ mime = "image/jpeg", regex = "^.*\\.jpg$" },
{ mime = "image/png", regex = "^.*\\.png$" },
{ mime = "image/svg+xml", regex = "^.*\\.svg$" },
{ mime = "video/webm", regex = "^.*\\.webm$" },
{ mime = "video/x-matroska", regex = "^.*\\.mkv$" },
{ mime = "application/octet-stream", regex = "^.*\\.bin$" },
{ mime = "text/plain", regex = "^.*\\.(log|txt|diff|sh|rs|toml)$" },
]
mime_blacklist = [
"application/x-dosexec",
"application/java-archive",
"application/java-vm",
]
duplicate_files = true
# default_expiry = "1h"
delete_expired_files = { enabled = true, interval = "1h" }