diff --git a/apps/duality-social-node/package.json b/apps/duality-social-node/package.json index ba0fe24..6648fb5 100644 --- a/apps/duality-social-node/package.json +++ b/apps/duality-social-node/package.json @@ -13,11 +13,12 @@ "author": "Freddie Mercurial (Jessica M.) ", "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", diff --git a/apps/duality-social-node/src/middlewares.ts b/apps/duality-social-node/src/middlewares.ts index 419a380..f2baff2 100644 --- a/apps/duality-social-node/src/middlewares.ts +++ b/apps/duality-social-node/src/middlewares.ts @@ -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 diff --git a/apps/duality-social-node/src/services/feed.ts b/apps/duality-social-node/src/services/feed.ts index fc595e6..bf6cb17 100644 --- a/apps/duality-social-node/src/services/feed.ts +++ b/apps/duality-social-node/src/services/feed.ts @@ -1,7 +1,8 @@ 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'; @@ -9,13 +10,16 @@ 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, }); } @@ -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); diff --git a/apps/duality-social-react/src/components/dashboard-page.tsx b/apps/duality-social-react/src/components/dashboard-page.tsx index 1bafd6f..4a913d3 100644 --- a/apps/duality-social-react/src/components/dashboard-page.tsx +++ b/apps/duality-social-react/src/components/dashboard-page.tsx @@ -12,6 +12,7 @@ import { CircularProgress, useTheme, } from '@mui/material'; +import Feed from './feed'; const DashboardPage: React.FC = () => { const theme = useTheme(); @@ -52,48 +53,11 @@ const DashboardPage: React.FC = () => { {/* Main content area */} - {/* Hot Posts */} - - - Hot Posts - - - {['Post 1', 'Post 2', 'Post 3'].map((post, index) => ( - - - - - {index < 2 && } - - ))} - - - - {/* Recent Comments */} - + - Recent Comments + Your Feed - - {['Comment 1', 'Comment 2', 'Comment 3'].map((comment, index) => ( - - - - - {index < 2 && } - - ))} - + diff --git a/apps/duality-social-react/src/components/feed.tsx b/apps/duality-social-react/src/components/feed.tsx index a0853e1..4ec8618 100644 --- a/apps/duality-social-react/src/components/feed.tsx +++ b/apps/duality-social-react/src/components/feed.tsx @@ -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) { @@ -40,11 +40,13 @@ const Feed: React.FC = () => { return ( - {posts.map((post) => ( - - ))} + {posts && posts.length > 0 ? ( + posts.map((post) => ) + ) : ( + No posts to display + )} ); }; -export default Feed; \ No newline at end of file +export default Feed; diff --git a/apps/duality-social-react/src/components/new-post.tsx b/apps/duality-social-react/src/components/new-post.tsx index 38b6841..e04ba7a 100644 --- a/apps/duality-social-react/src/components/new-post.tsx +++ b/apps/duality-social-react/src/components/new-post.tsx @@ -144,23 +144,24 @@ const NewPost: React.FC = ({ multiple disabled={images.length >= AppConstants.MaxPostImages} /> - - + =0.6.0, sax@^1.2.4: +sax@^1.2.4: version "1.4.1" resolved "https://registry.yarnpkg.com/sax/-/sax-1.4.1.tgz#44cc8988377f126304d3b3fc1010c733b929ef0f" integrity sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg== @@ -13962,6 +15026,14 @@ statuses@2.0.1: resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA== +stream-browserify@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-3.0.0.tgz#22b0a2850cdf6503e73085da1fc7b7d0c2122f2f" + integrity sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA== + dependencies: + inherits "~2.0.4" + readable-stream "^3.5.0" + stream-browserify@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.2.tgz#87521d38a44aa7ee91ce1cd2a47df0cb49dd660b" @@ -14174,6 +15246,11 @@ strip-outer@^2.0.0: resolved "https://registry.yarnpkg.com/strip-outer/-/strip-outer-2.0.0.tgz#c45c724ed9b1ff6be5f660503791404f4714084b" integrity sha512-A21Xsm1XzUkK0qK1ZrytDUvqsQWict2Cykhvi0fBQntGG5JSprESasEyV1EZ/4CiR5WB5KjzLTrP/bO37B0wPg== +strnum@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/strnum/-/strnum-1.0.5.tgz#5c4e829fe15ad4ff0d20c3db5ac97b73c9b072db" + integrity sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA== + strong-log-transformer@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/strong-log-transformer/-/strong-log-transformer-2.1.0.tgz#0f5ed78d325e0421ac6f90f7f10e691d6ae3ae10" @@ -14706,7 +15783,7 @@ tslib@^1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== -tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.4.0, tslib@^2.7.0: +tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.3.0, tslib@^2.4.0, tslib@^2.6.2, tslib@^2.7.0: version "2.7.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01" integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA== @@ -15011,14 +16088,6 @@ url-parse@^1.4.3, url-parse@^1.5.3: querystringify "^2.1.1" requires-port "^1.0.0" -url@0.10.3: - version "0.10.3" - resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64" - integrity sha512-hzSUW2q06EqL1gKM/a+obYHLIO6ct2hwPuviqTTOcfFVc61UbfJ2Q32+uGL/HCPxKqrdGB5QUwIe7UqlDgwsOQ== - dependencies: - punycode "1.3.2" - querystring "0.2.0" - url@^0.11.0: version "0.11.4" resolved "https://registry.yarnpkg.com/url/-/url-0.11.4.tgz#adca77b3562d56b72746e76b330b7f27b6721f3c" @@ -15051,27 +16120,11 @@ util@^0.11.0: dependencies: inherits "2.0.3" -util@^0.12.4: - version "0.12.5" - resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc" - integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA== - dependencies: - inherits "^2.0.3" - is-arguments "^1.0.4" - is-generator-function "^1.0.7" - is-typed-array "^1.1.3" - which-typed-array "^1.1.2" - utils-merge@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA== -uuid@8.0.0: - version "8.0.0" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.0.0.tgz#bc6ccf91b5ff0ac07bbcdbf1c7c4e150db4dbb6c" - integrity sha512-jOXGuXZAWdsTH7eZLtyXMqUb9EcWMGZNbL9YcGBJl4MH4nrxHmZJhEHvyLFrkxo+28uLb/NYRcStH48fnD0Vzw== - uuid@^10.0.0: version "10.0.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-10.0.0.tgz#5a95aa454e6e002725c79055fd42aaba30ca6294" @@ -15087,6 +16140,11 @@ uuid@^8.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== +uuid@^9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" + integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== + v8-compile-cache-lib@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" @@ -15496,7 +16554,7 @@ which-module@^2.0.0: resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.1.tgz#776b1fe35d90aebe99e8ac15eb24093389a4a409" integrity sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ== -which-typed-array@^1.1.14, which-typed-array@^1.1.15, which-typed-array@^1.1.2: +which-typed-array@^1.1.14, which-typed-array@^1.1.15: version "1.1.15" resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.15.tgz#264859e9b11a649b388bfaaf4f767df1f779b38d" integrity sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA== @@ -15606,19 +16664,6 @@ xml-name-validator@^4.0.0: resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-4.0.0.tgz#79a006e2e63149a8600f15430f0a4725d1524835" integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw== -xml2js@0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.6.2.tgz#dd0b630083aa09c161e25a4d0901e2b2a929b499" - integrity sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA== - dependencies: - sax ">=0.6.0" - xmlbuilder "~11.0.0" - -xmlbuilder@~11.0.0: - version "11.0.1" - resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" - integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA== - xmlchars@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"