456 lines
11 KiB
JavaScript
456 lines
11 KiB
JavaScript
import axios from "axios";
|
|
import { BASE_URL } from "../core/env";
|
|
import { consoleLogger } from "../core/logger";
|
|
import { hashAPIPath } from "../core/hash";
|
|
|
|
const buildHashedQueryUrl = async (queryUrl) => {
|
|
try {
|
|
const signRes = await axios.get(
|
|
"/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl)
|
|
);
|
|
|
|
if (!signRes?.data?.hash) {
|
|
throw new Error("Hash signature unavailable");
|
|
}
|
|
|
|
return queryUrl + signRes.data.hash;
|
|
} catch (error) {
|
|
if (typeof window === "undefined" && process.env.HASHKEY) {
|
|
return queryUrl + hashAPIPath(queryUrl);
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export const getAwaitingSubmissionFromBlob = (containerName) => {
|
|
return axios
|
|
.get(
|
|
BASE_URL +
|
|
"/api/file/getawaitingsubmissionfromblob?container=" +
|
|
containerName +
|
|
hashAPIPath(
|
|
"/api/file/getawaitingsubmissionfromblob?container=" +
|
|
containerName
|
|
)
|
|
)
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
});
|
|
};
|
|
|
|
export const getRepsFromBlob = (containerName) => {
|
|
return axios
|
|
.get(
|
|
BASE_URL +
|
|
"/api/file/getrepsblob?container=" +
|
|
containerName +
|
|
hashAPIPath("/api/file/getrepsblob?container=" + containerName)
|
|
)
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
});
|
|
};
|
|
|
|
export const getRepsFromBlobProxy = async (containerName) => {
|
|
try {
|
|
const res = await axios.get(
|
|
"/api/file/getrepsblobproxy?container=" + containerName
|
|
);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const getAwaitingSubmissionFromBlobProxy = async (containerName) => {
|
|
try {
|
|
const res = await axios.get(
|
|
BASE_URL +
|
|
"/api/file/getawaitingsubmissionfromblobproxy?container=" +
|
|
containerName
|
|
);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const deleteAwaitingSubmissionsFromBlob = (
|
|
containerID,
|
|
casefolderID
|
|
) => {
|
|
var queryUrl =
|
|
"/api/file/deleteblobcase?container=" +
|
|
containerID +
|
|
"&casefolderID=" +
|
|
casefolderID;
|
|
|
|
return buildHashedQueryUrl(queryUrl)
|
|
.then((signedUrl) =>
|
|
axios({
|
|
method: "get",
|
|
url: signedUrl
|
|
})
|
|
)
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
});
|
|
};
|
|
|
|
export const deleteMyRepresentationsFromBlob = (
|
|
containerID,
|
|
casefolderID,
|
|
repfile
|
|
) => {
|
|
var queryUrl =
|
|
"/api/file/deleteblobrep?container=" +
|
|
containerID +
|
|
"&casefolderID=" +
|
|
casefolderID +
|
|
"&repfile=" +
|
|
repfile;
|
|
|
|
return buildHashedQueryUrl(queryUrl)
|
|
.then((signedUrl) =>
|
|
axios({
|
|
method: "get",
|
|
url: signedUrl
|
|
})
|
|
)
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
});
|
|
};
|
|
|
|
export const uploadFiles = async (
|
|
formValues,
|
|
filesObj,
|
|
containerID,
|
|
casefolderID
|
|
) => {
|
|
let files = filesObj;
|
|
|
|
var formData = new FormData();
|
|
formData.append("appealData", JSON.stringify(formValues));
|
|
formData.append("containerID", containerID);
|
|
formData.append("casefolderID", casefolderID);
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
for (let j = 0; j < files[i].length; j++) {
|
|
formData.append(files[i][j].name, files[i][j]);
|
|
}
|
|
}
|
|
|
|
var queryUrl = "/api/file/upload";
|
|
|
|
const hashedUrl = await buildHashedQueryUrl(queryUrl);
|
|
|
|
const config = {
|
|
method: "post",
|
|
url: hashedUrl,
|
|
data: formData,
|
|
headers: { "content-type": "multipart/form-data" }
|
|
};
|
|
|
|
try {
|
|
const res = await axios(config);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const uploadSingleFile = async (filesObj, containerID, casefolderID) => {
|
|
let files = filesObj;
|
|
|
|
var formData = new FormData();
|
|
formData.append("containerID", containerID);
|
|
formData.append("casefolderID", casefolderID);
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
formData.append(files[i].name, files[i]);
|
|
}
|
|
|
|
var queryUrl = "/api/file/uploadsinglefile";
|
|
|
|
const hashedUrl = await buildHashedQueryUrl(queryUrl);
|
|
|
|
const config = {
|
|
method: "post",
|
|
url: hashedUrl,
|
|
data: formData,
|
|
headers: { "content-type": "multipart/form-data" }
|
|
};
|
|
|
|
try {
|
|
const res = await axios(config);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const uploadRepFiles = async (
|
|
formValues,
|
|
filesObj,
|
|
containerID,
|
|
casefolderID
|
|
) => {
|
|
var formData = new FormData();
|
|
formData.append("appealData", JSON.stringify(formValues));
|
|
formData.append("containerID", containerID);
|
|
formData.append("casefolderID", casefolderID);
|
|
formData.append("repOrAppeal", true);
|
|
|
|
var queryUrl = "/api/file/upload";
|
|
|
|
const hashedUrl = await buildHashedQueryUrl(queryUrl);
|
|
|
|
const config = {
|
|
method: "post",
|
|
url: hashedUrl,
|
|
data: formData,
|
|
headers: { "content-type": "multipart/form-data" }
|
|
};
|
|
|
|
try {
|
|
const res = await axios(config);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const generateRepPDF = async (
|
|
formValues,
|
|
containerID,
|
|
casefolderID,
|
|
options = {}
|
|
) => {
|
|
var queryUrl =
|
|
"/api/file/generatepdf" + (options.download ? "?download=true" : "");
|
|
|
|
const hashedUrl = await buildHashedQueryUrl(queryUrl);
|
|
|
|
const config = {
|
|
method: "post",
|
|
url: hashedUrl,
|
|
data: formValues,
|
|
...(options.download ? { responseType: "blob" } : {})
|
|
};
|
|
|
|
try {
|
|
const res = await axios(config);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const generateAppealPDF = async (
|
|
formValues,
|
|
containerID,
|
|
casefolderID,
|
|
appealType,
|
|
fileList
|
|
) => {
|
|
Object.assign(formValues, {
|
|
"filesList": fileList
|
|
});
|
|
|
|
var queryUrl = "/api/file/generateappealpdf?appealType=" + appealType;
|
|
|
|
const hashedUrl = await buildHashedQueryUrl(queryUrl);
|
|
|
|
const config = {
|
|
method: "post",
|
|
url: hashedUrl,
|
|
data: formValues
|
|
};
|
|
|
|
try {
|
|
const res = await axios(config);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const getFilesFromBlob = (containerName, casefolderID) => {
|
|
return axios
|
|
.get(
|
|
BASE_URL +
|
|
"/api/file/getbloblist?container=" +
|
|
containerName +
|
|
"&casefolderID=" +
|
|
casefolderID +
|
|
hashAPIPath(
|
|
"/api/file/getbloblist?container=" +
|
|
containerName +
|
|
"&casefolderID=" +
|
|
casefolderID
|
|
)
|
|
)
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
});
|
|
};
|
|
|
|
export const getFilesFromBlobproxy = (containerName, casefolderID) => {
|
|
return axios
|
|
.get(
|
|
"/api/file/getbloblistproxy?container=" +
|
|
containerName +
|
|
"&casefolderID=" +
|
|
casefolderID
|
|
)
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
});
|
|
};
|
|
|
|
export const getFilesFromBlobHashed = (
|
|
containerName,
|
|
getblobshash,
|
|
casefolderID
|
|
) => {
|
|
return axios
|
|
.get(
|
|
"/api/file/getbloblist?container=" +
|
|
containerName +
|
|
"&casefolderID=" +
|
|
casefolderID +
|
|
getblobshash
|
|
)
|
|
.then((res) => {
|
|
return res.data;
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
});
|
|
};
|
|
|
|
export const deleteBlob = async (
|
|
containerName,
|
|
blobName,
|
|
deleteblobhash,
|
|
casefolderID
|
|
) => {
|
|
try {
|
|
const res = await axios.get(
|
|
"/api/file/deleteblob?container=" +
|
|
containerName +
|
|
"&casefolderID=" +
|
|
encodeURIComponent(casefolderID) +
|
|
"&blobname=" +
|
|
encodeURIComponent(blobName) +
|
|
deleteblobhash
|
|
);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const deleteRepBlob = async (
|
|
containerName,
|
|
blobName,
|
|
deleteblobhash,
|
|
casefolderID,
|
|
filenamePrefix
|
|
) => {
|
|
try {
|
|
const res = await axios.get(
|
|
"/api/file/deleteblob?container=" +
|
|
containerName +
|
|
"&casefolderID=" +
|
|
encodeURIComponent(casefolderID + "/" + filenamePrefix) +
|
|
"&blobname=" +
|
|
encodeURIComponent(blobName) +
|
|
deleteblobhash
|
|
);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const downloadBlob = (containerName, blobName) => {
|
|
return axios
|
|
.get(
|
|
BASE_URL +
|
|
"/api/file/downloadblob?container=" +
|
|
containerName.toLowerCase() +
|
|
"&blobname=" +
|
|
blobName,
|
|
{ responseType: "blob" }
|
|
)
|
|
.then((response) => {
|
|
res.setHeader(
|
|
"content-disposition",
|
|
"attachment; filename=" + blobName
|
|
);
|
|
|
|
return res.status(200).send(response.data);
|
|
})
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
});
|
|
};
|
|
|
|
export const getProgressFromBlob = async (containerName, casereference) => {
|
|
try {
|
|
const res = await axios.get(
|
|
BASE_URL +
|
|
"/api/file/getprogressobjblob?container=" +
|
|
encodeURIComponent(containerName) +
|
|
"&casefolderID=" +
|
|
encodeURIComponent(casereference) +
|
|
hashAPIPath(
|
|
"/api/file/getprogressobjblob?container=" +
|
|
encodeURIComponent(containerName) +
|
|
"&casefolderID=" +
|
|
encodeURIComponent(casereference)
|
|
)
|
|
);
|
|
return res.data;
|
|
} catch (error) {
|
|
consoleLogger(error);
|
|
}
|
|
};
|
|
|
|
export const createContainerProxy = (containerName) => {
|
|
var queryUrl =
|
|
"/api/file/setupcontainer?ident=" +
|
|
containerName +
|
|
hashAPIPath("/api/file/setupcontainer?ident=" + containerName);
|
|
|
|
return axios
|
|
.get(BASE_URL + queryUrl)
|
|
.then((res) => res.data)
|
|
.catch((error) => {
|
|
consoleLogger(error);
|
|
|
|
return JSON.stringify(error);
|
|
});
|
|
};
|