Skip to content

Commit 8983440

Browse files
committed
Merge pull request #864 from nxglabs/staging
1 parent 5a28c0e commit 8983440

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

apps/OpenSign/src/constant/Utils.jsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
101122
export const color = [
102123
"#93a3db",
103124
"#e6c3db",
@@ -3425,7 +3446,7 @@ export const handleCheckResponse = (checkUser, setminRequiredCount) => {
34253446
export 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+
*/
34713501
export function getFileAsArrayBuffer(file) {
34723502
return new Promise((resolve, reject) => {
34733503
const reader = new FileReader();

apps/OpenSign/src/pages/Form.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
toDataUrl,
1717
decryptPdf,
1818
base64ToFile,
19-
getFileAsArrayBuffer
19+
getFileAsArrayBuffer,
20+
removeTrailingSegment
2021
} from "../constant/Utils";
2122
import { PDFDocument } from "pdf-lib";
2223
import axios from "axios";
@@ -240,7 +241,7 @@ const Forms = (props) => {
240241
) {
241242
try {
242243
const baseApi = localStorage.getItem("baseUrl") || "";
243-
const url = baseApi.replace("/app", "") + "docxtopdf";
244+
const url = removeTrailingSegment(baseApi) + "/docxtopdf";
244245
let fd = new FormData();
245246
fd.append("file", file);
246247
setfileload(true);

0 commit comments

Comments
 (0)