feat: baseline support for file sizes

This commit is contained in:
dicedtomato 2023-02-26 05:37:20 +00:00 committed by GitHub
parent 0848702f65
commit 535600edc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 19 additions and 0 deletions

View file

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "File" ADD COLUMN "size" INTEGER NOT NULL DEFAULT 0;

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1,5 @@
import { HardDrive } from 'react-feather';
export default function HardDriveIcon({ ...props }) {
return <HardDrive size={15} {...props} />;
}

View file

@ -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,
}; };

View file

@ -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,
}, },
}); });

View file

@ -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,
}, },
}); });

View file

@ -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,

View file

@ -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,
}, },
}); });