* Muted audio by default!

* Code renderin'

* not but still decently standard files being viewable

* reserved routes

* Update validateConfig.ts

---------

Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com>
This commit is contained in:
Jayvin Hernandez 2023-03-03 20:19:19 -08:00 committed by GitHub
parent 11bca28ef5
commit 8e44b71614
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 5 deletions

View file

@ -1,3 +1,4 @@
import exts from 'lib/exts';
import { import {
Alert, Alert,
Box, Box,
@ -55,10 +56,11 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop
const [text, setText] = useState(''); const [text, setText] = useState('');
const shouldRenderMarkdown = file.name.endsWith('.md'); const shouldRenderMarkdown = file.name.endsWith('.md');
const shouldRenderTex = file.name.endsWith('.tex'); const shouldRenderTex = file.name.endsWith('.tex');
const shouldRenderCode: boolean = Object.keys(exts).includes(file.name.split('.').pop());
const [loading, setLoading] = useState(type === 'text' && popup); const [loading, setLoading] = useState(type === 'text' && popup);
if (type === 'text' && popup) { if ((type === 'text' || shouldRenderMarkdown || shouldRenderTex || shouldRenderCode) && popup) {
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const res = await fetch('/r/' + file.name); 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 ( return (
<> <>
{renderAlert()} {renderAlert()}
<Card p='md' my='sm'> <Card p='md' my='sm'>
{shouldRenderMarkdown && <Markdown code={text} />} {shouldRenderMarkdown && <Markdown code={text} />}
{shouldRenderTex && <KaTeX code={text} />} {shouldRenderTex && <KaTeX code={text} />}
{shouldRenderCode && !(shouldRenderTex || shouldRenderMarkdown) && (
<PrismCode code={text} ext={type} />
)}
</Card> </Card>
</> </>
); );
@ -115,14 +120,14 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop
return popup ? ( return popup ? (
media ? ( media ? (
{ {
video: <video width='100%' autoPlay controls {...props} />, video: <video width='100%' autoPlay muted controls {...props} />,
image: ( image: (
<Image <Image
placeholder={<PlaceholderContent Icon={FileIcon} text={'Image failed to load...'} />} placeholder={<PlaceholderContent Icon={FileIcon} text={'Image failed to load...'} />}
{...props} {...props}
/> />
), ),
audio: <audio autoPlay controls {...props} style={{ width: '100%' }} />, audio: <audio autoPlay muted controls {...props} style={{ width: '100%' }} />,
text: ( text: (
<> <>
{loading ? ( {loading ? (

View file

@ -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; return validated as unknown as Config;
} catch (e) { } catch (e) {
if (process.env.ZIPLINE_DOCKER_BUILD) return null; 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 })}`); logger.debug(`config error: ${inspect(e, { depth: Infinity })}`);
e.stack = ''; e.stack = '';

View file

@ -1,4 +1,5 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'; import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
import exts from 'lib/exts';
export default async function uploadsRoute(this: FastifyInstance, req: FastifyRequest, reply: FastifyReply) { export default async function uploadsRoute(this: FastifyInstance, req: FastifyRequest, reply: FastifyReply) {
const { id } = req.params as { id: string }; 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); const failed = await reply.preFile(image);
if (failed) return reply.notFound(); 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}`); return reply.redirect(`/view/${image.name}`);
else return reply.dbFile(image); else return reply.dbFile(image);
} }