Browse Source

add a / landing page with a git link

Ondřej Hruška 1 year ago
parent
commit
72a51055d2
Signed by: Ondřej Hruška <ondra@ondrovo.com> GPG key ID: 2C5FD5035250423D
5 changed files with 59 additions and 4 deletions
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 2 2
      README.md
  4. 49 0
      src/embed/home.html
  5. 6 0
      src/main.rs

+ 1 - 1
Cargo.lock View File

@@ -735,7 +735,7 @@ dependencies = [
735 735
 
736 736
 [[package]]
737 737
 name = "postit"
738
-version = "0.2.0"
738
+version = "0.2.1"
739 739
 dependencies = [
740 740
  "anyhow",
741 741
  "bincode",

+ 1 - 1
Cargo.toml View File

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

+ 2 - 2
README.md View File

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

+ 49 - 0
src/embed/home.html View File

@@ -0,0 +1,49 @@
1
+<!DOCTYPE html>
2
+<html lang="en">
3
+<head>
4
+  <title>Post-it!</title>
5
+  <meta charset="utf-8">
6
+</head>
7
+<body>
8
+<h1>Welcome to Post-it!</h1>
9
+
10
+<p>Post-it is a tiny file sharing server for small files with limited lifespan.</p>
11
+
12
+<h2>API quickstart</h2>
13
+
14
+<h3>Submit a file: POST binary body to "/"</h3>
15
+
16
+<ul>
17
+  <li>Accepts <code>X-Expire</code> (secs) and <code>Content-Type</code> headers.
18
+  <li>Also accepts an <code>expire</code> URL param.
19
+  <li>Returns a secret token in the <code>X-Secret</code> header, and a File ID in response body.
20
+</ul>
21
+
22
+<h3>Read a file: GET /&lt;file-id&gt;</h3>
23
+<ul>
24
+  <li>The remaining lifespan us returned in an <code>X-Expire</code> header (secs).
25
+</ul>
26
+
27
+<h3>Update a file: PUT to /&lt;file-id&gt;</h3>
28
+<ul>
29
+  <li>Accepts the same headers and params as POST.
30
+  <li>Body may be left empty to leave it unchanged.
31
+  <li>File's lifespan can be extended by setting a new expiration time.
32
+  <li>Requires the secret token as an <code>X-Secret</code> header or a <code>secret</code> URL param.
33
+</ul>
34
+
35
+<h3>Delete a file: DELETE /&lt;file-id&gt;</h3>
36
+<ul>
37
+  <li>The secret token is required, like with PUT.
38
+</ul>
39
+
40
+<p>See the git repository for a more detailed README.</p>
41
+
42
+<h2>Source code</h2>
43
+
44
+<p>Post-it is written in Rust.</p>
45
+
46
+<p>Get the sources at: <a href="https://git.ondrovo.com/MightyPork/postit">https://git.ondrovo.com/MightyPork/postit</a></p>
47
+
48
+</body>
49
+</html>

+ 6 - 0
src/main.rs View File

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