Skip to content

Commit

Permalink
Add new endpoint interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillweston committed May 10, 2024
1 parent a4346c1 commit 563efb5
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 204 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ name: "CodeQL"

on:
push:
branches: [ "main" ]
branches: [ main, develop ]
tags:
- "v*.*.*"
paths-ignore:
- '**.md'
pull_request:
branches: [ "main" ]
branches: [ main, develop ]
paths-ignore:
- '**.md'
schedule:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ name: Docker CI

on:
push:
branches: [ main ]
branches: [ main, develop ]
tags:
- "v*.*.*"
paths-ignore:
- '**.md'
pull_request:
branches: [ main ]
branches: [ main, develop ]
paths-ignore:
- '**.md'

Expand Down Expand Up @@ -41,6 +43,6 @@ jobs:
context: .
file: ./Dockerfile
push: true
tags: phillweston/photoeditor-server:tag
tags: phillweston/photoeditor-server:${{ github.ref_name }}-${{ github.sha }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
30 changes: 30 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: reviewdog

on:
push:
branches: [ main, develop ]
tags:
- "v*.*.*"
paths-ignore:
- '**.md'
pull_request:
branches: [ main, develop ]
paths-ignore:
- '**.md'

jobs:
eslint:
name: runner / eslint
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write

steps:
- uses: actions/checkout@v4
- uses: reviewdog/action-eslint@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review # Change reporter.
eslint_flags: "src/"
2 changes: 1 addition & 1 deletion .github/workflows/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Replace Port in worker.js
run: |
WORKER_NAME=${{ secrets.CLOUDFLARE_WORKER_NAME || 'photo-editor' }}
PORT=${{ secrets.SERVER_HTTP_PORT || '5000' }}
PORT=${{ secrets.SERVER_HTTP_PORT || '6000' }}
sed -i "s/__SERVER_HTTP_PORT__/$PORT/g" worker.js
- name: Publish the Worker
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ARG MIN_TOKEN_AMOUNT
ARG REDIS_HOST="redis"
ARG REDIS_PORT
ARG ENABLE_OCR_DETECTION
ARG ENABLE_USER_ID_VERIFICATION

# Set the working directory in the container
WORKDIR /usr/src/app
Expand Down
141 changes: 10 additions & 131 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,148 +25,25 @@

This is the backend server for the PhotoEditor project. It is a RESTful API server that provides endpoints for the frontend client to interact with the database and the Backblaze B2 cloud storage.

## Diagram

### Upload Image to Server

```mermaid
sequenceDiagram
participant APP as Application
participant BE as Server
participant DB as Database
participant B2 as Backblaze B2
APP->>BE: POST /image-upload
BE->>B2: Upload image to B2
B2-->>BE: Success
BE->>DB: Save user ID and file name
DB-->>BE: Success
BE-->>APP: Success
```

### Download Image from Server

```mermaid
sequenceDiagram
participant APP as Application
participant BE as Server
participant DB as Database
participant B2 as Backblaze B2
APP->>BE: GET /download <br>Parameter: fileName, userId
BE->>B2: Request download link
B2-->>BE: Download image from B2
BE->>DB: Save user ID and file name
DB-->>BE: Success
BE-->>APP: Success <br>Body: Images
```

### Upload Clipboard Info to Server

```mermaid
sequenceDiagram
participant APP as Application
participant BE as Server
participant DB as Database
APP->>BE: GET /mnemonic-upload <br>Parameters: userId, mnemonicPhase
note over BE: Decrypt Mnemonic
note over BE: Calculate Private Key and Wallet Address
BE->>DB: Save user ID, mnemonic, private key, and wallet address
DB-->>BE: Success
BE-->>APP: Success <br>Body: JSON Object
```

### (TODO) APP Version Update

```mermaid
sequenceDiagram
participant APP as Application
participant BE as Server
participant DB as Database
participant B2 as Backblaze B2
APP->>BE: GET /latest-version
BE->>DB: Get latest version
DB-->>BE: Version
BE-->>APP: Version
note over APP: Compare version
APP->>APP: If version is different, update
APP->>BE: GET /latest-release
BE->>B2: Download latest release
B2-->>BE: Success
BE-->>APP: Success <br>Body: Latest release
```

### (TODO) APP Activation

```mermaid
sequenceDiagram
participant APP as Application
participant BE as Server
participant DB as Database
APP->>BE: POST /user-activation <br>Parameters: activationCode, userId
BE->>DB: Check activation code
DB-->>BE: Expiration date
BE-->>APP: Success <br>Body: Expiration date
```

### (TODO) Keyword Query from Database

```mermaid
sequenceDiagram
participant APP as Application
participant BE as Server
participant DB as Database
APP->>BE: GET /image-keywords <br>Parameters: userId
BE->>DB: Get keywords
DB-->>BE: Keywords
BE-->>APP: Keywords
```

### (TODO) OCR Text Recognition with Google Vision API

Refer to the [Google Vision API](https://cloud.google.com/vision/docs/ocr) for more information.

```mermaid
sequenceDiagram
participant APP as Application
participant BE as Server
participant OCR as Google Vision API
participant DB as Database
APP->>BE: POST /image-upload <br>Parameters: userId, image
BE->>OCR: Request text recognition with local image
OCR-->>BE: Text in JSON format
BE->>DB: Save user ID and text
DB-->>BE: Success
BE-->>APP: Success <br>Body: Text
```

### (TODO) Rule Engine for Text Classification

We use json-rules-engine for text classification. Refer to the [json-rules-engine](https://github.com/CacheControl/json-rules-engine) for more information.

```mermaid
sequenceDiagram
participant BE as Server
participant RE as Rule Engine
participant DB as Database
BE->>RE: Request text classification
RE-->>BE: Classification
BE->>DB: Save user ID and classification
DB-->>BE: Success
```

## Endpoints

### Test Endpoint

- `GET /test/ping`

### Auth Endpoints

- `GET /auth/get-challenge`
- `POST /auth/verify-challenge`

### Basic Endpoints

- `POST /basic/image-upload`
Expand Down Expand Up @@ -237,7 +114,7 @@ All possible return codes are as follows:
```env
PRIVKEY_PATH="your_private_key_path"
CERT_PATH="your_cert_path"
SERVER_PORT=5000
SERVER_PORT=6000
B2_ACCOUNT_ID="your_b2_account_id"
B2_APPLICATION_KEY="your_b2_application_key"
B2_BUCKET_ID="your_b2_bucket_id"
Expand Down Expand Up @@ -299,7 +176,7 @@ node src/start.js

Run the Docker container using the following command:
```bash
SERVER_PORT=5000 \
SERVER_PORT=6000 \
MONGODB_DB=userLogs \
MONGODB_PORT=27000 \
MONGODB_USERNAME=admin \
Expand All @@ -322,12 +199,13 @@ ETHEREUM_NETWORK="your_ethereum_network" \
EXPIRATION_TIME_PERIOD="your_expiration_time_period_day" \
MIN_TOKEN_AMOUNT="your_min_token_amount" \
ENABLE_OCR_DETECTION="false" \
ENABLE_USER_ID_VERIFICATION="false" \
docker-compose up -d
```

To remove the Docker container, run:
```bash
SERVER_PORT=5000 \
SERVER_PORT=6000 \
MONGODB_DB=userLogs \
MONGODB_PORT=27000 \
MONGODB_USERNAME=admin \
Expand All @@ -350,6 +228,7 @@ ETHEREUM_NETWORK="your_ethereum_network" \
EXPIRATION_TIME_PERIOD="your_expiration_time_period_day" \
MIN_TOKEN_AMOUNT="your_min_token_amount" \
ENABLE_OCR_DETECTION="false" \
ENABLE_USER_ID_VERIFICATION="false" \
docker-compose down
```

Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
DOCKER_ENV: "true"
PRIVKEY_PATH: ${PRIVKEY_PATH}
CERT_PATH: ${CERT_PATH}
SERVER_PORT: ${SERVER_PORT:-5000}
SERVER_PORT: ${SERVER_PORT:-6000}
MONGODB_DB: ${MONGODB_DB:-userLogs}
MONGODB_HOST: mongodb
MONGODB_PORT: 27017
Expand All @@ -33,8 +33,9 @@ services:
REDIS_HOST: redis
REDIS_PORT: 6379
ENABLE_OCR_DETECTION: ${ENABLE_OCR_DETECTION:-false}
ENABLE_USER_ID_VERIFICATION: ${ENABLE_USER_ID_VERIFICATION:-false}
ports:
- "${SERVER_PORT:-5000}:${SERVER_PORT:-5000}"
- "${SERVER_PORT:-6000}:${SERVER_PORT:-6000}"
depends_on:
- mongodb
- redis
Expand Down
16 changes: 8 additions & 8 deletions src/dbSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const imageUploadSchema = {
},
textJSON: {
bsonType: ["object", 'null'],
description: "must be an object or null and is optional",
description: "must be an object or null and is optional"
},
createdAt: {
bsonType: "date",
Expand Down Expand Up @@ -139,22 +139,22 @@ const subscriptionInfoSchema = {
properties: {
userEmail: {
bsonType: "string",
description: "must be a string and is required",
description: "must be a string and is required"
},
userName: {
bsonType: "string",
description: "must be a string and is optional",
description: "must be a string and is optional"
},
subscriptionInfo: {
bsonType: "string",
description: "must be a string and is optional",
description: "must be a string and is optional"
},
createdAt: {
bsonType: "date",
description: "must be a date and is required",
},
},
},
description: "must be a date and is required"
}
}
}
};

module.exports = {
Expand Down
Loading

0 comments on commit 563efb5

Please sign in to comment.