mirror of
https://github.com/diced/zipline.git
synced 2025-04-04 23:21:17 -05: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?
|
||||
mimetype String @default("image/png")
|
||||
createdAt DateTime @default(now())
|
||||
size Int @default(0)
|
||||
expiresAt DateTime?
|
||||
maxViews Int?
|
||||
views Int @default(0)
|
||||
|
|
|
@ -16,6 +16,7 @@ import { showNotification } from '@mantine/notifications';
|
|||
import useFetch from 'hooks/useFetch';
|
||||
import { useFileDelete, useFileFavorite } from 'lib/queries/files';
|
||||
import { useFolders } from 'lib/queries/folders';
|
||||
import { bytesToHuman } from 'lib/utils/bytes';
|
||||
import { relativeTime } from 'lib/utils/client';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
|
@ -27,6 +28,7 @@ import {
|
|||
DownloadIcon,
|
||||
ExternalLinkIcon,
|
||||
EyeIcon,
|
||||
HardDriveIcon,
|
||||
FileIcon,
|
||||
FolderMinusIcon,
|
||||
FolderPlusIcon,
|
||||
|
@ -245,6 +247,7 @@ export default function File({
|
|||
>
|
||||
<FileMeta Icon={FileIcon} title='Name' subtitle={image.name} />
|
||||
<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()} />
|
||||
{image.maxViews && (
|
||||
<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 LockIcon from './LockIcon';
|
||||
import UnlockIcon from './UnlockIcon';
|
||||
import HardDriveIcon from './HardDriveIcon';
|
||||
|
||||
export {
|
||||
ActivityIcon,
|
||||
|
@ -86,4 +87,5 @@ export {
|
|||
GlobeIcon,
|
||||
LockIcon,
|
||||
UnlockIcon,
|
||||
HardDriveIcon,
|
||||
};
|
||||
|
|
|
@ -293,6 +293,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
expiresAt: expiry,
|
||||
maxViews: fileMaxViews,
|
||||
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;
|
||||
maxViews: number;
|
||||
views: number;
|
||||
size: number;
|
||||
}[] = await prisma.file.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
|
@ -86,6 +87,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
|||
favorite: true,
|
||||
views: true,
|
||||
maxViews: true,
|
||||
size: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
|||
maxViews: number;
|
||||
views: number;
|
||||
folderId: number;
|
||||
size: number;
|
||||
}[] = await prisma.file.findMany({
|
||||
where,
|
||||
orderBy: {
|
||||
|
@ -73,6 +74,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
|||
views: true,
|
||||
maxViews: true,
|
||||
folderId: true,
|
||||
size: true,
|
||||
},
|
||||
skip: page ? (Number(page) - 1) * pageCount : undefined,
|
||||
take: page ? pageCount : undefined,
|
||||
|
|
|
@ -25,6 +25,7 @@ async function handler(req: NextApiReq, res: NextApiRes, user: UserExtended) {
|
|||
views: true,
|
||||
maxViews: true,
|
||||
folderId: true,
|
||||
size: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue