diff options
| author | 2023-04-12 10:41:15 +0200 | |
|---|---|---|
| committer | 2023-04-12 10:41:15 +0200 | |
| commit | 885031bed9e54876fb262921b11df23aa00cedb6 (patch) | |
| tree | a1541acecaa547b5a637600d76e8a0df1fde6225 | |
| parent | Use the ctime instead of the published date in mastoapi_id(). (diff) | |
| download | penes-snac2-885031bed9e54876fb262921b11df23aa00cedb6.tar.gz penes-snac2-885031bed9e54876fb262921b11df23aa00cedb6.tar.xz penes-snac2-885031bed9e54876fb262921b11df23aa00cedb6.zip | |
Don't generate invalid JSON if an attachment has no description.
| -rw-r--r-- | data.c | 10 | ||||
| -rw-r--r-- | mastoapi.c | 15 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 22 insertions, 5 deletions
| @@ -1971,7 +1971,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req, | |||
| 1971 | 1971 | ||
| 1972 | 1972 | ||
| 1973 | void srv_archive_error(const char *prefix, const xs_str *err, | 1973 | void srv_archive_error(const char *prefix, const xs_str *err, |
| 1974 | const xs_dict *req, const xs_dict *data) | 1974 | const xs_dict *req, const xs_val *data) |
| 1975 | /* archives an error */ | 1975 | /* archives an error */ |
| 1976 | { | 1976 | { |
| 1977 | xs *ntid = tid(0); | 1977 | xs *ntid = tid(0); |
| @@ -1993,8 +1993,12 @@ void srv_archive_error(const char *prefix, const xs_str *err, | |||
| 1993 | if (data) { | 1993 | if (data) { |
| 1994 | fprintf(f, "Data:\n"); | 1994 | fprintf(f, "Data:\n"); |
| 1995 | 1995 | ||
| 1996 | xs *j = xs_json_dumps_pp(data, 4); | 1996 | if (xs_type(data) == XSTYPE_LIST || xs_type(data) == XSTYPE_DICT) { |
| 1997 | fwrite(j, strlen(j), 1, f); | 1997 | xs *j = xs_json_dumps_pp(data, 4); |
| 1998 | fwrite(j, strlen(j), 1, f); | ||
| 1999 | } | ||
| 2000 | else | ||
| 2001 | fprintf(f, "%s", data); | ||
| 1998 | 2002 | ||
| 1999 | fprintf(f, "\n"); | 2003 | fprintf(f, "\n"); |
| 2000 | } | 2004 | } |
| @@ -506,7 +506,12 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 506 | matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url")); | 506 | matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url")); |
| 507 | matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url")); | 507 | matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url")); |
| 508 | matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url")); | 508 | matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url")); |
| 509 | matte = xs_dict_append(matte, "description", xs_dict_get(aobj, "name")); | 509 | |
| 510 | const char *name = xs_dict_get(aobj, "name"); | ||
| 511 | if (xs_is_null(name)) | ||
| 512 | name = ""; | ||
| 513 | |||
| 514 | matte = xs_dict_append(matte, "description", name); | ||
| 510 | 515 | ||
| 511 | matt = xs_list_append(matt, matte); | 516 | matt = xs_list_append(matt, matte); |
| 512 | } | 517 | } |
| @@ -730,6 +735,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 730 | *ctype = "application/json"; | 735 | *ctype = "application/json"; |
| 731 | status = 200; | 736 | status = 200; |
| 732 | 737 | ||
| 738 | { | ||
| 739 | xs *j = xs_json_loads(*body); | ||
| 740 | if (j == NULL) { | ||
| 741 | srv_debug(0, xs_fmt("mastoapi timeline: bad JSON")); | ||
| 742 | srv_archive_error("mastoapi_timeline", "bad JSON", req, *body); | ||
| 743 | } | ||
| 744 | } | ||
| 745 | |||
| 733 | srv_debug(0, xs_fmt("mastoapi timeline: returned %d entries", xs_list_len(out))); | 746 | srv_debug(0, xs_fmt("mastoapi timeline: returned %d entries", xs_list_len(out))); |
| 734 | } | 747 | } |
| 735 | else { | 748 | else { |
| @@ -56,7 +56,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req, | |||
| 56 | int status, xs_dict *headers, | 56 | int status, xs_dict *headers, |
| 57 | const char *body, int b_size); | 57 | const char *body, int b_size); |
| 58 | void srv_archive_error(const char *prefix, const xs_str *err, | 58 | void srv_archive_error(const char *prefix, const xs_str *err, |
| 59 | const xs_dict *req, const xs_dict *data); | 59 | const xs_dict *req, const xs_val *data); |
| 60 | 60 | ||
| 61 | double mtime_nl(const char *fn, int *n_link); | 61 | double mtime_nl(const char *fn, int *n_link); |
| 62 | #define mtime(fn) mtime_nl(fn, NULL) | 62 | #define mtime(fn) mtime_nl(fn, NULL) |