@@ -98,6 +98,27 @@ export const getSecureUrl = async (url) => {
9898 }
9999} ;
100100
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+
101122export const color = [
102123 "#93a3db" ,
103124 "#e6c3db" ,
@@ -3425,7 +3446,7 @@ export const handleCheckResponse = (checkUser, setminRequiredCount) => {
34253446export const decryptPdf = async ( file , password ) => {
34263447 const name = generatePdfName ( 16 ) ;
34273448 const baseApi = localStorage . getItem ( "baseUrl" ) || "" ;
3428- const url = baseApi . replace ( "/app" , "" ) + "decryptpdf?ts=" + Date . now ( ) ;
3449+ const url = removeTrailingSegment ( baseApi ) + "/ decryptpdf?ts=" + Date . now ( ) ;
34293450 let formData = new FormData ( ) ;
34303451 formData . append ( "file" , file ) ;
34313452 formData . append ( "password" , password ) ;
@@ -3468,6 +3489,15 @@ export function base64ToFile(base64String, filename) {
34683489 return new File ( [ u8arr ] , filename , { type : mime } ) ;
34693490}
34703491
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+ */
34713501export function getFileAsArrayBuffer ( file ) {
34723502 return new Promise ( ( resolve , reject ) => {
34733503 const reader = new FileReader ( ) ;
0 commit comments