mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 18:18:27 -05:00
refactor(tools): remove screenshot-service (#61172)
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
# Define project root argument
|
||||
ARG PROJECT_DIR=tools/screenshot-service
|
||||
|
||||
# Build the app
|
||||
FROM node:22-alpine AS builder
|
||||
ARG PROJECT_DIR
|
||||
|
||||
RUN npm i -g pnpm@10
|
||||
USER node
|
||||
WORKDIR /home/node/build
|
||||
|
||||
COPY --chown=node:node *.* .
|
||||
COPY --chown=node:node ${PROJECT_DIR} ${PROJECT_DIR}
|
||||
|
||||
RUN pnpm install --frozen-lockfile --ignore-scripts -F=./${PROJECT_DIR}
|
||||
|
||||
RUN pnpm -F=./${PROJECT_DIR} build
|
||||
|
||||
# Install production dependencies
|
||||
FROM node:22-alpine AS deps
|
||||
ARG PROJECT_DIR
|
||||
|
||||
RUN npm i -g pnpm@10
|
||||
USER node
|
||||
WORKDIR /home/node/build
|
||||
|
||||
COPY --chown=node:node pnpm*.yaml .
|
||||
COPY --chown=node:node ${PROJECT_DIR} ${PROJECT_DIR}
|
||||
|
||||
RUN pnpm install --prod --ignore-scripts --frozen-lockfile -F=./${PROJECT_DIR}
|
||||
|
||||
# App runner instance
|
||||
FROM node:22-alpine AS runner
|
||||
ARG PROJECT_DIR
|
||||
|
||||
USER node
|
||||
WORKDIR /home/node/fcc
|
||||
|
||||
# Copy the built app
|
||||
COPY --from=builder --chown=node:node /home/node/build/${PROJECT_DIR}/dist ./
|
||||
|
||||
# Copy the production dependencies
|
||||
COPY --from=deps --chown=node:node /home/node/build/node_modules/ node_modules/
|
||||
COPY --from=deps --chown=node:node /home/node/build/${PROJECT_DIR}/node_modules ${PROJECT_DIR}/node_modules/
|
||||
|
||||
ENV PORT 3003
|
||||
|
||||
# Run the app
|
||||
CMD [ "node", "./tools/screenshot-service/index.js" ]
|
||||
@@ -158,7 +158,6 @@ export default tseslint.config(
|
||||
'tools/scripts/**/*.ts',
|
||||
'tools/challenge-helper-scripts/**/*.ts',
|
||||
'tools/challenge-auditor/**/*.ts',
|
||||
'tools/screenshot-service/**/*.ts',
|
||||
'e2e/**/*.ts'
|
||||
],
|
||||
extends: [tseslint.configs.recommendedTypeChecked]
|
||||
|
||||
1360
pnpm-lock.yaml
generated
1360
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,6 @@ packages:
|
||||
- 'tools/client-plugins/*'
|
||||
- 'tools/crowdin'
|
||||
- 'tools/daily-challenges'
|
||||
- 'tools/screenshot-service'
|
||||
- 'tools/scripts/build'
|
||||
- 'tools/scripts/seed'
|
||||
- 'tools/scripts/seed-exams'
|
||||
|
||||
3
tools/screenshot-service/.gitignore
vendored
3
tools/screenshot-service/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
node_modules/
|
||||
.env
|
||||
dist/
|
||||
@@ -1,29 +0,0 @@
|
||||
# Screenshot Service
|
||||
|
||||
## Development
|
||||
|
||||
To install dependencies:
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
To run:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
Build the Docker image:
|
||||
|
||||
```bash
|
||||
docker build -t screenshot-service -f ./docker/screenshot-service/Dockerfile .
|
||||
```
|
||||
|
||||
Run the Docker container:
|
||||
|
||||
```bash
|
||||
docker run -d -p 3003:3003 screenshot-service
|
||||
```
|
||||
@@ -1,59 +0,0 @@
|
||||
import {
|
||||
PutObjectCommand,
|
||||
S3Client,
|
||||
type PutObjectCommandInput,
|
||||
type PutObjectCommandOutput
|
||||
} from '@aws-sdk/client-s3';
|
||||
import express, { type Request, type Response } from 'express';
|
||||
|
||||
interface ImageUploadRequest {
|
||||
image: string;
|
||||
examAttemptId: string;
|
||||
}
|
||||
|
||||
const app = express();
|
||||
|
||||
// Parse JSON bodies (in case images are sent as Base64 strings)
|
||||
app.use(express.json({ limit: '5mb' }));
|
||||
|
||||
// Configure S3
|
||||
const s3 = new S3Client({
|
||||
region: process.env.AWS_REGION,
|
||||
credentials: {
|
||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '',
|
||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? ''
|
||||
}
|
||||
});
|
||||
|
||||
const uploadToS3 = (
|
||||
image: string,
|
||||
examAttemptId: string
|
||||
): Promise<PutObjectCommandOutput> => {
|
||||
const params: PutObjectCommandInput = {
|
||||
Bucket: process.env.S3_BUCKET_NAME as string,
|
||||
Key: `${examAttemptId}/${Date.now()}`,
|
||||
Body: Buffer.from(image, 'base64'),
|
||||
ContentType: 'image/jpeg'
|
||||
};
|
||||
|
||||
return s3.send(new PutObjectCommand(params));
|
||||
};
|
||||
|
||||
// Route to handle image uploads from another backend
|
||||
app.post(
|
||||
'/upload',
|
||||
async (req: Request<object, object, ImageUploadRequest>, res: Response) => {
|
||||
try {
|
||||
await uploadToS3(req.body.image, req.body.examAttemptId);
|
||||
res.status(200).json({ message: 'Image uploaded successfully' });
|
||||
} catch (err) {
|
||||
console.error('Error uploading image:', err);
|
||||
res.status(500).json({ error: (err as Error).message });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const port = process.env.PORT || 3003;
|
||||
app.listen(port, () => {
|
||||
console.log(`Server running on port ${port}`);
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "@freecodecamp/exam-screenshot-service",
|
||||
"version": "1.0.0",
|
||||
"devDependencies": {
|
||||
"@types/express": "5.0.1",
|
||||
"tsx": "4.19.1",
|
||||
"typescript": "5.8.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-s3": "3.777.0",
|
||||
"express": "5.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsx watch index.ts"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
AWS_REGION=
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
S3_BUCKET_NAME=
|
||||
PORT=3003
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"module": "Node16",
|
||||
"moduleResolution": "nodenext",
|
||||
"allowJs": false,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "../../"
|
||||
},
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user