mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: ssr request to user; navbar positioning
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
: '';
|
: '';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="z-100 h-15 w-full bg-neutral-900">
|
<div class="fixed top-0 left-0 z-100 h-15 w-full bg-neutral-900">
|
||||||
<div class="mx-auto flex h-15 max-w-5xl items-center px-4 py-2">
|
<div class="mx-auto flex h-15 max-w-5xl items-center px-4 py-2">
|
||||||
<a href={resolve('/')} class="text-xl font-bold text-white hover:text-neutral-300">Sharpbin</a>
|
<a href={resolve('/')} class="text-xl font-bold text-white hover:text-neutral-300">Sharpbin</a>
|
||||||
{#if $user}
|
{#if $user}
|
||||||
|
|||||||
@@ -46,4 +46,5 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<Navbar {data} />
|
<Navbar {data} />
|
||||||
|
<div class="h-15 w-full"></div>
|
||||||
<slot />
|
<slot />
|
||||||
|
|||||||
@@ -100,7 +100,7 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
class="flex min-h-[calc(100vh-60px)] w-full flex-col items-center justify-center bg-neutral-950 text-white pt-5"
|
||||||
>
|
>
|
||||||
<div class="w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
<div class="w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||||
<h1 class="mb-6 text-center text-4xl font-bold">Create a Paste</h1>
|
<h1 class="mb-6 text-center text-4xl font-bold">Create a Paste</h1>
|
||||||
@@ -158,7 +158,7 @@
|
|||||||
{#if error}
|
{#if error}
|
||||||
<div
|
<div
|
||||||
transition:fly={{ y: 40, duration: 300 }}
|
transition:fly={{ y: 40, duration: 300 }}
|
||||||
class="rounded border border-red-900 bg-red-950 p-2 text-sm text-red-200"
|
class="rounded border border-red-900 bg-red-950 p-2 text-sm text-red-200 mt-2"
|
||||||
>
|
>
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -308,7 +308,7 @@
|
|||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
class="flex w-full min-h-[calc(100vh-60px)] flex-col items-center justify-center bg-neutral-950 text-white pt-5 pb-5"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="max-h-[80vh] w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-4"
|
class="max-h-[80vh] w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-4"
|
||||||
@@ -460,7 +460,7 @@
|
|||||||
|
|
||||||
<div class="overflow-hidden">
|
<div class="overflow-hidden">
|
||||||
<div
|
<div
|
||||||
class="flex items-center justify-between gap-2 rounded-t-md border-b border-neutral-700 bg-neutral-800 px-3 py-2"
|
class="flex flex-col md:flex-row items-center justify-between gap-2 rounded-t-md border-b border-neutral-700 bg-neutral-800 px-3 py-2"
|
||||||
>
|
>
|
||||||
<div class="flex items-center gap-2 text-sm text-neutral-300">
|
<div class="flex items-center gap-2 text-sm text-neutral-300">
|
||||||
<span class="font-medium text-neutral-100"
|
<span class="font-medium text-neutral-100"
|
||||||
@@ -621,7 +621,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{#if editing}
|
{#if editing}
|
||||||
<textarea
|
<textarea
|
||||||
class="mb-3 max-h-[60vh] min-h-10 w-full rounded-b bg-neutral-800 p-2 font-mono"
|
class="mb-3 max-h-[40vh] min-h-10 w-full rounded-b bg-neutral-800 p-2 font-mono"
|
||||||
rows="14"
|
rows="14"
|
||||||
placeholder="Paste content"
|
placeholder="Paste content"
|
||||||
bind:value={editContent}
|
bind:value={editContent}
|
||||||
@@ -637,8 +637,7 @@
|
|||||||
class:hidden={contentRendered && !editing}
|
class:hidden={contentRendered && !editing}
|
||||||
></div>
|
></div>
|
||||||
<code
|
<code
|
||||||
class="codeblock-with-lines hidden max-w-full overflow-x-auto overflow-y-auto"
|
class="codeblock-with-lines overflow-x-auto overflow-y-auto"
|
||||||
style="max-width:100vw; min-width:0;"
|
|
||||||
class:hidden={!contentRendered}
|
class:hidden={!contentRendered}
|
||||||
>
|
>
|
||||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
||||||
@@ -687,7 +686,9 @@
|
|||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
overflow: visible;
|
overflow: hidden;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
max-height: 1%;
|
||||||
}
|
}
|
||||||
.codeblock-with-lines pre {
|
.codeblock-with-lines pre {
|
||||||
display: block;
|
display: block;
|
||||||
@@ -701,7 +702,7 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-height: 60vh;
|
max-height: 40vh;
|
||||||
}
|
}
|
||||||
.code-row {
|
.code-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
class="flex min-h-[calc(100vh-60px)] w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
||||||
>
|
>
|
||||||
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||||
<h1 class="mb-6 text-center text-3xl font-bold">Login</h1>
|
<h1 class="mb-6 text-center text-3xl font-bold">Login</h1>
|
||||||
|
|||||||
@@ -103,7 +103,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
class="flex min-h-[calc(100vh-60px)] w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
||||||
>
|
>
|
||||||
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||||
<h1 class="mb-6 text-center text-3xl font-bold">Register</h1>
|
<h1 class="mb-6 text-center text-3xl font-bold">Register</h1>
|
||||||
|
|||||||
@@ -2,15 +2,33 @@ import type { PageServerLoad } from './$types';
|
|||||||
import { getServerToken } from '$lib/utils/auth';
|
import { getServerToken } from '$lib/utils/auth';
|
||||||
import type { User } from '$lib/types/user';
|
import type { User } from '$lib/types/user';
|
||||||
|
|
||||||
|
const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
|
export const load: PageServerLoad = async ({ params, fetch, cookies, url }) => {
|
||||||
const { username } = params;
|
const { username } = params;
|
||||||
const token = getServerToken(cookies);
|
const token = getServerToken(cookies);
|
||||||
const res = await fetch(`/api/user/${username}`, {
|
|
||||||
|
const res = await fetch(`${apiUrl}/api/user/${username}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: token ? `Bearer ${token}` : ''
|
Authorization: token ? `Bearer ${token}` : ''
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const user = (await res.json()) as User;
|
if (res.status === 500) {
|
||||||
|
return {
|
||||||
|
status: 500,
|
||||||
|
error: { message: 'Internal server error' }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
|
||||||
|
if (res.status !== 200) {
|
||||||
|
return {
|
||||||
|
status: res.status,
|
||||||
|
error: { message: json.message || 'An error occurred' }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const user = json as User;
|
||||||
return { user, url: url.href };
|
return { user, url: url.href };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,14 +22,14 @@
|
|||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
let currentPage = data.user.pagination?.page ?? 1;
|
let currentPage = data.user?.pagination?.page ?? 1;
|
||||||
let pagination: Pagination = data.user.pagination ?? {
|
let pagination: Pagination = data.user?.pagination ?? {
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 50,
|
pageSize: 50,
|
||||||
totalCount: 0,
|
totalCount: 0,
|
||||||
totalPages: 1
|
totalPages: 1
|
||||||
};
|
};
|
||||||
let pastes = data.user.pastes ?? [];
|
let pastes = data.user?.pastes ?? [];
|
||||||
let loading = false;
|
let loading = false;
|
||||||
let isOwner = false;
|
let isOwner = false;
|
||||||
let showEditModal = false;
|
let showEditModal = false;
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
let showRoleModal = false;
|
let showRoleModal = false;
|
||||||
let modalError = '';
|
let modalError = '';
|
||||||
|
|
||||||
$: isOwner = data.user && $user ? data.user.uuid === $user.uuid : false;
|
$: isOwner = data.user && $user ? data.user?.uuid === $user.uuid : false;
|
||||||
|
|
||||||
const roleOptions = [
|
const roleOptions = [
|
||||||
{ label: 'Member', value: 0 },
|
{ label: 'Member', value: 0 },
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
if (pageNum < 1 || pageNum > (pagination.totalPages || 1) || loading) return;
|
if (pageNum < 1 || pageNum > (pagination.totalPages || 1) || loading) return;
|
||||||
loading = true;
|
loading = true;
|
||||||
const token = getToken();
|
const token = getToken();
|
||||||
const res = await fetch(`/api/user/${data.user.username}?page=${pageNum}`, {
|
const res = await fetch(`/api/user/${data.user?.username}?page=${pageNum}`, {
|
||||||
headers: token ? { Authorization: `Bearer ${token}` } : {}
|
headers: token ? { Authorization: `Bearer ${token}` } : {}
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
async function handleUserUpdate(displayName?: string, selectedRoles?: number[]) {
|
async function handleUserUpdate(displayName?: string, selectedRoles?: number[]) {
|
||||||
loading = true;
|
loading = true;
|
||||||
const token = getToken();
|
const token = getToken();
|
||||||
const res = await fetch(`/api/user/uuid/${data.user.uuid}`, {
|
const res = await fetch(`/api/user/uuid/${data.user?.uuid}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -86,9 +86,9 @@
|
|||||||
}
|
}
|
||||||
showEditModal = false;
|
showEditModal = false;
|
||||||
showRoleModal = false;
|
showRoleModal = false;
|
||||||
data.user.displayName = displayName || data.user.displayName;
|
data.user!.displayName = displayName || data.user!.displayName;
|
||||||
if (selectedRoles !== undefined) {
|
if (selectedRoles !== undefined) {
|
||||||
data.user.roles = selectedRoles;
|
data.user!.roles = selectedRoles;
|
||||||
}
|
}
|
||||||
modalError = '';
|
modalError = '';
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
async function handleDeleteAccount() {
|
async function handleDeleteAccount() {
|
||||||
loading = true;
|
loading = true;
|
||||||
const token = getToken();
|
const token = getToken();
|
||||||
const res = await fetch(`/api/user/uuid/${data.user.uuid}`, {
|
const res = await fetch(`/api/user/uuid/${data.user?.uuid}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`
|
Authorization: `Bearer ${token}`
|
||||||
@@ -114,22 +114,22 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>{data.user.displayName || data.user.username} - User Profile</title>
|
<title>{data.user?.displayName || data.user?.username} - User Profile</title>
|
||||||
|
|
||||||
<meta property="og:title" content="{data.user.displayName || data.user.username} - User Profile" />
|
<meta property="og:title" content="{data.user?.displayName || data.user?.username} - User Profile" />
|
||||||
<meta property="og:description" content="View the profile and {pagination.totalCount} paste{pagination.totalCount !== 1 ? 's' : ''} of {data.user.displayName || data.user.username} on Sharpbin." />
|
<meta property="og:description" content="View the profile and {pagination.totalCount} paste{pagination.totalCount !== 1 ? 's' : ''} of {data.user?.displayName || data.user?.username} on Sharpbin." />
|
||||||
<meta property="og:type" content="profile" />
|
<meta property="og:type" content="profile" />
|
||||||
<meta property="og:url" content="{data.url}" />
|
<meta property="og:url" content="{data.url}" />
|
||||||
<meta property="og:site_name" content="Sharpbin" />
|
<meta property="og:site_name" content="Sharpbin" />
|
||||||
<meta property="profile:username" content="{data.user.username}" />
|
<meta property="profile:username" content="{data.user?.username}" />
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<main
|
<main
|
||||||
class="flex min-h-screen w-full flex-col items-center justify-center bg-neutral-950 text-white"
|
class="flex min-h-[calc(100vh-60px)] w-full flex-col items-center justify-center bg-neutral-950 text-white pt-5"
|
||||||
>
|
>
|
||||||
<div class="w-[95%] max-w-5xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
<div class="w-[95%] max-w-5xl rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||||
<h1 class="flex items-center justify-center gap-4 text-center text-4xl font-bold">
|
<h1 class="flex items-center justify-center gap-4 text-center text-4xl font-bold">
|
||||||
{#if data.user.roles.includes(403)}
|
{#if data.user?.roles.includes(403)}
|
||||||
<span
|
<span
|
||||||
class="relative flex h-7 w-7 items-center justify-center overflow-hidden rounded-full"
|
class="relative flex h-7 w-7 items-center justify-center overflow-hidden rounded-full"
|
||||||
use:tooltip={roles[403]}
|
use:tooltip={roles[403]}
|
||||||
@@ -137,8 +137,8 @@
|
|||||||
<User class="h-8 w-8 text-neutral-500" />
|
<User class="h-8 w-8 text-neutral-500" />
|
||||||
<Ban class="absolute h-7 w-7 text-red-500" />
|
<Ban class="absolute h-7 w-7 text-red-500" />
|
||||||
</span>
|
</span>
|
||||||
{:else if data.user.roles.includes(1) || data.user.roles.includes(255)}
|
{:else if data.user?.roles.includes(1) || data.user?.roles.includes(255)}
|
||||||
<span use:tooltip={roles[Math.max(...data.user.roles) as keyof typeof roles]}>
|
<span use:tooltip={roles[Math.max(...data.user?.roles) as keyof typeof roles]}>
|
||||||
<ShieldUser class="h-8 w-8 text-neutral-400" />
|
<ShieldUser class="h-8 w-8 text-neutral-400" />
|
||||||
</span>
|
</span>
|
||||||
{:else}
|
{:else}
|
||||||
@@ -146,12 +146,12 @@
|
|||||||
<User class="h-8 w-8 text-neutral-400" />
|
<User class="h-8 w-8 text-neutral-400" />
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
{data.user.displayName || data.user.username}
|
{data.user?.displayName || data.user?.username}
|
||||||
</h1>
|
</h1>
|
||||||
{#if data.user.displayName && data.user.displayName !== data.user.username}
|
{#if data.user?.displayName && data.user?.displayName !== data.user?.username}
|
||||||
<div class="mb-2 flex items-center justify-center">
|
<div class="mb-2 flex items-center justify-center">
|
||||||
<AtSign class="mr-2 inline h-5 w-5 text-neutral-400" />
|
<AtSign class="mr-2 inline h-5 w-5 text-neutral-400" />
|
||||||
<span class="text-neutral-400">{data.user.username}</span>
|
<span class="text-neutral-400">{data.user?.username}</span>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="mb-2 flex flex-wrap items-center justify-center gap-4 text-sm">
|
<div class="mb-2 flex flex-wrap items-center justify-center gap-4 text-sm">
|
||||||
@@ -159,9 +159,9 @@
|
|||||||
<CalendarDays class="mr-2 h-6 w-6 text-neutral-400" />
|
<CalendarDays class="mr-2 h-6 w-6 text-neutral-400" />
|
||||||
<span
|
<span
|
||||||
class="text-neutral-400"
|
class="text-neutral-400"
|
||||||
use:tooltip={extractDateFromUUIDv7(data.user.uuid)?.toLocaleString() ?? 'Unknown'}
|
use:tooltip={extractDateFromUUIDv7(data.user?.uuid)?.toLocaleString() ?? 'Unknown'}
|
||||||
>
|
>
|
||||||
Joined {extractDateFromUUIDv7(data.user.uuid)?.toLocaleDateString() ?? 'Unknown'}
|
Joined {extractDateFromUUIDv7(data.user?.uuid)?.toLocaleDateString() ?? 'Unknown'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex shrink-0 items-center">
|
<div class="flex shrink-0 items-center">
|
||||||
@@ -172,18 +172,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex shrink-0 items-center">
|
<div class="flex shrink-0 items-center">
|
||||||
<Hash class="mr-1 h-6 w-6 text-neutral-400" />
|
<Hash class="mr-1 h-6 w-6 text-neutral-400" />
|
||||||
<span class="text-neutral-400" use:tooltip={`User #${data.user.uid}`}>
|
<span class="text-neutral-400" use:tooltip={`User #${data.user?.uid}`}>
|
||||||
{data.user.uid}
|
{data.user?.uid}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{#if isOwner && data.user.lastLogin}
|
{#if isOwner && data.user?.lastLogin}
|
||||||
<div class="flex shrink-0 items-center">
|
<div class="flex shrink-0 items-center">
|
||||||
<Clock class="mr-2 h-6 w-6 text-neutral-400" />
|
<Clock class="mr-2 h-6 w-6 text-neutral-400" />
|
||||||
<span
|
<span
|
||||||
class="text-neutral-400"
|
class="text-neutral-400"
|
||||||
use:tooltip={new Date(data.user.lastLogin).toLocaleString()}
|
use:tooltip={new Date(data.user?.lastLogin).toLocaleString()}
|
||||||
>
|
>
|
||||||
Last login {dateToRelativeString(new Date(data.user.lastLogin))}
|
Last login {dateToRelativeString(new Date(data.user?.lastLogin))}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -303,7 +303,7 @@
|
|||||||
mode="multiselect"
|
mode="multiselect"
|
||||||
title="Edit User Roles"
|
title="Edit User Roles"
|
||||||
items={roleOptions}
|
items={roleOptions}
|
||||||
initialValue={data.user.roles}
|
initialValue={data.user?.roles}
|
||||||
error={modalError}
|
error={modalError}
|
||||||
onConfirm={(value) => handleUserUpdate(undefined, value as number[])}
|
onConfirm={(value) => handleUserUpdate(undefined, value as number[])}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
|
|||||||
@@ -103,9 +103,9 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
var pasteQuery = _db.Pastes.AsNoTracking().Where(p => p.AuthorUUID == user.UUID);
|
var pasteQuery = _db.Pastes.AsNoTracking().Where(p => p.AuthorUUID == user.UUID);
|
||||||
if (!isAuthenticatedUser)
|
if (!isAuthenticatedUser)
|
||||||
{
|
{
|
||||||
if (user.Visibility == 1 || user.Visibility == 2)
|
if (user.Visibility == 2)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
else
|
else if (user.Visibility != 1)
|
||||||
pasteQuery = pasteQuery.Where(p => p.Visibility == 0);
|
pasteQuery = pasteQuery.Where(p => p.Visibility == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user