summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar default2024-12-15 22:52:41 +0100
committerGravatar default2024-12-15 22:52:41 +0100
commitc6562fa39bc3b609429fea9064a94cf080922da5 (patch)
treeb28e0945fb1d17c0f9a4724fd657c5cc30efd2a9 /mastoapi.c
parentFixed crash in mastoapi_status() Emoji list. (diff)
downloadpenes-snac2-c6562fa39bc3b609429fea9064a94cf080922da5.tar.gz
penes-snac2-c6562fa39bc3b609429fea9064a94cf080922da5.tar.xz
penes-snac2-c6562fa39bc3b609429fea9064a94cf080922da5.zip
New function timeline_link_header().
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/mastoapi.c b/mastoapi.c
index be8be80..6b816f4 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1434,8 +1434,35 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
1434} 1434}
1435 1435
1436 1436
1437xs_str *timeline_link_header(const char *endpoint, xs_list *timeline)
1438/* returns a Link header with paging information */
1439{
1440 xs_str *s = NULL;
1441
1442 if (xs_list_len(timeline) == 0)
1443 return NULL;
1444
1445 const xs_dict *first_st = xs_list_get(timeline, 0);
1446 const xs_dict *last_st = xs_list_get(timeline, -1);
1447 const char *first_id = xs_dict_get(first_st, "id");
1448 const char *last_id = xs_dict_get(last_st, "id");
1449 const char *host = xs_dict_get(srv_config, "host");
1450 const char *protocol = xs_dict_get_def(srv_config, "protocol", "https");
1451
1452 s = xs_fmt(
1453 "<%s:/" "/%s%s?max_id=%s>; rel=\"next\", "
1454 "<%s:/" "/%s%s?since_id=%s>; rel=\"prev\"",
1455 protocol, host, endpoint, last_id,
1456 protocol, host, endpoint, first_id);
1457
1458 srv_debug(1, xs_fmt("timeline_link_header %s", s));
1459
1460 return s;
1461}
1462
1463
1437int mastoapi_get_handler(const xs_dict *req, const char *q_path, 1464int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1438 char **body, int *b_size, char **ctype) 1465 char **body, int *b_size, char **ctype, xs_str **link)
1439{ 1466{
1440 (void)b_size; 1467 (void)b_size;
1441 1468
@@ -1695,6 +1722,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1695 xs *ifn = user_index_fn(&snac1, "private"); 1722 xs *ifn = user_index_fn(&snac1, "private");
1696 xs *out = mastoapi_timeline(&snac1, args, ifn); 1723 xs *out = mastoapi_timeline(&snac1, args, ifn);
1697 1724
1725 *link = timeline_link_header(cmd, out);
1726
1698 *body = xs_json_dumps(out, 4); 1727 *body = xs_json_dumps(out, 4);
1699 *ctype = "application/json"; 1728 *ctype = "application/json";
1700 status = HTTP_STATUS_OK; 1729 status = HTTP_STATUS_OK;