Merge pull request #1803 from OpenSignLabs/updates-15736278136

fix: correct baseapi of docxtopdf and decryptpdf
This commit is contained in:
prafull-opensignlabs
2025-06-18 20:25:53 +05:30
committed by GitHub
2 changed files with 34 additions and 3 deletions
+31 -1
View File
@@ -98,6 +98,27 @@ export const getSecureUrl = async (url) => {
}
};
/**
* Removes a trailing path segment from a URL string, if present.
*
* @param {string} url - The original URL.
* @param {string} segment - The segment to strip off (default: "app").
* @returns {string} - The URL with the trailing segment removed, or unmodified if it didnt match.
*/
export function removeTrailingSegment(url, segment = "app") {
// Normalize a trailing slash (e.g. “/app/” → “/app”)
const normalized = url.endsWith("/") ? url.slice(0, -1) : url;
const lastSlash = normalized.lastIndexOf("/");
const lastPart = normalized.slice(lastSlash + 1);
if (lastPart === segment) {
return normalized.slice(0, lastSlash);
}
return normalized;
}
export const color = [
"#93a3db",
"#e6c3db",
@@ -3425,7 +3446,7 @@ export const handleCheckResponse = (checkUser, setminRequiredCount) => {
export const decryptPdf = async (file, password) => {
const name = generatePdfName(16);
const baseApi = localStorage.getItem("baseUrl") || "";
const url = baseApi.replace("/app", "") + "decryptpdf?ts=" + Date.now();
const url = removeTrailingSegment(baseApi) + "/decryptpdf?ts=" + Date.now();
let formData = new FormData();
formData.append("file", file);
formData.append("password", password);
@@ -3468,6 +3489,15 @@ export function base64ToFile(base64String, filename) {
return new File([u8arr], filename, { type: mime });
}
/**
* Reads the given File object and returns its contents as an ArrayBuffer.
*
* @param {File} file
* The File instance to be read.
* @returns {Promise<ArrayBuffer>}
* A promise that resolves with the files binary data as an ArrayBuffer,
* or rejects with an error if the read fails.
*/
export function getFileAsArrayBuffer(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
+3 -2
View File
@@ -16,7 +16,8 @@ import {
toDataUrl,
decryptPdf,
base64ToFile,
getFileAsArrayBuffer
getFileAsArrayBuffer,
removeTrailingSegment
} from "../constant/Utils";
import { PDFDocument } from "pdf-lib";
import axios from "axios";
@@ -240,7 +241,7 @@ const Forms = (props) => {
) {
try {
const baseApi = localStorage.getItem("baseUrl") || "";
const url = baseApi.replace("/app", "") + "docxtopdf";
const url = removeTrailingSegment(baseApi) + "/docxtopdf";
let fd = new FormData();
fd.append("file", file);
setfileload(true);