Skip to content

Commit

Permalink
upgrade frontend to aws sdk v3 + backend linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lkekana committed Jul 30, 2024
1 parent 7e58ead commit 731b641
Show file tree
Hide file tree
Showing 5 changed files with 3,787 additions and 2,259 deletions.
4 changes: 2 additions & 2 deletions backend/src/live/live.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import { Cron } from "@nestjs/schedule";
import { Server, Socket } from "socket.io";
//import { Cron } from "@nestjs/schedule";
import { Server } from "socket.io";

@Injectable()
export class LiveService {
Expand Down
52 changes: 0 additions & 52 deletions frontend/app/screens/rooms/RoomDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,18 @@ import {
import { useLocalSearchParams, useRouter } from "expo-router";
import * as ImagePicker from "expo-image-picker";
import { RoomDetailsProps } from "../../models/roomdetails";
import AWS from "aws-sdk";
import uploadImage from "../../services/ImageUpload";
import auth from "../../services/AuthManagement"; // Import AuthManagement
import * as utils from "../../services/Utils"; // Import Utils
import CyanButton from "../../components/CyanButton";
import { colors } from "../../styles/colors";

import {
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
AWS_S3_BUCKET_NAME,
AWS_S3_REGION,
AWS_S3_ENDPOINT,
} from "react-native-dotenv";

if (!AWS_ACCESS_KEY_ID) {
throw new Error(
"No AWS access key ID (AWS_ACCESS_KEY_ID) provided in environment variables",
);
}

const _AWS_SECRET_ACCESS_KEY = AWS_SECRET_ACCESS_KEY;
if (!_AWS_SECRET_ACCESS_KEY) {
throw new Error(
"No AWS secret access key (AWS_SECRET_ACCESS_KEY) provided in environment variables",
);
}

if (!AWS_S3_BUCKET_NAME) {
throw new Error(
"No AWS bucket name (AWS_S3_BUCKET_NAME) provided in environment variables",
);
}

if (!AWS_S3_REGION) {
throw new Error(
"No AWS region (AWS_S3_REGION) provided in environment variables",
);
}

if (!AWS_S3_ENDPOINT) {
throw new Error(
"No AWS endpoint (AWS_S3_ENDPOINT) provided in environment variables",
);
}

const RoomDetails: React.FC = () => {
const AWS_SECRET_ACCESS_KEY: string = _AWS_SECRET_ACCESS_KEY.replace(
"+",
"+",
);

// console.log(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_NEST_BUCKET_NAME, AWS_S3_REGION, AWS_S3_ENDPOINT)
const router = useRouter();
const { room } = useLocalSearchParams();
// console.log('room', room)
const newRoom = Array.isArray(room) ? JSON.parse(room[0]) : JSON.parse(room);
// console.log('room', newRoom);
AWS.config.update({
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
region: AWS_S3_REGION,
});
AWS.config.logger = console;

const [roomDetails, setRoomDetails] = useState<RoomDetailsProps>({
name: "",
Expand Down
25 changes: 13 additions & 12 deletions frontend/app/services/ImageUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AWS from "aws-sdk";
import { Upload } from "@aws-sdk/lib-storage";
import { S3 } from "@aws-sdk/client-s3";

import {
AWS_ACCESS_KEY_ID,
Expand Down Expand Up @@ -39,17 +40,14 @@ if (!AWS_S3_ENDPOINT) {
);
}

AWS.config.update({
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
region: AWS_S3_REGION,
});
AWS.config.logger = console;

// Create an S3 instance
const s3 = new AWS.S3({
apiVersion: "2006-03-01",
signatureVersion: "v4",
const s3 = new S3({
credentials: {
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY,
},
region: AWS_S3_REGION,
logger: console,
});

const uploadImage = async (imageURI: string, roomName: string) => {
Expand All @@ -62,7 +60,10 @@ const uploadImage = async (imageURI: string, roomName: string) => {
Body: blob,
ContentType: blob.type,
};
const data = await s3.upload(params).promise();
const data = await new Upload({
client: s3,
params,
}).done();
console.log("Successfully uploaded image", data.Location);
return data.Location;
} catch (error) {
Expand Down
Loading

0 comments on commit 731b641

Please sign in to comment.