mirror of https://github.com/MaxLeiter/Drift
convert admin, run lint
parent
cf7d89eb20
commit
8b0b172f7d
@ -1,5 +1,5 @@
|
|||||||
import PageSeo from "@components/head"
|
import PageSeo from "@components/page-seo"
|
||||||
|
|
||||||
export default function AuthHead() {
|
export default function AuthHead() {
|
||||||
return <PageSeo title="Sign In" />
|
return <PageSeo title="Sign In" />
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
"use client"
|
||||||
import ShiftBy from "@components/shift-by"
|
import ShiftBy from "@components/shift-by"
|
||||||
import { Spacer, Tabs, Card, Textarea, Text } from "@geist-ui/core/dist"
|
import { Spacer, Tabs, Card, Textarea, Text } from "@geist-ui/core/dist"
|
||||||
import Image from "next/image"
|
import Image from "next/image"
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { Note, Text } from "@geist-ui/core/dist"
|
||||||
|
|
||||||
|
export default function ExpiredPage() {
|
||||||
|
return (
|
||||||
|
<Note type="error" label={false}>
|
||||||
|
<Text h4>Error: The Drift you're trying to view has expired.</Text>
|
||||||
|
</Note>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
export default function NewLayout({ children }: { children: React.ReactNode }) {
|
export default function NewLayout({ children }: { children: React.ReactNode }) {
|
||||||
// useRedirectIfNotAuthed()
|
// useRedirectIfNotAuthed()
|
||||||
return <>{children}</>;
|
return <>{children}</>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
import PageSeo from "@components/page-seo"
|
||||||
|
|
||||||
|
export default function Head() {
|
||||||
|
return <PageSeo title="Drift - Your profile" isPrivate />
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
import { USER_COOKIE_NAME } from "@lib/constants"
|
||||||
|
import { notFound, useRouter } from "next/navigation"
|
||||||
|
import { cookies } from "next/headers"
|
||||||
|
import { getPostsByUser } from "app/prisma"
|
||||||
|
import PostList from "@components/post-list"
|
||||||
|
export default async function Mine() {
|
||||||
|
// TODO: fix router usage
|
||||||
|
// const router = useRouter()
|
||||||
|
const userId = cookies().get(USER_COOKIE_NAME)?.value
|
||||||
|
if (!userId) {
|
||||||
|
// return router.push("/signin")
|
||||||
|
return notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
const posts = await getPostsByUser(userId, true)
|
||||||
|
const hasMore = false
|
||||||
|
return <PostList morePosts={hasMore} initialPosts={posts} />
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
import PageSeo from "@components/page-seo"
|
||||||
|
|
||||||
|
export default function Head() {
|
||||||
|
return <PageSeo title="Drift - Settings" isPrivate />
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
import SettingsPage from "@components/settings"
|
||||||
|
|
||||||
|
const Settings = () => <SettingsPage />
|
||||||
|
|
||||||
|
export default Settings
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
import Admin from "@components/admin"
|
||||||
|
import { TOKEN_COOKIE_NAME } from "@lib/constants"
|
||||||
|
import { isUserAdmin } from "app/prisma"
|
||||||
|
import { cookies } from "next/headers"
|
||||||
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
|
const AdminPage = async () => {
|
||||||
|
const driftToken = cookies().get(TOKEN_COOKIE_NAME)?.value
|
||||||
|
if (!driftToken) {
|
||||||
|
return notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
const isAdmin = await isUserAdmin(driftToken)
|
||||||
|
|
||||||
|
if (!isAdmin) {
|
||||||
|
return notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Admin />
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdminPage
|
||||||
@ -1,34 +0,0 @@
|
|||||||
import styles from "@styles/Home.module.css"
|
|
||||||
|
|
||||||
import MyPosts from "@components/my-posts"
|
|
||||||
import type { GetServerSideProps } from "next"
|
|
||||||
import { Post } from "@lib/types"
|
|
||||||
import { Page } from "@geist-ui/core/dist"
|
|
||||||
import { getCookie } from "cookies-next"
|
|
||||||
import { TOKEN_COOKIE_NAME } from "@lib/constants"
|
|
||||||
import { useRouter } from "next/navigation"
|
|
||||||
import { cookies } from "next/headers"
|
|
||||||
export default function Mine() {
|
|
||||||
const router = useRouter()
|
|
||||||
const driftToken = cookies().get(TOKEN_COOKIE_NAME)
|
|
||||||
if (!driftToken) {
|
|
||||||
return router.push("/signin")
|
|
||||||
}
|
|
||||||
|
|
||||||
// const posts = await fetch(process.env.API_URL + `/posts/mine`, {
|
|
||||||
// method: "GET",
|
|
||||||
// headers: {
|
|
||||||
// "Content-Type": "application/json",
|
|
||||||
// Authorization: `Bearer ${driftToken}`,
|
|
||||||
// "x-secret-key": process.env.SECRET_KEY || ""
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
if (!posts.ok) {
|
|
||||||
return router.push("/signin")
|
|
||||||
}
|
|
||||||
|
|
||||||
const { posts, error, hasMore } = await posts.json()
|
|
||||||
|
|
||||||
return <MyPosts morePosts={hasMore} error={error} posts={posts} />
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import Header from "@components/header"
|
|
||||||
import { Page } from "@geist-ui/core/dist"
|
|
||||||
import styles from "@styles/Home.module.css"
|
|
||||||
|
|
||||||
export default function PageWrapper({
|
|
||||||
children
|
|
||||||
}: {
|
|
||||||
children: React.ReactNode
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<Page width={"100%"}>
|
|
||||||
<Page.Header>
|
|
||||||
<Header />
|
|
||||||
</Page.Header>
|
|
||||||
|
|
||||||
<Page.Content className={styles.main}>{children}</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
import Head from "next/head"
|
|
||||||
import React from "react"
|
|
||||||
|
|
||||||
type PageSeoProps = {
|
|
||||||
title?: string
|
|
||||||
description?: string
|
|
||||||
isLoading?: boolean
|
|
||||||
isPrivate?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
const PageSeo = ({
|
|
||||||
title = "Drift",
|
|
||||||
description = "A self-hostable clone of GitHub Gist",
|
|
||||||
isPrivate = false
|
|
||||||
}: PageSeoProps) => {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Head>
|
|
||||||
<title>{title}</title>
|
|
||||||
{!isPrivate && <meta name="description" content={description} />}
|
|
||||||
</Head>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PageSeo
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
import type { Post } from "@lib/types"
|
|
||||||
import PostList from "../post-list"
|
|
||||||
|
|
||||||
const MyPosts = ({
|
|
||||||
posts,
|
|
||||||
error,
|
|
||||||
morePosts
|
|
||||||
}: {
|
|
||||||
posts: Post[]
|
|
||||||
error: boolean
|
|
||||||
morePosts: boolean
|
|
||||||
}) => {
|
|
||||||
return <PostList morePosts={morePosts} initialPosts={posts} error={error} />
|
|
||||||
}
|
|
||||||
|
|
||||||
export default MyPosts
|
|
||||||
@ -1,12 +1,12 @@
|
|||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from "next/navigation"
|
||||||
import { isSignedIn } from "../is-signed-in"
|
import { isSignedIn } from "../is-signed-in"
|
||||||
|
|
||||||
export const useRedirectIfNotAuthed = (to = '/signin') => {
|
export const useRedirectIfNotAuthed = (to = "/signin") => {
|
||||||
const router = useRouter();
|
const router = useRouter()
|
||||||
|
|
||||||
const signedIn = isSignedIn();
|
const signedIn = isSignedIn()
|
||||||
|
|
||||||
if (!signedIn) {
|
if (!signedIn) {
|
||||||
router.push(to);
|
router.push(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
|
import { TOKEN_COOKIE_NAME, USER_COOKIE_NAME } from "@lib/constants"
|
||||||
import { cookies } from "next/headers"
|
import { cookies } from "next/headers"
|
||||||
|
|
||||||
export const isSignedIn = () => {
|
export const isSignedIn = () => {
|
||||||
const cookieList = cookies()
|
const cookieList = cookies()
|
||||||
return cookieList.has("drift-token") && cookieList.has("drift-userid")
|
return cookieList.has(TOKEN_COOKIE_NAME) && cookieList.has(USER_COOKIE_NAME)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
import styles from "@styles/Home.module.css"
|
|
||||||
|
|
||||||
import { Page } from "@geist-ui/core/dist"
|
|
||||||
import { useEffect } from "react"
|
|
||||||
import Admin from "@components/admin"
|
|
||||||
import useSignedIn from "@lib/hooks/use-signed-in"
|
|
||||||
import { useRouter } from "next/router"
|
|
||||||
import { GetServerSideProps } from "next"
|
|
||||||
import cookie from "cookie"
|
|
||||||
|
|
||||||
const AdminPage = () => {
|
|
||||||
const { signedIn } = useSignedIn()
|
|
||||||
const router = useRouter()
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof window === "undefined") return
|
|
||||||
if (!signedIn) {
|
|
||||||
router.push("/")
|
|
||||||
}
|
|
||||||
}, [router, signedIn])
|
|
||||||
return (
|
|
||||||
<Page className={styles.wrapper}>
|
|
||||||
<Page.Content className={styles.main}>
|
|
||||||
<Admin />
|
|
||||||
</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
|
||||||
const driftToken = cookie.parse(req.headers.cookie || "")[`drift-token`]
|
|
||||||
const res = await fetch(`${process.env.API_URL}/admin/is-admin`, {
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${driftToken}`,
|
|
||||||
"x-secret-key": process.env.SECRET_KEY || ""
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (res.ok) {
|
|
||||||
return {
|
|
||||||
props: {
|
|
||||||
signedIn: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
redirect: {
|
|
||||||
destination: "/",
|
|
||||||
permanent: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AdminPage
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
import config from "@lib/config"
|
|
||||||
import { NextApiRequest, NextApiResponse } from "next"
|
|
||||||
|
|
||||||
const handleRequiresPasscode = async (
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse
|
|
||||||
) => {
|
|
||||||
const requiresPasscode = Boolean(config.registration_password)
|
|
||||||
return res.json({ requiresPasscode })
|
|
||||||
}
|
|
||||||
|
|
||||||
const PATH_TO_HANDLER = {
|
|
||||||
"requires-passcode": handleRequiresPasscode
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-anonymous-default-export
|
|
||||||
export default (req: NextApiRequest, res: NextApiResponse) => {
|
|
||||||
const { slug } = req.query
|
|
||||||
|
|
||||||
if (!slug || Array.isArray(slug)) {
|
|
||||||
return res.status(400).json({ error: "Missing param" })
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (req.method) {
|
|
||||||
case "GET":
|
|
||||||
if (PATH_TO_HANDLER[slug as keyof typeof PATH_TO_HANDLER]) {
|
|
||||||
return PATH_TO_HANDLER[slug as keyof typeof PATH_TO_HANDLER](req, res)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return res.status(405).json({ error: "Method not allowed" })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
import prisma from "app/prisma"
|
|
||||||
|
|
||||||
export const getPostsByUser = async (userId: number) => {
|
|
||||||
const posts = await prisma.post.findMany({
|
|
||||||
where: {
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return posts
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
import config from "@lib/config"
|
|
||||||
import { NextApiRequest, NextApiResponse } from "next"
|
|
||||||
|
|
||||||
const handleSelf = async (req: NextApiRequest, res: NextApiResponse) => {}
|
|
||||||
|
|
||||||
const PATH_TO_HANDLER = {
|
|
||||||
self: handleRequiresPasscode
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-anonymous-default-export
|
|
||||||
export default (req: NextApiRequest, res: NextApiResponse) => {
|
|
||||||
const { slug } = req.query
|
|
||||||
|
|
||||||
if (!slug || Array.isArray(slug)) {
|
|
||||||
return res.status(400).json({ error: "Missing param" })
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (req.method) {
|
|
||||||
case "GET":
|
|
||||||
if (PATH_TO_HANDLER[slug as keyof typeof PATH_TO_HANDLER]) {
|
|
||||||
return PATH_TO_HANDLER[slug as keyof typeof PATH_TO_HANDLER](req, res)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return res.status(405).json({ error: "Method not allowed" })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
import { parseQueryParam } from "@lib/server/parse-query-param"
|
||||||
|
import { getPostsByUser } from "app/prisma"
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next"
|
||||||
|
|
||||||
|
export default async function handle(
|
||||||
|
req: NextApiRequest,
|
||||||
|
res: NextApiResponse
|
||||||
|
) {
|
||||||
|
switch (req.method) {
|
||||||
|
case "GET":
|
||||||
|
const userId = parseQueryParam(req.query.userId)
|
||||||
|
if (!userId) {
|
||||||
|
return res.status(400).json({ error: "Missing userId" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const posts = await getPostsByUser(userId)
|
||||||
|
return res.json(posts)
|
||||||
|
default:
|
||||||
|
return res.status(405).end()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
// user.get("/self", jwt, async (req: UserJwtRequest, res, next) => {
|
||||||
|
// const error = () =>
|
||||||
|
// res.status(401).json({
|
||||||
|
// message: "Unauthorized"
|
||||||
|
// })
|
||||||
|
|
||||||
|
import { USER_COOKIE_NAME } from "@lib/constants"
|
||||||
|
import prisma, { getUserById } from "app/prisma"
|
||||||
|
import { getCookie } from "cookies-next"
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next"
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// if (!req.user) {
|
||||||
|
// return error()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const user = await User.findByPk(req.user?.id, {
|
||||||
|
// attributes: {
|
||||||
|
// exclude: ["password"]
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// if (!user) {
|
||||||
|
// return error()
|
||||||
|
// }
|
||||||
|
// res.json(user)
|
||||||
|
// } catch (error) {
|
||||||
|
// next(error)
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
|
export default async function handler(
|
||||||
|
req: NextApiRequest,
|
||||||
|
res: NextApiResponse
|
||||||
|
): Promise<any> {
|
||||||
|
const error = () =>
|
||||||
|
res.status(401).json({
|
||||||
|
message: "Unauthorized"
|
||||||
|
})
|
||||||
|
|
||||||
|
const userId = String(getCookie(USER_COOKIE_NAME, {
|
||||||
|
req, res
|
||||||
|
}))
|
||||||
|
|
||||||
|
if (!userId) {
|
||||||
|
return error()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await getUserById(userId);
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return error()
|
||||||
|
}
|
||||||
|
return res.json(user)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`/api/user/self:`, e)
|
||||||
|
return error()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,33 +1,31 @@
|
|||||||
// a nextjs api handerl
|
// a nextjs api handerl
|
||||||
|
|
||||||
import config from "@lib/config"
|
import config from "@lib/config"
|
||||||
import markdown from "@lib/render-markdown"
|
import renderMarkdown from "@lib/render-markdown"
|
||||||
import { NextApiRequest, NextApiResponse } from "next"
|
import { NextApiRequest, NextApiResponse } from "next"
|
||||||
|
|
||||||
export const getWelcomeContent = async () => {
|
export const getWelcomeContent = async () => {
|
||||||
const introContent = config.welcome_content
|
const introContent = config.welcome_content
|
||||||
const introTitle = config.welcome_title
|
const introTitle = config.welcome_title
|
||||||
// if (!introContent || !introTitle) {
|
|
||||||
// return {}
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log(introContent)
|
|
||||||
|
|
||||||
|
console.log(renderMarkdown(introContent))
|
||||||
return {
|
return {
|
||||||
title: introTitle,
|
title: introTitle,
|
||||||
content: introContent,
|
content: introContent,
|
||||||
rendered: markdown(introContent)
|
rendered: renderMarkdown(introContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
req: NextApiRequest,
|
_: NextApiRequest,
|
||||||
res: NextApiResponse
|
res: NextApiResponse
|
||||||
) {
|
) {
|
||||||
const welcomeContent = await getWelcomeContent()
|
const welcomeContent = await getWelcomeContent()
|
||||||
if (!welcomeContent) {
|
if (!welcomeContent) {
|
||||||
return res.status(500).json({ error: "Missing welcome content" })
|
return res.status(500).json({ error: "Missing welcome content" })
|
||||||
}
|
}
|
||||||
|
console.log(welcomeContent.title)
|
||||||
|
|
||||||
return res.json(welcomeContent)
|
return res.json(welcomeContent)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
import { Note, Page, Text } from "@geist-ui/core/dist"
|
|
||||||
import styles from "@styles/Home.module.css"
|
|
||||||
|
|
||||||
const Expired = () => {
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<Page.Content className={styles.main}>
|
|
||||||
<Note type="error" label={false}>
|
|
||||||
<Text h4>
|
|
||||||
Error: The Drift you're trying to view has expired.
|
|
||||||
</Text>
|
|
||||||
</Note>
|
|
||||||
</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Expired
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
import styles from "@styles/Home.module.css"
|
|
||||||
import PageSeo from "@components/page-seo"
|
|
||||||
import HomeComponent from "@components/home"
|
|
||||||
import { Page, Text } from "@geist-ui/core/dist"
|
|
||||||
import type { GetStaticProps } from "next"
|
|
||||||
import { InferGetStaticPropsType } from "next"
|
|
||||||
type Props =
|
|
||||||
| {
|
|
||||||
introContent: string
|
|
||||||
introTitle: string
|
|
||||||
rendered: string
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
error: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getStaticProps: GetStaticProps = async () => {
|
|
||||||
try {
|
|
||||||
const resp = await fetch(process.env.API_URL + `/welcome`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-secret-key": process.env.SECRET_KEY || ""
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const { title, content, rendered } = await resp.json()
|
|
||||||
return {
|
|
||||||
props: {
|
|
||||||
introContent: content || null,
|
|
||||||
rendered: rendered || null,
|
|
||||||
introTitle: title || null
|
|
||||||
},
|
|
||||||
// Next.js will attempt to re-generate the page:
|
|
||||||
// - When a request comes in
|
|
||||||
// - At most every 60 seconds
|
|
||||||
revalidate: 60 // In seconds
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// If there was an error, it's likely due to the server not running, so we attempt to regenerate the page
|
|
||||||
return {
|
|
||||||
props: {
|
|
||||||
error: true
|
|
||||||
},
|
|
||||||
revalidate: 10 // In seconds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: fix props type
|
|
||||||
const Home = ({
|
|
||||||
rendered,
|
|
||||||
introContent,
|
|
||||||
introTitle,
|
|
||||||
error
|
|
||||||
}: InferGetStaticPropsType<typeof getStaticProps>) => {
|
|
||||||
return (
|
|
||||||
<Page className={styles.wrapper}>
|
|
||||||
<PageSeo />
|
|
||||||
<Page.Content className={styles.main}>
|
|
||||||
{error && <Text>Something went wrong. Is the server running?</Text>}
|
|
||||||
{!error && (
|
|
||||||
<HomeComponent
|
|
||||||
rendered={rendered}
|
|
||||||
introContent={introContent}
|
|
||||||
introTitle={introTitle}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Home
|
|
||||||
@ -1,78 +0,0 @@
|
|||||||
import styles from "@styles/Home.module.css"
|
|
||||||
import NewPost from "@components/new-post"
|
|
||||||
import Header from "@components/header"
|
|
||||||
import PageSeo from "@components/page-seo"
|
|
||||||
import { Page } from "@geist-ui/core/dist"
|
|
||||||
import Head from "next/head"
|
|
||||||
import { GetServerSideProps } from "next"
|
|
||||||
import { Post } from "@lib/types"
|
|
||||||
import cookie from "cookie"
|
|
||||||
|
|
||||||
const NewFromExisting = ({
|
|
||||||
post,
|
|
||||||
parentId
|
|
||||||
}: {
|
|
||||||
post: Post
|
|
||||||
parentId: string
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<Page className={styles.wrapper}>
|
|
||||||
<PageSeo title="Create a new Drift" />
|
|
||||||
<Head>
|
|
||||||
{/* TODO: solve this. */}
|
|
||||||
{/* eslint-disable-next-line @next/next/no-css-tags */}
|
|
||||||
<link rel="stylesheet" href="/css/react-datepicker.css" />
|
|
||||||
</Head>
|
|
||||||
<Page.Content className={styles.main}>
|
|
||||||
<NewPost initialPost={post} newPostParent={parentId} />
|
|
||||||
</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async ({
|
|
||||||
req,
|
|
||||||
params
|
|
||||||
}) => {
|
|
||||||
const id = params?.id
|
|
||||||
const redirect = {
|
|
||||||
redirect: {
|
|
||||||
destination: "/new",
|
|
||||||
permanent: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!id) {
|
|
||||||
return redirect
|
|
||||||
}
|
|
||||||
|
|
||||||
const driftToken = cookie.parse(req.headers.cookie || "")[`drift-token`]
|
|
||||||
|
|
||||||
const post = await fetch(`${process.env.API_URL}/posts/${id}`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: `Bearer ${driftToken}`,
|
|
||||||
"x-secret-key": process.env.SECRET_KEY || ""
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!post.ok) {
|
|
||||||
return redirect
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await post.json()
|
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
return redirect
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
props: {
|
|
||||||
post: data,
|
|
||||||
parentId: id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default NewFromExisting
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
import styles from "@styles/Home.module.css"
|
|
||||||
import NewPost from "@components/new-post"
|
|
||||||
import Header from "@components/header"
|
|
||||||
import PageSeo from "@components/page-seo"
|
|
||||||
import { Page } from "@geist-ui/core/dist"
|
|
||||||
import Head from "next/head"
|
|
||||||
|
|
||||||
const New = () => {
|
|
||||||
return (
|
|
||||||
<Page className={styles.wrapper}>
|
|
||||||
<PageSeo title="Create a new Drift" />
|
|
||||||
<Head>
|
|
||||||
{/* TODO: solve this. */}
|
|
||||||
{/* eslint-disable-next-line @next/next/no-css-tags */}
|
|
||||||
<link rel="stylesheet" href="/css/react-datepicker.css" />
|
|
||||||
</Head>
|
|
||||||
<Page.Content className={styles.main}>
|
|
||||||
<NewPost />
|
|
||||||
</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default New
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
import {
|
|
||||||
Button,
|
|
||||||
Divider,
|
|
||||||
Text,
|
|
||||||
Fieldset,
|
|
||||||
Input,
|
|
||||||
Page,
|
|
||||||
Note,
|
|
||||||
Textarea
|
|
||||||
} from "@geist-ui/core/dist"
|
|
||||||
import PageSeo from "@components/page-seo"
|
|
||||||
import styles from "@styles/Home.module.css"
|
|
||||||
import SettingsPage from "@components/settings"
|
|
||||||
|
|
||||||
const Settings = () => (
|
|
||||||
<Page width={"100%"}>
|
|
||||||
<PageSeo title="Drift - Settings" />
|
|
||||||
<Page.Content
|
|
||||||
className={styles.main}
|
|
||||||
style={{ gap: "var(--gap)", display: "flex", flexDirection: "column" }}
|
|
||||||
>
|
|
||||||
<SettingsPage />
|
|
||||||
</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
|
|
||||||
export default Settings
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
import { Page } from "@geist-ui/core/dist"
|
|
||||||
import PageSeo from "@components/page-seo"
|
|
||||||
import Auth from "@components/auth"
|
|
||||||
import styles from "@styles/Home.module.css"
|
|
||||||
const SignIn = () => (
|
|
||||||
<Page width={"100%"}>
|
|
||||||
<PageSeo title="Drift - Sign In" />
|
|
||||||
<Page.Content className={styles.main}>
|
|
||||||
<Auth page="signin" />
|
|
||||||
</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
|
|
||||||
export default SignIn
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
import { Page } from "@geist-ui/core/dist"
|
|
||||||
import Auth from "@components/auth"
|
|
||||||
import PageSeo from "@components/page-seo"
|
|
||||||
import styles from "@styles/Home.module.css"
|
|
||||||
|
|
||||||
const SignUp = () => (
|
|
||||||
<Page width="100%">
|
|
||||||
<PageSeo title="Drift - Sign Up" />
|
|
||||||
<Page.Content className={styles.main}>
|
|
||||||
<Auth page="signup" />
|
|
||||||
</Page.Content>
|
|
||||||
</Page>
|
|
||||||
)
|
|
||||||
|
|
||||||
export default SignUp
|
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the `PostAuthors` table. If the table is not empty, all the data it contains will be lost.
|
||||||
|
- Added the required column `authorId` to the `Posts` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- DropTable
|
||||||
|
PRAGMA foreign_keys=off;
|
||||||
|
DROP TABLE "PostAuthors";
|
||||||
|
PRAGMA foreign_keys=on;
|
||||||
|
|
||||||
|
-- RedefineTables
|
||||||
|
PRAGMA foreign_keys=OFF;
|
||||||
|
CREATE TABLE "new_Posts" (
|
||||||
|
"id" TEXT NOT NULL PRIMARY KEY,
|
||||||
|
"title" TEXT NOT NULL,
|
||||||
|
"visibility" TEXT NOT NULL,
|
||||||
|
"password" TEXT,
|
||||||
|
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" DATETIME NOT NULL,
|
||||||
|
"deletedAt" DATETIME,
|
||||||
|
"expiresAt" DATETIME,
|
||||||
|
"parentId" TEXT,
|
||||||
|
"description" TEXT,
|
||||||
|
"authorId" TEXT NOT NULL
|
||||||
|
);
|
||||||
|
INSERT INTO "new_Posts" ("createdAt", "deletedAt", "description", "expiresAt", "id", "parentId", "password", "title", "updatedAt", "visibility") SELECT "createdAt", "deletedAt", "description", "expiresAt", "id", "parentId", "password", "title", "updatedAt", "visibility" FROM "Posts";
|
||||||
|
DROP TABLE "Posts";
|
||||||
|
ALTER TABLE "new_Posts" RENAME TO "Posts";
|
||||||
|
PRAGMA foreign_key_check;
|
||||||
|
PRAGMA foreign_keys=ON;
|
||||||
Loading…
Reference in New Issue