mirror of
https://github.com/diced/zipline.git
synced 2025-04-11 23:31:17 -05:00
notFix: Removed the option to only clear db. It'd be a dangerous thing to continue allowing it.
This commit is contained in:
parent
478baeca83
commit
e5124c07da
2 changed files with 14 additions and 20 deletions
|
@ -7,7 +7,7 @@ import { useState } from 'react';
|
|||
|
||||
export default function ClearStorage({ open, setOpen }) {
|
||||
const [check, setCheck] = useState(false);
|
||||
const handleDelete = async (datasource: boolean, orphaned?: boolean) => {
|
||||
const handleDelete = async (orphaned?: boolean) => {
|
||||
showNotification({
|
||||
id: 'clear-uploads',
|
||||
title: 'Clearing...',
|
||||
|
@ -16,7 +16,7 @@ export default function ClearStorage({ open, setOpen }) {
|
|||
autoClose: false,
|
||||
});
|
||||
|
||||
const res = await useFetch('/api/admin/clear', 'POST', { datasource, orphaned });
|
||||
const res = await useFetch('/api/admin/clear', 'POST', { orphaned });
|
||||
|
||||
if (res.error) {
|
||||
updateNotification({
|
||||
|
@ -65,21 +65,13 @@ export default function ClearStorage({ open, setOpen }) {
|
|||
onClick={() => {
|
||||
setOpen(false);
|
||||
openConfirmModal({
|
||||
title: 'Do you want to clear storage too?',
|
||||
labels: { confirm: 'Yes', cancel: check ? 'Ok' : 'No' },
|
||||
children: check && (
|
||||
<Text size='sm' color='gray'>
|
||||
Due to clearing orphaned files, storage clearing will be unavailable.
|
||||
</Text>
|
||||
),
|
||||
confirmProps: { disabled: check },
|
||||
title: 'Are you sure?',
|
||||
confirmProps: { color: 'red' },
|
||||
children: <Text size='sm'>This action is destructive and irreversible.</Text>,
|
||||
labels: { confirm: 'Yes', cancel: 'No' },
|
||||
onConfirm: () => {
|
||||
closeAllModals();
|
||||
handleDelete(true);
|
||||
},
|
||||
onCancel: () => {
|
||||
closeAllModals();
|
||||
handleDelete(false, check);
|
||||
handleDelete(check);
|
||||
},
|
||||
onClose: () => setCheck(false),
|
||||
});
|
||||
|
|
|
@ -8,21 +8,23 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
|||
try {
|
||||
const { orphaned } = req.body;
|
||||
if (orphaned) {
|
||||
const files = await prisma.file.findMany({
|
||||
where: {
|
||||
userId: null,
|
||||
},
|
||||
});
|
||||
const { count } = await prisma.file.deleteMany({
|
||||
where: {
|
||||
userId: null,
|
||||
},
|
||||
});
|
||||
for (const file of files) await datasource.delete(file.name);
|
||||
logger.info(`User ${user.username} (${user.id}) cleared the database of ${count} orphaned files`);
|
||||
return res.json({ message: 'cleared storage (orphaned only)' });
|
||||
}
|
||||
const { count } = await prisma.file.deleteMany({});
|
||||
await datasource.clear();
|
||||
logger.info(`User ${user.username} (${user.id}) cleared the database of ${count} files`);
|
||||
|
||||
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue