@@ -2,14 +2,16 @@ import { Network } from '@internxt/sdk';
22import * as NetworkDownload from '@internxt/sdk/dist/network/download' ;
33import { DecryptFileFunction , DownloadFileFunction } from '@internxt/sdk/dist/network' ;
44import { Environment } from '@internxt/inxt-js' ;
5+ import { GenerateFileKey } from '@internxt/inxt-js/build/lib/utils/crypto' ;
56import { randomBytes } from 'node:crypto' ;
67import { Readable } from 'node:stream' ;
78import { DownloadOptions , DownloadProgressCallback } from '../../types/network.types' ;
89import { CryptoService } from '../crypto.service' ;
910import { DownloadService } from './download.service' ;
1011import { ValidationService } from '../validation.service' ;
1112import { RangeOptions } from '../../utils/network.utils' ;
12- import { EncryptProgressCallback } from '@internxt/inxt-js/build/lib/core' ;
13+ import { UsageService } from '../usage.service' ;
14+ import { FormatUtils } from '../../utils/format.utils' ;
1315
1416const FORTY_GIGABYTES = 40 * 1024 * 1024 * 1024 ;
1517
@@ -26,7 +28,7 @@ export class NetworkFacade {
2628 return ValidationService . instance . validateMnemonic ( mnemonic ) ;
2729 } ,
2830 generateFileKey : ( mnemonic , bucketId , index ) => {
29- return Environment . utils . generateFileKey ( mnemonic , bucketId , index as Buffer ) ;
31+ return GenerateFileKey ( mnemonic , bucketId , index as Buffer ) ;
3032 } ,
3133 randomBytes : randomBytes ,
3234 } ;
@@ -123,21 +125,26 @@ export class NetworkFacade {
123125 * @param encryptProgressCallback A callback to update the encryption progress
124126 * @returns A promise to execute the upload
125127 */
126- public uploadFile = ( {
128+ public uploadFile = async ( {
127129 from,
128130 size,
129131 bucketId,
130132 progressCallback,
131133 abortSignal,
132- encryptProgressCallback,
133134 } : {
134135 from : Readable ;
135136 size : number ;
136137 bucketId : string ;
137138 progressCallback : ( progress : number ) => void ;
138139 abortSignal ?: AbortSignal ;
139- encryptProgressCallback ?: EncryptProgressCallback ;
140140 } ) : Promise < string > => {
141+ const limits = await UsageService . instance . fetchLimits ( ) ;
142+ if ( limits ?. maxUploadFileSize && size > limits . maxUploadFileSize ) {
143+ const formattedSize = FormatUtils . humanFileSize ( size ) ;
144+ const formattedLimit = FormatUtils . humanFileSize ( limits . maxUploadFileSize ) ;
145+ throw new Error ( `File is too big (${ formattedSize } exceeds account upload limit of ${ formattedLimit } )` ) ;
146+ }
147+
141148 if ( size > FORTY_GIGABYTES ) {
142149 throw new Error ( 'File is too big (more than 40 GB)' ) ;
143150 }
@@ -147,7 +154,6 @@ export class NetworkFacade {
147154 fileSize : size ,
148155 progressCallback,
149156 abortSignal,
150- encryptProgressCallback,
151157 } ) ;
152158 } ;
153159}
0 commit comments