feat: storage and token limiting

This commit is contained in:
Vasily Zubarev
2025-04-21 13:50:45 +02:00
parent 62bad46e58
commit 73e83221b8
25 changed files with 232 additions and 65 deletions

View File

@@ -1,6 +1,7 @@
import { File, Transaction, User } from "@prisma/client"
import { access, constants, readdir, stat } from "fs/promises"
import path from "path"
import config from "./config"
export const FILE_UPLOAD_PATH = path.resolve(process.env.UPLOAD_PATH || "./uploads")
export const FILE_UNSORTED_DIRECTORY_NAME = "unsorted"
@@ -70,3 +71,10 @@ export async function getDirectorySize(directoryPath: string) {
await calculateSize(directoryPath)
return totalSize
}
export function isEnoughStorageToUploadFile(user: User, fileSize: number) {
if (config.selfHosted.isEnabled || user.storageLimit < 0) {
return true
}
return user.storageUsed + fileSize <= user.storageLimit
}