mirror of
https://github.com/diced/zipline.git
synced 2025-05-11 02:15:52 +02:00
fix: reload nextjs api route settings on saves
This commit is contained in:
parent
60e9b52100
commit
1801287deb
3 changed files with 27 additions and 0 deletions
|
@ -40,6 +40,7 @@ export function settingsOnSubmit(router: NextRouter, form: ReturnType<typeof use
|
||||||
});
|
});
|
||||||
|
|
||||||
await fetch('/reload');
|
await fetch('/reload');
|
||||||
|
await fetch('/api/reload');
|
||||||
mutate('/api/server/settings', data);
|
mutate('/api/server/settings', data);
|
||||||
router.replace(router.asPath, undefined, { scroll: false });
|
router.replace(router.asPath, undefined, { scroll: false });
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ export default function ImportButton() {
|
||||||
});
|
});
|
||||||
|
|
||||||
await fetch('/reload');
|
await fetch('/reload');
|
||||||
|
await fetch('/api/reload');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
25
src/pages/api/reload.ts
Normal file
25
src/pages/api/reload.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { reloadSettings } from '@/lib/config';
|
||||||
|
import { prisma } from '@/lib/db';
|
||||||
|
import { isAdministrator } from '@/lib/role';
|
||||||
|
import { getSession } from '@/server/session';
|
||||||
|
import { NextApiRequest, NextApiResponse } from 'next/types';
|
||||||
|
|
||||||
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
const session = await getSession(req, res);
|
||||||
|
if (!session.id || !session.sessionId) return res.redirect(302, '/auth/login');
|
||||||
|
|
||||||
|
const user = await prisma.user.findFirst({
|
||||||
|
where: {
|
||||||
|
sessions: {
|
||||||
|
has: session.sessionId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!user) return res.redirect(302, '/dashboard');
|
||||||
|
if (!isAdministrator(user.role)) return res.redirect(302, '/dashboard');
|
||||||
|
|
||||||
|
await reloadSettings();
|
||||||
|
|
||||||
|
return res.json({ success: true });
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue