commit ca89f8b
default
·
2023-04-09 20:10:49 +0000 UTC
parent ccce01d
Fixed avatar.
1 files changed,
+22,
-8
+22,
-8
1@@ -342,7 +342,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 return 0;
3
4 srv_debug(0, xs_fmt("mastoapi_get_handler %s", q_path));
5-
6 {
7 xs *j = xs_json_dumps_pp(req, 4);
8 printf("mastoapi get:\n%s\n", j);
9@@ -386,7 +385,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
10 acct = xs_dict_append(acct, "created_at", xs_dict_get(snac.config, "published"));
11 acct = xs_dict_append(acct, "note", xs_dict_get(snac.config, "bio"));
12 acct = xs_dict_append(acct, "url", snac.actor);
13- acct = xs_dict_append(acct, "avatar", xs_dict_get(snac.config, "avatar"));
14+
15+ xs *avatar = xs_dup(xs_dict_get(snac.config, "avatar"));
16+
17+ if (xs_is_null(avatar) || *avatar == '\0') {
18+ xs_free(avatar);
19+ avatar = xs_fmt("%s/susie.png", srv_baseurl);
20+ }
21+
22+ acct = xs_dict_append(acct, "avatar", avatar);
23
24 *body = xs_json_dumps_pp(acct, 4);
25 *ctype = "application/json";
26@@ -412,6 +419,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
27 if (!xs_startswith(q_path, "/api/v1/"))
28 return 0;
29
30+ srv_debug(0, xs_fmt("mastoapi_post_handler %s", q_path));
31 {
32 xs *j = xs_json_dumps_pp(req, 4);
33 printf("mastoapi post:\n%s\n", j);
34@@ -429,10 +437,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
35 if (msg == NULL)
36 return 400;
37
38- {
39- xs *j = xs_json_dumps_pp(req, 4);
40- printf("%s\n", j);
41- }
42 {
43 xs *j = xs_json_dumps_pp(msg, 4);
44 printf("%s\n", j);
45@@ -441,8 +445,12 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
46 xs *cmd = xs_replace(q_path, "/api/v1", "");
47
48 if (strcmp(cmd, "/apps") == 0) {
49- const char *name = xs_dict_get(msg, "client_name");
50- const char *ruri = xs_dict_get(msg, "redirect_uris");
51+ const char *name = xs_dict_get(msg, "client_name");
52+ const char *ruri = xs_dict_get(msg, "redirect_uris");
53+ const char *scope = xs_dict_get(msg, "scope");
54+
55+ if (xs_type(ruri) == XSTYPE_LIST)
56+ ruri = xs_dict_get(ruri, 0);
57
58 if (name && ruri) {
59 xs *app = xs_dict_new();
60@@ -463,7 +471,13 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
61 status = 200;
62
63 app = xs_dict_append(app, "code", "");
64+
65+ if (scope)
66+ app = xs_dict_append(app, "scope", scope);
67+
68 app_add(cid, app);
69+
70+ srv_debug(0, xs_fmt("mastoapi apps: new app %s", cid));
71 }
72 }
73