diff options
| author | 2022-10-16 18:03:28 +0200 | |
|---|---|---|
| committer | 2022-10-16 18:03:28 +0200 | |
| commit | d9a15b8af7da2bc27d4d55ee745242f5b4e39071 (patch) | |
| tree | f890fe2b2f0a327f08da31404fd267c675fac690 /html.c | |
| parent | Use multipart/form-data for posts (on the way to supporting uploads). (diff) | |
| download | snac2-d9a15b8af7da2bc27d4d55ee745242f5b4e39071.tar.gz snac2-d9a15b8af7da2bc27d4d55ee745242f5b4e39071.tar.xz snac2-d9a15b8af7da2bc27d4d55ee745242f5b4e39071.zip | |
Attachments are now starting to get real.
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 27 |
1 files changed, 26 insertions, 1 deletions
| @@ -877,12 +877,37 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 877 | char *content = xs_dict_get(p_vars, "content"); | 877 | char *content = xs_dict_get(p_vars, "content"); |
| 878 | char *in_reply_to = xs_dict_get(p_vars, "in_reply_to"); | 878 | char *in_reply_to = xs_dict_get(p_vars, "in_reply_to"); |
| 879 | char *attach_url = xs_dict_get(p_vars, "attach_url"); | 879 | char *attach_url = xs_dict_get(p_vars, "attach_url"); |
| 880 | char *attach_file = xs_dict_get(p_vars, "attach"); | ||
| 881 | xs *attach_list = xs_list_new(); | ||
| 882 | |||
| 883 | /* is attach_url set? */ | ||
| 884 | if (!xs_is_null(attach_url) && *attach_url != '\0') | ||
| 885 | attach_list = xs_list_append(attach_list, attach_url); | ||
| 886 | |||
| 887 | /* is attach_file set? */ | ||
| 888 | if (!xs_is_null(attach_file) && xs_type(attach_file) == XSTYPE_LIST) { | ||
| 889 | char *fn = xs_list_get(attach_file, 0); | ||
| 890 | |||
| 891 | if (*fn != '\0') { | ||
| 892 | char *ext = strrchr(fn, '.'); | ||
| 893 | xs *ntid = tid(0); | ||
| 894 | xs *id = xs_fmt("%s%s", ntid, ext); | ||
| 895 | xs *url = xs_fmt("%s/s/%s", snac.actor, id); | ||
| 896 | int fo = xs_number_get(xs_list_get(attach_file, 1)); | ||
| 897 | int fs = xs_number_get(xs_list_get(attach_file, 2)); | ||
| 898 | |||
| 899 | /* store */ | ||
| 900 | static_put(&snac, id, payload + fo, fs); | ||
| 901 | |||
| 902 | attach_list = xs_list_append(attach_list, url); | ||
| 903 | } | ||
| 904 | } | ||
| 880 | 905 | ||
| 881 | if (content != NULL) { | 906 | if (content != NULL) { |
| 882 | xs *msg = NULL; | 907 | xs *msg = NULL; |
| 883 | xs *c_msg = NULL; | 908 | xs *c_msg = NULL; |
| 884 | 909 | ||
| 885 | msg = msg_note(&snac, content, NULL, in_reply_to, attach_url); | 910 | msg = msg_note(&snac, content, NULL, in_reply_to, attach_list); |
| 886 | 911 | ||
| 887 | c_msg = msg_create(&snac, msg); | 912 | c_msg = msg_create(&snac, msg); |
| 888 | 913 | ||