Correct Account lookup

FossilOrigin-Name: 24de2d0db594ded826d27aea2151af230154a9bddc55082367b0fb19013ecba2
This commit is contained in:
me@ow.nekobit.net 2022-02-10 16:04:32 +00:00
parent 630e16d4c1
commit 5e24722d53
6 changed files with 82 additions and 16 deletions

7
dist/ratfe.css vendored
View file

@ -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

View file

@ -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);
}

View file

@ -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");

17
src/uri.c Normal file
View file

@ -0,0 +1,17 @@
#include <string.h>
#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;
}

25
src/uri.h Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#ifndef URI_H
#define URI_H
#include <stddef.h>
int parse_uri(char* dest, size_t dest_max_n, char* src);
#endif // URI_H

View file

@ -1,12 +1,12 @@
<div class="account">
<div class="acct-banner" style="background-image:url('/%s');">
<div class="acct-banner" style="background-image:url('%s');">
<div class="acct-info-data">
<span class="acct-displayname">%s</span>
<span class="acct-username">%s</span>
</div>
</div>
<div class="acct-pfp" style="background-image:url('/%s');">
<div class="acct-pfp" style="background-image:url('%s');">
</div>
<div class="acct-header">