add a / landing page with a git link

master
Ondřej Hruška 5 years ago
parent eb9c2898d0
commit 72a51055d2
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 4
      README.md
  4. 49
      src/embed/home.html
  5. 6
      src/main.rs

2
Cargo.lock generated

@ -735,7 +735,7 @@ dependencies = [
[[package]]
name = "postit"
version = "0.2.0"
version = "0.2.1"
dependencies = [
"anyhow",
"bincode",

@ -1,6 +1,6 @@
[package]
name = "postit"
version = "0.2.0"
version = "0.2.1"
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
edition = "2018"
publish = false

@ -1,6 +1,6 @@
# PostIt file sharing server
# Post-it file sharing server
PostIt is designed to work as a temporary public storage for text (and other)
Post-it is designed to work as a temporary public storage for text (and other)
files uploaded to it by software that need a publicly reachable page without
hosting its own server or even having a public IP.

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Post-it!</title>
<meta charset="utf-8">
</head>
<body>
<h1>Welcome to Post-it!</h1>
<p>Post-it is a tiny file sharing server for small files with limited lifespan.</p>
<h2>API quickstart</h2>
<h3>Submit a file: POST binary body to "/"</h3>
<ul>
<li>Accepts <code>X-Expire</code> (secs) and <code>Content-Type</code> headers.
<li>Also accepts an <code>expire</code> URL param.
<li>Returns a secret token in the <code>X-Secret</code> header, and a File ID in response body.
</ul>
<h3>Read a file: GET /&lt;file-id&gt;</h3>
<ul>
<li>The remaining lifespan us returned in an <code>X-Expire</code> header (secs).
</ul>
<h3>Update a file: PUT to /&lt;file-id&gt;</h3>
<ul>
<li>Accepts the same headers and params as POST.
<li>Body may be left empty to leave it unchanged.
<li>File's lifespan can be extended by setting a new expiration time.
<li>Requires the secret token as an <code>X-Secret</code> header or a <code>secret</code> URL param.
</ul>
<h3>Delete a file: DELETE /&lt;file-id&gt;</h3>
<ul>
<li>The secret token is required, like with PUT.
</ul>
<p>See the git repository for a more detailed README.</p>
<h2>Source code</h2>
<p>Post-it is written in Rust.</p>
<p>Get the sources at: <a href="https://git.ondrovo.com/MightyPork/postit">https://git.ondrovo.com/MightyPork/postit</a></p>
</body>
</html>

@ -35,6 +35,7 @@ const GET_SECRET: &str = "secret";
const FAVICON: &[u8] = include_bytes!("embed/favicon.ico");
const ROBOTS: &[u8] = include_bytes!("embed/robots.txt");
const LANDING_PAGE: &[u8] = include_bytes!("embed/home.html");
/// Post ID (represented as a 16-digit hex string)
type PostId = u64;
@ -97,6 +98,11 @@ fn main() -> anyhow::Result<()> {
info!("{} {}", method, req.raw_url());
if method == "GET" || method == "HEAD" {
if req.url() == "/" {
return decorate_response(Response::from_data("text/html", LANDING_PAGE)
.with_public_cache(86400));
}
if req.url() == "/favicon.ico" {
return decorate_response(Response::from_data("image/vnd.microsoft.icon", FAVICON)
.with_public_cache(86400 * 7));

Loading…
Cancel
Save