diff --git a/src/components/Type.tsx b/src/components/Type.tsx
index 4271d71..1f33642 100644
--- a/src/components/Type.tsx
+++ b/src/components/Type.tsx
@@ -1,3 +1,4 @@
+import exts from 'lib/exts';
import {
Alert,
Box,
@@ -55,10 +56,11 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop
const [text, setText] = useState('');
const shouldRenderMarkdown = file.name.endsWith('.md');
const shouldRenderTex = file.name.endsWith('.tex');
+ const shouldRenderCode: boolean = Object.keys(exts).includes(file.name.split('.').pop());
const [loading, setLoading] = useState(type === 'text' && popup);
- if (type === 'text' && popup) {
+ if ((type === 'text' || shouldRenderMarkdown || shouldRenderTex || shouldRenderCode) && popup) {
useEffect(() => {
(async () => {
const res = await fetch('/r/' + file.name);
@@ -86,13 +88,16 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop
);
};
- if ((shouldRenderMarkdown || shouldRenderTex) && !props.overrideRender && popup)
+ if ((shouldRenderMarkdown || shouldRenderTex || shouldRenderCode) && !props.overrideRender && popup)
return (
<>
{renderAlert()}
{shouldRenderMarkdown && }
{shouldRenderTex && }
+ {shouldRenderCode && !(shouldRenderTex || shouldRenderMarkdown) && (
+
+ )}
>
);
@@ -115,14 +120,14 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop
return popup ? (
media ? (
{
- video: ,
+ video: ,
image: (
}
{...props}
/>
),
- audio: ,
+ audio: ,
text: (
<>
{loading ? (
diff --git a/src/lib/config/validateConfig.ts b/src/lib/config/validateConfig.ts
index a1a3854..393c7b6 100644
--- a/src/lib/config/validateConfig.ts
+++ b/src/lib/config/validateConfig.ts
@@ -250,10 +250,28 @@ export default function validate(config): Config {
}
}
+ const reserved = ['/view', '/dashboard', '/code', '/folder', '/api', '/auth'];
+ if (reserved.some((r) => validated.uploader.route.startsWith(r))) {
+ throw {
+ errors: [`The uploader route cannot be ${validated.uploader.route}, this is a reserved route.`],
+ show: true,
+ };
+ } else if (reserved.some((r) => validated.urls.route.startsWith(r))) {
+ throw {
+ errors: [`The urls route cannot be ${validated.urls.route}, this is a reserved route.`],
+ show: true,
+ };
+ }
+
return validated as unknown as Config;
} catch (e) {
if (process.env.ZIPLINE_DOCKER_BUILD) return null;
+ if (e.show) {
+ Logger.get('config').error('Config is invalid, see below:').error(e.errors.join('\n'));
+ process.exit(1);
+ }
+
logger.debug(`config error: ${inspect(e, { depth: Infinity })}`);
e.stack = '';
diff --git a/src/server/routes/uploads.ts b/src/server/routes/uploads.ts
index df31b69..ea96b0e 100644
--- a/src/server/routes/uploads.ts
+++ b/src/server/routes/uploads.ts
@@ -1,4 +1,5 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
+import exts from 'lib/exts';
export default async function uploadsRoute(this: FastifyInstance, req: FastifyRequest, reply: FastifyReply) {
const { id } = req.params as { id: string };
@@ -16,7 +17,9 @@ export default async function uploadsRoute(this: FastifyInstance, req: FastifyRe
const failed = await reply.preFile(image);
if (failed) return reply.notFound();
- if (image.password || image.embed || image.mimetype.startsWith('text/'))
+ const ext = image.name.split('.').pop();
+
+ if (image.password || image.embed || image.mimetype.startsWith('text/') || Object.keys(exts).includes(ext))
return reply.redirect(`/view/${image.name}`);
else return reply.dbFile(image);
}