11/* eslint-disable no-console -- used for error logging */
2- import { type TUploadFileConfig , type TUploadFileResponse } from "@/types/storage" ;
2+ import {
3+ type TUploadFileConfig ,
4+ type TUploadFileResponse ,
5+ } from "@/types/storage" ;
36
47export class StorageAPI {
5- private appUrl : string ;
6- private environmentId : string ;
8+ private readonly appUrl : string ;
9+ private readonly environmentId : string ;
710
811 constructor ( appUrl : string , environmentId : string ) {
912 this . appUrl = appUrl ;
@@ -29,13 +32,16 @@ export class StorageAPI {
2932 surveyId,
3033 } ;
3134
32- const response = await fetch ( `${ this . appUrl } /api/v1/client/${ this . environmentId } /storage` , {
33- method : "POST" ,
34- headers : {
35- "Content-Type" : "application/json" ,
36- } ,
37- body : JSON . stringify ( payload ) ,
38- } ) ;
35+ const response = await fetch (
36+ `${ this . appUrl } /api/v1/client/${ this . environmentId } /storage` ,
37+ {
38+ method : "POST" ,
39+ headers : {
40+ "Content-Type" : "application/json" ,
41+ } ,
42+ body : JSON . stringify ( payload ) ,
43+ }
44+ ) ;
3945
4046 if ( ! response . ok ) {
4147 throw new Error ( `Upload failed with status: ${ String ( response . status ) } ` ) ;
@@ -45,7 +51,13 @@ export class StorageAPI {
4551
4652 const { data } = json ;
4753
48- const { signedUrl, fileUrl, signingData, presignedFields, updatedFileName } = data ;
54+ const {
55+ signedUrl,
56+ fileUrl,
57+ signingData,
58+ presignedFields,
59+ updatedFileName,
60+ } = data ;
4961
5062 let localUploadDetails : Record < string , string > = { } ;
5163
@@ -86,7 +98,10 @@ export class StorageAPI {
8698
8799 let uploadResponse : Response = { } as Response ;
88100
89- const signedUrlCopy = signedUrl . replace ( "http://localhost:3000" , this . appUrl ) ;
101+ const signedUrlCopy = signedUrl . replace (
102+ "http://localhost:3000" ,
103+ this . appUrl
104+ ) ;
90105
91106 try {
92107 uploadResponse = await fetch ( signedUrlCopy , {
@@ -114,12 +129,16 @@ export class StorageAPI {
114129 // if s3 is used, we'll use the text response:
115130 const errorText = await uploadResponse . text ( ) ;
116131 if ( presignedFields && errorText . includes ( "EntityTooLarge" ) ) {
117- const error = new Error ( "File size exceeds the size limit for your plan" ) ;
132+ const error = new Error (
133+ "File size exceeds the size limit for your plan"
134+ ) ;
118135 error . name = "FileTooLargeError" ;
119136 throw error ;
120137 }
121138
122- throw new Error ( `Upload failed with status: ${ String ( uploadResponse . status ) } ` ) ;
139+ throw new Error (
140+ `Upload failed with status: ${ String ( uploadResponse . status ) } `
141+ ) ;
123142 }
124143
125144 return fileUrl ;
0 commit comments