Skip to content

Commit

Permalink
Upgrade AWS to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaMulein committed Sep 8, 2024
1 parent 6b4f963 commit ec7f459
Show file tree
Hide file tree
Showing 7 changed files with 1,189 additions and 159 deletions.
3 changes: 2 additions & 1 deletion apps/duality-social-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
"author": "Freddie Mercurial (Jessica M.) <jessica@digitaldefiance.org>",
"license": "MIT",
"dependencies": {
"@aws-sdk/client-s3": "^3.645.0",
"@aws-sdk/lib-storage": "^3.645.0",
"@sendgrid/mail": "^8.1.3",
"@types/cors": "^2.8.17",
"@types/express-session": "^1.18.0",
"@types/uuid": "^10.0.0",
"aws-sdk": "^2.1691.0",
"axios": "^1.7.7",
"bcrypt": "^5.1.1",
"bson": "^6.8.0",
Expand Down
9 changes: 8 additions & 1 deletion apps/duality-social-node/src/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export class Middlewares {
};
public static init(app: Application): void {
// Helmet helps you secure your Express apps by setting various HTTP headers
app.use(helmet());
app.use(helmet({
contentSecurityPolicy: {
directives: {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
"img-src": ["'self'", "data:", "blob:"]
}
}
}));
// Enable CORS
app.use(cors(Middlewares.corsOptionsDelegate));
// Parse incoming requests with JSON payloads
Expand Down
24 changes: 17 additions & 7 deletions apps/duality-social-node/src/services/feed.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { Request, Response } from 'express';
import { Schema, Types as MongooseTypes, PipelineStage } from 'mongoose';
import { ObjectId } from 'bson';
import AWS from 'aws-sdk';
import { Upload } from '@aws-sdk/lib-storage';
import { S3 } from '@aws-sdk/client-s3';
import { v4 as uuidv4 } from 'uuid';
import sizeOf from 'image-size';
import { sanitizeWhitespace, HumanityTypeEnum, parsePostContent, IFeedPost, IRequestUser, ModelData, PostModel, PostViewpointModel, PostViewpointReactionModel, PostViewpointHumanityModel, DefaultReactionsTypeEnum, PostImpressionModel, PostExpandModel, IFeedPostViewpoint, AppConstants } from '@duality-social/duality-social-lib';
import { environment } from '../environment';
import { MulterRequest } from '../interfaces/multer-request';

export class FeedService {
private s3: AWS.S3;
private s3: S3;

constructor() {
this.s3 = new AWS.S3({
accessKeyId: environment.aws.accessKeyId,
secretAccessKey: environment.aws.secretAccessKey,
region: environment.aws.region
this.s3 = new S3({
credentials: {
accessKeyId: environment.aws.accessKeyId,
secretAccessKey: environment.aws.secretAccessKey,
},

region: environment.aws.region,
});
}

Expand Down Expand Up @@ -323,7 +327,13 @@ export class FeedService {
};

try {
const uploadResult = await this.s3.upload(uploadParams).promise();
const uploadResult = await new Upload({
client: this.s3,
params: uploadParams,
}).done();
if (!uploadResult || !uploadResult.Location) {
throw new Error('Upload failed');
}
imageUrls.push(uploadResult.Location);
} catch (error) {
console.error('Error uploading image to S3:', error);
Expand Down
44 changes: 4 additions & 40 deletions apps/duality-social-react/src/components/dashboard-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CircularProgress,
useTheme,
} from '@mui/material';
import Feed from './feed';

const DashboardPage: React.FC = () => {
const theme = useTheme();
Expand Down Expand Up @@ -52,48 +53,11 @@ const DashboardPage: React.FC = () => {

{/* Main content area */}
<Box display="flex" gap={3} flexDirection={{ xs: 'column', md: 'row' }}>
{/* Hot Posts */}
<Paper sx={{ p: theme.spacing(2), flex: 1 }}>
<Typography
variant="h6"
sx={{ color: theme.palette.primary.main }}
gutterBottom
>
Hot Posts
</Typography>
<List>
{['Post 1', 'Post 2', 'Post 3'].map((post, index) => (
<React.Fragment key={index}>
<ListItem>
<ListItemText
primary={post}
secondary={`Topic: Sample Topic ${index + 1}`}
/>
</ListItem>
{index < 2 && <Divider />}
</React.Fragment>
))}
</List>
</Paper>

{/* Recent Comments */}
<Paper sx={{ p: 2, flex: 1 }}>
<Paper sx={{ p: 2 }}>
<Typography variant="h6" color="primary" gutterBottom>
Recent Comments
Your Feed
</Typography>
<List>
{['Comment 1', 'Comment 2', 'Comment 3'].map((comment, index) => (
<React.Fragment key={index}>
<ListItem>
<ListItemText
primary={comment}
secondary={`On: Post ${index + 1}`}
/>
</ListItem>
{index < 2 && <Divider />}
</React.Fragment>
))}
</List>
<Feed />
</Paper>
</Box>

Expand Down
12 changes: 7 additions & 5 deletions apps/duality-social-react/src/components/feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Feed: React.FC = () => {
if (token && verifyToken(token)) {
try {
const response = await authenticatedApi.get('/feed', {
headers: { Authorization: `Bearer ${token}` }
headers: { Authorization: `Bearer ${token}` },
});
setPosts(response.data.posts);
} catch (err) {
Expand All @@ -40,11 +40,13 @@ const Feed: React.FC = () => {
return (
<Container maxWidth="md">
<NewPost isBlogPost={false} />
{posts.map((post) => (
<Post key={post.id?.toString()} post={post} />
))}
{posts && posts.length > 0 ? (
posts.map((post) => <Post key={post.id?.toString()} post={post} />)
) : (
<Typography>No posts to display</Typography>
)}
</Container>
);
};

export default Feed;
export default Feed;
27 changes: 14 additions & 13 deletions apps/duality-social-react/src/components/new-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,24 @@ const NewPost: React.FC<NewPostProps> = ({
multiple
disabled={images.length >= AppConstants.MaxPostImages}
/>
<label htmlFor="image-upload">
<Box display="flex" alignItems="center" gap={2} mt={2}>
<label htmlFor="image-upload">
<Button
component="span"
variant="contained"
disabled={images.length >= AppConstants.MaxPostImages}
>
Upload Image
</Button>
</label>
<Button
component="span"
type="submit"
variant="contained"
disabled={images.length >= AppConstants.MaxPostImages}
disabled={formik.isSubmitting}
>
Upload Image
{parentPostId ? 'Reply' : 'Post'}
</Button>
</label>
<Button
type="submit"
variant="contained"
sx={{ mt: 2 }}
disabled={formik.isSubmitting}
>
{parentPostId ? 'Reply' : 'Post'}
</Button>
</Box>
<ImageCropDialog
open={cropDialogOpen}
image={imageToEdit || ''}
Expand Down
Loading

0 comments on commit ec7f459

Please sign in to comment.