Form fixes and media id's
FossilOrigin-Name: 8ebe26ce8da05e5f79339885842b1ac7a9010d1fa353c21618ffc13c80add968
This commit is contained in:
parent
69c12e124e
commit
4a0862321e
8 changed files with 37 additions and 11 deletions
|
@ -22,6 +22,7 @@
|
|||
#include <mastodont_status.h>
|
||||
#include <mastodont_relationship.h>
|
||||
#include <mastodont_account.h>
|
||||
#include <mastodont_attachment.h>
|
||||
|
||||
/* Functions required form curl */
|
||||
void mastodont_global_curl_init();
|
||||
|
|
|
@ -59,6 +59,7 @@ struct mstdnt_args
|
|||
char* spoiler_text;
|
||||
char* status;
|
||||
char* visibility;
|
||||
int media_ids_len;
|
||||
int remote;
|
||||
int local;
|
||||
char** exclude_types;
|
||||
|
|
|
@ -41,8 +41,8 @@ struct mstdnt_attachment
|
|||
|
||||
struct mstdnt_upload_media_args
|
||||
{
|
||||
char* file;
|
||||
char* thumbnail;
|
||||
struct mstdnt_file file;
|
||||
struct mstdnt_file* thumbnail;
|
||||
char* description;
|
||||
/* TODO focus */
|
||||
};
|
||||
|
|
|
@ -22,7 +22,8 @@ enum _mstdnt_query_type
|
|||
{
|
||||
_MSTDNT_QUERY_STRING,
|
||||
_MSTDNT_QUERY_INT,
|
||||
_MSTDNT_QUERY_ARRAY
|
||||
_MSTDNT_QUERY_ARRAY,
|
||||
_MSTDNT_QUERY_FILE,
|
||||
};
|
||||
|
||||
struct _mstdnt_query_array
|
||||
|
@ -39,6 +40,7 @@ struct _mstdnt_query_param
|
|||
char* s;
|
||||
int i;
|
||||
struct _mstdnt_query_array a;
|
||||
struct mstdnt_file* f;
|
||||
} value;
|
||||
};
|
||||
|
||||
|
|
|
@ -46,4 +46,12 @@ struct mstdnt_storage
|
|||
char* error_description;
|
||||
};
|
||||
|
||||
struct mstdnt_file
|
||||
{
|
||||
char* file;
|
||||
char* filename;
|
||||
size_t filesize;
|
||||
char* filetype;
|
||||
};
|
||||
|
||||
#endif /* MASTODONT_TYPES_H */
|
||||
|
|
|
@ -101,14 +101,13 @@ int mastodont_upload_media(mastodont_t* api,
|
|||
struct mstdnt_attachment* attachment)
|
||||
{
|
||||
union param_value u_file, u_thumbnail, u_description;
|
||||
u_file.s = args->file;
|
||||
u_thumbnail.s = args->thumbnail;
|
||||
u_file.f = &(args->file);
|
||||
u_thumbnail.f = args->thumbnail;
|
||||
u_description.s = args->description;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "file", u_file },
|
||||
{ _MSTDNT_QUERY_STRING, "thumbnail", u_thumbnail },
|
||||
{ _MSTDNT_QUERY_STRING, "description", u_description },
|
||||
{ _MSTDNT_QUERY_FILE, "file", u_file },
|
||||
{ _MSTDNT_QUERY_FILE, "thumbnail", u_thumbnail }
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
|
|
@ -31,10 +31,17 @@ static void mime_params_post(curl_mime* mime,
|
|||
char conv_val[CONV_SIZE];
|
||||
char* val_ptr;
|
||||
char* escape_str;
|
||||
struct mstdnt_file* file = NULL;
|
||||
|
||||
for (i = 0; i < size; ++i)
|
||||
{
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* Skip if file is empty */
|
||||
if (params[i].type == _MSTDNT_QUERY_FILE &&
|
||||
params[i].value.f == NULL)
|
||||
continue;
|
||||
|
||||
switch (params[i].type)
|
||||
{
|
||||
case _MSTDNT_QUERY_INT:
|
||||
|
@ -44,12 +51,18 @@ static void mime_params_post(curl_mime* mime,
|
|||
case _MSTDNT_QUERY_STRING:
|
||||
val_ptr = params[i].value.s;
|
||||
break;
|
||||
case _MSTDNT_QUERY_FILE:
|
||||
file = params[i].value.f;
|
||||
val_ptr = file->file;
|
||||
curl_mime_type(part, file->filetype);
|
||||
curl_mime_filename(part, file->filename);
|
||||
default:
|
||||
/* Any other types are not supported! */
|
||||
break;
|
||||
}
|
||||
|
||||
curl_mime_data(part, val_ptr, CURL_ZERO_TERMINATED);
|
||||
|
||||
curl_mime_data(part, val_ptr,
|
||||
file ? file->filesize : CURL_ZERO_TERMINATED);
|
||||
curl_mime_name(part, params[i].key);
|
||||
}
|
||||
|
||||
|
|
|
@ -187,7 +187,8 @@ int mastodont_create_status(mastodont_t* data,
|
|||
u_in_reply_to_conversation_id.s = args->in_reply_to_conversation_id;
|
||||
u_in_reply_to_id.s = args->in_reply_to_id;
|
||||
u_language.s = args->language;
|
||||
/*u_media_ids.s = args->media_ids;*/
|
||||
u_media_ids.a.arr = args->media_ids;
|
||||
u_media_ids.a.arr_len = args->media_ids_len;
|
||||
/* poll */
|
||||
u_preview.i = args->preview;
|
||||
u_scheduled_at.s = args->scheduled_at;
|
||||
|
@ -201,6 +202,7 @@ int mastodont_create_status(mastodont_t* data,
|
|||
{ _MSTDNT_QUERY_STRING, "content_type", u_content_type },
|
||||
{ _MSTDNT_QUERY_STRING, "status", u_status },
|
||||
{ _MSTDNT_QUERY_STRING, "visibility", u_visibility },
|
||||
{ _MSTDNT_QUERY_ARRAY, "media_ids", u_media_ids },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
|
|
Loading…
Reference in a new issue