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