Skip to content

Commit

Permalink
Added formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhankarunhale committed Aug 3, 2024
1 parent fb21f0c commit 0301650
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 307 deletions.
22 changes: 10 additions & 12 deletions cdk/lambda/getPresignedUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { S3Client } = require("@aws-sdk/client-s3");
const { createPresignedPost } = require("@aws-sdk/s3-presigned-post");

exports.handler = async (event) => {

console.log("Received event:", JSON.stringify(event));
let body;
try {
Expand All @@ -14,14 +14,14 @@ exports.handler = async (event) => {
body: JSON.stringify({ message: "Invalid request body" }),
};
}
const { key } = body || {}; // Access key from query string parameters

const { key } = body || {};

try {
if (!process.env.BUCKET_NAME) {
throw new Error('BUCKET_NAME environment variable is not defined.');
}

const BUCKET_NAME = process.env.BUCKET_NAME;
if (!process.env.CLOUDFRONT_URL) {
throw new Error('CLOUDFRONT_URL environment variable is not defined.');
Expand All @@ -30,9 +30,9 @@ exports.handler = async (event) => {

const params = {
Bucket: BUCKET_NAME,
Key: key, // Specify the key for the object being uploaded
Expires: 3600,
ContentType: 'multipart/form-data'// Expiration time of the presigned URL in seconds
Key: key,
Expires: 3600,
ContentType: 'multipart/form-data'
};

const s3Client = new S3Client({ region: process.env.AWS_REGION });
Expand All @@ -41,7 +41,7 @@ exports.handler = async (event) => {

return {
statusCode: 200,
headers: {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": CLOUDFRONT_URL,
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Amz-Date, X-Api-Key, X-Amz-Security-Token, X-Amz-User-Agent",
Expand All @@ -59,6 +59,4 @@ exports.handler = async (event) => {
body: JSON.stringify({ message: error.message }),
};
}
};
//aws s3 presign s3://project-documents-654654368612-us-east-1/Transcripts --expires-in 3600
//curl -X PUT -T Transcripts.pdf ''
};
2 changes: 0 additions & 2 deletions cdk/lambda/listFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ exports.handler = async (event) => {
const s3Client = new S3Client({ region: process.env.AWS_REGION });

try {
// List objects in the bucket
const listObjectsCommand = new ListObjectsV2Command({
Bucket: bucketName,
});

const { Contents = [] } = await s3Client.send(listObjectsCommand);

// Generate a list of file keys
const fileList = Contents.map(object => ({
key: object.Key
}));
Expand Down
93 changes: 0 additions & 93 deletions frontend/README.md

This file was deleted.

32 changes: 0 additions & 32 deletions frontend/doc.txt

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "AWS-S3-Secure-File-Manager-Starter",
"name": "AWS CDK Serverless S3 File Manager",
"version": "0.1.0",
"private": true,
"dependencies": {
Expand Down
29 changes: 14 additions & 15 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
/* App.css */
html, body {
margin: 0px;
padding: 0px;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow-x: hidden;
box-sizing: border-box;
background-color: #d3d1d3;
}

.container-fluid {
width: 100%;
margin: 0px;
padding: 0px;
margin: 0;
padding: 0;
}

.App {
background-color: #d3d1d3; /* Light grey background */
min-height: 100vh; /* Full viewport height */
padding: 20px;
background-color: #d3d1d3;
min-height: 100vh;
box-sizing: border-box; /* Optional padding */
padding: 20px;
box-sizing: border-box;
}

.App-header {
background-color: #d3d1d3; /* Dark grey background */
color: white; /* White text */
background-color: #d3d1d3;
color: white;
text-align: center;
}

.text-center {
text-align: center;
}

.App-logo {
width: 400px; /* Adjust as needed */
width: 400px;
height: auto;
display: block;
margin: auto;

}

}
118 changes: 59 additions & 59 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
import React, { useState, useEffect, useCallback } from 'react';
import axios from 'axios';
import FileUpload from './components/FileUpload';
import FileList from './components/FileList';
import { Container, Row, Col, Spinner } from 'react-bootstrap';
import './App.css';
import React, { useState, useEffect, useCallback } from "react";
import axios from "axios";
import FileUpload from "./components/FileUpload";
import FileList from "./components/FileList";
import { Container, Row, Col, Spinner } from "react-bootstrap";
import "./App.css";

const App = () => {
const [files, setFiles] = useState([]);
const [loadingFiles, setLoadingFiles] = useState(false);
const apiUrl = process.env.REACT_APP_API_GATEWAY_URL;
const [files, setFiles] = useState([]);
const [loadingFiles, setLoadingFiles] = useState(false);
const apiUrl = process.env.REACT_APP_API_GATEWAY_URL;

const fetchFiles = useCallback(async () => {
setLoadingFiles(true);
try {
const response = await axios.get(`${apiUrl}listFiles`);
if (response.status === 200) {
setFiles(response.data);
} else {
console.error('Unexpected status code:', response.status);
}
} catch (error) {
console.error('Error fetching files:', error);
} finally {
setLoadingFiles(false);
}
}, [apiUrl]);
const fetchFiles = useCallback(async () => {
setLoadingFiles(true);
try {
const response = await axios.get(`${apiUrl}listFiles`);
if (response.status === 200) {
setFiles(response.data);
} else {
console.error("Unexpected status code:", response.status);
}
} catch (error) {
console.error("Error fetching files:", error);
} finally {
setLoadingFiles(false);
}
}, [apiUrl]);

useEffect(() => {
fetchFiles();
}, [fetchFiles]);
useEffect(() => {
fetchFiles();
}, [fetchFiles]);

const handleFileUploadSuccess = () => {
fetchFiles(); // Reload the file list
};
const handleFileUploadSuccess = () => {
fetchFiles(); // Reload the file list
};

return (
<Container className="App">
<Row className="mb-4">
<Col>
<img src="/logo.gif" alt="Animated Logo" className="App-logo" />
</Col>
</Row>
<Row className="mb-4">
<Col>
<FileUpload apiUrl={apiUrl} onUploadSuccess={handleFileUploadSuccess} />
</Col>
</Row>
<Row>
<Col>
{loadingFiles ? (
<div className="text-center">
<Spinner animation="border" />
<p>Loading files...</p>
</div>
) : (
<FileList files={files} apiUrl={apiUrl} />
)}
</Col>
</Row>
</Container>
);
return (
<Container className="App">
<Row className="mb-4">
<Col>
<img src="/logo.gif" alt="Animated Logo" className="App-logo" />
</Col>
</Row>
<Row className="mb-4">
<Col>
<FileUpload
apiUrl={apiUrl}
onUploadSuccess={handleFileUploadSuccess}
/>
</Col>
</Row>
<Row>
<Col>
{loadingFiles ? (
<div className="text-center">
<Spinner animation="border" />
<p>Loading files...</p>
</div>
) : (
<FileList files={files} apiUrl={apiUrl} />
)}
</Col>
</Row>
</Container>
);
};

export default App;
Loading

0 comments on commit 0301650

Please sign in to comment.