fix: stuff (#423)

* fix: copying and opening another user's upload url

* fix: delete thumbnails too

* fix: return target after removing files from output

* fix: add width to fix diced/zipline#419 (can't test)

* Minor script tune-ups.

* Remove the catcher for when upload has been offloaded to chunk
This commit is contained in:
Jayvin Hernandez 2023-06-18 19:28:20 -07:00 committed by GitHub
parent a1bc2db336
commit 226d946ec8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 60 additions and 9 deletions

View file

@ -349,7 +349,11 @@ export default function Layout({ children, props }) {
<Menu.Target> <Menu.Target>
<Button <Button
leftIcon={ leftIcon={
avatar ? <Image src={avatar} height={32} radius='md' /> : <IconUserCog size='1rem' /> avatar ? (
<Image src={avatar} height={32} width={32} fit='cover' radius='md' />
) : (
<IconUserCog size='1rem' />
)
} }
variant='subtle' variant='subtle'
color='gray' color='gray'

View file

@ -122,6 +122,8 @@ export default function File({ chunks: chunks_config }) {
}); });
if (j === chunks.length - 1) { if (j === chunks.length - 1) {
window.removeEventListener('beforeunload', beforeUnload);
router.events.off('routeChangeStart', beforeRouteChange);
updateNotification({ updateNotification({
id: 'upload-chunked', id: 'upload-chunked',
title: 'Finalizing partial upload', title: 'Finalizing partial upload',

View file

@ -3,6 +3,8 @@ import Logger from 'lib/logger';
import prisma from 'lib/prisma'; import prisma from 'lib/prisma';
import { hashPassword } from 'lib/util'; import { hashPassword } from 'lib/util';
import { jsonUserReplacer } from 'lib/utils/client'; import { jsonUserReplacer } from 'lib/utils/client';
import { formatRootUrl } from 'lib/utils/urls';
import zconfig from 'lib/config';
import { NextApiReq, NextApiRes, UserExtended, withZipline } from 'middleware/withZipline'; import { NextApiReq, NextApiRes, UserExtended, withZipline } from 'middleware/withZipline';
const logger = Logger.get('user'); const logger = Logger.get('user');
@ -15,7 +17,11 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
id: Number(id), id: Number(id),
}, },
include: { include: {
files: true, files: {
include: {
thumbnail: true,
},
},
Folder: true, Folder: true,
}, },
}); });
@ -179,9 +185,21 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
} else { } else {
delete target.password; delete target.password;
if (user.superAdmin && target.superAdmin) delete target.files; if (user.superAdmin && target.superAdmin) {
if (user.administrator && !user.superAdmin && (target.administrator || target.superAdmin))
delete target.files; delete target.files;
return res.json(target);
}
if (user.administrator && !user.superAdmin && (target.administrator || target.superAdmin)) {
delete target.files;
return res.json(target);
}
for (const file of target.files) {
(file as unknown as { url: string }).url = formatRootUrl(zconfig.uploader.route, file.name);
if (file.thumbnail) {
(file.thumbnail as unknown as string) = formatRootUrl('/r', file.thumbnail.name);
}
}
return res.json(target); return res.json(target);
} }

View file

@ -14,10 +14,14 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
where: { where: {
userId: user.id, userId: user.id,
}, },
include: {
thumbnail: true,
},
}); });
for (let i = 0; i !== files.length; ++i) { for (let i = 0; i !== files.length; ++i) {
await datasource.delete(files[i].name); await datasource.delete(files[i].name);
if (files[i].thumbnail?.name) await datasource.delete(files[i].thumbnail.name);
} }
const { count } = await prisma.file.deleteMany({ const { count } = await prisma.file.deleteMany({
@ -45,6 +49,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
id: true, id: true,
}, },
}, },
thumbnail: true,
}, },
}); });
@ -63,10 +68,12 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
id: true, id: true,
}, },
}, },
thumbnail: true,
}, },
}); });
await datasource.delete(file.name); await datasource.delete(file.name);
if (file.thumbnail?.name) await datasource.delete(file.thumbnail.name);
logger.info( logger.info(
`User ${user.username} (${user.id}) deleted an image ${file.name} (${file.id}) owned by ${file.user.username} (${file.user.id})` `User ${user.username} (${user.id}) deleted an image ${file.name} (${file.id}) owned by ${file.user.username} (${file.user.id})`

View file

@ -11,7 +11,9 @@ async function main() {
process.exit(0); process.exit(0);
} }
const files = (await readdir(temp)).filter((x) => x.startsWith('zipline_partial_')); const files = (await readdir(temp)).filter(
(x) => x.startsWith('zipline_partial_') || x.startsWith('zipline_thumb_')
);
if (files.length === 0) { if (files.length === 0) {
console.log('No partial files found, exiting..'); console.log('No partial files found, exiting..');
process.exit(0); process.exit(0);

View file

@ -47,6 +47,9 @@ async function main() {
}, },
}, },
}); });
await prisma.$disconnect();
console.log(`Deleted ${count} files from the database.`); console.log(`Deleted ${count} files from the database.`);
for (let i = 0; i !== toDelete.length; ++i) { for (let i = 0; i !== toDelete.length; ++i) {

View file

@ -52,6 +52,8 @@ async function main() {
await datasource.save(file, await readFile(join(directory, file))); await datasource.save(file, await readFile(join(directory, file)));
} }
console.log(`Finished copying files to ${config.datasource.type} storage.`); console.log(`Finished copying files to ${config.datasource.type} storage.`);
process.exit(0);
} }
main(); main();

View file

@ -1,6 +1,7 @@
import { PrismaClient } from '@prisma/client'; import { PrismaClient } from '@prisma/client';
import config from 'lib/config'; import config from 'lib/config';
import { migrations } from 'server/util'; import { migrations } from 'server/util';
import { inspect } from 'util';
async function main() { async function main() {
const extras = (process.argv[2] ?? '').split(','); const extras = (process.argv[2] ?? '').split(',');
@ -13,6 +14,7 @@ async function main() {
const select = { const select = {
username: true, username: true,
administrator: true, administrator: true,
superAdmin: true,
id: true, id: true,
}; };
for (let i = 0; i !== extras.length; ++i) { for (let i = 0; i !== extras.length; ++i) {
@ -30,7 +32,11 @@ async function main() {
select, select,
}); });
console.log(JSON.stringify(users, null, 2)); await prisma.$disconnect();
console.log(inspect(users, false, 4, true));
process.exit(0);
} }
main(); main();

View file

@ -60,11 +60,14 @@ async function main() {
} }
} }
await prisma.$disconnect();
notFound notFound
? console.log( ? console.log(
'At least one file has been found to not exist in the datasource but was on the database. To remove these files, run the script with the --force-delete flag.' 'At least one file has been found to not exist in the datasource but was on the database. To remove these files, run the script with the --force-delete flag.'
) )
: console.log('Done.'); : console.log('Done.');
process.exit(0); process.exit(0);
} }

View file

@ -66,11 +66,15 @@ async function main() {
data, data,
}); });
await prisma.$disconnect();
if (args[1] === 'password') { if (args[1] === 'password') {
parsed = '***'; parsed = '***';
} }
console.log(`Updated user ${user.id} with ${args[1]} = ${parsed}`); console.log(`Updated user ${user.id} with ${args[1]} = ${parsed}`);
process.exit(0);
} }
main(); main();

View file

@ -3841,9 +3841,9 @@ __metadata:
linkType: hard linkType: hard
"caniuse-lite@npm:^1.0.30001406": "caniuse-lite@npm:^1.0.30001406":
version: 1.0.30001439 version: 1.0.30001494
resolution: "caniuse-lite@npm:1.0.30001439" resolution: "caniuse-lite@npm:1.0.30001494"
checksum: 3912dd536c9735713ca85e47721988bbcefb881ddb4886b0b9923fa984247fd22cba032cf268e57d158af0e8a2ae2eae042ae01942a1d6d7849fa9fa5d62fb82 checksum: 770b742ebba6076da72e94f979ef609bbc855369d1b937c52227935d966b11c3b02baa6511fba04a804802b6eb22af0a2a4a82405963bbb769772530e6be7a8e
languageName: node languageName: node
linkType: hard linkType: hard