@@ -98,6 +98,27 @@ export const getSecureUrl = async (url) => {
98
98
}
99
99
} ;
100
100
101
+ /**
102
+ * Removes a trailing path segment from a URL string, if present.
103
+ *
104
+ * @param {string } url - The original URL.
105
+ * @param {string } segment - The segment to strip off (default: "app").
106
+ * @returns {string } - The URL with the trailing segment removed, or unmodified if it didn’t match.
107
+ */
108
+ export function removeTrailingSegment ( url , segment = "app" ) {
109
+ // Normalize a trailing slash (e.g. “/app/” → “/app”)
110
+ const normalized = url . endsWith ( "/" ) ? url . slice ( 0 , - 1 ) : url ;
111
+
112
+ const lastSlash = normalized . lastIndexOf ( "/" ) ;
113
+ const lastPart = normalized . slice ( lastSlash + 1 ) ;
114
+
115
+ if ( lastPart === segment ) {
116
+ return normalized . slice ( 0 , lastSlash ) ;
117
+ }
118
+
119
+ return normalized ;
120
+ }
121
+
101
122
export const color = [
102
123
"#93a3db" ,
103
124
"#e6c3db" ,
@@ -3425,7 +3446,7 @@ export const handleCheckResponse = (checkUser, setminRequiredCount) => {
3425
3446
export const decryptPdf = async ( file , password ) => {
3426
3447
const name = generatePdfName ( 16 ) ;
3427
3448
const baseApi = localStorage . getItem ( "baseUrl" ) || "" ;
3428
- const url = baseApi . replace ( "/app" , "" ) + "decryptpdf?ts=" + Date . now ( ) ;
3449
+ const url = removeTrailingSegment ( baseApi ) + "/ decryptpdf?ts=" + Date . now ( ) ;
3429
3450
let formData = new FormData ( ) ;
3430
3451
formData . append ( "file" , file ) ;
3431
3452
formData . append ( "password" , password ) ;
@@ -3468,6 +3489,15 @@ export function base64ToFile(base64String, filename) {
3468
3489
return new File ( [ u8arr ] , filename , { type : mime } ) ;
3469
3490
}
3470
3491
3492
+ /**
3493
+ * Reads the given File object and returns its contents as an ArrayBuffer.
3494
+ *
3495
+ * @param {File } file
3496
+ * The File instance to be read.
3497
+ * @returns {Promise<ArrayBuffer> }
3498
+ * A promise that resolves with the file’s binary data as an ArrayBuffer,
3499
+ * or rejects with an error if the read fails.
3500
+ */
3471
3501
export function getFileAsArrayBuffer ( file ) {
3472
3502
return new Promise ( ( resolve , reject ) => {
3473
3503
const reader = new FileReader ( ) ;
0 commit comments