From de68796101a90889aa8aa5ad0f27076d122a265b Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 23 Mar 2022 18:54:42 -0700 Subject: [PATCH] client: disable theme transitions on change --- client/pages/_app.tsx | 2 +- client/pages/api/markdown/[id].ts | 4 ++++ client/pages/api/raw/[id].ts | 4 +++- client/styles/markdown.css | 4 ++-- server/src/routes/files.ts | 5 +++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/client/pages/_app.tsx b/client/pages/_app.tsx index 0c887e17..5d46b912 100644 --- a/client/pages/_app.tsx +++ b/client/pages/_app.tsx @@ -31,7 +31,7 @@ function MyApp({ Component, pageProps }: AppProps) { Drift - + diff --git a/client/pages/api/markdown/[id].ts b/client/pages/api/markdown/[id].ts index cfb734f0..3cf942a9 100644 --- a/client/pages/api/markdown/[id].ts +++ b/client/pages/api/markdown/[id].ts @@ -11,6 +11,10 @@ const renderMarkdown: NextApiHandler = async (req, res) => { Authorization: `Bearer ${req.cookies["drift-token"]}` } }) + console.log(file.status) + if (file.status !== 200) { + return res.status(404).json({ error: "File not found" }) + } const json = await file.json() const { content, title } = json diff --git a/client/pages/api/raw/[id].ts b/client/pages/api/raw/[id].ts index d07eb525..7325c2b6 100644 --- a/client/pages/api/raw/[id].ts +++ b/client/pages/api/raw/[id].ts @@ -9,10 +9,12 @@ const getRawFile = async (req: NextApiRequest, res: NextApiResponse) => { Authorization: `Bearer ${req.cookies["drift-token"]}` } }) - const json = await file.json() + res.setHeader("Content-Type", "text/plain; charset=utf-8") res.setHeader("Cache-Control", "s-maxage=86400") if (file.ok) { + const json = await file.json() + console.log(json) const data = json const { title, content } = data // serve the file raw as plain text diff --git a/client/styles/markdown.css b/client/styles/markdown.css index df9ecd85..cf6386f9 100644 --- a/client/styles/markdown.css +++ b/client/styles/markdown.css @@ -16,8 +16,8 @@ article img { article [id]::before { content: ""; display: block; - height: 70px; - margin-top: -70px; + height: var(--gap-half); + margin-top: calc(var(--gap-half) * -1); visibility: hidden; } diff --git a/server/src/routes/files.ts b/server/src/routes/files.ts index 50ffc55b..21ee2b71 100644 --- a/server/src/routes/files.ts +++ b/server/src/routes/files.ts @@ -13,6 +13,11 @@ files.get("/raw/:id", secretKey, async (req, res, next) => { attributes: ["title", "content"], }) + + if (!file) { + return res.status(404).json({ error: "File not found" }) + } + // TODO: JWT-checkraw files if (file?.post?.visibility === "private") { // jwt(req as UserJwtRequest, res, () => {