summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-11-07 18:57:52 +0100
committerGravatar default2024-11-07 18:57:52 +0100
commit3313dc8df5fc936edd27fb1c74ac9d58df202817 (patch)
treed670068a473e175d49d07ca32798c78665899fc9
parentMore proxy_media work. (diff)
downloadsnac2-3313dc8df5fc936edd27fb1c74ac9d58df202817.tar.gz
snac2-3313dc8df5fc936edd27fb1c74ac9d58df202817.tar.xz
snac2-3313dc8df5fc936edd27fb1c74ac9d58df202817.zip
Changed make_url().
-rw-r--r--html.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/html.c b/html.c
index 45a0447..055a27d 100644
--- a/html.c
+++ b/html.c
@@ -42,16 +42,16 @@ int login(snac *snac, const xs_dict *headers)
42} 42}
43 43
44 44
45xs_str *make_url(snac *user, int proxy_media, const char *href) 45xs_str *make_url(const char *href, const char *proxy)
46/* makes an URL, possibly including proxying */ 46/* makes an URL, possibly including proxying */
47{ 47{
48 xs_str *url = NULL; 48 xs_str *url = NULL;
49 49
50 if (user && proxy_media) { 50 if (proxy) {
51 xs *h = xs_replace(href, "https:/" "/", ""); 51 xs *p = xs_str_cat(xs_dup(proxy), "/proxy/");
52 url = xs_fmt("%s/proxy/%s", user->actor, h); 52 url = xs_replace(href, "https:/" "/", p);
53 53
54 snac_debug(user, 1, xs_fmt("Proxying %s %s", href, url)); 54 srv_debug(1, xs_fmt("Proxying %s %s", href, url));
55 } 55 }
56 else 56 else
57 url = xs_dup(href); 57 url = xs_dup(href);
@@ -120,7 +120,7 @@ xs_str *actor_name(xs_dict *actor)
120 120
121 121
122xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date, 122xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
123 const char *udate, const char *url, int priv, int in_people, int proxy) 123 const char *udate, const char *url, int priv, int in_people, const char *proxy)
124{ 124{
125 xs_html *actor_icon = xs_html_tag("p", NULL); 125 xs_html *actor_icon = xs_html_tag("p", NULL);
126 126
@@ -138,7 +138,7 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
138 v = xs_list_get(v, 0); 138 v = xs_list_get(v, 0);
139 139
140 if ((v = xs_dict_get(v, "url")) != NULL) 140 if ((v = xs_dict_get(v, "url")) != NULL)
141 avatar = make_url(user, proxy, v); 141 avatar = make_url(v, proxy);
142 } 142 }
143 143
144 if (avatar == NULL) 144 if (avatar == NULL)
@@ -263,7 +263,7 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
263} 263}
264 264
265 265
266xs_html *html_msg_icon(snac *user, const char *actor_id, const xs_dict *msg, int proxy) 266xs_html *html_msg_icon(snac *user, const char *actor_id, const xs_dict *msg, const char *proxy)
267{ 267{
268 xs *actor = NULL; 268 xs *actor = NULL;
269 xs_html *actor_icon = NULL; 269 xs_html *actor_icon = NULL;
@@ -1483,7 +1483,10 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
1483 const char *v; 1483 const char *v;
1484 int has_title = 0; 1484 int has_title = 0;
1485 int collapse_threads = 0; 1485 int collapse_threads = 0;
1486 int proxy_media = xs_is_true(xs_dict_get(srv_config, "proxy_media")); 1486 const char *proxy = NULL;
1487
1488 if (user && !read_only && xs_is_true(xs_dict_get(srv_config, "proxy_media")))
1489 proxy = user->actor;
1487 1490
1488 /* do not show non-public messages in the public timeline */ 1491 /* do not show non-public messages in the public timeline */
1489 if ((read_only || !user) && !is_msg_public(msg)) 1492 if ((read_only || !user) && !is_msg_public(msg))
@@ -1515,7 +1518,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
1515 xs_html_tag("div", 1518 xs_html_tag("div",
1516 xs_html_attr("class", "snac-origin"), 1519 xs_html_attr("class", "snac-origin"),
1517 xs_html_text(L("follows you"))), 1520 xs_html_text(L("follows you"))),
1518 html_msg_icon(read_only ? NULL : user, xs_dict_get(msg, "actor"), msg, proxy_media))); 1521 html_msg_icon(read_only ? NULL : user, xs_dict_get(msg, "actor"), msg, proxy)));
1519 } 1522 }
1520 else 1523 else
1521 if (!xs_match(type, POSTLIKE_OBJECT_TYPE)) { 1524 if (!xs_match(type, POSTLIKE_OBJECT_TYPE)) {
@@ -1694,7 +1697,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
1694 } 1697 }
1695 1698
1696 xs_html_add(post_header, 1699 xs_html_add(post_header,
1697 html_msg_icon(read_only ? NULL : user, actor, msg, proxy_media)); 1700 html_msg_icon(read_only ? NULL : user, actor, msg, proxy));
1698 1701
1699 /** post content **/ 1702 /** post content **/
1700 1703
@@ -1981,7 +1984,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
1981 if (content && xs_str_in(content, o_href) != -1) 1984 if (content && xs_str_in(content, o_href) != -1)
1982 continue; 1985 continue;
1983 1986
1984 xs *href = make_url(user, proxy_media && !read_only, o_href); 1987 xs *href = make_url(o_href, proxy);
1985 1988
1986 if (xs_startswith(type, "image/") || strcmp(type, "Image") == 0) { 1989 if (xs_startswith(type, "image/") || strcmp(type, "Image") == 0) {
1987 xs_html_add(content_attachments, 1990 xs_html_add(content_attachments,
@@ -2433,10 +2436,8 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
2433} 2436}
2434 2437
2435 2438
2436xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t) 2439xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t, const char *proxy)
2437{ 2440{
2438 int proxy_media = xs_is_true(xs_dict_get(srv_config, "proxy_media"));
2439
2440 xs_html *snac_posts; 2441 xs_html *snac_posts;
2441 xs_html *people = xs_html_tag("div", 2442 xs_html *people = xs_html_tag("div",
2442 xs_html_tag("h2", 2443 xs_html_tag("h2",
@@ -2462,7 +2463,7 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t)
2462 xs_html_tag("div", 2463 xs_html_tag("div",
2463 xs_html_attr("class", "snac-post-header"), 2464 xs_html_attr("class", "snac-post-header"),
2464 html_actor_icon(snac, actor, xs_dict_get(actor, "published"), 2465 html_actor_icon(snac, actor, xs_dict_get(actor, "published"),
2465 NULL, NULL, 0, 1, proxy_media))); 2466 NULL, NULL, 0, 1, proxy)));
2466 2467
2467 /* content (user bio) */ 2468 /* content (user bio) */
2468 const char *c = xs_dict_get(actor, "summary"); 2469 const char *c = xs_dict_get(actor, "summary");
@@ -2565,6 +2566,11 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t)
2565 2566
2566xs_str *html_people(snac *user) 2567xs_str *html_people(snac *user)
2567{ 2568{
2569 const char *proxy = NULL;
2570
2571 if (xs_is_true(xs_dict_get(srv_config, "proxy_media")))
2572 proxy = user->actor;
2573
2568 xs *wing = following_list(user); 2574 xs *wing = following_list(user);
2569 xs *wers = follower_list(user); 2575 xs *wers = follower_list(user);
2570 2576
@@ -2573,8 +2579,8 @@ xs_str *html_people(snac *user)
2573 xs_html_add(html_user_body(user, 0), 2579 xs_html_add(html_user_body(user, 0),
2574 xs_html_tag("div", 2580 xs_html_tag("div",
2575 xs_html_attr("class", "snac-posts"), 2581 xs_html_attr("class", "snac-posts"),
2576 html_people_list(user, wing, L("People you follow"), "i"), 2582 html_people_list(user, wing, L("People you follow"), "i", proxy),
2577 html_people_list(user, wers, L("People that follow you"), "e")), 2583 html_people_list(user, wers, L("People that follow you"), "e", proxy)),
2578 html_footer())); 2584 html_footer()));
2579 2585
2580 return xs_html_render_s(html, "<!DOCTYPE html>\n"); 2586 return xs_html_render_s(html, "<!DOCTYPE html>\n");
@@ -2583,7 +2589,10 @@ xs_str *html_people(snac *user)
2583 2589
2584xs_str *html_notifications(snac *user, int skip, int show) 2590xs_str *html_notifications(snac *user, int skip, int show)
2585{ 2591{
2586 int proxy_media = xs_is_true(xs_dict_get(srv_config, "proxy_media")); 2592 const char *proxy = NULL;
2593
2594 if (xs_is_true(xs_dict_get(srv_config, "proxy_media")))
2595 proxy = user->actor;
2587 2596
2588 xs *n_list = notify_list(user, skip, show); 2597 xs *n_list = notify_list(user, skip, show);
2589 xs *n_time = notify_check_time(user, 0); 2598 xs *n_time = notify_check_time(user, 0);
@@ -2685,7 +2694,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
2685 xs_html_add(entry, 2694 xs_html_add(entry,
2686 xs_html_tag("div", 2695 xs_html_tag("div",
2687 xs_html_attr("class", "snac-post"), 2696 xs_html_attr("class", "snac-post"),
2688 html_actor_icon(user, actor, NULL, NULL, NULL, 0, 0, proxy_media))); 2697 html_actor_icon(user, actor, NULL, NULL, NULL, 0, 0, proxy)));
2689 } 2698 }
2690 else 2699 else
2691 if (strcmp(type, "Move") == 0) { 2700 if (strcmp(type, "Move") == 0) {
@@ -2699,7 +2708,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
2699 xs_html_add(entry, 2708 xs_html_add(entry,
2700 xs_html_tag("div", 2709 xs_html_tag("div",
2701 xs_html_attr("class", "snac-post"), 2710 xs_html_attr("class", "snac-post"),
2702 html_actor_icon(user, old_actor, NULL, NULL, NULL, 0, 0, proxy_media))); 2711 html_actor_icon(user, old_actor, NULL, NULL, NULL, 0, 0, proxy)));
2703 } 2712 }
2704 } 2713 }
2705 } 2714 }
@@ -2789,7 +2798,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2789 const char *p_path; 2798 const char *p_path;
2790 int cache = 1; 2799 int cache = 1;
2791 int save = 1; 2800 int save = 1;
2792 int proxy_media = xs_is_true(xs_dict_get(srv_config, "proxy_media")); 2801 const char *proxy = NULL;
2793 const char *v; 2802 const char *v;
2794 2803
2795 xs *l = xs_split_n(q_path, "/", 2); 2804 xs *l = xs_split_n(q_path, "/", 2);
@@ -2816,6 +2825,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2816 return HTTP_STATUS_NOT_FOUND; 2825 return HTTP_STATUS_NOT_FOUND;
2817 } 2826 }
2818 2827
2828 if (xs_is_true(xs_dict_get(srv_config, "proxy_media")))
2829 proxy = snac.actor;
2830
2819 /* return the RSS if requested by Accept header */ 2831 /* return the RSS if requested by Accept header */
2820 if (accept != NULL) { 2832 if (accept != NULL) {
2821 if (xs_str_in(accept, "text/xml") != -1 || 2833 if (xs_str_in(accept, "text/xml") != -1 ||
@@ -3192,7 +3204,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
3192 snac_debug(&snac, 1, xs_fmt("serving RSS")); 3204 snac_debug(&snac, 1, xs_fmt("serving RSS"));
3193 } 3205 }
3194 else 3206 else
3195 if (xs_startswith(p_path, "proxy/") && proxy_media) { /** remote media by proxy **/ 3207 if (xs_startswith(p_path, "proxy/") && proxy) { /** remote media by proxy **/
3196 if (!login(&snac, req)) { 3208 if (!login(&snac, req)) {
3197 *body = xs_dup(uid); 3209 *body = xs_dup(uid);
3198 status = HTTP_STATUS_UNAUTHORIZED; 3210 status = HTTP_STATUS_UNAUTHORIZED;