From 5e24722d5320ad4a2f2cd16b1b4706d94e2e37a7 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 10 Feb 2022 16:04:32 +0000 Subject: [PATCH] Correct Account lookup FossilOrigin-Name: 24de2d0db594ded826d27aea2151af230154a9bddc55082367b0fb19013ecba2 --- dist/ratfe.css | 7 +++++-- src/account.c | 44 ++++++++++++++++++++++++++++++++------------ src/path.c | 1 + src/uri.c | 17 +++++++++++++++++ src/uri.h | 25 +++++++++++++++++++++++++ static/account.html | 4 ++-- 6 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 src/uri.c create mode 100644 src/uri.h diff --git a/dist/ratfe.css b/dist/ratfe.css index d258835..2c73061 100644 --- a/dist/ratfe.css +++ b/dist/ratfe.css @@ -354,7 +354,8 @@ ul li:first-child a.sidebarbtn position: relative; left: 160px; top: -10px; - text-shadow: 0px 2px 5px rgba(0, 0, 0, 0.4); + font-weight: bold; + text-shadow: 0px 2px 6px #000; } .acct-displayname @@ -367,8 +368,10 @@ ul li:first-child a.sidebarbtn .acct-username { font-size: 14px; - color: #cacaca; + color: #dadada; display: block; + font-weight: bold; + text-shadow: 0px 0px 5px #000; } .header-btn diff --git a/src/account.c b/src/account.c index 0ed9344..8699a09 100644 --- a/src/account.c +++ b/src/account.c @@ -22,6 +22,7 @@ #include "../config.h" #include "account.h" #include "easprintf.h" +#include "uri.h" // Files #include "../static/index.chtml" @@ -32,17 +33,17 @@ char* construct_account_page(struct mstdnt_account* acct, size_t* res_size) int result_size; char* result; result_size = easprintf(&result, data_account_html, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL); + acct->header, + acct->display_name, + acct->username, + acct->avatar, + "Statuses", + 0, + "Following", + 0, + "Followers", + 0, + "Content"); if (result_size == -1) result = NULL; @@ -53,7 +54,22 @@ char* construct_account_page(struct mstdnt_account* acct, size_t* res_size) void content_account(mastodont_t* api) { char* account_page; - account_page = construct_account_page(NULL, NULL); + struct mstdnt_account acct; + struct mstdnt_storage storage; + char uri[MSTDNT_URISIZE]; + + if (parse_uri(uri, MSTDNT_URISIZE, getenv("PATH_INFO")+2)) + { + return; + } + if (mastodont_account(api, MSTDNT_LOOKUP_ACCT, uri, + &acct, &storage, NULL)) + account_page = "An error occured"; + else + account_page = construct_account_page(&acct, NULL); + + if (!account_page) + account_page = "Malloc error"; struct base_page b = { .locale = L10N_EN_US, @@ -63,4 +79,8 @@ void content_account(mastodont_t* api) /* Output */ render_base_page(&b); + + /* Cleanup */ + mastodont_storage_cleanup(&storage); + free(account_page); } diff --git a/src/path.c b/src/path.c index 77e817d..dceaf2b 100644 --- a/src/path.c +++ b/src/path.c @@ -21,6 +21,7 @@ #include "path.h" #include "index.h" #include "account.h" + void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len) { char* path = getenv("PATH_INFO"); diff --git a/src/uri.c b/src/uri.c new file mode 100644 index 0000000..3487660 --- /dev/null +++ b/src/uri.c @@ -0,0 +1,17 @@ +#include +#include "uri.h" + +int parse_uri(char* dest, size_t dest_max_n, char* src) +{ + strncpy(dest, src, dest_max_n); + char* delim = strchr(dest, '/'); + int xp = delim != NULL; /* Expression */ + if (xp || dest[strlen(dest)] == '\0') + { + /* Incase the second expression didn't match, check xp again */ + if (xp) *delim = '\0'; + return 0; + } + + return 1; +} diff --git a/src/uri.h b/src/uri.h new file mode 100644 index 0000000..63847f2 --- /dev/null +++ b/src/uri.h @@ -0,0 +1,25 @@ +/* + * 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 . + */ + +#ifndef URI_H +#define URI_H +#include + +int parse_uri(char* dest, size_t dest_max_n, char* src); + +#endif // URI_H diff --git a/static/account.html b/static/account.html index 5e353bc..c212f1f 100644 --- a/static/account.html +++ b/static/account.html @@ -1,12 +1,12 @@