feat: expose some more info in /settings

This commit is contained in:
Sam 2023-05-19 03:13:46 +02:00
parent 130a1996d7
commit c3291edd4f
No known key found for this signature in database
GPG key ID: B4EF20DDE721CAA1
3 changed files with 37 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package user
import ( import (
"net/http" "net/http"
"time"
"codeberg.org/u1f320/pronouns.cc/backend/db" "codeberg.org/u1f320/pronouns.cc/backend/db"
"codeberg.org/u1f320/pronouns.cc/backend/log" "codeberg.org/u1f320/pronouns.cc/backend/log"
@ -29,6 +30,8 @@ type GetUserResponse struct {
type GetMeResponse struct { type GetMeResponse struct {
GetUserResponse GetUserResponse
CreatedAt time.Time `json:"created_at"`
MaxInvites int `json:"max_invites"` MaxInvites int `json:"max_invites"`
IsAdmin bool `json:"is_admin"` IsAdmin bool `json:"is_admin"`
ListPrivate bool `json:"list_private"` ListPrivate bool `json:"list_private"`
@ -194,6 +197,7 @@ func (s *Server) getMeUser(w http.ResponseWriter, r *http.Request) error {
render.JSON(w, r, GetMeResponse{ render.JSON(w, r, GetMeResponse{
GetUserResponse: dbUserToResponse(u, fields, members), GetUserResponse: dbUserToResponse(u, fields, members),
CreatedAt: u.ID.Time(),
MaxInvites: u.MaxInvites, MaxInvites: u.MaxInvites,
IsAdmin: u.IsAdmin, IsAdmin: u.IsAdmin,
ListPrivate: u.ListPrivate, ListPrivate: u.ListPrivate,

View file

@ -1,6 +1,7 @@
import { PUBLIC_BASE_URL } from "$env/static/public"; import { PUBLIC_BASE_URL } from "$env/static/public";
export const MAX_MEMBERS = 500; export const MAX_MEMBERS = 500;
export const MAX_FIELDS = 25;
export const MAX_DESCRIPTION_LENGTH = 1000; export const MAX_DESCRIPTION_LENGTH = 1000;
export interface User { export interface User {
@ -38,7 +39,9 @@ export enum PreferenceSize {
} }
export interface MeUser extends User { export interface MeUser extends User {
created_at: string;
max_invites: number; max_invites: number;
is_admin: boolean;
discord: string | null; discord: string | null;
discord_username: string | null; discord_username: string | null;
tumblr: string | null; tumblr: string | null;

View file

@ -1,6 +1,12 @@
<script lang="ts"> <script lang="ts">
import { goto } from "$app/navigation"; import { goto } from "$app/navigation";
import { type MeUser, userAvatars, type APIError, MAX_MEMBERS } from "$lib/api/entities"; import {
type MeUser,
userAvatars,
type APIError,
MAX_MEMBERS,
MAX_FIELDS,
} from "$lib/api/entities";
import { apiFetchClient, fastFetchClient } from "$lib/api/fetch"; import { apiFetchClient, fastFetchClient } from "$lib/api/fetch";
import { usernameRegex } from "$lib/api/regex"; import { usernameRegex } from "$lib/api/regex";
import ErrorAlert from "$lib/components/ErrorAlert.svelte"; import ErrorAlert from "$lib/components/ErrorAlert.svelte";
@ -19,6 +25,7 @@
} from "sveltestrap"; } from "sveltestrap";
import type { PageData } from "./$types"; import type { PageData } from "./$types";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { DateTime } from "luxon";
export let data: PageData; export let data: PageData;
@ -188,16 +195,38 @@
<th scope="row">ID</th> <th scope="row">ID</th>
<td><code>{data.user.id}</code></td> <td><code>{data.user.id}</code></td>
</tr> </tr>
<tr>
<th scope="row">Account created at</th>
<td
>{DateTime.fromISO(data.user.created_at)
.toLocal()
.toLocaleString(DateTime.DATETIME_MED)}</td
>
</tr>
<tr> <tr>
<th scope="row">Members</th> <th scope="row">Members</th>
<td>{data.user.members.length}/{MAX_MEMBERS}</td> <td>{data.user.members.length}/{MAX_MEMBERS}</td>
</tr> </tr>
<tr>
<th scope="row">Member list hidden?</th>
<td>{data.user.list_private ? "Yes" : "No"}</td>
</tr>
<tr>
<th scope="row">Custom preferences</th>
<td>{Object.keys(data.user.custom_preferences).length}/{MAX_FIELDS}</td>
</tr>
{#if data.invitesEnabled} {#if data.invitesEnabled}
<tr> <tr>
<th scope="row">Invites</th> <th scope="row">Invites</th>
<td>{data.invites.length}/{data.user.max_invites}</td> <td>{data.invites.length}/{data.user.max_invites}</td>
</tr> </tr>
{/if} {/if}
{#if data.user.is_admin}
<tr>
<th scope="row">Admin?</th>
<td>Yes</td>
</tr>
{/if}
</tbody> </tbody>
</Table> </Table>
</div> </div>