fix: spaces and route fixes (#294)

* fix: spaces and route fixes

* fix: shorten url response

* feat: better version checking

* fix: use special characters should work

If it doesn't, better call saul

* save that extra byte

* fix: returning protocol again in domain

unrelated to this pr but whatever

* fix: above ^

* Rename shorten.tsv to shorten.ts

---------

Co-authored-by: diced <pranaco2@gmail.com>
Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com>
This commit is contained in:
Jayvin Hernandez 2023-02-23 16:16:11 -08:00 committed by GitHub
parent 04d8b6421a
commit 739f584921
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 22 deletions

View file

@ -225,7 +225,7 @@ export default function File({
<Stack>
<Type
file={image}
src={`/r/${image.name}`}
src={`/r/${encodeURI(image.name)}`}
alt={image.name}
popup
sx={{ minHeight: 200 }}
@ -356,7 +356,7 @@ export default function File({
<ActionIcon
color='blue'
variant='filled'
onClick={() => window.open(`/r/${image.name}?download=true`, '_blank')}
onClick={() => window.open(`/r/${encodeURI(image.name)}?download=true`, '_blank')}
>
<DownloadIcon />
</ActionIcon>
@ -383,7 +383,7 @@ export default function File({
width: '100%',
cursor: 'pointer',
}}
src={`/r/${image.name}`}
src={`/r/${encodeURI(image.name)}`}
alt={image.name}
onClick={() => setOpen(true)}
disableMediaPreview={disableMediaPreview}

View file

@ -1,3 +1,3 @@
export function formatRootUrl(route: string, src: string) {
return `${route === '/' ? '' : route}/${src}`;
return `${route === '/' ? '' : route}/${encodeURI(src)}`;
}

View file

@ -60,14 +60,13 @@ async function handler(req: NextApiReq, res: NextApiRes) {
if (req.headers['override-domain']) {
domain = `${zconfig.core.return_https ? 'https' : 'http'}://${req.headers['override-domain']}`;
} else if (user.domains.length) {
const randomDomain = user.domains[Math.floor(Math.random() * user.domains.length)];
domain = `${zconfig.core.return_https ? 'https' : 'http'}://${randomDomain}`;
domain = user.domains[Math.floor(Math.random() * user.domains.length)];
} else {
domain = `${zconfig.core.return_https ? 'https' : 'http'}://${req.headers.host}`;
}
const responseUrl = `${domain}${zconfig.uploader.route === '/' ? '/' : zconfig.uploader.route}${
req.body.vanity ? req.body.vanity : invis ? invis.invis : url.id
const responseUrl = `${domain}${zconfig.urls.route === '/' ? '/' : zconfig.urls.route + '/'}${
req.body.vanity ? encodeURI(req.body.vanity) : invis ? invis.invis : url.id
}`;
if (config.discord?.shorten) {

View file

@ -180,8 +180,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
domain = `${zconfig.core.return_https ? 'https' : 'http'}://${req.headers.host}`;
}
const responseUrl = `${domain}${zconfig.uploader.route === '/' ? '/' : zconfig.uploader.route}${
invis ? invis.invis : file.name
const responseUrl = `${domain}${zconfig.uploader.route === '/' ? '/' : zconfig.uploader.route + '/'}${
invis ? invis.invis : encodeURI(file.name)
}`;
response.files.push(responseUrl);
@ -313,14 +313,13 @@ async function handler(req: NextApiReq, res: NextApiRes) {
if (req.headers['override-domain']) {
domain = `${zconfig.core.return_https ? 'https' : 'http'}://${req.headers['override-domain']}`;
} else if (user.domains.length) {
const randomDomain = user.domains[Math.floor(Math.random() * user.domains.length)];
domain = `${zconfig.core.return_https ? 'https' : 'http'}://${randomDomain}`;
domain = user.domains[Math.floor(Math.random() * user.domains.length)];
} else {
domain = `${zconfig.core.return_https ? 'https' : 'http'}://${req.headers.host}`;
}
const responseUrl = `${domain}${zconfig.uploader.route === '/' ? '/' : zconfig.uploader.route}${
invis ? invis.invis : fileUpload.name
const responseUrl = `${domain}${zconfig.uploader.route === '/' ? '/' : zconfig.uploader.route + '/'}${
invis ? invis.invis : encodeURI(fileUpload.name)
}`;
response.files.push(responseUrl);

View file

@ -21,7 +21,7 @@ export default function EmbeddedFile({
pass: boolean;
prismRender: boolean;
}) {
const dataURL = (route: string) => `${route}/${file.name}`;
const dataURL = (route: string) => `${route}/${encodeURI(file.name)}`;
const router = useRouter();
const [opened, setOpened] = useState(pass);
@ -171,7 +171,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const file = await prisma.file.findFirst({
where: {
OR: [{ name: id }, { invisible: { invis: id } }],
OR: [{ name: id }, { invisible: { invis: decodeURI(encodeURI(id)) } }],
},
});
if (!file) return { notFound: true };

View file

@ -113,7 +113,7 @@ async function start() {
const url = await server.prisma.url.findFirst({
where: {
OR: [{ id: id }, { vanity: id }, { invisible: { invis: decodeURI(id) } }],
OR: [{ id: id }, { vanity: id }, { invisible: { invis: decodeURI(encodeURI(id)) } }],
},
});
@ -126,7 +126,7 @@ async function start() {
const url = await server.prisma.url.findFirst({
where: {
OR: [{ id: id }, { vanity: id }, { invisible: { invis: decodeURI(id) } }],
OR: [{ id: id }, { vanity: id }, { invisible: { invis: decodeURI(encodeURI(id)) } }],
},
});

View file

@ -6,7 +6,7 @@ export default async function rawRoute(this: FastifyInstance, req: FastifyReques
const file = await this.prisma.file.findFirst({
where: {
OR: [{ name: id }, { invisible: { invis: decodeURI(id) } }],
OR: [{ name: id }, { invisible: { invis: decodeURI(encodeURI(id)) } }],
},
});

View file

@ -8,7 +8,7 @@ export default async function uploadsRoute(this: FastifyInstance, req: FastifyRe
const image = await this.prisma.file.findFirst({
where: {
OR: [{ name: id }, { invisible: { invis: decodeURI(id) } }],
OR: [{ name: id }, { invisible: { invis: decodeURI(encodeURI(id)) } }],
},
});
if (!image) return reply.rawFile(id);
@ -32,7 +32,7 @@ export async function uploadsRouteOnResponse(
const file = await this.prisma.file.findFirst({
where: {
OR: [{ name: id }, { invisible: { invis: decodeURI(id) } }],
OR: [{ name: id }, { invisible: { invis: decodeURI(encodeURI(id)) } }],
},
});

View file

@ -8,7 +8,7 @@ export default async function urlsRoute(this: FastifyInstance, req: FastifyReque
const url = await this.prisma.url.findFirst({
where: {
OR: [{ id }, { vanity: id }, { invisible: { invis: decodeURI(id) } }],
OR: [{ id }, { vanity: decodeURI(encodeURI(id)) }, { invisible: { invis: decodeURI(encodeURI(id)) } }],
},
});
if (!url) return reply.notFound();