Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
6d7eee5
updated db schema
yellalena Apr 13, 2025
858ae9b
updated swagger
yellalena Apr 13, 2025
0f80b01
Mentors feature API design (#85)
yellalena Apr 13, 2025
683e237
updated deployment documentation, added docs on knex migrations
yellalena Apr 15, 2025
a55b334
improved environment logging
yellalena Apr 15, 2025
fb024b1
Deployment and migrations documentation (#92)
yellalena Apr 16, 2025
cb675a1
migrated to pino logger
yellalena Apr 19, 2025
8a208a7
unified logging format
yellalena Apr 19, 2025
3dcc585
added pino-http to log http requests if needed
yellalena Apr 19, 2025
8bde726
integrating discord oauth
vm2052 Apr 21, 2025
48cbf18
updated error res
vm2052 Apr 21, 2025
4ff194b
updated swagger docs
vm2052 Apr 21, 2025
c220a3e
fixed as per comments
vm2052 Apr 29, 2025
db324e0
fixed as per comments
vm2052 May 1, 2025
24ba55f
fixed eslint
vm2052 May 1, 2025
8acd4df
Authentication by Discord (#94)
yellalena May 1, 2025
52c771e
wip: setting up grafana integration
yellalena Apr 29, 2025
15c2aeb
added base docker-compose file, updated docker-compose files for dev …
yellalena May 1, 2025
4b36cb4
Merge branch 'develop' of github.com:catbytes-community/webplatform-b…
yellalena May 1, 2025
b744fdc
removed loki
yellalena May 1, 2025
be362ff
updated docker-compose files
yellalena May 1, 2025
f84a420
Add Pino logging + Grafana integration (#95)
vm2052 May 7, 2025
c409f39
change log level formatting
yellalena May 8, 2025
03620f6
added logs info to readme
yellalena May 8, 2025
7037c4b
Setting up Grafana Dashboards: change log level formatting (#98)
yellalena Jun 7, 2025
5f182d6
fixed custom headers naming and logging for users/login
yellalena Jun 25, 2025
aa4f7d8
updated Swagger
yellalena Jun 25, 2025
542411f
fixed linter errors
yellalena Jun 25, 2025
618c90a
fixed custom headers naming and logging for users/login (#99)
yellalena Jun 25, 2025
f2f7fbd
updated vulnerable dependencies & installed jest
yellalena Jun 25, 2025
4861497
whitelist custom headers for cors
yellalena Jun 25, 2025
03a86ef
whitelist custom headers for cors (#100)
yellalena Jun 25, 2025
2cba25a
tests for users/login + some setups
yellalena Jun 25, 2025
31e59fb
added tests coverage results to gitignore
yellalena Jun 25, 2025
e67b5e5
small cleanup
yellalena Jun 25, 2025
3fe4911
fixed undefined in cookies
yellalena Jun 28, 2025
c04ba26
Fixed undefined in cookies (#101)
marinacatbytes Jun 28, 2025
fd778e2
users routes tests
yellalena Jun 28, 2025
630fad2
authorization middleware tests
yellalena Jun 30, 2025
116cfe8
updated eslint config and fixed linter issues
yellalena Jun 30, 2025
de97a62
added a github workflow config to run unit tests
yellalena Jun 30, 2025
38988cb
Merge branch 'develop' of github.com:catbytes-community/webplatform-b…
yellalena Jun 30, 2025
df0595e
fixed tests after develop merge
yellalena Jun 30, 2025
76abd43
improved github workflows configuration
yellalena Jun 30, 2025
4173eae
application routes tests
yellalena Jul 6, 2025
0f8689c
fixed linter errors in applications routes tests
yellalena Jul 6, 2025
ec7ac8a
added tests for authentication middleware
yellalena Jul 6, 2025
d7399a4
add users/logout endpoint
AnastasiaDevs Jul 20, 2025
1bde6ab
fix
AnastasiaDevs Jul 20, 2025
c6f9b4e
Endpoint for user logout (#105)
yellalena Jul 20, 2025
9cd8496
added makefile
yellalena Aug 31, 2025
33e4032
pr comments
yellalena Aug 31, 2025
388ce3b
Unit Tests & Maintenance (#102)
yellalena Aug 31, 2025
4479195
Merge branch 'develop' of github.com:catbytes-community/webplatform-b…
yellalena Aug 31, 2025
ddc3781
updated makefile
yellalena Aug 31, 2025
4decb47
added deployment commands to the makefile, updated readme
yellalena Aug 31, 2025
242ed39
tiny updates after pr review
yellalena Sep 1, 2025
3a3f1cb
updated readme
yellalena Sep 1, 2025
0208c75
Added Makefile (#107)
yellalena Sep 1, 2025
7559ea6
verifyRole -> verifyRoles
yellalena Sep 14, 2025
4498c5d
linter
yellalena Sep 14, 2025
4b284a0
removed old method to get user roles from user service
yellalena Sep 14, 2025
40a8087
verifyRole -> verifyRoles (#108)
yellalena Sep 14, 2025
dae1e4f
added admin role
yellalena Sep 14, 2025
f6729a4
added endpoints to grant/revoke roles
yellalena Sep 14, 2025
d2572b8
Added admin role (#109)
yellalena Sep 14, 2025
f5336f1
mentors application create and get all mentors + tests
yellalena Sep 14, 2025
ef5453c
add mentor info to GET /user/id
yellalena Sep 14, 2025
23feb5e
small update
yellalena Sep 14, 2025
bd29acd
linter
yellalena Sep 14, 2025
31db6c1
pr comments
yellalena Sep 15, 2025
ca5c517
Create mentor application + Get all mentors (#110)
yellalena Sep 18, 2025
a8c228b
updated swagger
yellalena Sep 18, 2025
f4e0090
Updated swagger (#111)
yellalena Sep 20, 2025
3d60d63
get mentor by id
yellalena Sep 20, 2025
014e441
Get mentor by id (#112)
yellalena Sep 22, 2025
4e17c8d
send email on new mentor application
yellalena Sep 28, 2025
db42198
updated tests
yellalena Sep 28, 2025
ca14bd5
updated email template
yellalena Sep 28, 2025
f279171
Send email to admins on new mentor applications (#116)
yellalena Sep 28, 2025
ffbd76f
adds update mentor status endpoint
marinakim44 Sep 28, 2025
d025964
resolves most PR comments
marinakim44 Sep 29, 2025
b2e1547
removes unused import
marinakim44 Sep 29, 2025
62ab8de
updates swagger and adds tests
marinakim44 Oct 1, 2025
97aebff
remove pending enum from swagger
marinakim44 Oct 1, 2025
2578761
Update routes/mentors.js
marinacatbytes Oct 1, 2025
99baa77
resolves lint issues
marinakim44 Oct 1, 2025
9ad1fe8
updates mentor route test
marinakim44 Oct 1, 2025
1591fd6
adds update mentor status endpoint (#117)
yellalena Oct 1, 2025
a8000cd
send email to applicant on application approval or rejection
marinakim44 Oct 2, 2025
0726fe2
resolves eslint and npm test
marinakim44 Oct 2, 2025
07e0f8a
send email to applicant on application approval or rejection (#121)
yellalena Oct 4, 2025
a5e7c40
adds PATCH method to cors config
marinakim44 Oct 5, 2025
327fe2a
adds PATCH method to cors config (#122)
yellalena Oct 5, 2025
5b8801c
get mentors should return inactive mentors too
yellalena Oct 5, 2025
faf7d31
adds PUT mentor and updateMentor service
marinakim44 Oct 5, 2025
a3fcb3f
Get mentors should return inactive mentors too (#124)
yellalena Oct 5, 2025
fa48abe
prepare for s3 integration
yellalena Oct 5, 2025
f58674d
presigned URL + endpoint
yellalena Oct 5, 2025
5c69aea
updated swagger
yellalena Oct 5, 2025
597b51f
added unit tests
yellalena Oct 5, 2025
a724048
linter
yellalena Oct 5, 2025
af86ecf
update tests with s3_client call check
yellalena Oct 5, 2025
1229436
linter
yellalena Oct 5, 2025
3696c6e
updates PUT mentor as per comments
marinakim44 Oct 5, 2025
eb1a37e
adds DELETE mentors route and service
marinakim44 Oct 5, 2025
413ce7e
updates swagger and adds PUT and DELETE mentor route and service tests
marinakim44 Oct 5, 2025
1b44739
resolves lint issues
marinakim44 Oct 5, 2025
44f3c93
update sswagger.json
marinakim44 Oct 5, 2025
b032531
replace gard coded with enum
marinakim44 Oct 6, 2025
f4c9274
added video_filename to applications table
yellalena Oct 16, 2025
e363f34
added get applications by id, building download link to s3 object
yellalena Oct 16, 2025
603a484
removes verifyMentorOwnership from PUT mentors route and service
marinakim44 Oct 18, 2025
64704c4
updates tests PUT mentor
marinakim44 Oct 18, 2025
dc92771
S3 integration and presigned URL endpoint (#126)
yellalena Oct 18, 2025
024bda1
updated
yellalena Oct 18, 2025
f603544
update swagger
yellalena Oct 18, 2025
b79d68d
linter
yellalena Oct 18, 2025
0322705
Store video filename in application (#127)
yellalena Oct 18, 2025
7105320
changes req.body for PUT mentors and updates tests
marinakim44 Oct 18, 2025
7afa6ea
resolves conflicts with develop branch
marinakim44 Oct 18, 2025
5995140
adds return 0
marinakim44 Oct 18, 2025
5e43100
adds PUT mentor and updateMentor service (#125)
yellalena Oct 18, 2025
72b45fb
update new_mentor_application_email template
AnastasiaDevs Oct 19, 2025
6595271
add attachments to sendEmailOnNewMentorApplication
AnastasiaDevs Oct 19, 2025
b0b0567
feat-128: add tags tables and GET /tags endpoint and tests
marinakim44 Oct 19, 2025
d29dbc2
adjusts lint issues
marinakim44 Oct 19, 2025
81dc6e3
added duplicate knex migration to fix local run issues
yellalena Oct 19, 2025
0784055
added a script to create a test user with application locally
yellalena Oct 19, 2025
307bc06
user deletion functionality
yellalena Oct 19, 2025
a815d8b
added user deletion tests
yellalena Oct 19, 2025
57fd13f
added more tests for user service
yellalena Oct 19, 2025
7628766
linter
yellalena Oct 19, 2025
c623b14
update email template
AnastasiaDevs Oct 19, 2025
c27c44d
update PUT and POST mentor with tags
marinakim44 Oct 19, 2025
aaee0fb
changes as per comments
marinakim44 Oct 19, 2025
f8c9c3d
fixes lint issues
marinakim44 Oct 19, 2025
4fa42eb
removes tag id assertion from tags tests
marinakim44 Oct 20, 2025
31cbcfd
updates test for get tags
marinakim44 Oct 20, 2025
11bb677
feat-128: add tags tables and GET /tags endpoint and tests (#131)
yellalena Oct 20, 2025
8bfabf3
Merge remote-tracking branch 'origin/develop' into feat-129-update-me…
marinakim44 Oct 20, 2025
ab5bded
[Ticket-111] Create HTML email on new appl to mentors (#130)
yellalena Oct 21, 2025
3c6d5e4
Merge branch 'develop' of github.com:catbytes-community/webplatform-b…
yellalena Oct 21, 2025
034ac9d
removed duplicate migration file
yellalena Oct 21, 2025
92eb0c2
User profile and information deletion (#132)
yellalena Oct 21, 2025
bd2ed2a
add languages to mentor profile display
yellalena Oct 25, 2025
a0f47a8
endpoint to send login link if user exists
yellalena Oct 25, 2025
440937b
update swagger
yellalena Oct 25, 2025
91df1fe
lint
yellalena Oct 25, 2025
7be5a61
turn user email and discord username to lowercase before saving
yellalena Oct 25, 2025
c5c7ddd
added knex migration
yellalena Oct 25, 2025
54d054f
updated applications creation
yellalena Oct 25, 2025
de9d1c8
application creation test
yellalena Oct 25, 2025
180907f
lint
yellalena Oct 25, 2025
eb3acfe
add missing awaits
yellalena Oct 26, 2025
b2f0706
add missing awaits (#141)
yellalena Oct 26, 2025
0747a1b
Endpoint to send login link if user exists (#136)
yellalena Oct 26, 2025
c4a0fa7
Add languages to mentor profile display (#135)
yellalena Oct 26, 2025
b0d4933
Set user email and discord username to lowercase before saving (#137)
yellalena Oct 26, 2025
75a1744
resolves conflicts and removes mentor.tags from baseFields
marinakim44 Oct 27, 2025
4a0f8e3
updates tests for tags
marinakim44 Oct 27, 2025
8aeec3f
fix migration
yellalena Oct 28, 2025
5d180f9
fix migration (#142)
yellalena Oct 28, 2025
fc830a2
returns tags in getMentors
marinakim44 Nov 1, 2025
df73e4c
Feat 129 update mentor tags (#133)
yellalena Nov 1, 2025
77ef751
fix mentors status update
yellalena Nov 2, 2025
60d4538
updated tests
yellalena Nov 2, 2025
56845a1
lint
yellalena Nov 2, 2025
bdb95be
add missig await
yellalena Nov 2, 2025
e3f7edc
Fix mentor status update (#143)
yellalena Nov 2, 2025
b4ffa27
fix cors
yellalena Nov 2, 2025
70d15e7
added missing return
yellalena Nov 8, 2025
82549ad
added missing return (#145)
yellalena Nov 8, 2025
40058ab
fix create mentor
yellalena Nov 8, 2025
b4e008d
added migration to remove orphaned mentor roles
yellalena Nov 9, 2025
55c3c0d
fix cors (#144)
yellalena Nov 15, 2025
80bb690
fixed tests
yellalena Nov 23, 2025
4c95e25
Pre release fixes (#153)
yellalena Nov 23, 2025
1f63fe5
updated local run docs
yellalena Nov 29, 2025
66a8053
Updated local run docs (#154)
yellalena Nov 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .github/workflows/eslint.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run all checks before merge

on:
pull_request:
branches:
- main
- develop

jobs:
eslint:
uses: ./.github/workflows/node-env-command.yml
with:
node-version: '20'
commandDescription: 'Run ESLint'
command: 'npx eslint .'

unittests:
uses: ./.github/workflows/node-env-command.yml
with:
node-version: '20'
commandDescription: 'Run Jest tests'
command: 'npm test'
38 changes: 38 additions & 0 deletions .github/workflows/node-env-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Setup Node.js Environment and Run Command

on:
workflow_call:
inputs:
node-version:
description: 'Node.js version'
type: string
default: '20'

commandDescription:
description: 'Description of the command to execute'
required: true
type: string

command:
description: 'Command to execute'
required: true
type: string

jobs:
setup:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}

- name: Install dependencies
run: npm install

- name: ${{ inputs.commandDescription }}
run: ${{ inputs.command }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
node_modules
.env
.env.local
.DS_Store
/.vs
.vscode/
/serviceAccountKey.json
coverage/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ COPY package.json package-lock.json ./
RUN npm install
COPY . .

EXPOSE 3000
EXPOSE 8080
CMD ["node", "server.js"]
91 changes: 91 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
include .env.local
export

# To make sure these targets are not confused with files of the same name
.PHONY: help lint test clean deploy-dev deploy-prod stop-dev stop-prod \
connect-dev connect-prod create-migration apply-migrations rollback-migration

WARN_COLOR := $(shell tput setaf 208)
GREEN_COLOR := $(shell tput setaf 2)
RESET_COLOR := $(shell tput sgr0)

# Development
lint:
npx eslint .

test:
npm test

# EC2 instances connection
connect-dev:
@if [ -z "$(DEV_PRIVATE_KEY_LOCATION)" ] || [ -z "$(DEV_HOST)" ]; then \
echo "Error: DEV_PRIVATE_KEY_LOCATION and DEV_HOST environment variables must be set."; \
exit 1; \
fi
ssh -i $(DEV_PRIVATE_KEY_LOCATION) ec2-user@$(DEV_HOST)

connect-prod:
@if [ -z "$(PROD_PRIVATE_KEY_LOCATION)" ] || [ -z "$(PROD_HOST)" ]; then \
echo "Error: PROD_PRIVATE_KEY_LOCATION and PROD_HOST environment variables must be set."; \
exit 1; \
fi
ssh -i $(PROD_PRIVATE_KEY_LOCATION) ec2-user@$(PROD_HOST)

# Database migrations with knex
create-migration:
knex migrate:make $(name)

apply-migrations:
knex migrate:latest

rollback-migration:
knex migrate:rollback


# EC2 deployment
stop-dev:
docker-compose -f docker-compose.dev.yml down

stop-prod:
docker-compose -f docker-compose.prod.yml down

deploy-env:
@read -p "$(WARN_COLOR)You're about to deploy to the $(env) environment. Please make sure you pulled recent changes, \
installed new dependencies and verified the service starts using npm run as well as applied database migrations. \
Please refer to the /docs/how-tos/aws_ec2_deployment.md for the instructions. \
If you're sure, press Enter to continue.$(RESET_COLOR)" confirm; \

docker-compose -f docker-compose.$(env).yml build --no-cache
docker-compose -f docker-compose.$(env).yml up -d --force-recreate

deploy-dev:
@$(MAKE) deploy-env env=dev

deploy-prod:
@$(MAKE) deploy-env env=prod

help:
@echo ""
@echo "🛠 $(GREEN_COLOR)Makefile Help$(RESET_COLOR)"
@echo ""
@echo "🔧 Development:"
@echo " $(GREEN_COLOR)lint$(RESET_COLOR) Run eslint to check code quality"
@echo " $(GREEN_COLOR)test$(RESET_COLOR) Run unit tests with npm"

@echo ""
@echo "🌐 EC2 Instances:"
@echo " $(GREEN_COLOR)connect-dev$(RESET_COLOR) SSH into the dev EC2 instance"
@echo " $(GREEN_COLOR)connect-prod$(RESET_COLOR) SSH into the prod EC2 instance"

@echo ""
@echo "🛢 Database Migrations (Knex):"
@echo " $(GREEN_COLOR)create-migration$(RESET_COLOR) Create a new migration (usage: make create-migration name=xyz)"
@echo " $(GREEN_COLOR)apply-migrations$(RESET_COLOR) Apply the latest migrations"
@echo " $(GREEN_COLOR)rollback-migration$(RESET_COLOR)Rollback the last migration"

@echo ""
@echo "🚀 Deployment:"
@echo " $(GREEN_COLOR)deploy-dev$(RESET_COLOR) Deploy the dev environment"
@echo " $(GREEN_COLOR)deploy-prod$(RESET_COLOR) Deploy the prod environment"
@echo " $(GREEN_COLOR)stop-dev$(RESET_COLOR) Stop the dev Docker Compose"
@echo " $(GREEN_COLOR)stop-prod$(RESET_COLOR) Stop the prod Docker Compose"
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,48 @@ Located in the `/docs/how-tos` directory. All important information on local run

### How to run project locally

> ⚠️ For simple local run (no breaking changes) you can connect to the remote (DEV) database.

To do that, you have to authenticate with AWS CLI first (ref. `/docs/how-tos/local_run_and_configs.md`)

🚨 For proper development it is **strongly recommended** to use local database. Here's how to do that:

1. Follow `/docs/how-tos/setup_local_postgresql`, step "Setting up Local PostgreSQL instance"
2. Update your .env accordingly. Here is sample .env structure:
2. Use `.env.local` file for environment variables (default `.env` is picked up by Docker so to avoid confusion we use explicit local file for local development). Update your `.env.local` accordingly. Here is sample structure or reach out for up-to-date .env to fellow devs:
```
DB_USER=marina_kim
DB_HOST=localhost
DB_NAME=mydatabase
DB_PASS=password
DB_PORT=5432
ENVIRONMENT=local
ENVIRONMENT=local # the IMPORTANT part!!! this tells the service to use local resources.
```

✅ Once you are authenticated with AWS CLI or you have the local PostgreSQL setup, you can successfully run

```bash
npm start
```
or
```bash
nodemon server.js
```

to start the server.

### Useful commands: Makefile

Refer to the `Makefile` to see commands frequently used in development.
Example usage:

Note: ENVIRONMENT should be set to local for running the project locally, otherwise you have to authenticate with AWS CLI first (ref. `/docs/how-tos/aws_local_db_connection.md`)
```bash
make connect-dev
```
This will execute the `connect-dev` command and connect you to the dev EC2 instance.
Make sure you have all required environment variables set.

Once you are authenticated with AWS CLI or you have the local PostgreSQL setup, you should successfully run `npm start` to start the server
Run
```bash
make help
```
to list all available Makefile commands.
37 changes: 37 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const config = require('config');
const express = require("express");
const cookieParser = require('cookie-parser');
const cors = require("cors");
const { authenticate } = require("./middleware/authentication");
const pinoHttp = require('pino-http');
const { baseLogger } = require('./logger');

require('dotenv').config({ path: '.env.local' });

const app = express();

// Middleware
if (process.env.LOGGING_HTTP_REQUESTS === 'true') {
app.use(pinoHttp({ logger: baseLogger }));
}

app.use(express.json());
app.use(cookieParser());
const corsOptions = {
origin: (origin, callback) => {
if (!origin || config.cors.allowedOrigins.includes(origin)) {
callback(null, origin);
} else {
callback(new Error('Not allowed by CORS'));
}
},
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization', 'X-Firebase-Token', 'X-Discord-Code'],
};

app.use(cors(corsOptions));
app.options('*', cors(corsOptions));
app.use(authenticate());

module.exports = app;
16 changes: 16 additions & 0 deletions appForTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const app = require('./app');
const routes = require('./routes/routes');

// Setting the app up for tests - so it has all the routes
// (we don't need to wait for the database connection in unit-tests)

// to simulate authentication in tests, we read userId from headers
app.use((req, res, next) => {
if (!req.userId && req.headers['userid']) {
req.userId = Number(req.headers['userid']);
}
next();
});
app.use(routes);

module.exports = app;
79 changes: 79 additions & 0 deletions aws/s3_client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3");
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
const config = require("config");

const awsConfig = config.aws;
const s3 = new S3Client({ region: awsConfig.aws_region });

const BUCKET_PREFIXES = {
applications: "videos/applications",
// images and-or other video categories will be added later
};

const MIME_EXTENSION_MAP = {
"video/mp4": "mp4",
"video/webm": "webm",
"video/ogg": "ogv",
"video/quicktime": "mov",
};

async function generateUploadUrl(bucketPrefix, filename, contentType) {
if (!Object.values(BUCKET_PREFIXES).includes(bucketPrefix)) {
throw new Error("Invalid bucket prefix");
}

filename = `${filename}.${MIME_EXTENSION_MAP[contentType]}`;
const fullKey = buildFullObjectKey(bucketPrefix, filename);

const command = new PutObjectCommand({
Bucket: awsConfig.s3_bucket,
Key: fullKey,
ContentType: contentType,
StorageClass: "INTELLIGENT_TIERING", // Cheapest option, auto-moves to colder storage based on access patterns
});

const url = await getSignedUrl(s3, command, { expiresIn: 3600 });
return {
url,
filename,
};
}

async function getDownloadUrl(bucketPrefix, filename) {
if (!Object.values(BUCKET_PREFIXES).includes(bucketPrefix)) {
throw new Error("Invalid bucket prefix");
}

const command = new GetObjectCommand({
Bucket: awsConfig.s3_bucket,
Key: buildFullObjectKey(bucketPrefix, filename)
});

const signedUrl = await getSignedUrl(s3, command, { expiresIn: 3600 });
return signedUrl;
}

async function deleteObject(bucketPrefix, filename) {
if (!Object.values(BUCKET_PREFIXES).includes(bucketPrefix)) {
throw new Error("Invalid bucket prefix");
}

const command = new DeleteObjectCommand({
Bucket: awsConfig.s3_bucket,
Key: buildFullObjectKey(bucketPrefix, filename)
});

await s3.send(command);
}

function buildFullObjectKey(bucketPrefix, filename) {
return `${bucketPrefix}/${filename}`;
}

module.exports = {
BUCKET_PREFIXES,
MIME_EXTENSION_MAP,
generateUploadUrl,
getDownloadUrl,
deleteObject,
};
Loading