commit 3313dc8
default
·
2024-11-07 17:57:52 +0000 UTC
parent 484dd12
Changed make_url().
1 files changed,
+35,
-23
M
html.c
M
html.c
+35,
-23
1@@ -42,16 +42,16 @@ int login(snac *snac, const xs_dict *headers)
2 }
3
4
5-xs_str *make_url(snac *user, int proxy_media, const char *href)
6+xs_str *make_url(const char *href, const char *proxy)
7 /* makes an URL, possibly including proxying */
8 {
9 xs_str *url = NULL;
10
11- if (user && proxy_media) {
12- xs *h = xs_replace(href, "https:/" "/", "");
13- url = xs_fmt("%s/proxy/%s", user->actor, h);
14+ if (proxy) {
15+ xs *p = xs_str_cat(xs_dup(proxy), "/proxy/");
16+ url = xs_replace(href, "https:/" "/", p);
17
18- snac_debug(user, 1, xs_fmt("Proxying %s %s", href, url));
19+ srv_debug(1, xs_fmt("Proxying %s %s", href, url));
20 }
21 else
22 url = xs_dup(href);
23@@ -120,7 +120,7 @@ xs_str *actor_name(xs_dict *actor)
24
25
26 xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
27- const char *udate, const char *url, int priv, int in_people, int proxy)
28+ const char *udate, const char *url, int priv, int in_people, const char *proxy)
29 {
30 xs_html *actor_icon = xs_html_tag("p", NULL);
31
32@@ -138,7 +138,7 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
33 v = xs_list_get(v, 0);
34
35 if ((v = xs_dict_get(v, "url")) != NULL)
36- avatar = make_url(user, proxy, v);
37+ avatar = make_url(v, proxy);
38 }
39
40 if (avatar == NULL)
41@@ -263,7 +263,7 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
42 }
43
44
45-xs_html *html_msg_icon(snac *user, const char *actor_id, const xs_dict *msg, int proxy)
46+xs_html *html_msg_icon(snac *user, const char *actor_id, const xs_dict *msg, const char *proxy)
47 {
48 xs *actor = NULL;
49 xs_html *actor_icon = NULL;
50@@ -1483,7 +1483,10 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
51 const char *v;
52 int has_title = 0;
53 int collapse_threads = 0;
54- int proxy_media = xs_is_true(xs_dict_get(srv_config, "proxy_media"));
55+ const char *proxy = NULL;
56+
57+ if (user && !read_only && xs_is_true(xs_dict_get(srv_config, "proxy_media")))
58+ proxy = user->actor;
59
60 /* do not show non-public messages in the public timeline */
61 if ((read_only || !user) && !is_msg_public(msg))
62@@ -1515,7 +1518,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
63 xs_html_tag("div",
64 xs_html_attr("class", "snac-origin"),
65 xs_html_text(L("follows you"))),
66- html_msg_icon(read_only ? NULL : user, xs_dict_get(msg, "actor"), msg, proxy_media)));
67+ html_msg_icon(read_only ? NULL : user, xs_dict_get(msg, "actor"), msg, proxy)));
68 }
69 else
70 if (!xs_match(type, POSTLIKE_OBJECT_TYPE)) {
71@@ -1694,7 +1697,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
72 }
73
74 xs_html_add(post_header,
75- html_msg_icon(read_only ? NULL : user, actor, msg, proxy_media));
76+ html_msg_icon(read_only ? NULL : user, actor, msg, proxy));
77
78 /** post content **/
79
80@@ -1981,7 +1984,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
81 if (content && xs_str_in(content, o_href) != -1)
82 continue;
83
84- xs *href = make_url(user, proxy_media && !read_only, o_href);
85+ xs *href = make_url(o_href, proxy);
86
87 if (xs_startswith(type, "image/") || strcmp(type, "Image") == 0) {
88 xs_html_add(content_attachments,
89@@ -2433,10 +2436,8 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
90 }
91
92
93-xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t)
94+xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t, const char *proxy)
95 {
96- int proxy_media = xs_is_true(xs_dict_get(srv_config, "proxy_media"));
97-
98 xs_html *snac_posts;
99 xs_html *people = xs_html_tag("div",
100 xs_html_tag("h2",
101@@ -2462,7 +2463,7 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t)
102 xs_html_tag("div",
103 xs_html_attr("class", "snac-post-header"),
104 html_actor_icon(snac, actor, xs_dict_get(actor, "published"),
105- NULL, NULL, 0, 1, proxy_media)));
106+ NULL, NULL, 0, 1, proxy)));
107
108 /* content (user bio) */
109 const char *c = xs_dict_get(actor, "summary");
110@@ -2565,6 +2566,11 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t)
111
112 xs_str *html_people(snac *user)
113 {
114+ const char *proxy = NULL;
115+
116+ if (xs_is_true(xs_dict_get(srv_config, "proxy_media")))
117+ proxy = user->actor;
118+
119 xs *wing = following_list(user);
120 xs *wers = follower_list(user);
121
122@@ -2573,8 +2579,8 @@ xs_str *html_people(snac *user)
123 xs_html_add(html_user_body(user, 0),
124 xs_html_tag("div",
125 xs_html_attr("class", "snac-posts"),
126- html_people_list(user, wing, L("People you follow"), "i"),
127- html_people_list(user, wers, L("People that follow you"), "e")),
128+ html_people_list(user, wing, L("People you follow"), "i", proxy),
129+ html_people_list(user, wers, L("People that follow you"), "e", proxy)),
130 html_footer()));
131
132 return xs_html_render_s(html, "<!DOCTYPE html>\n");
133@@ -2583,7 +2589,10 @@ xs_str *html_people(snac *user)
134
135 xs_str *html_notifications(snac *user, int skip, int show)
136 {
137- int proxy_media = xs_is_true(xs_dict_get(srv_config, "proxy_media"));
138+ const char *proxy = NULL;
139+
140+ if (xs_is_true(xs_dict_get(srv_config, "proxy_media")))
141+ proxy = user->actor;
142
143 xs *n_list = notify_list(user, skip, show);
144 xs *n_time = notify_check_time(user, 0);
145@@ -2685,7 +2694,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
146 xs_html_add(entry,
147 xs_html_tag("div",
148 xs_html_attr("class", "snac-post"),
149- html_actor_icon(user, actor, NULL, NULL, NULL, 0, 0, proxy_media)));
150+ html_actor_icon(user, actor, NULL, NULL, NULL, 0, 0, proxy)));
151 }
152 else
153 if (strcmp(type, "Move") == 0) {
154@@ -2699,7 +2708,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
155 xs_html_add(entry,
156 xs_html_tag("div",
157 xs_html_attr("class", "snac-post"),
158- html_actor_icon(user, old_actor, NULL, NULL, NULL, 0, 0, proxy_media)));
159+ html_actor_icon(user, old_actor, NULL, NULL, NULL, 0, 0, proxy)));
160 }
161 }
162 }
163@@ -2789,7 +2798,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
164 const char *p_path;
165 int cache = 1;
166 int save = 1;
167- int proxy_media = xs_is_true(xs_dict_get(srv_config, "proxy_media"));
168+ const char *proxy = NULL;
169 const char *v;
170
171 xs *l = xs_split_n(q_path, "/", 2);
172@@ -2816,6 +2825,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
173 return HTTP_STATUS_NOT_FOUND;
174 }
175
176+ if (xs_is_true(xs_dict_get(srv_config, "proxy_media")))
177+ proxy = snac.actor;
178+
179 /* return the RSS if requested by Accept header */
180 if (accept != NULL) {
181 if (xs_str_in(accept, "text/xml") != -1 ||
182@@ -3192,7 +3204,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
183 snac_debug(&snac, 1, xs_fmt("serving RSS"));
184 }
185 else
186- if (xs_startswith(p_path, "proxy/") && proxy_media) { /** remote media by proxy **/
187+ if (xs_startswith(p_path, "proxy/") && proxy) { /** remote media by proxy **/
188 if (!login(&snac, req)) {
189 *body = xs_dup(uid);
190 status = HTTP_STATUS_UNAUTHORIZED;