mirror of
https://github.com/diced/zipline.git
synced 2025-05-11 10:26:05 +02:00
feat: baseline support for file sizes
This commit is contained in:
parent
0848702f65
commit
535600edc8
9 changed files with 19 additions and 0 deletions
2
prisma/migrations/20230226051016_file_size/migration.sql
Normal file
2
prisma/migrations/20230226051016_file_size/migration.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "File" ADD COLUMN "size" INTEGER NOT NULL DEFAULT 0;
|
|
@ -53,6 +53,7 @@ model File {
|
||||||
originalName String?
|
originalName String?
|
||||||
mimetype String @default("image/png")
|
mimetype String @default("image/png")
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
size Int @default(0)
|
||||||
expiresAt DateTime?
|
expiresAt DateTime?
|
||||||
maxViews Int?
|
maxViews Int?
|
||||||
views Int @default(0)
|
views Int @default(0)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { showNotification } from '@mantine/notifications';
|
||||||
import useFetch from 'hooks/useFetch';
|
import useFetch from 'hooks/useFetch';
|
||||||
import { useFileDelete, useFileFavorite } from 'lib/queries/files';
|
import { useFileDelete, useFileFavorite } from 'lib/queries/files';
|
||||||
import { useFolders } from 'lib/queries/folders';
|
import { useFolders } from 'lib/queries/folders';
|
||||||
|
import { bytesToHuman } from 'lib/utils/bytes';
|
||||||
import { relativeTime } from 'lib/utils/client';
|
import { relativeTime } from 'lib/utils/client';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
|
@ -27,6 +28,7 @@ import {
|
||||||
DownloadIcon,
|
DownloadIcon,
|
||||||
ExternalLinkIcon,
|
ExternalLinkIcon,
|
||||||
EyeIcon,
|
EyeIcon,
|
||||||
|
HardDriveIcon,
|
||||||
FileIcon,
|
FileIcon,
|
||||||
FolderMinusIcon,
|
FolderMinusIcon,
|
||||||
FolderPlusIcon,
|
FolderPlusIcon,
|
||||||
|
@ -245,6 +247,7 @@ export default function File({
|
||||||
>
|
>
|
||||||
<FileMeta Icon={FileIcon} title='Name' subtitle={image.name} />
|
<FileMeta Icon={FileIcon} title='Name' subtitle={image.name} />
|
||||||
<FileMeta Icon={ImageIcon} title='Type' subtitle={image.mimetype} />
|
<FileMeta Icon={ImageIcon} title='Type' subtitle={image.mimetype} />
|
||||||
|
<FileMeta Icon={HardDriveIcon} title='Size' subtitle={bytesToHuman(image.size || 0)} />
|
||||||
<FileMeta Icon={EyeIcon} title='Views' subtitle={image?.views?.toLocaleString()} />
|
<FileMeta Icon={EyeIcon} title='Views' subtitle={image?.views?.toLocaleString()} />
|
||||||
{image.maxViews && (
|
{image.maxViews && (
|
||||||
<FileMeta
|
<FileMeta
|
||||||
|
|
5
src/components/icons/HardDriveIcon.tsx
Normal file
5
src/components/icons/HardDriveIcon.tsx
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { HardDrive } from 'react-feather';
|
||||||
|
|
||||||
|
export default function HardDriveIcon({ ...props }) {
|
||||||
|
return <HardDrive size={15} {...props} />;
|
||||||
|
}
|
|
@ -41,6 +41,7 @@ import FolderPlusIcon from './FolderPlusIcon';
|
||||||
import GlobeIcon from './GlobeIcon';
|
import GlobeIcon from './GlobeIcon';
|
||||||
import LockIcon from './LockIcon';
|
import LockIcon from './LockIcon';
|
||||||
import UnlockIcon from './UnlockIcon';
|
import UnlockIcon from './UnlockIcon';
|
||||||
|
import HardDriveIcon from './HardDriveIcon';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ActivityIcon,
|
ActivityIcon,
|
||||||
|
@ -86,4 +87,5 @@ export {
|
||||||
GlobeIcon,
|
GlobeIcon,
|
||||||
LockIcon,
|
LockIcon,
|
||||||
UnlockIcon,
|
UnlockIcon,
|
||||||
|
HardDriveIcon,
|
||||||
};
|
};
|
||||||
|
|
|
@ -293,6 +293,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
expiresAt: expiry,
|
expiresAt: expiry,
|
||||||
maxViews: fileMaxViews,
|
maxViews: fileMaxViews,
|
||||||
originalName: req.headers['original-name'] ? file.originalname ?? null : null,
|
originalName: req.headers['original-name'] ? file.originalname ?? null : null,
|
||||||
|
size: file.size,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
||||||
expiresAt: Date;
|
expiresAt: Date;
|
||||||
maxViews: number;
|
maxViews: number;
|
||||||
views: number;
|
views: number;
|
||||||
|
size: number;
|
||||||
}[] = await prisma.file.findMany({
|
}[] = await prisma.file.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
@ -86,6 +87,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
||||||
favorite: true,
|
favorite: true,
|
||||||
views: true,
|
views: true,
|
||||||
maxViews: true,
|
maxViews: true,
|
||||||
|
size: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
||||||
maxViews: number;
|
maxViews: number;
|
||||||
views: number;
|
views: number;
|
||||||
folderId: number;
|
folderId: number;
|
||||||
|
size: number;
|
||||||
}[] = await prisma.file.findMany({
|
}[] = await prisma.file.findMany({
|
||||||
where,
|
where,
|
||||||
orderBy: {
|
orderBy: {
|
||||||
|
@ -73,6 +74,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
||||||
views: true,
|
views: true,
|
||||||
maxViews: true,
|
maxViews: true,
|
||||||
folderId: true,
|
folderId: true,
|
||||||
|
size: true,
|
||||||
},
|
},
|
||||||
skip: page ? (Number(page) - 1) * pageCount : undefined,
|
skip: page ? (Number(page) - 1) * pageCount : undefined,
|
||||||
take: page ? pageCount : undefined,
|
take: page ? pageCount : undefined,
|
||||||
|
|
|
@ -25,6 +25,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
||||||
views: true,
|
views: true,
|
||||||
maxViews: true,
|
maxViews: true,
|
||||||
folderId: true,
|
folderId: true,
|
||||||
|
size: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue