Skip to content

Commit

Permalink
refactor: 升级 nestjs 架构
Browse files Browse the repository at this point in the history
  • Loading branch information
027xiguapi committed Dec 13, 2023
1 parent 4223c28 commit a5d04e6
Show file tree
Hide file tree
Showing 59 changed files with 1,217 additions and 874 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"only-build:web": "pnpm run -C packages/web build",
"watch:web": "pnpm run -C packages/web watch",
"project:web": "pnpm run -C packages/web build && node tools/copy-files-web2server.js",
"dev:server": "pnpm run -C packages/server dev",
"dev:server": "pnpm run -C packages/server start:dev",
"build:server": "pnpm run -C packages/server build",
"dev:docs": "pnpm run -C packages/docs dev",
"build:docs": "pnpm run -C packages/docs build",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/electron/main/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const VITE_API_URL = import.meta.env.VITE_API_URL;
// export const WEB_URL = 'http://127.0.0.1:9191/';
// export const VITE_API_URL = 'http://127.0.0.1:9190/';
export const preload = path.join(__dirname, '../preload/index.js');

export const serverPath = path.join(__dirname, '../server/index.js');
export const DIST_ELECTRON = path.join(__dirname, '../');
export const DIST = path.join(DIST_ELECTRON, '../dist');

Expand Down
13 changes: 10 additions & 3 deletions packages/desktop/electron/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { app, BrowserWindow, shell, ipcMain } from 'electron';
import { release } from 'node:os';
import { spawn } from 'node:child_process';
import * as mainWin from '../win/mainWin';
import { initTray } from './tray';
import { update } from './update';
import { registerFileProtocol } from './protocol';
import { registerGlobalShortcut, unregisterAllGlobalShortcut } from './globalShortcut';
import { initConfig, getConfig } from '@pear-rec/server/src/config';
import { serverPath } from './contract';
import './ipcMain';
import '@pear-rec/server/src';

const appName = app.getPath('exe');
const serverAppProcess = spawn(appName, [serverPath]);

initConfig();

Expand All @@ -16,8 +20,10 @@ initConfig();
// ├─┬ dist-electron
// │ ├─┬ main
// │ │ └── index.js > Electron-Main
// │ └─┬ preload
// │ └── index.js > Preload-Scripts
// │ ├─┬ preload
// │ │ └── index.js > Preload-Scripts
// │ └─┬ server
// │ └── index.js > Server-Scripts
// ├─┬ dist
// │ └── index.html > Electron-Renderer
//
Expand Down Expand Up @@ -52,6 +58,7 @@ app.whenReady().then(() => {
});

app.on('will-quit', () => {
serverAppProcess?.kill();
unregisterAllGlobalShortcut();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import pkg from './package.json';

// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
rmSync('dist-electron', { recursive: true, force: true });
// rmSync('dist-electron', { recursive: true, force: true });

const isServe = command === 'serve';
const isBuild = command === 'build';
Expand Down
4 changes: 4 additions & 0 deletions packages/server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @pear-rec/server

## 1.3.0

refactor: 升级 nestjs 架构

## 1.2.5

feat: 重置设置
Expand Down
73 changes: 73 additions & 0 deletions packages/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Installation

```bash
$ pnpm install
```

## Running the app

```bash
# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod
```

## Test

```bash
# unit tests
$ pnpm run test

# e2e tests
$ pnpm run test:e2e

# test coverage
$ pnpm run test:cov
```

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](LICENSE).
8 changes: 8 additions & 0 deletions packages/server/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
65 changes: 35 additions & 30 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
{
"name": "@pear-rec/server",
"version": "1.2.4",
"description": "",
"main": "dist/index.js",
"typings": "index.d.ts",
"version": "1.3.0",
"scripts": {
"dev": "nodemon index.ts",
"build": "rollup -c",
"watch": "rollup -c --watch",
"preview": "node dist/index.js"
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/typeorm": "^10.0.1",
"jsonfile": "^6.1.0",
"multer": "^1.4.5-lts.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
"author": "027xiguapi",
"license": "Apache-2.0",
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-typescript": "^11.1.5",
"@types/cors": "^2.8.14",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/node": "^20.6.0",
"@types/validator": "^13.11.1",
"nodemon": "^3.0.1",
"rollup": "^3.29.3",
"@types/multer": "^1.4.11",
"@types/node": "^20.3.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"http-proxy-middleware": "^2.0.6",
"multer": "1.4.5-lts.1",
"reflect-metadata": "^0.1.13",
"sql.js": "^1.8.0",
"typeorm": "^0.3.17"
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
}
}
21 changes: 0 additions & 21 deletions packages/server/rollup.config.mjs

This file was deleted.

18 changes: 6 additions & 12 deletions packages/server/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { Application, Request, Response } from 'express';
// import { initBaiduProxy } from '../proxy/baidu';
// import { initGoogleProxy } from '../proxy/google';

import { initLocalApi } from './local';
import { initPageProxy } from './page';
import { initBaiduProxy } from '../proxy/baidu';
import { initGoogleProxy } from '../proxy/google';

export function initApi(app: Application) {
initLocalApi(app);
initBaiduProxy(app);
initGoogleProxy(app);
initPageProxy(app);
}
// export function initApi(app: Application) {
// initBaiduProxy(app);
// initGoogleProxy(app);
// }
26 changes: 12 additions & 14 deletions packages/server/src/api/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ import { join, dirname } from 'node:path';
import { Application } from 'express';
import { exec } from 'child_process';
import { getImgsByImgUrl, getAudiosByAudioUrl, getVideosByVideoUrl } from '../util/index';
import { RecordController } from '../controller/RecordController';
import { UserController } from '../controller/UserController';
import { SettingController } from '../controller/SettingController';
import { RecordsService } from '../records/records.service';
import { UsersService } from '../users/users.service';
import { SettingsService } from '../settings/settings.service';
import { PEAR_FILES_PATH } from '../contract';

const recordController = new RecordController();
const userController = new UserController();
const settingController = new SettingController();
// const usersService = new UsersService();

const storage = multer.diskStorage({
destination: async function (req, file, cb) {
const { type, userId } = req.body;
const user = await userController._getUserById(userId);
const setting = await settingController._getSettingByUserId(userId);
// const user = await usersService.findOneById(userId);
// const setting = await settingController._getSettingByUserId(userId);
try {
const filePath = join(setting?.filePath || PEAR_FILES_PATH, `${user.uuid}/${type}`);
if (!fs.existsSync(filePath)) {
fs.mkdirSync(filePath, { recursive: true });
}
cb(null, filePath);
// const filePath = join(setting?.filePath || PEAR_FILES_PATH, `${user.uuid}/${type}`);
// if (!fs.existsSync(filePath)) {
// fs.mkdirSync(filePath, { recursive: true });
// }
// cb(null, filePath);
} catch (err) {
console.log('saveFile err', err);
}
Expand All @@ -45,7 +43,7 @@ const upload = multer({ storage: storage });

export function initLocalApi(app: Application) {
app.post('/saveFile', upload.single('file'), async (req: any, res) => {
recordController.saveFile(req, res);
// recordController.saveFile(req, res);
});

app.get('/getFile', async (req, res) => {
Expand Down
50 changes: 0 additions & 50 deletions packages/server/src/api/page.ts

This file was deleted.

Loading

0 comments on commit a5d04e6

Please sign in to comment.