From b9963bedadf1121ef4872bb6addc21ed0d5ee6e8 Mon Sep 17 00:00:00 2001 From: kemboi590 Date: Wed, 26 Jul 2023 12:05:52 +0300 Subject: [PATCH] env --- .env | 1 + .gitignore | 4 ++-- src/pages/Profile/Profile.jsx | 44 +++++++++-------------------------- 3 files changed, 14 insertions(+), 35 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..26b9a88 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VITE_SAS_TOKEN = 'sv=2022-11-02&ss=bf&srt=sco&sp=rwdlaciytfx&se=2023-08-10T14:42:42Z&st=2023-07-17T06:42:42Z&spr=https&sig=FSiYio%2FYQfHjjD8oHFyWiyXFYNuEpKSiDxqs4GP0sCc%3D' \ No newline at end of file diff --git a/.gitignore b/.gitignore index ca02bf2..57d4e05 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,5 @@ dist-ssr *.sw? # Environment viriables -.env -/env +# .env +# /env diff --git a/src/pages/Profile/Profile.jsx b/src/pages/Profile/Profile.jsx index af3532a..df5354f 100644 --- a/src/pages/Profile/Profile.jsx +++ b/src/pages/Profile/Profile.jsx @@ -6,12 +6,12 @@ import { useNavigate } from "react-router-dom"; import placeholder from "../../Images/placeholder.png"; import Loading from "../../components/Loading/Loading"; import { BlobServiceClient } from "@azure/storage-blob"; -import { MdDelete } from "react-icons/md"; +import { MdDelete } from "react-icons/md"; import { toast } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; import { toastStyles } from "../../toastConfig"; -// Import environment variable + function Profile() { const navigate = useNavigate(); @@ -20,7 +20,7 @@ function Profile() { const [file, setFile] = useState(null); const [loading, setLoading] = useState(false); const [imageUrls, setImageUrls] = useState([]); - const [userImageUrl, setUserImageUrl] = useState(null); // Store the user-specific image URL + const [userImageUrl, setUserImageUrl] = useState(null); let account = "taskminderimagestore"; let sasToken = import.meta.env.VITE_SAS_TOKEN; @@ -35,11 +35,8 @@ function Profile() { const fetchImages = async () => { try { setLoading(true); - const blobServiceClient = new BlobServiceClient( - `https://${account}.blob.core.windows.net` - ); - const containerClient = - blobServiceClient.getContainerClient(containerName); + const blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net`); + const containerClient = blobServiceClient.getContainerClient(containerName); const blobItems = containerClient.listBlobsFlat(); let urls = []; //returns an array of objects with name and url @@ -51,9 +48,7 @@ function Profile() { setLoading(false); // Find the URL for the specific user and set it to the state - const userImage = urls.find( - (url) => url.name === `${userData.user_id}.png` - ); + const userImage = urls.find((url) => url.name === `${userData.user_id}.png`); if (userImage) { setUserImageUrl(userImage.url); } else { @@ -74,11 +69,10 @@ function Profile() { setLoading(true); const blobName = `${userData.user_id}.png`; const blobServiceClient = new BlobServiceClient( - `https://${account}.blob.core.windows.net/?${sasToken}` // Use the SAS token to authenticate + `https://${account}.blob.core.windows.net/?${sasToken}` ); //blobService Client is a class that allows us to interact with the blob storage - const containerClient = - blobServiceClient.getContainerClient(containerName); // Get the container client used to interact with the container + const containerClient = blobServiceClient.getContainerClient(containerName); // Get the container client used to interact with the container const blobClient = containerClient.getBlockBlobClient(blobName); // Get the blob client used to interact with the blob const result = await blobClient.uploadData(file, { blobHTTPHeaders: { blobContentType: file.type }, @@ -95,9 +89,7 @@ function Profile() { }; const deleteImage = async (blobName) => { - const blobServiceClient = new BlobServiceClient( - `https://${account}.blob.core.windows.net/?${sasToken}` - ); + const blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net/?${sasToken}`); const containerClient = blobServiceClient.getContainerClient(containerName); const blobClient = containerClient.getBlockBlobClient(blobName); try { @@ -122,17 +114,7 @@ function Profile() {
- {file ? ( - no pic - ) : userImageUrl ? ( - profile pic - ) : ( - nopic - )} + {file ? no pic : userImageUrl ? profile pic : nopic}
@@ -141,11 +123,7 @@ function Profile() { id="fileInput" onChange={(e) => setFile(e.target.files[0])} // set the file to the state. /> -