commit 5c33066

default  ·  2024-12-31 16:01:08 +0000 UTC
parent c6fc02e
Started support for Mastodon-like /share endpoint.
1 files changed,  +39, -0
+39, -0
 1@@ -164,6 +164,23 @@ static xs_str *greeting_html(void)
 2 }
 3 
 4 
 5+const char *share_page = ""
 6+"<!DOCTYPE html>\n"
 7+"<html>\n"
 8+"<head>\n"
 9+"<title>%s - snac</title>\n"
10+"<meta content=\"width=device-width, initial-scale=1, minimum-scale=1, user-scalable=no\" name=\"viewport\">"
11+"<style>:root {color-scheme: light dark}</style>\n"
12+"</head>\n"
13+"<body><h1>%s link share</h1>\n"
14+"<form method=\"post\" action=\"%s/share-bridge\">\n"
15+"<textarea name=\"content\" rows=\"6\" wrap=\"virtual\" required=\"required\" style=\"width: 50em\">%s</textarea>\n"
16+"<p>Login: <input type=\"text\" name=\"login\" autocapitalize=\"off\" required=\"required\"></p>\n"
17+"<input type=\"submit\" value=\"OK\">\n"
18+"</form><p>%s</p></body></html>\n"
19+"";
20+
21+
22 int server_get_handler(xs_dict *req, const char *q_path,
23                        char **body, int *b_size, char **ctype)
24 /* basic server services */
25@@ -257,6 +274,28 @@ int server_get_handler(xs_dict *req, const char *q_path,
26         *body  = xs_str_new("User-agent: *\n"
27                             "Disallow: /\n");
28     }
29+    else
30+    if (strcmp(q_path, "/share") == 0) {
31+        const xs_dict *q_vars = xs_dict_get(req, "q_vars");
32+        const char *url  = xs_dict_get(q_vars, "url");
33+        const char *text = xs_dict_get(q_vars, "text");
34+        xs *s = NULL;
35+
36+        if (xs_type(text) == XSTYPE_STRING)
37+            s = xs_fmt("%s\n\n%s\n", text, url);
38+        else
39+            s = xs_fmt("%s\n", url);
40+
41+        status = HTTP_STATUS_OK;
42+        *ctype = "text/html";
43+        *body  = xs_fmt(share_page,
44+            xs_dict_get(srv_config, "host"),
45+            xs_dict_get(srv_config, "host"),
46+            srv_baseurl,
47+            s,
48+            USER_AGENT
49+        );
50+    }
51 
52     if (status != 0)
53         srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status));