From d9a15b8af7da2bc27d4d55ee745242f5b4e39071 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 16 Oct 2022 18:03:28 +0200 Subject: Attachments are now starting to get real. --- html.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'html.c') diff --git a/html.c b/html.c index f4ecb8a..5e4f60c 100644 --- a/html.c +++ b/html.c @@ -877,12 +877,37 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, char *content = xs_dict_get(p_vars, "content"); char *in_reply_to = xs_dict_get(p_vars, "in_reply_to"); char *attach_url = xs_dict_get(p_vars, "attach_url"); + char *attach_file = xs_dict_get(p_vars, "attach"); + xs *attach_list = xs_list_new(); + + /* is attach_url set? */ + if (!xs_is_null(attach_url) && *attach_url != '\0') + attach_list = xs_list_append(attach_list, attach_url); + + /* is attach_file set? */ + if (!xs_is_null(attach_file) && xs_type(attach_file) == XSTYPE_LIST) { + char *fn = xs_list_get(attach_file, 0); + + if (*fn != '\0') { + char *ext = strrchr(fn, '.'); + xs *ntid = tid(0); + xs *id = xs_fmt("%s%s", ntid, ext); + xs *url = xs_fmt("%s/s/%s", snac.actor, id); + int fo = xs_number_get(xs_list_get(attach_file, 1)); + int fs = xs_number_get(xs_list_get(attach_file, 2)); + + /* store */ + static_put(&snac, id, payload + fo, fs); + + attach_list = xs_list_append(attach_list, url); + } + } if (content != NULL) { xs *msg = NULL; xs *c_msg = NULL; - msg = msg_note(&snac, content, NULL, in_reply_to, attach_url); + msg = msg_note(&snac, content, NULL, in_reply_to, attach_list); c_msg = msg_create(&snac, msg); -- cgit v1.2.3