mirror of
https://github.com/vastxie/99AI.git
synced 2025-09-17 09:16:38 +08:00
Compare commits
2 Commits
0f7adc5c65
...
a23fbe1da6
Author | SHA1 | Date | |
---|---|---|---|
|
a23fbe1da6 | ||
|
86e2eecc1f |
56
.github/workflows/docker-image.yml
vendored
56
.github/workflows/docker-image.yml
vendored
@ -1,56 +0,0 @@
|
||||
name: Publish Docker image
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [published]
|
||||
repository_dispatch:
|
||||
types: [trigger-docker-image]
|
||||
|
||||
jobs:
|
||||
push_to_registry:
|
||||
name: Push Docker image to Docker Hub
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Set timezone to Shanghai
|
||||
run: sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" | sudo tee /etc/timezone
|
||||
|
||||
- name: Generate tag with Chinese date format
|
||||
id: date
|
||||
run: echo "::set-output name=date::$(date +'%y%m%d')"
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: buqian/99ai
|
||||
tags: |
|
||||
type=raw,value=latest
|
||||
type=raw,value=${{ steps.date.outputs.date }}
|
||||
type=ref,event=tag
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
129
.github/workflows/electron-build.yml
vendored
Normal file
129
.github/workflows/electron-build.yml
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
name: Build Electron App
|
||||
|
||||
on:
|
||||
# push:
|
||||
# branches: [ main ]
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
# pull_request:
|
||||
# branches: [ main ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-mac:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 8
|
||||
run_install: false
|
||||
|
||||
- name: Get pnpm store directory
|
||||
shell: bash
|
||||
run: |
|
||||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup pnpm cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ env.STORE_PATH }}
|
||||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd chat
|
||||
pnpm install
|
||||
|
||||
- name: Build for Mac
|
||||
env:
|
||||
VITE_GLOB_API_URL: https://asst.lightai.cloud/api
|
||||
run: |
|
||||
cd chat
|
||||
pnpm run electron:mac-universal
|
||||
|
||||
- name: Upload Mac artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: mac-builds
|
||||
path: chat/release/*.dmg
|
||||
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 8
|
||||
run_install: false
|
||||
|
||||
- name: Get pnpm store directory
|
||||
shell: bash
|
||||
run: |
|
||||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup pnpm cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ env.STORE_PATH }}
|
||||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd chat
|
||||
pnpm install
|
||||
|
||||
- name: Build for Windows x64
|
||||
env:
|
||||
VITE_GLOB_API_URL: https://asst.lightai.cloud/api
|
||||
run: |
|
||||
cd chat
|
||||
pnpm run electron:win-x64
|
||||
|
||||
- name: Upload Windows artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: windows-builds
|
||||
path: |
|
||||
chat/release/*.exe
|
||||
chat/release/*.zip
|
||||
|
||||
create-release:
|
||||
needs: [build-mac, build-windows]
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
artifacts/mac-builds/*
|
||||
artifacts/windows-builds/*
|
||||
draft: false
|
||||
prerelease: false
|
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,7 +0,0 @@
|
||||
node_modules
|
||||
logs
|
||||
.env
|
||||
/public/file
|
||||
.DS_Store
|
||||
data
|
||||
sql
|
113
.vscode/settings.json
vendored
113
.vscode/settings.json
vendored
@ -1,5 +1,110 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"Luma"
|
||||
]
|
||||
}
|
||||
"prettier.enable": true,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit",
|
||||
"source.organizeImports": "explicit"
|
||||
},
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"typescript",
|
||||
"typescriptreact",
|
||||
"vue",
|
||||
"html",
|
||||
"json",
|
||||
"jsonc",
|
||||
"json5",
|
||||
"yaml",
|
||||
"yml",
|
||||
"markdown"
|
||||
],
|
||||
"cSpell.words": [
|
||||
"aiweb",
|
||||
"antfu",
|
||||
"axios",
|
||||
"Baichuan",
|
||||
"bumpp",
|
||||
"Chatbox",
|
||||
"chatglm",
|
||||
"chatgpt",
|
||||
"chatlog",
|
||||
"chatweb",
|
||||
"chenzhaoyu",
|
||||
"chevereto",
|
||||
"cogvideox",
|
||||
"commitlint",
|
||||
"cref",
|
||||
"dall",
|
||||
"dalle",
|
||||
"davinci",
|
||||
"deepsearch",
|
||||
"deepseek",
|
||||
"dockerhub",
|
||||
"duckduckgo",
|
||||
"EMAILCODE",
|
||||
"errmsg",
|
||||
"esno",
|
||||
"flowith",
|
||||
"GPTAPI",
|
||||
"gpts",
|
||||
"highlightjs",
|
||||
"hljs",
|
||||
"hunyuan",
|
||||
"iconify",
|
||||
"ISDEV",
|
||||
"katex",
|
||||
"katexmath",
|
||||
"langchain",
|
||||
"lightai",
|
||||
"linkify",
|
||||
"logprobs",
|
||||
"longcontext",
|
||||
"luma",
|
||||
"mapi",
|
||||
"Markmap",
|
||||
"mdhljs",
|
||||
"mediumtext",
|
||||
"micromessenger",
|
||||
"mila",
|
||||
"Mindmap",
|
||||
"MODELSMAPLIST",
|
||||
"MODELTYPELIST",
|
||||
"modelvalue",
|
||||
"newconfig",
|
||||
"niji",
|
||||
"Nmessage",
|
||||
"nodata",
|
||||
"OPENAI",
|
||||
"pinia",
|
||||
"Popconfirm",
|
||||
"PPTCREATE",
|
||||
"projectaddress",
|
||||
"qwen",
|
||||
"rushstack",
|
||||
"sdxl",
|
||||
"seededit",
|
||||
"seedream",
|
||||
"Sider",
|
||||
"sref",
|
||||
"suno",
|
||||
"tailwindcss",
|
||||
"Tavily",
|
||||
"traptitech",
|
||||
"tsup",
|
||||
"Typecheck",
|
||||
"typeorm",
|
||||
"unplugin",
|
||||
"usercenter",
|
||||
"vastxie",
|
||||
"VITE",
|
||||
"vueuse",
|
||||
"wechat"
|
||||
],
|
||||
"vue.codeActions.enabled": false,
|
||||
"volar.experimental.tsconfigPaths": {
|
||||
"./chat": ["./src/chat/tsconfig.json"],
|
||||
"./admin": ["./src/admin/tsconfig.json"],
|
||||
"./service": ["./src/service/tsconfig.json"]
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
# server base
|
||||
PORT=9520
|
||||
|
||||
# mysql
|
||||
DB_HOST=mysql
|
||||
DB_PORT=3306
|
||||
DB_USER=root
|
||||
DB_PASS=123456
|
||||
DB_DATABASE=chatgpt
|
||||
DB_SYNC=true
|
||||
|
||||
# Redis
|
||||
REDIS_PORT=6379
|
||||
@ -16,12 +16,15 @@ REDIS_USER=
|
||||
REDIS_DB=0
|
||||
|
||||
# 是否测试环境
|
||||
ISDEV=FALSE
|
||||
ISDEV=false
|
||||
|
||||
# 自定义微信URL
|
||||
weChatOpenUrl=https://open.weixin.qq.com
|
||||
weChatApiUrl=https://api.weixin.qq.com
|
||||
weChatApiUrlToken=https://api.weixin.qq.com/cgi-bin/token
|
||||
weChatMpUrl=https://mp.weixin.qq.com
|
||||
|
||||
# 自定义后台路径
|
||||
ADMIN_SERVE_ROOT=/admin
|
||||
|
||||
# 机器码及授权码
|
||||
|
@ -7,7 +7,6 @@ DB_PORT=3306
|
||||
DB_USER=root
|
||||
DB_PASS=
|
||||
DB_DATABASE=chatgpt
|
||||
DB_SYNC=true
|
||||
|
||||
# Redis
|
||||
REDIS_PORT=6379
|
||||
@ -22,7 +21,10 @@ ISDEV=false
|
||||
# 自定义微信URL
|
||||
weChatOpenUrl=https://open.weixin.qq.com
|
||||
weChatApiUrl=https://api.weixin.qq.com
|
||||
weChatApiUrlToken=https://api.weixin.qq.com/cgi-bin/token
|
||||
weChatMpUrl=https://mp.weixin.qq.com
|
||||
|
||||
# 自定义后台路径
|
||||
ADMIN_SERVE_ROOT=/admin
|
||||
|
||||
# 机器码及授权码
|
||||
|
@ -1,35 +1,21 @@
|
||||
# 编译阶段
|
||||
FROM node:20.14.0-alpine AS build
|
||||
# 使用官方Node.js的基础镜像
|
||||
FROM node:latest
|
||||
|
||||
WORKDIR /app
|
||||
# 设置时区为上海
|
||||
ENV TZ="Asia/Shanghai"
|
||||
|
||||
COPY package*.json ./
|
||||
# 设置工作目录
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# 设置环境变量来忽略一些警告
|
||||
ENV NPM_CONFIG_LOGLEVEL=error
|
||||
ENV NODE_OPTIONS=--max-old-space-size=4096
|
||||
# 安装pnpm
|
||||
RUN npm install -g npm pm2 pnpm
|
||||
|
||||
# 合并RUN命令,更新依赖,设置镜像源,安装依赖,然后清理
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
|
||||
npm config set registry https://registry.npmmirror.com && \
|
||||
apk add --no-cache --virtual .build-deps git && \
|
||||
npm install -g npm@latest && \
|
||||
npm install --production --no-optional --legacy-peer-deps && \
|
||||
npm cache clean --force && \
|
||||
apk del .build-deps && \
|
||||
rm -rf /var/cache/apk/* /tmp/*
|
||||
|
||||
# 运行阶段
|
||||
FROM node:20.14.0-alpine AS runner
|
||||
|
||||
ENV TZ="Asia/Shanghai" \
|
||||
NODE_ENV=production
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=build /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
# 复制package.json以利用Docker缓存机制
|
||||
COPY package.json ./
|
||||
RUN pnpm install
|
||||
|
||||
# 暴露应用端口
|
||||
EXPOSE 9520
|
||||
|
||||
CMD ["node", "--max-old-space-size=4096", "./dist/main.js"]
|
||||
# 启动应用
|
||||
CMD ["pm2-runtime", "start", "pm2.conf.json"]
|
||||
|
96
AIWebQuickDeploy/dist/app.module.js
vendored
96
AIWebQuickDeploy/dist/app.module.js
vendored
@ -1,96 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AppModule = void 0;
|
||||
const abort_interceptor_1 = require("./common/interceptors/abort.interceptor");
|
||||
const custom_logger_service_1 = require("./common/logger/custom-logger.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const core_1 = require("@nestjs/core");
|
||||
const serve_static_1 = require("@nestjs/serve-static");
|
||||
const fetch = require("isomorphic-fetch");
|
||||
const path_1 = require("path");
|
||||
const app_module_1 = require("./modules/app/app.module");
|
||||
const auth_module_1 = require("./modules/auth/auth.module");
|
||||
const autoreply_module_1 = require("./modules/autoreply/autoreply.module");
|
||||
const badWords_module_1 = require("./modules/badWords/badWords.module");
|
||||
const chat_module_1 = require("./modules/chat/chat.module");
|
||||
const chatGroup_module_1 = require("./modules/chatGroup/chatGroup.module");
|
||||
const chatLog_module_1 = require("./modules/chatLog/chatLog.module");
|
||||
const crami_module_1 = require("./modules/crami/crami.module");
|
||||
const database_module_1 = require("./modules/database/database.module");
|
||||
const globalConfig_module_1 = require("./modules/globalConfig/globalConfig.module");
|
||||
const models_module_1 = require("./modules/models/models.module");
|
||||
const official_module_1 = require("./modules/official/official.module");
|
||||
const order_module_1 = require("./modules/order/order.module");
|
||||
const pay_module_1 = require("./modules/pay/pay.module");
|
||||
const plugin_module_1 = require("./modules/plugin/plugin.module");
|
||||
const redisCache_module_1 = require("./modules/redisCache/redisCache.module");
|
||||
const signin_module_1 = require("./modules/signin/signin.module");
|
||||
const statistic_module_1 = require("./modules/statistic/statistic.module");
|
||||
const task_module_1 = require("./modules/task/task.module");
|
||||
const upload_module_1 = require("./modules/upload/upload.module");
|
||||
const user_module_1 = require("./modules/user/user.module");
|
||||
const userBalance_module_1 = require("./modules/userBalance/userBalance.module");
|
||||
const verification_module_1 = require("./modules/verification/verification.module");
|
||||
global.fetch = fetch;
|
||||
let AppModule = class AppModule {
|
||||
};
|
||||
AppModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
database_module_1.DatabaseModule,
|
||||
serve_static_1.ServeStaticModule.forRoot({
|
||||
rootPath: (0, path_1.join)(__dirname, '..', 'public/admin'),
|
||||
serveRoot: process.env.ADMIN_SERVE_ROOT || '/admin',
|
||||
}, {
|
||||
rootPath: (0, path_1.join)(__dirname, '..', 'public/file'),
|
||||
serveRoot: '/file',
|
||||
serveStaticOptions: {
|
||||
setHeaders: (res, path, stat) => {
|
||||
res.set('Access-Control-Allow-Origin', '*');
|
||||
},
|
||||
},
|
||||
}, {
|
||||
rootPath: (0, path_1.join)(__dirname, '..', 'public/chat'),
|
||||
serveRoot: '/',
|
||||
}),
|
||||
user_module_1.UserModule,
|
||||
plugin_module_1.PluginModule,
|
||||
auth_module_1.AuthModule,
|
||||
verification_module_1.VerificationModule,
|
||||
chat_module_1.ChatModule,
|
||||
crami_module_1.CramiModule,
|
||||
userBalance_module_1.UserBalanceModule,
|
||||
chatLog_module_1.ChatLogModule,
|
||||
upload_module_1.UploadModule,
|
||||
redisCache_module_1.RedisCacheModule,
|
||||
globalConfig_module_1.GlobalConfigModule,
|
||||
statistic_module_1.StatisticModule,
|
||||
badWords_module_1.BadWordsModule,
|
||||
autoreply_module_1.AutoreplyModule,
|
||||
app_module_1.AppModule,
|
||||
pay_module_1.PayModule,
|
||||
order_module_1.OrderModule,
|
||||
official_module_1.OfficialModule,
|
||||
task_module_1.TaskModule,
|
||||
chatGroup_module_1.ChatGroupModule,
|
||||
signin_module_1.SigninModule,
|
||||
models_module_1.ModelsModule,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: core_1.APP_INTERCEPTOR,
|
||||
useClass: abort_interceptor_1.AbortInterceptor,
|
||||
},
|
||||
custom_logger_service_1.CustomLoggerService,
|
||||
],
|
||||
exports: [custom_logger_service_1.CustomLoggerService],
|
||||
})
|
||||
], AppModule);
|
||||
exports.AppModule = AppModule;
|
@ -1,31 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AdminAuthGuard = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const jwtAuth_guard_1 = require("./jwtAuth.guard");
|
||||
let AdminAuthGuard = class AdminAuthGuard extends jwtAuth_guard_1.JwtAuthGuard {
|
||||
async canActivate(context) {
|
||||
const isAuthorized = await super.canActivate(context);
|
||||
if (!isAuthorized) {
|
||||
return false;
|
||||
}
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const user = request.user;
|
||||
if (user && ['admin', 'super'].includes(user.role)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new common_1.UnauthorizedException('非法操作、您的权限等级不足、无法执行当前请求!');
|
||||
}
|
||||
}
|
||||
};
|
||||
AdminAuthGuard = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], AdminAuthGuard);
|
||||
exports.AdminAuthGuard = AdminAuthGuard;
|
@ -1,33 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JwtStrategy = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const passport_1 = require("@nestjs/passport");
|
||||
const passport_jwt_1 = require("passport-jwt");
|
||||
const redisCache_service_1 = require("../../modules/redisCache/redisCache.service");
|
||||
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
||||
constructor(redisService) {
|
||||
super({
|
||||
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
secretOrKey: redisService.getJwtSecret(),
|
||||
});
|
||||
this.redisService = redisService;
|
||||
}
|
||||
async validate(payload) {
|
||||
return payload;
|
||||
}
|
||||
};
|
||||
JwtStrategy = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [redisCache_service_1.RedisCacheService])
|
||||
], JwtStrategy);
|
||||
exports.JwtStrategy = JwtStrategy;
|
@ -1,85 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.JwtAuthGuard = void 0;
|
||||
const globalConfig_service_1 = require("../../modules/globalConfig/globalConfig.service");
|
||||
const redisCache_service_1 = require("../../modules/redisCache/redisCache.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const core_1 = require("@nestjs/core");
|
||||
const passport_1 = require("@nestjs/passport");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const auth_service_1 = require("../../modules/auth/auth.service");
|
||||
let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)('jwt') {
|
||||
constructor(redisCacheService, moduleRef, globalConfigService, authService) {
|
||||
super();
|
||||
this.redisCacheService = redisCacheService;
|
||||
this.moduleRef = moduleRef;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.authService = authService;
|
||||
}
|
||||
async canActivate(context) {
|
||||
if (!this.redisCacheService) {
|
||||
this.redisCacheService = this.moduleRef.get(redisCache_service_1.RedisCacheService, {
|
||||
strict: false,
|
||||
});
|
||||
}
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const domain = request.headers['x-website-domain'];
|
||||
const token = this.extractToken(request);
|
||||
request.user = await this.validateToken(token);
|
||||
await this.redisCacheService.checkTokenAuth(token, request);
|
||||
return true;
|
||||
}
|
||||
extractToken(request) {
|
||||
if (!request.headers.authorization) {
|
||||
if (request.headers.fingerprint) {
|
||||
let id = request.headers.fingerprint;
|
||||
if (id > 2147483647) {
|
||||
id = id.toString().slice(-9);
|
||||
id = Number(String(Number(id)));
|
||||
}
|
||||
const token = this.authService.createTokenFromFingerprint(id);
|
||||
return token;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const parts = request.headers.authorization.split(' ');
|
||||
if (parts.length !== 2 || parts[0] !== 'Bearer') {
|
||||
return null;
|
||||
}
|
||||
return parts[1];
|
||||
}
|
||||
async validateToken(token) {
|
||||
try {
|
||||
const secret = await this.redisCacheService.getJwtSecret();
|
||||
const decoded = await jwt.verify(token, secret);
|
||||
return decoded;
|
||||
}
|
||||
catch (error) {
|
||||
throw new common_1.HttpException('亲爱的用户,请登录后继续操作,我们正在等您的到来!', common_1.HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
handleRequest(err, user, info) {
|
||||
if (err || !user) {
|
||||
console.log('err: ', err);
|
||||
throw err || new common_1.UnauthorizedException();
|
||||
}
|
||||
return user;
|
||||
}
|
||||
};
|
||||
JwtAuthGuard = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [redisCache_service_1.RedisCacheService,
|
||||
core_1.ModuleRef,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
auth_service_1.AuthService])
|
||||
], JwtAuthGuard);
|
||||
exports.JwtAuthGuard = JwtAuthGuard;
|
@ -1,31 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SuperAuthGuard = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const jwtAuth_guard_1 = require("./jwtAuth.guard");
|
||||
let SuperAuthGuard = class SuperAuthGuard extends jwtAuth_guard_1.JwtAuthGuard {
|
||||
async canActivate(context) {
|
||||
const isAuthorized = await super.canActivate(context);
|
||||
if (!isAuthorized) {
|
||||
return false;
|
||||
}
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const user = request.user;
|
||||
if (user && user.role === 'super') {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new common_1.UnauthorizedException('非法操作、非超级管理员无权操作!');
|
||||
}
|
||||
}
|
||||
};
|
||||
SuperAuthGuard = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], SuperAuthGuard);
|
||||
exports.SuperAuthGuard = SuperAuthGuard;
|
@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RechargeType = exports.ChatType = void 0;
|
||||
exports.ChatType = {
|
||||
NORMAL_CHAT: 1,
|
||||
PAINT: 2,
|
||||
EXTENDED_CHAT: 3,
|
||||
};
|
||||
exports.RechargeType = {
|
||||
REG_GIFT: 1,
|
||||
INVITE_GIFT: 2,
|
||||
REFER_GIFT: 3,
|
||||
PACKAGE_GIFT: 4,
|
||||
ADMIN_GIFT: 5,
|
||||
SCAN_PAY: 6,
|
||||
DRAW_FAIL_REFUND: 7,
|
||||
SIGN_IN: 8,
|
||||
};
|
@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OpenAiErrorCodeMessage = exports.ErrorMessageEnum = void 0;
|
||||
var ErrorMessageEnum;
|
||||
(function (ErrorMessageEnum) {
|
||||
ErrorMessageEnum["USERNAME_OR_EMAIL_ALREADY_REGISTERED"] = "\u7528\u6237\u540D\u6216\u90AE\u7BB1\u5DF2\u6CE8\u518C\uFF01";
|
||||
ErrorMessageEnum["USER_NOT_FOUND"] = "\u7528\u6237\u4E0D\u5B58\u5728\uFF01";
|
||||
ErrorMessageEnum["VERIFICATION_NOT_FOUND"] = "\u9A8C\u8BC1\u8BB0\u5F55\u4E0D\u5B58\u5728\uFF01";
|
||||
ErrorMessageEnum["VERIFICATION_CODE_EXPIRED"] = "\u9A8C\u8BC1\u7801\u5DF2\u8FC7\u671F\uFF01";
|
||||
ErrorMessageEnum["VERIFICATION_CODE_INVALID"] = "\u9A8C\u8BC1\u7801\u65E0\u6548\uFF01";
|
||||
ErrorMessageEnum["VERIFICATION_CODE_MISMATCH"] = "\u9A8C\u8BC1\u7801\u4E0D\u5339\u914D\uFF01";
|
||||
ErrorMessageEnum["VERIFICATION_CODE_SEND_FAILED"] = "\u9A8C\u8BC1\u7801\u53D1\u9001\u5931\u8D25\uFF01";
|
||||
ErrorMessageEnum["VERIFICATION_CODE_SEND_TOO_OFTEN"] = "\u9A8C\u8BC1\u7801\u53D1\u9001\u8FC7\u4E8E\u9891\u7E41\uFF01";
|
||||
})(ErrorMessageEnum = exports.ErrorMessageEnum || (exports.ErrorMessageEnum = {}));
|
||||
exports.OpenAiErrorCodeMessage = {
|
||||
400: '[Inter Error] 服务端错误[400]',
|
||||
401: '[Inter Error] 服务出现错误、请稍后再试一次吧[401]',
|
||||
403: '[Inter Error] 服务器拒绝访问,请稍后再试 | Server refused to access, please try again later',
|
||||
429: '[Inter Error] 当前key调用频率过高、请重新对话再试一次吧[429]',
|
||||
502: '[Inter Error] 错误的网关 | Bad Gateway[502]',
|
||||
503: '[Inter Error] 服务器繁忙,请稍后再试 | Server is busy, please try again later[503]',
|
||||
504: '[Inter Error] 网关超时 | Gateway Time-out[504]',
|
||||
500: '[Inter Error] 服务器繁忙,请稍后再试 | Internal Server Error[500]',
|
||||
};
|
@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MidjourneyActionEnum = exports.MidjourneyStatusEnum = void 0;
|
||||
var MidjourneyStatusEnum;
|
||||
(function (MidjourneyStatusEnum) {
|
||||
MidjourneyStatusEnum[MidjourneyStatusEnum["WAITING"] = 1] = "WAITING";
|
||||
MidjourneyStatusEnum[MidjourneyStatusEnum["DRAWING"] = 2] = "DRAWING";
|
||||
MidjourneyStatusEnum[MidjourneyStatusEnum["DRAWED"] = 3] = "DRAWED";
|
||||
MidjourneyStatusEnum[MidjourneyStatusEnum["DRAWFAIL"] = 4] = "DRAWFAIL";
|
||||
MidjourneyStatusEnum[MidjourneyStatusEnum["DRAWTIMEOUT"] = 5] = "DRAWTIMEOUT";
|
||||
})(MidjourneyStatusEnum = exports.MidjourneyStatusEnum || (exports.MidjourneyStatusEnum = {}));
|
||||
var MidjourneyActionEnum;
|
||||
(function (MidjourneyActionEnum) {
|
||||
MidjourneyActionEnum[MidjourneyActionEnum["DRAW"] = 1] = "DRAW";
|
||||
MidjourneyActionEnum[MidjourneyActionEnum["UPSCALE"] = 2] = "UPSCALE";
|
||||
MidjourneyActionEnum[MidjourneyActionEnum["VARIATION"] = 3] = "VARIATION";
|
||||
MidjourneyActionEnum[MidjourneyActionEnum["GENERATE"] = 4] = "GENERATE";
|
||||
MidjourneyActionEnum[MidjourneyActionEnum["REGENERATE"] = 5] = "REGENERATE";
|
||||
MidjourneyActionEnum[MidjourneyActionEnum["VARY"] = 6] = "VARY";
|
||||
MidjourneyActionEnum[MidjourneyActionEnum["ZOOM"] = 7] = "ZOOM";
|
||||
})(MidjourneyActionEnum = exports.MidjourneyActionEnum || (exports.MidjourneyActionEnum = {}));
|
@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ModelsMapCn = exports.VerificationUseStatusEnum = void 0;
|
||||
var VerificationUseStatusEnum;
|
||||
(function (VerificationUseStatusEnum) {
|
||||
VerificationUseStatusEnum[VerificationUseStatusEnum["UNUSED"] = 0] = "UNUSED";
|
||||
VerificationUseStatusEnum[VerificationUseStatusEnum["USED"] = 1] = "USED";
|
||||
})(VerificationUseStatusEnum = exports.VerificationUseStatusEnum || (exports.VerificationUseStatusEnum = {}));
|
||||
exports.ModelsMapCn = {
|
||||
1: '普通模型',
|
||||
2: '绘画模型',
|
||||
3: '特殊模型'
|
||||
};
|
@ -1,16 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserStatusErrMsg = exports.UserStatusEnum = void 0;
|
||||
var UserStatusEnum;
|
||||
(function (UserStatusEnum) {
|
||||
UserStatusEnum[UserStatusEnum["PENDING"] = 0] = "PENDING";
|
||||
UserStatusEnum[UserStatusEnum["ACTIVE"] = 1] = "ACTIVE";
|
||||
UserStatusEnum[UserStatusEnum["LOCKED"] = 2] = "LOCKED";
|
||||
UserStatusEnum[UserStatusEnum["BLACKLISTED"] = 3] = "BLACKLISTED";
|
||||
})(UserStatusEnum = exports.UserStatusEnum || (exports.UserStatusEnum = {}));
|
||||
exports.UserStatusErrMsg = {
|
||||
[UserStatusEnum.PENDING]: '当前账户未激活,请前往邮箱验证或重新发送验证码!',
|
||||
[UserStatusEnum.ACTIVE]: '当前账户已激活!',
|
||||
[UserStatusEnum.LOCKED]: '当前账户已锁定,请联系管理员解锁!',
|
||||
[UserStatusEnum.BLACKLISTED]: '当前账户已被永久封禁!',
|
||||
};
|
@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.VerificationEnum = void 0;
|
||||
var VerificationEnum;
|
||||
(function (VerificationEnum) {
|
||||
VerificationEnum[VerificationEnum["Registration"] = 0] = "Registration";
|
||||
VerificationEnum[VerificationEnum["PasswordReset"] = 1] = "PasswordReset";
|
||||
VerificationEnum[VerificationEnum["ChangeEmail"] = 2] = "ChangeEmail";
|
||||
})(VerificationEnum = exports.VerificationEnum || (exports.VerificationEnum = {}));
|
@ -1,35 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BaseEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
let BaseEntity = class BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
||||
__metadata("design:type", Number)
|
||||
], BaseEntity.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.CreateDateColumn)({ type: 'datetime', length: 0, nullable: false, name: 'createdAt', comment: '创建时间' }),
|
||||
__metadata("design:type", Date)
|
||||
], BaseEntity.prototype, "createdAt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.UpdateDateColumn)({ type: 'datetime', length: 0, nullable: false, name: 'updatedAt', comment: '更新时间' }),
|
||||
__metadata("design:type", Date)
|
||||
], BaseEntity.prototype, "updatedAt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.DeleteDateColumn)({ type: 'datetime', length: 0, nullable: false, name: 'deletedAt', comment: '删除时间' }),
|
||||
__metadata("design:type", Date)
|
||||
], BaseEntity.prototype, "deletedAt", void 0);
|
||||
BaseEntity = __decorate([
|
||||
(0, typeorm_1.Entity)()
|
||||
], BaseEntity);
|
||||
exports.BaseEntity = BaseEntity;
|
@ -1,51 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AllExceptionsFilter = void 0;
|
||||
const result_1 = require("../result");
|
||||
const common_1 = require("@nestjs/common");
|
||||
let AllExceptionsFilter = class AllExceptionsFilter {
|
||||
catch(exception, host) {
|
||||
const ctx = host.switchToHttp();
|
||||
const response = ctx.getResponse();
|
||||
const request = ctx.getRequest();
|
||||
const status = exception instanceof common_1.HttpException
|
||||
? exception.getStatus()
|
||||
: common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
let message = 'Internal server error';
|
||||
if (exception instanceof common_1.HttpException) {
|
||||
const exceptionRes = exception.getResponse();
|
||||
message = (exceptionRes === null || exceptionRes === void 0 ? void 0 : exceptionRes.message)
|
||||
? Array.isArray(exceptionRes.message)
|
||||
? exceptionRes.message[0]
|
||||
: exceptionRes.message
|
||||
: exceptionRes;
|
||||
}
|
||||
else if (typeof exception.getResponse === 'function') {
|
||||
const exceptionRes = exception.getResponse();
|
||||
message = (exceptionRes === null || exceptionRes === void 0 ? void 0 : exceptionRes.message)
|
||||
? Array.isArray(exceptionRes.message)
|
||||
? exceptionRes.message[0]
|
||||
: exceptionRes.message
|
||||
: exceptionRes;
|
||||
}
|
||||
if (status === common_1.HttpStatus.NOT_FOUND) {
|
||||
response.redirect('/');
|
||||
}
|
||||
else {
|
||||
const statusCode = status || 400;
|
||||
response.status(statusCode);
|
||||
response.header('Content-Type', 'application/json; charset=utf-8');
|
||||
response.send(result_1.Result.fail(statusCode, Array.isArray(message) ? message[0] : message));
|
||||
}
|
||||
}
|
||||
};
|
||||
AllExceptionsFilter = __decorate([
|
||||
(0, common_1.Catch)()
|
||||
], AllExceptionsFilter);
|
||||
exports.AllExceptionsFilter = AllExceptionsFilter;
|
@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TypeOrmQueryFailedFilter = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let TypeOrmQueryFailedFilter = class TypeOrmQueryFailedFilter {
|
||||
catch(exception, host) {
|
||||
const ctx = host.switchToHttp();
|
||||
const response = ctx.getResponse();
|
||||
const request = ctx.getRequest();
|
||||
if (exception.code === 'ER_DUP_ENTRY') {
|
||||
throw new common_1.BadRequestException('该记录已经存在,请勿重复添加!');
|
||||
}
|
||||
else {
|
||||
console.log('other query error');
|
||||
}
|
||||
response.status(500).json({
|
||||
statusCode: 500,
|
||||
timestamp: new Date().toISOString(),
|
||||
path: request.url,
|
||||
message: `Database query failed: ${exception.message}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
TypeOrmQueryFailedFilter = __decorate([
|
||||
(0, common_1.Catch)(typeorm_1.QueryFailedError)
|
||||
], TypeOrmQueryFailedFilter);
|
||||
exports.TypeOrmQueryFailedFilter = TypeOrmQueryFailedFilter;
|
@ -1,19 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RolesGuard = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
let RolesGuard = class RolesGuard {
|
||||
canActivate(context) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
RolesGuard = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], RolesGuard);
|
||||
exports.RolesGuard = RolesGuard;
|
@ -1,23 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AbortInterceptor = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const abort_controller_1 = require("abort-controller");
|
||||
let AbortInterceptor = class AbortInterceptor {
|
||||
intercept(context, next) {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const abortController = new abort_controller_1.AbortController();
|
||||
request.abortController = abortController;
|
||||
return next.handle();
|
||||
}
|
||||
};
|
||||
AbortInterceptor = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], AbortInterceptor);
|
||||
exports.AbortInterceptor = AbortInterceptor;
|
@ -1,35 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TransformInterceptor = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const rxjs_1 = require("rxjs");
|
||||
const operators_1 = require("rxjs/operators");
|
||||
const result_1 = require("../result");
|
||||
let TransformInterceptor = class TransformInterceptor {
|
||||
intercept(context, next) {
|
||||
return next.handle().pipe((0, operators_1.map)((data) => {
|
||||
const response = context.switchToHttp().getResponse();
|
||||
const request = context.switchToHttp().getRequest();
|
||||
response.statusCode = 200;
|
||||
if (request.path.includes('notify')) {
|
||||
return data;
|
||||
}
|
||||
const message = response.status < 400 ? null : response.statusText;
|
||||
return result_1.Result.success(data, message);
|
||||
}), (0, rxjs_1.catchError)((error) => {
|
||||
const statusCode = error.status || 500;
|
||||
const message = (error.response || 'Internal server error');
|
||||
return (0, rxjs_1.throwError)(new common_1.HttpException(message, statusCode));
|
||||
}));
|
||||
}
|
||||
};
|
||||
TransformInterceptor = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], TransformInterceptor);
|
||||
exports.TransformInterceptor = TransformInterceptor;
|
@ -1,45 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CustomLoggerService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
let CustomLoggerService = class CustomLoggerService extends common_1.ConsoleLogger {
|
||||
constructor() {
|
||||
super();
|
||||
this.isDev = process.env.ISDEV === 'TRUE';
|
||||
}
|
||||
log(message, context) {
|
||||
super.log(message, context);
|
||||
}
|
||||
error(message, trace, context) {
|
||||
super.error(message, trace, context);
|
||||
}
|
||||
warn(message, context) {
|
||||
if (this.isDev) {
|
||||
super.warn(message, context);
|
||||
}
|
||||
}
|
||||
debug(message, context) {
|
||||
if (this.isDev) {
|
||||
super.debug(message, context);
|
||||
}
|
||||
}
|
||||
verbose(message, context) {
|
||||
if (this.isDev) {
|
||||
super.verbose(message, context);
|
||||
}
|
||||
}
|
||||
};
|
||||
CustomLoggerService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [])
|
||||
], CustomLoggerService);
|
||||
exports.CustomLoggerService = CustomLoggerService;
|
@ -1,23 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.XMLMiddleware = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const bodyParser = require("body-parser");
|
||||
const bodyParserMiddleware = bodyParser.text({
|
||||
type: 'application/xml',
|
||||
});
|
||||
let XMLMiddleware = class XMLMiddleware {
|
||||
use(req, res, next) {
|
||||
bodyParserMiddleware(req, res, next);
|
||||
}
|
||||
};
|
||||
XMLMiddleware = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], XMLMiddleware);
|
||||
exports.XMLMiddleware = XMLMiddleware;
|
18
AIWebQuickDeploy/dist/common/result/index.js
vendored
18
AIWebQuickDeploy/dist/common/result/index.js
vendored
@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Result = void 0;
|
||||
class Result {
|
||||
constructor(code, success, data, message) {
|
||||
this.code = code;
|
||||
this.data = data;
|
||||
this.success = success;
|
||||
this.message = message;
|
||||
}
|
||||
static success(data, message = '请求成功') {
|
||||
return new Result(200, true, data, message);
|
||||
}
|
||||
static fail(code, message = '请求失败', data) {
|
||||
return new Result(code, false, data, message);
|
||||
}
|
||||
}
|
||||
exports.Result = Result;
|
15
AIWebQuickDeploy/dist/common/swagger/index.js
vendored
15
AIWebQuickDeploy/dist/common/swagger/index.js
vendored
@ -1,15 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createSwagger = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const swaggerOptions = new swagger_1.DocumentBuilder()
|
||||
.setTitle('AIWeb Team api document')
|
||||
.setDescription('AIWeb Team api document')
|
||||
.setVersion('1.0.0')
|
||||
.addBearerAuth()
|
||||
.build();
|
||||
function createSwagger(app) {
|
||||
const document = swagger_1.SwaggerModule.createDocument(app, swaggerOptions);
|
||||
swagger_1.SwaggerModule.setup('/swagger/docs', app, document);
|
||||
}
|
||||
exports.createSwagger = createSwagger;
|
26
AIWebQuickDeploy/dist/common/utils/base.js
vendored
26
AIWebQuickDeploy/dist/common/utils/base.js
vendored
@ -1,26 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.decrypt = exports.encrypt = void 0;
|
||||
const crypto = require("crypto");
|
||||
const encryptionKey = 'bf3c116f2470cb4che9071240917c171';
|
||||
const initializationVector = '518363fh72eec1v4';
|
||||
const algorithm = 'aes-256-cbc';
|
||||
function encrypt(text) {
|
||||
const cipher = crypto.createCipheriv(algorithm, encryptionKey, initializationVector);
|
||||
let encrypted = cipher.update(text, 'utf8', 'base64');
|
||||
encrypted += cipher.final('base64');
|
||||
return encrypted;
|
||||
}
|
||||
exports.encrypt = encrypt;
|
||||
function decrypt(text) {
|
||||
try {
|
||||
const decipher = crypto.createDecipheriv(algorithm, encryptionKey, initializationVector);
|
||||
let decrypted = decipher.update(text, 'base64', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
return decrypted;
|
||||
}
|
||||
catch (error) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
exports.decrypt = decrypt;
|
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createOrderId = void 0;
|
||||
const uuid_1 = require("uuid");
|
||||
function createOrderId() {
|
||||
return (0, uuid_1.v1)().toString().replace(/-/g, '');
|
||||
}
|
||||
exports.createOrderId = createOrderId;
|
@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createRandomCode = void 0;
|
||||
function createRandomCode() {
|
||||
const min = 100000;
|
||||
const max = 999999;
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
}
|
||||
exports.createRandomCode = createRandomCode;
|
@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateRandomString = void 0;
|
||||
function generateRandomString() {
|
||||
const length = 10;
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
let result = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * characters.length);
|
||||
result += characters.charAt(randomIndex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.generateRandomString = generateRandomString;
|
@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createRandomNonceStr = void 0;
|
||||
function createRandomNonceStr(len) {
|
||||
const data = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
let str = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
str += data.charAt(parseInt((Math.random() * data.length).toFixed(0), 10));
|
||||
}
|
||||
return str;
|
||||
}
|
||||
exports.createRandomNonceStr = createRandomNonceStr;
|
@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createRandomUid = void 0;
|
||||
const guid_typescript_1 = require("guid-typescript");
|
||||
function createRandomUid() {
|
||||
const uuid = guid_typescript_1.Guid.create();
|
||||
return uuid.toString().substr(0, 10).replace('-', '');
|
||||
}
|
||||
exports.createRandomUid = createRandomUid;
|
43
AIWebQuickDeploy/dist/common/utils/date.js
vendored
43
AIWebQuickDeploy/dist/common/utils/date.js
vendored
@ -1,43 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isExpired = exports.formatCreateOrUpdateDate = exports.formatDate = void 0;
|
||||
const dayjs = require("dayjs");
|
||||
require("dayjs/locale/zh-cn");
|
||||
const a = require("dayjs/plugin/utc");
|
||||
const b = require("dayjs/plugin/timezone");
|
||||
dayjs.locale('zh-cn');
|
||||
dayjs.extend(a);
|
||||
dayjs.extend(b);
|
||||
dayjs.tz.setDefault('Asia/Shanghai');
|
||||
function formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
return dayjs(date).format(format);
|
||||
}
|
||||
exports.formatDate = formatDate;
|
||||
function formatCreateOrUpdateDate(input, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
if (Array.isArray(input)) {
|
||||
return input.map((t) => {
|
||||
t.createdAt = (t === null || t === void 0 ? void 0 : t.createdAt) ? dayjs(t.createdAt).format(format) : dayjs().format(format);
|
||||
t.updatedAt = (t === null || t === void 0 ? void 0 : t.updatedAt) ? dayjs(t.updatedAt).format(format) : dayjs().format(format);
|
||||
return t;
|
||||
});
|
||||
}
|
||||
else {
|
||||
let obj = {};
|
||||
try {
|
||||
obj = JSON.parse(JSON.stringify(input));
|
||||
}
|
||||
catch (error) {
|
||||
}
|
||||
(obj === null || obj === void 0 ? void 0 : obj.createdAt) && (obj.createdAt = dayjs(obj.createdAt).format(format));
|
||||
(obj === null || obj === void 0 ? void 0 : obj.updatedAt) && (obj.updatedAt = dayjs(obj.updatedAt).format(format));
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
exports.formatCreateOrUpdateDate = formatCreateOrUpdateDate;
|
||||
function isExpired(createdAt, days) {
|
||||
const expireDate = new Date(createdAt.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
const now = new Date();
|
||||
return now > expireDate;
|
||||
}
|
||||
exports.isExpired = isExpired;
|
||||
exports.default = dayjs;
|
14
AIWebQuickDeploy/dist/common/utils/encrypt.js
vendored
14
AIWebQuickDeploy/dist/common/utils/encrypt.js
vendored
@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.copyRightMsg = exports.atob = void 0;
|
||||
function atob(str) {
|
||||
return Buffer.from(str, 'base64').toString('utf-8');
|
||||
}
|
||||
exports.atob = atob;
|
||||
exports.copyRightMsg = [
|
||||
'agxoTstMY8m+DJO89Iwy4zqcFTqlcj/Fa/erMTvn0IexetXaDttr4K/BN2+RbtfouXOeFjPDYnxOfQ+IIpuJ3PmtyHAzmlGFls/HvBDeh6EXAQ3waALbvK9Ue96soAb5/3Tv6VuZE7npISqXiYhI6Vqx4yDVYf6vUUkEO9jvVotWQkLOLkr6M/guLK6sik/ZOgHvSlDYKAv79NFJJ0Tt0WkH2SyN8l+woMiWVTOKkdE=',
|
||||
'nXdXi8UU7J5av2eDOFjxQWlZDa+3bdASE4UwpqT6B11XSCweKKuzHxmFO2wx45iVlib/V0tt+NbEcOQZtzEWKqHsREkwEb5aqVCUl2Kj4nJeEFId2iyvY6MWEV1lHtCY+htpJoyqwQJc7yeNfpTl2SLBubWk77p4AHei1QFEs1rpOOwyE79lF0RqzY/Cpzhs',
|
||||
'VjVCGib1VFp7hNynpKGQPUrX+ishpxi2u5a4txHXzk2nyUP1NZfIomEDmGhDTQ7VRJLox+8urtVG1CBBSct1v+4OA2ucAcDUFoy1H1Kl1z+dndVcNU6gz5YGnDppsxY8uGFAVGsWrDl2DIOKxk7kMURaRiQCXCHRF/3sLGyIEmE6KL9Q4kDInB6vuzBScxupFShMXTq2XrOhwRgn2elcig==',
|
||||
'ZPcz1IaPDMGI3Yn9sm4QOT0qCZo7yZbJl4/c2RTrhUKINkjGB5yb0yN5vAnLtt/o8cmpoOoH3PUSOOWQa9aKD86NWK+1r8wBOVjwXZOpp2gbB1ZJLbWvjRbENvEJxVsLROXnpNDqUXVGxFMaIt+gmEi3Rp0thqC1soXUpvM1zqU4+LkQmunR7UytvzwXEmXBlIfPwz5hv+n/lxDsw526KWixC3jLLpeijw5433Zh7cI=',
|
||||
'YPo1HNzS6p6190ku4f1PQENUBa/ip+v+6sPuQXVyAn3axo6SLKQBszNr3PAW2EzWhZLy2o+nBgr3o3IOy9OgNit1JHrCklpVp172wbGDKh8sB8HCXyJoRv3BaZVY5UhyhpV5K+4nPoM2RUwvIGONUGFPQfPQv9N8MS8UCL7UnWYcVLzxWo0ZDg+UXFRr7NhXKu7KQ7e1+Wiqm0qE+olfDVowi4pGDRGrYL154wEEJUo='
|
||||
];
|
11
AIWebQuickDeploy/dist/common/utils/fromatUrl.js
vendored
11
AIWebQuickDeploy/dist/common/utils/fromatUrl.js
vendored
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.formatUrl = void 0;
|
||||
function formatUrl(url) {
|
||||
let formattedUrl = url.replace(/\s+/g, '');
|
||||
if (formattedUrl.endsWith('/')) {
|
||||
formattedUrl = formattedUrl.slice(0, -1);
|
||||
}
|
||||
return formattedUrl;
|
||||
}
|
||||
exports.formatUrl = formatUrl;
|
@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateCramiCode = void 0;
|
||||
const uuid_1 = require("uuid");
|
||||
function generateCramiCode() {
|
||||
const code = (0, uuid_1.v4)().replace(/-/g, '').slice(0, 16);
|
||||
return code;
|
||||
}
|
||||
exports.generateCramiCode = generateCramiCode;
|
@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getClientIp = void 0;
|
||||
function getFirstValidIp(ipString) {
|
||||
const ips = ipString.split(',').map(ip => ip.trim());
|
||||
return ips.find(ip => isValidIp(ip)) || '';
|
||||
}
|
||||
function isValidIp(ip) {
|
||||
return /^\d{1,3}(\.\d{1,3}){3}$/.test(ip) || /^::ffff:\d{1,3}(\.\d{1,3}){3}$/.test(ip);
|
||||
}
|
||||
function getClientIp(req) {
|
||||
const forwardedFor = req.header('x-forwarded-for');
|
||||
let clientIp = forwardedFor ? getFirstValidIp(forwardedFor) : '';
|
||||
if (!clientIp) {
|
||||
clientIp = req.connection.remoteAddress || req.socket.remoteAddress || '';
|
||||
}
|
||||
if (clientIp.startsWith('::ffff:')) {
|
||||
clientIp = clientIp.substring(7);
|
||||
}
|
||||
return clientIp;
|
||||
}
|
||||
exports.getClientIp = getClientIp;
|
@ -1,15 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getDiffArray = void 0;
|
||||
function getDiffArray(aLength, bLength, str) {
|
||||
const a = Array.from({ length: aLength }, (_, i) => i + 1);
|
||||
const b = Array.from({ length: bLength }, (_, i) => i + 1);
|
||||
const diffArray = [];
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!b.includes(a[i])) {
|
||||
diffArray.push(`${str}${a[i]}`);
|
||||
}
|
||||
}
|
||||
return diffArray;
|
||||
}
|
||||
exports.getDiffArray = getDiffArray;
|
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getRandomItem = void 0;
|
||||
function getRandomItem(array) {
|
||||
const randomIndex = Math.floor(Math.random() * array.length);
|
||||
return array[randomIndex];
|
||||
}
|
||||
exports.getRandomItem = getRandomItem;
|
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getRandomItemFromArray = void 0;
|
||||
function getRandomItemFromArray(array) {
|
||||
if (array.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const randomIndex = Math.floor(Math.random() * array.length);
|
||||
return array[randomIndex];
|
||||
}
|
||||
exports.getRandomItemFromArray = getRandomItemFromArray;
|
@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getTokenCount = void 0;
|
||||
const gpt_tokenizer_1 = require("gpt-tokenizer");
|
||||
const getTokenCount = async (input) => {
|
||||
let text = '';
|
||||
if (Array.isArray(input)) {
|
||||
text = input.reduce((pre, cur) => {
|
||||
if (Array.isArray(cur.content)) {
|
||||
const contentText = cur.content
|
||||
.filter((item) => item.type === 'text')
|
||||
.map((item) => item.text)
|
||||
.join(' ');
|
||||
return pre + contentText;
|
||||
}
|
||||
else {
|
||||
return pre + (cur.content || '');
|
||||
}
|
||||
}, '');
|
||||
}
|
||||
else if (typeof input === 'string') {
|
||||
text = input;
|
||||
}
|
||||
else if (input) {
|
||||
text = String(input);
|
||||
}
|
||||
text = text.replace(/<\|endoftext\|>/g, '');
|
||||
return (0, gpt_tokenizer_1.encode)(text).length;
|
||||
};
|
||||
exports.getTokenCount = getTokenCount;
|
@ -1,43 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.handleError = void 0;
|
||||
const axios_1 = require("axios");
|
||||
function handleError(error) {
|
||||
let message = '发生未知错误,请稍后再试';
|
||||
if (axios_1.default.isAxiosError(error) && error.response) {
|
||||
switch (error.response.status) {
|
||||
case 400:
|
||||
message =
|
||||
'发生错误:400 Bad Request - 请求因格式错误无法被服务器处理。';
|
||||
break;
|
||||
case 401:
|
||||
message = '发生错误:401 Unauthorized - 请求要求进行身份验证。';
|
||||
break;
|
||||
case 403:
|
||||
message = '发生错误:403 Forbidden - 服务器拒绝执行请求。';
|
||||
break;
|
||||
case 404:
|
||||
message = '发生错误:404 Not Found - 请求的资源无法在服务器上找到。';
|
||||
break;
|
||||
case 500:
|
||||
message =
|
||||
'发生错误:500 Internal Server Error - 服务器内部错误,无法完成请求。';
|
||||
break;
|
||||
case 502:
|
||||
message =
|
||||
'发生错误:502 Bad Gateway - 作为网关或代理工作的服务器从上游服务器收到无效响应。';
|
||||
break;
|
||||
case 503:
|
||||
message =
|
||||
'发生错误:503 Service Unavailable - 服务器暂时处于超负载或维护状态,无法处理请求。';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
message = error.message || message;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
exports.handleError = handleError;
|
14
AIWebQuickDeploy/dist/common/utils/hideString.js
vendored
14
AIWebQuickDeploy/dist/common/utils/hideString.js
vendored
@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hideString = void 0;
|
||||
function hideString(input, str) {
|
||||
const length = input.length;
|
||||
const start = input.slice(0, (length - 10) / 2);
|
||||
const end = input.slice((length + 10) / 2, length);
|
||||
const hidden = '*'.repeat(10);
|
||||
if (str) {
|
||||
return `**********${str}**********`;
|
||||
}
|
||||
return `${start}${hidden}${end}`;
|
||||
}
|
||||
exports.hideString = hideString;
|
39
AIWebQuickDeploy/dist/common/utils/index.js
vendored
39
AIWebQuickDeploy/dist/common/utils/index.js
vendored
@ -1,39 +0,0 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./base"), exports);
|
||||
__exportStar(require("./createOrderId"), exports);
|
||||
__exportStar(require("./createRandomCode"), exports);
|
||||
__exportStar(require("./createRandomInviteCode"), exports);
|
||||
__exportStar(require("./createRandomNonceStr"), exports);
|
||||
__exportStar(require("./createRandomUid"), exports);
|
||||
__exportStar(require("./date"), exports);
|
||||
__exportStar(require("./encrypt"), exports);
|
||||
__exportStar(require("./fromatUrl"), exports);
|
||||
__exportStar(require("./generateCrami"), exports);
|
||||
__exportStar(require("./getClientIp"), exports);
|
||||
__exportStar(require("./getDiffArray"), exports);
|
||||
__exportStar(require("./getRandomItem"), exports);
|
||||
__exportStar(require("./getRandomItemFromArray"), exports);
|
||||
__exportStar(require("./getTokenCount"), exports);
|
||||
__exportStar(require("./handleError"), exports);
|
||||
__exportStar(require("./hideString"), exports);
|
||||
__exportStar(require("./maskCrami"), exports);
|
||||
__exportStar(require("./maskEmail"), exports);
|
||||
__exportStar(require("./maskIpAddress"), exports);
|
||||
__exportStar(require("./removeSpecialCharacters"), exports);
|
||||
__exportStar(require("./tools"), exports);
|
||||
__exportStar(require("./utcformatTime"), exports);
|
11
AIWebQuickDeploy/dist/common/utils/maskCrami.js
vendored
11
AIWebQuickDeploy/dist/common/utils/maskCrami.js
vendored
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.maskCrami = void 0;
|
||||
function maskCrami(str) {
|
||||
if (str.length !== 16) {
|
||||
throw new Error('Invalid input');
|
||||
}
|
||||
const masked = str.substring(0, 6) + '****' + str.substring(10);
|
||||
return masked;
|
||||
}
|
||||
exports.maskCrami = maskCrami;
|
16
AIWebQuickDeploy/dist/common/utils/maskEmail.js
vendored
16
AIWebQuickDeploy/dist/common/utils/maskEmail.js
vendored
@ -1,16 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.maskEmail = void 0;
|
||||
function maskEmail(email) {
|
||||
if (!email)
|
||||
return '';
|
||||
const atIndex = email.indexOf('@');
|
||||
if (atIndex <= 1) {
|
||||
return email;
|
||||
}
|
||||
const firstPart = email.substring(0, atIndex - 1);
|
||||
const lastPart = email.substring(atIndex);
|
||||
const maskedPart = '*'.repeat(firstPart.length - 1);
|
||||
return `${firstPart.charAt(0)}${maskedPart}${email.charAt(atIndex - 1)}${lastPart}`;
|
||||
}
|
||||
exports.maskEmail = maskEmail;
|
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.maskIpAddress = void 0;
|
||||
function maskIpAddress(ipAddress) {
|
||||
if (!ipAddress)
|
||||
return '';
|
||||
const ipArray = ipAddress.split('.');
|
||||
ipArray[2] = '***';
|
||||
return ipArray.join('.');
|
||||
}
|
||||
exports.maskIpAddress = maskIpAddress;
|
@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.removeSpecialCharacters = void 0;
|
||||
function removeSpecialCharacters(inputString) {
|
||||
return inputString.replace(/[^\w\s-]/g, '');
|
||||
}
|
||||
exports.removeSpecialCharacters = removeSpecialCharacters;
|
8
AIWebQuickDeploy/dist/common/utils/tools.js
vendored
8
AIWebQuickDeploy/dist/common/utils/tools.js
vendored
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.importDynamic = exports.isNotEmptyString = void 0;
|
||||
function isNotEmptyString(value) {
|
||||
return typeof value === 'string' && value.length > 0;
|
||||
}
|
||||
exports.isNotEmptyString = isNotEmptyString;
|
||||
exports.importDynamic = new Function('modulePath', 'return import(modulePath)');
|
@ -1,16 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.utcToShanghaiTime = void 0;
|
||||
function utcToShanghaiTime(utcTime, format = 'YYYY/MM/DD hh:mm:ss') {
|
||||
const date = new Date(utcTime);
|
||||
const shanghaiTime = date.getTime() + 8 * 60 * 60 * 1000;
|
||||
const shanghaiDate = new Date(shanghaiTime);
|
||||
let result = format.replace('YYYY', shanghaiDate.getFullYear().toString());
|
||||
result = result.replace('MM', `0${shanghaiDate.getMonth() + 1}`.slice(-2));
|
||||
result = result.replace('DD', `0${shanghaiDate.getDate()}`.slice(-2));
|
||||
result = result.replace('hh', `0${shanghaiDate.getHours()}`.slice(-2));
|
||||
result = result.replace('mm', `0${shanghaiDate.getMinutes()}`.slice(-2));
|
||||
result = result.replace('ss', `0${shanghaiDate.getSeconds()}`.slice(-2));
|
||||
return result;
|
||||
}
|
||||
exports.utcToShanghaiTime = utcToShanghaiTime;
|
19725
AIWebQuickDeploy/dist/main.js
vendored
19725
AIWebQuickDeploy/dist/main.js
vendored
File diff suppressed because it is too large
Load Diff
44
AIWebQuickDeploy/dist/modules/ai/aiPPT.js
vendored
44
AIWebQuickDeploy/dist/modules/ai/aiPPT.js
vendored
@ -1,44 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var AiPptService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AiPptService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const models_service_1 = require("../models/models.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
const openaiChat_service_1 = require("./openaiChat.service");
|
||||
let AiPptService = AiPptService_1 = class AiPptService {
|
||||
constructor(uploadService, globalConfigService, chatLogService, openAIChatService, modelsService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.chatLogService = chatLogService;
|
||||
this.openAIChatService = openAIChatService;
|
||||
this.modelsService = modelsService;
|
||||
this.logger = new common_1.Logger(AiPptService_1.name);
|
||||
}
|
||||
async aiPPT(inputs) {
|
||||
return;
|
||||
}
|
||||
async pptCover(inputs) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
AiPptService = AiPptService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
chatLog_service_1.ChatLogService,
|
||||
openaiChat_service_1.OpenAIChatService,
|
||||
models_service_1.ModelsService])
|
||||
], AiPptService);
|
||||
exports.AiPptService = AiPptService;
|
214
AIWebQuickDeploy/dist/modules/ai/cogVideo.service.js
vendored
214
AIWebQuickDeploy/dist/modules/ai/cogVideo.service.js
vendored
@ -1,214 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CogVideoService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let CogVideoService = class CogVideoService {
|
||||
constructor(chatLogService, globalConfigService, uploadService) {
|
||||
this.chatLogService = chatLogService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.uploadService = uploadService;
|
||||
}
|
||||
async cogVideo(inputs) {
|
||||
var _a, _b, _c;
|
||||
const { apiKey, proxyUrl, fileInfo, prompt, timeout, assistantLogId } = inputs;
|
||||
let result = {
|
||||
text: '',
|
||||
fileInfo: '',
|
||||
taskId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
};
|
||||
let response = null;
|
||||
let url = '';
|
||||
let payloadJson = {};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
url = `${proxyUrl}/cogvideox/v4/videos/generations`;
|
||||
payloadJson = {
|
||||
model: 'cogvideox',
|
||||
prompt: prompt,
|
||||
};
|
||||
if (fileInfo) {
|
||||
payloadJson['image_url'] = fileInfo;
|
||||
}
|
||||
common_1.Logger.log(`正在准备发送请求到 ${url},payload: ${JSON.stringify(payloadJson)}, headers: ${JSON.stringify(headers)}`, 'CogService');
|
||||
try {
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
common_1.Logger.debug(`任务提交结果,状态码: ${response.status}, 状态消息: ${response.statusText}, 数据: ${JSON.stringify(response.data)}`);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`任务提交失败: ${error.message}`, 'CogService');
|
||||
throw new Error('任务提交失败');
|
||||
}
|
||||
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.id) {
|
||||
result.taskId = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.id;
|
||||
common_1.Logger.log(`任务提交成功, 任务ID: ${(_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.id}`, 'CogService');
|
||||
}
|
||||
else {
|
||||
throw new Error('未能获取结果数据, 即将重试');
|
||||
}
|
||||
try {
|
||||
await this.pollCogVideoResult({
|
||||
proxyUrl,
|
||||
apiKey,
|
||||
taskId: response.data.id,
|
||||
timeout,
|
||||
prompt,
|
||||
onSuccess: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: '100%',
|
||||
status: 3,
|
||||
taskId: data === null || data === void 0 ? void 0 : data.taskId,
|
||||
taskData: data === null || data === void 0 ? void 0 : data.taskData,
|
||||
});
|
||||
common_1.Logger.log('视频任务已完成', 'CogService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'CogService');
|
||||
}
|
||||
},
|
||||
onGenerating: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || '视频生成中...',
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('视频生成中...', 'CogService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'CogService');
|
||||
}
|
||||
},
|
||||
onFailure: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: '视频生成失败',
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('生成失败', 'Lum aService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'CogService');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('查询生成结果时发生错误:', error.message, 'CogService');
|
||||
throw new Error('查询生成结果时发生错误');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async pollCogVideoResult(inputs) {
|
||||
const { proxyUrl, apiKey, taskId, timeout, onSuccess, onFailure, onGenerating, prompt, action, } = inputs;
|
||||
let result = {
|
||||
videoUrl: '',
|
||||
audioUrl: '',
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
progress: 0,
|
||||
answer: '',
|
||||
};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
const url = `${proxyUrl}/cogvideox/v4/async-result/${taskId}`;
|
||||
const startTime = Date.now();
|
||||
const totalDuration = 300000;
|
||||
const POLL_INTERVAL = 5000;
|
||||
let retryCount = 0;
|
||||
try {
|
||||
while (Date.now() - startTime < timeout) {
|
||||
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
||||
try {
|
||||
const res = await axios_1.default.get(url, { headers });
|
||||
const interval = setInterval(() => {
|
||||
const elapsed = Date.now() - startTime;
|
||||
let percentage = Math.floor((elapsed / totalDuration) * 100);
|
||||
if (percentage >= 99)
|
||||
percentage = 99;
|
||||
result.answer = `视频生成中 (${percentage}%)`;
|
||||
}, 1000);
|
||||
const responses = res.data;
|
||||
common_1.Logger.debug(`轮询结果: ${JSON.stringify(responses)}`, 'CogService');
|
||||
if (responses.task_status === 'SUCCESS') {
|
||||
result.taskId = responses.request_id;
|
||||
result.taskData = JSON.stringify(responses);
|
||||
common_1.Logger.log('视频生成成功', 'CogService');
|
||||
result.fileInfo = responses.video_result[0].url;
|
||||
common_1.Logger.log(result.fileInfo, 'CogService');
|
||||
try {
|
||||
const localStorageStatus = await this.globalConfigService.getConfigs([
|
||||
'localStorageStatus',
|
||||
]);
|
||||
if (Number(localStorageStatus)) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: responses.video_result[0].url,
|
||||
dir: `video/cog/${currentDate}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传文件失败: ${error.message}`, 'CogService');
|
||||
}
|
||||
result.answer = `提示词: "${prompt}"`;
|
||||
onSuccess(result);
|
||||
clearInterval(interval);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
onGenerating(result);
|
||||
}
|
||||
if (result.progress) {
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
common_1.Logger.error(`轮询失败,重试次数: ${retryCount}`, 'CogService');
|
||||
}
|
||||
}
|
||||
common_1.Logger.error('轮询超时,请稍后再试!', 'CogService');
|
||||
result.status = 4;
|
||||
onFailure(result);
|
||||
throw new Error('查询超时,请稍后再试!');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`轮询过程中发生错误: ${error}`, 'CogService');
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
CogVideoService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [chatLog_service_1.ChatLogService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
upload_service_1.UploadService])
|
||||
], CogVideoService);
|
||||
exports.CogVideoService = CogVideoService;
|
148
AIWebQuickDeploy/dist/modules/ai/fluxDraw.service.js
vendored
148
AIWebQuickDeploy/dist/modules/ai/fluxDraw.service.js
vendored
@ -1,148 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var FluxDrawService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FluxDrawService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
const openaiChat_service_1 = require("./openaiChat.service");
|
||||
let FluxDrawService = FluxDrawService_1 = class FluxDrawService {
|
||||
constructor(uploadService, globalConfigService, chatLogService, openAIChatService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.chatLogService = chatLogService;
|
||||
this.openAIChatService = openAIChatService;
|
||||
this.logger = new common_1.Logger(FluxDrawService_1.name);
|
||||
}
|
||||
async fluxDraw(inputs, buildMessageFromParentMessageId) {
|
||||
var _a, _b, _c, _d;
|
||||
common_1.Logger.log('开始提交 Flux 绘图任务 ', 'DrawService');
|
||||
const { apiKey, model, proxyUrl, prompt, extraParam, timeout, onSuccess, onFailure, groupId, } = inputs;
|
||||
const isDalleChat = await this.globalConfigService.getConfigs([
|
||||
'isDalleChat',
|
||||
]);
|
||||
let drawPrompt;
|
||||
if (isDalleChat === '1') {
|
||||
try {
|
||||
common_1.Logger.log('已开启连续绘画模式', 'FluxDraw');
|
||||
const { messagesHistory } = await buildMessageFromParentMessageId(`参考上文,结合我的需求,给出绘画描述。我的需求是:${prompt}`, {
|
||||
groupId,
|
||||
systemMessage: '你是一个绘画提示词生成工具,请根据用户的要求,结合上下文,用一段文字,描述用户需要的绘画需求,不用包含任何礼貌性的寒暄,只需要场景的描述,可以适当联想',
|
||||
maxModelTokens: 8000,
|
||||
maxRounds: 5,
|
||||
fileInfo: '',
|
||||
}, this.chatLogService);
|
||||
drawPrompt = await this.openAIChatService.chatFree(prompt, undefined, messagesHistory);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('调用chatFree失败:', error);
|
||||
drawPrompt = prompt;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawPrompt = prompt;
|
||||
}
|
||||
const size = (extraParam === null || extraParam === void 0 ? void 0 : extraParam.size) || '1024x1024';
|
||||
let result = { answer: '', fileInfo: '', status: 2 };
|
||||
try {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/images/generations`,
|
||||
timeout: timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
data: {
|
||||
model: model,
|
||||
prompt: drawPrompt,
|
||||
size,
|
||||
},
|
||||
};
|
||||
common_1.Logger.log(`正在准备发送请求到 ${options.url},payload: ${JSON.stringify(options.data)}, headers: ${JSON.stringify(options.headers)}`, 'FluxDrawService');
|
||||
const response = await (0, axios_1.default)(options);
|
||||
common_1.Logger.debug(`请求成功${JSON.stringify(response.data.data[0])}`);
|
||||
common_1.Logger.debug(`请求状态${JSON.stringify(response.status)}`);
|
||||
const url = response.data.data[0].url;
|
||||
try {
|
||||
common_1.Logger.log(`------> 开始上传图片!!!`, 'DrawService');
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `images/dalle/${currentDate}`,
|
||||
});
|
||||
common_1.Logger.log(`图片上传成功,URL: ${result.fileInfo}`, 'DrawService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传图片过程中出现错误: ${error}`, 'DrawService');
|
||||
}
|
||||
let revised_prompt_cn;
|
||||
try {
|
||||
revised_prompt_cn = await this.openAIChatService.chatFree(`根据提示词{${drawPrompt}}, 模拟AI绘画机器人的语气,用中文回复,告诉用户已经画好了`);
|
||||
}
|
||||
catch (error) {
|
||||
revised_prompt_cn = `${prompt} 绘制成功`;
|
||||
common_1.Logger.error('翻译失败: ', error);
|
||||
}
|
||||
result.answer = revised_prompt_cn;
|
||||
result.status = 3;
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
catch (error) {
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
const status = ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) || 500;
|
||||
console.log('draw error: ', JSON.stringify(error), status);
|
||||
const message = (_d = (_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.message;
|
||||
if (status === 429) {
|
||||
result.text = '当前请求已过载、请稍等会儿再试试吧!';
|
||||
return result;
|
||||
}
|
||||
if (status === 400 &&
|
||||
message.includes('This request has been blocked by our content filters')) {
|
||||
result.text = '您的请求已被系统拒绝。您的提示可能存在一些非法的文本。';
|
||||
return result;
|
||||
}
|
||||
if (status === 400 &&
|
||||
message.includes('Billing hard limit has been reached')) {
|
||||
result.text =
|
||||
'当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧!';
|
||||
return result;
|
||||
}
|
||||
if (status === 500) {
|
||||
result.text = '绘制图片失败,请检查你的提示词是否有非法描述!';
|
||||
return result;
|
||||
}
|
||||
if (status === 401) {
|
||||
result.text = '绘制图片失败,此次绘画被拒绝了!';
|
||||
return result;
|
||||
}
|
||||
result.text = '绘制图片失败,请稍后试试吧!';
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
FluxDrawService = FluxDrawService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
chatLog_service_1.ChatLogService,
|
||||
openaiChat_service_1.OpenAIChatService])
|
||||
], FluxDrawService);
|
||||
exports.FluxDrawService = FluxDrawService;
|
@ -1,213 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LumaVideoService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let LumaVideoService = class LumaVideoService {
|
||||
constructor(chatLogService, globalConfigService, uploadService) {
|
||||
this.chatLogService = chatLogService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.uploadService = uploadService;
|
||||
}
|
||||
async lumaVideo(inputs) {
|
||||
var _a, _b, _c;
|
||||
const { apiKey, proxyUrl, fileInfo, prompt, timeout, assistantLogId, extraParam, } = inputs;
|
||||
let result = {
|
||||
text: '',
|
||||
fileInfo: '',
|
||||
taskId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
};
|
||||
let response = null;
|
||||
let url = '';
|
||||
let payloadJson = {};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
url = `${proxyUrl}/luma/generations/`;
|
||||
const aspectRatio = extraParam.size || '16:9';
|
||||
payloadJson = {
|
||||
user_prompt: prompt,
|
||||
aspect_ratio: aspectRatio,
|
||||
expand_prompt: true,
|
||||
};
|
||||
if (fileInfo) {
|
||||
payloadJson['image_url'] = fileInfo;
|
||||
}
|
||||
common_1.Logger.log(`正在准备发送请求到 ${url},payload: ${JSON.stringify(payloadJson)}, headers: ${JSON.stringify(headers)}`, 'LumaService');
|
||||
try {
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`任务提交失败: ${error.message}`, 'LumaService');
|
||||
throw new Error('任务提交失败');
|
||||
}
|
||||
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.id) {
|
||||
result.taskId = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.id;
|
||||
common_1.Logger.log(`任务提交成功, 任务ID: ${(_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.id}`, 'LumaService');
|
||||
}
|
||||
else {
|
||||
throw new Error('未能获取结果数据, 即将重试');
|
||||
}
|
||||
try {
|
||||
await this.pollLumaVideoResult({
|
||||
proxyUrl,
|
||||
apiKey,
|
||||
taskId: response.data.id,
|
||||
timeout,
|
||||
prompt,
|
||||
onSuccess: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: '100%',
|
||||
status: 3,
|
||||
taskId: data === null || data === void 0 ? void 0 : data.taskId,
|
||||
taskData: data === null || data === void 0 ? void 0 : data.taskData,
|
||||
});
|
||||
common_1.Logger.log('视频任务已完成', 'LumaService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'LumaService');
|
||||
}
|
||||
},
|
||||
onGenerating: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || '视频生成中...',
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('视频生成中...', 'LumaService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'LumaService');
|
||||
}
|
||||
},
|
||||
onFailure: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: '视频生成失败',
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('生成失败', 'Lum aService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'LumaService');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('查询生成结果时发生错误:', error.message, 'LumaService');
|
||||
throw new Error('查询生成结果时发生错误');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async pollLumaVideoResult(inputs) {
|
||||
const { proxyUrl, apiKey, taskId, timeout, onSuccess, onFailure, onGenerating, action, } = inputs;
|
||||
let result = {
|
||||
videoUrl: '',
|
||||
audioUrl: '',
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
progress: 0,
|
||||
answer: '',
|
||||
};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
const url = `${proxyUrl}/luma/generations/${taskId}`;
|
||||
const startTime = Date.now();
|
||||
const totalDuration = 300000;
|
||||
const POLL_INTERVAL = 5000;
|
||||
let retryCount = 0;
|
||||
try {
|
||||
while (Date.now() - startTime < timeout) {
|
||||
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
||||
try {
|
||||
const res = await axios_1.default.get(url, { headers });
|
||||
const interval = setInterval(() => {
|
||||
const elapsed = Date.now() - startTime;
|
||||
let percentage = Math.floor((elapsed / totalDuration) * 100);
|
||||
if (percentage >= 99)
|
||||
percentage = 99;
|
||||
result.answer = `视频生成中 (${percentage}%)`;
|
||||
}, 1000);
|
||||
const responses = res.data;
|
||||
common_1.Logger.debug(`轮询结果: ${JSON.stringify(responses)}`, 'LumaService');
|
||||
if (responses.state === 'completed') {
|
||||
result.taskId = responses.id;
|
||||
result.taskData = JSON.stringify(responses);
|
||||
result.fileInfo = responses.video.url;
|
||||
try {
|
||||
const localStorageStatus = await this.globalConfigService.getConfigs([
|
||||
'localStorageStatus',
|
||||
]);
|
||||
if (Number(localStorageStatus)) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: responses.video.download_url,
|
||||
dir: `video/luma/${currentDate}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传文件失败: ${error.message}`, 'LumaService');
|
||||
}
|
||||
result.answer = `提示词: "${responses.prompt}"`;
|
||||
onSuccess(result);
|
||||
clearInterval(interval);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
onGenerating(result);
|
||||
}
|
||||
if (result.progress) {
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
common_1.Logger.error(`轮询失败,重试次数: ${retryCount}`, 'LumaService');
|
||||
}
|
||||
}
|
||||
common_1.Logger.error('轮询超时,请稍后再试!', 'LumaService');
|
||||
result.status = 4;
|
||||
onFailure(result);
|
||||
throw new Error('查询超时,请稍后再试!');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`轮询过程中发生错误: ${error}`, 'LumaService');
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
LumaVideoService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [chatLog_service_1.ChatLogService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
upload_service_1.UploadService])
|
||||
], LumaVideoService);
|
||||
exports.LumaVideoService = LumaVideoService;
|
@ -1,237 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MidjourneyService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let MidjourneyService = class MidjourneyService {
|
||||
constructor(uploadService, globalConfigService, chatLogService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.chatLogService = chatLogService;
|
||||
}
|
||||
async midjourneyDraw(inputs) {
|
||||
var _a, _b, _c, _d;
|
||||
const { id, apiKey, proxyUrl, action, drawId, prompt, usePrompt, customId, timeout, fileInfo, assistantLogId, } = inputs;
|
||||
let result = {
|
||||
text: '',
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
customId: '',
|
||||
status: 2,
|
||||
};
|
||||
let response;
|
||||
let retryCount = 0;
|
||||
let url = '';
|
||||
const headers = { 'mj-api-secret': apiKey };
|
||||
common_1.Logger.debug(`当前任务类型: ${action}`, 'MidjourneyService');
|
||||
while (retryCount < 3) {
|
||||
let payloadJson = {};
|
||||
try {
|
||||
if (action === 'IMAGINE') {
|
||||
url = `${proxyUrl}/mj/submit/imagine`;
|
||||
payloadJson = { prompt: usePrompt };
|
||||
}
|
||||
else if (action === 'DESCRIBE') {
|
||||
url = `${proxyUrl}/mj/submit/describe`;
|
||||
if (fileInfo) {
|
||||
const response = await fetch(fileInfo);
|
||||
const blob = await response.blob();
|
||||
const buffer = Buffer.from(await blob.arrayBuffer());
|
||||
const base64String = buffer.toString('base64');
|
||||
payloadJson = { base64: `data:image/png;base64,${base64String}` };
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (action === 'PICREADER') {
|
||||
url = `${proxyUrl}/mj/submit/action`;
|
||||
payloadJson = { taskId: drawId, customId: customId };
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
if ((response === null || response === void 0 ? void 0 : response.status) === 200 && ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.result)) {
|
||||
url = `${proxyUrl}/mj/submit/modal`;
|
||||
payloadJson = { taskId: (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.result };
|
||||
}
|
||||
}
|
||||
else {
|
||||
url = `${proxyUrl}/mj/submit/action`;
|
||||
payloadJson = { taskId: drawId, customId: customId };
|
||||
}
|
||||
common_1.Logger.log(`正在准备发送请求到 ${url},payload: ${JSON.stringify(payloadJson)}, headers: ${JSON.stringify(headers)}`, 'MidjourneyService');
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
if ((response === null || response === void 0 ? void 0 : response.status) === 200 && ((_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.result)) {
|
||||
common_1.Logger.debug(`收到响应: ${JSON.stringify(response.data)}`, 'MidjourneyService');
|
||||
result.drawId = (_d = response === null || response === void 0 ? void 0 : response.data) === null || _d === void 0 ? void 0 : _d.result;
|
||||
result.state = 2;
|
||||
result.answer = '绘画任务提交成功';
|
||||
common_1.Logger.log(`绘画任务提交成功, 绘画ID: ${response.data.result}`, 'MidjourneyService');
|
||||
break;
|
||||
}
|
||||
else {
|
||||
throw new Error('未能获取结果数据, 即将重试');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
if (retryCount >= 3) {
|
||||
result.answer = '任务提交失败,请检查提示词后重试';
|
||||
result.status = 5;
|
||||
common_1.Logger.log(`绘画任务提交失败, 请检查后台配置或者稍后重试! ${error}`, 'MidjourneyService');
|
||||
}
|
||||
}
|
||||
}
|
||||
this.pollMjDrawingResult({
|
||||
proxyUrl,
|
||||
apiKey,
|
||||
drawId: result.drawId,
|
||||
timeout,
|
||||
prompt,
|
||||
onSuccess: async (data) => {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: '100%',
|
||||
status: 3,
|
||||
drawId: data === null || data === void 0 ? void 0 : data.drawId,
|
||||
customId: data === null || data === void 0 ? void 0 : data.customId,
|
||||
});
|
||||
common_1.Logger.log('绘图成功!', 'MidjourneyService');
|
||||
},
|
||||
onDrawing: async (data) => {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || '绘制中',
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: 2,
|
||||
});
|
||||
common_1.Logger.log(`绘制中!绘制进度${data === null || data === void 0 ? void 0 : data.progress}`, 'MidjourneyService');
|
||||
},
|
||||
onFailure: async (data) => {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: '绘图失败',
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('绘图失败', 'MidjourneyService');
|
||||
},
|
||||
}).catch((error) => {
|
||||
common_1.Logger.error('查询绘图结果时发生错误:', error, 'MidjourneyService');
|
||||
});
|
||||
return result;
|
||||
}
|
||||
async pollMjDrawingResult(inputs) {
|
||||
const { proxyUrl, apiKey, drawId, timeout, onSuccess, prompt, onFailure, onDrawing, } = inputs;
|
||||
const { mjNotSaveImg, mjProxyImgUrl, mjNotUseProxy } = await this.globalConfigService.getConfigs([
|
||||
'mjNotSaveImg',
|
||||
'mjProxyImgUrl',
|
||||
'mjNotUseProxy',
|
||||
]);
|
||||
let result = {
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
customId: '',
|
||||
status: 2,
|
||||
progress: 0,
|
||||
answer: '',
|
||||
};
|
||||
const startTime = Date.now();
|
||||
const POLL_INTERVAL = 5000;
|
||||
let retryCount = 0;
|
||||
try {
|
||||
while (Date.now() - startTime < timeout) {
|
||||
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
||||
try {
|
||||
const headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'mj-api-secret': apiKey,
|
||||
};
|
||||
const url = `${proxyUrl}/mj/task/${drawId}/fetch`;
|
||||
const res = await axios_1.default.get(url, { headers });
|
||||
const responses = res.data;
|
||||
common_1.Logger.debug(`查询结果: ${JSON.stringify(responses)}`, 'MidjourneyService');
|
||||
if (responses.status === 'SUCCESS') {
|
||||
common_1.Logger.log(`绘制成功, 获取到的URL: ${responses.imageUrl}`, 'MidjourneyService');
|
||||
let processedUrl = responses.imageUrl;
|
||||
const shouldReplaceUrl = mjNotUseProxy === '0' && mjProxyImgUrl;
|
||||
let logMessage = '';
|
||||
if (shouldReplaceUrl) {
|
||||
const newUrlBase = new URL(mjProxyImgUrl);
|
||||
const parsedUrl = new URL(responses.imageUrl);
|
||||
parsedUrl.protocol = newUrlBase.protocol;
|
||||
parsedUrl.hostname = newUrlBase.hostname;
|
||||
parsedUrl.port = newUrlBase.port ? newUrlBase.port : '';
|
||||
processedUrl = parsedUrl.toString();
|
||||
logMessage = `使用代理替换后的 URL: ${processedUrl}`;
|
||||
common_1.Logger.log(logMessage, 'MidjourneyService');
|
||||
}
|
||||
if (mjNotSaveImg !== '1') {
|
||||
try {
|
||||
common_1.Logger.log(`------> 开始上传图片!!!`, 'MidjourneyService');
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
processedUrl = await this.uploadService.uploadFileFromUrl({
|
||||
url: processedUrl,
|
||||
dir: `images/midjourney/${currentDate}`,
|
||||
});
|
||||
logMessage = `上传成功 URL: ${processedUrl}`;
|
||||
}
|
||||
catch (uploadError) {
|
||||
common_1.Logger.error('存储图片失败,使用原始/代理图片链接');
|
||||
logMessage = `存储图片失败,使用原始/代理图片链接 ${processedUrl}`;
|
||||
}
|
||||
common_1.Logger.log(logMessage, 'MidjourneyService');
|
||||
}
|
||||
else {
|
||||
logMessage = `不保存图片,使用 URL: ${processedUrl}`;
|
||||
common_1.Logger.log(logMessage, 'MidjourneyService');
|
||||
}
|
||||
result.fileInfo = processedUrl;
|
||||
result.drawId = responses.id;
|
||||
result.customId = JSON.stringify(responses.buttons);
|
||||
result.answer = `${prompt}\n${responses.finalPrompt || responses.properties.finalPrompt || ''}`;
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
result.progress = responses === null || responses === void 0 ? void 0 : responses.progress;
|
||||
result.answer = `当前绘制进度 ${responses === null || responses === void 0 ? void 0 : responses.progress}`;
|
||||
if (result.progress) {
|
||||
onDrawing(result);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
common_1.Logger.error(`轮询过程中发生错误: ${error}`, 'MidjourneyService');
|
||||
}
|
||||
}
|
||||
common_1.Logger.error(`超过 ${startTime / 1000} s 未完成绘画, 请稍后再试! MidjourneyService`);
|
||||
result.status = 4;
|
||||
onFailure(result);
|
||||
throw new common_1.HttpException('绘画超时,请稍后再试!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`绘画失败: ${error} MidjourneyService`);
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
MidjourneyService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
chatLog_service_1.ChatLogService])
|
||||
], MidjourneyService);
|
||||
exports.MidjourneyService = MidjourneyService;
|
@ -1,128 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.netSearchService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
let netSearchService = class netSearchService {
|
||||
constructor(globalConfigService) {
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
async webSearchPro(prompt) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
try {
|
||||
const { pluginUrl, pluginKey } = await this.globalConfigService.getConfigs(['pluginUrl', 'pluginKey']);
|
||||
if (!pluginUrl || !pluginKey) {
|
||||
common_1.Logger.warn('搜索插件配置缺失');
|
||||
return { searchResults: [] };
|
||||
}
|
||||
const keys = pluginKey.split(',').filter((key) => key.trim());
|
||||
const selectedKey = keys[Math.floor(Math.random() * keys.length)];
|
||||
const isBochaiApi = pluginUrl.includes('bochaai.com');
|
||||
const isBigModelApi = pluginUrl.includes('bigmodel.cn');
|
||||
const isTavilyApi = pluginUrl.includes('tavily.com');
|
||||
common_1.Logger.log(`[搜索] API类型: ${isBochaiApi
|
||||
? 'Bochai'
|
||||
: isBigModelApi
|
||||
? 'BigModel'
|
||||
: isTavilyApi
|
||||
? 'Tavily'
|
||||
: '未知'}`);
|
||||
common_1.Logger.log(`[搜索] 请求URL: ${pluginUrl}`);
|
||||
common_1.Logger.log(`[搜索] 搜索关键词: ${prompt}`);
|
||||
const requestBody = isBochaiApi
|
||||
? {
|
||||
query: prompt,
|
||||
freshness: 'oneWeek',
|
||||
summary: true,
|
||||
}
|
||||
: isTavilyApi
|
||||
? {
|
||||
query: prompt,
|
||||
search_depth: 'basic',
|
||||
include_answer: false,
|
||||
include_raw_content: false,
|
||||
include_images: false,
|
||||
}
|
||||
: {
|
||||
tool: 'web-search-pro',
|
||||
stream: false,
|
||||
messages: [{ role: 'user', content: prompt }],
|
||||
};
|
||||
common_1.Logger.log(`[搜索] 请求参数: ${JSON.stringify(requestBody, null, 2)}`);
|
||||
const response = await fetch(pluginUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: selectedKey,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
if (!response.ok) {
|
||||
common_1.Logger.error(`[搜索] 接口返回错误: ${response.status}`);
|
||||
return { searchResults: [] };
|
||||
}
|
||||
const apiResult = await response.json();
|
||||
common_1.Logger.log(`[搜索] 原始返回数据: ${JSON.stringify(apiResult, null, 2)}`);
|
||||
let searchResults = [];
|
||||
if (isBochaiApi) {
|
||||
if ((apiResult === null || apiResult === void 0 ? void 0 : apiResult.code) === 200 && ((_b = (_a = apiResult === null || apiResult === void 0 ? void 0 : apiResult.data) === null || _a === void 0 ? void 0 : _a.webPages) === null || _b === void 0 ? void 0 : _b.value)) {
|
||||
searchResults = apiResult.data.webPages.value.map((item) => ({
|
||||
title: (item === null || item === void 0 ? void 0 : item.name) || '',
|
||||
link: (item === null || item === void 0 ? void 0 : item.url) || '',
|
||||
content: (item === null || item === void 0 ? void 0 : item.summary) || '',
|
||||
icon: (item === null || item === void 0 ? void 0 : item.siteIcon) || '',
|
||||
media: (item === null || item === void 0 ? void 0 : item.siteName) || '',
|
||||
}));
|
||||
}
|
||||
}
|
||||
else if (isBigModelApi) {
|
||||
if (((_f = (_e = (_d = (_c = apiResult === null || apiResult === void 0 ? void 0 : apiResult.choices) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.tool_calls) === null || _f === void 0 ? void 0 : _f.length) > 0) {
|
||||
for (const toolCall of apiResult.choices[0].message.tool_calls) {
|
||||
if (Array.isArray(toolCall.search_result)) {
|
||||
searchResults = toolCall.search_result.map((item) => ({
|
||||
title: (item === null || item === void 0 ? void 0 : item.title) || '',
|
||||
link: (item === null || item === void 0 ? void 0 : item.link) || '',
|
||||
content: (item === null || item === void 0 ? void 0 : item.content) || '',
|
||||
icon: (item === null || item === void 0 ? void 0 : item.icon) || '',
|
||||
media: (item === null || item === void 0 ? void 0 : item.media) || '',
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isTavilyApi) {
|
||||
if (Array.isArray(apiResult === null || apiResult === void 0 ? void 0 : apiResult.results)) {
|
||||
searchResults = apiResult.results.map((item) => ({
|
||||
title: (item === null || item === void 0 ? void 0 : item.title) || '',
|
||||
link: (item === null || item === void 0 ? void 0 : item.url) || '',
|
||||
content: (item === null || item === void 0 ? void 0 : item.content) || '',
|
||||
icon: '',
|
||||
media: '',
|
||||
}));
|
||||
}
|
||||
}
|
||||
const formattedResult = searchResults.map((item, index) => (Object.assign({ resultIndex: index + 1 }, item)));
|
||||
common_1.Logger.log(`[搜索] 格式化后的结果: ${JSON.stringify(formattedResult, null, 2)}`);
|
||||
return { searchResults: formattedResult };
|
||||
}
|
||||
catch (fetchError) {
|
||||
common_1.Logger.error('[搜索] 调用接口出错:', fetchError);
|
||||
return { searchResults: [] };
|
||||
}
|
||||
}
|
||||
};
|
||||
netSearchService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [globalConfig_service_1.GlobalConfigService])
|
||||
], netSearchService);
|
||||
exports.netSearchService = netSearchService;
|
@ -1,180 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OpenAIChatService = void 0;
|
||||
const utils_1 = require("../../common/utils");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
let OpenAIChatService = class OpenAIChatService {
|
||||
constructor(globalConfigService) {
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
async openAIChat(messagesHistory, inputs) {
|
||||
const { onFailure, onProgress, apiKey, model, proxyUrl, modelName, timeout, chatId, isFileUpload, modelAvatar, temperature, abortController, } = inputs;
|
||||
let result = {
|
||||
text: '',
|
||||
model: '',
|
||||
modelName: modelName,
|
||||
chatId: chatId,
|
||||
answer: '',
|
||||
errMsg: '',
|
||||
modelAvatar: modelAvatar,
|
||||
};
|
||||
const data = Object.assign({ model, messages: messagesHistory }, (isFileUpload === 2 && { max_tokens: 2048 }));
|
||||
data.stream = true;
|
||||
data.temperature = temperature;
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/chat/completions`,
|
||||
responseType: 'stream',
|
||||
timeout: timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
data: data,
|
||||
};
|
||||
const sanitizedOptions = await this.sanitizeOptionsForLogging(options);
|
||||
console.log('请求配置:', JSON.stringify(sanitizedOptions, null, 2), 'ChatService');
|
||||
console.log('请求配置:', JSON.stringify(sanitizedOptions, null, 2), 'ChatService');
|
||||
try {
|
||||
const response = await (0, axios_1.default)(options);
|
||||
const stream = response.data;
|
||||
let buffer = '';
|
||||
await new Promise((resolve, reject) => {
|
||||
stream.on('data', (chunk) => {
|
||||
buffer += chunk.toString();
|
||||
let lines = buffer.split('\n');
|
||||
buffer = lines.pop();
|
||||
lines.forEach((line) => {
|
||||
var _a, _b;
|
||||
if (line.trim() === 'data: [DONE]') {
|
||||
console.log('处理结束信号 [DONE]');
|
||||
resolve(result);
|
||||
return;
|
||||
}
|
||||
if (line.startsWith('data: ')) {
|
||||
try {
|
||||
const cleanedLine = line.slice(6).trim();
|
||||
if (cleanedLine) {
|
||||
const jsonLine = JSON.parse(cleanedLine);
|
||||
const content = ((_b = (_a = jsonLine.choices[0]) === null || _a === void 0 ? void 0 : _a.delta) === null || _b === void 0 ? void 0 : _b.content) || '';
|
||||
result.answer += content;
|
||||
onProgress === null || onProgress === void 0 ? void 0 : onProgress({ text: content, answer: result.answer });
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Error parsing line:', line, error);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
stream.on('end', () => {
|
||||
resolve(result);
|
||||
});
|
||||
stream.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
abortController.signal.addEventListener('abort', () => {
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
catch (error) {
|
||||
result.errMsg = (0, utils_1.handleError)(error);
|
||||
common_1.Logger.error(result.errMsg);
|
||||
onFailure(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
async sanitizeOptionsForLogging(options) {
|
||||
const sanitizedOptions = JSON.parse(JSON.stringify(options));
|
||||
if (sanitizedOptions.headers && sanitizedOptions.headers.Authorization) {
|
||||
const authHeader = sanitizedOptions.headers.Authorization;
|
||||
if (authHeader.startsWith('Bearer ')) {
|
||||
const token = authHeader.slice(7);
|
||||
if (token.length > 10) {
|
||||
sanitizedOptions.headers.Authorization = `Bearer ${token.slice(0, 5)}****${token.slice(-4)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sanitizedOptions.data &&
|
||||
sanitizedOptions.data.messages &&
|
||||
Array.isArray(sanitizedOptions.data.messages)) {
|
||||
sanitizedOptions.data.messages = sanitizedOptions.data.messages.map((message) => {
|
||||
if (message.content && Array.isArray(message.content)) {
|
||||
message.content = message.content.map((content) => {
|
||||
if (content.type === 'image_url' &&
|
||||
content.image_url &&
|
||||
content.image_url.url) {
|
||||
content.image_url.url = 'data:image/***;base64 ... ...';
|
||||
}
|
||||
return content;
|
||||
});
|
||||
}
|
||||
return message;
|
||||
});
|
||||
}
|
||||
return sanitizedOptions;
|
||||
}
|
||||
async chatFree(prompt, systemMessage, messagesHistory) {
|
||||
const { openaiBaseUrl = '', openaiBaseKey = '', openaiBaseModel, } = await this.globalConfigService.getConfigs([
|
||||
'openaiBaseKey',
|
||||
'openaiBaseUrl',
|
||||
'openaiBaseModel',
|
||||
]);
|
||||
const key = openaiBaseKey;
|
||||
const proxyUrl = openaiBaseUrl;
|
||||
let requestData = [];
|
||||
if (systemMessage) {
|
||||
requestData.push({
|
||||
role: 'system',
|
||||
content: systemMessage,
|
||||
});
|
||||
}
|
||||
if (messagesHistory && messagesHistory.length > 0) {
|
||||
requestData = requestData.concat(messagesHistory);
|
||||
}
|
||||
else {
|
||||
requestData.push({
|
||||
role: 'user',
|
||||
content: prompt,
|
||||
});
|
||||
}
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/chat/completions`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${key}`,
|
||||
},
|
||||
data: {
|
||||
model: openaiBaseModel || 'gpt-3.5-turbo-0125',
|
||||
messages: requestData,
|
||||
},
|
||||
};
|
||||
try {
|
||||
const response = await (0, axios_1.default)(options);
|
||||
common_1.Logger.log(`全局模型调用成功, 返回结果: ${response === null || response === void 0 ? void 0 : response.data.choices[0].message.content}`, 'ChatService');
|
||||
return response === null || response === void 0 ? void 0 : response.data.choices[0].message.content;
|
||||
}
|
||||
catch (error) {
|
||||
console.log('error: ', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
OpenAIChatService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [globalConfig_service_1.GlobalConfigService])
|
||||
], OpenAIChatService);
|
||||
exports.OpenAIChatService = OpenAIChatService;
|
@ -1,145 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var OpenAIDrawService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OpenAIDrawService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
const openaiChat_service_1 = require("./openaiChat.service");
|
||||
let OpenAIDrawService = OpenAIDrawService_1 = class OpenAIDrawService {
|
||||
constructor(uploadService, globalConfigService, chatLogService, openAIChatService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.chatLogService = chatLogService;
|
||||
this.openAIChatService = openAIChatService;
|
||||
this.logger = new common_1.Logger(OpenAIDrawService_1.name);
|
||||
}
|
||||
async dalleDraw(inputs, buildMessageFromParentMessageId) {
|
||||
var _a, _b, _c, _d;
|
||||
common_1.Logger.log('开始提交 Dalle 绘图任务 ', 'DrawService');
|
||||
const { apiKey, model, proxyUrl, prompt, extraParam, timeout, onSuccess, onFailure, groupId, } = inputs;
|
||||
const isDalleChat = await this.globalConfigService.getConfigs([
|
||||
'isDalleChat',
|
||||
]);
|
||||
let drawPrompt;
|
||||
if (isDalleChat === '1') {
|
||||
try {
|
||||
common_1.Logger.log('已开启连续绘画模式', 'DalleDraw');
|
||||
const { messagesHistory } = await buildMessageFromParentMessageId(`参考上文,结合我的需求,给出绘画描述。我的需求是:${prompt}`, {
|
||||
groupId,
|
||||
systemMessage: '你是一个绘画提示词生成工具,请根据用户的要求,结合上下文,用一段文字,描述用户需要的绘画需求,不用包含任何礼貌性的寒暄,只需要场景的描述,可以适当联想',
|
||||
maxModelTokens: 8000,
|
||||
maxRounds: 5,
|
||||
fileInfo: '',
|
||||
}, this.chatLogService);
|
||||
drawPrompt = await this.openAIChatService.chatFree(prompt, undefined, messagesHistory);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('调用chatFree失败:', error);
|
||||
drawPrompt = prompt;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawPrompt = prompt;
|
||||
}
|
||||
const size = (extraParam === null || extraParam === void 0 ? void 0 : extraParam.size) || '1024x1024';
|
||||
let result = { answer: '', fileInfo: '', status: 2 };
|
||||
try {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/images/generations`,
|
||||
timeout: timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
data: {
|
||||
model: model,
|
||||
prompt: drawPrompt,
|
||||
size,
|
||||
},
|
||||
};
|
||||
const response = await (0, axios_1.default)(options);
|
||||
const url = response.data.data[0].url;
|
||||
try {
|
||||
common_1.Logger.log(`------> 开始上传图片!!!`, 'DrawService');
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `images/dalle/${currentDate}`,
|
||||
});
|
||||
common_1.Logger.log(`图片上传成功,URL: ${result.fileInfo}`, 'DrawService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传图片过程中出现错误: ${error}`, 'DrawService');
|
||||
}
|
||||
let revised_prompt_cn;
|
||||
try {
|
||||
revised_prompt_cn = await this.openAIChatService.chatFree(`根据提示词{${response.data.data[0].revised_prompt}}, 模拟AI绘画机器人的语气,用中文回复,告诉用户已经画好了`);
|
||||
}
|
||||
catch (error) {
|
||||
revised_prompt_cn = `${prompt} 绘制成功`;
|
||||
common_1.Logger.error('翻译失败: ', error);
|
||||
}
|
||||
result.answer = revised_prompt_cn;
|
||||
result.status = 3;
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
catch (error) {
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
const status = ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) || 500;
|
||||
console.log('draw error: ', JSON.stringify(error), status);
|
||||
const message = (_d = (_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.message;
|
||||
if (status === 429) {
|
||||
result.text = '当前请求已过载、请稍等会儿再试试吧!';
|
||||
return result;
|
||||
}
|
||||
if (status === 400 &&
|
||||
message.includes('This request has been blocked by our content filters')) {
|
||||
result.text = '您的请求已被系统拒绝。您的提示可能存在一些非法的文本。';
|
||||
return result;
|
||||
}
|
||||
if (status === 400 &&
|
||||
message.includes('Billing hard limit has been reached')) {
|
||||
result.text =
|
||||
'当前模型key已被封禁、已冻结当前调用Key、尝试重新对话试试吧!';
|
||||
return result;
|
||||
}
|
||||
if (status === 500) {
|
||||
result.text = '绘制图片失败,请检查你的提示词是否有非法描述!';
|
||||
return result;
|
||||
}
|
||||
if (status === 401) {
|
||||
result.text = '绘制图片失败,此次绘画被拒绝了!';
|
||||
return result;
|
||||
}
|
||||
result.text = '绘制图片失败,请稍后试试吧!';
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
OpenAIDrawService = OpenAIDrawService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService,
|
||||
chatLog_service_1.ChatLogService,
|
||||
openaiChat_service_1.OpenAIChatService])
|
||||
], OpenAIDrawService);
|
||||
exports.OpenAIDrawService = OpenAIDrawService;
|
@ -1,104 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var StableDiffusionService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.StableDiffusionService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let StableDiffusionService = StableDiffusionService_1 = class StableDiffusionService {
|
||||
constructor(uploadService, globalConfigService) {
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
this.logger = new common_1.Logger(StableDiffusionService_1.name);
|
||||
}
|
||||
async sdxl(inputs) {
|
||||
const { onSuccess, onFailure, apiKey, model, proxyUrl, modelName, timeout, chatId, prompt, } = inputs;
|
||||
let result = {
|
||||
answer: '',
|
||||
model: model,
|
||||
modelName: modelName,
|
||||
chatId: chatId,
|
||||
fileInfo: '',
|
||||
status: 2,
|
||||
};
|
||||
console.log('开始处理', { model, modelName, prompt });
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: `${proxyUrl}/v1/chat/completions`,
|
||||
timeout: timeout,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
data: {
|
||||
model,
|
||||
messages: [{ role: 'user', content: prompt }],
|
||||
},
|
||||
};
|
||||
try {
|
||||
const response = await (0, axios_1.default)(options);
|
||||
console.log('API响应接收', response.data);
|
||||
if (response.data.choices && response.data.choices.length > 0) {
|
||||
const choice = response.data.choices[0];
|
||||
const content = choice.message.content;
|
||||
console.log('处理内容', content);
|
||||
const regex = /\]\((https?:\/\/[^\)]+)\)/;
|
||||
const match = content.match(regex);
|
||||
if (match && match[1]) {
|
||||
result.fileInfo = match[1];
|
||||
try {
|
||||
const localStorageStatus = await this.globalConfigService.getConfigs(['localStorageStatus']);
|
||||
if (Number(localStorageStatus)) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
result.fileInfo = await this.uploadService.uploadFileFromUrl({
|
||||
url: result.fileInfo,
|
||||
dir: `images/stable-diffusion/${currentDate}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传文件失败: ${error.message}`, 'StableDiffusionService');
|
||||
}
|
||||
console.log('找到链接', match[1]);
|
||||
}
|
||||
else {
|
||||
console.log('没有找到链接');
|
||||
}
|
||||
result.answer = `${prompt} 绘制成功`;
|
||||
if (result.fileInfo) {
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
onFailure('No link found.');
|
||||
}
|
||||
}
|
||||
else {
|
||||
onFailure('No choices returned.');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('服务器错误,请求失败:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
StableDiffusionService = StableDiffusionService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService])
|
||||
], StableDiffusionService);
|
||||
exports.StableDiffusionService = StableDiffusionService;
|
325
AIWebQuickDeploy/dist/modules/ai/suno.service.js
vendored
325
AIWebQuickDeploy/dist/modules/ai/suno.service.js
vendored
@ -1,325 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SunoService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const axios_1 = require("axios");
|
||||
const chatLog_service_1 = require("../chatLog/chatLog.service");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const upload_service_1 = require("../upload/upload.service");
|
||||
let SunoService = class SunoService {
|
||||
constructor(chatLogService, uploadService, globalConfigService) {
|
||||
this.chatLogService = chatLogService;
|
||||
this.uploadService = uploadService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
async suno(inputs) {
|
||||
var _a, _b, _c;
|
||||
const { apiKey, proxyUrl, action, prompt, timeout, assistantLogId, taskData, extraParam, } = inputs;
|
||||
common_1.Logger.debug(`SunoService: ${JSON.stringify(inputs)}`, 'SunoService');
|
||||
let result = {
|
||||
text: '',
|
||||
fileInfo: '',
|
||||
taskId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
};
|
||||
common_1.Logger.log('开始生成音乐', 'SunoService');
|
||||
let response = null;
|
||||
let url = '';
|
||||
let payloadJson = {};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
if (action === 'LYRICS') {
|
||||
url = `${proxyUrl}/task/suno/v1/submit/lyrics`;
|
||||
payloadJson = { prompt: prompt };
|
||||
}
|
||||
if (action === 'MUSIC') {
|
||||
url = `${proxyUrl}/task/suno/v1/submit/music`;
|
||||
try {
|
||||
payloadJson = JSON.parse(taskData);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`解析taskData失败: ${error.message}`, 'SunoService');
|
||||
throw new Error('taskData格式错误');
|
||||
}
|
||||
}
|
||||
common_1.Logger.log(`正在准备发送请求到 ${url},payload: ${JSON.stringify(payloadJson)}, headers: ${JSON.stringify(headers)}`, 'SunoService');
|
||||
try {
|
||||
response = await axios_1.default.post(url, payloadJson, { headers });
|
||||
common_1.Logger.debug(`任务提交结果,状态码: ${response.status}, 状态消息: ${response.statusText}, 数据: ${JSON.stringify(response.data)}`);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`任务提交失败: ${error.message}`, 'SunoService');
|
||||
throw new Error('任务提交失败');
|
||||
}
|
||||
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.data) {
|
||||
result.taskId = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.data;
|
||||
common_1.Logger.log(`任务提交成功, 任务ID: ${(_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.data}`, 'SunoService');
|
||||
}
|
||||
else {
|
||||
throw new Error('未能获取结果数据, 即将重试');
|
||||
}
|
||||
try {
|
||||
await this.pollSunoMusicResult({
|
||||
proxyUrl,
|
||||
apiKey,
|
||||
taskId: response.data.data,
|
||||
timeout,
|
||||
prompt,
|
||||
action,
|
||||
onSuccess: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: '100%',
|
||||
status: 3,
|
||||
taskId: data === null || data === void 0 ? void 0 : data.taskId,
|
||||
taskData: data === null || data === void 0 ? void 0 : data.taskData,
|
||||
});
|
||||
common_1.Logger.log('音乐任务已完成', 'SunoService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'SunoService');
|
||||
}
|
||||
},
|
||||
onAudioSuccess: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || prompt,
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: data.status,
|
||||
taskId: data === null || data === void 0 ? void 0 : data.taskId,
|
||||
taskData: data === null || data === void 0 ? void 0 : data.taskData,
|
||||
});
|
||||
common_1.Logger.log('音频生成成功,等待视频生成...', 'SunoService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'SunoService');
|
||||
}
|
||||
},
|
||||
onGenerating: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
videoUrl: data === null || data === void 0 ? void 0 : data.videoUrl,
|
||||
audioUrl: data === null || data === void 0 ? void 0 : data.audioUrl,
|
||||
fileInfo: data === null || data === void 0 ? void 0 : data.fileInfo,
|
||||
answer: (data === null || data === void 0 ? void 0 : data.answer) || '音乐生成中...',
|
||||
progress: data === null || data === void 0 ? void 0 : data.progress,
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('音乐生成中...', 'SunoService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'SunoService');
|
||||
}
|
||||
},
|
||||
onFailure: async (data) => {
|
||||
try {
|
||||
await this.chatLogService.updateChatLog(assistantLogId, {
|
||||
answer: '音乐生成失败',
|
||||
status: data.status,
|
||||
});
|
||||
common_1.Logger.log('生成失败', 'SunoService');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`更新日志失败: ${error.message}`, 'SunoService');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('查询生成结果时发生错误:', error.message, 'SunoService');
|
||||
throw new Error('查询生成结果时发生错误');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async pollSunoMusicResult(inputs) {
|
||||
const { proxyUrl, apiKey, taskId, timeout, onSuccess, onAudioSuccess, onFailure, onGenerating, action, } = inputs;
|
||||
let result = {
|
||||
videoUrl: '',
|
||||
audioUrl: '',
|
||||
fileInfo: '',
|
||||
drawId: '',
|
||||
taskData: '',
|
||||
status: 2,
|
||||
progress: 0,
|
||||
answer: '',
|
||||
};
|
||||
const headers = { Authorization: `Bearer ${apiKey}` };
|
||||
const url = `${proxyUrl}/task/suno/v1/fetch/${taskId}`;
|
||||
const startTime = Date.now();
|
||||
const POLL_INTERVAL = 5000;
|
||||
let retryCount = 0;
|
||||
try {
|
||||
while (Date.now() - startTime < timeout) {
|
||||
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
||||
try {
|
||||
const res = await axios_1.default.get(url, { headers });
|
||||
const responses = res.data.data;
|
||||
common_1.Logger.debug(`轮询结果: ${JSON.stringify(responses)}`, 'SunoService');
|
||||
if (action === 'LYRICS') {
|
||||
if (responses.status === 'SUCCESS') {
|
||||
result.taskId = responses.data.id;
|
||||
result.taskData = JSON.stringify(responses.data);
|
||||
result.answer = responses.data.text;
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
result.progress = responses === null || responses === void 0 ? void 0 : responses.progress;
|
||||
result.answer = `歌词生成中`;
|
||||
if (result.progress) {
|
||||
onGenerating(result);
|
||||
}
|
||||
}
|
||||
if (action === 'MUSIC') {
|
||||
if (responses.data) {
|
||||
const data = responses.data;
|
||||
result.taskData = JSON.stringify(data);
|
||||
if (Array.isArray(data)) {
|
||||
const validAudioUrls = data
|
||||
.map((item) => item.audio_url)
|
||||
.filter((url) => url);
|
||||
const validVideoUrls = data
|
||||
.map((item) => item.video_url)
|
||||
.filter((url) => url);
|
||||
const validImageUrls = data
|
||||
.map((item) => item.image_url)
|
||||
.filter((url) => url);
|
||||
const titles = data.map((item) => item.title);
|
||||
const firstTitle = titles.length > 0 ? titles[0] : '音乐已生成';
|
||||
if (responses.status === 'SUCCESS') {
|
||||
let audioUrls = [];
|
||||
let videoUrls = [];
|
||||
let imageUrls = [];
|
||||
try {
|
||||
const localStorageStatus = await this.globalConfigService.getConfigs([
|
||||
'localStorageStatus',
|
||||
]);
|
||||
if (Number(localStorageStatus)) {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const currentDate = `${year}${month}/${day}`;
|
||||
for (const url of validAudioUrls) {
|
||||
try {
|
||||
const uploadedUrl = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `audio/suno-music/${currentDate}`,
|
||||
});
|
||||
audioUrls.push(uploadedUrl);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传音频文件失败: ${error.message}`, 'SunoService');
|
||||
audioUrls.push(url);
|
||||
}
|
||||
}
|
||||
for (const url of validVideoUrls) {
|
||||
try {
|
||||
const uploadedUrl = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `video/suno-music/${currentDate}`,
|
||||
});
|
||||
videoUrls.push(uploadedUrl);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传视频文件失败: ${error.message}`, 'SunoService');
|
||||
videoUrls.push(url);
|
||||
}
|
||||
}
|
||||
for (const url of validImageUrls) {
|
||||
try {
|
||||
const uploadedUrl = await this.uploadService.uploadFileFromUrl({
|
||||
url: url,
|
||||
dir: `images/suno-music/${currentDate}`,
|
||||
});
|
||||
imageUrls.push(uploadedUrl);
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`上传图片文件失败: ${error.message}`, 'SunoService');
|
||||
imageUrls.push(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
audioUrls = validAudioUrls;
|
||||
videoUrls = validVideoUrls;
|
||||
imageUrls = validImageUrls;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`获取配置失败: ${error.message}`, 'LumaService');
|
||||
audioUrls = validAudioUrls;
|
||||
videoUrls = validVideoUrls;
|
||||
imageUrls = validImageUrls;
|
||||
}
|
||||
result.audioUrl = audioUrls.join(',');
|
||||
result.videoUrl = videoUrls.join(',');
|
||||
result.fileInfo = imageUrls.join(',');
|
||||
if (validAudioUrls.length === 2) {
|
||||
result.status = 3;
|
||||
result.answer = firstTitle;
|
||||
}
|
||||
else {
|
||||
result.status = 2;
|
||||
result.progress = responses === null || responses === void 0 ? void 0 : responses.progress;
|
||||
result.answer = `当前生成进度 ${responses === null || responses === void 0 ? void 0 : responses.progress}`;
|
||||
}
|
||||
common_1.Logger.debug(`音乐生成成功: ${JSON.stringify(data)}`, 'SunoService');
|
||||
onSuccess(result);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
result.audioUrl = validAudioUrls.join(',');
|
||||
result.videoUrl = validVideoUrls.join(',');
|
||||
result.fileInfo = validImageUrls.join(',');
|
||||
result.status = 2;
|
||||
result.progress = responses === null || responses === void 0 ? void 0 : responses.progress;
|
||||
result.answer = firstTitle;
|
||||
onAudioSuccess(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!result.audioUrl && result.progress && result.status === 2) {
|
||||
onGenerating(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
retryCount++;
|
||||
common_1.Logger.error(`轮询失败,重试次数: ${retryCount}`, 'SunoService');
|
||||
}
|
||||
}
|
||||
common_1.Logger.error('轮询超时,请稍后再试!', 'SunoService');
|
||||
result.status = 4;
|
||||
onFailure(result);
|
||||
throw new Error('查询超时,请稍后再试!');
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error(`轮询过程中发生错误: ${error}`, 'SunoService');
|
||||
result.status = 5;
|
||||
onFailure(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
SunoService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [chatLog_service_1.ChatLogService,
|
||||
upload_service_1.UploadService,
|
||||
globalConfig_service_1.GlobalConfigService])
|
||||
], SunoService);
|
||||
exports.SunoService = SunoService;
|
218
AIWebQuickDeploy/dist/modules/app/app.controller.js
vendored
218
AIWebQuickDeploy/dist/modules/app/app.controller.js
vendored
@ -1,218 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AppController = void 0;
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const app_service_1 = require("./app.service");
|
||||
const collectApp_dto_1 = require("./dto/collectApp.dto");
|
||||
const createApp_dto_1 = require("./dto/createApp.dto");
|
||||
const createCats_dto_1 = require("./dto/createCats.dto");
|
||||
const deleteApp_dto_1 = require("./dto/deleteApp.dto");
|
||||
const deleteCats_dto_1 = require("./dto/deleteCats.dto");
|
||||
const queryApp_dto_1 = require("./dto/queryApp.dto");
|
||||
const queryCats_dto_1 = require("./dto/queryCats.dto");
|
||||
const updateApp_dto_1 = require("./dto/updateApp.dto");
|
||||
const updateCats_dto_1 = require("./dto/updateCats.dto");
|
||||
let AppController = class AppController {
|
||||
constructor(appService) {
|
||||
this.appService = appService;
|
||||
}
|
||||
appCatsList(query) {
|
||||
return this.appService.appCatsList(query);
|
||||
}
|
||||
catsList() {
|
||||
const params = { status: 1, page: 1, size: 1000, name: '' };
|
||||
return this.appService.appCatsList(params);
|
||||
}
|
||||
queryOneCats(query) {
|
||||
return this.appService.queryOneCat(query);
|
||||
}
|
||||
createAppCat(body) {
|
||||
return this.appService.createAppCat(body);
|
||||
}
|
||||
updateAppCats(body) {
|
||||
return this.appService.updateAppCats(body);
|
||||
}
|
||||
delAppCat(body) {
|
||||
return this.appService.delAppCat(body);
|
||||
}
|
||||
appList(req, query) {
|
||||
return this.appService.appList(req, query);
|
||||
}
|
||||
list(req, query) {
|
||||
return this.appService.frontAppList(req, query);
|
||||
}
|
||||
async searchList(body) {
|
||||
return this.appService.searchAppList(body);
|
||||
}
|
||||
createApp(body) {
|
||||
return this.appService.createApp(body);
|
||||
}
|
||||
updateApp(body) {
|
||||
return this.appService.updateApp(body);
|
||||
}
|
||||
delApp(body) {
|
||||
return this.appService.delApp(body);
|
||||
}
|
||||
collect(body, req) {
|
||||
return this.appService.collect(body, req);
|
||||
}
|
||||
mineApps(req) {
|
||||
return this.appService.mineApps(req);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryAppCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '获取App分类列表' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryCats_dto_1.QuerCatsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "appCatsList", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户端获取App分类列表' }),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "catsList", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryOneCat'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户端获取App分类列表' }),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "queryOneCats", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('createAppCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加App分类' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [createCats_dto_1.CreateCatsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "createAppCat", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updateAppCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '修改App分类' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [updateCats_dto_1.UpdateCatsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "updateAppCats", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delAppCats'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除App分类' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [deleteCats_dto_1.DeleteCatsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "delAppCat", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('queryApp'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '获取App列表' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, queryApp_dto_1.QuerAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "appList", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('list'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '客户端获取App' }),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, queryApp_dto_1.QuerAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "list", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('searchList'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '客户端获取App' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AppController.prototype, "searchList", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('createApp'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加App' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [createApp_dto_1.CreateAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "createApp", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updateApp'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '修改App' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [updateApp_dto_1.UpdateAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "updateApp", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('delApp'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除App' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [deleteApp_dto_1.OperateAppDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "delApp", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('collect'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '收藏/取消收藏App' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [collectApp_dto_1.CollectAppDto, Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "collect", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('mineApps'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '我的收藏' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AppController.prototype, "mineApps", null);
|
||||
AppController = __decorate([
|
||||
(0, swagger_1.ApiTags)('App'),
|
||||
(0, common_1.Controller)('app'),
|
||||
__metadata("design:paramtypes", [app_service_1.AppService])
|
||||
], AppController);
|
||||
exports.AppController = AppController;
|
84
AIWebQuickDeploy/dist/modules/app/app.entity.js
vendored
84
AIWebQuickDeploy/dist/modules/app/app.entity.js
vendored
@ -1,84 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AppEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let AppEntity = class AppEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true, comment: 'App应用名称' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App分类Id' }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用描述信息' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "des", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用预设场景信息', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "preset", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用封面图片', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "coverImg", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用排序、数字越大越靠前', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用是否启用中 0:禁用 1:启用', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App示例数据', nullable: true, type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "demoData", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用角色 system user', default: 'system' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "role", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用是否是GPTs', default: '0' }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "isGPTs", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用是否是固定使用模型', default: '0' }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "isFixedModel", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用使用的模型', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "appModel", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'GPTs 的调用ID', default: '' }),
|
||||
__metadata("design:type", String)
|
||||
], AppEntity.prototype, "gizmoID", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App是否共享到应用广场', default: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], AppEntity.prototype, "public", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户Id', nullable: true }),
|
||||
__metadata("design:type", Number)
|
||||
], AppEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否系统预留', default: false, nullable: true }),
|
||||
__metadata("design:type", Boolean)
|
||||
], AppEntity.prototype, "isSystemReserved", void 0);
|
||||
AppEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'app' })
|
||||
], AppEntity);
|
||||
exports.AppEntity = AppEntity;
|
26
AIWebQuickDeploy/dist/modules/app/app.module.js
vendored
26
AIWebQuickDeploy/dist/modules/app/app.module.js
vendored
@ -1,26 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AppModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const app_controller_1 = require("./app.controller");
|
||||
const app_service_1 = require("./app.service");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const appCats_entity_1 = require("./appCats.entity");
|
||||
const app_entity_1 = require("./app.entity");
|
||||
const userApps_entity_1 = require("./userApps.entity");
|
||||
let AppModule = class AppModule {
|
||||
};
|
||||
AppModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([appCats_entity_1.AppCatsEntity, app_entity_1.AppEntity, userApps_entity_1.UserAppsEntity])],
|
||||
controllers: [app_controller_1.AppController],
|
||||
providers: [app_service_1.AppService],
|
||||
})
|
||||
], AppModule);
|
||||
exports.AppModule = AppModule;
|
331
AIWebQuickDeploy/dist/modules/app/app.service.js
vendored
331
AIWebQuickDeploy/dist/modules/app/app.service.js
vendored
@ -1,331 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AppService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const app_entity_1 = require("./app.entity");
|
||||
const appCats_entity_1 = require("./appCats.entity");
|
||||
const userApps_entity_1 = require("./userApps.entity");
|
||||
let AppService = class AppService {
|
||||
constructor(appCatsEntity, appEntity, userAppsEntity) {
|
||||
this.appCatsEntity = appCatsEntity;
|
||||
this.appEntity = appEntity;
|
||||
this.userAppsEntity = userAppsEntity;
|
||||
}
|
||||
async createAppCat(body) {
|
||||
const { name } = body;
|
||||
const c = await this.appCatsEntity.findOne({ where: { name } });
|
||||
if (c) {
|
||||
throw new common_1.HttpException('该分类名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.appCatsEntity.save(body);
|
||||
}
|
||||
async delAppCat(body) {
|
||||
const { id } = body;
|
||||
const c = await this.appCatsEntity.findOne({ where: { id } });
|
||||
if (!c) {
|
||||
throw new common_1.HttpException('该分类不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const count = await this.appEntity.count({ where: { catId: id } });
|
||||
if (count > 0) {
|
||||
throw new common_1.HttpException('该分类下存在App,不可删除!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.appCatsEntity.delete(id);
|
||||
if (res.affected > 0)
|
||||
return '删除成功';
|
||||
throw new common_1.HttpException('删除失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async updateAppCats(body) {
|
||||
const { id, name } = body;
|
||||
const c = await this.appCatsEntity.findOne({
|
||||
where: { name, id: (0, typeorm_2.Not)(id) },
|
||||
});
|
||||
if (c) {
|
||||
throw new common_1.HttpException('该分类名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.appCatsEntity.update({ id }, body);
|
||||
if (res.affected > 0)
|
||||
return '修改成功';
|
||||
throw new common_1.HttpException('修改失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async queryOneCat(params) {
|
||||
const { id } = params;
|
||||
if (!id) {
|
||||
throw new common_1.HttpException('缺失必要参数!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const app = await this.appEntity.findOne({ where: { id } });
|
||||
const { demoData: demo, coverImg, des, name, isFixedModel, isGPTs, appModel, } = app;
|
||||
return {
|
||||
demoData: demo ? demo.split('\n') : [],
|
||||
coverImg,
|
||||
des,
|
||||
name,
|
||||
isGPTs,
|
||||
isFixedModel,
|
||||
appModel,
|
||||
};
|
||||
}
|
||||
async appCatsList(query) {
|
||||
const { page = 1, size = 10, name, status } = query;
|
||||
const where = {};
|
||||
name && (where.name = (0, typeorm_2.Like)(`%${name}%`));
|
||||
[0, 1, '0', '1'].includes(status) && (where.status = status);
|
||||
const [rows, count] = await this.appCatsEntity.findAndCount({
|
||||
where,
|
||||
order: { order: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const catIds = rows.map((item) => item.id);
|
||||
const apps = await this.appEntity.find({ where: { catId: (0, typeorm_2.In)(catIds) } });
|
||||
const appCountMap = {};
|
||||
apps.forEach((item) => {
|
||||
if (appCountMap[item.catId]) {
|
||||
appCountMap[item.catId] += 1;
|
||||
}
|
||||
else {
|
||||
appCountMap[item.catId] = 1;
|
||||
}
|
||||
});
|
||||
rows.forEach((item) => (item.appCount = appCountMap[item.id] || 0));
|
||||
return { rows, count };
|
||||
}
|
||||
async appList(req, query, orderKey = 'id') {
|
||||
var _a;
|
||||
const { page = 1, size = 10, name, status, catId, role } = query;
|
||||
const where = { isSystemReserved: 0 };
|
||||
name && (where.name = (0, typeorm_2.Like)(`%${name}%`));
|
||||
catId && (where.catId = catId);
|
||||
role && (where.role = role);
|
||||
status && (where.status = status);
|
||||
const [rows, count] = await this.appEntity.findAndCount({
|
||||
where,
|
||||
order: { [orderKey]: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const catIds = rows.map((item) => item.catId);
|
||||
const cats = await this.appCatsEntity.find({ where: { id: (0, typeorm_2.In)(catIds) } });
|
||||
rows.forEach((item) => {
|
||||
const cat = cats.find((c) => c.id === item.catId);
|
||||
item.catName = cat ? cat.name : '';
|
||||
});
|
||||
if (((_a = req === null || req === void 0 ? void 0 : req.user) === null || _a === void 0 ? void 0 : _a.role) !== 'super') {
|
||||
rows.forEach((item) => {
|
||||
delete item.preset;
|
||||
});
|
||||
}
|
||||
return { rows, count };
|
||||
}
|
||||
async frontAppList(req, query, orderKey = 'id') {
|
||||
var _a;
|
||||
const { page = 1, size = 1000, name, catId, role } = query;
|
||||
const where = [
|
||||
{
|
||||
status: (0, typeorm_2.In)([1, 4]),
|
||||
userId: (0, typeorm_2.IsNull)(),
|
||||
public: false,
|
||||
isSystemReserved: 0,
|
||||
},
|
||||
{ userId: (0, typeorm_2.MoreThan)(0), public: true },
|
||||
];
|
||||
const [rows, count] = await this.appEntity.findAndCount({
|
||||
where,
|
||||
order: { order: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const catIds = rows.map((item) => item.catId);
|
||||
const cats = await this.appCatsEntity.find({ where: { id: (0, typeorm_2.In)(catIds) } });
|
||||
rows.forEach((item) => {
|
||||
const cat = cats.find((c) => c.id === item.catId);
|
||||
item.catName = cat ? cat.name : '';
|
||||
});
|
||||
if (((_a = req === null || req === void 0 ? void 0 : req.user) === null || _a === void 0 ? void 0 : _a.role) !== 'super') {
|
||||
rows.forEach((item) => {
|
||||
delete item.preset;
|
||||
});
|
||||
}
|
||||
return { rows, count };
|
||||
}
|
||||
async searchAppList(body) {
|
||||
console.log('搜索App列表', body);
|
||||
const { page = 1, size = 1000, keyword } = body;
|
||||
console.log(`搜索关键词:${keyword}`);
|
||||
let baseWhere = [
|
||||
{
|
||||
status: (0, typeorm_2.In)([1, 4]),
|
||||
userId: (0, typeorm_2.IsNull)(),
|
||||
public: false,
|
||||
isSystemReserved: 0,
|
||||
},
|
||||
{ userId: (0, typeorm_2.MoreThan)(0), public: true },
|
||||
];
|
||||
console.log('初始查询条件:', JSON.stringify(baseWhere));
|
||||
if (keyword) {
|
||||
baseWhere = baseWhere.map((condition) => (Object.assign(Object.assign({}, condition), { name: (0, typeorm_2.Like)(`%${keyword}%`) })));
|
||||
console.log('更新后的查询条件:', JSON.stringify(baseWhere));
|
||||
}
|
||||
try {
|
||||
const [rows, count] = await this.appEntity.findAndCount({
|
||||
where: baseWhere,
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
console.log(`查询返回 ${count} 条结果,显示第 ${page} 页的结果。`);
|
||||
rows.forEach((item) => {
|
||||
delete item.preset;
|
||||
});
|
||||
console.log('完成查询,准备返回结果');
|
||||
return { rows, count };
|
||||
}
|
||||
catch (error) {
|
||||
console.error('查询数据库时出错:', error);
|
||||
throw new Error('Database query failed');
|
||||
}
|
||||
}
|
||||
async createApp(body) {
|
||||
const { name, catId } = body;
|
||||
body.role = 'system';
|
||||
const a = await this.appEntity.findOne({ where: { name } });
|
||||
if (a) {
|
||||
throw new common_1.HttpException('该应用名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const c = await this.appCatsEntity.findOne({ where: { id: catId } });
|
||||
if (!c) {
|
||||
throw new common_1.HttpException('该分类不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return await this.appEntity.save(body);
|
||||
}
|
||||
async updateApp(body) {
|
||||
const { id, name, catId, status } = body;
|
||||
const a = await this.appEntity.findOne({ where: { name, id: (0, typeorm_2.Not)(id) } });
|
||||
if (a) {
|
||||
throw new common_1.HttpException('该应用名称已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const c = await this.appCatsEntity.findOne({ where: { id: catId } });
|
||||
if (!c) {
|
||||
throw new common_1.HttpException('该分类不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const curApp = await this.appEntity.findOne({ where: { id } });
|
||||
if (curApp.status !== body.status) {
|
||||
await this.userAppsEntity.update({ appId: id }, { status });
|
||||
}
|
||||
const res = await this.appEntity.update({ id }, body);
|
||||
if (res.affected > 0)
|
||||
return '修改App信息成功';
|
||||
throw new common_1.HttpException('修改App信息失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async delApp(body) {
|
||||
const { id } = body;
|
||||
const a = await this.appEntity.findOne({ where: { id } });
|
||||
if (!a) {
|
||||
throw new common_1.HttpException('该应用不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const useApp = await this.userAppsEntity.count({ where: { appId: id } });
|
||||
const res = await this.appEntity.delete(id);
|
||||
if (res.affected > 0)
|
||||
return '删除App成功';
|
||||
throw new common_1.HttpException('删除App失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async auditPass(body) {
|
||||
const { id } = body;
|
||||
const a = await this.appEntity.findOne({ where: { id, status: 3 } });
|
||||
if (!a) {
|
||||
throw new common_1.HttpException('该应用不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.appEntity.update({ id }, { status: 4 });
|
||||
await this.userAppsEntity.update({ appId: id }, { status: 4 });
|
||||
return '应用审核通过';
|
||||
}
|
||||
async auditFail(body) {
|
||||
const { id } = body;
|
||||
const a = await this.appEntity.findOne({ where: { id, status: 3 } });
|
||||
if (!a) {
|
||||
throw new common_1.HttpException('该应用不存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.appEntity.update({ id }, { status: 5 });
|
||||
await this.userAppsEntity.update({ appId: id }, { status: 5 });
|
||||
return '应用审核拒绝完成';
|
||||
}
|
||||
async collect(body, req) {
|
||||
const { appId } = body;
|
||||
const { id: userId } = req.user;
|
||||
const historyApp = await this.userAppsEntity.findOne({
|
||||
where: { appId, userId },
|
||||
});
|
||||
if (historyApp) {
|
||||
const r = await this.userAppsEntity.delete({ appId, userId });
|
||||
if (r.affected > 0) {
|
||||
return '取消收藏成功!';
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('取消收藏失败!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
const app = await this.appEntity.findOne({ where: { id: appId } });
|
||||
const { id, role: appRole, catId } = app;
|
||||
const collectInfo = {
|
||||
userId,
|
||||
appId: id,
|
||||
catId,
|
||||
appRole,
|
||||
public: true,
|
||||
status: 1,
|
||||
};
|
||||
await this.userAppsEntity.save(collectInfo);
|
||||
return '已将应用加入到我的收藏!';
|
||||
}
|
||||
async mineApps(req, query = { page: 1, size: 30 }) {
|
||||
const { id } = req.user;
|
||||
const { page = 1, size = 30 } = query;
|
||||
let rows, count;
|
||||
try {
|
||||
[rows, count] = await this.userAppsEntity.findAndCount({
|
||||
where: { userId: id, status: (0, typeorm_2.In)([1, 3, 4, 5]) },
|
||||
order: { id: 'DESC' },
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
});
|
||||
const appIds = rows.map((item) => item.appId);
|
||||
const appsInfo = await this.appEntity.find({ where: { id: (0, typeorm_2.In)(appIds) } });
|
||||
rows.forEach((item) => {
|
||||
const app = appsInfo.find((c) => c.id === item.appId);
|
||||
item.appName = app ? app.name : '未知';
|
||||
item.appRole = app ? app.role : '未知';
|
||||
item.appDes = app ? app.des : '未知';
|
||||
item.coverImg = app ? app.coverImg : '未知';
|
||||
item.demoData = app ? app.demoData : '未知';
|
||||
item.preset = app.userId === id ? app.preset : '******';
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`处理用户ID: ${id} 的mineApps请求时发生错误`, error);
|
||||
throw error;
|
||||
}
|
||||
return { rows, count };
|
||||
}
|
||||
};
|
||||
AppService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(appCats_entity_1.AppCatsEntity)),
|
||||
__param(1, (0, typeorm_1.InjectRepository)(app_entity_1.AppEntity)),
|
||||
__param(2, (0, typeorm_1.InjectRepository)(userApps_entity_1.UserAppsEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
typeorm_2.Repository,
|
||||
typeorm_2.Repository])
|
||||
], AppService);
|
||||
exports.AppService = AppService;
|
@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AppCatsEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let AppCatsEntity = class AppCatsEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ unique: true, comment: 'App分类名称' }),
|
||||
__metadata("design:type", String)
|
||||
], AppCatsEntity.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App分类排序、数字越大越靠前', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], AppCatsEntity.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App分类是否启用中 0:禁用 1:启用', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], AppCatsEntity.prototype, "status", void 0);
|
||||
AppCatsEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'app_cats' })
|
||||
], AppCatsEntity);
|
||||
exports.AppCatsEntity = AppCatsEntity;
|
@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CollectAppDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class CollectAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要收藏的appId', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: 'ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], CollectAppDto.prototype, "appId", void 0);
|
||||
exports.CollectAppDto = CollectAppDto;
|
@ -1,75 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CreateAppDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class CreateAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '前端助手', description: 'app名称', required: true }),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app名称是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'app分类Id', required: true }),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app分类Id必传参数' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreateAppDto.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '适用于编程编码、期望成为您的编程助手',
|
||||
description: 'app名称详情描述',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app名称描述是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "des", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你现在是一个翻译官。接下来我说的所有话帮我翻译成中文', description: '预设的prompt', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "preset", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'GPTs 的调用ID', description: 'GPTs 使用的 ID', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "gizmoID", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ description: '是否GPTs', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreateAppDto.prototype, "isGPTs", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://xxxx.png', description: '套餐封面图片', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "coverImg", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 100, description: '套餐排序、数字越大越靠前', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreateAppDto.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '套餐状态 0:禁用 1:启用', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '套餐状态必须是Number' }),
|
||||
(0, class_validator_1.IsIn)([0, 1, 3, 4, 5], { message: '套餐状态错误' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreateAppDto.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '这是一句示例数据', description: 'app示例数据', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "demoData", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'system', description: '创建的角色', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], CreateAppDto.prototype, "role", void 0);
|
||||
exports.CreateAppDto = CreateAppDto;
|
@ -1,45 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CreateCatsDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class CreateCatsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '编程助手',
|
||||
description: 'app分类名称',
|
||||
required: true,
|
||||
}),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app分类名称是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CreateCatsDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: 100,
|
||||
description: '分类排序、数字越大越靠前',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreateCatsDto.prototype, "order", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: 1,
|
||||
description: '分类状态 0:禁用 1:启用',
|
||||
required: true,
|
||||
}),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '状态必须是Number' }),
|
||||
(0, class_validator_1.IsIn)([0, 1, 3, 4, 5], { message: '套餐状态错误' }),
|
||||
__metadata("design:type", Number)
|
||||
], CreateCatsDto.prototype, "status", void 0);
|
||||
exports.CreateCatsDto = CreateCatsDto;
|
@ -1,55 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CustomAppDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class CustomAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '前端助手', description: 'app名称', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'app分类Id', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], CustomAppDto.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '适用于编程编码、期望成为您的编程助手',
|
||||
description: 'app名称详情描述',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsDefined)({ message: 'app名称描述是必传参数' }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "des", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你现在是一个翻译官。接下来我说的所有话帮我翻译成中文', description: '预设的prompt', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "preset", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'https://xxxx.png', description: '套餐封面图片', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "coverImg", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '这是一句示例数据', description: 'app示例数据', required: false }),
|
||||
__metadata("design:type", String)
|
||||
], CustomAppDto.prototype, "demoData", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: false, description: '是否共享到所有人', required: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], CustomAppDto.prototype, "public", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '应用ID', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], CustomAppDto.prototype, "appId", void 0);
|
||||
exports.CustomAppDto = CustomAppDto;
|
@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OperateAppDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class OperateAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要删除的appId', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: 'ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], OperateAppDto.prototype, "id", void 0);
|
||||
exports.OperateAppDto = OperateAppDto;
|
@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DeleteCatsDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class DeleteCatsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要删除app分类Id', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: 'ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], DeleteCatsDto.prototype, "id", void 0);
|
||||
exports.DeleteCatsDto = DeleteCatsDto;
|
@ -1,52 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.QuerAppDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class QuerAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAppDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAppDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'name', description: 'app名称', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAppDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: 'app状态 0:禁用 1:启用 3:审核加入广场中 4:已拒绝加入广场', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAppDto.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 2, description: 'app分类Id', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerAppDto.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'role', description: 'app角色', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAppDto.prototype, "role", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '关键词', description: '搜索关键词', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerAppDto.prototype, "keyword", void 0);
|
||||
exports.QuerAppDto = QuerAppDto;
|
@ -1,37 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.QuerCatsDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QuerCatsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerCatsDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerCatsDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'name', description: '分类名称', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QuerCatsDto.prototype, "name", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '分类状态 0:禁用 1:启用', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QuerCatsDto.prototype, "status", void 0);
|
||||
exports.QuerCatsDto = QuerCatsDto;
|
@ -1,23 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdateAppDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const createApp_dto_1 = require("./createApp.dto");
|
||||
class UpdateAppDto extends createApp_dto_1.CreateAppDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要修改的分类Id', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '分类ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateAppDto.prototype, "id", void 0);
|
||||
exports.UpdateAppDto = UpdateAppDto;
|
@ -1,23 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdateCatsDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const createCats_dto_1 = require("./createCats.dto");
|
||||
class UpdateCatsDto extends createCats_dto_1.CreateCatsDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '要修改的分类Id', required: true }),
|
||||
(0, class_validator_1.IsNumber)({}, { message: '分类ID必须是Number' }),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateCatsDto.prototype, "id", void 0);
|
||||
exports.UpdateCatsDto = UpdateCatsDto;
|
@ -1,48 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserAppsEntity = void 0;
|
||||
const typeorm_1 = require("typeorm");
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
let UserAppsEntity = class UserAppsEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '用户ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "userId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '应用ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "appId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '应用分类ID' }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "catId", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'app类型 system/user', default: 'user' }),
|
||||
__metadata("design:type", String)
|
||||
], UserAppsEntity.prototype, "appType", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '是否公开到公告菜单', default: false }),
|
||||
__metadata("design:type", Boolean)
|
||||
], UserAppsEntity.prototype, "public", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'app状态 1正常 2审核 3违规', default: 1 }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "status", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: 'App应用排序、数字越大越靠前', default: 100 }),
|
||||
__metadata("design:type", Number)
|
||||
], UserAppsEntity.prototype, "order", void 0);
|
||||
UserAppsEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'user_apps' })
|
||||
], UserAppsEntity);
|
||||
exports.UserAppsEntity = UserAppsEntity;
|
@ -1,161 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthController = void 0;
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const auth_service_1 = require("./auth.service");
|
||||
const authLogin_dto_1 = require("./dto/authLogin.dto");
|
||||
const authRegister_dto_1 = require("./dto/authRegister.dto");
|
||||
const updatePassByOther_dto_1 = require("./dto/updatePassByOther.dto");
|
||||
const updatePassword_dto_1 = require("./dto/updatePassword.dto");
|
||||
let AuthController = class AuthController {
|
||||
constructor(authService) {
|
||||
this.authService = authService;
|
||||
}
|
||||
async register(body, req) {
|
||||
return await this.authService.register(body, req);
|
||||
}
|
||||
async login(body, req) {
|
||||
return this.authService.login(body, req);
|
||||
}
|
||||
async loginWithCaptcha(body, req) {
|
||||
return this.authService.loginWithCaptcha(body, req);
|
||||
}
|
||||
async updatePassword(req, body) {
|
||||
return this.authService.updatePassword(req, body);
|
||||
}
|
||||
async updatePassByOther(req, body) {
|
||||
return this.authService.updatePassByOther(req, body);
|
||||
}
|
||||
async getInfo(req) {
|
||||
return this.authService.getInfo(req);
|
||||
}
|
||||
async sendCode(parmas) {
|
||||
return this.authService.sendCode(parmas);
|
||||
}
|
||||
async sendPhoneCode(parmas) {
|
||||
return this.authService.sendPhoneCode(parmas);
|
||||
}
|
||||
async verifyIdentity(req, body) {
|
||||
return this.authService.verifyIdentity(req, body);
|
||||
}
|
||||
async verifyPhoneIdentity(req, body) {
|
||||
return this.authService.verifyPhoneIdentity(req, body);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Post)('register'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户注册' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [authRegister_dto_1.UserRegisterDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "register", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('login'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户登录' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [authLogin_dto_1.UserLoginDto, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "login", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('loginWithCaptcha'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户使用验证码登录' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__param(1, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "loginWithCaptcha", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updatePassword'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户更改密码' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, updatePassword_dto_1.UpdatePasswordDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "updatePassword", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('updatePassByOther'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '用户更改密码' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, updatePassByOther_dto_1.UpdatePassByOtherDto]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "updatePassByOther", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('getInfo'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '获取用户个人信息' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "getInfo", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('sendCode'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '发送验证码' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "sendCode", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('sendPhoneCode'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '发送手机验证码' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "sendPhoneCode", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('verifyIdentity'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '验证身份' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "verifyIdentity", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('verifyPhoneIdentity'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '验证手机号' }),
|
||||
(0, common_1.UseGuards)(jwtAuth_guard_1.JwtAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "verifyPhoneIdentity", null);
|
||||
AuthController = __decorate([
|
||||
(0, swagger_1.ApiTags)('auth'),
|
||||
(0, common_1.Controller)('auth'),
|
||||
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
||||
], AuthController);
|
||||
exports.AuthController = AuthController;
|
@ -1,76 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthModule = void 0;
|
||||
const jwt_strategy_1 = require("../../common/auth/jwt.strategy");
|
||||
const jwtAuth_guard_1 = require("../../common/auth/jwtAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const jwt_1 = require("@nestjs/jwt");
|
||||
const passport_1 = require("@nestjs/passport");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const chatGroup_entity_1 = require("../chatGroup/chatGroup.entity");
|
||||
const chatLog_entity_1 = require("../chatLog/chatLog.entity");
|
||||
const cramiPackage_entity_1 = require("../crami/cramiPackage.entity");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const mailer_service_1 = require("../mailer/mailer.service");
|
||||
const redisCache_module_1 = require("../redisCache/redisCache.module");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const user_entity_1 = require("../user/user.entity");
|
||||
const user_module_1 = require("../user/user.module");
|
||||
const accountLog_entity_1 = require("../userBalance/accountLog.entity");
|
||||
const balance_entity_1 = require("../userBalance/balance.entity");
|
||||
const fingerprint_entity_1 = require("../userBalance/fingerprint.entity");
|
||||
const userBalance_entity_1 = require("../userBalance/userBalance.entity");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const verification_service_1 = require("./../verification/verification.service");
|
||||
const verifycation_entity_1 = require("./../verification/verifycation.entity");
|
||||
const auth_controller_1 = require("./auth.controller");
|
||||
const auth_service_1 = require("./auth.service");
|
||||
let AuthModule = class AuthModule {
|
||||
};
|
||||
AuthModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
user_module_1.UserModule,
|
||||
redisCache_module_1.RedisCacheModule,
|
||||
passport_1.PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
jwt_1.JwtModule.registerAsync({
|
||||
inject: [redisCache_service_1.RedisCacheService],
|
||||
useFactory: async (redisService) => ({
|
||||
secret: await redisService.getJwtSecret(),
|
||||
signOptions: { expiresIn: '7d' },
|
||||
}),
|
||||
}),
|
||||
typeorm_1.TypeOrmModule.forFeature([
|
||||
verifycation_entity_1.VerifycationEntity,
|
||||
balance_entity_1.BalanceEntity,
|
||||
accountLog_entity_1.AccountLogEntity,
|
||||
config_entity_1.ConfigEntity,
|
||||
cramiPackage_entity_1.CramiPackageEntity,
|
||||
userBalance_entity_1.UserBalanceEntity,
|
||||
user_entity_1.UserEntity,
|
||||
fingerprint_entity_1.FingerprintLogEntity,
|
||||
chatLog_entity_1.ChatLogEntity,
|
||||
chatGroup_entity_1.ChatGroupEntity,
|
||||
]),
|
||||
],
|
||||
controllers: [auth_controller_1.AuthController],
|
||||
providers: [
|
||||
auth_service_1.AuthService,
|
||||
jwt_strategy_1.JwtStrategy,
|
||||
jwtAuth_guard_1.JwtAuthGuard,
|
||||
mailer_service_1.MailerService,
|
||||
verification_service_1.VerificationService,
|
||||
userBalance_service_1.UserBalanceService,
|
||||
redisCache_service_1.RedisCacheService,
|
||||
],
|
||||
exports: [auth_service_1.AuthService],
|
||||
})
|
||||
], AuthModule);
|
||||
exports.AuthModule = AuthModule;
|
460
AIWebQuickDeploy/dist/modules/auth/auth.service.js
vendored
460
AIWebQuickDeploy/dist/modules/auth/auth.service.js
vendored
@ -1,460 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthService = void 0;
|
||||
const user_constant_1 = require("../../common/constants/user.constant");
|
||||
const utils_1 = require("../../common/utils");
|
||||
const globalConfig_service_1 = require("../globalConfig/globalConfig.service");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const jwt_1 = require("@nestjs/jwt");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const bcrypt = require("bcryptjs");
|
||||
const os = require("os");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const config_entity_1 = require("../globalConfig/config.entity");
|
||||
const mailer_service_1 = require("../mailer/mailer.service");
|
||||
const redisCache_service_1 = require("../redisCache/redisCache.service");
|
||||
const user_service_1 = require("../user/user.service");
|
||||
const userBalance_service_1 = require("../userBalance/userBalance.service");
|
||||
const verification_service_1 = require("./../verification/verification.service");
|
||||
let AuthService = class AuthService {
|
||||
constructor(configEntity, userService, jwtService, mailerService, verificationService, userBalanceService, redisCacheService, globalConfigService) {
|
||||
this.configEntity = configEntity;
|
||||
this.userService = userService;
|
||||
this.jwtService = jwtService;
|
||||
this.mailerService = mailerService;
|
||||
this.verificationService = verificationService;
|
||||
this.userBalanceService = userBalanceService;
|
||||
this.redisCacheService = redisCacheService;
|
||||
this.globalConfigService = globalConfigService;
|
||||
}
|
||||
async onModuleInit() {
|
||||
this.getIp();
|
||||
}
|
||||
async register(body, req) {
|
||||
const { password, contact, code } = body;
|
||||
let email = '', phone = '';
|
||||
const isEmail = /\S+@\S+\.\S+/.test(contact);
|
||||
const isPhone = /^\d{10,}$/.test(contact);
|
||||
common_1.Logger.debug(`Contact: ${contact}, isEmail: ${isEmail}, isPhone: ${isPhone}`);
|
||||
let username = (0, utils_1.createRandomUid)();
|
||||
while (true) {
|
||||
const usernameTaken = await this.userService.verifyUserRegister({
|
||||
username,
|
||||
});
|
||||
common_1.Logger.debug(`Checking if username ${username} is taken: ${usernameTaken}`);
|
||||
if (usernameTaken) {
|
||||
break;
|
||||
}
|
||||
username = (0, utils_1.createRandomUid)();
|
||||
}
|
||||
if (isEmail) {
|
||||
email = contact;
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
username,
|
||||
email,
|
||||
});
|
||||
common_1.Logger.debug(`Email ${email} is available: ${isAvailable}`);
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前邮箱已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
else if (isPhone) {
|
||||
phone = contact;
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
username,
|
||||
phone,
|
||||
});
|
||||
common_1.Logger.debug(`Phone ${phone} is available: ${isAvailable}`);
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前手机号已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('请提供有效的邮箱地址或手机号码。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const noVerifyRegister = await this.globalConfigService.getConfigs([
|
||||
'noVerifyRegister',
|
||||
]);
|
||||
common_1.Logger.debug(`noVerifyRegister: ${noVerifyRegister}`);
|
||||
if (noVerifyRegister !== '1') {
|
||||
const nameSpace = await this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${contact}`;
|
||||
const redisCode = await this.redisCacheService.get({ key });
|
||||
common_1.Logger.debug(`Retrieved redisCode for ${contact}: ${redisCode}`);
|
||||
if (code === '') {
|
||||
throw new common_1.HttpException('请输入验证码', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!redisCode) {
|
||||
common_1.Logger.log(`验证码过期: ${contact}`, 'authService');
|
||||
throw new common_1.HttpException('验证码已过期,请重新发送!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (code !== redisCode) {
|
||||
common_1.Logger.log(`验证码错误: ${contact} 输入的验证码: ${code}, 期望的验证码: ${redisCode}`, 'authService');
|
||||
throw new common_1.HttpException('验证码填写错误,请重新输入!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
let newUser;
|
||||
if (isEmail) {
|
||||
newUser = {
|
||||
username,
|
||||
password,
|
||||
email: contact,
|
||||
status: user_constant_1.UserStatusEnum.ACTIVE,
|
||||
};
|
||||
}
|
||||
else {
|
||||
const email = `${(0, utils_1.createRandomUid)()}@aiweb.com`;
|
||||
newUser = {
|
||||
username,
|
||||
password,
|
||||
email,
|
||||
phone: contact,
|
||||
status: user_constant_1.UserStatusEnum.ACTIVE,
|
||||
};
|
||||
}
|
||||
common_1.Logger.debug('获取默认用户头像...');
|
||||
const userDefautlAvatar = await this.globalConfigService.getConfigs([
|
||||
'userDefautlAvatar',
|
||||
]);
|
||||
common_1.Logger.debug(`使用默认用户头像: ${userDefautlAvatar}`);
|
||||
newUser.avatar = userDefautlAvatar;
|
||||
common_1.Logger.debug('加密用户密码...');
|
||||
const hashedPassword = bcrypt.hashSync(password, 10);
|
||||
newUser.password = hashedPassword;
|
||||
common_1.Logger.debug('保存新用户到数据库...');
|
||||
const u = await this.userService.createUser(newUser);
|
||||
common_1.Logger.debug(`用户创建成功,用户ID: ${u.id}`);
|
||||
await this.userBalanceService.addBalanceToNewUser(u.id);
|
||||
common_1.Logger.debug('完成新用户余额处理');
|
||||
return { success: true, message: '注册成功' };
|
||||
}
|
||||
async login(user, req) {
|
||||
console.log(`开始用户登录流程,用户名: ${user.username}`);
|
||||
const u = await this.userService.verifyUserCredentials(user);
|
||||
if (!u) {
|
||||
console.error(`登录失败: 用户凭证无效 - 用户名: ${user.username}`);
|
||||
throw new common_1.HttpException('登录失败,用户凭证无效。', common_1.HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
const { username, id, email, role, openId, client, phone } = u;
|
||||
console.log(`用户凭证验证成功,用户ID: ${id}, 用户名: ${username}`);
|
||||
const ip = (0, utils_1.getClientIp)(req);
|
||||
await this.userService.savaLoginIp(id, ip);
|
||||
console.log(`保存登录IP: ${ip} - 用户ID: ${id}`);
|
||||
const token = await this.jwtService.sign({
|
||||
username,
|
||||
id,
|
||||
email,
|
||||
role,
|
||||
openId,
|
||||
client,
|
||||
phone,
|
||||
});
|
||||
console.log(`JWT令牌生成成功 - 用户ID: ${id}`);
|
||||
await this.redisCacheService.saveToken(id, token);
|
||||
console.log(`令牌已保存到Redis - 用户ID: ${id}`);
|
||||
return token;
|
||||
}
|
||||
async loginWithCaptcha(body, req) {
|
||||
const { contact, code } = body;
|
||||
let email = '', phone = '';
|
||||
const isEmail = /\S+@\S+\.\S+/.test(contact);
|
||||
const isPhone = /^\d{10,}$/.test(contact);
|
||||
if (isEmail) {
|
||||
email = contact;
|
||||
}
|
||||
else if (isPhone) {
|
||||
phone = contact;
|
||||
}
|
||||
else {
|
||||
throw new common_1.HttpException('请提供有效的邮箱地址或手机号码。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
email,
|
||||
phone,
|
||||
});
|
||||
const nameSpace = await this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${contact}`;
|
||||
const redisCode = await this.redisCacheService.get({ key });
|
||||
if (!redisCode) {
|
||||
common_1.Logger.log(`验证码过期: ${contact}`, 'authService');
|
||||
throw new common_1.HttpException('验证码已过期,请重新发送!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (code !== redisCode) {
|
||||
common_1.Logger.log(`验证码错误: ${contact} 输入的验证码: ${code}, 期望的验证码: ${redisCode}`, 'authService');
|
||||
throw new common_1.HttpException('验证码填写错误,请重新输入!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
let u;
|
||||
if (isAvailable) {
|
||||
u = await this.userService.createUserFromContact({ email, phone });
|
||||
}
|
||||
else {
|
||||
u = await this.userService.getUserByContact({ email, phone });
|
||||
}
|
||||
if (!u) {
|
||||
throw new common_1.HttpException('登录失败,用户凭证无效。', common_1.HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
const { username, id, role, openId, client } = u;
|
||||
console.log(`用户凭证验证成功,用户ID: ${id}, 用户名: ${username}`);
|
||||
const ip = (0, utils_1.getClientIp)(req);
|
||||
await this.userService.savaLoginIp(id, ip);
|
||||
console.log(`保存登录IP: ${ip} - 用户ID: ${id}`);
|
||||
const token = await this.jwtService.sign({
|
||||
username,
|
||||
id,
|
||||
email,
|
||||
role,
|
||||
openId,
|
||||
client,
|
||||
phone,
|
||||
});
|
||||
console.log(`JWT令牌生成成功 - 用户ID: ${id}`);
|
||||
await this.redisCacheService.saveToken(id, token);
|
||||
console.log(`令牌已保存到Redis - 用户ID: ${id}`);
|
||||
return token;
|
||||
}
|
||||
async loginByOpenId(user, req) {
|
||||
const { status } = user;
|
||||
if (status !== user_constant_1.UserStatusEnum.ACTIVE) {
|
||||
throw new common_1.HttpException(user_constant_1.UserStatusErrMsg[status], common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const { username, id, email, role, openId, client } = user;
|
||||
const ip = (0, utils_1.getClientIp)(req);
|
||||
await this.userService.savaLoginIp(id, ip);
|
||||
const token = await this.jwtService.sign({
|
||||
username,
|
||||
id,
|
||||
email,
|
||||
role,
|
||||
openId,
|
||||
client,
|
||||
});
|
||||
await this.redisCacheService.saveToken(id, token);
|
||||
return token;
|
||||
}
|
||||
async getInfo(req) {
|
||||
const { id } = req.user;
|
||||
return await this.userService.getUserInfo(id);
|
||||
}
|
||||
async updatePassword(req, body) {
|
||||
const { id, client, role } = req.user;
|
||||
if (client && Number(client) > 0) {
|
||||
throw new common_1.HttpException('无权此操作、请联系管理员!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (role === 'admin') {
|
||||
throw new common_1.HttpException('非法操作、请联系管理员!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
this.userService.updateUserPassword(id, body.password);
|
||||
return '密码修改成功';
|
||||
}
|
||||
async updatePassByOther(req, body) {
|
||||
const { id, client } = req.user;
|
||||
if (!client) {
|
||||
throw new common_1.HttpException('无权此操作!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
this.userService.updateUserPassword(id, body.password);
|
||||
return '密码修改成功';
|
||||
}
|
||||
getIp() {
|
||||
let ipAddress;
|
||||
const interfaces = os.networkInterfaces();
|
||||
Object.keys(interfaces).forEach((interfaceName) => {
|
||||
const interfaceInfo = interfaces[interfaceName];
|
||||
for (let i = 0; i < interfaceInfo.length; i++) {
|
||||
const alias = interfaceInfo[i];
|
||||
if (alias.family === 'IPv4' &&
|
||||
alias.address !== '127.0.0.1' &&
|
||||
!alias.internal) {
|
||||
ipAddress = alias.address;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
async sendCode(body) {
|
||||
const { contact, isLogin } = body;
|
||||
let email = '', phone = '';
|
||||
const code = (0, utils_1.createRandomCode)();
|
||||
const isEmail = /\S+@\S+\.\S+/.test(contact);
|
||||
const isPhone = /^\d{10,}$/.test(contact);
|
||||
if (!isEmail && !isPhone) {
|
||||
throw new common_1.HttpException('请提供有效的邮箱地址或手机号码。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!isLogin) {
|
||||
if (isEmail) {
|
||||
email = contact;
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
email,
|
||||
});
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前邮箱已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
else if (isPhone) {
|
||||
phone = contact;
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
phone,
|
||||
});
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前手机号已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
const nameSpace = await this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${contact}`;
|
||||
const ttl = await this.redisCacheService.ttl(key);
|
||||
if (ttl && ttl > 0 && isPhone) {
|
||||
throw new common_1.HttpException(`${ttl}秒内不得重复发送验证码!`, common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (isEmail) {
|
||||
const existingCode = await this.redisCacheService.get({ key });
|
||||
if (existingCode) {
|
||||
await this.mailerService.sendMail({
|
||||
to: email,
|
||||
context: {
|
||||
code: existingCode,
|
||||
},
|
||||
});
|
||||
return `验证码发送成功、请填写验证码完成注册!`;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
await this.mailerService.sendMail({
|
||||
to: email,
|
||||
context: {
|
||||
code: code,
|
||||
},
|
||||
});
|
||||
console.log('邮件发送成功');
|
||||
}
|
||||
catch (error) {
|
||||
console.error('邮件发送失败', error);
|
||||
}
|
||||
await this.redisCacheService.set({ key, val: code }, 10 * 60);
|
||||
return `验证码发送成功、请填写验证码完成注册!`;
|
||||
}
|
||||
}
|
||||
else if (isPhone) {
|
||||
const messageInfo = { phone, code };
|
||||
await this.verificationService.sendPhoneCode(messageInfo);
|
||||
await this.redisCacheService.set({ key, val: code }, 10 * 60);
|
||||
return `验证码发送成功、请填写验证码完成注册!`;
|
||||
}
|
||||
}
|
||||
async sendPhoneCode(body) {
|
||||
const { phone, isLogin } = body;
|
||||
const code = (0, utils_1.createRandomCode)();
|
||||
const isPhone = /^\d{10,}$/.test(phone);
|
||||
if (!isPhone) {
|
||||
throw new common_1.HttpException('请提供有效的邮箱地址或手机号码。', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (isLogin) {
|
||||
if (isPhone) {
|
||||
const isAvailable = await this.userService.verifyUserRegister({
|
||||
phone,
|
||||
});
|
||||
if (!isAvailable) {
|
||||
throw new common_1.HttpException('当前手机号已注册,请勿重复注册!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
const nameSpace = await this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${phone}`;
|
||||
const ttl = await this.redisCacheService.ttl(key);
|
||||
if (ttl && ttl > 0 && isPhone) {
|
||||
throw new common_1.HttpException(`${ttl}秒内不得重复发送验证码!`, common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const messageInfo = { phone, code };
|
||||
await this.redisCacheService.set({ key, val: code }, 10 * 60);
|
||||
await this.verificationService.sendPhoneCode(messageInfo);
|
||||
return `验证码发送成功、请填写验证码完成认证!`;
|
||||
}
|
||||
createTokenFromFingerprint(fingerprint) {
|
||||
const token = this.jwtService.sign({
|
||||
username: `游客${fingerprint}`,
|
||||
id: fingerprint,
|
||||
email: `${fingerprint}@visitor.com`,
|
||||
role: 'visitor',
|
||||
openId: null,
|
||||
client: null,
|
||||
});
|
||||
return token;
|
||||
}
|
||||
async verifyIdentity(req, body) {
|
||||
common_1.Logger.debug('开始实名认证流程');
|
||||
const { name, idCard } = body;
|
||||
const { id } = req.user;
|
||||
try {
|
||||
const result = await this.verificationService.verifyIdentity(body);
|
||||
common_1.Logger.debug(`实名认证结果: ${result}`);
|
||||
if (!result) {
|
||||
throw new common_1.HttpException('身份验证错误,请检查实名信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
await this.userService.saveRealNameInfo(id, name, idCard);
|
||||
return '认证成功';
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('验证过程出现错误', error);
|
||||
throw new common_1.HttpException('认证失败,请检查相关信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
async verifyPhoneIdentity(req, body) {
|
||||
common_1.Logger.debug('开始手机号认证流程');
|
||||
const { phone, username, password, code } = body;
|
||||
const { id } = req.user;
|
||||
const nameSpace = this.globalConfigService.getNamespace();
|
||||
const key = `${nameSpace}:CODE:${phone}`;
|
||||
const redisCode = await this.redisCacheService.get({ key });
|
||||
common_1.Logger.debug(`Retrieved redisCode for ${phone}: ${redisCode}`);
|
||||
if (code === '') {
|
||||
throw new common_1.HttpException('请输入验证码', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (!redisCode) {
|
||||
common_1.Logger.log(`验证码过期: ${phone}`, 'authService');
|
||||
throw new common_1.HttpException('验证码已过期,请重新发送!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (code !== redisCode) {
|
||||
common_1.Logger.log(`验证码错误: ${phone} 输入的验证码: ${code}, 期望的验证码: ${redisCode}`, 'authService');
|
||||
throw new common_1.HttpException('验证码填写错误,请重新输入!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (username) {
|
||||
const usernameTaken = await this.userService.isUsernameTaken(body.username, id);
|
||||
if (usernameTaken) {
|
||||
throw new common_1.HttpException('用户名已存在!', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
try {
|
||||
await this.userService.updateUserPhone(id, phone, username, password);
|
||||
return '认证成功';
|
||||
}
|
||||
catch (error) {
|
||||
common_1.Logger.error('验证过程出现错误', error);
|
||||
throw new common_1.HttpException('身份验证错误,请检查相关信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
};
|
||||
AuthService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(config_entity_1.ConfigEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository,
|
||||
user_service_1.UserService,
|
||||
jwt_1.JwtService,
|
||||
mailer_service_1.MailerService,
|
||||
verification_service_1.VerificationService,
|
||||
userBalance_service_1.UserBalanceService,
|
||||
redisCache_service_1.RedisCacheService,
|
||||
globalConfig_service_1.GlobalConfigService])
|
||||
], AuthService);
|
||||
exports.AuthService = AuthService;
|
@ -1,32 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AdminLoginDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class AdminLoginDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'super', description: '邮箱' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户名不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(2, { message: '用户名最短是两位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户名最长不得超过30位!' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], AdminLoginDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '999999', description: '密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], AdminLoginDto.prototype, "password", void 0);
|
||||
exports.AdminLoginDto = AdminLoginDto;
|
@ -1,37 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserLoginDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UserLoginDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'super', description: '邮箱' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户名不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(2, { message: '用户名最短是两位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户名最长不得超过30位!' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UserLoginDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '用户ID' }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UserLoginDto.prototype, "uid", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '999999', description: '密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserLoginDto.prototype, "password", void 0);
|
||||
exports.UserLoginDto = UserLoginDto;
|
@ -1,50 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserRegisterDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UserRegisterDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'cooper', description: '用户名称' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '123456', description: '用户密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "password", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'ai@aiweb.com', description: '用户邮箱' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "email", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '',
|
||||
description: '用户头像',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "avatar", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: 'default',
|
||||
description: '用户注册来源',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterDto.prototype, "client", void 0);
|
||||
exports.UserRegisterDto = UserRegisterDto;
|
@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LoginByPhoneDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class LoginByPhoneDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '19999999', description: '手机号' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '手机号不能为空!' }),
|
||||
(0, class_validator_1.IsPhoneNumber)('CN', { message: '手机号格式不正确!' }),
|
||||
__metadata("design:type", String)
|
||||
], LoginByPhoneDto.prototype, "phone", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '999999', description: '密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], LoginByPhoneDto.prototype, "password", void 0);
|
||||
exports.LoginByPhoneDto = LoginByPhoneDto;
|
@ -1,34 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SendPhoneCodeDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class SendPhoneCodeDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '199999999', description: '手机号' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '手机号不能为空' }),
|
||||
(0, class_validator_1.MinLength)(11, { message: '手机号长度为11位' }),
|
||||
(0, class_validator_1.MaxLength)(11, { message: '手机号长度为11位!' }),
|
||||
__metadata("design:type", String)
|
||||
], SendPhoneCodeDto.prototype, "phone", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '2b4i1b4', description: '图形验证码KEY' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '验证码KEY不能为空' }),
|
||||
__metadata("design:type", String)
|
||||
], SendPhoneCodeDto.prototype, "captchaId", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '1g4d', description: '图形验证码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '验证码不能为空' }),
|
||||
__metadata("design:type", String)
|
||||
], SendPhoneCodeDto.prototype, "captchaCode", void 0);
|
||||
exports.SendPhoneCodeDto = SendPhoneCodeDto;
|
@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdatePassByOtherDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class UpdatePassByOtherDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '666666', description: '三方用户更新新密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UpdatePassByOtherDto.prototype, "password", void 0);
|
||||
exports.UpdatePassByOtherDto = UpdatePassByOtherDto;
|
@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdatePasswordDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UpdatePasswordDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '666666', description: '用户更新新密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UpdatePasswordDto.prototype, "password", void 0);
|
||||
exports.UpdatePasswordDto = UpdatePasswordDto;
|
@ -1,42 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UserRegisterByPhoneDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UserRegisterByPhoneDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 'cooper', description: '用户名称' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户名不能为空!' }),
|
||||
(0, class_validator_1.MinLength)(2, { message: '用户名最低需要大于2位数!' }),
|
||||
(0, class_validator_1.MaxLength)(12, { message: '用户名不得超过12位!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterByPhoneDto.prototype, "username", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '123456', description: '用户密码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '用户密码不能为空' }),
|
||||
(0, class_validator_1.MinLength)(6, { message: '用户密码最低需要大于6位数!' }),
|
||||
(0, class_validator_1.MaxLength)(30, { message: '用户密码最长不能超过30位数!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterByPhoneDto.prototype, "password", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '19999999999', description: '用户手机号码' }),
|
||||
(0, class_validator_1.IsPhoneNumber)('CN', { message: '手机号码格式不正确!' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '手机号码不能为空!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterByPhoneDto.prototype, "phone", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '152546', description: '手机验证码' }),
|
||||
(0, class_validator_1.IsNotEmpty)({ message: '手机验证码不能为空!' }),
|
||||
__metadata("design:type", String)
|
||||
], UserRegisterByPhoneDto.prototype, "phoneCode", void 0);
|
||||
exports.UserRegisterByPhoneDto = UserRegisterByPhoneDto;
|
@ -1,87 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AutoreplyController = void 0;
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const autoreply_service_1 = require("./autoreply.service");
|
||||
const addAutoReply_dto_1 = require("./dto/addAutoReply.dto");
|
||||
const delBadWords_dto_1 = require("./dto/delBadWords.dto");
|
||||
const queryAutoReply_dto_1 = require("./dto/queryAutoReply.dto");
|
||||
const updateAutoReply_dto_1 = require("./dto/updateAutoReply.dto");
|
||||
let AutoreplyController = class AutoreplyController {
|
||||
constructor(autoreplyService) {
|
||||
this.autoreplyService = autoreplyService;
|
||||
}
|
||||
queryAutoreply(query) {
|
||||
return this.autoreplyService.queryAutoreply(query);
|
||||
}
|
||||
addAutoreply(body) {
|
||||
return this.autoreplyService.addAutoreply(body);
|
||||
}
|
||||
updateAutoreply(body) {
|
||||
return this.autoreplyService.updateAutoreply(body);
|
||||
}
|
||||
delAutoreply(body) {
|
||||
return this.autoreplyService.delAutoreply(body);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('query'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询自动回复' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryAutoReply_dto_1.QueryAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "queryAutoreply", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('add'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '添加自动回复' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [addAutoReply_dto_1.AddAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "addAutoreply", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('update'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '修改自动回复' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [updateAutoReply_dto_1.UpdateAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "updateAutoreply", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('del'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除自动回复' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [delBadWords_dto_1.DelAutoReplyDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], AutoreplyController.prototype, "delAutoreply", null);
|
||||
AutoreplyController = __decorate([
|
||||
(0, swagger_1.ApiTags)('autoreply'),
|
||||
(0, common_1.Controller)('autoreply'),
|
||||
__metadata("design:paramtypes", [autoreply_service_1.AutoreplyService])
|
||||
], AutoreplyController);
|
||||
exports.AutoreplyController = AutoreplyController;
|
@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AutoReplyEntity = void 0;
|
||||
const baseEntity_1 = require("../../common/entity/baseEntity");
|
||||
const typeorm_1 = require("typeorm");
|
||||
let AutoReplyEntity = class AutoReplyEntity extends baseEntity_1.BaseEntity {
|
||||
};
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '提问的问题', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AutoReplyEntity.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ comment: '定义的答案', type: 'text' }),
|
||||
__metadata("design:type", String)
|
||||
], AutoReplyEntity.prototype, "answer", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '是否开启AI回复,0:关闭 1:启用' }),
|
||||
__metadata("design:type", Number)
|
||||
], AutoReplyEntity.prototype, "isAIReplyEnabled", void 0);
|
||||
__decorate([
|
||||
(0, typeorm_1.Column)({ default: 1, comment: '启用当前自动回复状态, 0:关闭 1:启用' }),
|
||||
__metadata("design:type", Number)
|
||||
], AutoReplyEntity.prototype, "status", void 0);
|
||||
AutoReplyEntity = __decorate([
|
||||
(0, typeorm_1.Entity)({ name: 'auto_reply' })
|
||||
], AutoReplyEntity);
|
||||
exports.AutoReplyEntity = AutoReplyEntity;
|
@ -1,26 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AutoreplyModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const autoreply_controller_1 = require("./autoreply.controller");
|
||||
const autoreply_entity_1 = require("./autoreply.entity");
|
||||
const autoreply_service_1 = require("./autoreply.service");
|
||||
let AutoreplyModule = class AutoreplyModule {
|
||||
};
|
||||
AutoreplyModule = __decorate([
|
||||
(0, common_1.Global)(),
|
||||
(0, common_1.Module)({
|
||||
imports: [typeorm_1.TypeOrmModule.forFeature([autoreply_entity_1.AutoReplyEntity])],
|
||||
controllers: [autoreply_controller_1.AutoreplyController],
|
||||
providers: [autoreply_service_1.AutoreplyService],
|
||||
exports: [autoreply_service_1.AutoreplyService],
|
||||
})
|
||||
], AutoreplyModule);
|
||||
exports.AutoreplyModule = AutoreplyModule;
|
@ -1,126 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AutoreplyService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const typeorm_1 = require("@nestjs/typeorm");
|
||||
const typeorm_2 = require("typeorm");
|
||||
const autoreply_entity_1 = require("./autoreply.entity");
|
||||
let AutoreplyService = class AutoreplyService {
|
||||
constructor(autoReplyEntity) {
|
||||
this.autoReplyEntity = autoReplyEntity;
|
||||
this.autoReplyKes = [];
|
||||
this.autoReplyMap = {};
|
||||
this.autoReplyFuzzyMatch = true;
|
||||
}
|
||||
async onModuleInit() {
|
||||
await this.loadAutoReplyList();
|
||||
}
|
||||
async loadAutoReplyList() {
|
||||
const res = await this.autoReplyEntity.find({
|
||||
where: { status: 1 },
|
||||
select: ['prompt', 'answer', 'isAIReplyEnabled'],
|
||||
});
|
||||
this.autoReplyMap = {};
|
||||
this.autoReplyKes = [];
|
||||
res.forEach((t) => {
|
||||
this.autoReplyMap[t.prompt] = {
|
||||
answer: t.answer,
|
||||
isAIReplyEnabled: t.isAIReplyEnabled,
|
||||
};
|
||||
const keywords = t.prompt.split(' ').map((k) => k.trim());
|
||||
this.autoReplyKes.push({ prompt: t.prompt, keywords });
|
||||
});
|
||||
}
|
||||
async checkAutoReply(prompt) {
|
||||
let answers = [];
|
||||
let isAIReplyEnabled = 0;
|
||||
const seenGroups = new Set();
|
||||
if (this.autoReplyFuzzyMatch) {
|
||||
for (const item of this.autoReplyKes) {
|
||||
if (item.keywords.some((keyword) => prompt.includes(keyword))) {
|
||||
if (!seenGroups.has(item.prompt)) {
|
||||
answers.push(this.autoReplyMap[item.prompt].answer);
|
||||
seenGroups.add(item.prompt);
|
||||
if (this.autoReplyMap[item.prompt].isAIReplyEnabled === 1) {
|
||||
isAIReplyEnabled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const matches = this.autoReplyKes.filter((item) => item.prompt === prompt);
|
||||
for (const match of matches) {
|
||||
if (!seenGroups.has(match.prompt)) {
|
||||
answers.push(this.autoReplyMap[match.prompt].answer);
|
||||
seenGroups.add(match.prompt);
|
||||
if (this.autoReplyMap[match.prompt].isAIReplyEnabled === 1) {
|
||||
isAIReplyEnabled = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
answer: answers.join('\n'),
|
||||
isAIReplyEnabled,
|
||||
};
|
||||
}
|
||||
async queryAutoreply(query) {
|
||||
const { page = 1, size = 10, prompt, status } = query;
|
||||
const where = {};
|
||||
[0, 1, '0', '1'].includes(status) && (where.status = status);
|
||||
prompt && (where.prompt = (0, typeorm_2.Like)(`%${prompt}%`));
|
||||
const [rows, count] = await this.autoReplyEntity.findAndCount({
|
||||
where,
|
||||
skip: (page - 1) * size,
|
||||
take: size,
|
||||
order: { id: 'DESC' },
|
||||
});
|
||||
return { rows, count };
|
||||
}
|
||||
async addAutoreply(body) {
|
||||
await this.autoReplyEntity.save(body);
|
||||
await this.loadAutoReplyList();
|
||||
return '添加问题成功!';
|
||||
}
|
||||
async updateAutoreply(body) {
|
||||
const { id } = body;
|
||||
const res = await this.autoReplyEntity.update({ id }, body);
|
||||
if (res.affected > 0) {
|
||||
await this.loadAutoReplyList();
|
||||
return '更新问题成功';
|
||||
}
|
||||
throw new common_1.HttpException('更新失败', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
async delAutoreply(body) {
|
||||
const { id } = body;
|
||||
const z = await this.autoReplyEntity.findOne({ where: { id } });
|
||||
if (!z) {
|
||||
throw new common_1.HttpException('该问题不存在,请检查您的提交信息', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const res = await this.autoReplyEntity.delete({ id });
|
||||
if (res.affected > 0) {
|
||||
await this.loadAutoReplyList();
|
||||
return '删除问题成功';
|
||||
}
|
||||
throw new common_1.HttpException('删除失败', common_1.HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
};
|
||||
AutoreplyService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(0, (0, typeorm_1.InjectRepository)(autoreply_entity_1.AutoReplyEntity)),
|
||||
__metadata("design:paramtypes", [typeorm_2.Repository])
|
||||
], AutoreplyService);
|
||||
exports.AutoreplyService = AutoreplyService;
|
@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AddAutoReplyDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class AddAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你是谁', description: '提问的问题', required: true }),
|
||||
__metadata("design:type", String)
|
||||
], AddAutoReplyDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '我是AIWeb提供的Ai服务机器人',
|
||||
description: '回答的答案',
|
||||
required: true,
|
||||
}),
|
||||
__metadata("design:type", String)
|
||||
], AddAutoReplyDto.prototype, "answer", void 0);
|
||||
exports.AddAutoReplyDto = AddAutoReplyDto;
|
@ -1,20 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DelAutoReplyDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class DelAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '自动回复id', required: true }),
|
||||
__metadata("design:type", Number)
|
||||
], DelAutoReplyDto.prototype, "id", void 0);
|
||||
exports.DelAutoReplyDto = DelAutoReplyDto;
|
@ -1,37 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.QueryAutoReplyDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
class QueryAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '查询页数', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAutoReplyDto.prototype, "page", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 10, description: '每页数量', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAutoReplyDto.prototype, "size", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你是谁', description: '提问问题', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], QueryAutoReplyDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '问题状态', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], QueryAutoReplyDto.prototype, "status", void 0);
|
||||
exports.QueryAutoReplyDto = QueryAutoReplyDto;
|
@ -1,41 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdateAutoReplyDto = void 0;
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UpdateAutoReplyDto {
|
||||
}
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 1, description: '自动回复id', required: true }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateAutoReplyDto.prototype, "id", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: '你可以干嘛', description: '问题', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateAutoReplyDto.prototype, "prompt", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({
|
||||
example: '我可以干很多事情.......',
|
||||
description: '答案',
|
||||
required: false,
|
||||
}),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateAutoReplyDto.prototype, "answer", void 0);
|
||||
__decorate([
|
||||
(0, swagger_1.ApiProperty)({ example: 0, description: '状态', required: false }),
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateAutoReplyDto.prototype, "status", void 0);
|
||||
exports.UpdateAutoReplyDto = UpdateAutoReplyDto;
|
@ -1,100 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BadWordsController = void 0;
|
||||
const adminAuth_guard_1 = require("../../common/auth/adminAuth.guard");
|
||||
const superAuth_guard_1 = require("../../common/auth/superAuth.guard");
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const badWords_service_1 = require("./badWords.service");
|
||||
const addBadWords_dto_1 = require("./dto/addBadWords.dto");
|
||||
const delBadWords_dto_1 = require("./dto/delBadWords.dto");
|
||||
const queryBadWords_dto_1 = require("./dto/queryBadWords.dto");
|
||||
const queryViolation_dto_1 = require("./dto/queryViolation.dto");
|
||||
const updateBadWords_dto_1 = require("./dto/updateBadWords.dto");
|
||||
let BadWordsController = class BadWordsController {
|
||||
constructor(badWordsService) {
|
||||
this.badWordsService = badWordsService;
|
||||
}
|
||||
queryBadWords(query) {
|
||||
return this.badWordsService.queryBadWords(query);
|
||||
}
|
||||
delBadWords(body) {
|
||||
return this.badWordsService.delBadWords(body);
|
||||
}
|
||||
updateBadWords(body) {
|
||||
return this.badWordsService.updateBadWords(body);
|
||||
}
|
||||
addBadWord(body) {
|
||||
return this.badWordsService.addBadWord(body);
|
||||
}
|
||||
violation(req, query) {
|
||||
return this.badWordsService.violation(req, query);
|
||||
}
|
||||
};
|
||||
__decorate([
|
||||
(0, common_1.Get)('query'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询所有敏感词' }),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [queryBadWords_dto_1.QueryBadWordsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "queryBadWords", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('del'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '删除敏感词' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [delBadWords_dto_1.DelBadWordsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "delBadWords", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('update'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '更新敏感词' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [updateBadWords_dto_1.UpdateBadWordsDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "updateBadWords", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('add'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '新增敏感词' }),
|
||||
(0, common_1.UseGuards)(superAuth_guard_1.SuperAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [addBadWords_dto_1.AddBadWordDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "addBadWord", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('violation'),
|
||||
(0, swagger_1.ApiOperation)({ summary: '查询违规记录' }),
|
||||
(0, common_1.UseGuards)(adminAuth_guard_1.AdminAuthGuard),
|
||||
(0, swagger_1.ApiBearerAuth)(),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, queryViolation_dto_1.QueryViolationDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], BadWordsController.prototype, "violation", null);
|
||||
BadWordsController = __decorate([
|
||||
(0, swagger_1.ApiTags)('badWords'),
|
||||
(0, common_1.Controller)('badWords'),
|
||||
__metadata("design:paramtypes", [badWords_service_1.BadWordsService])
|
||||
], BadWordsController);
|
||||
exports.BadWordsController = BadWordsController;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user