@@ -3,7 +3,7 @@ import { factory } from '@innei/prettier'
|
||||
export default {
|
||||
...factory({
|
||||
tailwindcss: false,
|
||||
importSort: false,
|
||||
importSort: true,
|
||||
}),
|
||||
importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
"dev": "npm run start",
|
||||
"repl": "npm run start -- --entryFile repl",
|
||||
"bundle": "rimraf out && npm run build && cd dist/src && npx ncc build main.js -o ../../out --minify -s && cd ../.. && chmod +x out/index.js && node scripts/after-bundle.js",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"packages/**/*.ts\"",
|
||||
"start": "cross-env NODE_ENV=development nest start -w --path tsconfig.json -- ",
|
||||
"start:debug": "cross-env NODE_ENV=development nest start --debug --watch",
|
||||
"start:cluster": "cross-env NODE_ENV=development nest start --watch -- --cluster --cluster_workers 2",
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { seconds } from '@nestjs/throttler'
|
||||
import { program } from 'commander'
|
||||
import { load as yamlLoad } from 'js-yaml'
|
||||
|
||||
import { machineIdSync } from 'node-machine-id'
|
||||
import { isDebugMode, isDev } from './global/env.global'
|
||||
|
||||
import { parseBooleanishValue } from './utils/tool.util'
|
||||
import type { AxiosRequestConfig } from 'axios'
|
||||
|
||||
import { seconds } from '@nestjs/throttler'
|
||||
|
||||
import { isDebugMode, isDev } from './global/env.global'
|
||||
import { parseBooleanishValue } from './utils/tool.util'
|
||||
|
||||
const { PORT: ENV_PORT, ALLOWED_ORIGINS, MX_ENCRYPT_KEY } = process.env
|
||||
|
||||
const commander = program
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
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'
|
||||
|
||||
@@ -60,12 +66,6 @@ import { DatabaseModule } from './processors/database/database.module'
|
||||
import { GatewayModule } from './processors/gateway/gateway.module'
|
||||
import { HelperModule } from './processors/helper/helper.module'
|
||||
import { RedisModule } from './processors/redis/redis.module'
|
||||
import type {
|
||||
DynamicModule,
|
||||
MiddlewareConsumer,
|
||||
NestModule,
|
||||
Type,
|
||||
} from '@nestjs/common'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import cluster from 'node:cluster'
|
||||
import { performance } from 'node:perf_hooks'
|
||||
import wcmatch from 'wildcard-match'
|
||||
import type { LogLevel } from '@nestjs/common'
|
||||
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
|
||||
|
||||
import { Logger } from '@innei/pretty-logger-nestjs'
|
||||
import { NestFactory } from '@nestjs/core'
|
||||
|
||||
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'
|
||||
@@ -15,8 +17,6 @@ import { ExtendedValidationPipe } from './common/pipes/validation.pipe'
|
||||
import { logger } from './global/consola.global'
|
||||
import { isMainProcess, isTest } from './global/env.global'
|
||||
import { checkInit } from './utils/check-init.util'
|
||||
import type { LogLevel } from '@nestjs/common'
|
||||
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
|
||||
|
||||
const Origin: false | string[] = Array.isArray(CROSS_DOMAIN.allowedOrigins)
|
||||
? [...CROSS_DOMAIN.allowedOrigins, '*.shizuri.net', '22333322.xyz']
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
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'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
const app: FastifyAdapter = new FastifyAdapter({
|
||||
trustProxy: true,
|
||||
@@ -38,7 +39,7 @@ app.getInstance().addHook('onRequest', (request, reply, done) => {
|
||||
logWarn('PHP 是世界上最好的语言!!!!!', request, 'GodPHP')
|
||||
|
||||
return reply.code(418).send()
|
||||
} else if (/\/(adminer|admin|wp-login|phpmyadmin|\.env)$/gi.test(url)) {
|
||||
} else if (/\/(?:adminer|admin|wp-login|phpmyadmin|\.env)$/i.test(url)) {
|
||||
const isMxSpaceClient = ua?.match('mx-space')
|
||||
reply.raw.statusMessage = 'Hey, What the fuck are you doing!'
|
||||
reply.raw.statusCode = isMxSpaceClient ? 666 : 200
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
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,10 +1,11 @@
|
||||
/* 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 { UnauthorizedException } from '@nestjs/common'
|
||||
import type { UserDocument } from '~/modules/user/user.model'
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http'
|
||||
|
||||
import { UnauthorizedException } from '@nestjs/common'
|
||||
|
||||
type Nullable<T> = T | null
|
||||
export class RequestContext {
|
||||
readonly id: number
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { ControllerOptions } from '@nestjs/common'
|
||||
|
||||
import { Controller } from '@nestjs/common'
|
||||
|
||||
import { API_VERSION } from '~/app.config'
|
||||
import { isDev } from '~/global/env.global'
|
||||
import type { ControllerOptions } from '@nestjs/common'
|
||||
|
||||
export const apiRoutePrefix = isDev ? '' : `/api/v${API_VERSION}`
|
||||
export const ApiController: (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UseGuards, applyDecorators } from '@nestjs/common'
|
||||
import { applyDecorators, UseGuards } from '@nestjs/common'
|
||||
|
||||
import { AuthGuard } from '../guards/auth.guard'
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
|
||||
export const Cookies = createParamDecorator(
|
||||
(data: string, ctx: ExecutionContext) => {
|
||||
const request = ctx.switchToHttp().getRequest<FastifyRequest>()
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
|
||||
export const CurrentUser = createParamDecorator(
|
||||
(data: unknown, ctx: ExecutionContext) => {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { UseGuards, applyDecorators } from '@nestjs/common'
|
||||
import { banInDemo } from '~/utils'
|
||||
import type { CanActivate } from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { applyDecorators, UseGuards } from '@nestjs/common'
|
||||
|
||||
import { banInDemo } from '~/utils'
|
||||
|
||||
class DemoGuard implements CanActivate {
|
||||
canActivate(): boolean | Promise<boolean> | Observable<boolean> {
|
||||
banInDemo()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { IdempotenceOption } from '../interceptors/idempotence.interceptor'
|
||||
|
||||
import { SetMetadata } from '@nestjs/common'
|
||||
|
||||
import {
|
||||
@@ -5,7 +7,6 @@ import {
|
||||
HTTP_RES_TRANSFORM_PAGINATE,
|
||||
} from '~/constants/meta.constant'
|
||||
import * as SYSTEM from '~/constants/system.constant'
|
||||
import type { IdempotenceOption } from '../interceptors/idempotence.interceptor'
|
||||
|
||||
/**
|
||||
* @description 分页转换
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
* @FilePath: /mx-server/src/core/decorators/ip.decorator.ts
|
||||
* @Coding with Love
|
||||
*/
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
import { getIp } from '~/utils/ip.util'
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
|
||||
import { getIp } from '~/utils/ip.util'
|
||||
|
||||
export type IpRecord = {
|
||||
ip: string
|
||||
agent: string
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
|
||||
import { createParamDecorator } from '@nestjs/common'
|
||||
|
||||
import { isTest } from '~/global/env.global'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
|
||||
export const IsGuest = createParamDecorator(
|
||||
(data: unknown, ctx: ExecutionContext) => {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
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 {
|
||||
Catch,
|
||||
@@ -21,9 +24,6 @@ import { EventManagerService } from '~/processors/helper/helper.event.service'
|
||||
import { getIp } from '../../utils/ip.util'
|
||||
import { BizException } from '../exceptions/biz.exception'
|
||||
import { LoggingInterceptor } from '../interceptors/logging.interceptor'
|
||||
import type { WriteStream } from 'node:fs'
|
||||
import type { FastifyReply, FastifyRequest } from 'fastify'
|
||||
import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'
|
||||
|
||||
type myError = {
|
||||
readonly status: number
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
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'
|
||||
|
||||
@@ -6,9 +9,6 @@ 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 type { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
import type { UserModel } from '~/modules/user/user.model'
|
||||
import type { CanActivate, ExecutionContext } from '@nestjs/common'
|
||||
|
||||
/**
|
||||
* JWT auth guard
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { CanActivate, ExecutionContext } from '@nestjs/common'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { AuthService } from '~/modules/auth/auth.service'
|
||||
@@ -6,7 +8,6 @@ import { UserService } from '~/modules/user/user.service'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
import { AuthGuard } from './auth.guard'
|
||||
import type { CanActivate, ExecutionContext } from '@nestjs/common'
|
||||
|
||||
/**
|
||||
* 区分游客和主人的守卫
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
* @author Innei <https://innei.in>
|
||||
*/
|
||||
|
||||
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'
|
||||
import type { CanActivate, ExecutionContext } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class SpiderGuard implements CanActivate {
|
||||
@@ -24,8 +25,8 @@ export class SpiderGuard implements CanActivate {
|
||||
const headers = request.headers
|
||||
const ua: string = headers['user-agent'] || ''
|
||||
const isSpiderUA =
|
||||
!!/(scrapy|httpclient|axios|python|requests)/i.test(ua) &&
|
||||
!/(mx-space|rss|google|baidu|bing)/gi.test(ua)
|
||||
!!/scrapy|httpclient|axios|python|requests/i.test(ua) &&
|
||||
!/mx-space|rss|google|baidu|bing/i.test(ua)
|
||||
if (ua && !isSpiderUA) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
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 { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import { getIp } from '~/utils'
|
||||
import type { FastifyBizRequest } from '~/transformers/get-req.transformer'
|
||||
import type { ExecutionContext } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class ExtendThrottlerGuard extends ThrottlerGuard {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { RequestMethod } from '@nestjs/common'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
@@ -6,6 +5,8 @@ import type {
|
||||
} from '@nestjs/common'
|
||||
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()
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
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'
|
||||
@@ -23,12 +29,6 @@ import { InjectModel } from '~/transformers/model.transformer'
|
||||
import { scheduleManager } from '~/utils'
|
||||
import { getIp } from '~/utils/ip.util'
|
||||
import { getRedisKey } from '~/utils/redis.util'
|
||||
import type { Observable } from 'rxjs'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class AnalyzeInterceptor implements NestInterceptor {
|
||||
|
||||
@@ -6,6 +6,13 @@
|
||||
* @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'
|
||||
@@ -17,13 +24,6 @@ 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'
|
||||
import type { Observable } from 'rxjs'
|
||||
import type { FastifyReply } from 'fastify'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
|
||||
/**
|
||||
* @class HttpCacheInterceptor
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import qs from 'qs'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
@@ -8,6 +6,10 @@ import type {
|
||||
} from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
/** 此拦截器用于转换 req.query.query -> js object,用于直接数据库查询,需要鉴权 */
|
||||
@Injectable()
|
||||
export class DbQueryInterceptor implements NestInterceptor {
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { catchError, tap } from 'rxjs'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
|
||||
import {
|
||||
ConflictException,
|
||||
@@ -15,12 +21,6 @@ import {
|
||||
import { REFLECTOR } from '~/constants/system.constant'
|
||||
import { CacheService } from '~/processors/redis/cache.service'
|
||||
import { getIp, getRedisKey, hashString } from '~/utils'
|
||||
import type { FastifyRequest } from 'fastify'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
|
||||
const IdempotenceHeaderKey = 'x-idempotence'
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
import { isObjectLike } from 'lodash'
|
||||
import { map } from 'rxjs'
|
||||
import snakecaseKeys from 'snakecase-keys'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { Reflector } from '@nestjs/core'
|
||||
|
||||
import { RESPONSE_PASSTHROUGH_METADATA } from '~/constants/system.constant'
|
||||
import type { Observable } from 'rxjs'
|
||||
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'
|
||||
|
||||
@Injectable()
|
||||
export class JSONTransformInterceptor implements NestInterceptor {
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
* @author Innei <https://github.com/Innei>
|
||||
*/
|
||||
import { tap } from 'rxjs/operators'
|
||||
|
||||
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 type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { Injectable, Logger, SetMetadata } from '@nestjs/common'
|
||||
|
||||
import { HTTP_REQUEST_TIME } from '~/constants/meta.constant'
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
|
||||
@Injectable()
|
||||
export class LoggingInterceptor implements NestInterceptor {
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
*/
|
||||
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'
|
||||
@@ -11,12 +17,6 @@ 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 type { Observable } from 'rxjs'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
|
||||
export interface Response<T> {
|
||||
data: T
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
// https://github.dev/ever-co/ever-gauzy/packages/core/src/core/context/request-context.middleware.ts
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import * as cls from 'cls-hooked'
|
||||
import { RequestContext } from '../contexts/request.context'
|
||||
import type { NestMiddleware } from '@nestjs/common'
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { RequestContext } from '../contexts/request.context'
|
||||
|
||||
@Injectable()
|
||||
export class RequestContextMiddleware implements NestMiddleware {
|
||||
use(req: IncomingMessage, res: ServerResponse, next: () => any) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { ValidationPipeOptions } from '@nestjs/common'
|
||||
|
||||
import { Injectable, ValidationPipe } from '@nestjs/common'
|
||||
|
||||
import { isDev } from '~/global/env.global'
|
||||
import type { ValidationPipeOptions } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class ExtendedValidationPipe extends ValidationPipe {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { isURL } from 'class-validator'
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
import type { ValidationOptions } from 'class-validator'
|
||||
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
|
||||
export const IsAllowedUrl = (validationOptions?: ValidationOptions) => {
|
||||
return validatorFactory((val) =>
|
||||
isURL(val, { require_protocol: true, require_tld: false }),
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { isString } from 'class-validator'
|
||||
import { isBoolean, merge } from 'lodash'
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
import type { ValidationOptions } from 'class-validator'
|
||||
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
|
||||
export function IsBooleanOrString(validationOptions?: ValidationOptions) {
|
||||
return validatorFactory((value) => isBoolean(value) || isString(value))(
|
||||
merge<ValidationOptions, ValidationOptions>(validationOptions || {}, {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { isInt, isMongoId } from 'class-validator'
|
||||
import { merge } from 'lodash'
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
import type { ValidationOptions } from 'class-validator'
|
||||
|
||||
import { validatorFactory } from '../simpleValidatorFactory'
|
||||
|
||||
export function IsBooleanOrString(validationOptions?: ValidationOptions) {
|
||||
return validatorFactory((value) => isInt(value) || isMongoId(value))(
|
||||
merge<ValidationOptions, ValidationOptions>(validationOptions || {}, {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
ValidatorConstraint,
|
||||
isString,
|
||||
registerDecorator,
|
||||
ValidatorConstraint,
|
||||
} from 'class-validator'
|
||||
import { isNil } from 'lodash'
|
||||
import type {
|
||||
@@ -18,7 +18,7 @@ class IsNilOrStringConstraint implements ValidatorConstraintInterface {
|
||||
}
|
||||
|
||||
export function IsNilOrString(validationOptions?: ValidationOptions) {
|
||||
return function (object: Object, propertyName: string) {
|
||||
return function (object: object, propertyName: string) {
|
||||
registerDecorator({
|
||||
target: object.constructor,
|
||||
propertyName,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import v8 from 'node:v8'
|
||||
import fs from 'node:fs'
|
||||
import v8 from 'node:v8'
|
||||
|
||||
import { TEMP_DIR } from './constants/path.constant'
|
||||
|
||||
export function registerForMemoryDump() {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
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')
|
||||
|
||||
@@ -4,7 +4,6 @@ import { mkdirSync } from 'node:fs'
|
||||
import { Logger } from '@nestjs/common'
|
||||
|
||||
import { CLUSTER } from '~/app.config'
|
||||
|
||||
import {
|
||||
DATA_DIR,
|
||||
LOG_DIR,
|
||||
@@ -16,7 +15,6 @@ import {
|
||||
|
||||
import { consola, logger } from './consola.global'
|
||||
import { cwd, isDev } from './env.global'
|
||||
|
||||
import { registerJSONGlobal } from './json.global'
|
||||
|
||||
import './dayjs.global'
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { plainToInstance } from 'class-transformer'
|
||||
import type { IConfigKeys } from '~/modules/configs/configs.interface'
|
||||
|
||||
import { ENCRYPT } from '~/app.config'
|
||||
|
||||
import { register } 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 { IConfig } from '~/modules/configs/configs.interface'
|
||||
import { getDatabaseConnection } from '~/utils/database.util'
|
||||
import type { IConfigKeys } from '~/modules/configs/configs.interface'
|
||||
|
||||
import 'reflect-metadata'
|
||||
|
||||
console.log(ENCRYPT)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
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,10 +1,11 @@
|
||||
// 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([
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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'
|
||||
|
||||
@@ -14,7 +15,6 @@ import { CountingService } from '~/processors/helper/helper.counting.service'
|
||||
import { CacheService } from '~/processors/redis/cache.service'
|
||||
|
||||
import { AckDto, AckEventType, AckReadPayloadDto } from './ack.dto'
|
||||
import type { CountModel } from '~/shared/model/count.model'
|
||||
|
||||
@ApiController('ack')
|
||||
export class AckController {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { GatewayModule } from '~/processors/gateway/gateway.module'
|
||||
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
import { omit, pick, uniqBy } from 'lodash'
|
||||
import { Types } from 'mongoose'
|
||||
import type { OnModuleDestroy, OnModuleInit } from '@nestjs/common'
|
||||
import type { Collection } from 'mongodb'
|
||||
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,
|
||||
Inject,
|
||||
Injectable,
|
||||
Logger,
|
||||
forwardRef,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { ArticleTypeEnum } from '~/constants/article.constant'
|
||||
@@ -37,19 +50,6 @@ import {
|
||||
isValidRoomName,
|
||||
parseRoomName,
|
||||
} from './activity.util'
|
||||
import type { UpdatePresenceDto } from './dtos/presence.dto'
|
||||
import type {
|
||||
ActivityLikePayload,
|
||||
ActivityLikeSupportType,
|
||||
ActivityPresence,
|
||||
} from './activity.interface'
|
||||
import type { RecentlyModel } from '../recently/recently.model'
|
||||
import type { PostModel } from '../post/post.model'
|
||||
import type { PageModel } from '../page/page.model'
|
||||
import type { NoteModel } from '../note/note.model'
|
||||
import type { Socket } from 'socket.io'
|
||||
import type { Collection } from 'mongodb'
|
||||
import type { OnModuleDestroy, OnModuleInit } from '@nestjs/common'
|
||||
|
||||
declare module '~/types/socket-meta' {
|
||||
interface SocketMetadata {
|
||||
|
||||
@@ -5,10 +5,10 @@ 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 { HttpCache } from '~/common/decorators/cache.decorator'
|
||||
import { AnalyzeService } from '../analyze/analyze.service'
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import { NoteService } from '../note/note.service'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { GatewayModule } from '~/processors/gateway/gateway.module'
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
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 { Inject, Injectable, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Inject, Injectable } from '@nestjs/common'
|
||||
import { OnEvent } from '@nestjs/event-emitter'
|
||||
|
||||
import {
|
||||
@@ -30,11 +35,6 @@ 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'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
import type { AnyParamConstructor } from '@typegoose/typegoose/lib/types'
|
||||
import type { ReturnModelType } from '@typegoose/typegoose'
|
||||
|
||||
@Injectable()
|
||||
export class AggregateService {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { JsonOutputFunctionsParser } from 'langchain/output_parsers'
|
||||
import removeMdCodeblock from 'remove-md-codeblock'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
import { Injectable, Logger } from '@nestjs/common'
|
||||
import { OnEvent } from '@nestjs/event-emitter'
|
||||
|
||||
import { JsonOutputFunctionsParser } from 'langchain/output_parsers'
|
||||
import { BizException } from '~/common/exceptions/biz.exception'
|
||||
import { BusinessEvents } from '~/constants/business-event.constant'
|
||||
import { CollectionRefTypes } from '~/constants/db.constant'
|
||||
@@ -18,7 +19,7 @@ import { ConfigsService } from '../../configs/configs.service'
|
||||
import { DEFAULT_SUMMARY_LANG, LANGUAGE_CODE_TO_NAME } from '../ai.constants'
|
||||
import { AiService } from '../ai.service'
|
||||
import { AISummaryModel } from './ai-summary.model'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
@Injectable()
|
||||
export class AiSummaryService {
|
||||
private readonly logger: Logger
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
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,9 @@
|
||||
import { JsonOutputFunctionsParser } from 'langchain/output_parsers'
|
||||
import type { FunctionDefinition } from '@langchain/core/language_models/base'
|
||||
|
||||
import { Injectable, Logger } from '@nestjs/common'
|
||||
|
||||
import { JsonOutputFunctionsParser } from 'langchain/output_parsers'
|
||||
import { AiService } from '../ai.service'
|
||||
import type { FunctionDefinition } from '@langchain/core/language_models/base'
|
||||
|
||||
@Injectable()
|
||||
export class AiWriterService {
|
||||
|
||||
@@ -2,9 +2,9 @@ import { Module } from '@nestjs/common'
|
||||
|
||||
import { AiSummaryController } from './ai-summary/ai-summary.controller'
|
||||
import { AiSummaryService } from './ai-summary/ai-summary.service'
|
||||
import { AiService } from './ai.service'
|
||||
import { AiWriterService } from './ai-writer/ai-writer.service'
|
||||
import { AiWriterController } from './ai-writer/ai-writer.controller'
|
||||
import { AiWriterService } from './ai-writer/ai-writer.service'
|
||||
import { AiService } from './ai.service'
|
||||
|
||||
@Module({
|
||||
providers: [AiSummaryService, AiService, AiWriterService],
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { ChatOpenAI } from '@langchain/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,4 +1,5 @@
|
||||
import dayjs from 'dayjs'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
import { Delete, Get, HttpCode, Query } from '@nestjs/common'
|
||||
|
||||
@@ -12,7 +13,6 @@ import { getTodayEarly, getWeekStart } from '~/utils/time.util'
|
||||
|
||||
import { AnalyzeDto } from './analyze.dto'
|
||||
import { AnalyzeService } from './analyze.service'
|
||||
import type { PagerDto } from '~/shared/dto/pager.dto'
|
||||
|
||||
@ApiController({ path: 'analyze' })
|
||||
@Auth()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SchemaTypes } from 'mongoose'
|
||||
import { UAParser } from 'ua-parser-js'
|
||||
|
||||
import { Severity, index, modelOptions, prop } from '@typegoose/typegoose'
|
||||
import { index, modelOptions, prop, Severity } from '@typegoose/typegoose'
|
||||
|
||||
import { ANALYZE_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import dayjs from 'dayjs'
|
||||
import { merge } from 'lodash'
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ReturnModelType } from '@typegoose/typegoose'
|
||||
@@ -11,7 +12,6 @@ import { getRedisKey } from '~/utils/redis.util'
|
||||
|
||||
import { OptionModel } from '../configs/configs.model'
|
||||
import { AnalyzeModel } from './analyze.model'
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
|
||||
@Injectable()
|
||||
export class AnalyzeService {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Transform } from 'class-transformer'
|
||||
import {
|
||||
IsDate,
|
||||
isMongoId,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
isMongoId,
|
||||
} from 'class-validator'
|
||||
|
||||
import {
|
||||
|
||||
@@ -2,10 +2,13 @@ import dayjs from 'dayjs'
|
||||
import jwt from 'jsonwebtoken'
|
||||
import { isDate, omit } from 'lodash'
|
||||
import { LRUCache } from 'lru-cache'
|
||||
import type { ClerkClient } from '@clerk/clerk-sdk-node'
|
||||
import type { TokenModel, UserModel } from '~/modules/user/user.model'
|
||||
import type { TokenDto } from './auth.controller'
|
||||
|
||||
import { createClerkClient } from '@clerk/clerk-sdk-node'
|
||||
import { nanoid } from '@mx-space/external'
|
||||
import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common'
|
||||
import { ReturnModelType } from '@typegoose/typegoose'
|
||||
|
||||
import { alphabet } from '~/constants/other.constant'
|
||||
@@ -14,9 +17,6 @@ import { JWTService } from '~/processors/helper/helper.jwt.service'
|
||||
import { InjectModel } from '~/transformers/model.transformer'
|
||||
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import type { TokenDto } from './auth.controller'
|
||||
import type { TokenModel, UserModel } from '~/modules/user/user.model'
|
||||
import type { ClerkClient } from '@clerk/clerk-sdk-node'
|
||||
|
||||
const { customAlphabet } = nanoid
|
||||
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
import type {
|
||||
VerifiedAuthenticationResponse,
|
||||
VerifiedRegistrationResponse,
|
||||
} from '@simplewebauthn/server'
|
||||
import type {
|
||||
AuthenticationResponseJSON,
|
||||
CredentialDeviceType,
|
||||
RegistrationResponseJSON,
|
||||
} from '@simplewebauthn/server/script/deps'
|
||||
import type { UserDocument } from '../user/user.model'
|
||||
|
||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||
import {
|
||||
generateAuthenticationOptions,
|
||||
@@ -12,20 +23,10 @@ import { RequestContext } from '~/common/contexts/request.context'
|
||||
import { RedisKeys } from '~/constants/cache.constant'
|
||||
import { CacheService } from '~/processors/redis/cache.service'
|
||||
import { InjectModel } from '~/transformers/model.transformer'
|
||||
|
||||
import { getRedisKey } from '~/utils'
|
||||
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import type { UserDocument } from '../user/user.model'
|
||||
import { AuthnModel } from './authn.model'
|
||||
import type {
|
||||
VerifiedAuthenticationResponse,
|
||||
VerifiedRegistrationResponse,
|
||||
} from '@simplewebauthn/server'
|
||||
import type {
|
||||
AuthenticationResponseJSON,
|
||||
CredentialDeviceType,
|
||||
RegistrationResponseJSON,
|
||||
} from '@simplewebauthn/server/script/deps'
|
||||
|
||||
// TODO Compatible with versions below node v20
|
||||
if (!globalThis.crypto) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { existsSync, statSync } from 'node:fs'
|
||||
import { readFile, readdir, rm, writeFile } from 'node:fs/promises'
|
||||
import { readdir, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { flatten } from 'lodash'
|
||||
import { mkdirp } from 'mkdirp'
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Delete,
|
||||
forwardRef,
|
||||
Get,
|
||||
HttpCode,
|
||||
Inject,
|
||||
@@ -12,7 +13,6 @@ import {
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
forwardRef,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { ApiController } from '~/common/decorators/api-controller.decorator'
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
|
||||
import { PartialType } from '@nestjs/mapped-types'
|
||||
import { index, modelOptions, prop } from '@typegoose/typegoose'
|
||||
|
||||
import { CATEGORY_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
|
||||
export type CategoryDocument = DocumentType<CategoryModel>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { PostModule } from '../post/post.module'
|
||||
import { SlugTrackerModule } from '../slug-tracker/slug-tracker.module'
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { omit } from 'lodash'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
import type { FilterQuery } from 'mongoose'
|
||||
import type { PostModel } from '../post/post.model'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
Injectable,
|
||||
forwardRef,
|
||||
} from '@nestjs/common'
|
||||
import { ReturnModelType } from '@typegoose/typegoose'
|
||||
|
||||
@@ -20,9 +23,6 @@ import { scheduleManager } from '~/utils'
|
||||
import { PostService } from '../post/post.service'
|
||||
import { SlugTrackerService } from '../slug-tracker/slug-tracker.service'
|
||||
import { CategoryModel, CategoryType } from './category.model'
|
||||
import type { PostModel } from '../post/post.model'
|
||||
import type { FilterQuery } from 'mongoose'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
|
||||
@Injectable()
|
||||
export class CategoryService {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { isUndefined } from 'lodash'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
import type { Document, FilterQuery } from 'mongoose'
|
||||
import type { CommentModel } from './comment.model'
|
||||
|
||||
import {
|
||||
Body,
|
||||
@@ -42,9 +45,6 @@ import { CommentReplyMailType } from './comment.enum'
|
||||
import { CommentFilterEmailInterceptor } from './comment.interceptor'
|
||||
import { CommentState } from './comment.model'
|
||||
import { CommentService } from './comment.service'
|
||||
import type { CommentModel } from './comment.model'
|
||||
import type { Document, FilterQuery } from 'mongoose'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
|
||||
const idempotenceMessage = '哦吼,这句话你已经说过啦'
|
||||
const NESTED_REPLY_MAX = 10
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { isDefined } from 'class-validator'
|
||||
import { cloneDeep, isArrayLike, isObjectLike } from 'lodash'
|
||||
import { map } from 'rxjs'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import { getAvatar } from '~/utils'
|
||||
import type {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
|
||||
import { getAvatar } from '~/utils'
|
||||
|
||||
@Injectable()
|
||||
export class CommentFilterEmailInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, next: CallHandler) {
|
||||
|
||||
@@ -2,11 +2,11 @@ import { URL } from 'node:url'
|
||||
import { Types } from 'mongoose'
|
||||
import autopopulate from 'mongoose-autopopulate'
|
||||
|
||||
import { Ref, modelOptions, plugin, prop } from '@typegoose/typegoose'
|
||||
import { modelOptions, plugin, prop, Ref } from '@typegoose/typegoose'
|
||||
|
||||
import {
|
||||
COMMENT_COLLECTION_NAME,
|
||||
CollectionRefTypes,
|
||||
COMMENT_COLLECTION_NAME,
|
||||
} from '~/constants/db.constant'
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { GatewayModule } from '~/processors/gateway/gateway.module'
|
||||
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
import { URL } from 'node:url'
|
||||
import { render } from 'ejs'
|
||||
import { omit, pick } from 'lodash'
|
||||
import { Types, isObjectIdOrHexString } from 'mongoose'
|
||||
import { isObjectIdOrHexString, Types } from 'mongoose'
|
||||
import type { OnModuleInit } from '@nestjs/common'
|
||||
import type { ReturnModelType } from '@typegoose/typegoose/lib/types'
|
||||
import type { WriteBaseModel } from '~/shared/model/write-base.model'
|
||||
import type { SnippetModel } from '../snippet/snippet.model'
|
||||
import type {
|
||||
CommentEmailTemplateRenderProps,
|
||||
CommentModelRenderProps,
|
||||
} from './comment.email.default'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
Injectable,
|
||||
Logger,
|
||||
forwardRef,
|
||||
} from '@nestjs/common'
|
||||
import { OnEvent } from '@nestjs/event-emitter'
|
||||
|
||||
@@ -36,14 +44,6 @@ import {
|
||||
} from './comment.email.default'
|
||||
import { CommentReplyMailType } from './comment.enum'
|
||||
import { CommentModel, CommentState } from './comment.model'
|
||||
import type {
|
||||
CommentEmailTemplateRenderProps,
|
||||
CommentModelRenderProps,
|
||||
} from './comment.email.default'
|
||||
import type { SnippetModel } from '../snippet/snippet.model'
|
||||
import type { WriteBaseModel } from '~/shared/model/write-base.model'
|
||||
import type { OnModuleInit } from '@nestjs/common'
|
||||
import type { ReturnModelType } from '@typegoose/typegoose/lib/types'
|
||||
|
||||
@Injectable()
|
||||
export class CommentService implements OnModuleInit {
|
||||
@@ -120,7 +120,7 @@ export class CommentService implements OnModuleInit {
|
||||
}
|
||||
const isBlock = commentOptions.blockIps.some((ip) =>
|
||||
// @ts-ignore
|
||||
new RegExp(ip, 'ig').test(doc.ip),
|
||||
new RegExp(ip, 'gi').test(doc.ip),
|
||||
)
|
||||
if (isBlock) {
|
||||
return true
|
||||
@@ -129,7 +129,7 @@ export class CommentService implements OnModuleInit {
|
||||
|
||||
const customKeywords = commentOptions.spamKeywords || []
|
||||
const isBlock = [...customKeywords, ...BlockedKeywords].some((keyword) =>
|
||||
new RegExp(keyword, 'ig').test(doc.text),
|
||||
new RegExp(keyword, 'gi').test(doc.text),
|
||||
)
|
||||
|
||||
if (isBlock) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DEMO_MODE } from '~/app.config'
|
||||
import type { IConfig } from './configs.interface'
|
||||
|
||||
import { DEMO_MODE } from '~/app.config'
|
||||
|
||||
export const generateDefaultConfig: () => IConfig = () => ({
|
||||
seo: {
|
||||
title: '我的小世界呀',
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
ValidateNested,
|
||||
} from 'class-validator'
|
||||
import { JSONSchema } from 'class-validator-jsonschema'
|
||||
import type { ChatModel } from 'openai/resources'
|
||||
|
||||
import { IsAllowedUrl } from '~/decorators/dto/isAllowedUrl'
|
||||
|
||||
@@ -27,7 +28,6 @@ import {
|
||||
JSONSchemaTextAreaField,
|
||||
JSONSchemaToggleField,
|
||||
} from './configs.jsonschema.decorator'
|
||||
import type { ChatModel } from 'openai/resources'
|
||||
|
||||
const SecretField = (target: object, propertyKey: string | symbol) => {
|
||||
Encrypt(target, propertyKey)
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { Type } from 'class-transformer'
|
||||
import { ValidateNested } from 'class-validator'
|
||||
import { JSONSchema } from 'class-validator-jsonschema'
|
||||
import type {
|
||||
ClassConstructor,
|
||||
TypeHelpOptions,
|
||||
TypeOptions,
|
||||
} from 'class-transformer'
|
||||
|
||||
import {
|
||||
AIDto,
|
||||
AdminExtraDto,
|
||||
AIDto,
|
||||
AlgoliaSearchOptionsDto,
|
||||
AuthSecurityDto,
|
||||
BackupOptionsDto,
|
||||
@@ -19,11 +25,6 @@ import {
|
||||
ThirdPartyServiceIntegrationDto,
|
||||
UrlDto,
|
||||
} from './configs.dto'
|
||||
import type {
|
||||
ClassConstructor,
|
||||
TypeHelpOptions,
|
||||
TypeOptions,
|
||||
} from 'class-transformer'
|
||||
|
||||
export const configDtoMapping = {} as Record<string, ClassConstructor<any>>
|
||||
const ConfigField =
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Schema } from 'mongoose'
|
||||
|
||||
import { Severity, modelOptions, prop } from '@typegoose/typegoose'
|
||||
import { modelOptions, prop, Severity } from '@typegoose/typegoose'
|
||||
|
||||
@modelOptions({
|
||||
options: { allowMixed: Severity.ALLOW, customName: 'Option' },
|
||||
|
||||
@@ -2,6 +2,7 @@ import cluster from 'node:cluster'
|
||||
import { plainToInstance } from 'class-transformer'
|
||||
import { validateSync } from 'class-validator'
|
||||
import { cloneDeep, mergeWith } from 'lodash'
|
||||
import type { ClassConstructor } from 'class-transformer'
|
||||
|
||||
import { createClerkClient } from '@clerk/clerk-sdk-node'
|
||||
import {
|
||||
@@ -27,9 +28,8 @@ import { getRedisKey } from '~/utils/redis.util'
|
||||
|
||||
import { generateDefaultConfig } from './configs.default'
|
||||
import { decryptObject, encryptObject } from './configs.encrypt.util'
|
||||
import { IConfig, configDtoMapping } from './configs.interface'
|
||||
import { configDtoMapping, IConfig } from './configs.interface'
|
||||
import { OptionModel } from './configs.model'
|
||||
import type { ClassConstructor } from 'class-transformer'
|
||||
|
||||
const configsKeySet = new Set(Object.keys(configDtoMapping))
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import RemoveMarkdown from 'remove-markdown'
|
||||
import xss from 'xss'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
|
||||
import { CacheKey, CacheTTL } from '@nestjs/cache-manager'
|
||||
import { Controller, Get, Header } from '@nestjs/common'
|
||||
@@ -12,7 +13,6 @@ import { AggregateService } from '../aggregate/aggregate.service'
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import { MarkdownService } from '../markdown/markdown.service'
|
||||
import { UserService } from '../user/user.service'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
|
||||
@Controller()
|
||||
export class FeedController {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { createWriteStream } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import type { Readable } from 'node:stream'
|
||||
import type { FileType } from './file.type'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
@@ -15,8 +17,6 @@ import {
|
||||
} from '~/constants/path.constant'
|
||||
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import type { FileType } from './file.type'
|
||||
import type { Readable } from 'node:stream'
|
||||
|
||||
@Injectable()
|
||||
export class FileService {
|
||||
@@ -79,8 +79,8 @@ export class FileService {
|
||||
async deleteFile(type: FileType, name: string) {
|
||||
try {
|
||||
const path = this.resolveFilePath(type, name)
|
||||
await fs.copyFile(path, resolve(STATIC_FILE_TRASH_DIR, name));
|
||||
await fs.unlink(path);
|
||||
await fs.copyFile(path, resolve(STATIC_FILE_TRASH_DIR, name))
|
||||
await fs.unlink(path)
|
||||
} catch (error) {
|
||||
this.logger.error('删除文件失败', error)
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { Readable } from 'form-data'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
Delete,
|
||||
@@ -17,7 +19,6 @@ import { formatByteSize } from '~/utils'
|
||||
import { getTodayLogFilePath } from '~/utils/path.util'
|
||||
|
||||
import { LogQueryDto, LogTypeDto } from '../health.dto'
|
||||
import type { Readable } from 'form-data'
|
||||
|
||||
@ApiController('health/log')
|
||||
@Auth()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { checkInit } from '~/utils/check-init.util'
|
||||
import type { CanActivate } from '@nestjs/common'
|
||||
|
||||
import { checkInit } from '~/utils/check-init.util'
|
||||
|
||||
export class InitGuard implements CanActivate {
|
||||
async canActivate() {
|
||||
return !(await checkInit())
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type mongoose from 'mongoose'
|
||||
|
||||
import {
|
||||
Body,
|
||||
ForbiddenException,
|
||||
@@ -24,7 +26,6 @@ import { scheduleManager } from '~/utils'
|
||||
import { AuditReasonDto, LinkDto } from './link.dto'
|
||||
import { LinkModel, LinkState } from './link.model'
|
||||
import { LinkService } from './link.service'
|
||||
import type mongoose from 'mongoose'
|
||||
|
||||
const paths = ['links', 'friends']
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { modelOptions, prop } from '@typegoose/typegoose'
|
||||
import { Transform } from 'class-transformer'
|
||||
|
||||
import {
|
||||
IsEmail,
|
||||
IsEnum,
|
||||
@@ -10,6 +8,8 @@ import {
|
||||
MaxLength,
|
||||
} from 'class-validator'
|
||||
|
||||
import { modelOptions, prop } from '@typegoose/typegoose'
|
||||
|
||||
import { BaseModel } from '~/shared/model/base.model'
|
||||
|
||||
export enum LinkType {
|
||||
|
||||
@@ -7,14 +7,15 @@ import {
|
||||
NotFoundException,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { BusinessEvents, EventScope } from '~/constants/business-event.constant'
|
||||
import { isDev } from '~/global/env.global'
|
||||
import { EmailService } from '~/processors/helper/helper.email.service'
|
||||
import { EventManagerService } from '~/processors/helper/helper.event.service'
|
||||
import { HttpService } from '~/processors/helper/helper.http.service'
|
||||
import { InjectModel } from '~/transformers/model.transformer'
|
||||
|
||||
import { scheduleManager } from '~/utils'
|
||||
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import { UserService } from '../user/user.service'
|
||||
import { LinkApplyEmailType } from './link-mail.enum'
|
||||
|
||||
@@ -2,6 +2,8 @@ import { join } from 'node:path'
|
||||
import { Readable } from 'node:stream'
|
||||
import JSZip from 'jszip'
|
||||
import { omit } from 'lodash'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
import type { MarkdownYAMLProperty } from './markdown.interface'
|
||||
|
||||
import { CacheTTL } from '@nestjs/cache-manager'
|
||||
import { Body, Get, Header, Param, Post, Query } from '@nestjs/common'
|
||||
@@ -14,8 +16,6 @@ import { MongoIdDto } from '~/shared/dto/id.dto'
|
||||
|
||||
import { DataListDto, ExportMarkdownQueryDto } from './markdown.dto'
|
||||
import { MarkdownService } from './markdown.service'
|
||||
import type { MarkdownYAMLProperty } from './markdown.interface'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
|
||||
@ApiController('markdown')
|
||||
export class MarkdownController {
|
||||
|
||||
@@ -2,6 +2,8 @@ import { dump } from 'js-yaml'
|
||||
import JSZip from 'jszip'
|
||||
import { omit } from 'lodash'
|
||||
import { Types } from 'mongoose'
|
||||
import type { DatatypeDto } from './markdown.dto'
|
||||
import type { MarkdownYAMLProperty } from './markdown.interface'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
@@ -22,8 +24,6 @@ import { NoteModel } from '../note/note.model'
|
||||
import { PageModel } from '../page/page.model'
|
||||
import { PostModel } from '../post/post.model'
|
||||
import { markdownToHtml } from './markdown.util'
|
||||
import type { MarkdownYAMLProperty } from './markdown.interface'
|
||||
import type { DatatypeDto } from './markdown.dto'
|
||||
|
||||
@Injectable()
|
||||
export class MarkdownService {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { FilterQuery } from 'mongoose'
|
||||
|
||||
import {
|
||||
Body,
|
||||
Delete,
|
||||
@@ -30,7 +32,6 @@ import {
|
||||
} from './note.dto'
|
||||
import { NoteModel, PartialNoteModel } from './note.model'
|
||||
import { NoteService } from './note.service'
|
||||
import type { FilterQuery } from 'mongoose'
|
||||
|
||||
@ApiController({ path: 'notes' })
|
||||
export class NoteController {
|
||||
|
||||
@@ -12,7 +12,7 @@ import mongooseAutoPopulate from 'mongoose-autopopulate'
|
||||
|
||||
import { PartialType } from '@nestjs/mapped-types'
|
||||
import { AutoIncrementID } from '@typegoose/auto-increment'
|
||||
import { Ref, index, modelOptions, plugin, prop } from '@typegoose/typegoose'
|
||||
import { index, modelOptions, plugin, prop, Ref } from '@typegoose/typegoose'
|
||||
|
||||
import { NOTE_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
import { TransformEmptyNull } from '~/decorators/dto/transformEmptyNull'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { GatewayModule } from '~/processors/gateway/gateway.module'
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { isDefined, isMongoId } from 'class-validator'
|
||||
import dayjs from 'dayjs'
|
||||
import { debounce, omit } from 'lodash'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
import type { FilterQuery, PaginateOptions } from 'mongoose'
|
||||
|
||||
import { Inject, Injectable, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Inject, Injectable } from '@nestjs/common'
|
||||
|
||||
import { CannotFindException } from '~/common/exceptions/cant-find.exception'
|
||||
import { NoContentCanBeModifiedException } from '~/common/exceptions/no-content-canbe-modified.exception'
|
||||
@@ -18,8 +20,6 @@ import { getLessThanNow, scheduleManager } from '~/utils'
|
||||
import { getArticleIdFromRoomName } from '../activity/activity.util'
|
||||
import { CommentService } from '../comment/comment.service'
|
||||
import { NoteModel } from './note.model'
|
||||
import type { FilterQuery, PaginateOptions } from 'mongoose'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
|
||||
@Injectable()
|
||||
export class NoteService {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { extname, join } from 'node:path'
|
||||
import { render } from 'ejs'
|
||||
import { FastifyReply, FastifyRequest } from 'fastify'
|
||||
import { lookup } from 'mime-types'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
import { Controller, Get, Query, Req, Res } from '@nestjs/common'
|
||||
import { SkipThrottle } from '@nestjs/throttler'
|
||||
@@ -14,7 +15,6 @@ import { AssetService } from '~/processors/helper/helper.asset.service'
|
||||
|
||||
import { UpdateService } from '../update/update.service'
|
||||
import { PageProxyService } from './pageproxy.service'
|
||||
import type { Observable } from 'rxjs'
|
||||
|
||||
@Controller('/')
|
||||
@SkipThrottle()
|
||||
|
||||
@@ -3,11 +3,11 @@ import { parseHTML } from 'linkedom'
|
||||
|
||||
import { Injectable, InternalServerErrorException } from '@nestjs/common'
|
||||
|
||||
import PKG from '~/../package.json'
|
||||
import { API_VERSION } from '~/app.config'
|
||||
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import { UserService } from '../user/user.service'
|
||||
import PKG from '~/../package.json'
|
||||
|
||||
@Injectable()
|
||||
export class PageProxyService {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
|
||||
import {
|
||||
Body,
|
||||
Delete,
|
||||
@@ -21,8 +24,6 @@ import { addYearCondition } from '~/transformers/db-query.transformer'
|
||||
import { CategoryAndSlugDto, PostPagerDto } from './post.dto'
|
||||
import { PartialPostModel, PostModel } from './post.model'
|
||||
import { PostService } from './post.service'
|
||||
import type { CategoryModel } from '../category/category.model'
|
||||
import type { PipelineStage } from 'mongoose'
|
||||
|
||||
@ApiController('posts')
|
||||
export class PostController {
|
||||
|
||||
@@ -3,27 +3,28 @@ import {
|
||||
ArrayUnique,
|
||||
IsBoolean,
|
||||
IsDate,
|
||||
isDateString,
|
||||
IsInt,
|
||||
IsMongoId,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Min,
|
||||
isDateString,
|
||||
} from 'class-validator'
|
||||
import { Types } from 'mongoose'
|
||||
import aggregatePaginate from 'mongoose-aggregate-paginate-v2'
|
||||
import mongooseAutoPopulate from 'mongoose-autopopulate'
|
||||
import type { Paginator } from '~/shared/interface/paginator.interface'
|
||||
|
||||
import { UnprocessableEntityException } from '@nestjs/common'
|
||||
import { PartialType } from '@nestjs/mapped-types'
|
||||
import {
|
||||
Ref,
|
||||
Severity,
|
||||
index,
|
||||
modelOptions,
|
||||
plugin,
|
||||
prop,
|
||||
Ref,
|
||||
Severity,
|
||||
} from '@typegoose/typegoose'
|
||||
|
||||
import { POST_COLLECTION_NAME } from '~/constants/db.constant'
|
||||
@@ -32,7 +33,6 @@ import { CountModel as Count } from '~/shared/model/count.model'
|
||||
import { WriteBaseModel } from '~/shared/model/write-base.model'
|
||||
|
||||
import { CategoryModel as Category } from '../category/category.model'
|
||||
import type { Paginator } from '~/shared/interface/paginator.interface'
|
||||
|
||||
@plugin(aggregatePaginate)
|
||||
@plugin(mongooseAutoPopulate)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { CategoryModule } from '../category/category.module'
|
||||
import { SlugTrackerModule } from '../slug-tracker/slug-tracker.module'
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { isDefined } from 'class-validator'
|
||||
import { debounce, omit } from 'lodash'
|
||||
import slugify from 'slugify'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
import type { AggregatePaginateModel, Document, Types } from 'mongoose'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
forwardRef,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { BusinessException } from '~/common/exceptions/biz.exception'
|
||||
@@ -27,8 +29,6 @@ import { CategoryService } from '../category/category.service'
|
||||
import { CommentModel } from '../comment/comment.model'
|
||||
import { SlugTrackerService } from '../slug-tracker/slug-tracker.service'
|
||||
import { PostModel } from './post.model'
|
||||
import type { AggregatePaginateModel, Document, Types } from 'mongoose'
|
||||
import type { DocumentType } from '@typegoose/typegoose'
|
||||
|
||||
@Injectable()
|
||||
export class PostService {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { CommentModule } from '../comment/comment.module'
|
||||
import { RecentlyController } from './recently.controller'
|
||||
|
||||
@@ -3,10 +3,10 @@ import pluralize from 'pluralize'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
Injectable,
|
||||
UnprocessableEntityException,
|
||||
forwardRef,
|
||||
} from '@nestjs/common'
|
||||
|
||||
import { CannotFindException } from '~/common/exceptions/cant-find.exception'
|
||||
|
||||
@@ -2,6 +2,9 @@ import dayjs from 'dayjs'
|
||||
import { render } from 'ejs'
|
||||
import { isNil } from 'lodash'
|
||||
import xss from 'xss'
|
||||
import type { NoteModel } from '../note/note.model'
|
||||
import type { PageModel } from '../page/page.model'
|
||||
import type { PostModel } from '../post/post.model'
|
||||
|
||||
import { CacheTTL } from '@nestjs/cache-manager'
|
||||
import {
|
||||
@@ -26,9 +29,6 @@ import { ConfigsService } from '../configs/configs.service'
|
||||
import { MarkdownPreviewDto } from '../markdown/markdown.dto'
|
||||
import { MarkdownService } from '../markdown/markdown.service'
|
||||
import { UserService } from '../user/user.service'
|
||||
import type { PostModel } from '../post/post.model'
|
||||
import type { PageModel } from '../page/page.model'
|
||||
import type { NoteModel } from '../note/note.model'
|
||||
|
||||
@Controller('/render')
|
||||
@HTTPDecorators.Bypass
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Module, forwardRef } from '@nestjs/common'
|
||||
import { forwardRef, Module } from '@nestjs/common'
|
||||
|
||||
import { NoteModule } from '../note/note.module'
|
||||
import { PageModule } from '../page/page.module'
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
import algoliasearch from 'algoliasearch'
|
||||
import { omit } from 'lodash'
|
||||
import removeMdCodeblock from 'remove-md-codeblock'
|
||||
import type { SearchResponse } from '@algolia/client-search'
|
||||
import type { SearchDto } from '~/modules/search/search.dto'
|
||||
import type { Pagination } from '~/shared/interface/paginator.interface'
|
||||
import type { SearchIndex } from 'algoliasearch'
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
forwardRef,
|
||||
@@ -8,10 +16,6 @@ import {
|
||||
import { OnEvent } from '@nestjs/event-emitter'
|
||||
import { CronExpression } from '@nestjs/schedule'
|
||||
|
||||
import algoliasearch from 'algoliasearch'
|
||||
import { omit } from 'lodash'
|
||||
import removeMdCodeblock from 'remove-md-codeblock'
|
||||
|
||||
import { CronDescription } from '~/common/decorators/cron-description.decorator'
|
||||
import { CronOnce } from '~/common/decorators/cron-once.decorator'
|
||||
import { BusinessEvents } from '~/constants/business-event.constant'
|
||||
@@ -19,16 +23,12 @@ import { EventBusEvents } from '~/constants/event-bus.constant'
|
||||
import { DatabaseService } from '~/processors/database/database.service'
|
||||
import { transformDataToPaginate } from '~/transformers/paginate.transformer'
|
||||
|
||||
import type { SearchDto } from '~/modules/search/search.dto'
|
||||
import type { Pagination } from '~/shared/interface/paginator.interface'
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import { NoteModel } from '../note/note.model'
|
||||
import { NoteService } from '../note/note.service'
|
||||
import { PageService } from '../page/page.service'
|
||||
import { PostModel } from '../post/post.model'
|
||||
import { PostService } from '../post/post.service'
|
||||
import type { SearchResponse } from '@algolia/client-search'
|
||||
import type { SearchIndex } from 'algoliasearch'
|
||||
|
||||
@Injectable()
|
||||
export class SearchService {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { MiddlewareConsumer, NestModule } from '@nestjs/common'
|
||||
|
||||
import { Module, RequestMethod } from '@nestjs/common'
|
||||
|
||||
import { ServerTimeController } from './server-time.controller'
|
||||
import { trackResponseTimeMiddleware } from './server-time.middleware'
|
||||
import type { MiddlewareConsumer, NestModule } from '@nestjs/common'
|
||||
|
||||
@Module({
|
||||
controllers: [ServerTimeController],
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { HttpException } from '@nestjs/common'
|
||||
import type { FastifyReply } from 'fastify'
|
||||
import type { FunctionContextResponse } from './function.types'
|
||||
|
||||
import { HttpException } from '@nestjs/common'
|
||||
|
||||
export const createMockedContextResponse = (
|
||||
reply: FastifyReply,
|
||||
): FunctionContextResponse => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
Severity,
|
||||
index,
|
||||
modelOptions,
|
||||
mongoose,
|
||||
prop,
|
||||
Severity,
|
||||
} from '@typegoose/typegoose'
|
||||
|
||||
export const ServerlessStorageCollectionName = `serverlessstorages`
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user