Attachment

FossilOrigin-Name: f8e983bd3be01d2f49bcef3af3f3784dade144e7bbbb15d8ab1127938edcf84d
This commit is contained in:
me@ow.nekobit.net 2022-02-28 17:25:29 +00:00
parent ae3f4f577b
commit 2ef8740731
9 changed files with 310 additions and 54 deletions

30
dist/skel.css vendored
View file

@ -454,3 +454,33 @@ ul li:not(:last-child) .split,
list-style-type: none;
padding-left: 15px;
}
/* Attachments */
.attachments img
{
min-width: 100px;
max-width: 300px;
min-height: 100px;
max-height: 300px;
}
.attachments
{
margin: 10px 0 3px 0;
}
.zoom
{
transition: transform .1s;
transition-timing-function: cubic-bezier(0, 1, 1, 1);
}
.zoom:hover
{
transform: scaleX(1.8) scaleY(1.8);
}
.statusbox textarea
{
border: 1px solid #cacaca;
}

54
src/attachments.c Normal file
View file

@ -0,0 +1,54 @@
/*
* RatFE - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "easprintf.h"
#include "attachments.h"
#include "string_helpers.h"
// Pages
#include "../static/attachments.chtml"
#include "../static/attachment_image.chtml"
char* construct_attachment(struct mstdnt_attachment* att, int* str_size)
{
char* att_html;
size_t s = easprintf(&att_html, data_attachment_image_html,
att->url);
if (str_size) *str_size = s;
return att_html;
}
static char* construct_attachments_voidwrap(void* passed, size_t index, int* res)
{
return construct_attachment((struct mstdnt_attachment*)passed + index, res);
}
char* construct_attachments(struct mstdnt_attachment* atts, size_t atts_len, size_t* str_size)
{
size_t elements_size;
char* elements = construct_func_strings(construct_attachments_voidwrap, atts, atts_len, &elements_size);
char* att_view;
size_t s = easprintf(&att_view, data_attachments_html, elements);
if (str_size) *str_size = s;
// Cleanup
free(elements);
return att_view;
}

26
src/attachments.h Normal file
View file

@ -0,0 +1,26 @@
/*
* RatFE - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ATTACHMENTS_H
#define ATTACHMENTS_H
#include <mastodont.h>
char* construct_attachment(struct mstdnt_attachment* att, int* str_size);
char* construct_attachments(struct mstdnt_attachment* atts, size_t atts_len, size_t* str_size);
#endif // ATTACHMENTS_H

View file

@ -17,57 +17,10 @@
*/
#include <stdlib.h>
#include <stdio.h>
#include "base_page.h"
#include "../config.h"
#include "index.h"
#include "status.h"
#include "easprintf.h"
#include "reply.h"
// Files
#include "../static/index.chtml"
#include "../static/post.chtml"
#include "timeline.h"
void content_index(mastodont_t* api)
{
int cleanup = 0;
size_t status_count, statuses_html_count;
struct mstdnt_status* statuses;
struct mstdnt_storage storage = { 0 };
char* status_format, *post_box;
char* output = NULL;
try_post_status(api);
if (mastodont_timeline_public(api, NULL, &storage, &statuses, &status_count))
{
status_format = "An error occured loading the timeline";
}
else {
// Construct statuses into HTML
status_format = construct_statuses(statuses, status_count, &statuses_html_count);
if (!status_format)
status_format = "Error in malloc!";
cleanup = 1;
}
// Create post box
post_box = construct_post_box(NULL, "", NULL);
easprintf(&output, "%s %s", post_box, status_format);
struct base_page b = {
.locale = L10N_EN_US,
.content = output,
.sidebar_right = NULL
};
// Output
render_base_page(&b);
// Cleanup
mastodont_storage_cleanup(&storage);
if (cleanup) free(status_format);
if (post_box) free(post_box);
if (output) free(output);
// Check logins
tl_public(api, 0);
}

View file

@ -31,6 +31,7 @@
#include "query.h"
#include "status.h"
#include "lists.h"
#include "timeline.h"
int main(void)
{
@ -63,7 +64,10 @@ int main(void)
{ "/status/:/interact", status_interact },
{ "/status/:/reply", status_reply },
{ "/status/:", status_view },
{ "/lists", content_lists }
{ "/lists/for/:", content_tl_list },
{ "/lists", content_lists },
{ "/federated", content_tl_federated },
{ "/local", content_tl_local },
};
handle_paths(&api, paths, sizeof(paths)/sizeof(paths[0]));

View file

@ -25,6 +25,7 @@
#include "cookie.h"
#include "string_helpers.h"
#include "reply.h"
#include "attachments.h"
#include "../config.h"
// Pages
@ -89,13 +90,16 @@ char* construct_status(struct mstdnt_status* status, int* size)
char* reply_count = NULL;
char* repeat_count = NULL;
char* favourites_count = NULL;
char* attachments = NULL;
if (status->replies_count)
easprintf(&reply_count, NUM_STR, status->replies_count);
if (status->reblogs_count)
easprintf(&repeat_count, NUM_STR, status->reblogs_count);
if (status->favourites_count)
easprintf(&favourites_count, NUM_STR, status->favourites_count);
if (status->media_attachments_len)
attachments = construct_attachments(status->media_attachments, status->media_attachments_len, NULL);
size_t s = easprintf(&stat_html, data_status_html,
status->account.avatar,
status->account.display_name, /* Username */
@ -104,6 +108,7 @@ char* construct_status(struct mstdnt_status* status, int* size)
status->account.acct, /* Account */
"Public", /* visibility */
status->content,
attachments ? attachments : "",
config_url_prefix,
status->id,
reply_count ? reply_count : "",
@ -124,6 +129,7 @@ char* construct_status(struct mstdnt_status* status, int* size)
if (reply_count) free(reply_count);
if (repeat_count) free(repeat_count);
if (favourites_count) free(favourites_count);
if (attachments) free(attachments);
return stat_html;
}
@ -164,7 +170,7 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl
struct mstdnt_storage storage, status_storage;
struct mstdnt_status* statuses_before, *statuses_after, status;
size_t stat_before_len, stat_after_len;
char* before_html = NULL, *stat_html = NULL, *after_html = NULL, *stat_reply;
char* before_html = NULL, *stat_html = NULL, *after_html = NULL, *stat_reply = NULL;
try_post_status(api);

151
src/timeline.c Normal file
View file

@ -0,0 +1,151 @@
/*
* RatFE - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "timeline.h"
#include <stdlib.h>
#include <stdio.h>
#include "base_page.h"
#include "../config.h"
#include "index.h"
#include "status.h"
#include "easprintf.h"
#include "reply.h"
void tl_public(mastodont_t* api, int local)
{
int cleanup = 0;
size_t status_count, statuses_html_count;
struct mstdnt_status* statuses;
struct mstdnt_storage storage = { 0 };
char* status_format, *post_box;
char* output = NULL;
struct mstdnt_timeline_public_args args = {
.local = local,
.remote = 0,
.only_media = 0,
.max_id = NULL,
.since_id = NULL,
.min_id = NULL,
.limit = 20,
};
try_post_status(api);
if (mastodont_timeline_public(api, &args, &storage, &statuses, &status_count))
{
status_format = "An error occured loading the timeline";
}
else {
// Construct statuses into HTML
status_format = construct_statuses(statuses, status_count, &statuses_html_count);
if (!status_format)
status_format = "Error in malloc!";
cleanup = 1;
}
// Create post box
post_box = construct_post_box(NULL, "", NULL);
easprintf(&output, "%s %s", post_box, status_format);
struct base_page b = {
.locale = L10N_EN_US,
.content = output,
.sidebar_right = NULL
};
// Output
render_base_page(&b);
// Cleanup
mastodont_storage_cleanup(&storage);
if (cleanup) free(status_format);
if (post_box) free(post_box);
if (output) free(output);
}
void tl_list(mastodont_t* api, char* list_id)
{
int cleanup = 0;
size_t status_count, statuses_html_count;
struct mstdnt_status* statuses;
struct mstdnt_storage storage = { 0 };
char* status_format, *post_box;
char* output = NULL;
struct mstdnt_timeline_list_args args = {
.max_id = NULL,
.since_id = NULL,
.min_id = NULL,
.limit = 20,
};
try_post_status(api);
if (mastodont_timeline_list(api, list_id, &args, &storage, &statuses, &status_count))
{
status_format = "An error occured loading the timeline";
}
else {
// Construct statuses into HTML
status_format = construct_statuses(statuses, status_count, &statuses_html_count);
if (!status_format)
status_format = "Error in malloc!";
cleanup = 1;
}
// Create post box
post_box = construct_post_box(NULL, "", NULL);
easprintf(&output, "%s %s", post_box, status_format);
struct base_page b = {
.locale = L10N_EN_US,
.content = output,
.sidebar_right = NULL
};
// Output
render_base_page(&b);
// Cleanup
mastodont_storage_cleanup(&storage);
if (cleanup) free(status_format);
if (post_box) free(post_box);
}
void content_tl_federated(mastodont_t* api, char** data, size_t data_size)
{
(void)data;
(void)data_size;
tl_public(api, 0);
}
void content_tl_local(mastodont_t* api, char** data, size_t data_size)
{
(void)data;
(void)data_size;
tl_public(api, 1);
}
void content_tl_list(mastodont_t* api, char** data, size_t data_size)
{
(void)data;
(void)data_size;
tl_list(api, data[0]);
}

32
src/timeline.h Normal file
View file

@ -0,0 +1,32 @@
/*
* RatFE - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TIMELINE_H
#define TIMELINE_H
#include <stddef.h>
#include <mastodont.h>
// Federated and local are here
void tl_public(mastodont_t* api, int local);
void tl_list(mastodont_t* api, char* list_id);
void content_tl_federated(mastodont_t* api, char** data, size_t data_size);
void content_tl_local(mastodont_t* api, char** data, size_t data_size);
void content_tl_list(mastodont_t* api, char** data, size_t data_size);
#endif // TIMELINE_H

View file

@ -1 +1 @@
<img src="%s">
<img class="zoom" src="%s">