mirror of
https://github.com/marcogll/TaxHacker_s23.git
synced 2026-01-13 21:35:19 +00:00
feat: storage and token limiting
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user