Skip to content

Commit

Permalink
Merge pull request #183 from AprilNEA/ENG-56
Browse files Browse the repository at this point in the history
  • Loading branch information
AprilNEA authored Dec 10, 2023
2 parents 41eecd8 + 7c9daa6 commit c30081d
Show file tree
Hide file tree
Showing 50 changed files with 1,599 additions and 265 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/frontend-bundle-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ defaults:

jobs:
analyze:
name: Frontend Analyze Bundle
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.12.0
Expand All @@ -21,6 +26,14 @@ jobs:

- uses: actions/checkout@v4

- name: Cache turbo build setup
uses: actions/cache@v3
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- uses: pnpm/action-setup@v2.4.0

- name: Install Node.js
Expand All @@ -30,7 +43,7 @@ jobs:
cache: 'pnpm'

- name: Install Dependencies
run: pnpm i
run: pnpm install

- name: Restore Next.js Build
uses: actions/cache@v3
Expand All @@ -46,7 +59,7 @@ jobs:

- name: Build Next.js App
# change this if your site requires a custom build command
run: cd packages/frontend && ./node_modules/.bin/next build
run: pnpm run build:frontend

# Here's the first place where next-bundle-analysis' own script is used
# This step pulls the raw bundle stats for the current bundle
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Test Suite

on:
push:
branches: ["v3","v3-dev"]
pull_request:
types: [opened, synchronize]

jobs:
test:
name: Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest
# To use Remote Caching, uncomment the next lines and follow the steps below.
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Cache turbo build setup
uses: actions/cache@v3
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- uses: pnpm/action-setup@v2.0.1
with:
version: 6.32.2

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: Test
run: pnpm test
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ English</a></h4>
<a href="https://github.com/AprilNEA/ChatGPT-Admin-Web/issues?q=is%3Aissue+is%3Aclosed" target="_blank">
<img alt="GitHub closed issues" src="https://img.shields.io/github/issues-closed/AprilNEA/ChatGPT-Admin-Web.svg?style=flat-square"></a>
<br/>
<img src="https://hits-app.vercel.app/hits?url=https%3A%2F%2Fgithub.com%2FAprilNEA%2FChatGPT-Admin-Web" />
<img src="https://hits.siyue.best/v1/hits?url=https://github.com/AprilNEA/ChatGPT-Admin-Web&bgRight=000&bgLeft=000&border=square" />

</div>
<div align="left">CAW 是一个自托管网络应用程序,提供开箱即用的用户管理,包括后台界面以及可配置的支付计划和相关支付界面。</div>
Expand All @@ -35,7 +35,7 @@ English</a></h4>

| | |
|---------------------------------------------------------------------------|---------------------------------------------------------------------------|
| <img src=https://s2.loli.net/2023/11/10/53Q4ZodyIhvmaHt.png width="500"/> | |
| <img src=https://s2.loli.net/2023/11/10/53Q4ZodyIhvmaHt.png width="500"/> | |
| <img src=https://s2.loli.net/2023/11/10/KoieRB9jnTxgCuz.png width="500"/> | <img src=https://s2.loli.net/2023/11/10/kI8z2auXcnFGwTe.png width="500"/> |

## 开始
Expand All @@ -50,6 +50,18 @@ English</a></h4>
| [V2](https://github.com/AprilNEA/ChatGPT-Admin-Web/tree/v2) | 弃用 | 存在设计缺陷 |
| [V1](https://github.com/AprilNEA/ChatGPT-Admin-Web/tree/main) | 不再更新 | Redis数据库,可拓展性较差 |

[更新日志](https://manual.sku.moe/project/chatgpt-admin-web/update-log)

## 技术栈

| Part | Tech |
|:---------|:-------------------|
| Frontend | Next.js |
| Backend | Nest.js |
| Database | PostgreSQL & Redis |

更多技术细节:[开发手册](https://manual.sku.moe/project/chatgpt-admin-web/development)

## 项目动态

![Alt](https://repobeats.axiom.co/api/embed/67fc3464887e0956a6225b4c5c6579c2699d8363.svg "Repobeats analytics image")
Expand All @@ -62,7 +74,6 @@ English</a></h4>
<img src="https://contrib.rocks/image?repo=AprilNEA/ChatGPT-Admin-Web" />
</a>


## 捐赠

感谢您的激励,能让该项目持续发展。
Expand Down
15 changes: 14 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<a href="https://github.com/AprilNEA/ChatGPT-Admin-Web/issues?q=is%3Aissue+is%3Aclosed" target="_blank">
<img alt="GitHub closed issues" src="https://img.shields.io/github/issues-closed/AprilNEA/ChatGPT-Admin-Web.svg?style=flat-square"></a>
<br/>
<img src="https://hits-app.vercel.app/hits?url=https%3A%2F%2Fgithub.com%2FAprilNEA%2FChatGPT-Admin-Web" />
<img src="https://hits.siyue.best/v1/hits?url=https://github.com/AprilNEA/ChatGPT-Admin-Web&bgRight=000&bgLeft=000&border=square" />

</div>
<div align="left">CAW(ChatGPT-Admin-Web) is a self-hosted web application that provides out-of-the-box user management including a back-end interface as well as configurable payment plans and related payment interfaces.</div>
Expand Down Expand Up @@ -51,6 +51,19 @@ For configuration and installation, see [documentation](https://manual.sku.moe/p
| [V2](https://github.com/AprilNEA/ChatGPT-Admin-Web/tree/v2) | :x: Deprecated | Flawed design |
| [V1](https://github.com/AprilNEA/ChatGPT-Admin-Web/tree/main) | :o: No longer updated | Redis database, less scalable |

[Update Log](https://manual.sku.moe/project/chatgpt-admin-web/update-log)


## 技术栈

| Part | Tech |
|:---------|:-------------------|
| Frontend | Next.js |
| Backend | Nest.js |
| Database | PostgreSQL & Redis |

You can go to [Developer Manual](https://manual.sku.moe/project/chatgpt-admin-web/development) for more technical details.

## Project Status

![Alt](https://repobeats.axiom.co/api/embed/67fc3464887e0956a6225b4c5c6579c2699d8363.svg "Repobeats analytics image")
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
],
"scripts": {
"build": "turbo run build",
"build:frontend": "turbo run build --filter frontend",
"dev": "turbo run dev --parallel",
"start": "turbo run start",
"lint": "turbo run lint",
"test": "vitest run",
"prettier": "prettier --write .",
"db:init": "prisma db push && prisma db seed",
"db:generate": "prisma generate"
Expand All @@ -26,10 +28,14 @@
"@trivago/prettier-plugin-sort-imports": "latest",
"@types/node": "latest",
"prettier": "latest",
"prisma": "5.6.0",
"ts-node": "latest",
"turbo": "latest",
"typescript": "latest",
"prisma": "5.6.0"
"vite": "^5.0.7",
"vite-tsconfig-paths": "^4.2.2",
"vitest": "^1.0.2",
"zod": "latest"
},
"prisma": {
"schema": "prisma/schema.prisma",
Expand Down
10 changes: 3 additions & 7 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
"dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config test/jest-e2e.json"
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"dependencies": {
"@liaoliaots/nestjs-redis": "^9.0.5",
Expand All @@ -38,7 +33,8 @@
"prisma-extension-pagination": "^0.5.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"spark-md5": "^3.0.2"
"spark-md5": "^3.0.2",
"zod": "*"
},
"devDependencies": {
"@nestjs/cli": "^10.2.1",
Expand Down
22 changes: 22 additions & 0 deletions packages/backend/src/common/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,26 @@ export class ConfigService {
fs.writeFileSync(this.configFilePath, jsonData, 'utf8');
this.loadConfig();
}

checkEmailEnable() {
return (
this.get('email') &&
this.get('email').use &&
this.get('email').use !== 'disable'
);
}

checkSMSEnable() {
return (
this.get('sms') &&
this.get('sms').use &&
this.get('sms').use !== 'disable'
);
}

checkNotifierEnable(all = false) {
return all
? this.checkEmailEnable() && this.checkSMSEnable()
: this.checkEmailEnable() || this.checkSMSEnable();
}
}
4 changes: 4 additions & 0 deletions packages/backend/src/common/exceptions/biz.exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ export const ErrorCode = Object.freeze<
});

export class BizException extends HttpException {
code: ErrorCodeEnum;

constructor(code: ErrorCodeEnum) {
const [message, chMessage, statusCode] = ErrorCode[code];
super(
HttpException.createBody({ success: false, code, message, chMessage }),
statusCode,
);

this.code = code;
}
}
19 changes: 19 additions & 0 deletions packages/backend/src/common/pipes/zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ZodObject } from 'zod';

import { ArgumentMetadata, PipeTransform } from '@nestjs/common';

import { BizException } from '@/common/exceptions/biz.exception';

import { ErrorCodeEnum } from 'shared';

export class ZodValidationPipe implements PipeTransform {
constructor(private schema: ZodObject<any>) {}

transform(value: unknown, metadata: ArgumentMetadata) {
try {
return this.schema.parse(value);
} catch (error) {
throw new BizException(ErrorCodeEnum.ValidationError);
}
}
}
Loading

0 comments on commit c30081d

Please sign in to comment.