Skip to content

Commit

Permalink
fix(shared): disable eslint rule for a entry file
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Aug 27, 2023
1 parent 18e1226 commit cabd57c
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 91 deletions.
4 changes: 2 additions & 2 deletions apps/core/src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const MONGO_DB = {
return `mongodb+srv://${this.userAndPassword}${this.host}/${this.dbName}?retryWrites=true&w=majority`;
} else {
return `mongodb://${this.userAndPassword}${this.host}:${this.port}${
CONFIG.railway ? '' : `/${this.dbName}`
}`;
CONFIG.railway ? '' : `/${this.dbName}`
}`;
}
},
};
Expand Down
10 changes: 5 additions & 5 deletions apps/core/src/common/adapt/fastify.adapt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
* @author: Wibus
* Coding With IU
*/
import FastifyMultipart from '@fastify/multipart'
import { FastifyAdapter } from '@nestjs/platform-fastify'
import FastifyMultipart from '@fastify/multipart';
import { FastifyAdapter } from '@nestjs/platform-fastify';

const app: FastifyAdapter = new FastifyAdapter({
trustProxy: true,
})
export { app as fastifyApp }
});
export { app as fastifyApp };

app.register(FastifyMultipart, {
limits: {
fields: 10, // Max number of non-file fields
fileSize: 1024 * 1024 * 6, // limit size 6M
files: 5, // Max number of file fields
},
})
});

app.getInstance().addHook('onRequest', (request, reply, done) => {
// set undefined origin
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/modules/migrate/migrate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class MigrateService {
const pagesData = await this.importPages(pages).catch((e) => {
Logger.error(`导入页面时出错 ${e}`, MigrateService.name);
return [];
})
});
const commentsData = await this.importComments(comments).catch((e) => {
Logger.error(`导入评论时出错 ${e}`, MigrateService.name);
return [];
Expand Down
119 changes: 80 additions & 39 deletions apps/core/src/modules/schedule/schedule.controller.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,107 @@
import { Body, Controller, Delete, Get, Inject, Param, Patch, Post, Put } from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import { ApiOperation } from "@nestjs/swagger";
import { ScheduleDto } from "~/libs/config/src/config.dto";
import { ApiName } from "~/shared/common/decorator/openapi.decorator";
import { NotificationEvents } from "~/shared/constants/event.constant";
import { ServicesEnum } from "~/shared/constants/services.constant";
import { transportReqToMicroservice } from "~/shared/microservice.transporter";
import {
Body,
Controller,
Delete,
Get,
Inject,
Param,
Patch,
Post,
Put,
} from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { ApiOperation } from '@nestjs/swagger';
import { ScheduleDto } from '~/libs/config/src/config.dto';
import { ApiName } from '~/shared/common/decorator/openapi.decorator';
import { NotificationEvents } from '~/shared/constants/event.constant';
import { ServicesEnum } from '~/shared/constants/services.constant';
import { transportReqToMicroservice } from '~/shared/microservice.transporter';

@Controller("schedule")
@Controller('schedule')
@ApiName
export class ScheduleController {
constructor(
@Inject(ServicesEnum.notification) private readonly notification: ClientProxy
){}
@Inject(ServicesEnum.notification)
private readonly notification: ClientProxy,
) {}

@Post("")
@ApiOperation({ summary: "创建定时任务" })
@Post('')
@ApiOperation({ summary: '创建定时任务' })
// @Auth()
async createSchedule(@Body() body: ScheduleDto) {
return transportReqToMicroservice(this.notification, NotificationEvents.ScheduleCreateByMaster, body)
return transportReqToMicroservice(
this.notification,
NotificationEvents.ScheduleCreateByMaster,
body,
);
}

@Delete("/:token")
@ApiOperation({ summary: "删除定时任务" })
@Delete('/:token')
@ApiOperation({ summary: '删除定时任务' })
// @Auth()
async deleteSchedule(@Param("token") token: string) {
return transportReqToMicroservice(this.notification, NotificationEvents.ScheduleDeleteByMaster, token)
async deleteSchedule(@Param('token') token: string) {
return transportReqToMicroservice(
this.notification,
NotificationEvents.ScheduleDeleteByMaster,
token,
);
}

@Put("/:token")
@ApiOperation({ summary: "更新定时任务" })
@Put('/:token')
@ApiOperation({ summary: '更新定时任务' })
// @Auth()
async updateSchedule(@Param("token") token: string, @Body() body: ScheduleDto) {
return transportReqToMicroservice(this.notification, NotificationEvents.ScheduleUpdateByMaster, { token, body })
async updateSchedule(
@Param('token') token: string,
@Body() body: ScheduleDto,
) {
return transportReqToMicroservice(
this.notification,
NotificationEvents.ScheduleUpdateByMaster,
{ token, body },
);
}

@Get("/:token/run")
@ApiOperation({ summary: "立即运行定时任务" })
@Get('/:token/run')
@ApiOperation({ summary: '立即运行定时任务' })
// @Auth()
async runSchedule(@Param("token") token: string) {
return transportReqToMicroservice(this.notification, NotificationEvents.ScheduleRunByMaster, token)
async runSchedule(@Param('token') token: string) {
return transportReqToMicroservice(
this.notification,
NotificationEvents.ScheduleRunByMaster,
token,
);
}

@Get("/:token")
@ApiOperation({ summary: "获取定时任务详情" })
@Get('/:token')
@ApiOperation({ summary: '获取定时任务详情' })
// @Auth()
async getSchedule(@Param("token") token: string) {
return transportReqToMicroservice(this.notification, NotificationEvents.ScheduleGetByMaster, token)
async getSchedule(@Param('token') token: string) {
return transportReqToMicroservice(
this.notification,
NotificationEvents.ScheduleGetByMaster,
token,
);
}

@Get("")
@ApiOperation({ summary: "获取所有定时任务" })
@Get('')
@ApiOperation({ summary: '获取所有定时任务' })
// @Auth()
async getSchedules() {
return transportReqToMicroservice(this.notification, NotificationEvents.SchedulesGetAllByMaster, {})
return transportReqToMicroservice(
this.notification,
NotificationEvents.SchedulesGetAllByMaster,
{},
);
}

@Patch("/:token")
@ApiOperation({ summary: "切换定时任务状态" })
@Patch('/:token')
@ApiOperation({ summary: '切换定时任务状态' })
// @Auth()
async toggleSchedule(@Param("token") token: string) {
return transportReqToMicroservice(this.notification, NotificationEvents.ScheduleToggleByMaster, token)
async toggleSchedule(@Param('token') token: string) {
return transportReqToMicroservice(
this.notification,
NotificationEvents.ScheduleToggleByMaster,
token,
);
}

}
}
18 changes: 9 additions & 9 deletions apps/core/src/modules/schedule/schedule.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Module } from "@nestjs/common";
import { ClientsModule } from "@nestjs/microservices";
import { ServicesEnum } from "~/shared/constants/services.constant";
import { REDIS_TRANSPORTER } from "~/shared/constants/transporter.constants";
import { ScheduleController } from "./schedule.controller";
import { Module } from '@nestjs/common';
import { ClientsModule } from '@nestjs/microservices';
import { ServicesEnum } from '~/shared/constants/services.constant';
import { REDIS_TRANSPORTER } from '~/shared/constants/transporter.constants';
import { ScheduleController } from './schedule.controller';

@Module({
imports: [
ClientsModule.register([
{
name: ServicesEnum.notification,
...REDIS_TRANSPORTER,
}
])
},
]),
],
controllers: [ScheduleController]
controllers: [ScheduleController],
})
export class ScheduleModule{}
export class ScheduleModule {}
2 changes: 1 addition & 1 deletion apps/core/src/modules/store/store.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class StoreController {
);
}

@Post("/create")
@Post('/create')
@ApiOperation({ summary: '创建文件' })
@Auth()
create(@Body('name') name: string, @Body('content') content: Buffer) {
Expand Down
7 changes: 5 additions & 2 deletions apps/friends-service/src/friends-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,13 @@ export class FriendsService {
);
return isAlive;
}

if (!friend.verifyLink) {
await this.friendsModel.findByIdAndUpdate(id, { autoCheck: false });
Logger.warn(`${friend.name} 无验证链接,跳过互链检测`, FriendsService.name);
Logger.warn(
`${friend.name} 无验证链接,跳过互链检测`,
FriendsService.name,
);
return isAlive;
}
const isAutoCheck = await this.autoCheck(friend.verifyLink);
Expand Down
5 changes: 4 additions & 1 deletion apps/notification-service/src/notification-service.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { NotificationScheduleServiceController } from './notification-schedule.c
},
]),
],
controllers: [NotificationServiceController, NotificationScheduleServiceController],
controllers: [
NotificationServiceController,
NotificationScheduleServiceController,
],
providers: [NotificationService, NotificationScheduleService],
})
export class NotificationServiceModule {}
18 changes: 9 additions & 9 deletions apps/page-service/src/page-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ export class PageService {
return res;
}

/**
/**
* 根据id删除页面
* @param id 页面id
* @returns void
**/
async deletePageById(id: string) {
return this.pageModel.findByIdAndDelete(id).then((res) => {
if (res) {
this.notification.emit(NotificationEvents.SystemPageDelete, res);
}
return true;
});
}
async deletePageById(id: string) {
return this.pageModel.findByIdAndDelete(id).then((res) => {
if (res) {
this.notification.emit(NotificationEvents.SystemPageDelete, res);
}
return true;
});
}
}
5 changes: 2 additions & 3 deletions apps/page-service/src/post-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ export class PostService {
password?: any,
isMaster?: boolean,
) {
const categoryDocument = await this.categoryService.getCategoryBySlug(
category,
);
const categoryDocument =
await this.categoryService.getCategoryBySlug(category);
if (!categoryDocument) {
throw new NotFoundRpcExcption(ExceptionMessage.CategoryIsNotExist);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/store-service/src/store-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class StoreServiceController {
}

@MessagePattern({ cmd: StoreEvents.StoreFileCreateByMaster })
async storeFileCreate(data: { name: string, content: string | Buffer }) {
async storeFileCreate(data: { name: string; content: string | Buffer }) {
return await this.storeServiceService.create(data.name, data.content);
}
}
10 changes: 6 additions & 4 deletions apps/store-service/src/store-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ export class StoreServiceService {
}

async create(name: string, content: string | Buffer) {
if (!name) {
if (!name) {
throw new InternalServerErrorRpcExcption('文件名不能为空');
}
return await this.assetHelper.createFile(STORE_DIR, name, content).catch((e) => {
throw new InternalServerErrorRpcExcption(e.message);
});
return await this.assetHelper
.createFile(STORE_DIR, name, content)
.catch((e) => {
throw new InternalServerErrorRpcExcption(e.message);
});
}
}
5 changes: 2 additions & 3 deletions apps/themes-service/src/themes-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ export class ThemesServiceService {
}
if (!config?.type) {
throw new InternalServerErrorRpcExcption(
`主题配置文件格式错误, "${
(config as ThemeConfigItemAll)?.name
}" 字段中的 type 字段不存在`,
`主题配置文件格式错误, "${(config as ThemeConfigItemAll)
?.name}" 字段中的 type 字段不存在`,
);
}
if (!Object.values(ThemeConfigType).includes(config.type)) {
Expand Down
2 changes: 1 addition & 1 deletion libs/config/src/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ConfigService {
: validateSync(model, this.validateOptions);
if (errors.length) {
console.log(errors);

throw this.validate.createExceptionFactory()(errors as any);
}
return model;
Expand Down
2 changes: 0 additions & 2 deletions libs/helper/src/helper.assets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ export class AssetsService {
}

async getFileList(_path: string) {


const files = fs.readdirSync(_path);
const fileList = files.map((file) => {
const filePath = path.join(_path, file);
Expand Down
9 changes: 1 addition & 8 deletions shared/constants/services.constant.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
/*
* @FilePath: /mog-core/shared/constants/services.constant.ts
* @author: Wibus
* @Date: 2022-09-03 22:28:40
* @LastEditors: Wibus
* @LastEditTime: 2022-11-18 11:37:58
* Coding With IU
*/
/* eslint-disable @typescript-eslint/no-duplicate-enum-values */

export enum ServicesEnum {
core = 'CORE',
Expand Down

0 comments on commit cabd57c

Please sign in to comment.