diff options
| author | 2024-08-29 08:30:09 +0200 | |
|---|---|---|
| committer | 2024-08-29 08:30:09 +0200 | |
| commit | 08de4913955c6a4a31c13f72fbce2601bed215ba (patch) | |
| tree | 27192a33496fcccefe86cd49b620169c00bf9926 | |
| parent | mastoapi: added support for [un]bookmarking. (diff) | |
| download | penes-snac2-08de4913955c6a4a31c13f72fbce2601bed215ba.tar.gz penes-snac2-08de4913955c6a4a31c13f72fbce2601bed215ba.tar.xz penes-snac2-08de4913955c6a4a31c13f72fbce2601bed215ba.zip | |
mastoapi: added bookmark list.
| -rw-r--r-- | data.c | 14 | ||||
| -rw-r--r-- | mastoapi.c | 18 | ||||
| -rw-r--r-- | snac.h | 1 |
3 files changed, 28 insertions, 5 deletions
| @@ -1026,12 +1026,18 @@ xs_str *object_user_cache_fn(snac *user, const char *id, const char *cachedir) | |||
| 1026 | } | 1026 | } |
| 1027 | 1027 | ||
| 1028 | 1028 | ||
| 1029 | xs_str *object_user_cache_index_fn(snac *user, const char *cachedir) | ||
| 1030 | { | ||
| 1031 | return xs_fmt("%s/%s.idx", user->basedir, cachedir); | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | |||
| 1029 | int _object_user_cache(snac *user, const char *id, const char *cachedir, int del) | 1035 | int _object_user_cache(snac *user, const char *id, const char *cachedir, int del) |
| 1030 | /* adds or deletes from a user cache */ | 1036 | /* adds or deletes from a user cache */ |
| 1031 | { | 1037 | { |
| 1032 | xs *ofn = _object_fn(id); | 1038 | xs *ofn = _object_fn(id); |
| 1033 | xs *cfn = object_user_cache_fn(user, id, cachedir); | 1039 | xs *cfn = object_user_cache_fn(user, id, cachedir); |
| 1034 | xs *idx = xs_fmt("%s/%s.idx", user->basedir, cachedir); | 1040 | xs *idx = object_user_cache_index_fn(user, cachedir); |
| 1035 | int ret; | 1041 | int ret; |
| 1036 | 1042 | ||
| 1037 | if (del) { | 1043 | if (del) { |
| @@ -1590,6 +1596,12 @@ xs_list *bookmark_list(snac *user) | |||
| 1590 | } | 1596 | } |
| 1591 | 1597 | ||
| 1592 | 1598 | ||
| 1599 | xs_str *bookmark_index_fn(snac *user) | ||
| 1600 | { | ||
| 1601 | return object_user_cache_index_fn(user, "bookmark"); | ||
| 1602 | } | ||
| 1603 | |||
| 1604 | |||
| 1593 | /** pinning **/ | 1605 | /** pinning **/ |
| 1594 | 1606 | ||
| 1595 | int is_pinned(snac *user, const char *id) | 1607 | int is_pinned(snac *user, const char *id) |
| @@ -1822,10 +1822,16 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1822 | } | 1822 | } |
| 1823 | else | 1823 | else |
| 1824 | if (strcmp(cmd, "/v1/bookmarks") == 0) { /** **/ | 1824 | if (strcmp(cmd, "/v1/bookmarks") == 0) { /** **/ |
| 1825 | /* snac does not support bookmarks */ | 1825 | if (logged_in) { |
| 1826 | *body = xs_dup("[]"); | 1826 | xs *ifn = bookmark_index_fn(&snac1); |
| 1827 | *ctype = "application/json"; | 1827 | xs *out = mastoapi_timeline(&snac1, args, ifn); |
| 1828 | status = HTTP_STATUS_OK; | 1828 | |
| 1829 | *body = xs_json_dumps(out, 4); | ||
| 1830 | *ctype = "application/json"; | ||
| 1831 | status = HTTP_STATUS_OK; | ||
| 1832 | } | ||
| 1833 | else | ||
| 1834 | status = HTTP_STATUS_UNAUTHORIZED; | ||
| 1829 | } | 1835 | } |
| 1830 | else | 1836 | else |
| 1831 | if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/ | 1837 | if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/ |
| @@ -1850,6 +1856,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1850 | *ctype = "application/json"; | 1856 | *ctype = "application/json"; |
| 1851 | status = HTTP_STATUS_OK; | 1857 | status = HTTP_STATUS_OK; |
| 1852 | } | 1858 | } |
| 1859 | else | ||
| 1860 | status = HTTP_STATUS_UNAUTHORIZED; | ||
| 1853 | } | 1861 | } |
| 1854 | else | 1862 | else |
| 1855 | if (xs_startswith(cmd, "/v1/lists/")) { /** list information **/ | 1863 | if (xs_startswith(cmd, "/v1/lists/")) { /** list information **/ |
| @@ -1910,6 +1918,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1910 | } | 1918 | } |
| 1911 | } | 1919 | } |
| 1912 | } | 1920 | } |
| 1921 | else | ||
| 1922 | status = HTTP_STATUS_UNAUTHORIZED; | ||
| 1913 | } | 1923 | } |
| 1914 | else | 1924 | else |
| 1915 | if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ | 1925 | if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ |
| @@ -170,6 +170,7 @@ int is_bookmarked(snac *user, const char *id); | |||
| 170 | int bookmark(snac *user, const char *id); | 170 | int bookmark(snac *user, const char *id); |
| 171 | int unbookmark(snac *user, const char *id); | 171 | int unbookmark(snac *user, const char *id); |
| 172 | xs_list *bookmark_list(snac *user); | 172 | xs_list *bookmark_list(snac *user); |
| 173 | xs_str *bookmark_index_fn(snac *user); | ||
| 173 | 174 | ||
| 174 | int pin(snac *user, const char *id); | 175 | int pin(snac *user, const char *id); |
| 175 | int unpin(snac *user, const char *id); | 176 | int unpin(snac *user, const char *id); |