summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar Louis Brauer2024-05-29 11:53:34 +0200
committerGravatar Louis Brauer2024-05-29 11:53:34 +0200
commitaf8f1ef273e457318cb48f198e73c59e57373723 (patch)
tree5998501d0ea9a09f26db65e2d29fcb0927b5eee0 /mastoapi.c
parentFix parsing of boundary for multipart/form-data (diff)
downloadpenes-snac2-af8f1ef273e457318cb48f198e73c59e57373723.tar.gz
penes-snac2-af8f1ef273e457318cb48f198e73c59e57373723.tar.xz
penes-snac2-af8f1ef273e457318cb48f198e73c59e57373723.zip
Implement image uploads for Tokodon
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 0adba08..c1f70b9 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -3116,15 +3116,16 @@ void persist_image(const char *key, const xs_val *data, const char *payload, sna
3116 3116
3117 if (fn && *fn) { 3117 if (fn && *fn) {
3118 const char *ext = strrchr(fn, '.'); 3118 const char *ext = strrchr(fn, '.');
3119 /* Mona iOS sends JPG file as application/octet-stream with filename "header" 3119
3120 * Make sure we have a unique file name, otherwise updated images will not be 3120 /* Mona iOS sends always jpg as application/octet-stream with no filename */
3121 * loaded by clients.
3122 */
3123 if (ext == NULL || strcmp(fn, key) == 0) { 3121 if (ext == NULL || strcmp(fn, key) == 0) {
3124 fn = random_str();
3125 ext = ".jpg"; 3122 ext = ".jpg";
3126 } 3123 }
3127 xs *hash = xs_md5_hex(fn, strlen(fn)); 3124
3125 /* Make sure we have a unique file name, otherwise updated images will not be
3126 * re-loaded by clients. */
3127 xs *rnd = random_str();
3128 xs *hash = xs_md5_hex(rnd, strlen(rnd));
3128 xs *id = xs_fmt("%s%s", hash, ext); 3129 xs *id = xs_fmt("%s%s", hash, ext);
3129 xs *url = xs_fmt("%s/s/%s", snac->actor, id); 3130 xs *url = xs_fmt("%s/s/%s", snac->actor, id);
3130 int fo = xs_number_get(xs_list_get(data, 1)); 3131 int fo = xs_number_get(xs_list_get(data, 1));
@@ -3158,6 +3159,14 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path,
3158 if (!xs_is_null(payload)) 3159 if (!xs_is_null(payload))
3159 args = xs_json_loads(payload); 3160 args = xs_json_loads(payload);
3160 } 3161 }
3162 else if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded"))
3163 {
3164 // Some apps send form data instead of json so we should cater for those
3165 if (!xs_is_null(payload)) {
3166 xs *upl = xs_url_dec(payload);
3167 args = xs_url_vars(upl);
3168 }
3169 }
3161 else 3170 else
3162 args = xs_dup(xs_dict_get(req, "p_vars")); 3171 args = xs_dup(xs_dict_get(req, "p_vars"));
3163 3172
@@ -3172,10 +3181,6 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path,
3172 if (xs_startswith(cmd, "/v1/accounts/update_credentials")) { 3181 if (xs_startswith(cmd, "/v1/accounts/update_credentials")) {
3173 /* Update user profile fields */ 3182 /* Update user profile fields */
3174 if (logged_in) { 3183 if (logged_in) {
3175 /*
3176 xs_str *dump = xs_json_dumps(args, 4);
3177 printf("%s\n\n", dump);
3178 */
3179 int c = 0; 3184 int c = 0;
3180 const xs_str *k; 3185 const xs_str *k;
3181 const xs_val *v; 3186 const xs_val *v;
@@ -3195,7 +3200,8 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path,
3195 if (strcmp(k, "bot") == 0) { 3200 if (strcmp(k, "bot") == 0) {
3196 if (v != NULL) 3201 if (v != NULL)
3197 snac.config = xs_dict_set(snac.config, "bot", 3202 snac.config = xs_dict_set(snac.config, "bot",
3198 strcmp(v, "true") == 0 ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE)); 3203 (strcmp(v, "true") == 0 ||
3204 strcmp(v, "1") == 0) ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
3199 } 3205 }
3200 else 3206 else
3201 if (strcmp(k, "source[sensitive]") == 0) { 3207 if (strcmp(k, "source[sensitive]") == 0) {
@@ -3228,6 +3234,10 @@ int mastoapi_patch_handler(const xs_dict *req, const char *q_path,
3228 snac.config = xs_dict_set(snac.config, "metadata", new_fields); 3234 snac.config = xs_dict_set(snac.config, "metadata", new_fields);
3229 } 3235 }
3230 } 3236 }
3237 /* we don't have support for the following options, yet
3238 - discoverable (0/1)
3239 - locked (0/1)
3240 */
3231 } 3241 }
3232 3242
3233 /* Persist profile */ 3243 /* Persist profile */