fix: small bug & no file ext (#234)
* fix: allow empty file extensions * fix: Add a button to show non-media files * fix: Looks better * Update FilePagation.tsx Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com>
This commit is contained in:
parent
dcfcce7803
commit
f07cbeac52
2 changed files with 14 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { Box, Center, Checkbox, Group, Pagination, SimpleGrid, Skeleton, Title } from '@mantine/core';
|
import { Box, Button, Center, Checkbox, Group, Pagination, SimpleGrid, Skeleton, Title } from '@mantine/core';
|
||||||
import File from 'components/File';
|
import File from 'components/File';
|
||||||
import { FileIcon } from 'components/icons';
|
import { FileIcon } from 'components/icons';
|
||||||
import MutedText from 'components/MutedText';
|
import MutedText from 'components/MutedText';
|
||||||
|
@ -13,7 +13,7 @@ export default function FilePagation({ disableMediaPreview, exifEnabled }) {
|
||||||
|
|
||||||
if (pages.isSuccess && pages.data.length === 0) {
|
if (pages.isSuccess && pages.data.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Center>
|
<Center sx={{ flexDirection: 'column' }}>
|
||||||
<Group>
|
<Group>
|
||||||
<div>
|
<div>
|
||||||
<FileIcon size={48} />
|
<FileIcon size={48} />
|
||||||
|
@ -23,6 +23,14 @@ export default function FilePagation({ disableMediaPreview, exifEnabled }) {
|
||||||
<MutedText size='md'>Upload some files and they will show up here.</MutedText>
|
<MutedText size='md'>Upload some files and they will show up here.</MutedText>
|
||||||
</div>
|
</div>
|
||||||
</Group>
|
</Group>
|
||||||
|
<Box my='sm' hidden={checked}>
|
||||||
|
<MutedText size='md'>
|
||||||
|
There might be some non-media files, would you like to show them?
|
||||||
|
<Button mx='sm' compact type='button' onClick={() => setChecked(true)}>
|
||||||
|
Show
|
||||||
|
</Button>
|
||||||
|
</MutedText>
|
||||||
|
</Box>
|
||||||
</Center>
|
</Center>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
chunks.set(buffer, chunkData.start);
|
chunks.set(buffer, chunkData.start);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ext = filename.split('.').pop();
|
const ext = filename.split('.').length === 1 ? '' : filename.split('.').pop();
|
||||||
if (zconfig.uploader.disabled_extensions.includes(ext))
|
if (zconfig.uploader.disabled_extensions.includes(ext))
|
||||||
return res.error('disabled extension recieved: ' + ext);
|
return res.error('disabled extension recieved: ' + ext);
|
||||||
let fileName: string;
|
let fileName: string;
|
||||||
|
@ -149,7 +149,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
|
|
||||||
const file = await prisma.image.create({
|
const file = await prisma.image.create({
|
||||||
data: {
|
data: {
|
||||||
file: `${fileName}.${compressionUsed ? 'jpg' : ext}`,
|
file: `${fileName}${compressionUsed ? '.jpg' : ext ?? ''}`,
|
||||||
mimetype,
|
mimetype,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
embed: !!req.headers.embed,
|
embed: !!req.headers.embed,
|
||||||
|
@ -241,7 +241,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
return res.badRequest(`file[${i}]: size too big`);
|
return res.badRequest(`file[${i}]: size too big`);
|
||||||
if (!file.originalname) return res.badRequest(`file[${i}]: no filename`);
|
if (!file.originalname) return res.badRequest(`file[${i}]: no filename`);
|
||||||
|
|
||||||
const ext = file.originalname.split('.').pop();
|
const ext = file.originalname.split('.').length === 1 ? '' : file.originalname.split('.').pop();
|
||||||
if (zconfig.uploader.disabled_extensions.includes(ext))
|
if (zconfig.uploader.disabled_extensions.includes(ext))
|
||||||
return res.badRequest(`file[${i}]: disabled extension recieved: ${ext}`);
|
return res.badRequest(`file[${i}]: disabled extension recieved: ${ext}`);
|
||||||
let fileName: string;
|
let fileName: string;
|
||||||
|
@ -273,7 +273,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
let invis: InvisibleImage;
|
let invis: InvisibleImage;
|
||||||
const image = await prisma.image.create({
|
const image = await prisma.image.create({
|
||||||
data: {
|
data: {
|
||||||
file: `${fileName}.${compressionUsed ? 'jpg' : ext}`,
|
file: `${fileName}${compressionUsed ? '.jpg' : ext ?? ''}`,
|
||||||
mimetype: req.headers.uploadtext ? 'text/plain' : compressionUsed ? 'image/jpeg' : file.mimetype,
|
mimetype: req.headers.uploadtext ? 'text/plain' : compressionUsed ? 'image/jpeg' : file.mimetype,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
embed: !!req.headers.embed,
|
embed: !!req.headers.embed,
|
||||||
|
|
Loading…
Reference in a new issue