From 0bfecc99299670a26b263c561123eb2b80b8c67b Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 15 Feb 2023 20:31:46 -0600 Subject: [PATCH] Fix media posts --- src/controller/api/status.c | 4 +--- src/controller/mastodon_api.c | 2 ++ src/model/activity.c | 28 +++++++++++++--------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/controller/api/status.c b/src/controller/api/status.c index 3be53ae..0e591ff 100644 --- a/src/controller/api/status.c +++ b/src/controller/api/status.c @@ -136,9 +136,7 @@ bool handle_post( struct http_request* req, struct account* a ) struct media* m = media_from_id( atoi(params.media_ids.items[i]) ); if( !m ) { continue; } - char* url = aformat( "https://%s/media/%d/blob", g_server->domain, m->id ); - array_append( &s->media, sizeof(url), &url ); - media_free(m); + array_append( &s->media2, sizeof(m), &m ); } if( params.in_reply_to_id ) { diff --git a/src/controller/mastodon_api.c b/src/controller/mastodon_api.c index 97f596d..b969c59 100644 --- a/src/controller/mastodon_api.c +++ b/src/controller/mastodon_api.c @@ -158,6 +158,8 @@ bool handle_media( struct http_request* req ) m = malloc(sizeof(*m)); memset(m,0,sizeof(*m)); m->id = id; + m->remote_url = aformat( "https://%s/media/%d/blob", g_server->domain, id ); + m->preview_url = aformat( "https://%s/media/%d/preview", g_server->domain, id ); f = fopen(format(filename,sizeof(filename), "data/media/%d.blob",id), "w" ); if( !http_request_write_multipart_to_FILE( req, f, &m->content_type ) ) { goto failed; } diff --git a/src/model/activity.c b/src/model/activity.c index e6a03a3..e47003d 100644 --- a/src/model/activity.c +++ b/src/model/activity.c @@ -292,21 +292,19 @@ struct ap_object* activity_create_Note( struct status* s ) char* str = strdup("https://www.w3.org/ns/activitystreams#Public"); array_append( &act->to, sizeof(str), &str ); - for( int i = 0; i < s->media.count; ++i ) { - struct media* m = media_from_local_uri( s->media.items[i] ); - if( m ) { - struct ap_object* att; - att = malloc(sizeof(*att)); - memset(att,0,sizeof(*att)); - - att->type = ap_Document; - att->url = strdup(s->media.items[i]); - att->media_type = strdup(m->content_type); - att->name = strdup(""); - - array_append( &act->attachments, sizeof(att), &att ); - } - media_free(m); + for( int i = 0; i < s->media2.count; ++i ) { + struct media* m = s->media2.items[i]; + + struct ap_object* att; + att = malloc(sizeof(*att)); + memset(att,0,sizeof(*att)); + + att->type = ap_Document; + att->url = strdup(m->remote_url); + att->media_type = strdup(m->content_type); + att->name = strdup(""); + + array_append( &act->attachments, sizeof(att), &att ); } for( int i = 0; i < s->emoji.count; ++i ) {