fix: add comma dangles

This commit is contained in:
diced 2021-09-25 09:39:51 -07:00
parent 9e4152e298
commit 212c69d303
No known key found for this signature in database
GPG key ID: 85AB64C74535D76E
32 changed files with 152 additions and 137 deletions

View file

@ -45,7 +45,7 @@
"@types/multer": "^1.4.6", "@types/multer": "^1.4.6",
"@types/node": "^15.12.2", "@types/node": "^15.12.2",
"babel-plugin-transform-imports": "^2.0.0", "babel-plugin-transform-imports": "^2.0.0",
"eslint": "7.28.0", "eslint": "^7.32.0",
"eslint-config-next": "11.0.0", "eslint-config-next": "11.0.0",
"husky": "^6.0.0", "husky": "^6.0.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",

View file

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { import {
Backdrop as MuiBackdrop, Backdrop as MuiBackdrop,
CircularProgress CircularProgress,
} from '@material-ui/core'; } from '@material-ui/core';
export default function Backdrop({ open }) { export default function Backdrop({ open }) {

View file

@ -2,7 +2,7 @@ import React from 'react';
import { import {
Card as MuiCard, Card as MuiCard,
CardContent, CardContent,
Typography Typography,
} from '@material-ui/core'; } from '@material-ui/core';
export default function Card(props) { export default function Card(props) {

View file

@ -8,7 +8,7 @@ import {
Dialog, Dialog,
DialogTitle, DialogTitle,
DialogActions, DialogActions,
DialogContent DialogContent,
} from '@material-ui/core'; } from '@material-ui/core';
import AudioIcon from '@material-ui/icons/Audiotrack'; import AudioIcon from '@material-ui/icons/Audiotrack';
import copy from 'copy-to-clipboard'; import copy from 'copy-to-clipboard';
@ -16,7 +16,7 @@ import useFetch from 'hooks/useFetch';
export default function Image({ image, updateImages }) { export default function Image({ image, updateImages }) {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [t,] = useState(image.mimetype.split('/')[0]); const [t] = useState(image.mimetype.split('/')[0]);
const handleDelete = async () => { const handleDelete = async () => {
const res = await useFetch('/api/user/files', 'DELETE', { id: image.id }); const res = await useFetch('/api/user/files', 'DELETE', { id: image.id });
@ -40,7 +40,7 @@ export default function Image({ image, updateImages }) {
'video': <video controls {...props} />, 'video': <video controls {...props} />,
// eslint-disable-next-line jsx-a11y/alt-text // eslint-disable-next-line jsx-a11y/alt-text
'image': <img {...props} />, 'image': <img {...props} />,
'audio': <audio controls {...props} /> 'audio': <audio controls {...props} />,
}[t]; }[t];
}; };

View file

@ -48,18 +48,18 @@ const items = [
{ {
icon: <HomeIcon />, icon: <HomeIcon />,
text: 'Home', text: 'Home',
link: '/dashboard' link: '/dashboard',
}, },
{ {
icon: <FolderIcon />, icon: <FolderIcon />,
text: 'Files', text: 'Files',
link: '/dashboard/files' link: '/dashboard/files',
}, },
{ {
icon: <UploadIcon />, icon: <UploadIcon />,
text: 'Upload', text: 'Upload',
link: '/dashboard/upload' link: '/dashboard/upload',
} },
]; ];
const drawerWidth = 240; const drawerWidth = 240;
@ -153,7 +153,7 @@ export default function Layout({ children, user, loading, noPaper }) {
const handleUpdateTheme = async (event: React.ChangeEvent<{ value: string }>) => { const handleUpdateTheme = async (event: React.ChangeEvent<{ value: string }>) => {
const newUser = await useFetch('/api/user', 'PATCH', { const newUser = await useFetch('/api/user', 'PATCH', {
systemTheme: event.target.value || 'dark_blue' systemTheme: event.target.value || 'dark_blue',
}); });
setSystemTheme(newUser.systemTheme); setSystemTheme(newUser.systemTheme);
@ -168,7 +168,7 @@ export default function Layout({ children, user, loading, noPaper }) {
<ResetTokenDialog open={resetOpen} setOpen={setResetOpen} setToken={setToken} /> <ResetTokenDialog open={resetOpen} setOpen={setResetOpen} setToken={setToken} />
<Toolbar <Toolbar
sx={{ sx={{
width: { xs: drawerWidth } width: { xs: drawerWidth },
}} }}
> >
<AppBar <AppBar
@ -177,7 +177,7 @@ export default function Layout({ children, user, loading, noPaper }) {
sx={{ sx={{
borderBottom: 1, borderBottom: 1,
borderBottomColor: t => t.palette.divider, borderBottomColor: t => t.palette.divider,
display: { xs: 'none', sm: 'block' } display: { xs: 'none', sm: 'block' },
}} }}
> >
<Toolbar> <Toolbar>
@ -293,7 +293,7 @@ export default function Layout({ children, user, loading, noPaper }) {
elevation={0} elevation={0}
sx={{ sx={{
width: { sm: `calc(100% - ${drawerWidth}px)` }, width: { sm: `calc(100% - ${drawerWidth}px)` },
ml: { sm: `${drawerWidth}px` } ml: { sm: `${drawerWidth}px` },
}} }}
> >
<Toolbar> <Toolbar>
@ -363,7 +363,7 @@ export default function Layout({ children, user, loading, noPaper }) {
component='nav' component='nav'
sx={{ sx={{
width: { sm: drawerWidth }, width: { sm: drawerWidth },
flexShrink: { sm: 0 } flexShrink: { sm: 0 },
}} }}
> >
<Drawer <Drawer
@ -373,11 +373,11 @@ export default function Layout({ children, user, loading, noPaper }) {
open={mobileOpen} open={mobileOpen}
elevation={0} elevation={0}
ModalProps={{ ModalProps={{
keepMounted: true keepMounted: true,
}} }}
sx={{ sx={{
display: { xs: 'block', sm: 'none' }, display: { xs: 'block', sm: 'none' },
'* .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth } '* .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
}} }}
> >
{drawer} {drawer}
@ -386,7 +386,7 @@ export default function Layout({ children, user, loading, noPaper }) {
variant='permanent' variant='permanent'
sx={{ sx={{
display: { xs: 'none', sm: 'block' }, display: { xs: 'none', sm: 'block' },
'* .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth } '* .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
}} }}
open open
> >

View file

@ -23,7 +23,7 @@ export const themes = {
'ayu_light': ayu_light, 'ayu_light': ayu_light,
'nord': nord, 'nord': nord,
'polar': polar, 'polar': polar,
'dracula': dracula 'dracula': dracula,
}; };
export const friendlyThemeName = { export const friendlyThemeName = {
@ -34,7 +34,7 @@ export const friendlyThemeName = {
'ayu_light': 'Ayu Light', 'ayu_light': 'Ayu Light',
'nord': 'Nord', 'nord': 'Nord',
'polar': 'Polar', 'polar': 'Polar',
'dracula': 'Dracula' 'dracula': 'Dracula',
}; };
export default function ZiplineTheming({ Component, pageProps }) { export default function ZiplineTheming({ Component, pageProps }) {
@ -54,8 +54,8 @@ export default function ZiplineTheming({ Component, pageProps }) {
border: user.customTheme.border, border: user.customTheme.border,
background: { background: {
main: user.customTheme.mainBackground, main: user.customTheme.mainBackground,
paper: user.customTheme.paperBackground paper: user.customTheme.paperBackground,
} },
}); });
} else { } else {
t = themes[user.systemTheme] ?? themes.dark_blue; t = themes[user.systemTheme] ?? themes.dark_blue;

View file

@ -14,7 +14,7 @@ import {
Skeleton, Skeleton,
CardActionArea, CardActionArea,
CardMedia, CardMedia,
Card as MuiCard Card as MuiCard,
} from '@material-ui/core'; } from '@material-ui/core';
import AudioIcon from '@material-ui/icons/Audiotrack'; import AudioIcon from '@material-ui/icons/Audiotrack';
@ -48,7 +48,7 @@ const columns = [
minWidth: 170, minWidth: 170,
align: 'right' as Aligns, align: 'right' as Aligns,
format: (value) => new Date(value).toLocaleString(), format: (value) => new Date(value).toLocaleString(),
} },
]; ];
function StatText({ children }) { function StatText({ children }) {
@ -229,7 +229,7 @@ export default function Dashboard() {
<StatTable <StatTable
columns={[ columns={[
{ id: 'username', name: 'Name' }, { id: 'username', name: 'Name' },
{ id: 'count', name: 'Images' } { id: 'count', name: 'Images' },
]} ]}
rows={stats ? stats.count_by_user : []} /> rows={stats ? stats.count_by_user : []} />
</Card> </Card>
@ -237,7 +237,7 @@ export default function Dashboard() {
<StatTable <StatTable
columns={[ columns={[
{ id: 'mimetype', name: 'Type' }, { id: 'mimetype', name: 'Type' },
{ id: 'count', name: 'Count' } { id: 'count', name: 'Count' },
]} ]}
rows={stats ? stats.types_count : []} /> rows={stats ? stats.types_count : []} />
</Card> </Card>

View file

@ -14,7 +14,7 @@ import { useRouter } from 'next/router';
const validationSchema = yup.object({ const validationSchema = yup.object({
username: yup username: yup
.string() .string()
.required('Username is required') .required('Username is required'),
}); });
const themeValidationSchema = yup.object({ const themeValidationSchema = yup.object({
@ -94,11 +94,11 @@ export default function Manage() {
Headers: { Headers: {
Authorization: user?.token, Authorization: user?.token,
...(withEmbed && {Embed: 'true'}), ...(withEmbed && {Embed: 'true'}),
...(withZws && {ZWS: 'true'}) ...(withZws && {ZWS: 'true'}),
}, },
URL: '$json:url$', URL: '$json:url$',
Body: 'MultipartFormData', Body: 'MultipartFormData',
FileFormName: 'file' FileFormName: 'file',
}; };
const pseudoElement = document.createElement('a'); const pseudoElement = document.createElement('a');
@ -115,7 +115,7 @@ export default function Manage() {
username: user.username, username: user.username,
password: '', password: '',
embedTitle: user.embedTitle ?? '', embedTitle: user.embedTitle ?? '',
embedColor: user.embedColor embedColor: user.embedColor,
}, },
validationSchema, validationSchema,
onSubmit: async values => { onSubmit: async values => {
@ -132,7 +132,7 @@ export default function Manage() {
username: cleanUsername, username: cleanUsername,
password: cleanPassword === '' ? null : cleanPassword, password: cleanPassword === '' ? null : cleanPassword,
embedTitle: cleanEmbedTitle === '' ? null : cleanEmbedTitle, embedTitle: cleanEmbedTitle === '' ? null : cleanEmbedTitle,
embedColor: cleanEmbedColor === '' ? null : cleanEmbedColor embedColor: cleanEmbedColor === '' ? null : cleanEmbedColor,
}; };
const newUser = await useFetch('/api/user', 'PATCH', data); const newUser = await useFetch('/api/user', 'PATCH', data);
@ -149,7 +149,7 @@ export default function Manage() {
setSeverity('success'); setSeverity('success');
setOpen(true); setOpen(true);
} }
} },
}); });
const customThemeFormik = useFormik({ const customThemeFormik = useFormik({
@ -182,7 +182,7 @@ export default function Manage() {
setSeverity('success'); setSeverity('success');
setOpen(true); setOpen(true);
} }
} },
}); });
return ( return (

View file

@ -28,9 +28,9 @@ export default function Upload({ route }) {
const res = await fetch('/api/upload', { const res = await fetch('/api/upload', {
method: 'POST', method: 'POST',
headers: { headers: {
'Authorization': user.token 'Authorization': user.token,
}, },
body body,
}); });
const json = await res.json(); const json = await res.json();
if (res.ok && json.error === undefined) { if (res.ok && json.error === undefined) {
@ -65,7 +65,7 @@ export default function Upload({ route }) {
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
display: 'block', display: 'block',
p: 5 p: 5,
}} }}
{...getRootProps()} {...getRootProps()}
> >

View file

@ -13,7 +13,7 @@ import {
Button, Button,
TextField, TextField,
Switch, Switch,
FormControlLabel FormControlLabel,
} from '@material-ui/core'; } from '@material-ui/core';
import { Delete as DeleteIcon, Add as AddIcon } from '@material-ui/icons'; import { Delete as DeleteIcon, Add as AddIcon } from '@material-ui/icons';
@ -59,7 +59,7 @@ function CreateUserDialog({ open, setOpen, updateUsers, setSeverity, setMessage,
initialValues: { initialValues: {
username: '', username: '',
password: '', password: '',
administrator: false administrator: false,
}, },
onSubmit: async (values) => { onSubmit: async (values) => {
const cleanUsername = values.username.trim(); const cleanUsername = values.username.trim();
@ -70,7 +70,7 @@ function CreateUserDialog({ open, setOpen, updateUsers, setSeverity, setMessage,
const data = { const data = {
username: cleanUsername, username: cleanUsername,
password: cleanPassword, password: cleanPassword,
administrator: values.administrator administrator: values.administrator,
}; };
setOpen(false); setOpen(false);
@ -87,7 +87,7 @@ function CreateUserDialog({ open, setOpen, updateUsers, setSeverity, setMessage,
updateUsers(); updateUsers();
} }
setLoading(false); setLoading(false);
} },
}); });
return ( return (
@ -96,7 +96,7 @@ function CreateUserDialog({ open, setOpen, updateUsers, setSeverity, setMessage,
open={open} open={open}
onClose={() => setOpen(false)} onClose={() => setOpen(false)}
PaperProps={{ PaperProps={{
elevation: 1 elevation: 1,
}} }}
> >
<DialogTitle> <DialogTitle>
@ -151,7 +151,7 @@ export default function Users() {
const handleDelete = async (user) => { const handleDelete = async (user) => {
const res = await useFetch('/api/users', 'DELETE', { const res = await useFetch('/api/users', 'DELETE', {
id: user.id id: user.id,
}); });
if (res.error) { if (res.error) {
setMessage(`Could not delete ${user.username}`); setMessage(`Could not delete ${user.username}`);

View file

@ -5,7 +5,7 @@ export default async function useFetch(url: string, method: 'GET' | 'POST' | 'PA
const res = await global.fetch(url, { const res = await global.fetch(url, {
body: body ? JSON.stringify(body) : null, body: body ? JSON.stringify(body) : null,
method, method,
headers headers,
}); });
return res.json(); return res.json();

View file

@ -45,7 +45,7 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
res.error = (message: string) => { res.error = (message: string) => {
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.json({ res.json({
error: message error: message,
}); });
}; };
@ -53,7 +53,7 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.status(403); res.status(403);
res.json({ res.json({
error: '403: ' + message error: '403: ' + message,
}); });
}; };
@ -61,7 +61,7 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
res.setHeader('Content-Type', 'application/json'); res.setHeader('Content-Type', 'application/json');
res.status(401); res.status(401);
res.json({ res.json({
error: '403: ' + message error: '403: ' + message,
}); });
}; };
@ -82,7 +82,7 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
res.setHeader('Set-Cookie', serialize(name, '', { res.setHeader('Set-Cookie', serialize(name, '', {
path: '/', path: '/',
expires: new Date(1), expires: new Date(1),
maxAge: undefined maxAge: undefined,
})); }));
}; };
req.user = async () => { req.user = async () => {
@ -92,7 +92,7 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
const user = await prisma.user.findFirst({ const user = await prisma.user.findFirst({
where: { where: {
id: Number(userId) id: Number(userId),
}, },
select: { select: {
administrator: true, administrator: true,
@ -103,8 +103,8 @@ export const withZipline = (handler: (req: NextApiRequest, res: NextApiResponse)
systemTheme: true, systemTheme: true,
customTheme: true, customTheme: true,
token: true, token: true,
username: true username: true,
} },
}); });
if (!user) return null; if (!user) return null;

View file

@ -12,6 +12,6 @@ export default createTheme({
border: '#191e29', border: '#191e29',
background: { background: {
main: '#0A0E14', main: '#0A0E14',
paper: '#0D1016' paper: '#0D1016',
} },
}); });

View file

@ -12,6 +12,6 @@ export default createTheme({
border: '#e3e3e3', border: '#e3e3e3',
background: { background: {
main: '#FAFAFA', main: '#FAFAFA',
paper: '#FFFFFF' paper: '#FFFFFF',
} },
}); });

View file

@ -12,6 +12,6 @@ export default createTheme({
border: '#363c4d', border: '#363c4d',
background: { background: {
main: '#1F2430', main: '#1F2430',
paper: '#232834' paper: '#232834',
} },
}); });

View file

@ -10,6 +10,6 @@ export default createTheme({
border: '#2b2b2b', border: '#2b2b2b',
background: { background: {
main: '#000000', main: '#000000',
paper: '#060606' paper: '#060606',
} },
}); });

View file

@ -10,6 +10,6 @@ export default createTheme({
border: '#1b2541', border: '#1b2541',
background: { background: {
main: '#05070f', main: '#05070f',
paper: '#0c101c' paper: '#0c101c',
} },
}); });

View file

@ -12,6 +12,6 @@ export default createTheme({
border: '#7D8096', border: '#7D8096',
background: { background: {
main: '#282A36', main: '#282A36',
paper: '#44475A' paper: '#44475A',
} },
}); });

View file

@ -45,9 +45,9 @@ export default function createTheme(o: ThemeOptions) {
MuiTableHead: { MuiTableHead: {
styleOverrides: { styleOverrides: {
root: { root: {
backgroundColor: o.border backgroundColor: o.border,
} },
} },
}, },
}, },
}); });

View file

@ -12,6 +12,6 @@ export default createTheme({
border: '#565e70', border: '#565e70',
background: { background: {
main: '#2E3440', main: '#2E3440',
paper: '#3B4252' paper: '#3B4252',
} },
}); });

View file

@ -12,6 +12,6 @@ export default createTheme({
border: '#989fab', border: '#989fab',
background: { background: {
main: '#D8DEE9', main: '#D8DEE9',
paper: '#E5E9F0' paper: '#E5E9F0',
} },
}); });

View file

@ -17,8 +17,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const existing = await prisma.user.findFirst({ const existing = await prisma.user.findFirst({
where: { where: {
username username,
} },
}); });
if (existing) return res.forbid('user exists'); if (existing) return res.forbid('user exists');
@ -29,8 +29,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
password: hashed, password: hashed,
username, username,
token: createToken(), token: createToken(),
administrator administrator,
} },
}); });
delete newUser.password; delete newUser.password;

View file

@ -15,16 +15,16 @@ async function handler(req: NextApiReq, res: NextApiRes) {
username: 'administrator', username: 'administrator',
password: await hashPassword('password'), password: await hashPassword('password'),
token: createToken(), token: createToken(),
administrator: true administrator: true,
} },
}); });
Logger.get('database').info('created default user:\nUsername: "administrator"\nPassword: "password"'); Logger.get('database').info('created default user:\nUsername: "administrator"\nPassword: "password"');
} }
const user = await prisma.user.findFirst({ const user = await prisma.user.findFirst({
where: { where: {
username username,
} },
}); });
if (!user) return res.status(404).end(JSON.stringify({ error: 'User not found' })); if (!user) return res.status(404).end(JSON.stringify({ error: 'User not found' }));

View file

@ -12,8 +12,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const byUser = await prisma.image.groupBy({ const byUser = await prisma.image.groupBy({
by: ['userId'], by: ['userId'],
_count: { _count: {
_all: true _all: true,
} },
}); });
const count_users = await prisma.user.count(); const count_users = await prisma.user.count();
@ -21,13 +21,13 @@ async function handler(req: NextApiReq, res: NextApiRes) {
for (let i = 0, L = byUser.length; i !== L; ++i) { for (let i = 0, L = byUser.length; i !== L; ++i) {
const user = await prisma.user.findFirst({ const user = await prisma.user.findFirst({
where: { where: {
id: byUser[i].userId id: byUser[i].userId,
} },
}); });
count_by_user.push({ count_by_user.push({
username: user.username, username: user.username,
count: byUser[i]._count._all count: byUser[i]._count._all,
}); });
} }
@ -35,14 +35,14 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const viewsCount = await prisma.image.groupBy({ const viewsCount = await prisma.image.groupBy({
by: ['views'], by: ['views'],
_sum: { _sum: {
views: true views: true,
} },
}); });
const typesCount = await prisma.image.groupBy({ const typesCount = await prisma.image.groupBy({
by: ['mimetype'], by: ['mimetype'],
_count: { _count: {
mimetype: true mimetype: true,
}, },
}); });
const types_count = []; const types_count = [];
@ -55,7 +55,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
count_by_user: count_by_user.sort((a,b) => b.count-a.count), count_by_user: count_by_user.sort((a,b) => b.count-a.count),
count_users, count_users,
views_count: (viewsCount[0]?._sum?.views ?? 0), views_count: (viewsCount[0]?._sum?.views ?? 0),
types_count: types_count.sort((a,b) => b.count-a.count) types_count: types_count.sort((a,b) => b.count-a.count),
}); });
} }

View file

@ -17,8 +17,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const user = await prisma.user.findFirst({ const user = await prisma.user.findFirst({
where: { where: {
token: req.headers.authorization token: req.headers.authorization,
} },
}); });
@ -42,8 +42,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
file: `${rand}.${ext}`, file: `${rand}.${ext}`,
mimetype: file.mimetype, mimetype: file.mimetype,
userId: user.id, userId: user.id,
embed: !!req.headers.embed embed: !!req.headers.embed,
} },
}); });
if (req.headers.zws) invis = await createInvisImage(zconfig.uploader.length, image.id); if (req.headers.zws) invis = await createInvisImage(zconfig.uploader.length, image.id);

View file

@ -15,8 +15,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const image = await prisma.image.delete({ const image = await prisma.image.delete({
where: { where: {
id: req.body.id id: req.body.id,
} },
}); });
await rm(join(process.cwd(), config.uploader.directory, image.file)); await rm(join(process.cwd(), config.uploader.directory, image.file));
@ -32,8 +32,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
if (req.body.favorite !== null) image = await prisma.image.update({ if (req.body.favorite !== null) image = await prisma.image.update({
where: { id: req.body.id }, where: { id: req.body.id },
data: { data: {
favorite: req.body.favorite favorite: req.body.favorite,
} },
}); });
return res.json(image); return res.json(image);
@ -41,15 +41,15 @@ async function handler(req: NextApiReq, res: NextApiRes) {
let images = await prisma.image.findMany({ let images = await prisma.image.findMany({
where: { where: {
userId: user.id, userId: user.id,
favorite: !!req.query.favorite favorite: !!req.query.favorite,
}, },
select: { select: {
created_at: true, created_at: true,
file: true, file: true,
mimetype: true, mimetype: true,
id: true, id: true,
favorite: true favorite: true,
} },
}); });

View file

@ -12,38 +12,38 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const hashed = await hashPassword(req.body.password); const hashed = await hashPassword(req.body.password);
await prisma.user.update({ await prisma.user.update({
where: { id: user.id }, where: { id: user.id },
data: { password: hashed } data: { password: hashed },
}); });
} }
if (req.body.username) { if (req.body.username) {
const existing = await prisma.user.findFirst({ const existing = await prisma.user.findFirst({
where: { where: {
username: req.body.username username: req.body.username,
} },
}); });
if (existing && user.username !== req.body.username) { if (existing && user.username !== req.body.username) {
return res.forbid('Username is already taken'); return res.forbid('Username is already taken');
} }
await prisma.user.update({ await prisma.user.update({
where: { id: user.id }, where: { id: user.id },
data: { username: req.body.username } data: { username: req.body.username },
}); });
} }
if (req.body.embedTitle) await prisma.user.update({ if (req.body.embedTitle) await prisma.user.update({
where: { id: user.id }, where: { id: user.id },
data: { embedTitle: req.body.embedTitle } data: { embedTitle: req.body.embedTitle },
}); });
if (req.body.embedColor) await prisma.user.update({ if (req.body.embedColor) await prisma.user.update({
where: { id: user.id }, where: { id: user.id },
data: { embedColor: req.body.embedColor } data: { embedColor: req.body.embedColor },
}); });
if (req.body.systemTheme) await prisma.user.update({ if (req.body.systemTheme) await prisma.user.update({
where: { id: user.id }, where: { id: user.id },
data: { systemTheme: req.body.systemTheme } data: { systemTheme: req.body.systemTheme },
}); });
if (req.body.customTheme) { if (req.body.customTheme) {
@ -52,21 +52,21 @@ async function handler(req: NextApiReq, res: NextApiRes) {
data: { data: {
customTheme: { customTheme: {
update: { update: {
...req.body.customTheme ...req.body.customTheme,
} },
} },
} },
}); else await prisma.theme.create({ }); else await prisma.theme.create({
data: { data: {
userId: user.id, userId: user.id,
...req.body.customTheme ...req.body.customTheme,
} },
}); });
} }
const newUser = await prisma.user.findFirst({ const newUser = await prisma.user.findFirst({
where: { where: {
id: Number(user.id) id: Number(user.id),
}, },
select: { select: {
administrator: true, administrator: true,
@ -78,8 +78,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
systemTheme: true, systemTheme: true,
customTheme: true, customTheme: true,
token: true, token: true,
username: true username: true,
} },
}); });
Logger.get('user').info(`User ${user.username} (${newUser.username}) (${newUser.id}) was updated`); Logger.get('user').info(`User ${user.username} (${newUser.username}) (${newUser.id}) was updated`);

View file

@ -15,13 +15,13 @@ async function handler(req: NextApiReq, res: NextApiRes) {
userId: user.id, userId: user.id,
}, },
orderBy: { orderBy: {
created_at: 'desc' created_at: 'desc',
}, },
select: { select: {
created_at: true, created_at: true,
file: true, file: true,
mimetype: true mimetype: true,
} },
}); });
// @ts-ignore // @ts-ignore

View file

@ -10,11 +10,11 @@ async function handler(req: NextApiReq, res: NextApiRes) {
if (req.method === 'PATCH') { if (req.method === 'PATCH') {
const updated = await prisma.user.update({ const updated = await prisma.user.update({
where: { where: {
id: user.id id: user.id,
}, },
data: { data: {
token: createToken() token: createToken(),
} },
}); });
Logger.get('user').info(`User ${user.username} (${user.id}) reset their token`); Logger.get('user').info(`User ${user.username} (${user.id}) reset their token`);

View file

@ -14,15 +14,15 @@ async function handler(req: NextApiReq, res: NextApiRes) {
const deleteUser = await prisma.user.findFirst({ const deleteUser = await prisma.user.findFirst({
where: { where: {
id: req.body.id id: req.body.id,
} },
}); });
if (!deleteUser) return res.forbid('user doesn\'t exist'); if (!deleteUser) return res.forbid('user doesn\'t exist');
await prisma.user.delete({ await prisma.user.delete({
where: { where: {
id: deleteUser.id id: deleteUser.id,
} },
}); });
delete deleteUser.password; delete deleteUser.password;
@ -37,8 +37,8 @@ async function handler(req: NextApiReq, res: NextApiRes) {
embedColor: true, embedColor: true,
embedTitle: true, embedTitle: true,
customTheme: true, customTheme: true,
systemTheme: true systemTheme: true,
} },
}); });
return res.json(users); return res.json(users);
} }

View file

@ -37,7 +37,7 @@ export default function Login() {
const formik = useFormik({ const formik = useFormik({
initialValues: { initialValues: {
username: '', username: '',
password: '' password: '',
}, },
onSubmit: async values => { onSubmit: async values => {
const username = values.username.trim(); const username = values.username.trim();
@ -47,7 +47,7 @@ export default function Login() {
setLoadingOpen(true); setLoadingOpen(true);
const res = await useFetch('/api/auth/login', 'POST', { const res = await useFetch('/api/auth/login', 'POST', {
username, password username, password,
}); });
if (res.error) { if (res.error) {
@ -61,7 +61,7 @@ export default function Login() {
setMessage('Logged in'); setMessage('Logged in');
router.push('/dashboard'); router.push('/dashboard');
} }
} },
}); });
useEffect(() => { useEffect(() => {

View file

@ -323,10 +323,10 @@
resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz#8eed982e2ee6f7f4e44c253e12962980791efd46" resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz#8eed982e2ee6f7f4e44c253e12962980791efd46"
integrity sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA== integrity sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==
"@eslint/eslintrc@^0.4.2": "@eslint/eslintrc@^0.4.3":
version "0.4.2" version "0.4.3"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.2.tgz#f63d0ef06f5c0c57d76c4ab5f63d3835c51b0179" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.3.tgz#9e42981ef035beb3dd49add17acb96e8ff6f394c"
integrity sha512-8nmGq/4ycLpIwzvhI4tNDmQztZ8sp+hI7cyG8i1nQDhkAbRzHpXPidRAHlNvCZQpJTKw5ItIpMw9RSToGF00mg== integrity sha512-J6KFFz5QCYUJq3pf0mjEcCJVERbzv71PUIDczuh9JkwGEzced6CO5ADLHB1rbf/+oPBtoPfMYNOpGDzCANlbXw==
dependencies: dependencies:
ajv "^6.12.4" ajv "^6.12.4"
debug "^4.1.1" debug "^4.1.1"
@ -358,6 +358,20 @@
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.2.0.tgz#f3933a44e365864f4dad5db94158106d511e8131" resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.2.0.tgz#f3933a44e365864f4dad5db94158106d511e8131"
integrity sha512-sqKVVVOe5ivCaXDWivIJYVSaEgdQK9ul7a4Kity5Iw7u9+wBAPbX1RMSnLLmp7O4Vzj0WOWwMAJsTL00xwaNug== integrity sha512-sqKVVVOe5ivCaXDWivIJYVSaEgdQK9ul7a4Kity5Iw7u9+wBAPbX1RMSnLLmp7O4Vzj0WOWwMAJsTL00xwaNug==
"@humanwhocodes/config-array@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.5.0.tgz#1407967d4c6eecd7388f83acf1eaf4d0c6e58ef9"
integrity sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==
dependencies:
"@humanwhocodes/object-schema" "^1.2.0"
debug "^4.1.1"
minimatch "^3.0.4"
"@humanwhocodes/object-schema@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.0.tgz#87de7af9c231826fdd68ac7258f77c429e0e5fcf"
integrity sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==
"@iarna/toml@2.2.5": "@iarna/toml@2.2.5":
version "2.2.5" version "2.2.5"
resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c" resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c"
@ -2245,13 +2259,14 @@ eslint-visitor-keys@^2.0.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw== integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
eslint@7.28.0: eslint@^7.32.0:
version "7.28.0" version "7.32.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.28.0.tgz#435aa17a0b82c13bb2be9d51408b617e49c1e820" resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.32.0.tgz#c6d328a14be3fb08c8d1d21e12c02fdb7a2a812d"
integrity sha512-UMfH0VSjP0G4p3EWirscJEQ/cHqnT/iuH6oNZOB94nBjWbMnhGEPxsZm1eyIW0C/9jLI0Fow4W5DXLjEI7mn1g== integrity sha512-VHZ8gX+EDfz+97jGcgyGCyRia/dPOd6Xh9yPv8Bl1+SoaIwD+a/vlrOmGRUyOYu7MwUhc7CxqeaDZU13S4+EpA==
dependencies: dependencies:
"@babel/code-frame" "7.12.11" "@babel/code-frame" "7.12.11"
"@eslint/eslintrc" "^0.4.2" "@eslint/eslintrc" "^0.4.3"
"@humanwhocodes/config-array" "^0.5.0"
ajv "^6.10.0" ajv "^6.10.0"
chalk "^4.0.0" chalk "^4.0.0"
cross-spawn "^7.0.2" cross-spawn "^7.0.2"