mirror of
https://github.com/QingWei-Li/notea.git
synced 2024-12-03 23:21:09 +03:00
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import LayoutMain from 'components/layout/layout-main'
|
|
import { useSession } from 'libs/server/middlewares/session'
|
|
import { applySettings } from 'libs/server/middlewares/settings'
|
|
import { applyAuth, applyRedirectLogin } from 'libs/server/middlewares/auth'
|
|
import { applyNote } from 'libs/server/middlewares/note'
|
|
import LayoutPublic from 'components/layout/layout-public'
|
|
import { EditContainer } from 'components/container/edit-container'
|
|
import { PostContainer } from 'components/container/post-container'
|
|
import { applyCsrf } from 'libs/server/middlewares/csrf'
|
|
import { ssr, SSRContext, ServerProps } from 'libs/server/connect'
|
|
import { applyUA } from 'libs/server/middlewares/ua'
|
|
import { applyPostWithAuth } from 'libs/server/middlewares/post'
|
|
import { isNoteLink } from 'libs/shared/note'
|
|
import { applyReset } from 'libs/server/middlewares/reset'
|
|
|
|
export default function EditNotePage({
|
|
tree,
|
|
note,
|
|
pageMode,
|
|
baseURL,
|
|
isLoggedIn,
|
|
post,
|
|
}: ServerProps) {
|
|
if (isLoggedIn) {
|
|
return (
|
|
<LayoutMain tree={tree} note={note}>
|
|
<EditContainer />
|
|
</LayoutMain>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<LayoutPublic tree={tree} note={note} pageMode={pageMode} baseURL={baseURL}>
|
|
<PostContainer title={note?.title} post={post} />
|
|
</LayoutPublic>
|
|
)
|
|
}
|
|
|
|
export const getServerSideProps = async (
|
|
ctx: SSRContext & {
|
|
query: {
|
|
id: string
|
|
}
|
|
}
|
|
) => {
|
|
if (!isNoteLink('/' + ctx.query.id)) {
|
|
return { props: {} }
|
|
}
|
|
|
|
await ssr()
|
|
.use(useSession)
|
|
.use(applyAuth)
|
|
.use(applyNote(ctx.query.id))
|
|
.use(applyRedirectLogin(ctx.resolvedUrl))
|
|
.use(applyReset)
|
|
.use(applySettings)
|
|
.use(applyCsrf)
|
|
.use(applyUA)
|
|
.use(applyPostWithAuth)
|
|
.run(ctx.req, ctx.res)
|
|
|
|
return {
|
|
props: ctx.req.props,
|
|
redirect: ctx.req.redirect,
|
|
}
|
|
}
|