Skip to content

Commit db1ae78

Browse files
authored
Merge branch 'trunk' into drizzle
2 parents 17268c1 + e2e3edd commit db1ae78

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "zipline",
33
"private": true,
44
"license": "MIT",
5-
"version": "4.2.3",
5+
"version": "4.3.0",
66
"scripts": {
77
"build": "tsx scripts/build.ts",
88
"dev": "cross-env NODE_ENV=development DEBUG=zipline tsx --require dotenv/config --enable-source-maps ./src/server",

src/components/file/DashboardFileType.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export default function DashboardFileType({
8383
const user = useUserStore((state) => state.user);
8484
const disableMediaPreview = useSettingsStore((state) => state.settings.disableMediaPreview);
8585
const fileRoute = user ? `/api/user/files/${(file as DbFile).id}/raw` : `/raw/${file.name}`;
86-
86+
const thumbnailRoute = user
87+
? `/api/user/files/${(file as DbFile).thumbnail?.path}/raw`
88+
: `/raw/${(file as DbFile).thumbnail?.path}`;
8789
const dbFile = 'id' in file;
8890
const renderIn = useMemo(() => renderMode(file.name.split('.').pop() || ''), [file.name]);
8991

@@ -184,10 +186,7 @@ export default function DashboardFileType({
184186
/>
185187
) : (file as DbFile).thumbnail && dbFile ? (
186188
<Box pos='relative'>
187-
<MantineImage
188-
src={`/raw/${(file as DbFile).thumbnail!.path}`}
189-
alt={file.name || 'Video thumbnail'}
190-
/>
189+
<MantineImage src={thumbnailRoute} alt={file.name || 'Video thumbnail'} />
191190

192191
<Center
193192
pos='absolute'

src/server/routes/api/user/files/[id]/raw.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ export default fastifyPlugin(
2828
const { id } = req.params;
2929
const { pw, download } = req.query;
3030

31+
if (id.startsWith('.thumbnail')) {
32+
const thumbnail = await prisma.thumbnail.findFirst({
33+
where: {
34+
path: id,
35+
file: {
36+
userId: req.user.id,
37+
},
38+
},
39+
});
40+
41+
if (!thumbnail) return res.callNotFound();
42+
}
43+
3144
const file = await prisma.file.findFirst({
3245
where: {
3346
id,

src/server/routes/raw/[id].ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { verifyPassword } from '@/lib/crypto';
44
import { datasource } from '@/lib/datasource';
55
import { prisma } from '@/lib/db';
66
import { log } from '@/lib/logger';
7+
import { guess } from '@/lib/mimes';
78
import { FastifyReply, FastifyRequest } from 'fastify';
89
import fastifyPlugin from 'fastify-plugin';
910

@@ -31,12 +32,35 @@ export const rawFileHandler = async (
3132
const { id } = req.params;
3233
const { pw, download } = req.query;
3334

35+
if (id.startsWith('.thumbnail')) {
36+
const thumbnail = await prisma.thumbnail.findFirst({
37+
where: {
38+
path: id,
39+
},
40+
});
41+
42+
if (!thumbnail) return res.callNotFound();
43+
44+
const size = await datasource.size(thumbnail.path);
45+
if (!size) return res.callNotFound();
46+
47+
const buf = await datasource.get(thumbnail.path);
48+
if (!buf) return res.callNotFound();
49+
50+
return res
51+
.type(await guess(thumbnail.path.replace('.thumbnail-', '').split('.').pop() || 'jpg'))
52+
.headers({
53+
'Content-Length': size,
54+
})
55+
.status(200)
56+
.send(buf);
57+
}
58+
3459
const file = await prisma.file.findFirst({
3560
where: {
3661
name: decodeURIComponent(id),
3762
},
3863
});
39-
4064
if (!file) return res.callNotFound();
4165

4266
if (file?.deletesAt && file.deletesAt <= new Date()) {

0 commit comments

Comments
 (0)