More work in the Mastodon-share webpoint.

This commit is contained in:
default
2024-12-31 17:42:33 +01:00
parent 5c330660cd
commit 33b6f2af00
2 changed files with 35 additions and 2 deletions
+34 -1
View File
@@ -2917,6 +2917,8 @@ int html_get_handler(const xs_dict *req, const char *q_path,
int proxy = 0;
const char *v;
const xs_dict *q_vars = xs_dict_get(req, "q_vars");
xs *l = xs_split_n(q_path, "/", 2);
v = xs_list_get(l, 1);
@@ -2925,6 +2927,23 @@ int html_get_handler(const xs_dict *req, const char *q_path,
return HTTP_STATUS_NOT_FOUND;
}
if (strcmp(v, "share-bridge") == 0) {
/* temporary redirect for a post */
const char *login = xs_dict_get(q_vars, "login");
const char *content = xs_dict_get(q_vars, "content");
if (xs_type(login) == XSTYPE_STRING && xs_type(content) == XSTYPE_STRING) {
xs *b64 = xs_base64_enc(content, strlen(content));
srv_log(xs_fmt("share-bridge for user '%s'", login));
*body = xs_fmt("%s/%s/share?content=%s", srv_baseurl, login, b64);
return HTTP_STATUS_SEE_OTHER;
}
else
return HTTP_STATUS_NOT_FOUND;
}
uid = xs_dup(v);
/* rss extension? */
@@ -2959,7 +2978,6 @@ int html_get_handler(const xs_dict *req, const char *q_path,
int def_show = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries"));
int show = def_show;
const xs_dict *q_vars = xs_dict_get(req, "q_vars");
if ((v = xs_dict_get(q_vars, "skip")) != NULL)
skip = atoi(v), cache = 0, save = 0;
if ((v = xs_dict_get(q_vars, "show")) != NULL)
@@ -3472,6 +3490,21 @@ int html_get_handler(const xs_dict *req, const char *q_path,
snac_debug(&snac, 1, xs_fmt("Proxy for %s %d", url, status));
}
}
else
if (strcmp(p_path, "share") == 0) { /** direct post **/
if (!login(&snac, req)) {
*body = xs_dup(uid);
status = HTTP_STATUS_UNAUTHORIZED;
}
else {
const char *content = xs_dict_get(q_vars, "content");
// srv_log(xs_fmt("---> SHARE %s", content));
*body = xs_fmt("%s/admin", snac.actor);
*b_size = strlen(*body);
status = HTTP_STATUS_SEE_OTHER;
}
}
else
status = HTTP_STATUS_NOT_FOUND;
+1 -1
View File
@@ -173,7 +173,7 @@ const char *share_page = ""
"<style>:root {color-scheme: light dark}</style>\n"
"</head>\n"
"<body><h1>%s link share</h1>\n"
"<form method=\"post\" action=\"%s/share-bridge\">\n"
"<form method=\"get\" action=\"%s/share-bridge\">\n"
"<textarea name=\"content\" rows=\"6\" wrap=\"virtual\" required=\"required\" style=\"width: 50em\">%s</textarea>\n"
"<p>Login: <input type=\"text\" name=\"login\" autocapitalize=\"off\" required=\"required\"></p>\n"
"<input type=\"submit\" value=\"OK\">\n"