Files
pedwfrontend/pages/storage.js
T
2024-06-19 06:32:38 +01:00

101 lines
3.1 KiB
JavaScript

import { DefaultAzureCredential } from "@azure/identity";
import { BlobServiceClient, ContainerClient } from "@azure/storage-blob";
import { v4 as uuidv4 } from "uuid";
import { wrapper } from "../store/store";
import { getIP } from "../actions";
const ShowStorage = (props) => {
const { container } = props;
//console.log("Containers:");
// // for await (const container of blobServiceClient.listContainers()) {
// // console.log(`- ${container.name}`);
// // }
console.log(container);
return <div>hello</div>;
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
getIP(req);
console.log(
"have therese?:",
process.env.AZURE_TENANT_ID,
process.env.AZURE_CLIENT_ID,
process.env.AZURE_CLIENT_SECRET
);
const creds = new DefaultAzureCredential();
const blobServiceClient = new BlobServiceClient(
`https://pedwdev.blob.core.windows.net`,
creds
);
const containerName = `CAS-999999-22222`;
const containerClient = new ContainerClient(
`https://pedwdev.blob.core.windows.net/${containerName}`,
creds
);
//const createContainerResponse = await containerClient.create();
//console.log(
// `Created container ${containerName} successfully`,
// createContainerResponse.requestId
// );
console.log("Containers:");
for await (const container of blobServiceClient.listContainers()) {
console.log(`- ${container.name}`);
}
const appealID = uuidv4();
const uploadOptions = {
metadata: { reviewer: "john", reviewDate: "2022-04-01" },
tags: { owner: appealID },
};
// for (let index = 0; index < 7; index++) {
// // Create a blob
// const content = "hello";
// const blobName = appealID + "/BOBnewblob" + new Date().getTime();
// const blockBlobClient =
// containerClient.getBlockBlobClient(blobName);
// //const uploadBlobResponse = await blockBlobClient.upload(
// // content,
// // Buffer.byteLength(content),
// // uploadOptions
// // );
// const uploadBlobResponse = await blockBlobClient.uploadFile(
// "public/assets/images/HM-Govt-Supplier-to-Govt.jpg"
// // uploadOptions
// );
// const tags = {
// owner: appealID,
// };
// //console.log(tags);
// //await blockBlobClient.setTags(tags);
// //console.log(
// // `Uploaded block blob ${blobName} successfully`,
// // uploadBlobResponse.requestId
// // );
// }
console.log("Blobs:");
for await (const blob of containerClient.listBlobsFlat()) {
console.log(`- ${blob.name}`);
}
}
);
export default ShowStorage;