Skip to content

Commit 1125e2a

Browse files
luch1994luchunhui
and
luchunhui
authored
feat: 修改状态相关功能 (#433)
Co-authored-by: luchunhui <[email protected]>
1 parent 0b4e1fa commit 1125e2a

File tree

213 files changed

+5239
-2220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

213 files changed

+5239
-2220
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ pnpm-debug.log*
2525
*.sw?
2626

2727
.history
28+
2829
components.d.ts
2930

3031
# 默认的上传文件夹
3132
userUpload
33+
exportfile
34+
yarn.lock

DATA_COLLECTION.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Important Disclosure re:XIAOJUSURVEY Data Collection
2+
3+
XIAOJUSURVEY is open-source software developed and maintained by XIAOJUSURVEY Team and available at https://github.com/didi/xiaoju-survey.
4+
We hereby state the purpose and reason for collecting data.
5+
6+
## Purpose of data collection
7+
8+
Data collected is used to help improve XIAOJUSURVEY for all users. It is important that our team understands the usage patterns as soon as possible, so we can best decide how to design future features and prioritize current work.
9+
10+
## Types of data collected
11+
12+
XIAOJUSURVEY just collects data about version's information. The data collected is subsequently reported to the XIAOJUSURVEY's backend services.
13+
14+
All data collected will be used exclusively by the XIAOJUSURVEY team for analytical purposes only. The data will be neither accessible nor sold to any third party.
15+
16+
## Sensitive data
17+
18+
XIAOJUSURVEY will never collect and/or report sensitive information, such as private keys, API keys, or passwords.
19+
20+
## How do I opt-in to or opt-out of data sharing?
21+
22+
See [docs](https://xiaojusurvey.didi.cn/docs/next/community/%E6%95%B0%E6%8D%AE%E9%87%87%E9%9B%86%E5%A3%B0%E6%98%8E) for information on configuring this functionality.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ npm run local
144144

145145
#### 1、配置数据库
146146

147-
> 项目使用 MongoDB,需要提前准备,请查看[如何拥有 MongoDB 指南](./数据库#安装)
147+
> 项目使用 MongoDB,需要提前准备,请查看[如何拥有 MongoDB 指南](https://xiaojusurvey.didi.cn/docs/next/document/%E6%A6%82%E8%BF%B0/%E6%95%B0%E6%8D%AE%E5%BA%93#%E5%AE%89%E8%A3%85)
148148
149-
配置数据库信息,查看[MongoDB 配置](./数据库)
149+
配置数据库信息,查看[MongoDB 配置](https://xiaojusurvey.didi.cn/docs/next/document/%E6%A6%82%E8%BF%B0/%E6%95%B0%E6%8D%AE%E5%BA%93)
150150

151151
#### 2、安装依赖
152152

README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ npm run local
145145

146146
#### 1.Configure Database
147147

148-
> The project uses MongoDB: [MongoDB Guide](https://xiaojusurvey.didi.cn/docs/next/document/%E6%A6%82%E8%BF%B0/%E6%95%B0%E6%8D%AE%E5%BA%93#%E5%AE%89%E8%A3%85)
148+
> The project uses MongoDB: [MongoDB Guide](https://xiaojusurvey.didi.cn/docs/next/document/%E6%A6%82%E8%BF%B0/%E6%95%B0%E6%8D%AE%E5%BA%93)
149149
150150
Configure the database, check MongoDB configuration.
151151

docker-compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
- xiaoju-survey
1616

1717
xiaoju-survey:
18-
image: "xiaojusurvey/xiaoju-survey:1.1.6-slim" # 最新版本:https://hub.docker.com/r/xiaojusurvey/xiaoju-survey/tags
18+
image: "xiaojusurvey/xiaoju-survey:1.2.0-slim" # 最新版本:https://hub.docker.com/r/xiaojusurvey/xiaoju-survey/tags
1919
container_name: xiaoju-survey
2020
restart: always
2121
ports:

nginx/nginx.conf

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ http {
5252
proxy_pass http://127.0.0.1:3000;
5353
}
5454

55+
location /exportfile {
56+
proxy_pass http://127.0.0.1:3000;
57+
}
5558
# 静态文件的默认存储文件夹
5659
# 文件夹的配置在 server/src/modules/file/config/index.ts SERVER_LOCAL_CONFIG.FILE_KEY_PREFIX
5760
location /userUpload {

server/.env

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
XIAOJU_SURVEY_MONGO_DB_NAME=xiaojuSurvey
2-
XIAOJU_SURVEY_MONGO_URL=mongodb://localhost:27017
2+
XIAOJU_SURVEY_MONGO_URL=
33
XIAOJU_SURVEY_MONGO_AUTH_SOURCE=admin
44

5+
XIAOJU_SURVEY_REDIS_HOST=
6+
XIAOJU_SURVEY_REDIS_PORT=
7+
XIAOJU_SURVEY_REDIS_USERNAME=
8+
XIAOJU_SURVEY_REDIS_PASSWORD=
9+
XIAOJU_SURVEY_REDIS_DB=
10+
511

612
XIAOJU_SURVEY_RESPONSE_AES_ENCRYPT_SECRET_KEY=dataAesEncryptSecretKey
713
XIAOJU_SURVEY_HTTP_DATA_ENCRYPT_TYPE=rsa

server/.env.development

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
XIAOJU_SURVEY_REPORT=true
2+
XIAOJU_SURVEY_MONGO_URL=mongodb://127.0.0.1:27017
3+

server/.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pnpm-debug.log*
1313
yarn-debug.log*
1414
yarn-error.log*
1515
lerna-debug.log*
16+
yarn.lock
1617

1718
# OS
1819
.DS_Store
@@ -37,4 +38,6 @@ lerna-debug.log*
3738
!.vscode/launch.json
3839
!.vscode/extensions.json
3940

40-
tmp
41+
tmp
42+
exportfile
43+
userUpload

server/package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@
2222
"@nestjs/common": "^10.0.0",
2323
"@nestjs/config": "^3.1.1",
2424
"@nestjs/core": "^10.0.0",
25+
"@nestjs/microservices": "^10.4.4",
2526
"@nestjs/platform-express": "^10.0.0",
2627
"@nestjs/serve-static": "^4.0.0",
2728
"@nestjs/swagger": "^7.3.0",
2829
"@nestjs/typeorm": "^10.0.1",
2930
"ali-oss": "^6.20.0",
30-
"cheerio": "^1.0.0-rc.12",
31+
"cheerio": "1.0.0-rc.12",
3132
"crypto-js": "^4.2.0",
3233
"dotenv": "^16.3.2",
3334
"fs-extra": "^11.2.0",
35+
"ioredis": "^5.4.1",
3436
"joi": "^17.11.0",
3537
"jsonwebtoken": "^9.0.2",
3638
"lodash": "^4.17.21",
@@ -41,7 +43,9 @@
4143
"nanoid": "^3.3.7",
4244
"node-fetch": "^2.7.0",
4345
"node-forge": "^1.3.1",
46+
"node-xlsx": "^0.24.0",
4447
"qiniu": "^7.11.1",
48+
"redlock": "^5.0.0-beta.2",
4549
"reflect-metadata": "^0.1.13",
4650
"rxjs": "^7.8.1",
4751
"svg-captcha": "^1.4.0",
@@ -70,8 +74,9 @@
7074
"jest": "^29.5.0",
7175
"mongodb-memory-server": "^9.1.4",
7276
"prettier": "^3.0.0",
77+
"redis-memory-server": "^0.11.0",
7378
"source-map-support": "^0.5.21",
74-
"supertest": "^6.3.3",
79+
"supertest": "^7.0.0",
7580
"ts-jest": "^29.1.0",
7681
"ts-loader": "^9.4.3",
7782
"ts-node": "^10.9.1",

server/scripts/run-local.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MongoMemoryServer } from 'mongodb-memory-server';
22
import { spawn } from 'child_process';
3+
// import { RedisMemoryServer } from 'redis-memory-server';
34

45
async function startServerAndRunScript() {
56
// 启动 MongoDB 内存服务器
@@ -8,12 +9,19 @@ async function startServerAndRunScript() {
89

910
console.log('MongoDB Memory Server started:', mongoUri);
1011

12+
// const redisServer = new RedisMemoryServer();
13+
// const redisHost = await redisServer.getHost();
14+
// const redisPort = await redisServer.getPort();
15+
1116
// 通过 spawn 运行另一个脚本,并传递 MongoDB 连接 URL 作为环境变量
1217
const tsnode = spawn(
1318
'cross-env',
1419
[
1520
`XIAOJU_SURVEY_MONGO_URL=${mongoUri}`,
21+
// `XIAOJU_SURVEY_REDIS_HOST=${redisHost}`,
22+
// `XIAOJU_SURVEY_REDIS_PORT=${redisPort}`,
1623
'NODE_ENV=development',
24+
'SERVER_ENV=local',
1725
'npm',
1826
'run',
1927
'start:dev',
@@ -31,9 +39,10 @@ async function startServerAndRunScript() {
3139
console.error(data);
3240
});
3341

34-
tsnode.on('close', (code) => {
42+
tsnode.on('close', async (code) => {
3543
console.log(`Nodemon process exited with code ${code}`);
36-
mongod.stop(); // 停止 MongoDB 内存服务器
44+
await mongod.stop(); // 停止 MongoDB 内存服务器
45+
// await redisServer.stop();
3746
});
3847
}
3948

server/scripts/run-report.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import fs, { promises as fsa } from 'fs-extra';
2+
import path from 'path';
3+
import fetch from 'node-fetch';
4+
5+
interface PackageJson {
6+
type?: string;
7+
name?: string;
8+
version?: string;
9+
description?: string;
10+
id?: string;
11+
msg?: string;
12+
}
13+
14+
const getId = () => {
15+
const id = new Date().getTime().toString();
16+
process.env.XIAOJU_SURVEY_REPORT_ID = id;
17+
18+
return id;
19+
};
20+
21+
const readData = async (directory: string): Promise<PackageJson | null> => {
22+
const packageJsonPath = path.join(directory, 'package.json');
23+
const id = process.env.XIAOJU_SURVEY_REPORT_ID || getId();
24+
try {
25+
if (!fs.existsSync(directory)) {
26+
return {
27+
type: 'server',
28+
name: '',
29+
version: '',
30+
description: '',
31+
id,
32+
msg: '文件不存在',
33+
};
34+
}
35+
const data = await fsa.readFile(packageJsonPath, 'utf8').catch((e) => e);
36+
const { name, version, description } = JSON.parse(data) as PackageJson;
37+
return { type: 'server', name, version, description, id };
38+
} catch (error) {
39+
return error;
40+
}
41+
};
42+
43+
(async (): Promise<void> => {
44+
if (
45+
process.env.NODE_ENV === 'development' &&
46+
!process.env.XIAOJU_SURVEY_REPORT
47+
) {
48+
return;
49+
}
50+
51+
const res = await readData(path.join(process.cwd()));
52+
53+
// 上报
54+
fetch('https://xiaojusurveysrc.didi.cn/reportSourceData', {
55+
method: 'POST',
56+
headers: {
57+
Accept: 'application/json, */*',
58+
'Content-Type': 'application/json',
59+
},
60+
body: JSON.stringify(res),
61+
}).catch((e) => {
62+
console.log(99999, e);
63+
});
64+
})();

server/src/app.module.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@ import { MessagePushingLog } from './models/messagePushingLog.entity';
3636
import { WorkspaceMember } from './models/workspaceMember.entity';
3737
import { Workspace } from './models/workspace.entity';
3838
import { Collaborator } from './models/collaborator.entity';
39+
import { DownloadTask } from './models/downloadTask.entity';
40+
import { Session } from './models/session.entity';
3941

4042
import { LoggerProvider } from './logger/logger.provider';
4143
import { PluginManagerProvider } from './securityPlugin/pluginManager.provider';
4244
import { LogRequestMiddleware } from './middlewares/logRequest.middleware';
43-
import { XiaojuSurveyPluginManager } from './securityPlugin/pluginManager';
45+
import { PluginManager } from './securityPlugin/pluginManager';
4446
import { Logger } from './logger';
4547

4648
@Module({
4749
imports: [
48-
ConfigModule.forRoot({}),
50+
ConfigModule.forRoot({
51+
envFilePath: `.env.${process.env.NODE_ENV}`, // 根据 NODE_ENV 动态加载对应的 .env 文件
52+
isGlobal: true, // 使配置模块在应用的任何地方可用
53+
}),
4954
TypeOrmModule.forRootAsync({
5055
imports: [ConfigModule],
5156
inject: [ConfigService],
@@ -82,6 +87,8 @@ import { Logger } from './logger';
8287
Workspace,
8388
WorkspaceMember,
8489
Collaborator,
90+
DownloadTask,
91+
Session,
8592
],
8693
};
8794
},
@@ -116,7 +123,7 @@ import { Logger } from './logger';
116123
export class AppModule {
117124
constructor(
118125
private readonly configService: ConfigService,
119-
private readonly pluginManager: XiaojuSurveyPluginManager,
126+
private readonly pluginManager: PluginManager,
120127
) {}
121128
configure(consumer: MiddlewareConsumer) {
122129
consumer.apply(LogRequestMiddleware).forRoutes('*');
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export enum DOWNLOAD_TASK_STATUS {
2+
WAITING = 'waiting', // 排队中
3+
COMPUTING = 'computing', // 计算中
4+
SUCCEED = 'succeed', // 导出成功
5+
FAILED = 'failed', // 导出失败
6+
}

server/src/enums/exceptionCode.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum EXCEPTION_CODE {
1212
SURVEY_TYPE_ERROR = 3003, // 问卷类型错误
1313
SURVEY_NOT_FOUND = 3004, // 问卷不存在
1414
SURVEY_CONTENT_NOT_ALLOW = 3005, // 存在禁用内容
15+
SURVEY_SAVE_CONFLICT = 3006, // 问卷冲突
1516
CAPTCHA_INCORRECT = 4001, // 验证码不正确
1617
WHITELIST_ERROR = 4002, // 白名单校验错误
1718

server/src/enums/index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
export enum RECORD_STATUS {
33
NEW = 'new', // 新建 | 未发布
44
PUBLISHED = 'published', // 发布
5-
CLOSE = 'close', // 关闭
5+
EDITING = 'editing', // 编辑
6+
FINISHED = 'finished', // 已结束
7+
REMOVED = 'removed',
68
}
79

810
export const enum RECORD_SUB_STATUS {
911
DEFAULT = '', // 默认
10-
EDITING = 'editing', // 编辑
1112
PAUSING = 'pausing', // 暂停
12-
REMOVED = 'removed', // 删除
13-
FORCE_REMOVED = 'forceRemoved', // 从回收站删除
1413
}
1514

1615
// 历史类型
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum SESSION_STATUS {
2+
ACTIVATED = 'activated',
3+
DEACTIVATED = 'deactivated',
4+
}

0 commit comments

Comments
 (0)