mirror of
https://github.com/diced/zipline.git
synced 2025-05-11 10:26:05 +02:00
* - fix: use oauth's user id instead of username - feat: add login only config for oauth * Addresses tomato's concerns * fix: catch same account on different user * Add storage cleaning Co-authored-by: dicedtomato <diced@users.noreply.github.com> * Update src/components/pages/Manage/index.tsx Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com> * Update src/components/pages/Manage/index.tsx Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com> Co-authored-by: dicedtomato <diced@users.noreply.github.com> Co-authored-by: dicedtomato <35403473+diced@users.noreply.github.com>
30 lines
987 B
TypeScript
30 lines
987 B
TypeScript
import datasource from 'lib/datasource';
|
|
import Logger from 'lib/logger';
|
|
import prisma from 'lib/prisma';
|
|
import { NextApiReq, NextApiRes, UserExtended, withZipline } from 'middleware/withZipline';
|
|
|
|
const logger = Logger.get('admin');
|
|
|
|
async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
|
try {
|
|
const { count } = await prisma.image.deleteMany({});
|
|
logger.info(`User ${user.username} (${user.id}) cleared the database of ${count} images`);
|
|
|
|
if (req.body.datasource) {
|
|
await datasource.clear();
|
|
logger.info(`User ${user.username} (${user.id}) cleared storage`);
|
|
}
|
|
} catch (e) {
|
|
logger.error(`User ${user.username} (${user.id}) failed to clear the database or storage`);
|
|
logger.error(e);
|
|
return res.badRequest(`failed to clear the database or storage: ${e}`);
|
|
}
|
|
|
|
return res.json({ message: 'cleared storage' });
|
|
}
|
|
|
|
export default withZipline(handler, {
|
|
methods: ['POST'],
|
|
user: true,
|
|
administrator: true,
|
|
});
|