admin panel
This commit is contained in:
parent
2a512ee545
commit
26f2a10d0a
13 changed files with 139 additions and 1 deletions
124
src/app/jams/admin/page.tsx
Normal file
124
src/app/jams/admin/page.tsx
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
import { MainLayout } from "@/layout/MainLayout/MainLayout";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
import { db, JamTable, UserTable } from "@/lib/mastoauth/kysely";
|
||||||
|
import { ConditionalNull } from "@/components/utility/Conditional";
|
||||||
|
import Link from "next/link";
|
||||||
|
import Markdown from "react-markdown";
|
||||||
|
import rehypeRaw from "rehype-raw";
|
||||||
|
import { JSONJamTable, JSONUserTable } from "@/lib/mastoauth/realtypes";
|
||||||
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
|
export default async function Home({
|
||||||
|
searchParams
|
||||||
|
}: {
|
||||||
|
searchParams: {
|
||||||
|
until: string
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
const curDate = Date.now();
|
||||||
|
const curPage = parseInt(searchParams?.until) || curDate;
|
||||||
|
|
||||||
|
const cookieStore = cookies();
|
||||||
|
const token = cookieStore.get('token')?.value;
|
||||||
|
let existingUser;
|
||||||
|
if (token != null) {
|
||||||
|
let existingToken = await db
|
||||||
|
.selectFrom('tokens')
|
||||||
|
.where('tokens.id', '=', token)
|
||||||
|
.select('owner')
|
||||||
|
.executeTakeFirst();
|
||||||
|
|
||||||
|
if (existingToken != null) {
|
||||||
|
existingUser = await db
|
||||||
|
.selectFrom('users')
|
||||||
|
.where('users.id', '=', existingToken.owner)
|
||||||
|
.selectAll()
|
||||||
|
.executeTakeFirst();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingUser != null && !existingUser.admin) return notFound();
|
||||||
|
|
||||||
|
// It's a JSONJamTable. I don't know why TS hates `number` => `string` conversion.
|
||||||
|
let users = await db
|
||||||
|
.selectFrom('users')
|
||||||
|
.where('users.joined', '<=', curPage)
|
||||||
|
.limit(20)
|
||||||
|
.orderBy('users.joined', 'asc')
|
||||||
|
.selectAll()
|
||||||
|
.execute() as unknown[] as JSONUserTable[];
|
||||||
|
|
||||||
|
// It's a JSONJamTable. I don't know why TS hates `number` => `string` conversion.
|
||||||
|
let apps = await db
|
||||||
|
.selectFrom('apps')
|
||||||
|
.selectAll()
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MainLayout currentPage="/jams/" title="Admin" subtitle="">
|
||||||
|
<h2>cool admin panel !!! :3</h2>
|
||||||
|
<p>contact me@abtmtr.link for help</p>
|
||||||
|
<ConditionalNull condition={existingUser != null}>
|
||||||
|
<p><small>Logged in as <b>{existingUser?.username}@{existingUser?.instance}</b></small></p>
|
||||||
|
<ConditionalNull condition={existingUser?.admin == true}><p><a href="/jams/new/jam">Create Jam</a></p></ConditionalNull>
|
||||||
|
</ConditionalNull>
|
||||||
|
<h2>Users</h2>
|
||||||
|
<p>use this to ban or promote users</p>
|
||||||
|
<p>PLEASE DO NOT PROMOTE USERS WITHOUT MEOWCATHEORANGE'S PERMISSION</p>
|
||||||
|
{users.map(async (user:JSONUserTable) => {
|
||||||
|
let jams = await db
|
||||||
|
.selectFrom('jams')
|
||||||
|
.where('jams.author_id', '=', user.id)
|
||||||
|
.select('id')
|
||||||
|
.orderBy('jams.created', 'asc')
|
||||||
|
.execute();
|
||||||
|
let content = await db
|
||||||
|
.selectFrom('content')
|
||||||
|
.where('content.author_id', '=', user.id)
|
||||||
|
.select('id')
|
||||||
|
.orderBy('content.submitted', 'asc')
|
||||||
|
.execute();
|
||||||
|
let judgements = await db
|
||||||
|
.selectFrom('judgements')
|
||||||
|
.where('judgements.author_id', '=', user.id)
|
||||||
|
.select('id')
|
||||||
|
.orderBy('judgements.published', 'asc')
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
return (<div style={{
|
||||||
|
margin: '16px 0'
|
||||||
|
}}>
|
||||||
|
<p><Link href={`/jams/user/${user.id}`}>{user.username}@{user.instance}</Link></p>
|
||||||
|
<p><small><Link href={user.url} target="_blank">{user.url}</Link></small></p>
|
||||||
|
<p><small>{user.banned ? <><b>BANNED</b> - </> : <></>}{user.admin ? <><b>ADMIN</b> - </> : <></>}Joined {new Date(parseInt(user.joined)).toDateString()}</small></p>
|
||||||
|
<p><small>{jams.length} jam{jams.length != 1 && "s"}, {content.length} submission{content.length != 1 && "s"}, {judgements.length} judgement{judgements.length != 1 && "s"}</small></p>
|
||||||
|
<p><Link href={`/jams/edit/user/${user.id}`}>Edit user</Link> - <Link href={`/jams/delete/user/${user.id}`}>Delete user</Link></p>
|
||||||
|
</div>);
|
||||||
|
})}
|
||||||
|
<div className="navigation">
|
||||||
|
<ConditionalNull condition={curPage < curDate}>
|
||||||
|
<Link href={`?`}>Later</Link>
|
||||||
|
</ConditionalNull>
|
||||||
|
{/* <ConditionalNull condition={curPage * 10 < blogs.data.total_posts}> */}
|
||||||
|
<Link href={`?until=${users.at(-1)?.joined}`}>Earlier</Link>
|
||||||
|
{/* </ConditionalNull> */}
|
||||||
|
</div>
|
||||||
|
<h2>Apps</h2>
|
||||||
|
<p>apps stored in the database</p>
|
||||||
|
<p>if sign-in breaks, it might be one of these</p>
|
||||||
|
<p>contact me@abtmtr.link if sign-in breaks</p>
|
||||||
|
{apps.map(async (app) => {
|
||||||
|
|
||||||
|
return (<div style={{
|
||||||
|
margin: '16px 0'
|
||||||
|
}}>
|
||||||
|
<p><Link href={`https://${app.instance_domain}/`}>{app.instance_domain}</Link></p>
|
||||||
|
<p><small>Client ID: {app.client_id}</small></p>
|
||||||
|
<p><small>Client Secret: {app.client_secret}</small></p>
|
||||||
|
<p><small>Redirect URI: {app.redirect_uri}</small></p>
|
||||||
|
<p><small>Scopes: read</small></p>
|
||||||
|
</div>);
|
||||||
|
})}
|
||||||
|
</MainLayout>
|
||||||
|
)
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ export async function GET(request: NextRequest, {params}: {params: {content: str
|
||||||
.where('judgements.content_id', '=', id)
|
.where('judgements.content_id', '=', id)
|
||||||
.where('judgements.published', '<', until)
|
.where('judgements.published', '<', until)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('judgements.published', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ export async function GET(request: NextRequest) {
|
||||||
.selectFrom('content')
|
.selectFrom('content')
|
||||||
.where('content.submitted', '<', until)
|
.where('content.submitted', '<', until)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('content.submitted', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ export async function GET(request: NextRequest, {params}: {params: {jam: string}
|
||||||
.selectFrom('content')
|
.selectFrom('content')
|
||||||
.where('content.submitted', '<', until)
|
.where('content.submitted', '<', until)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('content.submitted', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ export async function GET(request: NextRequest) {
|
||||||
.selectFrom('jams')
|
.selectFrom('jams')
|
||||||
.where('jams.created', '<', until)
|
.where('jams.created', '<', until)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('jams.created', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ export async function GET(request: NextRequest, {params}: {params: {user: string
|
||||||
.selectFrom('content')
|
.selectFrom('content')
|
||||||
.where('content.submitted', '<', until)
|
.where('content.submitted', '<', until)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('content.submitted', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ export async function GET(request: NextRequest, {params}: { params: {user: strin
|
||||||
.where('jams.created', '<', until)
|
.where('jams.created', '<', until)
|
||||||
.where('jams.author_id', '=', id)
|
.where('jams.author_id', '=', id)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('jams.created', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ export async function GET(request: NextRequest, {params}: {params: {user: string
|
||||||
.where('judgements.author_id', '=', id)
|
.where('judgements.author_id', '=', id)
|
||||||
.where('judgements.published', '<', until)
|
.where('judgements.published', '<', until)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('judgements.published', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ export async function GET(request: NextRequest) {
|
||||||
.selectFrom('users')
|
.selectFrom('users')
|
||||||
.where('users.joined', '<', until)
|
.where('users.joined', '<', until)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('users.joined', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ export default async function Home({
|
||||||
.where('judgements.content_id', '=', content.id)
|
.where('judgements.content_id', '=', content.id)
|
||||||
.where('judgements.published', '<=', curPage)
|
.where('judgements.published', '<=', curPage)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('judgements.published', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute() as unknown[] as JSONJudgementTable[];
|
.execute() as unknown[] as JSONJudgementTable[];
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ export default async function Home({
|
||||||
.where('content.jam_id', '=', jam.id)
|
.where('content.jam_id', '=', jam.id)
|
||||||
.where('content.submitted', '<=', curPage)
|
.where('content.submitted', '<=', curPage)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('content.submitted', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute() as unknown[] as JSONContentTable[];
|
.execute() as unknown[] as JSONContentTable[];
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ export default async function Home({
|
||||||
.selectFrom('jams')
|
.selectFrom('jams')
|
||||||
.where('jams.created', '<=', curPage)
|
.where('jams.created', '<=', curPage)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('jams.created', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute() as unknown[] as JSONJamTable[];
|
.execute() as unknown[] as JSONJamTable[];
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ export default async function Home({
|
||||||
<ConditionalNull condition={existingUser == null}>
|
<ConditionalNull condition={existingUser == null}>
|
||||||
<h2>Log in with the Fediverse</h2>
|
<h2>Log in with the Fediverse</h2>
|
||||||
<form action="/jams/oauth/login">
|
<form action="/jams/oauth/login">
|
||||||
<input name="instance" placeholder="Instance URL" type="text" />
|
<input name="instance" placeholder="Instance URL (e.g. "social.besties.house" or "woem.men")" type="text" />
|
||||||
<input type="submit" />
|
<input type="submit" />
|
||||||
</form>
|
</form>
|
||||||
<p><small>Tested on Mastodon, GoToSocial, Pleroma, and Misskey</small></p>
|
<p><small>Tested on Mastodon, GoToSocial, Pleroma, and Misskey</small></p>
|
||||||
|
|
|
@ -59,6 +59,7 @@ export default async function Home({
|
||||||
.where('content.author_id', '=', user.id)
|
.where('content.author_id', '=', user.id)
|
||||||
.where('content.submitted', '<=', curPage)
|
.where('content.submitted', '<=', curPage)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('content.submitted', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute() as unknown[] as JSONContentTable[];
|
.execute() as unknown[] as JSONContentTable[];
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ export default async function Home({
|
||||||
.where('jams.author_id', '=', user.id)
|
.where('jams.author_id', '=', user.id)
|
||||||
.where('jams.created', '<=', curPage)
|
.where('jams.created', '<=', curPage)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('jams.created', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute() as unknown[] as JSONJamTable[];
|
.execute() as unknown[] as JSONJamTable[];
|
||||||
|
|
||||||
|
@ -75,6 +77,7 @@ export default async function Home({
|
||||||
.where('judgements.author_id', '=', user.id)
|
.where('judgements.author_id', '=', user.id)
|
||||||
.where('judgements.published', '<=', curPage)
|
.where('judgements.published', '<=', curPage)
|
||||||
.limit(20)
|
.limit(20)
|
||||||
|
.orderBy('judgements.published', 'asc')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute() as unknown[] as JSONJudgementTable[];
|
.execute() as unknown[] as JSONJudgementTable[];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue