Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: 修改状态相关功能 #433

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ pnpm-debug.log*
*.sw?

.history

components.d.ts

# 默认的上传文件夹
userUpload
exportfile
yarn.lock
22 changes: 22 additions & 0 deletions DATA_COLLECTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Important Disclosure re:XIAOJUSURVEY Data Collection

XIAOJUSURVEY is open-source software developed and maintained by XIAOJUSURVEY Team and available at https://github.com/didi/xiaoju-survey.
We hereby state the purpose and reason for collecting data.

## Purpose of data collection

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.

## Types of data collected

XIAOJUSURVEY just collects data about version's information. The data collected is subsequently reported to the XIAOJUSURVEY's backend services.

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.

## Sensitive data

XIAOJUSURVEY will never collect and/or report sensitive information, such as private keys, API keys, or passwords.

## How do I opt-in to or opt-out of data sharing?

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.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ npm run local

#### 1、配置数据库

> 项目使用 MongoDB,需要提前准备,请查看[如何拥有 MongoDB 指南](./数据库#安装)
> 项目使用 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)

配置数据库信息,查看[MongoDB 配置](./数据库)。
配置数据库信息,查看[MongoDB 配置](https://xiaojusurvey.didi.cn/docs/next/document/%E6%A6%82%E8%BF%B0/%E6%95%B0%E6%8D%AE%E5%BA%93)。

#### 2、安装依赖

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ npm run local

#### 1.Configure Database

> 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)
> 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)

Configure the database, check MongoDB configuration.

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- xiaoju-survey

xiaoju-survey:
image: "xiaojusurvey/xiaoju-survey:1.1.6-slim" # 最新版本:https://hub.docker.com/r/xiaojusurvey/xiaoju-survey/tags
image: "xiaojusurvey/xiaoju-survey:1.2.0-slim" # 最新版本:https://hub.docker.com/r/xiaojusurvey/xiaoju-survey/tags
container_name: xiaoju-survey
restart: always
ports:
Expand Down
3 changes: 3 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ http {
proxy_pass http://127.0.0.1:3000;
}

location /exportfile {
proxy_pass http://127.0.0.1:3000;
}
# 静态文件的默认存储文件夹
# 文件夹的配置在 server/src/modules/file/config/index.ts SERVER_LOCAL_CONFIG.FILE_KEY_PREFIX
location /userUpload {
Expand Down
8 changes: 7 additions & 1 deletion server/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
XIAOJU_SURVEY_MONGO_DB_NAME=xiaojuSurvey
XIAOJU_SURVEY_MONGO_URL=mongodb://localhost:27017
XIAOJU_SURVEY_MONGO_URL=
XIAOJU_SURVEY_MONGO_AUTH_SOURCE=admin

XIAOJU_SURVEY_REDIS_HOST=
XIAOJU_SURVEY_REDIS_PORT=
XIAOJU_SURVEY_REDIS_USERNAME=
XIAOJU_SURVEY_REDIS_PASSWORD=
XIAOJU_SURVEY_REDIS_DB=


XIAOJU_SURVEY_RESPONSE_AES_ENCRYPT_SECRET_KEY=dataAesEncryptSecretKey
XIAOJU_SURVEY_HTTP_DATA_ENCRYPT_TYPE=rsa
Expand Down
3 changes: 3 additions & 0 deletions server/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
XIAOJU_SURVEY_REPORT=true
XIAOJU_SURVEY_MONGO_URL=mongodb://127.0.0.1:27017

5 changes: 4 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
yarn.lock

# OS
.DS_Store
Expand All @@ -37,4 +38,6 @@ lerna-debug.log*
!.vscode/launch.json
!.vscode/extensions.json

tmp
tmp
exportfile
userUpload
9 changes: 7 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/microservices": "^10.4.4",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/swagger": "^7.3.0",
"@nestjs/typeorm": "^10.0.1",
"ali-oss": "^6.20.0",
"cheerio": "^1.0.0-rc.12",
"cheerio": "1.0.0-rc.12",
"crypto-js": "^4.2.0",
"dotenv": "^16.3.2",
"fs-extra": "^11.2.0",
"ioredis": "^5.4.1",
"joi": "^17.11.0",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
Expand All @@ -41,7 +43,9 @@
"nanoid": "^3.3.7",
"node-fetch": "^2.7.0",
"node-forge": "^1.3.1",
"node-xlsx": "^0.24.0",
"qiniu": "^7.11.1",
"redlock": "^5.0.0-beta.2",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"svg-captcha": "^1.4.0",
Expand Down Expand Up @@ -70,8 +74,9 @@
"jest": "^29.5.0",
"mongodb-memory-server": "^9.1.4",
"prettier": "^3.0.0",
"redis-memory-server": "^0.11.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"supertest": "^7.0.0",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
Expand Down
13 changes: 11 additions & 2 deletions server/scripts/run-local.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MongoMemoryServer } from 'mongodb-memory-server';
import { spawn } from 'child_process';
// import { RedisMemoryServer } from 'redis-memory-server';

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

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

// const redisServer = new RedisMemoryServer();
// const redisHost = await redisServer.getHost();
// const redisPort = await redisServer.getPort();

// 通过 spawn 运行另一个脚本,并传递 MongoDB 连接 URL 作为环境变量
const tsnode = spawn(
'cross-env',
[
`XIAOJU_SURVEY_MONGO_URL=${mongoUri}`,
// `XIAOJU_SURVEY_REDIS_HOST=${redisHost}`,
// `XIAOJU_SURVEY_REDIS_PORT=${redisPort}`,
'NODE_ENV=development',
'SERVER_ENV=local',
'npm',
'run',
'start:dev',
Expand All @@ -31,9 +39,10 @@ async function startServerAndRunScript() {
console.error(data);
});

tsnode.on('close', (code) => {
tsnode.on('close', async (code) => {
console.log(`Nodemon process exited with code ${code}`);
mongod.stop(); // 停止 MongoDB 内存服务器
await mongod.stop(); // 停止 MongoDB 内存服务器
// await redisServer.stop();
});
}

Expand Down
64 changes: 64 additions & 0 deletions server/scripts/run-report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import fs, { promises as fsa } from 'fs-extra';
import path from 'path';
import fetch from 'node-fetch';

interface PackageJson {
type?: string;
name?: string;
version?: string;
description?: string;
id?: string;
msg?: string;
}

const getId = () => {
const id = new Date().getTime().toString();
process.env.XIAOJU_SURVEY_REPORT_ID = id;

return id;
};

const readData = async (directory: string): Promise<PackageJson | null> => {
const packageJsonPath = path.join(directory, 'package.json');
const id = process.env.XIAOJU_SURVEY_REPORT_ID || getId();
try {
if (!fs.existsSync(directory)) {
return {
type: 'server',
name: '',
version: '',
description: '',
id,
msg: '文件不存在',
};
}
const data = await fsa.readFile(packageJsonPath, 'utf8').catch((e) => e);
const { name, version, description } = JSON.parse(data) as PackageJson;
return { type: 'server', name, version, description, id };
} catch (error) {
return error;
}
};

(async (): Promise<void> => {
if (
process.env.NODE_ENV === 'development' &&
!process.env.XIAOJU_SURVEY_REPORT
) {
return;
}

const res = await readData(path.join(process.cwd()));

// 上报
fetch('https://xiaojusurveysrc.didi.cn/reportSourceData', {
method: 'POST',
headers: {
Accept: 'application/json, */*',
'Content-Type': 'application/json',
},
body: JSON.stringify(res),
}).catch((e) => {
console.log(99999, e);
});
})();
13 changes: 10 additions & 3 deletions server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ import { MessagePushingLog } from './models/messagePushingLog.entity';
import { WorkspaceMember } from './models/workspaceMember.entity';
import { Workspace } from './models/workspace.entity';
import { Collaborator } from './models/collaborator.entity';
import { DownloadTask } from './models/downloadTask.entity';
import { Session } from './models/session.entity';

import { LoggerProvider } from './logger/logger.provider';
import { PluginManagerProvider } from './securityPlugin/pluginManager.provider';
import { LogRequestMiddleware } from './middlewares/logRequest.middleware';
import { XiaojuSurveyPluginManager } from './securityPlugin/pluginManager';
import { PluginManager } from './securityPlugin/pluginManager';
import { Logger } from './logger';

@Module({
imports: [
ConfigModule.forRoot({}),
ConfigModule.forRoot({
envFilePath: `.env.${process.env.NODE_ENV}`, // 根据 NODE_ENV 动态加载对应的 .env 文件
isGlobal: true, // 使配置模块在应用的任何地方可用
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
Expand Down Expand Up @@ -82,6 +87,8 @@ import { Logger } from './logger';
Workspace,
WorkspaceMember,
Collaborator,
DownloadTask,
Session,
],
};
},
Expand Down Expand Up @@ -116,7 +123,7 @@ import { Logger } from './logger';
export class AppModule {
constructor(
private readonly configService: ConfigService,
private readonly pluginManager: XiaojuSurveyPluginManager,
private readonly pluginManager: PluginManager,
) {}
configure(consumer: MiddlewareConsumer) {
consumer.apply(LogRequestMiddleware).forRoutes('*');
Expand Down
6 changes: 6 additions & 0 deletions server/src/enums/downloadTaskStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum DOWNLOAD_TASK_STATUS {
WAITING = 'waiting', // 排队中
COMPUTING = 'computing', // 计算中
SUCCEED = 'succeed', // 导出成功
FAILED = 'failed', // 导出失败
}
1 change: 1 addition & 0 deletions server/src/enums/exceptionCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum EXCEPTION_CODE {
SURVEY_TYPE_ERROR = 3003, // 问卷类型错误
SURVEY_NOT_FOUND = 3004, // 问卷不存在
SURVEY_CONTENT_NOT_ALLOW = 3005, // 存在禁用内容
SURVEY_SAVE_CONFLICT = 3006, // 问卷冲突
CAPTCHA_INCORRECT = 4001, // 验证码不正确
WHITELIST_ERROR = 4002, // 白名单校验错误

Expand Down
7 changes: 3 additions & 4 deletions server/src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
export enum RECORD_STATUS {
NEW = 'new', // 新建 | 未发布
PUBLISHED = 'published', // 发布
CLOSE = 'close', // 关闭
EDITING = 'editing', // 编辑
FINISHED = 'finished', // 已结束
REMOVED = 'removed',
}

export const enum RECORD_SUB_STATUS {
DEFAULT = '', // 默认
EDITING = 'editing', // 编辑
PAUSING = 'pausing', // 暂停
REMOVED = 'removed', // 删除
FORCE_REMOVED = 'forceRemoved', // 从回收站删除
}

// 历史类型
Expand Down
4 changes: 4 additions & 0 deletions server/src/enums/surveySessionStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum SESSION_STATUS {
ACTIVATED = 'activated',
DEACTIVATED = 'deactivated',
}
Loading
Loading