diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx
index c57a770..1d1603b 100644
--- a/src/components/Layout.tsx
+++ b/src/components/Layout.tsx
@@ -349,7 +349,11 @@ export default function Layout({ children, props }) {
:
+ avatar ? (
+
+ ) : (
+
+ )
}
variant='subtle'
color='gray'
diff --git a/src/components/pages/Upload/File.tsx b/src/components/pages/Upload/File.tsx
index 9c6a5dc..5a6229b 100644
--- a/src/components/pages/Upload/File.tsx
+++ b/src/components/pages/Upload/File.tsx
@@ -122,6 +122,8 @@ export default function File({ chunks: chunks_config }) {
});
if (j === chunks.length - 1) {
+ window.removeEventListener('beforeunload', beforeUnload);
+ router.events.off('routeChangeStart', beforeRouteChange);
updateNotification({
id: 'upload-chunked',
title: 'Finalizing partial upload',
diff --git a/src/pages/api/user/[id].ts b/src/pages/api/user/[id].ts
index 5767f3a..3b16344 100644
--- a/src/pages/api/user/[id].ts
+++ b/src/pages/api/user/[id].ts
@@ -3,6 +3,8 @@ import Logger from 'lib/logger';
import prisma from 'lib/prisma';
import { hashPassword } from 'lib/util';
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';
const logger = Logger.get('user');
@@ -15,7 +17,11 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
id: Number(id),
},
include: {
- files: true,
+ files: {
+ include: {
+ thumbnail: true,
+ },
+ },
Folder: true,
},
});
@@ -179,9 +185,21 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
} else {
delete target.password;
- if (user.superAdmin && target.superAdmin) delete target.files;
- if (user.administrator && !user.superAdmin && (target.administrator || target.superAdmin))
+ if (user.superAdmin && target.superAdmin) {
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);
}
diff --git a/src/pages/api/user/files.ts b/src/pages/api/user/files.ts
index a840a19..2e2ac45 100644
--- a/src/pages/api/user/files.ts
+++ b/src/pages/api/user/files.ts
@@ -14,10 +14,14 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
where: {
userId: user.id,
},
+ include: {
+ thumbnail: true,
+ },
});
for (let i = 0; i !== files.length; ++i) {
await datasource.delete(files[i].name);
+ if (files[i].thumbnail?.name) await datasource.delete(files[i].thumbnail.name);
}
const { count } = await prisma.file.deleteMany({
@@ -45,6 +49,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
id: true,
},
},
+ thumbnail: true,
},
});
@@ -63,10 +68,12 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
id: true,
},
},
+ thumbnail: true,
},
});
await datasource.delete(file.name);
+ if (file.thumbnail?.name) await datasource.delete(file.thumbnail.name);
logger.info(
`User ${user.username} (${user.id}) deleted an image ${file.name} (${file.id}) owned by ${file.user.username} (${file.user.id})`
diff --git a/src/scripts/clear-temp.ts b/src/scripts/clear-temp.ts
index 9f8787a..b1a43f9 100644
--- a/src/scripts/clear-temp.ts
+++ b/src/scripts/clear-temp.ts
@@ -11,7 +11,9 @@ async function main() {
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) {
console.log('No partial files found, exiting..');
process.exit(0);
diff --git a/src/scripts/clear-zero-byte.ts b/src/scripts/clear-zero-byte.ts
index 3286b43..50a4a20 100644
--- a/src/scripts/clear-zero-byte.ts
+++ b/src/scripts/clear-zero-byte.ts
@@ -47,6 +47,9 @@ async function main() {
},
},
});
+
+ await prisma.$disconnect();
+
console.log(`Deleted ${count} files from the database.`);
for (let i = 0; i !== toDelete.length; ++i) {
diff --git a/src/scripts/import-dir.ts b/src/scripts/import-dir.ts
index a69194f..191d3da 100644
--- a/src/scripts/import-dir.ts
+++ b/src/scripts/import-dir.ts
@@ -52,6 +52,8 @@ async function main() {
await datasource.save(file, await readFile(join(directory, file)));
}
console.log(`Finished copying files to ${config.datasource.type} storage.`);
+
+ process.exit(0);
}
main();
diff --git a/src/scripts/list-users.ts b/src/scripts/list-users.ts
index 7b16748..6244963 100644
--- a/src/scripts/list-users.ts
+++ b/src/scripts/list-users.ts
@@ -1,6 +1,7 @@
import { PrismaClient } from '@prisma/client';
import config from 'lib/config';
import { migrations } from 'server/util';
+import { inspect } from 'util';
async function main() {
const extras = (process.argv[2] ?? '').split(',');
@@ -13,6 +14,7 @@ async function main() {
const select = {
username: true,
administrator: true,
+ superAdmin: true,
id: true,
};
for (let i = 0; i !== extras.length; ++i) {
@@ -30,7 +32,11 @@ async function main() {
select,
});
- console.log(JSON.stringify(users, null, 2));
+ await prisma.$disconnect();
+
+ console.log(inspect(users, false, 4, true));
+
+ process.exit(0);
}
main();
diff --git a/src/scripts/query-size.ts b/src/scripts/query-size.ts
index 5649769..c0fabc9 100644
--- a/src/scripts/query-size.ts
+++ b/src/scripts/query-size.ts
@@ -60,11 +60,14 @@ async function main() {
}
}
+ await prisma.$disconnect();
+
notFound
? 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.'
)
: console.log('Done.');
+
process.exit(0);
}
diff --git a/src/scripts/set-user.ts b/src/scripts/set-user.ts
index e42d80f..bdb05c6 100644
--- a/src/scripts/set-user.ts
+++ b/src/scripts/set-user.ts
@@ -66,11 +66,15 @@ async function main() {
data,
});
+ await prisma.$disconnect();
+
if (args[1] === 'password') {
parsed = '***';
}
console.log(`Updated user ${user.id} with ${args[1]} = ${parsed}`);
+
+ process.exit(0);
}
main();
diff --git a/yarn.lock b/yarn.lock
index 3e73b78..bae717b 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3841,9 +3841,9 @@ __metadata:
linkType: hard
"caniuse-lite@npm:^1.0.30001406":
- version: 1.0.30001439
- resolution: "caniuse-lite@npm:1.0.30001439"
- checksum: 3912dd536c9735713ca85e47721988bbcefb881ddb4886b0b9923fa984247fd22cba032cf268e57d158af0e8a2ae2eae042ae01942a1d6d7849fa9fa5d62fb82
+ version: 1.0.30001494
+ resolution: "caniuse-lite@npm:1.0.30001494"
+ checksum: 770b742ebba6076da72e94f979ef609bbc855369d1b937c52227935d966b11c3b02baa6511fba04a804802b6eb22af0a2a4a82405963bbb769772530e6be7a8e
languageName: node
linkType: hard