Merged PR 1815: Ticketnumber on watched cases and storage browser
Related work items: #18356
This commit is contained in:
@@ -1696,7 +1696,12 @@ export const listBlobHierarchical = async (
|
|||||||
export async function listBlobHierarchicalForUser(containerClient) {
|
export async function listBlobHierarchicalForUser(containerClient) {
|
||||||
const blobNames = [];
|
const blobNames = [];
|
||||||
for await (const blob of containerClient.listBlobsFlat()) {
|
for await (const blob of containerClient.listBlobsFlat()) {
|
||||||
blobNames.push(blob.name);
|
// blobNames.push(blob.name);
|
||||||
|
|
||||||
|
blobNames.push({
|
||||||
|
name: blob.name,
|
||||||
|
size: blob.properties.contentLength || 0, // in bytes
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return blobNames;
|
return blobNames;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-9
@@ -1431,7 +1431,7 @@ export const deleteMyRepresentationsFromBlob = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteWatchedCases = (watchedCaseID) => {
|
export const deleteWatchedCases = async (watchedCaseID) => {
|
||||||
var queryUrl =
|
var queryUrl =
|
||||||
"/api/endpoint/deletewatchedcases_api?watchedCaseID=" + watchedCaseID;
|
"/api/endpoint/deletewatchedcases_api?watchedCaseID=" + watchedCaseID;
|
||||||
var config = {
|
var config = {
|
||||||
@@ -1439,14 +1439,12 @@ export const deleteWatchedCases = (watchedCaseID) => {
|
|||||||
url: queryUrl,
|
url: queryUrl,
|
||||||
};
|
};
|
||||||
|
|
||||||
return axios(config)
|
try {
|
||||||
.then((res) => {
|
const res = await axios(config);
|
||||||
//console.log("deleted ", res.data);
|
return res.data;
|
||||||
return res.data;
|
} catch (error) {
|
||||||
})
|
consoleLogger(error);
|
||||||
.catch((error) => {
|
}
|
||||||
consoleLogger(error);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createAccount = (formValues) => {
|
export const createAccount = (formValues) => {
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ const TopThree = (props) => {
|
|||||||
props.accountDetails
|
props.accountDetails
|
||||||
.containerID,
|
.containerID,
|
||||||
showTopThreeArr[key]
|
showTopThreeArr[key]
|
||||||
.pinswg_name,
|
.ticketnumber,
|
||||||
showTopThreeArr[key]
|
showTopThreeArr[key]
|
||||||
.repfile_name
|
.repfile_name
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -878,7 +878,10 @@ const ViewAllResults = (props) => {
|
|||||||
deleteWatchedCases(caseID)
|
deleteWatchedCases(caseID)
|
||||||
.then((data) => data)
|
.then((data) => data)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
getWatchedCasesProxy(cookies.pinsUser).then((data) => {
|
console.log("in heree");
|
||||||
|
getWatchedCasesProxy(
|
||||||
|
props.accountDetails.loggedinUserId
|
||||||
|
).then((data) => {
|
||||||
setWatchedCases(data),
|
setWatchedCases(data),
|
||||||
getDetailsProxy(data, "myWatchedCases")
|
getDetailsProxy(data, "myWatchedCases")
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default async function ApiProxy(req, res) {
|
|||||||
var queryUrl =
|
var queryUrl =
|
||||||
"pinswg_watchlists?$filter= _pinswg_contact_value eq " +
|
"pinswg_watchlists?$filter= _pinswg_contact_value eq " +
|
||||||
loggedInUserId +
|
loggedInUserId +
|
||||||
"&$select=modifiedon,pinswg_appealcasetype,pinswg_watchlistid,_pinswg_watchedcase_value,statuscode&$count=true&$orderby=createdon desc&$expand=pinswg_WatchedCase($select=pinswg_AssociatedLPA)";
|
"&$select=modifiedon,pinswg_appealcasetype,pinswg_watchlistid,_pinswg_watchedcase_value,statuscode,pinswg_representationsubmitted,pinswg_representationtype&$count=true&$orderby=createdon desc&$expand=pinswg_WatchedCase($select=pinswg_AssociatedLPA)";
|
||||||
|
|
||||||
return axios
|
return axios
|
||||||
.get(
|
.get(
|
||||||
@@ -51,6 +51,33 @@ export default async function ApiProxy(req, res) {
|
|||||||
azureHeaders(token.access_token)
|
azureHeaders(token.access_token)
|
||||||
)
|
)
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
|
data.value.forEach(function (element) {
|
||||||
|
element.ticketnumber = element.pinswg_WatchedCase.ticketnumber;
|
||||||
|
element.pinswg_title =
|
||||||
|
element[
|
||||||
|
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||||
|
];
|
||||||
|
|
||||||
|
element[
|
||||||
|
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||||
|
] =
|
||||||
|
element.pinswg_WatchedCase[
|
||||||
|
"_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue"
|
||||||
|
];
|
||||||
|
element._pinswg_associatedlpa_value =
|
||||||
|
element.pinswg_WatchedCase._pinswg_associatedlpa_value;
|
||||||
|
element[
|
||||||
|
"_ownerid_value@OData.Community.Display.V1.FormattedValue"
|
||||||
|
] =
|
||||||
|
element.pinswg_WatchedCase[
|
||||||
|
"_ownerid_value@OData.Community.Display.V1.FormattedValue"
|
||||||
|
];
|
||||||
|
element._ownerid_value =
|
||||||
|
element.pinswg_WatchedCase._ownerid_value;
|
||||||
|
|
||||||
|
delete element.pinswg_WatchedCase;
|
||||||
|
});
|
||||||
|
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|||||||
@@ -24,10 +24,19 @@ ApiProxy.get(async (req, res) => {
|
|||||||
"&blobname=" +
|
"&blobname=" +
|
||||||
blobName.trim();
|
blobName.trim();
|
||||||
|
|
||||||
|
// console.log(checkquerypath);
|
||||||
|
|
||||||
|
// console.log(hashAPIPath(checkquerypath));
|
||||||
|
|
||||||
|
// console.log(req.query);
|
||||||
|
|
||||||
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
|
if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
|
||||||
|
const bloblocation =
|
||||||
|
casefolderID + (blobName.indexOf(".json") > 0 ? "/" : "/files/");
|
||||||
|
|
||||||
const downloaded = await downloadFile(
|
const downloaded = await downloadFile(
|
||||||
containerName,
|
containerName,
|
||||||
casefolderID + "/files/" + decodeURI(blobName)
|
bloblocation + decodeURI(blobName)
|
||||||
);
|
);
|
||||||
|
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
import { DefaultAzureCredential } from "@azure/identity";
|
||||||
|
import { BlobServiceClient } from "@azure/storage-blob";
|
||||||
|
|
||||||
|
export default async function handler(req, res) {
|
||||||
|
if (req.method !== "POST") {
|
||||||
|
res.status(405).json({ error: "Method not allowed" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { container, blobName } = req.body;
|
||||||
|
|
||||||
|
if (!container || !blobName) {
|
||||||
|
res.status(400).json({ error: "Missing container or blobName" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME;
|
||||||
|
const creds = new DefaultAzureCredential();
|
||||||
|
const blobServiceClient = new BlobServiceClient(
|
||||||
|
`https://${accountName}.blob.core.windows.net`,
|
||||||
|
creds
|
||||||
|
);
|
||||||
|
|
||||||
|
const containerClient = blobServiceClient.getContainerClient(container);
|
||||||
|
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
|
||||||
|
|
||||||
|
// Download blob content
|
||||||
|
const downloadResponse = await blockBlobClient.download(0);
|
||||||
|
const downloaded = await streamToString(
|
||||||
|
downloadResponse.readableStreamBody
|
||||||
|
);
|
||||||
|
|
||||||
|
// Parse JSON
|
||||||
|
const json = JSON.parse(downloaded);
|
||||||
|
|
||||||
|
// Remove repComplete element if it exists
|
||||||
|
if ("repComplete" in json) {
|
||||||
|
delete json.repComplete;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tags = {
|
||||||
|
containerid: json.containerID,
|
||||||
|
caseID: json.ticketnumber,
|
||||||
|
blobType: "Representation",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert back to string
|
||||||
|
const updatedContent = JSON.stringify(json, null, 2);
|
||||||
|
|
||||||
|
// Upload updated content (overwrite)
|
||||||
|
await blockBlobClient.upload(
|
||||||
|
updatedContent,
|
||||||
|
Buffer.byteLength(updatedContent),
|
||||||
|
{
|
||||||
|
blobHTTPHeaders: { blobContentType: "application/json" },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("the tags:", tags);
|
||||||
|
const withTags = await blockBlobClient.setTags(tags);
|
||||||
|
const withMeta = await blockBlobClient.setMetadata(tags);
|
||||||
|
|
||||||
|
res.status(200).json({ message: "repComplete removed successfully" });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error editing rep.json:", error);
|
||||||
|
res.status(500).json({ error: "Failed to edit rep.json" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to read stream to string
|
||||||
|
async function streamToString(readableStream) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const chunks = [];
|
||||||
|
readableStream.on("data", (data) => {
|
||||||
|
chunks.push(data.toString());
|
||||||
|
});
|
||||||
|
readableStream.on("end", () => {
|
||||||
|
resolve(chunks.join(""));
|
||||||
|
});
|
||||||
|
readableStream.on("error", reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
+442
-28
@@ -7,10 +7,238 @@ import {
|
|||||||
listBlobHierarchical,
|
listBlobHierarchical,
|
||||||
listContainersForUser,
|
listContainersForUser,
|
||||||
} from "../actions/azurestorage";
|
} from "../actions/azurestorage";
|
||||||
|
import Link from "next/link";
|
||||||
import { PrismaClient } from "@prisma/client";
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
import {
|
||||||
|
bytesToSize,
|
||||||
|
getThumbnailIconByExtension,
|
||||||
|
updateLinks,
|
||||||
|
} from "../components/utils";
|
||||||
|
import {
|
||||||
|
consoleLogger,
|
||||||
|
getIP,
|
||||||
|
sendRepCompleteMessage,
|
||||||
|
deleteMyRepresentationsFromBlob,
|
||||||
|
} from "../actions";
|
||||||
|
import CryptoJS from "crypto-js";
|
||||||
|
|
||||||
import { consoleLogger, getIP } from "../actions";
|
function getUpToLastSlash(url) {
|
||||||
|
let lastSlash = url.lastIndexOf("/");
|
||||||
|
|
||||||
|
url = url.substring(0, lastSlash);
|
||||||
|
|
||||||
|
url =
|
||||||
|
url.lastIndexOf("/files") > 0
|
||||||
|
? url.substring(0, url.lastIndexOf("/files"))
|
||||||
|
: url;
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function streamToString(readableStream) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const chunks = [];
|
||||||
|
readableStream.on("data", (data) => {
|
||||||
|
chunks.push(data.toString());
|
||||||
|
});
|
||||||
|
readableStream.on("end", () => {
|
||||||
|
resolve(chunks.join(""));
|
||||||
|
});
|
||||||
|
readableStream.on("error", reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteRepItem = (containerID, caseID, repfile) => {
|
||||||
|
deleteMyRepresentationsFromBlob(containerID, caseID, repfile).then(
|
||||||
|
(data) => {
|
||||||
|
console.log("======== rep deleted =========");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function StoragePage({ data }) {
|
||||||
|
console.log(data);
|
||||||
|
return (
|
||||||
|
<div className="govuk-width-container">
|
||||||
|
<div className="govuk-main-wrapper govuk-main-wrapper--auto-spacing">
|
||||||
|
<h1>Storage Account Contents</h1>
|
||||||
|
{data.map((user) => (
|
||||||
|
<div key={user.id} className="govuk-grid-row">
|
||||||
|
{user.containers.map((c) => (
|
||||||
|
<div key={c.container} className="card">
|
||||||
|
<div className="card-body">
|
||||||
|
<h3>
|
||||||
|
{c.container} - {user.email}
|
||||||
|
</h3>
|
||||||
|
{c.folders.map((folder) => (
|
||||||
|
<div key={folder.folderPath}>
|
||||||
|
<h4>
|
||||||
|
{folder.folderPath || "Root"}
|
||||||
|
</h4>
|
||||||
|
{/* {folder.hasRepJson && (
|
||||||
|
<p>
|
||||||
|
rep.json file found:{" "}
|
||||||
|
{folder.repJsonBlob.name}
|
||||||
|
</p>
|
||||||
|
)} */}
|
||||||
|
{folder.hasRepJson && (
|
||||||
|
<div>
|
||||||
|
{" "}
|
||||||
|
<button
|
||||||
|
title={
|
||||||
|
"Do you want to delete rep"
|
||||||
|
}
|
||||||
|
className=" cardModuleRemoveCase govuk-link govuk-link--no-underline govuk-link--inverse "
|
||||||
|
onClick={() => {
|
||||||
|
confirm(
|
||||||
|
"Do you want tyo delete rep " +
|
||||||
|
folder.repJsonBlob.name.split(
|
||||||
|
"/"
|
||||||
|
)[0] +
|
||||||
|
"?\n"
|
||||||
|
) &&
|
||||||
|
(deleteRepItem(
|
||||||
|
c.container,
|
||||||
|
folder.repJsonBlob.name.split(
|
||||||
|
"/"
|
||||||
|
)[0],
|
||||||
|
folder.repJsonBlob.name.split(
|
||||||
|
"/"
|
||||||
|
)[1]
|
||||||
|
),
|
||||||
|
alert(
|
||||||
|
"Rep Deleted!"
|
||||||
|
),
|
||||||
|
window.location.reload());
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Delete Rep
|
||||||
|
</button>
|
||||||
|
{folder.repComplete && (
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
const response =
|
||||||
|
await fetch(
|
||||||
|
"/api/file/editRepJson",
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers:
|
||||||
|
{
|
||||||
|
"Content-Type":
|
||||||
|
"application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(
|
||||||
|
{
|
||||||
|
container:
|
||||||
|
c.container,
|
||||||
|
blobName:
|
||||||
|
folder
|
||||||
|
.repJsonBlob
|
||||||
|
.name,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const result =
|
||||||
|
await response.json();
|
||||||
|
if (
|
||||||
|
response.ok
|
||||||
|
) {
|
||||||
|
alert(
|
||||||
|
"repComplete removed!"
|
||||||
|
),
|
||||||
|
window.location.reload();
|
||||||
|
// Optionally refresh the page or update UI state here
|
||||||
|
} else {
|
||||||
|
alert(
|
||||||
|
"Error: " +
|
||||||
|
result.error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Remove repComplete
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{folder.repComplete && (
|
||||||
|
<button
|
||||||
|
onClick={async () => {
|
||||||
|
confirm(
|
||||||
|
"Do you want resend the rep queue message " +
|
||||||
|
folder.repJsonBlob.name.split(
|
||||||
|
"/"
|
||||||
|
)[0] +
|
||||||
|
" --- " +
|
||||||
|
folder.repJsonBlob.name.split(
|
||||||
|
"/"
|
||||||
|
)[1]
|
||||||
|
) &&
|
||||||
|
(sendRepCompleteMessage(
|
||||||
|
c.container,
|
||||||
|
folder.repJsonBlob.name.split(
|
||||||
|
"/"
|
||||||
|
)[0],
|
||||||
|
folder.repJsonBlob.name.split(
|
||||||
|
"/"
|
||||||
|
)[1]
|
||||||
|
),
|
||||||
|
alert(
|
||||||
|
"rep queue message sent!"
|
||||||
|
),
|
||||||
|
window.location.reload());
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Recreate Queue
|
||||||
|
Message
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{folder.blobs.map((blob) => (
|
||||||
|
<li key={blob.name}>
|
||||||
|
<Link
|
||||||
|
scroll={false}
|
||||||
|
href={
|
||||||
|
"/api/file/downloadblob?container=" +
|
||||||
|
c.container +
|
||||||
|
"&casefolderID=" +
|
||||||
|
folder.folderPath +
|
||||||
|
"&blobname=" +
|
||||||
|
blob.name
|
||||||
|
.substring(
|
||||||
|
blob.name.lastIndexOf(
|
||||||
|
"/"
|
||||||
|
) + 1
|
||||||
|
)
|
||||||
|
.trim() +
|
||||||
|
"&hash=" +
|
||||||
|
blob.hashedfilepath
|
||||||
|
}
|
||||||
|
className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5 govuk-link"
|
||||||
|
>
|
||||||
|
{blob.name} (
|
||||||
|
{bytesToSize(
|
||||||
|
blob.contentLength ||
|
||||||
|
blob.size
|
||||||
|
)}
|
||||||
|
)
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export async function getServerSideProps({ req }) {
|
export async function getServerSideProps({ req }) {
|
||||||
// Load allowed IPs from env and trim spaces
|
// Load allowed IPs from env and trim spaces
|
||||||
@@ -54,41 +282,227 @@ export async function getServerSideProps({ req }) {
|
|||||||
|
|
||||||
const users = await prisma.user.findMany();
|
const users = await prisma.user.findMany();
|
||||||
|
|
||||||
const data = await Promise.all(
|
const hashAPIPath = (queryPath, WORDKEY) => {
|
||||||
|
var hashlink = CryptoJS.HmacSHA256(
|
||||||
|
queryPath,
|
||||||
|
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||||
|
);
|
||||||
|
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||||
|
return hashlink;
|
||||||
|
};
|
||||||
|
|
||||||
|
let data = await Promise.all(
|
||||||
users.map(async (user) => {
|
users.map(async (user) => {
|
||||||
const containers = await listContainersForUser(
|
const containers = await listContainersForUser(
|
||||||
blobServiceClient,
|
blobServiceClient,
|
||||||
`${user.id}`,
|
`${user.id}`,
|
||||||
user.email
|
user.email
|
||||||
);
|
);
|
||||||
return containers.length > 0
|
|
||||||
? { id: user.id, email: user.email, containers }
|
// Add hashedName for each blob
|
||||||
|
// const containersWithHashes = containers.map((container) => {
|
||||||
|
// console.log("eee ");
|
||||||
|
|
||||||
|
// const groupedByFolder = container.blobs.reduce((acc, blob) => {
|
||||||
|
// // Get folder path - everything before last slash, or "" if no slash
|
||||||
|
// const folderPath = getUpToLastSlash(blob.name.trim()) || "";
|
||||||
|
|
||||||
|
// const hashedfilepath = hashAPIPath(
|
||||||
|
// "/api/file/downloadblob?container=" +
|
||||||
|
// container.container +
|
||||||
|
// "&casefolderID=" +
|
||||||
|
// folderPath +
|
||||||
|
// "&blobname=" +
|
||||||
|
// blob.name
|
||||||
|
// .substring(blob.name.lastIndexOf("/") + 1)
|
||||||
|
// .trim(),
|
||||||
|
// process.env.HASHKEY
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const blobWithHash = { ...blob, hashedfilepath };
|
||||||
|
|
||||||
|
// // Find or create folder group
|
||||||
|
// let folderGroup = acc.find(
|
||||||
|
// (f) => f.folderPath === folderPath
|
||||||
|
// );
|
||||||
|
// if (!folderGroup) {
|
||||||
|
// folderGroup = { folderPath, blobs: [] };
|
||||||
|
// acc.push(folderGroup);
|
||||||
|
// }
|
||||||
|
// folderGroup.blobs.push(blobWithHash);
|
||||||
|
|
||||||
|
// return acc;
|
||||||
|
// }, []);
|
||||||
|
|
||||||
|
// console.log(groupedByFolder);
|
||||||
|
// return {
|
||||||
|
// ...container,
|
||||||
|
// blobs: container.blobs.map((blob) => ({
|
||||||
|
// ...blob,
|
||||||
|
// hashedfilepath: hashAPIPath(
|
||||||
|
// "/api/file/downloadblob?container=" +
|
||||||
|
// container.container +
|
||||||
|
// "&casefolderID=" +
|
||||||
|
// getUpToLastSlash(blob.name.trim()) +
|
||||||
|
// "&blobname=" +
|
||||||
|
// blob.name
|
||||||
|
// .substring(blob.name.lastIndexOf("/") + 1)
|
||||||
|
// .trim(),
|
||||||
|
// process.env.HASHKEY
|
||||||
|
// ),
|
||||||
|
// })),
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const containersWithHashes = containers.map((container) => {
|
||||||
|
// const groupedByFolder = container.blobs.reduce((acc, blob) => {
|
||||||
|
// const folderPath = getUpToLastSlash(blob.name.trim()) || "";
|
||||||
|
|
||||||
|
// const hashedfilepath = hashAPIPath(
|
||||||
|
// "/api/file/downloadblob?container=" +
|
||||||
|
// container.container +
|
||||||
|
// "&casefolderID=" +
|
||||||
|
// folderPath +
|
||||||
|
// "&blobname=" +
|
||||||
|
// blob.name
|
||||||
|
// .substring(blob.name.lastIndexOf("/") + 1)
|
||||||
|
// .trim(),
|
||||||
|
// process.env.HASHKEY
|
||||||
|
// );
|
||||||
|
|
||||||
|
// const blobWithHash = { ...blob, hashedfilepath };
|
||||||
|
|
||||||
|
// let folderGroup = acc.find(
|
||||||
|
// (f) => f.folderPath === folderPath
|
||||||
|
// );
|
||||||
|
// if (!folderGroup) {
|
||||||
|
// folderGroup = {
|
||||||
|
// folderPath,
|
||||||
|
// blobs: [],
|
||||||
|
// hasRepJson: false, // flag
|
||||||
|
// repJsonBlob: null, // save the rep.json blob if found
|
||||||
|
// };
|
||||||
|
// acc.push(folderGroup);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// folderGroup.blobs.push(blobWithHash);
|
||||||
|
|
||||||
|
// // Check if this blob ends with "rep.json"
|
||||||
|
// if (blob.name.toLowerCase().endsWith("rep.json")) {
|
||||||
|
// folderGroup.hasRepJson = true;
|
||||||
|
// folderGroup.repJsonBlob = blobWithHash;
|
||||||
|
// // You can also do some processing here if you want
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return acc;
|
||||||
|
// }, []);
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// ...container,
|
||||||
|
// folders: groupedByFolder,
|
||||||
|
// // Optionally remove flat blobs if you don't want them
|
||||||
|
// // blobs: undefined,
|
||||||
|
// };
|
||||||
|
// });
|
||||||
|
|
||||||
|
const containersWithHashes = await Promise.all(
|
||||||
|
containers.map(async (container) => {
|
||||||
|
const groupedByFolder = await container.blobs.reduce(
|
||||||
|
async (accP, blob) => {
|
||||||
|
// Because we'll do async read, reduce needs to be async, so accP is a Promise
|
||||||
|
const acc = await accP;
|
||||||
|
|
||||||
|
const folderPath =
|
||||||
|
getUpToLastSlash(blob.name.trim()) || "";
|
||||||
|
|
||||||
|
const hashedfilepath = hashAPIPath(
|
||||||
|
"/api/file/downloadblob?container=" +
|
||||||
|
container.container +
|
||||||
|
"&casefolderID=" +
|
||||||
|
folderPath +
|
||||||
|
"&blobname=" +
|
||||||
|
blob.name
|
||||||
|
.substring(
|
||||||
|
blob.name.lastIndexOf("/") + 1
|
||||||
|
)
|
||||||
|
.trim(),
|
||||||
|
process.env.HASHKEY
|
||||||
|
);
|
||||||
|
|
||||||
|
const blobWithHash = { ...blob, hashedfilepath };
|
||||||
|
|
||||||
|
let folderGroup = acc.find(
|
||||||
|
(f) => f.folderPath === folderPath
|
||||||
|
);
|
||||||
|
if (!folderGroup) {
|
||||||
|
folderGroup = {
|
||||||
|
folderPath,
|
||||||
|
blobs: [],
|
||||||
|
hasRepJson: false,
|
||||||
|
repJsonBlob: null,
|
||||||
|
repComplete: false, // new flag
|
||||||
|
};
|
||||||
|
acc.push(folderGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
folderGroup.blobs.push(blobWithHash);
|
||||||
|
|
||||||
|
// If this blob ends with rep.json, fetch and parse JSON
|
||||||
|
if (blob.name.toLowerCase().endsWith("rep.json")) {
|
||||||
|
folderGroup.hasRepJson = true;
|
||||||
|
folderGroup.repJsonBlob = blobWithHash;
|
||||||
|
|
||||||
|
// Read blob content from Azure Storage
|
||||||
|
const containerClient =
|
||||||
|
blobServiceClient.getContainerClient(
|
||||||
|
container.container
|
||||||
|
);
|
||||||
|
const blockBlobClient =
|
||||||
|
containerClient.getBlockBlobClient(
|
||||||
|
blob.name
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const downloadResponse =
|
||||||
|
await blockBlobClient.download(0);
|
||||||
|
const downloaded = await streamToString(
|
||||||
|
downloadResponse.readableStreamBody
|
||||||
|
);
|
||||||
|
|
||||||
|
const json = JSON.parse(downloaded);
|
||||||
|
folderGroup.repComplete = Boolean(
|
||||||
|
json.repComplete
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(
|
||||||
|
"Error reading or parsing rep.json",
|
||||||
|
err
|
||||||
|
);
|
||||||
|
folderGroup.repComplete = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
Promise.resolve([])
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...container,
|
||||||
|
folders: groupedByFolder,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return containersWithHashes.length > 0
|
||||||
|
? {
|
||||||
|
id: user.id,
|
||||||
|
email: user.email,
|
||||||
|
containers: containersWithHashes,
|
||||||
|
}
|
||||||
: null;
|
: null;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
return { props: { data: data.filter(Boolean) } };
|
return { props: { data: data.filter(Boolean) } };
|
||||||
}
|
}
|
||||||
export default function StoragePage({ data }) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<h1>Storage Account Contents</h1>
|
|
||||||
{data.map((user) => (
|
|
||||||
<div key={user.id}>
|
|
||||||
{user.containers.map((c) => (
|
|
||||||
<div key={c.container}>
|
|
||||||
<h3>
|
|
||||||
{c.container} - {user.email}
|
|
||||||
</h3>
|
|
||||||
<ul>
|
|
||||||
{c.blobs.map((blob) => (
|
|
||||||
<li key={blob}>{blob}</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user