chore: move to tsdown
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
import { factory } from '@innei/prettier'
|
||||
import sortPlugin from '@ianvs/prettier-plugin-sort-imports'
|
||||
import jsonPlugin from 'prettier-package-json'
|
||||
|
||||
export default {
|
||||
...factory({
|
||||
tailwindcss: false,
|
||||
importSort: true,
|
||||
}),
|
||||
singleQuote: true,
|
||||
semi: false,
|
||||
trailingComma: 'all',
|
||||
importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
|
||||
tabWidth: 2,
|
||||
printWidth: 80,
|
||||
|
||||
arrowParens: 'always',
|
||||
endOfLine: 'lf',
|
||||
plugins: [jsonPlugin, sortPlugin],
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { AxiosRequestConfig } from 'axios'
|
||||
|
||||
import { argv } from '@mx-space/compiled'
|
||||
import type { AxiosRequestConfig } from 'axios'
|
||||
|
||||
export const PORT = process.env.PORT || 2333
|
||||
export const API_VERSION = 2
|
||||
|
||||
export const DEMO_MODE = false
|
||||
|
||||
export const CROSS_DOMAIN = {
|
||||
allowedOrigins: argv.allowed_origins
|
||||
? argv.allowed_origins?.split?.(',')
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { seconds } from '@nestjs/throttler'
|
||||
import type { AxiosRequestConfig } from 'axios'
|
||||
import { program } from 'commander'
|
||||
import { load as yamlLoad } from 'js-yaml'
|
||||
import { machineIdSync } from 'node-machine-id'
|
||||
import type { AxiosRequestConfig } from 'axios'
|
||||
|
||||
import { seconds } from '@nestjs/throttler'
|
||||
|
||||
import { isDebugMode, isDev } from './global/env.global'
|
||||
import { parseBooleanishValue } from './utils/tool.util'
|
||||
|
||||
@@ -14,7 +12,7 @@ const { PORT: ENV_PORT, ALLOWED_ORIGINS, MX_ENCRYPT_KEY } = process.env
|
||||
|
||||
const commander = program
|
||||
.option('-p, --port <number>', 'server port', ENV_PORT)
|
||||
.option('--demo', 'enable demo mode')
|
||||
|
||||
.option(
|
||||
'--allowed_origins <string>',
|
||||
'allowed origins, e.g. innei.ren,*.innei.ren',
|
||||
@@ -126,7 +124,7 @@ export const CROSS_DOMAIN = {
|
||||
}
|
||||
|
||||
export const MONGO_DB = {
|
||||
dbName: argv.collection_name || (DEMO_MODE ? 'mx-space_demo' : 'mx-space'),
|
||||
dbName: argv.collection_name || 'mx-space',
|
||||
host: argv.db_host || '127.0.0.1',
|
||||
// host: argv.db_host || '10.0.0.33',
|
||||
port: argv.db_port || 27017,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
Get,
|
||||
@@ -7,11 +5,10 @@ import {
|
||||
Post,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { InjectModel } from '~/transformers/model.transformer'
|
||||
|
||||
import dayjs from 'dayjs'
|
||||
import PKG from '../package.json'
|
||||
import { DEMO_MODE } from './app.config'
|
||||
import { HttpCache } from './common/decorators/cache.decorator'
|
||||
@@ -48,7 +45,7 @@ export class AppController {
|
||||
return {
|
||||
name: PKG.name,
|
||||
author: PKG.author,
|
||||
version: isDev ? 'dev' : `${DEMO_MODE ? 'demo/' : ''}${PKG.version}`,
|
||||
version: isDev ? 'dev' : String(PKG.version),
|
||||
homepage: PKG.homepage,
|
||||
issues: PKG.issues,
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { LoggerModule } from '@innei/pretty-logger-nestjs'
|
||||
import type {
|
||||
DynamicModule,
|
||||
MiddlewareConsumer,
|
||||
NestModule,
|
||||
Type,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { LoggerModule } from '@innei/pretty-logger-nestjs'
|
||||
import { Module } from '@nestjs/common'
|
||||
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core'
|
||||
|
||||
import { DEMO_MODE } from './app.config'
|
||||
import { AppController } from './app.controller'
|
||||
import { AllExceptionsFilter } from './common/filters/any-exception.filter'
|
||||
import { RolesGuard } from './common/guards/roles.guard'
|
||||
@@ -33,7 +30,6 @@ import { CategoryModule } from './modules/category/category.module'
|
||||
import { CommentModule } from './modules/comment/comment.module'
|
||||
import { ConfigsModule } from './modules/configs/configs.module'
|
||||
import { DebugModule } from './modules/debug/debug.module'
|
||||
import { DemoModule } from './modules/demo/demo.module'
|
||||
import { DependencyModule } from './modules/dependency/dependency.module'
|
||||
import { FeedModule } from './modules/feed/feed.module'
|
||||
import { FileModule } from './modules/file/file.module'
|
||||
@@ -88,7 +84,7 @@ import { RedisModule } from './processors/redis/redis.module'
|
||||
CategoryModule,
|
||||
CommentModule,
|
||||
ConfigsModule,
|
||||
DEMO_MODE && DemoModule,
|
||||
|
||||
DependencyModule,
|
||||
FeedModule,
|
||||
FileModule,
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import cluster from 'node:cluster'
|
||||
import { performance } from 'node:perf_hooks'
|
||||
import wcmatch from 'wildcard-match'
|
||||
import type { FastifyCorsOptions } from '@fastify/cors'
|
||||
import type { LogLevel } from '@nestjs/common'
|
||||
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
|
||||
|
||||
import { Logger } from '@innei/pretty-logger-nestjs'
|
||||
import { chalk } from '@mx-space/compiled'
|
||||
import type { LogLevel } from '@nestjs/common'
|
||||
import { NestFactory } from '@nestjs/core'
|
||||
|
||||
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
|
||||
import wcmatch from 'wildcard-match'
|
||||
import { CROSS_DOMAIN, DEBUG_MODE, PORT } from './app.config'
|
||||
import { AppModule } from './app.module'
|
||||
import { fastifyApp } from './common/adapters/fastify.adapter'
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import cluster from 'node:cluster'
|
||||
import os from 'node:os'
|
||||
|
||||
import { logger } from './global/consola.global'
|
||||
|
||||
export const Cluster = {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
import fastifyCookie from '@fastify/cookie'
|
||||
import FastifyMultipart from '@fastify/multipart'
|
||||
import { Logger } from '@nestjs/common'
|
||||
import { FastifyAdapter } from '@nestjs/platform-fastify'
|
||||
|
||||
import { getIp } from '~/utils/ip.util'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
const app: FastifyAdapter = new FastifyAdapter({
|
||||
trustProxy: true,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { Server } from 'socket.io'
|
||||
|
||||
import { IoAdapter } from '@nestjs/platform-socket.io'
|
||||
import { createAdapter } from '@socket.io/redis-adapter'
|
||||
|
||||
import { redisSubPub } from '~/utils/redis-subpub.util'
|
||||
import type { Server } from 'socket.io'
|
||||
|
||||
export const RedisIoAdapterKey = 'mx-core-socket'
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
/* eslint-disable dot-notation */
|
||||
// @reference https://github.com/ever-co/ever-gauzy/blob/d36b4f40b1446f3c33d02e0ba00b53a83109d950/packages/core/src/core/context/request-context.ts
|
||||
import * as cls from 'cls-hooked'
|
||||
import type { ServerResponse } from 'node:http'
|
||||
import { UnauthorizedException } from '@nestjs/common'
|
||||
import type { UserModel } from '~/modules/user/user.model'
|
||||
import type { BizIncomingMessage } from '~/transformers/get-req.transformer'
|
||||
import type { ServerResponse } from 'node:http'
|
||||
|
||||
import { UnauthorizedException } from '@nestjs/common'
|
||||
import * as cls from 'cls-hooked'
|
||||
|
||||
type Nullable<T> = T | null
|
||||
export class RequestContext {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { ControllerOptions } from '@nestjs/common'
|
||||
|
||||
import { Controller } from '@nestjs/common'
|
||||
|
||||
import { API_VERSION } from '~/app.config'
|
||||
import { isDev } from '~/global/env.global'
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { applyDecorators, UseGuards } from '@nestjs/common'
|
||||
|
||||
import { AuthGuard } from '../guards/auth.guard'
|
||||
|
||||
export function Auth() {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
import { CacheKey, CacheTTL } from '@nestjs/cache-manager'
|
||||
import { SetMetadata } from '@nestjs/common'
|
||||
|
||||
import * as META from '~/constants/meta.constant'
|
||||
|
||||
// 缓存器配置
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
export const Cookies = createParamDecorator(
|
||||
(data: string, ctx: ExecutionContext) => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { SetMetadata } from '@nestjs/common'
|
||||
|
||||
import { CRON_DESCRIPTION } from '~/constants/meta.constant'
|
||||
|
||||
export const CronDescription = (description: string) =>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import cluster from 'node:cluster'
|
||||
|
||||
import { Cron } from '@nestjs/schedule'
|
||||
|
||||
import { isMainProcess } from '~/global/env.global'
|
||||
|
||||
export const CronOnce: typeof Cron = (...rest): MethodDecorator => {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
export const CurrentUser = createParamDecorator(
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import type { CanActivate } from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { applyDecorators, UseGuards } from '@nestjs/common'
|
||||
|
||||
import { banInDemo } from '~/utils/biz.util'
|
||||
|
||||
class DemoGuard implements CanActivate {
|
||||
canActivate(): boolean | Promise<boolean> | Observable<boolean> {
|
||||
banInDemo()
|
||||
return true
|
||||
}
|
||||
}
|
||||
export const BanInDemo = applyDecorators(UseGuards(DemoGuard))
|
||||
@@ -1,12 +1,10 @@
|
||||
import type { IdempotenceOption } from '../interceptors/idempotence.interceptor'
|
||||
|
||||
import { SetMetadata } from '@nestjs/common'
|
||||
|
||||
import {
|
||||
HTTP_IDEMPOTENCE_OPTIONS,
|
||||
HTTP_RES_TRANSFORM_PAGINATE,
|
||||
} from '~/constants/meta.constant'
|
||||
import * as SYSTEM from '~/constants/system.constant'
|
||||
import type { IdempotenceOption } from '../interceptors/idempotence.interceptor'
|
||||
|
||||
/**
|
||||
* @description 分页转换
|
||||
|
||||
@@ -7,11 +7,9 @@
|
||||
* @Coding with Love
|
||||
*/
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
|
||||
import { getIp } from '~/utils/ip.util'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
export type IpRecord = {
|
||||
ip: string
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
|
||||
import { isTest } from '~/global/env.global'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
|
||||
import { BusinessException } from './biz.exception'
|
||||
|
||||
export class BanInDemoExcpetion extends BusinessException {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { HttpException } from '@nestjs/common'
|
||||
|
||||
import { ErrorCode, ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
|
||||
export class BusinessException extends HttpException {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { sample } from 'lodash'
|
||||
|
||||
import { NotFoundException } from '@nestjs/common'
|
||||
import { sample } from 'lodash'
|
||||
|
||||
export const NotFoundMessage = [
|
||||
'真不巧,内容走丢了 o(╥﹏╥)o',
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
|
||||
import { BizException } from './biz.exception'
|
||||
|
||||
export class NoContentCanBeModifiedException extends BizException {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { createWriteStream } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify'
|
||||
import type { WriteStream } from 'node:fs'
|
||||
|
||||
import { resolve } from 'node:path'
|
||||
import { chalk } from '@mx-space/compiled'
|
||||
import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'
|
||||
import {
|
||||
Catch,
|
||||
HttpException,
|
||||
@@ -13,7 +11,6 @@ import {
|
||||
Logger,
|
||||
} from '@nestjs/common'
|
||||
import { Reflector } from '@nestjs/core'
|
||||
|
||||
import { EventScope } from '~/constants/business-event.constant'
|
||||
import { EventBusEvents } from '~/constants/event-bus.constant'
|
||||
import { HTTP_REQUEST_TIME } from '~/constants/meta.constant'
|
||||
@@ -23,7 +20,7 @@ import { isDev } from '~/global/env.global'
|
||||
import { ConfigsService } from '~/modules/configs/configs.service'
|
||||
import { BarkPushService } from '~/processors/helper/helper.bark.service'
|
||||
import { EventManagerService } from '~/processors/helper/helper.event.service'
|
||||
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify'
|
||||
import { getIp } from '../../utils/ip.util'
|
||||
import { BizException } from '../exceptions/biz.exception'
|
||||
import { LoggingInterceptor } from '../interceptors/logging.interceptor'
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { isJWT } from 'class-validator'
|
||||
import type { CanActivate, ExecutionContext } from '@nestjs/common'
|
||||
import type { UserModel } from '~/modules/user/user.model'
|
||||
import type { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common'
|
||||
|
||||
import { AuthService } from '~/modules/auth/auth.service'
|
||||
import { ConfigsService } from '~/modules/configs/configs.service'
|
||||
import type { UserModel } from '~/modules/user/user.model'
|
||||
import { UserService } from '~/modules/user/user.service'
|
||||
import type { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import { isJWT } from 'class-validator'
|
||||
|
||||
/**
|
||||
* JWT auth guard
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { CanActivate, ExecutionContext } from '@nestjs/common'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { AuthService } from '~/modules/auth/auth.service'
|
||||
import { ConfigsService } from '~/modules/configs/configs.service'
|
||||
import { UserService } from '~/modules/user/user.service'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
import { AuthGuard } from './auth.guard'
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
*/
|
||||
|
||||
import type { CanActivate, ExecutionContext } from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { ForbiddenException, Injectable } from '@nestjs/common'
|
||||
|
||||
import { isDev } from '~/global/env.global'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
@Injectable()
|
||||
export class SpiderGuard implements CanActivate {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
import type { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ThrottlerGuard } from '@nestjs/throttler'
|
||||
|
||||
import type { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import { getIp } from '~/utils/ip.util'
|
||||
|
||||
|
||||
@@ -3,11 +3,10 @@ import type {
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import { RequestMethod } from '@nestjs/common'
|
||||
import type { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
import type { FastifyReply } from 'fastify'
|
||||
|
||||
import { RequestMethod } from '@nestjs/common'
|
||||
|
||||
export class AllowAllCorsInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, next: CallHandler<any>) {
|
||||
const handle = next.handle()
|
||||
|
||||
@@ -5,19 +5,14 @@
|
||||
* @author Innei <https://github.com/Innei>
|
||||
*/
|
||||
import { URL } from 'node:url'
|
||||
import { isbot } from 'isbot'
|
||||
import { UAParser } from 'ua-parser-js'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { Reflector } from '@nestjs/core'
|
||||
import { ReturnModelType } from '@typegoose/typegoose'
|
||||
|
||||
import { RedisKeys } from '~/constants/cache.constant'
|
||||
import * as SYSTEM from '~/constants/system.constant'
|
||||
import { REFLECTOR } from '~/constants/system.constant'
|
||||
@@ -29,6 +24,9 @@ import { InjectModel } from '~/transformers/model.transformer'
|
||||
import { getIp } from '~/utils/ip.util'
|
||||
import { getRedisKey } from '~/utils/redis.util'
|
||||
import { scheduleManager } from '~/utils/schedule.util'
|
||||
import { isbot } from 'isbot'
|
||||
import type { Observable } from 'rxjs'
|
||||
import { UAParser } from 'ua-parser-js'
|
||||
|
||||
@Injectable()
|
||||
export class AnalyzeInterceptor implements NestInterceptor {
|
||||
|
||||
@@ -5,18 +5,13 @@
|
||||
* @author Surmon <https://github.com/surmon-china>
|
||||
* @author Innei <https://innei.in>
|
||||
*/
|
||||
import { of, tap } from 'rxjs'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { FastifyReply } from 'fastify'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { Inject, Injectable, Logger, RequestMethod } from '@nestjs/common'
|
||||
import { HttpAdapterHost, Reflector } from '@nestjs/core'
|
||||
|
||||
import { HTTP_CACHE, REDIS } from '~/app.config'
|
||||
import { API_CACHE_PREFIX } from '~/constants/cache.constant'
|
||||
import * as META from '~/constants/meta.constant'
|
||||
@@ -24,6 +19,9 @@ import * as SYSTEM from '~/constants/system.constant'
|
||||
import { CacheService } from '~/processors/redis/cache.service'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import { hashString } from '~/utils/tool.util'
|
||||
import type { FastifyReply } from 'fastify'
|
||||
import { of, tap } from 'rxjs'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
/**
|
||||
* @class HttpCacheInterceptor
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import qs from 'qs'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import qs from 'qs'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
/** 此拦截器用于转换 req.query.query -> js object,用于直接数据库查询,需要鉴权 */
|
||||
@Injectable()
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import { catchError, tap } from 'rxjs'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
import {
|
||||
ConflictException,
|
||||
Inject,
|
||||
@@ -13,7 +10,6 @@ import {
|
||||
SetMetadata,
|
||||
} from '@nestjs/common'
|
||||
import { Reflector } from '@nestjs/core'
|
||||
|
||||
import {
|
||||
HTTP_IDEMPOTENCE_KEY,
|
||||
HTTP_IDEMPOTENCE_OPTIONS,
|
||||
@@ -23,6 +19,8 @@ import { RedisService } from '~/processors/redis/redis.service'
|
||||
import { getIp } from '~/utils/ip.util'
|
||||
import { getRedisKey } from '~/utils/redis.util'
|
||||
import { hashString } from '~/utils/tool.util'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
import { catchError, tap } from 'rxjs'
|
||||
|
||||
const IdempotenceHeaderKey = 'x-idempotence'
|
||||
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
* 对响应体进行 JSON 标准的转换
|
||||
* @author Innei
|
||||
*/
|
||||
import { isObjectLike } from 'lodash'
|
||||
import { map } from 'rxjs'
|
||||
import snakecaseKeys from 'snakecase-keys'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { Reflector } from '@nestjs/core'
|
||||
|
||||
import { RESPONSE_PASSTHROUGH_METADATA } from '~/constants/system.constant'
|
||||
import { isObjectLike } from 'lodash'
|
||||
import { map } from 'rxjs'
|
||||
import type { Observable } from 'rxjs'
|
||||
import snakecaseKeys from 'snakecase-keys'
|
||||
|
||||
@Injectable()
|
||||
export class JSONTransformInterceptor implements NestInterceptor {
|
||||
|
||||
@@ -5,19 +5,17 @@
|
||||
* @author Surmon <https://github.com/surmon-china>
|
||||
* @author Innei <https://github.com/Innei>
|
||||
*/
|
||||
import { tap } from 'rxjs/operators'
|
||||
import { chalk } from '@mx-space/compiled'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { chalk } from '@mx-space/compiled'
|
||||
import { Injectable, Logger, SetMetadata } from '@nestjs/common'
|
||||
|
||||
import { HTTP_REQUEST_TIME } from '~/constants/meta.constant'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import type { Observable } from 'rxjs'
|
||||
import { tap } from 'rxjs/operators'
|
||||
|
||||
@Injectable()
|
||||
export class LoggingInterceptor implements NestInterceptor {
|
||||
|
||||
@@ -2,21 +2,19 @@
|
||||
* 对响应体进行转换结构
|
||||
* @author Innei
|
||||
*/
|
||||
import { isArrayLike } from 'lodash'
|
||||
import { map } from 'rxjs/operators'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { Reflector } from '@nestjs/core'
|
||||
|
||||
import { HTTP_RES_TRANSFORM_PAGINATE } from '~/constants/meta.constant'
|
||||
import * as SYSTEM from '~/constants/system.constant'
|
||||
import { transformDataToPaginate } from '~/transformers/paginate.transformer'
|
||||
import { isArrayLike } from 'lodash'
|
||||
import type { Observable } from 'rxjs'
|
||||
import { map } from 'rxjs/operators'
|
||||
|
||||
export interface Response<T> {
|
||||
data: T
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
// https://github.dev/ever-co/ever-gauzy/packages/core/src/core/context/request-context.middleware.ts
|
||||
|
||||
import * as cls from 'cls-hooked'
|
||||
import type { NestMiddleware } from '@nestjs/common'
|
||||
import type { ServerResponse } from 'node:http'
|
||||
|
||||
import type { NestMiddleware } from '@nestjs/common'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { BizIncomingMessage } from '~/transformers/get-req.transformer'
|
||||
|
||||
import * as cls from 'cls-hooked'
|
||||
import { RequestContext } from '../contexts/request.context'
|
||||
|
||||
@Injectable()
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { ValidationPipeOptions } from '@nestjs/common'
|
||||
|
||||
import { Injectable, ValidationPipe } from '@nestjs/common'
|
||||
|
||||
import { isDev } from '~/global/env.global'
|
||||
|
||||
@Injectable()
|
||||
|
||||
@@ -59,8 +59,8 @@ export const ErrorCode = Object.freeze<Record<ErrorCodeEnum, [string, number]>>(
|
||||
|
||||
[ErrorCodeEnum.EmailTemplateNotFound]: ['邮件模板不存在', 400],
|
||||
|
||||
[ErrorCodeEnum.BingAPIFailed]: ['Bing API请求失败', 503],
|
||||
[ErrorCodeEnum.BingKeyInvalid]: ['Bing API密钥无效', 401],
|
||||
[ErrorCodeEnum.BingDomainInvalid]: ['Bing API域名无效', 400],
|
||||
[ErrorCodeEnum.BingAPIFailed]: ['Bing API 请求失败', 503],
|
||||
[ErrorCodeEnum.BingKeyInvalid]: ['Bing API 密钥无效', 401],
|
||||
[ErrorCodeEnum.BingDomainInvalid]: ['Bing API 域名无效', 400],
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { homedir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { cwd, isDev } from '~/global/env.global'
|
||||
|
||||
export const HOME = homedir()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { isURL } from 'class-validator'
|
||||
import type { ValidationOptions } from 'class-validator'
|
||||
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
|
||||
export const IsAllowedUrl = (validationOptions?: ValidationOptions) => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { isString } from 'class-validator'
|
||||
import { isBoolean, merge } from 'lodash'
|
||||
import type { ValidationOptions } from 'class-validator'
|
||||
|
||||
import { isBoolean, merge } from 'lodash'
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
|
||||
export function IsBooleanOrString(validationOptions?: ValidationOptions) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { isInt, isMongoId } from 'class-validator'
|
||||
import { merge } from 'lodash'
|
||||
import type { ValidationOptions } from 'class-validator'
|
||||
|
||||
import { merge } from 'lodash'
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
|
||||
export function IsBooleanOrString(validationOptions?: ValidationOptions) {
|
||||
|
||||
@@ -3,12 +3,12 @@ import {
|
||||
registerDecorator,
|
||||
ValidatorConstraint,
|
||||
} from 'class-validator'
|
||||
import { isNil } from 'lodash'
|
||||
import type {
|
||||
ValidationArguments,
|
||||
ValidationOptions,
|
||||
ValidatorConstraintInterface,
|
||||
} from 'class-validator'
|
||||
import { isNil } from 'lodash'
|
||||
|
||||
@ValidatorConstraint({ async: true })
|
||||
class IsNilOrStringConstraint implements ValidatorConstraintInterface {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { applyDecorators } from '@nestjs/common'
|
||||
import { Transform } from 'class-transformer'
|
||||
import { IsOptional } from 'class-validator'
|
||||
|
||||
import { applyDecorators } from '@nestjs/common'
|
||||
|
||||
export const TransformEmptyNull = () => {
|
||||
return applyDecorators(
|
||||
Transform(({ value: val }) => (String(val).length === 0 ? null : val)),
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import fs from 'node:fs'
|
||||
import v8 from 'node:v8'
|
||||
|
||||
import { TEMP_DIR } from './constants/path.constant'
|
||||
|
||||
function createHeapSnapshot() {
|
||||
const snapshotStream = v8.getHeapSnapshot()
|
||||
const localeDate = new Date().toLocaleString()
|
||||
const fileName = `${TEMP_DIR}/HeapSnapshot-${localeDate}.heapsnapshot`
|
||||
const fileStream = fs.createWriteStream(fileName)
|
||||
snapshotStream.pipe(fileStream).on('finish', () => {
|
||||
console.info('Heap snapshot saved to', fileName)
|
||||
})
|
||||
}
|
||||
export function registerForMemoryDump() {
|
||||
function createHeapSnapshot() {
|
||||
const snapshotStream = v8.getHeapSnapshot()
|
||||
const localeDate = new Date().toLocaleString()
|
||||
const fileName = `${TEMP_DIR}/HeapSnapshot-${localeDate}.heapsnapshot`
|
||||
const fileStream = fs.createWriteStream(fileName)
|
||||
snapshotStream.pipe(fileStream).on('finish', () => {
|
||||
console.log('Heap snapshot saved to', fileName)
|
||||
})
|
||||
}
|
||||
|
||||
process.on('SIGUSR2', () => {
|
||||
console.log('SIGUSR2 received, creating heap snapshot...')
|
||||
console.info('SIGUSR2 received, creating heap snapshot...')
|
||||
createHeapSnapshot()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { createLogger, Logger } from '@innei/pretty-logger-nestjs'
|
||||
|
||||
import { LOG_DIR } from '~/constants/path.constant'
|
||||
|
||||
import { isTest } from './env.global'
|
||||
|
||||
const logger = createLogger({
|
||||
|
||||
@@ -2,7 +2,6 @@ import dayjs from 'dayjs'
|
||||
import duration from 'dayjs/plugin/duration'
|
||||
import localizedFormat from 'dayjs/plugin/localizedFormat'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
|
||||
import 'dayjs/locale/zh-cn'
|
||||
|
||||
dayjs.locale('zh-cn')
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import cluster from 'node:cluster'
|
||||
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
||||
|
||||
import { Logger } from '@nestjs/common'
|
||||
|
||||
import { CLUSTER } from '~/app.config'
|
||||
import {
|
||||
DATA_DIR,
|
||||
@@ -12,13 +10,10 @@ import {
|
||||
TEMP_DIR,
|
||||
USER_ASSET_DIR,
|
||||
} from '~/constants/path.constant'
|
||||
|
||||
import { consola, logger } from './consola.global'
|
||||
import { cwd, isDev } from './env.global'
|
||||
import { registerJSONGlobal } from './json.global'
|
||||
|
||||
import './dayjs.global'
|
||||
|
||||
import { $, chalk } from '@mx-space/compiled'
|
||||
|
||||
// 建立目录
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
// register global
|
||||
import cluster from 'node:cluster'
|
||||
import { cpus } from 'node:os'
|
||||
|
||||
import { argv } from '@mx-space/compiled'
|
||||
|
||||
import { DEBUG_MODE } from './app.config'
|
||||
import { registerForMemoryDump } from './dump'
|
||||
import { logger } from './global/consola.global'
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import 'reflect-metadata'
|
||||
|
||||
import { plainToInstance } from 'class-transformer'
|
||||
import type { IConfigKeys } from '~/modules/configs/configs.interface'
|
||||
|
||||
import { ENCRYPT } from '~/app.config'
|
||||
import { initializeApp } from '~/global/index.global'
|
||||
import { generateDefaultConfig } from '~/modules/configs/configs.default'
|
||||
import * as optionDtos from '~/modules/configs/configs.dto'
|
||||
import { encryptObject } from '~/modules/configs/configs.encrypt.util'
|
||||
import type { IConfigKeys } from '~/modules/configs/configs.interface'
|
||||
import { IConfig } from '~/modules/configs/configs.interface'
|
||||
import { getDatabaseConnection } from '~/utils/database.util'
|
||||
import { plainToInstance } from 'class-transformer'
|
||||
|
||||
console.log(ENCRYPT)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { MIGRATE_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
import { logger } from '~/global/consola.global'
|
||||
import { getDatabaseConnection } from '~/utils/database.util'
|
||||
|
||||
import VersionList from './history'
|
||||
|
||||
export async function migrateDatabase() {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import type { Db } from 'mongodb'
|
||||
|
||||
import {
|
||||
NOTE_COLLECTION_NAME,
|
||||
POST_COLLECTION_NAME,
|
||||
} from '~/constants/db.constant'
|
||||
import type { Db } from 'mongodb'
|
||||
|
||||
export default (async function v4_6_0__4(db: Db) {
|
||||
const countDefault = {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// patch for version lower than v4.6.0
|
||||
|
||||
import type { Db } from 'mongodb'
|
||||
|
||||
import {
|
||||
NOTE_COLLECTION_NAME,
|
||||
PAGE_COLLECTION_NAME,
|
||||
} from '~/constants/db.constant'
|
||||
import type { Db } from 'mongodb'
|
||||
|
||||
export default (async function v4_6_0(db: Db) {
|
||||
await Promise.all([
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
POST_COLLECTION_NAME,
|
||||
RECENTLY_COLLECTION_NAME,
|
||||
} from '~/constants/db.constant'
|
||||
|
||||
import { defineMigration } from '../helper'
|
||||
|
||||
export default defineMigration('v4.6.2__0', async (db, _connection) => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { NOTE_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
|
||||
import { defineMigration } from '../helper'
|
||||
|
||||
export default defineMigration('v5.0.0-1', async (db) => {
|
||||
|
||||
@@ -2,7 +2,6 @@ import {
|
||||
COMMENT_COLLECTION_NAME,
|
||||
RECENTLY_COLLECTION_NAME,
|
||||
} from '~/constants/db.constant'
|
||||
|
||||
import { defineMigration } from '../helper'
|
||||
|
||||
export default defineMigration('v5.1.1', async (db) => {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//patch for version 8.4.0 v1
|
||||
//移除Note中的isPublished字段,并将hide字段重命名为isPublished
|
||||
//移除 Note 中的 isPublished 字段,并将 hide 字段重命名为 isPublished
|
||||
import type { Db } from 'mongodb'
|
||||
|
||||
export default (async function v0840Fix1(db: Db) {
|
||||
try {
|
||||
const notesCollection = db.collection('notes')
|
||||
|
||||
// 将 hide 字段重命名为 isPublished, 同时将true与false互换
|
||||
// 将 hide 字段重命名为 isPublished, 同时将 true 与 false 互换
|
||||
await notesCollection.updateMany(
|
||||
{},
|
||||
[
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// patch for version 8.4.0 v2
|
||||
// 将Posts中的isPublished字段全部设置为true
|
||||
// 将 Posts 中的 isPublished 字段全部设置为 true
|
||||
import type { Db } from 'mongodb'
|
||||
|
||||
export default (async function v0840Fix2(db: Db) {
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import { plainToInstance } from 'class-transformer'
|
||||
import { validateSync } from 'class-validator'
|
||||
import { FastifyReply } from 'fastify'
|
||||
import type { CountModel } from '~/shared/model/count.model'
|
||||
|
||||
import { Body, HttpCode, Inject, Post, Res } from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Cookies } from '~/common/decorators/cookie.decorator'
|
||||
import { ExtendedValidationPipe } from '~/common/pipes/validation.pipe'
|
||||
@@ -13,7 +7,10 @@ import { VALIDATION_PIPE_INJECTION } from '~/constants/system.constant'
|
||||
import { WebEventsGateway } from '~/processors/gateway/web/events.gateway'
|
||||
import { CountingService } from '~/processors/helper/helper.counting.service'
|
||||
import { CacheService } from '~/processors/redis/cache.service'
|
||||
|
||||
import type { CountModel } from '~/shared/model/count.model'
|
||||
import { plainToInstance } from 'class-transformer'
|
||||
import { validateSync } from 'class-validator'
|
||||
import { FastifyReply } from 'fastify'
|
||||
import { AckDto, AckEventType, AckReadPayloadDto } from './ack.dto'
|
||||
|
||||
@ApiController('ack')
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { IsEnum, IsMongoId, IsObject } from 'class-validator'
|
||||
|
||||
import { ArticleTypeEnum } from '~/constants/article.constant'
|
||||
import { IsEnum, IsMongoId, IsObject } from 'class-validator'
|
||||
|
||||
export enum AckEventType {
|
||||
READ = 'read',
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
|
||||
import { ExtendedValidationPipe } from '~/common/pipes/validation.pipe'
|
||||
import { VALIDATION_PIPE_INJECTION } from '~/constants/system.constant'
|
||||
|
||||
import { AckController } from './ack.controller'
|
||||
|
||||
@Module({
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { keyBy, pick } from 'lodash'
|
||||
import snakecaseKeys from 'snakecase-keys'
|
||||
|
||||
import { Body, Delete, Get, Param, Post, Query } from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { HTTPDecorators } from '~/common/decorators/http.decorator'
|
||||
import { IpLocation, IpRecord } from '~/common/decorators/ip.decorator'
|
||||
import { CollectionRefTypes } from '~/constants/db.constant'
|
||||
import { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
import { keyBy, pick } from 'lodash'
|
||||
import snakecaseKeys from 'snakecase-keys'
|
||||
import { ReaderService } from '../reader/reader.service'
|
||||
import { Activity } from './activity.constant'
|
||||
import { ActivityService } from './activity.service'
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { modelOptions, prop } from '@typegoose/typegoose'
|
||||
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
|
||||
import { Activity } from './activity.constant'
|
||||
|
||||
@modelOptions({
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { GatewayModule } from '~/processors/gateway/gateway.module'
|
||||
|
||||
import { CommentModule } from '../comment/comment.module'
|
||||
import { NoteModule } from '../note/note.module'
|
||||
import { PostModule } from '../post/post.module'
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
import { omit, pick, uniqBy } from 'lodash'
|
||||
import { ObjectId } from 'mongodb'
|
||||
import type { OnModuleDestroy, OnModuleInit } from '@nestjs/common'
|
||||
import type { Document } from 'mongoose'
|
||||
import type { Socket } from 'socket.io'
|
||||
import type { NoteModel } from '../note/note.model'
|
||||
import type { PageModel } from '../page/page.model'
|
||||
import type { PostModel } from '../post/post.model'
|
||||
import type { RecentlyModel } from '../recently/recently.model'
|
||||
import type {
|
||||
ActivityLikePayload,
|
||||
ActivityLikeSupportType,
|
||||
ActivityPresence,
|
||||
} from './activity.interface'
|
||||
import type { UpdatePresenceDto } from './dtos/presence.dto'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
forwardRef,
|
||||
@@ -21,7 +6,6 @@ import {
|
||||
Injectable,
|
||||
Logger,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { RequestContext } from '~/common/contexts/request.context'
|
||||
import { ArticleTypeEnum } from '~/constants/article.constant'
|
||||
import { BusinessEvents, EventScope } from '~/constants/business-event.constant'
|
||||
@@ -39,21 +23,34 @@ import { InjectModel } from '~/transformers/model.transformer'
|
||||
import { transformDataToPaginate } from '~/transformers/paginate.transformer'
|
||||
import { checkRefModelCollectionType } from '~/utils/biz.util'
|
||||
import { camelcaseKeys } from '~/utils/tool.util'
|
||||
|
||||
import { omit, pick, uniqBy } from 'lodash'
|
||||
import { ObjectId } from 'mongodb'
|
||||
import type { Document } from 'mongoose'
|
||||
import type { Socket } from 'socket.io'
|
||||
import { CommentState } from '../comment/comment.model'
|
||||
import { CommentService } from '../comment/comment.service'
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import type { NoteModel } from '../note/note.model'
|
||||
import { NoteService } from '../note/note.service'
|
||||
import type { PageModel } from '../page/page.model'
|
||||
import type { PostModel } from '../post/post.model'
|
||||
import { PostService } from '../post/post.service'
|
||||
import { ReaderModel } from '../reader/reader.model'
|
||||
import { ReaderService } from '../reader/reader.service'
|
||||
import type { RecentlyModel } from '../recently/recently.model'
|
||||
import { Activity } from './activity.constant'
|
||||
import type {
|
||||
ActivityLikePayload,
|
||||
ActivityLikeSupportType,
|
||||
ActivityPresence,
|
||||
} from './activity.interface'
|
||||
import { ActivityModel } from './activity.model'
|
||||
import {
|
||||
extractArticleIdFromRoomName,
|
||||
isValidRoomName,
|
||||
parseRoomName,
|
||||
} from './activity.util'
|
||||
import type { UpdatePresenceDto } from './dtos/presence.dto'
|
||||
|
||||
declare module '~/types/socket-meta' {
|
||||
interface SocketMetadata {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { PagerDto } from '~/shared/dto/pager.dto'
|
||||
import { Transform, Type } from 'class-transformer'
|
||||
import { IsEnum, IsInt, IsNumber, IsOptional } from 'class-validator'
|
||||
|
||||
import { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
import { Activity } from '../activity.constant'
|
||||
|
||||
const TransformEnum = () =>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { IsEnum } from 'class-validator'
|
||||
|
||||
import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
|
||||
import { IsEnum } from 'class-validator'
|
||||
import { ActivityLikeSupportType } from '../activity.interface'
|
||||
|
||||
export class LikeBodyDto extends MongoIdDto {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import { omit } from 'lodash'
|
||||
|
||||
import { CacheKey, CacheTTL } from '@nestjs/cache-manager'
|
||||
import { Get, Query } from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { HttpCache } from '~/common/decorators/cache.decorator'
|
||||
import { IsAuthenticated } from '~/common/decorators/role.decorator'
|
||||
import { CacheKeys } from '~/constants/cache.constant'
|
||||
|
||||
import { omit } from 'lodash'
|
||||
import { AnalyzeService } from '../analyze/analyze.service'
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import { NoteService } from '../note/note.service'
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { GatewayModule } from '~/processors/gateway/gateway.module'
|
||||
|
||||
import { AnalyzeModule } from '../analyze/analyze.module'
|
||||
import { CategoryModule } from '../category/category.module'
|
||||
import { CommentModule } from '../comment/comment.module'
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import { URL } from 'node:url'
|
||||
import { pick } from 'lodash'
|
||||
import type { ReturnModelType } from '@typegoose/typegoose'
|
||||
import type { AnyParamConstructor } from '@typegoose/typegoose/lib/types'
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
import type { RSSProps } from './aggregate.interface'
|
||||
|
||||
import { forwardRef, Inject, Injectable } from '@nestjs/common'
|
||||
import { OnEvent } from '@nestjs/event-emitter'
|
||||
|
||||
import type { ReturnModelType } from '@typegoose/typegoose'
|
||||
import type { AnyParamConstructor } from '@typegoose/typegoose/lib/types'
|
||||
import {
|
||||
API_CACHE_PREFIX,
|
||||
CacheKeys,
|
||||
@@ -21,7 +15,9 @@ import { RedisService } from '~/processors/redis/redis.service'
|
||||
import { addYearCondition } from '~/transformers/db-query.transformer'
|
||||
import { getRedisKey } from '~/utils/redis.util'
|
||||
import { getShortDate } from '~/utils/time.util'
|
||||
|
||||
import { pick } from 'lodash'
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
import { CategoryService } from '../category/category.service'
|
||||
import { CommentState } from '../comment/comment.model'
|
||||
import { CommentService } from '../comment/comment.service'
|
||||
@@ -35,6 +31,7 @@ import { RecentlyService } from '../recently/recently.service'
|
||||
import { SayService } from '../say/say.service'
|
||||
import { UserService } from '../user/user.service'
|
||||
import { ReadAndLikeCountDocumentType, TimelineType } from './aggregate.dto'
|
||||
import type { RSSProps } from './aggregate.interface'
|
||||
|
||||
@Injectable()
|
||||
export class AggregateService {
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { Readable } from 'node:stream'
|
||||
import { FastifyReply } from 'fastify'
|
||||
|
||||
import { Body, Get, Post, Res } from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { BizException } from '~/common/exceptions/biz.exception'
|
||||
import { ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
|
||||
import { FastifyReply } from 'fastify'
|
||||
import { ConfigsService } from '../../configs/configs.service'
|
||||
import { ChatRequestDto, ChatResponseDto } from './ai-agent.dto'
|
||||
import { AIAgentService } from './ai-agent.service'
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { generateText, streamText, tool } from 'ai'
|
||||
|
||||
import { z } from '@mx-space/compiled/zod'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { generateText, streamText, tool } from 'ai'
|
||||
import { McpService } from '../../mcp/mcp.service'
|
||||
import { AI_PROMPTS } from '../ai.prompts'
|
||||
import { AiService } from '../ai.service'
|
||||
@@ -14,17 +12,17 @@ export class AIAgentService {
|
||||
private readonly mcpService: McpService,
|
||||
) {}
|
||||
|
||||
// 使用Vercel AI SDK的工具与MCP数据交互(流式响应)
|
||||
// 使用 Vercel AI SDK 的工具与 MCP 数据交互(流式响应)
|
||||
async chatWithTools(userPrompt: string) {
|
||||
// 获取OpenAI模型
|
||||
// 获取 OpenAI 模型
|
||||
const model = await this.aiService.getOpenAiModel()
|
||||
|
||||
// 定义工具(与runWithTools相同)
|
||||
// 定义工具(与 runWithTools 相同)
|
||||
const tools = {
|
||||
get_post_by_id: tool({
|
||||
description: '根据ID获取博客文章',
|
||||
description: '根据 ID 获取博客文章',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('帖子的ID'),
|
||||
id: z.string().describe('帖子的 ID'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -38,12 +36,12 @@ export class AIAgentService {
|
||||
get_posts: tool({
|
||||
description: '获取博客文章列表',
|
||||
parameters: z.object({
|
||||
page: z.number().optional().default(1).describe('页码,默认为1'),
|
||||
page: z.number().optional().default(1).describe('页码,默认为 1'),
|
||||
size: z
|
||||
.number()
|
||||
.optional()
|
||||
.default(10)
|
||||
.describe('每页数量,默认为10'),
|
||||
.describe('每页数量,默认为 10'),
|
||||
}),
|
||||
execute: async ({ page, size }) => {
|
||||
try {
|
||||
@@ -55,9 +53,9 @@ export class AIAgentService {
|
||||
},
|
||||
}),
|
||||
get_note_by_id: tool({
|
||||
description: '根据ID获取笔记',
|
||||
description: '根据 ID 获取笔记',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('笔记的ID或nid'),
|
||||
id: z.string().describe('笔记的 ID 或 nid'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -71,12 +69,12 @@ export class AIAgentService {
|
||||
get_notes: tool({
|
||||
description: '获取笔记列表',
|
||||
parameters: z.object({
|
||||
page: z.number().optional().default(1).describe('页码,默认为1'),
|
||||
page: z.number().optional().default(1).describe('页码,默认为 1'),
|
||||
size: z
|
||||
.number()
|
||||
.optional()
|
||||
.default(10)
|
||||
.describe('每页数量,默认为10'),
|
||||
.describe('每页数量,默认为 10'),
|
||||
}),
|
||||
execute: async ({ page, size }) => {
|
||||
try {
|
||||
@@ -112,9 +110,9 @@ export class AIAgentService {
|
||||
},
|
||||
}),
|
||||
get_category_by_id: tool({
|
||||
description: '根据ID获取分类',
|
||||
description: '根据 ID 获取分类',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('分类的ID'),
|
||||
id: z.string().describe('分类的 ID'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -140,7 +138,7 @@ export class AIAgentService {
|
||||
get_posts_by_category: tool({
|
||||
description: '获取指定分类下的所有文章',
|
||||
parameters: z.object({
|
||||
categoryId: z.string().describe('分类的ID'),
|
||||
categoryId: z.string().describe('分类的 ID'),
|
||||
}),
|
||||
execute: async ({ categoryId }) => {
|
||||
try {
|
||||
@@ -178,9 +176,9 @@ export class AIAgentService {
|
||||
},
|
||||
}),
|
||||
get_page_by_id: tool({
|
||||
description: '根据ID获取页面',
|
||||
description: '根据 ID 获取页面',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('页面的ID'),
|
||||
id: z.string().describe('页面的 ID'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -240,9 +238,9 @@ export class AIAgentService {
|
||||
},
|
||||
}),
|
||||
get_recently_by_id: tool({
|
||||
description: '根据ID获取特定动态/活动',
|
||||
description: '根据 ID 获取特定动态/活动',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('动态的ID'),
|
||||
id: z.string().describe('动态的 ID'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -268,9 +266,9 @@ export class AIAgentService {
|
||||
get_recently_offset: tool({
|
||||
description: '获取指定范围的动态/活动',
|
||||
parameters: z.object({
|
||||
size: z.number().optional().default(10).describe('数量,默认为10'),
|
||||
before: z.string().optional().describe('获取此ID之前的动态'),
|
||||
after: z.string().optional().describe('获取此ID之后的动态'),
|
||||
size: z.number().optional().default(10).describe('数量,默认为 10'),
|
||||
before: z.string().optional().describe('获取此 ID 之前的动态'),
|
||||
after: z.string().optional().describe('获取此 ID 之后的动态'),
|
||||
}),
|
||||
execute: async ({ size, before, after }) => {
|
||||
try {
|
||||
@@ -288,17 +286,17 @@ export class AIAgentService {
|
||||
get_comments: tool({
|
||||
description: '获取所有评论,可按状态筛选',
|
||||
parameters: z.object({
|
||||
page: z.number().optional().default(1).describe('页码,默认为1'),
|
||||
page: z.number().optional().default(1).describe('页码,默认为 1'),
|
||||
size: z
|
||||
.number()
|
||||
.optional()
|
||||
.default(10)
|
||||
.describe('每页数量,默认为10'),
|
||||
.describe('每页数量,默认为 10'),
|
||||
state: z
|
||||
.number()
|
||||
.optional()
|
||||
.default(0)
|
||||
.describe('评论状态筛选,0表示所有'),
|
||||
.describe('评论状态筛选,0 表示所有'),
|
||||
}),
|
||||
execute: async ({ page, size, state }) => {
|
||||
try {
|
||||
@@ -316,11 +314,11 @@ export class AIAgentService {
|
||||
get_content_comments: tool({
|
||||
description: '获取特定内容的评论',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('内容的ID'),
|
||||
id: z.string().describe('内容的 ID'),
|
||||
type: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('内容类型,如post, note, page等'),
|
||||
.describe('内容类型,如 post, note, page 等'),
|
||||
}),
|
||||
execute: async ({ id, type }) => {
|
||||
try {
|
||||
@@ -333,7 +331,7 @@ export class AIAgentService {
|
||||
}),
|
||||
}
|
||||
|
||||
// 使用streamText进行流式响应
|
||||
// 使用 streamText 进行流式响应
|
||||
const result = await streamText({
|
||||
model,
|
||||
tools,
|
||||
@@ -347,15 +345,15 @@ export class AIAgentService {
|
||||
|
||||
// 保留原有的非流式方法以备后用
|
||||
async runWithTools(userPrompt: string) {
|
||||
// 获取OpenAI模型
|
||||
// 获取 OpenAI 模型
|
||||
const model = await this.aiService.getOpenAiModel()
|
||||
|
||||
// 定义工具
|
||||
const tools = {
|
||||
get_post_by_id: tool({
|
||||
description: '根据ID获取博客文章',
|
||||
description: '根据 ID 获取博客文章',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('帖子的ID'),
|
||||
id: z.string().describe('帖子的 ID'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -369,12 +367,12 @@ export class AIAgentService {
|
||||
get_posts: tool({
|
||||
description: '获取博客文章列表',
|
||||
parameters: z.object({
|
||||
page: z.number().optional().default(1).describe('页码,默认为1'),
|
||||
page: z.number().optional().default(1).describe('页码,默认为 1'),
|
||||
size: z
|
||||
.number()
|
||||
.optional()
|
||||
.default(10)
|
||||
.describe('每页数量,默认为10'),
|
||||
.describe('每页数量,默认为 10'),
|
||||
}),
|
||||
execute: async ({ page, size }) => {
|
||||
try {
|
||||
@@ -386,9 +384,9 @@ export class AIAgentService {
|
||||
},
|
||||
}),
|
||||
get_note_by_id: tool({
|
||||
description: '根据ID获取笔记',
|
||||
description: '根据 ID 获取笔记',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('笔记的ID或nid'),
|
||||
id: z.string().describe('笔记的 ID 或 nid'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -402,12 +400,12 @@ export class AIAgentService {
|
||||
get_notes: tool({
|
||||
description: '获取笔记列表',
|
||||
parameters: z.object({
|
||||
page: z.number().optional().default(1).describe('页码,默认为1'),
|
||||
page: z.number().optional().default(1).describe('页码,默认为 1'),
|
||||
size: z
|
||||
.number()
|
||||
.optional()
|
||||
.default(10)
|
||||
.describe('每页数量,默认为10'),
|
||||
.describe('每页数量,默认为 10'),
|
||||
}),
|
||||
execute: async ({ page, size }) => {
|
||||
try {
|
||||
@@ -443,9 +441,9 @@ export class AIAgentService {
|
||||
},
|
||||
}),
|
||||
get_category_by_id: tool({
|
||||
description: '根据ID获取分类',
|
||||
description: '根据 ID 获取分类',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('分类的ID'),
|
||||
id: z.string().describe('分类的 ID'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -471,7 +469,7 @@ export class AIAgentService {
|
||||
get_posts_by_category: tool({
|
||||
description: '获取指定分类下的所有文章',
|
||||
parameters: z.object({
|
||||
categoryId: z.string().describe('分类的ID'),
|
||||
categoryId: z.string().describe('分类的 ID'),
|
||||
}),
|
||||
execute: async ({ categoryId }) => {
|
||||
try {
|
||||
@@ -509,9 +507,9 @@ export class AIAgentService {
|
||||
},
|
||||
}),
|
||||
get_page_by_id: tool({
|
||||
description: '根据ID获取页面',
|
||||
description: '根据 ID 获取页面',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('页面的ID'),
|
||||
id: z.string().describe('页面的 ID'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -571,9 +569,9 @@ export class AIAgentService {
|
||||
},
|
||||
}),
|
||||
get_recently_by_id: tool({
|
||||
description: '根据ID获取特定动态/活动',
|
||||
description: '根据 ID 获取特定动态/活动',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('动态的ID'),
|
||||
id: z.string().describe('动态的 ID'),
|
||||
}),
|
||||
execute: async ({ id }) => {
|
||||
try {
|
||||
@@ -599,9 +597,9 @@ export class AIAgentService {
|
||||
get_recently_offset: tool({
|
||||
description: '获取指定范围的动态/活动',
|
||||
parameters: z.object({
|
||||
size: z.number().optional().default(10).describe('数量,默认为10'),
|
||||
before: z.string().optional().describe('获取此ID之前的动态'),
|
||||
after: z.string().optional().describe('获取此ID之后的动态'),
|
||||
size: z.number().optional().default(10).describe('数量,默认为 10'),
|
||||
before: z.string().optional().describe('获取此 ID 之前的动态'),
|
||||
after: z.string().optional().describe('获取此 ID 之后的动态'),
|
||||
}),
|
||||
execute: async ({ size, before, after }) => {
|
||||
try {
|
||||
@@ -619,17 +617,17 @@ export class AIAgentService {
|
||||
get_comments: tool({
|
||||
description: '获取所有评论,可按状态筛选',
|
||||
parameters: z.object({
|
||||
page: z.number().optional().default(1).describe('页码,默认为1'),
|
||||
page: z.number().optional().default(1).describe('页码,默认为 1'),
|
||||
size: z
|
||||
.number()
|
||||
.optional()
|
||||
.default(10)
|
||||
.describe('每页数量,默认为10'),
|
||||
.describe('每页数量,默认为 10'),
|
||||
state: z
|
||||
.number()
|
||||
.optional()
|
||||
.default(0)
|
||||
.describe('评论状态筛选,0表示所有'),
|
||||
.describe('评论状态筛选,0 表示所有'),
|
||||
}),
|
||||
execute: async ({ page, size, state }) => {
|
||||
try {
|
||||
@@ -647,11 +645,11 @@ export class AIAgentService {
|
||||
get_content_comments: tool({
|
||||
description: '获取特定内容的评论',
|
||||
parameters: z.object({
|
||||
id: z.string().describe('内容的ID'),
|
||||
id: z.string().describe('内容的 ID'),
|
||||
type: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe('内容类型,如post, note, page等'),
|
||||
.describe('内容类型,如 post, note, page 等'),
|
||||
}),
|
||||
execute: async ({ id, type }) => {
|
||||
try {
|
||||
@@ -664,7 +662,7 @@ export class AIAgentService {
|
||||
}),
|
||||
}
|
||||
|
||||
// 执行AI调用
|
||||
// 执行 AI 调用
|
||||
const result = await generateText({
|
||||
model,
|
||||
tools,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Delete, Get, Param, Post, Query } from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { BizException } from '~/common/exceptions/biz.exception'
|
||||
import { ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
import { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
import { ConfigsService } from '../../configs/configs.service'
|
||||
import { GetDeepReadingQueryDto } from './ai-deep-reading.dto'
|
||||
import { AiDeepReadingService } from './ai-deep-reading.service'
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
import { TransformBoolean } from '~/common/decorators/transform-boolean.decorator'
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
class BaseLangQueryDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
import { modelOptions, prop } from '@typegoose/typegoose'
|
||||
|
||||
import { AI_DEEP_READING_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
@modelOptions({
|
||||
options: {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import { generateText, tool } from 'ai'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
import { z } from '@mx-space/compiled/zod'
|
||||
import { Injectable, Logger } from '@nestjs/common'
|
||||
import { OnEvent } from '@nestjs/event-emitter'
|
||||
|
||||
import { BizException } from '~/common/exceptions/biz.exception'
|
||||
import { CollectionRefTypes } from '~/constants/db.constant'
|
||||
import { ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
import { DatabaseService } from '~/processors/database/database.service'
|
||||
import { RedisService } from '~/processors/redis/redis.service'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
import { InjectModel } from '~/transformers/model.transformer'
|
||||
import { md5 } from '~/utils/tool.util'
|
||||
|
||||
import { generateText, tool } from 'ai'
|
||||
import { ConfigsService } from '../../configs/configs.service'
|
||||
import { AI_PROMPTS } from '../ai.prompts'
|
||||
import { AiService } from '../ai.service'
|
||||
@@ -99,7 +96,7 @@ export class AiDeepReadingService {
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用Vercel AI SDK执行多步骤工具调用
|
||||
// 使用 Vercel AI SDK 执行多步骤工具调用
|
||||
await generateText({
|
||||
model,
|
||||
tools,
|
||||
@@ -171,7 +168,7 @@ export class AiDeepReadingService {
|
||||
id: string,
|
||||
text: string,
|
||||
) {
|
||||
// 处理时间增加到5分钟
|
||||
// 处理时间增加到 5 分钟
|
||||
await redis.set(taskId, 'processing', 'EX', 300)
|
||||
|
||||
const result = await this.deepReadingAgentChain(id)
|
||||
@@ -200,7 +197,7 @@ export class AiDeepReadingService {
|
||||
)
|
||||
throw new BizException(
|
||||
ErrorCodeEnum.AIException,
|
||||
'AI处理迭代次数超过限制',
|
||||
'AI 处理迭代次数超过限制',
|
||||
error.stack,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
Query,
|
||||
Req,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { BizException } from '~/common/exceptions/biz.exception'
|
||||
@@ -16,7 +15,6 @@ import { ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
import { PagerDto } from '~/shared/dto/pager.dto'
|
||||
import { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
import { ConfigsService } from '../../configs/configs.service'
|
||||
import { DEFAULT_SUMMARY_LANG } from '../ai.constants'
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
import { TransformBoolean } from '~/common/decorators/transform-boolean.decorator'
|
||||
import { IsBoolean, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
class BaseLangQueryDto {
|
||||
@IsString()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { modelOptions, prop } from '@typegoose/typegoose'
|
||||
|
||||
import { AI_SUMMARY_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
import { generateObject } from 'ai'
|
||||
import removeMdCodeblock from 'remove-md-codeblock'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
import { z } from '@mx-space/compiled/zod'
|
||||
import { Injectable, Logger } from '@nestjs/common'
|
||||
import { OnEvent } from '@nestjs/event-emitter'
|
||||
|
||||
import { BizException } from '~/common/exceptions/biz.exception'
|
||||
import { BusinessEvents } from '~/constants/business-event.constant'
|
||||
import { CollectionRefTypes } from '~/constants/db.constant'
|
||||
import { ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
import { DatabaseService } from '~/processors/database/database.service'
|
||||
import { RedisService } from '~/processors/redis/redis.service'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
import { InjectModel } from '~/transformers/model.transformer'
|
||||
import { transformDataToPaginate } from '~/transformers/paginate.transformer'
|
||||
import { md5 } from '~/utils/tool.util'
|
||||
|
||||
import { generateObject } from 'ai'
|
||||
import removeMdCodeblock from 'remove-md-codeblock'
|
||||
import { ConfigsService } from '../../configs/configs.service'
|
||||
import { DEFAULT_SUMMARY_LANG } from '../ai.constants'
|
||||
import { AI_PROMPTS } from '../ai.prompts'
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Body, Post } from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
|
||||
import { AiQueryType, GenerateAiDto } from './ai-writer.dto'
|
||||
import { AiWriterService } from './ai-writer.service'
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { generateObject } from 'ai'
|
||||
|
||||
import { z } from '@mx-space/compiled/zod'
|
||||
import { Injectable, Logger } from '@nestjs/common'
|
||||
|
||||
import { generateObject } from 'ai'
|
||||
import { AI_PROMPTS } from '../ai.prompts'
|
||||
import { AiService } from '../ai.service'
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { McpModule } from '../mcp/mcp.module'
|
||||
import { AIAgentController } from './ai-agent/ai-agent.controller'
|
||||
import { AIAgentService } from './ai-agent/ai-agent.service'
|
||||
|
||||
@@ -79,28 +79,28 @@ Respond with a JSON object containing the slug field.`,
|
||||
|
||||
// AI Deep Reading Prompts
|
||||
deepReading: {
|
||||
systemPrompt: `你是一个专门进行文章深度阅读的AI助手,需要分析文章并提供详细的解读。
|
||||
systemPrompt: `你是一个专门进行文章深度阅读的 AI 助手,需要分析文章并提供详细的解读。
|
||||
分析过程:
|
||||
1. 首先提取文章关键点,然后使用 save_key_points 保存到数据库
|
||||
2. 然后进行批判性分析,包括文章的优点、缺点和改进建议,然后使用 save_critical_analysis 保存到数据库
|
||||
3. 最后使用 deep_reading 生成完整的深度阅读内容
|
||||
4. 返回完整结果,包括关键点、批判性分析和深度阅读内容`,
|
||||
|
||||
deepReadingSystem: `创建一个全面的深度阅读Markdown文本,保持文章的原始结构但提供扩展的解释和见解。
|
||||
deepReadingSystem: `创建一个全面的深度阅读 Markdown 文本,保持文章的原始结构但提供扩展的解释和见解。
|
||||
内容应该:
|
||||
1. 遵循原文的流程和主要论点
|
||||
2. 包含原文的所有关键技术细节
|
||||
3. 扩展未充分解释的复杂概念
|
||||
4. 在需要的地方提供额外背景和解释
|
||||
5. 保持文章的原始语调和语言风格
|
||||
6. 使用适当的Markdown格式,包括标题、代码块、列表等
|
||||
6. 使用适当的 Markdown 格式,包括标题、代码块、列表等
|
||||
7. 输出的语言必须与原文的语言匹配`,
|
||||
|
||||
getDeepReadingPrompt: (text: string) =>
|
||||
`分析以下文章:${text}\n\n创建一个全面的深度阅读Markdown文本,保持文章的原始结构但提供扩展的解释和见解。`,
|
||||
`分析以下文章:${text}\n\n创建一个全面的深度阅读 Markdown 文本,保持文章的原始结构但提供扩展的解释和见解。`,
|
||||
|
||||
getUserPrompt: (title: string, text: string) =>
|
||||
`文章标题: ${title}\n文章内容: ${text}`,
|
||||
`文章标题:${title}\n文章内容:${text}`,
|
||||
},
|
||||
|
||||
// Comment Review Prompts
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { createOpenAI } from '@ai-sdk/openai'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { BizException } from '~/common/exceptions/biz.exception'
|
||||
import { ErrorCodeEnum } from '~/constants/error-code.constant'
|
||||
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
|
||||
@Injectable()
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import dayjs from 'dayjs'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
import { Delete, Get, HttpCode, Query } from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { Paginator } from '~/common/decorators/http.decorator'
|
||||
import { RedisKeys } from '~/constants/cache.constant'
|
||||
import { RedisService } from '~/processors/redis/redis.service'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
import { getRedisKey } from '~/utils/redis.util'
|
||||
import { getTodayEarly, getWeekStart } from '~/utils/time.util'
|
||||
|
||||
import dayjs from 'dayjs'
|
||||
import { AnalyzeDto } from './analyze.dto'
|
||||
import { AnalyzeService } from './analyze.service'
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { SchemaTypes } from 'mongoose'
|
||||
import { UAParser } from 'ua-parser-js'
|
||||
|
||||
import { index, modelOptions, prop, Severity } from '@typegoose/typegoose'
|
||||
|
||||
import { ANALYZE_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
import { SchemaTypes } from 'mongoose'
|
||||
import { UAParser } from 'ua-parser-js'
|
||||
|
||||
@modelOptions({
|
||||
schemaOptions: {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
|
||||
import { AnalyzeController } from './analyze.controller'
|
||||
import { AnalyzeService } from './analyze.service'
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import dayjs from 'dayjs'
|
||||
import { merge } from 'lodash'
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ReturnModelType } from '@typegoose/typegoose'
|
||||
|
||||
import { RedisKeys } from '~/constants/cache.constant'
|
||||
import { RedisService } from '~/processors/redis/redis.service'
|
||||
import { InjectModel } from '~/transformers/model.transformer'
|
||||
import { getRedisKey } from '~/utils/redis.util'
|
||||
|
||||
import dayjs from 'dayjs'
|
||||
import { merge } from 'lodash'
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
import { OptionModel } from '../configs/configs.model'
|
||||
import { AnalyzeModel } from './analyze.model'
|
||||
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
import { Transform } from 'class-transformer'
|
||||
import {
|
||||
IsDate,
|
||||
isMongoId,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from 'class-validator'
|
||||
import { omit } from 'lodash'
|
||||
|
||||
import {
|
||||
Body,
|
||||
Delete,
|
||||
@@ -20,14 +10,21 @@ import {
|
||||
Req,
|
||||
} from '@nestjs/common'
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { HttpCache } from '~/common/decorators/cache.decorator'
|
||||
import { EventBusEvents } from '~/constants/event-bus.constant'
|
||||
import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
import { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
import { Transform } from 'class-transformer'
|
||||
import {
|
||||
IsDate,
|
||||
isMongoId,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from 'class-validator'
|
||||
import { omit } from 'lodash'
|
||||
import { AuthInstanceInjectKey } from './auth.constant'
|
||||
import { InjectAuthInstance } from './auth.interface'
|
||||
import { AuthService } from './auth.service'
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { IncomingMessage } from 'node:http'
|
||||
import { MongoClient } from 'mongodb'
|
||||
import type { ServerResponse } from 'node:http'
|
||||
import type {
|
||||
BetterAuthOptions,
|
||||
BetterAuthPlugin,
|
||||
} from '@mx-space/compiled/auth'
|
||||
import type { ServerResponse } from 'node:http'
|
||||
|
||||
import {
|
||||
APIError,
|
||||
betterAuth,
|
||||
@@ -13,10 +11,9 @@ import {
|
||||
mongodbAdapter,
|
||||
toNodeHandler,
|
||||
} from '@mx-space/compiled/auth'
|
||||
|
||||
import { API_VERSION, CROSS_DOMAIN, MONGO_DB } from '~/app.config'
|
||||
import { SECURITY } from '~/app.config.test'
|
||||
|
||||
import { MongoClient } from 'mongodb'
|
||||
import {
|
||||
AUTH_JS_ACCOUNT_COLLECTION,
|
||||
AUTH_JS_SESSION_COLLECTION,
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http'
|
||||
import type { BetterAuthOptions } from '@mx-space/compiled/auth'
|
||||
import type { NestMiddleware, OnModuleInit } from '@nestjs/common'
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http'
|
||||
|
||||
import { Inject } from '@nestjs/common'
|
||||
|
||||
import { EventBusEvents } from '~/constants/event-bus.constant'
|
||||
import { SubPubBridgeService } from '~/processors/redis/subpub.service'
|
||||
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import { AuthInstanceInjectKey } from './auth.constant'
|
||||
import { CreateAuth } from './auth.implement'
|
||||
|
||||
@@ -4,12 +4,10 @@ import type {
|
||||
NestModule,
|
||||
Provider,
|
||||
} from '@nestjs/common'
|
||||
import type { AuthInstance } from './auth.interface'
|
||||
|
||||
import { API_VERSION } from '~/app.config'
|
||||
|
||||
import { AuthInstanceInjectKey } from './auth.constant'
|
||||
import { AuthController } from './auth.controller'
|
||||
import type { AuthInstance } from './auth.interface'
|
||||
import { AuthMiddleware } from './auth.middleware'
|
||||
import { AuthService } from './auth.service'
|
||||
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import { IncomingMessage } from 'node:http'
|
||||
import dayjs from 'dayjs'
|
||||
import { isDate, omit } from 'lodash'
|
||||
import { Types } from 'mongoose'
|
||||
import type { TokenModel, UserModel } from '~/modules/user/user.model'
|
||||
import type { TokenDto } from './auth.controller'
|
||||
|
||||
import { nanoid } from '@mx-space/compiled'
|
||||
import {
|
||||
BadRequestException,
|
||||
@@ -13,19 +7,22 @@ import {
|
||||
InternalServerErrorException,
|
||||
} from '@nestjs/common'
|
||||
import { ReturnModelType } from '@typegoose/typegoose'
|
||||
|
||||
import { RequestContext } from '~/common/contexts/request.context'
|
||||
import { alphabet } from '~/constants/other.constant'
|
||||
import type { TokenModel, UserModel } from '~/modules/user/user.model'
|
||||
import { UserModel as User } from '~/modules/user/user.model'
|
||||
import { DatabaseService } from '~/processors/database/database.service'
|
||||
import { JWTService } from '~/processors/helper/helper.jwt.service'
|
||||
import { InjectModel } from '~/transformers/model.transformer'
|
||||
|
||||
import dayjs from 'dayjs'
|
||||
import { isDate, omit } from 'lodash'
|
||||
import { Types } from 'mongoose'
|
||||
import {
|
||||
AUTH_JS_ACCOUNT_COLLECTION,
|
||||
AUTH_JS_USER_COLLECTION,
|
||||
AuthInstanceInjectKey,
|
||||
} from './auth.constant'
|
||||
import type { TokenDto } from './auth.controller'
|
||||
import { InjectAuthInstance } from './auth.interface'
|
||||
|
||||
const { customAlphabet } = nanoid
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Global, Module } from '@nestjs/common'
|
||||
|
||||
import { AuthnController } from '../authn/authn.controller'
|
||||
import { AuthnService } from './authn.service'
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Body, Delete, Get, Param, Post } from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
import { Auth } from '~/common/decorators/auth.decorator'
|
||||
import { CurrentUser } from '~/common/decorators/current-user.decorator'
|
||||
import { HTTPDecorators } from '~/common/decorators/http.decorator'
|
||||
import { IpLocation, IpRecord } from '~/common/decorators/ip.decorator'
|
||||
import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
|
||||
import { AuthService } from '../auth/auth.service'
|
||||
import { UserDocument } from '../user/user.model'
|
||||
import { UserService } from '../user/user.service'
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { mongooseLeanGetters } from 'mongoose-lean-getters'
|
||||
|
||||
import { modelOptions, plugin, prop } from '@typegoose/typegoose'
|
||||
import { mongooseLeanGetters } from 'mongoose-lean-getters'
|
||||
|
||||
type CredentialDeviceType = 'singleDevice' | 'multiDevice'
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user