added hashing on api calls

This commit is contained in:
2022-07-12 12:49:26 +01:00
parent f23ad2a300
commit be9f86b6b2
13 changed files with 234 additions and 158 deletions
+9
View File
@@ -85,6 +85,15 @@ export const getBlobs = async (containerName) => {
"&blobname=" +
blob.name.split("/")[1]
),
"hasheddeletepath": hashAPIPath(
"/api/file/deleteblob?container=" +
containerName.toLowerCase() +
"&blobname=" +
blob.name.split("/")[1]
),
"hashgetblobs": hashAPIPath(
"/api/file/getbloblist?container=" + containerName.toLowerCase()
),
});
}
+27 -5
View File
@@ -1024,7 +1024,7 @@ export const createAccount = (formValues) => {
});
};
export const uploadFiles = async (formValues, filesObj) => {
export const uploadFiles = async (formValues, filesObj, uploadhash) => {
let files = filesObj;
console.log(formValues);
@@ -1065,10 +1065,14 @@ export const getFilesFromBlob = (containerName) => {
.get(
BASE_URL +
"/api/file/getbloblist?container=" +
containerName.toLowerCase()
containerName.toLowerCase() +
hashAPIPath(
"/api/file/getbloblist?container=" +
containerName.toLowerCase()
)
)
.then((res) => {
console.log("//////////----", res.data);
//console.log("//////////----", res.data);
return res.data;
})
.catch((error) => {
@@ -1076,14 +1080,32 @@ export const getFilesFromBlob = (containerName) => {
});
};
export const deleteBlob = async (containerName, blobName) => {
export const getFilesFromBlobHashed = (containerName, getblobshash) => {
return axios
.get(
BASE_URL +
"/api/file/getbloblist?container=" +
containerName.toLowerCase() +
getblobshash
)
.then((res) => {
//console.log("//////////----", res.data);
return res.data;
})
.catch((error) => {
console.log("this serror", error);
});
};
export const deleteBlob = async (containerName, blobName, deleteblobhash) => {
try {
const res = await axios.get(
BASE_URL +
"/api/file/deleteblob?container=" +
containerName.toLowerCase() +
"&blobname=" +
blobName
blobName +
deleteblobhash
);
return res.data;
} catch (error) {
+17 -8
View File
@@ -15,10 +15,9 @@ import Dropzone, { useDropzone } from "react-dropzone";
import _ from "lodash";
import { connect, useDispatch } from "react-redux";
import {
getFilesFromBlob,
getFilesFromBlobHashed,
deleteBlob,
downloadBlob,
hashAPIPath,
} from "../../actions";
import { setFilesForAppeal } from "../../store/appealType/action";
import Link from "next/link";
@@ -1456,13 +1455,18 @@ const RenderFileUpload = (field) => {
"$..[?(@.documentType=='" + field.documentTypeCode + "')]"
);
const deleteThisBlob = async (containerName, blobName) => {
console.log(containerName, blobName);
deleteBlob(containerName, blobName)
const deleteThisBlob = async (
containerName,
blobName,
deleteblobhash,
getblobshash
) => {
//console.log(containerName, blobName, deleteblobhash);
deleteBlob(containerName, blobName, deleteblobhash)
.then((data) => data)
.then(() => {
getFilesFromBlob(containerName).then((newfilelist) =>
field.setFilesForAppeal(newfilelist)
getFilesFromBlobHashed(containerName, getblobshash).then(
(newfilelist) => field.setFilesForAppeal(newfilelist)
);
});
};
@@ -1538,7 +1542,12 @@ const RenderFileUpload = (field) => {
<span
className="govuk-summary-list__actionLink watched_link govuk-!-margin-right-5 govuk-!-text-align-left"
onClick={() => {
deleteThisBlob(field.ticketnumber, blob.name);
deleteThisBlob(
field.ticketnumber,
blob.name,
blob.hasheddeletepath,
blob.hashgetblobs
);
}}
title="Remove this file"
>
+25
View File
@@ -95,6 +95,28 @@ let BuildCheckRow = (props) => {
"')]"
);
// if (datafieldname[0].value.indexOf("fileUpload") > 0) {
// isRequiredField.push({
// "LogicalName": datafieldname[0].value,
// "RequiredLevel": {
// "Value": "Recommended",
// "CanBeChanged": true,
// "ManagedPropertyLogicalName":
// "canmodifyrequirementlevelsettings",
// },
// "MetadataId":
// "32a7e6fc-4283-eb11-aac0-00224800be9c",
// });
// }
// console.log(
// datafieldname[0].value.indexOf("fileUpload") > 0,
// isRequiredField,
// props.props.form["appealForm"].values[
// datafieldname[0].value
// ]
// );
if (
typeof props.props.form["appealForm"].values[
datafieldname[0].value
@@ -147,6 +169,9 @@ let BuildCheckRow = (props) => {
datafieldname[0].value
]
)
: fieldtype[0].value ==
"{16D63FD6-119B-4353-BDCA-18358721C3FE}"
? "ssss"
: props.props.form["appealForm"]
.values[
datafieldname[0].value
+98 -11
View File
@@ -28,6 +28,7 @@ let BuildCheckSection = (props) => {
handleSubmit,
formTitle,
setCurrentSection,
updateCurrentSection,
mandatoryFieldsData,
} = props;
@@ -63,6 +64,54 @@ let BuildCheckSection = (props) => {
alert(1);
};
function bytesToSize(bytes) {
var sizes = ["Bytes", "KB", "MB", "GB", "TB"];
if (bytes == 0) return "0 Byte";
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i];
}
const getThumbnailIconByExtension = (blobName) => {
let fileType = blobName.slice(blobName.lastIndexOf(".") + 1);
switch (fileType) {
case "html":
return "/assets/images/documenttypes/html.png";
break;
case "txt":
return "/assets/images/documenttypes/txt.png";
break;
case "doc":
return "/assets/images/documenttypes/doc.png";
break;
case "pdf":
return "/assets/images/documenttypes/pdf.png";
break;
case "docx":
return "/assets/images/documenttypes/docx.png";
break;
case "csv":
return "/assets/images/documenttypes/csv.png";
break;
case "xlsx":
return "/assets/images/documenttypes/xlsx.png";
break;
case "zip":
return "/assets/images/documenttypes/zip.png";
break;
case "jpeg":
case "jpg":
return "/assets/images/documenttypes/jpg.png";
case "png":
return "/assets/images/documenttypes/png.png";
break;
default:
return "/assets/images/documenttypes/txt.png";
break;
}
};
return (
<div className="govuk-grid-row" key={1222}>
<div className="govuk-grid-column-full">
@@ -88,24 +137,58 @@ let BuildCheckSection = (props) => {
</div>
))}
</dl>
<dl className="govuk-summary-list govuk-!-margin-bottom-9 at-summary-list"></dl>
<dl className="govuk-summary-list govuk-!-margin-bottom-9 at-summary-list">
<div className="govuk-summary-list__row" key={"9999"}>
<dt>
{props.props.appealType.fileList.files.length >
0
? props.props.appealType.fileList.files.map(
(blob, i) => (
<div
key={blob.name + "_" + i}
className="govuk-!-margin-bottom-5 fileThumb "
>
<img
src={getThumbnailIconByExtension(
blob.name
)}
alt={blob.name}
width="50"
/>
<span className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5">
{blob.name} (
{bytesToSize(
blob.contentLength
)}
)
</span>
</div>
)
)
: ""}
</dt>
<dd className="govuk-summary-list__actions">
<a
className="govuk-link"
href="#"
onClick={() => {
updateCurrentSection(sectionCount);
}}
>
{t("newappeal:change-link-label")}
</a>
</dd>
</div>
</dl>
</div>
<div className="govuk-button-group">
<button
type="submit"
onClick={() => {
console.log(props.props.form.appealForm.values);
}}
className="govuk-button"
>
{t("newappeal:submit-appeal-button")}
</button>
<a
className="govuk-button"
data-module="govuk-button"
onClick={() => setCurrentSection(9999)}
>
sss{t("newappeal:submit-appeal-button")}
{t("newappeal:submit-appeal-button")}
</a>
</div>
</div>
@@ -128,6 +211,10 @@ const mapDispatchToProps = (dispatch) => {
setCurrentSection: (currentSection) => {
dispatch(setCurrentSection(currentSection));
},
updateCurrentSection: (whichSection) => {
dispatch(setCurrentSection(whichSection));
dispatch(setFormComplete("true"));
},
};
};
+8 -88
View File
@@ -142,8 +142,14 @@ let BuildSection = (props) => {
};
const onHandleSubmit = (values) => {
//alert(1);
//updateCaseProgress(values);
if (currentSection == sectionCount) {
let valuesObj = values || {};
delete valuesObj["_pinswg_appellant_value"];
updateCaseProgress(valuesObj);
}
setCurrentSection(currentSection + 1);
};
@@ -289,93 +295,7 @@ let BuildSection = (props) => {
currentSection={currentSection}
initialValues={props.initialValues}
/>
{/* <nav
role="navigation"
aria-labelledby="progress-list"
className="at-nav"
>
<h3 className="govuk-heading-s govuk-!-font-weight-bold gov-font-dark-grey progress-heading">
{t("newappeal:new-appeal-progress-nav-label")}:{" "}
<span className="progress-case-reference">
{props.appealType.caseReference.ticketnumber}
</span>
</h3>
<hr className="govuk-section-break govuk-section-break--m govuk-section-break--visible" />
<ol className="govuk-list">
<ul className="govuk-list ">
<li className="at-nav__page">
<ol className="govuk-list">
{Object.keys(titleList).map((key) =>
parseInt(key) + 1 ==
currentSection ? (
<li key={key}>
<b>
{FieldsTranslations(
titleList[key].value
)}{" "}
</b>
</li>
) : (
<li key={key}>
{props.appealType
.formComplete ==
"true" ||
parseInt(key) + 1 <
currentSection ? (
<a
className="govuk-link"
href="#"
onClick={() => {
gotoSection(
parseInt(
key
) + 1
);
}}
>
{FieldsTranslations(
titleList[key]
.value
)}
</a>
) : (
FieldsTranslations(
titleList[key].value
)
)}
</li>
)
)}
</ol>
</li>
</ul>
</ol>
</nav>
{Object.keys(documentListObj).length > 0 && (
<div>
<h3 className="govuk-heading-s govuk-!-font-weight-bold gov-font-dark-grey">
{t("newappeal:new-appeal-documentlist-nav")}:
</h3>
<hr className="govuk-section-break govuk-section-break--m govuk-section-break--visible" />
<ol className="govuk-list document-list">
<ul className="govuk-list ">
<li className="at-nav__page">
<ol className="govuk-list govuk-list--bullet">
{Object.entries(
documentListObj
).map(([key, value]) => {
return (
<li key={key}>{value}</li>
);
})}
</ol>
</li>
</ul>
</ol>
</div>
)} */}
<hr className="govuk-section-break govuk-section-break--m govuk-section-break--visible" />
<button
className="govuk-button govuk-button--secondary progress-save "
+18 -4
View File
@@ -6,6 +6,7 @@ import {
uploadFile,
deleteBlob,
} from "../../../actions/azurestorage";
import { hashAPIPath } from "../../../actions";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
@@ -16,11 +17,24 @@ ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var blobName = req.query.blobname;
console.log(containerName, blobName);
var checkHash = req.query.hash;
await deleteBlob(containerName, "files/" + blobName).then((data) => {
return res.status(200).json({ data: data });
});
var checkquerypath =
"/api/file/deleteblob?container=" +
containerName.toLowerCase() +
"&blobname=" +
blobName;
console.log(hashAPIPath(checkquerypath), checkHash);
console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
await deleteBlob(containerName, "files/" + blobName).then((data) => {
return res.status(200).json({ data: data });
});
} else {
return res.status(400).json();
}
});
export const config = {
-12
View File
@@ -37,18 +37,6 @@ ApiProxy.get(async (req, res) => {
"&blobname=" +
blobName;
console.log(
"containerName " +
containerName +
`\n` +
blobName +
`\n` +
checkHash +
`\n` +
checkquerypath
);
console.log(hashAPIPath(checkquerypath), checkHash);
console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const downloaded = await downloadFile(containerName, blobName);
+14 -4
View File
@@ -5,6 +5,7 @@ import {
createBlob,
uploadFile,
} from "../../../actions/azurestorage";
import { hashAPIPath } from "../../../actions";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
@@ -14,10 +15,19 @@ ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
console.log(containerName);
await getBlobs(containerName).then((data) => {
return res.status(200).json({ files: data });
});
var checkHash = req.query.hash;
var checkquerypath = "/api/file/getbloblist?container=" + containerName;
console.log(hashAPIPath(checkquerypath), checkHash);
console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
await getBlobs(containerName).then((data) => {
return res.status(200).json({ files: data });
});
} else {
return res.status(400).json();
}
});
export const config = {
+10
View File
@@ -13,11 +13,18 @@ const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.post(async (req, res) => {
var checkHash = req.query.hash;
console.log(JSON.parse(req.body.appealData));
console.log(req.files);
const appealData = JSON.parse(req.body.appealData);
// var checkquerypath = "/api/file/upload";
// console.log(hashAPIPath(checkquerypath), checkHash);
// console.log(hashAPIPath(checkquerypath) == "?hash=" + checkHash);
// if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) {
createContainer(appealData.pinswg_name.trim()).then((containerName) => {
createBlob(appealData, containerName).then((data) => {
uploadFile(req.files, containerName, data);
@@ -25,6 +32,9 @@ ApiProxy.post(async (req, res) => {
});
return res.status(200).json({ data: "success" });
// } else {
// return res.status(400).json();
// }
});
export const config = {
+8 -18
View File
@@ -32,6 +32,7 @@ const Home = (props) => {
loginEmailStr,
loggedInUserEmail,
ggLocale,
hasLoginCode,
} = props;
let { t, lang } = useTranslation();
@@ -43,7 +44,7 @@ const Home = (props) => {
expDate.setDate(now.getDate() + 1);
//console.log("hashed email str", loginEmailStr);
_.isEmpty(loggedInUserId) != false && !hasGGCode
hasLoginCode != false
? console.log("no session")
: _.has(loggedInUserId, "value")
? _.isEmpty(loggedInUserId.value)
@@ -144,8 +145,8 @@ const Home = (props) => {
showLogin={showLogin}
showMap={showMap}
loggedInUserId={loggedInUserId}
GG_REDIRECT_URI={props.GG_REDIRECT_URI}
GG_CLIENT_ID={props.GG_CLIENT_ID}
// GG_REDIRECT_URI={props.GG_REDIRECT_URI}
// GG_CLIENT_ID={props.GG_CLIENT_ID}
/>
</>
)}
@@ -172,22 +173,13 @@ export const getServerSideProps = wrapper.getServerSideProps(
const hasLoginCode = thisSession != null;
let providerConfig = await getProviderConfig();
// let providerConfig = await getProviderConfig();
let ggLocale =
typeof query.ui_locales != "undefined" && query.ui_locales;
console.log(
"endpoint: ",
providerConfig.token_endpoint,
"\n",
"hasloginCode:",
hasLoginCode,
"\n",
"redirect:",
process.env.GG_REDIRECT_URI
);
console.log("\n", "hasloginCode:", hasLoginCode);
store.dispatch(getGovGatewayConfig(providerConfig));
// store.dispatch(getGovGatewayConfig(providerConfig));
let ggToken = {};
let ggUserInfo = {};
@@ -219,11 +211,9 @@ export const getServerSideProps = wrapper.getServerSideProps(
ggLocale: ggLocale,
showLogin: showLoginCheck,
showMap: showMapCheck,
hasGGCode: hasLoginCode,
hasSession: hasLoginCode,
loggedInUserId: portalUserObj,
loggedInUserEmail: loginEmailStr,
GG_REDIRECT_URI: process.env.GG_REDIRECT_URI,
GG_CLIENT_ID: process.env.GG_CLIENT_ID,
},
};
}
-7
View File
@@ -179,13 +179,6 @@ export const getServerSideProps = wrapper.getServerSideProps(
await getAwaitingSubmission(loggedInUser),
]);
//const cookiesMaker = nookies.get(ctx)
// console.log(
// "acc details:",
// accountDetails,
// _.has(accountDetails, "errorCode") != false
// );
if (_.has(accountDetails, "errorCode") != false) {
return {
redirect: {
-1
View File
@@ -73,7 +73,6 @@ export const setDocumentsList = (documentList) => (dispatch) => {
};
export const setFilesForAppeal = (fileList) => (dispatch) => {
console.log("have got here");
return dispatch({
type: appealTypeDataActionTypes.SETFILELIST,
fileList: fileList,