@@ -11,30 +11,47 @@ const MAX_FILE_SIZE_MB = 10;
1111// see: shared/leUtils/FormatPresets.js
1212const ACCEPTED_MIME_TYPES = [ 'image/png' , 'image/jpeg' , 'image/jpg' , 'image/gif' , 'image/svg+xml' ] ;
1313
14- const { noFileProvided$, invalidFileType$, fileTooLarge$, fileSizeUnit$, failedToProcessImage$ } =
15- getTipTapEditorStrings ( ) ;
14+ const {
15+ noFileProvided$,
16+ invalidFileType$,
17+ fileTooLarge$,
18+ fileSizeUnit$,
19+ failedToProcessImage$,
20+ noEnoughStorageSpace$,
21+ } = getTipTapEditorStrings ( ) ;
1622
1723/**
18- * Validates a file based on type and size .
24+ * Validates a file based on type, size, and available storage .
1925 * @param {File } file - The file to validate.
26+ * @param {number } availableSpace - Available storage space in bytes.
2027 * @returns {{isValid: boolean, error?: string} }
2128 */
22- function validateFile ( file ) {
29+ function validateFile ( file , availableSpace = null ) {
2330 if ( ! file ) {
2431 return { isValid : false , error : noFileProvided$ ( ) } ;
2532 }
33+
2634 if ( ! ACCEPTED_MIME_TYPES . includes ( file . type ) ) {
2735 return {
2836 isValid : false ,
2937 error : invalidFileType$ ( ) + ACCEPTED_MIME_TYPES . join ( ', ' ) ,
3038 } ;
3139 }
40+
3241 if ( file . size > MAX_FILE_SIZE_MB * 1024 * 1024 ) {
3342 return {
3443 isValid : false ,
3544 error : fileTooLarge$ ( ) + MAX_FILE_SIZE_MB + fileSizeUnit$ ( ) ,
3645 } ;
3746 }
47+
48+ if ( availableSpace !== null && file . size > availableSpace ) {
49+ return {
50+ isValid : false ,
51+ error : noEnoughStorageSpace$ ( ) ,
52+ } ;
53+ }
54+
3855 return { isValid : true } ;
3956}
4057
@@ -62,10 +79,19 @@ function uploadFileToStorage({ file_format, mightSkip, checksum, file, url, cont
6279 * Main file processing function that uploads to server.
6380 * Adapted from uploadFile action but simplified for image-specific use.
6481 * @param {File } file - The image file to process.
82+ * @param {Object } context - Vue component context with $store access.
6583 * @returns {Promise<{src: string, width: number, height: number, file: File, id: string}> }
6684 */
67- async function processFile ( file ) {
68- const validation = validateFile ( file ) ;
85+ async function processFile ( file , context = null ) {
86+ let availableSpace = null ;
87+
88+ // Get available space if context is provided
89+ if ( context && context . $store ) {
90+ await context . $store . dispatch ( 'fetchUserStorage' ) ;
91+ availableSpace = context . $store . getters . availableSpace ;
92+ }
93+
94+ const validation = validateFile ( file , availableSpace ) ;
6995 if ( ! validation . isValid ) {
7096 throw new Error ( validation . error ) ;
7197 }
0 commit comments