summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-09 22:10:49 +0200
committerGravatar default2023-04-09 22:10:49 +0200
commitca89f8b8460b5b2388e24d0fbe712e7268eca4ef (patch)
tree7f65eca7a99f892574789f6f964ee7030ba69647
parentMore mastoapi work. (diff)
downloadpenes-snac2-ca89f8b8460b5b2388e24d0fbe712e7268eca4ef.tar.gz
penes-snac2-ca89f8b8460b5b2388e24d0fbe712e7268eca4ef.tar.xz
penes-snac2-ca89f8b8460b5b2388e24d0fbe712e7268eca4ef.zip
Fixed avatar.
-rw-r--r--mastoapi.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/mastoapi.c b/mastoapi.c
index b80d8c8..b7f3c95 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -342,7 +342,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
342 return 0; 342 return 0;
343 343
344 srv_debug(0, xs_fmt("mastoapi_get_handler %s", q_path)); 344 srv_debug(0, xs_fmt("mastoapi_get_handler %s", q_path));
345
346 { 345 {
347 xs *j = xs_json_dumps_pp(req, 4); 346 xs *j = xs_json_dumps_pp(req, 4);
348 printf("mastoapi get:\n%s\n", j); 347 printf("mastoapi get:\n%s\n", j);
@@ -386,7 +385,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
386 acct = xs_dict_append(acct, "created_at", xs_dict_get(snac.config, "published")); 385 acct = xs_dict_append(acct, "created_at", xs_dict_get(snac.config, "published"));
387 acct = xs_dict_append(acct, "note", xs_dict_get(snac.config, "bio")); 386 acct = xs_dict_append(acct, "note", xs_dict_get(snac.config, "bio"));
388 acct = xs_dict_append(acct, "url", snac.actor); 387 acct = xs_dict_append(acct, "url", snac.actor);
389 acct = xs_dict_append(acct, "avatar", xs_dict_get(snac.config, "avatar")); 388
389 xs *avatar = xs_dup(xs_dict_get(snac.config, "avatar"));
390
391 if (xs_is_null(avatar) || *avatar == '\0') {
392 xs_free(avatar);
393 avatar = xs_fmt("%s/susie.png", srv_baseurl);
394 }
395
396 acct = xs_dict_append(acct, "avatar", avatar);
390 397
391 *body = xs_json_dumps_pp(acct, 4); 398 *body = xs_json_dumps_pp(acct, 4);
392 *ctype = "application/json"; 399 *ctype = "application/json";
@@ -412,6 +419,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
412 if (!xs_startswith(q_path, "/api/v1/")) 419 if (!xs_startswith(q_path, "/api/v1/"))
413 return 0; 420 return 0;
414 421
422 srv_debug(0, xs_fmt("mastoapi_post_handler %s", q_path));
415 { 423 {
416 xs *j = xs_json_dumps_pp(req, 4); 424 xs *j = xs_json_dumps_pp(req, 4);
417 printf("mastoapi post:\n%s\n", j); 425 printf("mastoapi post:\n%s\n", j);
@@ -430,10 +438,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
430 return 400; 438 return 400;
431 439
432 { 440 {
433 xs *j = xs_json_dumps_pp(req, 4);
434 printf("%s\n", j);
435 }
436 {
437 xs *j = xs_json_dumps_pp(msg, 4); 441 xs *j = xs_json_dumps_pp(msg, 4);
438 printf("%s\n", j); 442 printf("%s\n", j);
439 } 443 }
@@ -441,8 +445,12 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
441 xs *cmd = xs_replace(q_path, "/api/v1", ""); 445 xs *cmd = xs_replace(q_path, "/api/v1", "");
442 446
443 if (strcmp(cmd, "/apps") == 0) { 447 if (strcmp(cmd, "/apps") == 0) {
444 const char *name = xs_dict_get(msg, "client_name"); 448 const char *name = xs_dict_get(msg, "client_name");
445 const char *ruri = xs_dict_get(msg, "redirect_uris"); 449 const char *ruri = xs_dict_get(msg, "redirect_uris");
450 const char *scope = xs_dict_get(msg, "scope");
451
452 if (xs_type(ruri) == XSTYPE_LIST)
453 ruri = xs_dict_get(ruri, 0);
446 454
447 if (name && ruri) { 455 if (name && ruri) {
448 xs *app = xs_dict_new(); 456 xs *app = xs_dict_new();
@@ -463,7 +471,13 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
463 status = 200; 471 status = 200;
464 472
465 app = xs_dict_append(app, "code", ""); 473 app = xs_dict_append(app, "code", "");
474
475 if (scope)
476 app = xs_dict_append(app, "scope", scope);
477
466 app_add(cid, app); 478 app_add(cid, app);
479
480 srv_debug(0, xs_fmt("mastoapi apps: new app %s", cid));
467 } 481 }
468 } 482 }
469 483