Remove and cleanup media posts / CSS fixes
FossilOrigin-Name: af1e0399f81e673e6c72d93767b183ca30cb8f80c0685747f1abe29d176c0fe4
This commit is contained in:
parent
84e453e798
commit
bbe110ed7b
7 changed files with 77 additions and 59 deletions
2
dist/treebird20.css
vendored
2
dist/treebird20.css
vendored
|
@ -98,7 +98,7 @@ table.ui-table td
|
|||
|
||||
#navbar-right-container
|
||||
{
|
||||
width: 800px;
|
||||
width: 782px;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
top: 9px;
|
||||
|
|
12
dist/treebird40.css
vendored
12
dist/treebird40.css
vendored
|
@ -23,7 +23,7 @@ body
|
|||
margin-right: auto;
|
||||
box-shadow: 0px 2px 15px rgba(0, 0, 0, 0.3);
|
||||
border-width: 0;
|
||||
border-radius: 5px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.hidden
|
||||
|
@ -63,14 +63,14 @@ table.ui-table td
|
|||
#content
|
||||
{
|
||||
overflow: hidden;
|
||||
border-bottom-left-radius: 5px;
|
||||
border-bottom-right-radius: 5px;
|
||||
border-bottom-left-radius: 8px;
|
||||
border-bottom-right-radius: 8px;
|
||||
}
|
||||
|
||||
#navbar
|
||||
{
|
||||
border-top-left-radius: 5px;
|
||||
border-top-right-radius: 5px;
|
||||
border-top-left-radius: 8px;
|
||||
border-top-right-radius: 8px;
|
||||
background: rgba(245, 245, 245, 0.8);
|
||||
backdrop-filter: blur(12px);
|
||||
width: 1000px;
|
||||
|
@ -98,7 +98,7 @@ table.ui-table td
|
|||
|
||||
#navbar-right-container
|
||||
{
|
||||
width: 800px;
|
||||
width: 782px;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
top: 11px;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "easprintf.h"
|
||||
#include "attachments.h"
|
||||
|
@ -31,6 +32,57 @@ struct attachments_args
|
|||
mstdnt_bool sensitive;
|
||||
};
|
||||
|
||||
int try_upload_media(struct mstdnt_storage* storage,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct mstdnt_attachment** attachments,
|
||||
char*** media_ids)
|
||||
{
|
||||
if (!ssn->post.files.array_size)
|
||||
return 1;
|
||||
|
||||
if (media_ids)
|
||||
*media_ids = malloc(sizeof(char*) * ssn->post.files.array_size);
|
||||
|
||||
*attachments = malloc(sizeof(struct mstdnt_attachment) * ssn->post.files.array_size);
|
||||
|
||||
for (int i = 0; i < ssn->post.files.array_size; ++i)
|
||||
{
|
||||
struct file_content* content = ssn->post.files.content + i;
|
||||
struct mstdnt_upload_media_args args = {
|
||||
.file = {
|
||||
.file = content->content,
|
||||
.filename = content->filename,
|
||||
.filesize = content->content_size,
|
||||
.filetype = content->filetype,
|
||||
},
|
||||
.thumbnail = NULL,
|
||||
.description = "Treebird image"
|
||||
};
|
||||
|
||||
mastodont_upload_media(api,
|
||||
&args,
|
||||
storage,
|
||||
*attachments + i);
|
||||
|
||||
if (media_ids)
|
||||
{
|
||||
(*media_ids)[i] = malloc(strlen((*attachments)[i].id)+1);
|
||||
strcpy((*media_ids)[i], (*attachments)[i].id);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cleanup_media_ids(struct session* ssn, char** media_ids)
|
||||
{
|
||||
if (!media_ids) return;
|
||||
for (size_t i = 0; i < ssn->post.files.array_size; ++i)
|
||||
free(media_ids[i]);
|
||||
free(media_ids);
|
||||
}
|
||||
|
||||
char* construct_attachment(mstdnt_bool sensitive, struct mstdnt_attachment* att, int* str_size)
|
||||
{
|
||||
char* att_html;
|
||||
|
|
|
@ -19,7 +19,14 @@
|
|||
#ifndef ATTACHMENTS_H
|
||||
#define ATTACHMENTS_H
|
||||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
|
||||
int try_upload_media(struct mstdnt_storage* storage,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct mstdnt_attachment** attachments,
|
||||
char*** media_ids);
|
||||
void cleanup_media_ids(struct session* ssn, char** media_ids);
|
||||
char* construct_attachment(mstdnt_bool sensitive, struct mstdnt_attachment* att, int* str_size);
|
||||
char* construct_attachments(mstdnt_bool sensitive, struct mstdnt_attachment* atts, size_t atts_len, size_t* str_size);
|
||||
|
||||
|
|
54
src/status.c
54
src/status.c
|
@ -46,64 +46,19 @@ struct status_args
|
|||
struct mstdnt_status* status;
|
||||
};
|
||||
|
||||
// TODO move to attachments.c
|
||||
int try_upload_media(struct session* ssn,
|
||||
mastodont_t* api,
|
||||
char*** media_ids)
|
||||
{
|
||||
struct mstdnt_attachment attachment;
|
||||
struct mstdnt_storage storage;
|
||||
|
||||
if (!ssn->post.files.array_size)
|
||||
return 1;
|
||||
*media_ids = malloc(sizeof(char*) * ssn->post.files.array_size);
|
||||
|
||||
for (int i = 0; i < ssn->post.files.array_size; ++i)
|
||||
{
|
||||
struct file_content* content = ssn->post.files.content + i;
|
||||
struct mstdnt_upload_media_args args = {
|
||||
.file = {
|
||||
.file = content->content,
|
||||
.filename = content->filename,
|
||||
.filesize = content->content_size,
|
||||
.filetype = content->filetype,
|
||||
},
|
||||
.thumbnail = NULL,
|
||||
.description = "Treebird image"
|
||||
};
|
||||
|
||||
mastodont_upload_media(api,
|
||||
&args,
|
||||
&storage,
|
||||
&attachment);
|
||||
|
||||
(*media_ids)[i] = malloc(strlen(attachment.id)+1);
|
||||
strcpy((*media_ids)[i], attachment.id);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cleanup_media_ids(struct session* ssn, char** media_ids)
|
||||
{
|
||||
if (!media_ids) return;
|
||||
for (size_t i = 0; i < ssn->post.files.array_size; ++i)
|
||||
free(media_ids[i]);
|
||||
free(media_ids);
|
||||
}
|
||||
|
||||
int try_post_status(struct session* ssn, mastodont_t* api)
|
||||
{
|
||||
if (!(ssn->post.content)) return 1;
|
||||
|
||||
struct mstdnt_storage storage;
|
||||
struct mstdnt_storage storage, att_storage = { 0 };
|
||||
|
||||
char** files;
|
||||
size_t files_len;
|
||||
struct mstdnt_attachment* attachments = NULL;
|
||||
char** media_ids = NULL;
|
||||
|
||||
// Upload images
|
||||
try_upload_media(ssn, api, &media_ids);
|
||||
try_upload_media(&att_storage, ssn, api, &attachments, &media_ids);
|
||||
|
||||
// Cookie copy and read
|
||||
struct mstdnt_args args = {
|
||||
|
@ -127,7 +82,9 @@ int try_post_status(struct session* ssn, mastodont_t* api)
|
|||
|
||||
// TODO cleanup when errors are properly implemented
|
||||
mastodont_storage_cleanup(&storage);
|
||||
mastodont_storage_cleanup(&att_storage);
|
||||
cleanup_media_ids(ssn, media_ids);
|
||||
if (attachments) free(attachments);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -139,7 +96,6 @@ void content_status_create(struct session* ssn, mastodont_t* api, char** data)
|
|||
try_post_status(ssn, api);
|
||||
|
||||
redirect(REDIRECT_303, referer);
|
||||
|
||||
}
|
||||
|
||||
int try_interact_status(struct session* ssn, mastodont_t* api, char* id)
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
#define STATUS_EMOJI_PICKER (1<<1)
|
||||
|
||||
char* construct_in_reply_to(mastodont_t* api, struct mstdnt_status* status, size_t* size);
|
||||
int try_upload_media(struct session* ssn,
|
||||
mastodont_t* api,
|
||||
char*** media_ids);
|
||||
int try_post_status(struct session* ssn, mastodont_t* api);
|
||||
int try_interact_status(struct session* ssn, mastodont_t* api, char* id);
|
||||
void content_status_create(struct session* ssn, mastodont_t* api, char** data);
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
<label for="cfgdark">Dark</label>
|
||||
</li>
|
||||
</ul>
|
||||
<h3>Background</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<input type="file" name="file">
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue