diff --git a/README.md b/README.md index d4ccfef..e71b7e2 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,11 @@ - .dockerignore 配置哪些文件应该被忽略掉 - .gitea/workflows/depoy.yaml 流水线任务的配置文件,语法上与 Github Actions 一致 +## 计划 +- 双token无感刷新 +- session/cookie,jwt,sso单点登陆 +- 大文件上传,断点续传 + ## 笔记 - createUserDto与User分开 diff --git a/content/data/db.sqlite b/content/data/db.sqlite index 6625cd6..e39fdef 100644 Binary files a/content/data/db.sqlite and b/content/data/db.sqlite differ diff --git a/content/upload/2023-11-03/1698981118120.txt b/content/upload/2023-11-03/1698981118120.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698981118120.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698981118122.png b/content/upload/2023-11-03/1698981118122.png new file mode 100644 index 0000000..f6feb27 Binary files /dev/null and b/content/upload/2023-11-03/1698981118122.png differ diff --git a/content/upload/2023-11-03/1698981118145.png b/content/upload/2023-11-03/1698981118145.png new file mode 100644 index 0000000..ca661d1 Binary files /dev/null and b/content/upload/2023-11-03/1698981118145.png differ diff --git a/content/upload/2023-11-03/1698981118147.png b/content/upload/2023-11-03/1698981118147.png new file mode 100644 index 0000000..8a94bde Binary files /dev/null and b/content/upload/2023-11-03/1698981118147.png differ diff --git a/content/upload/2023-11-03/1698981118149.ico b/content/upload/2023-11-03/1698981118149.ico new file mode 100644 index 0000000..9a4ec5b Binary files /dev/null and b/content/upload/2023-11-03/1698981118149.ico differ diff --git a/content/upload/2023-11-03/1698981118150.png b/content/upload/2023-11-03/1698981118150.png new file mode 100644 index 0000000..763e7a2 Binary files /dev/null and b/content/upload/2023-11-03/1698981118150.png differ diff --git a/content/upload/2023-11-03/1698981118216.png b/content/upload/2023-11-03/1698981118216.png new file mode 100644 index 0000000..68a7cfa Binary files /dev/null and b/content/upload/2023-11-03/1698981118216.png differ diff --git a/content/upload/2023-11-03/1698981118219.webmanifest b/content/upload/2023-11-03/1698981118219.webmanifest new file mode 100644 index 0000000..45dc8a2 --- /dev/null +++ b/content/upload/2023-11-03/1698981118219.webmanifest @@ -0,0 +1 @@ +{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file diff --git a/content/upload/2023-11-03/1698982084503.txt b/content/upload/2023-11-03/1698982084503.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698982084503.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698982126742.txt b/content/upload/2023-11-03/1698982126742.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698982126742.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698982168940.txt b/content/upload/2023-11-03/1698982168940.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698982168940.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698982280989.txt b/content/upload/2023-11-03/1698982280989.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698982280989.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698982946508.txt b/content/upload/2023-11-03/1698982946508.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698982946508.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698982998189.txt b/content/upload/2023-11-03/1698982998189.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698982998189.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698983054615.txt b/content/upload/2023-11-03/1698983054615.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698983054615.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698983054622.png b/content/upload/2023-11-03/1698983054622.png new file mode 100644 index 0000000..f6feb27 Binary files /dev/null and b/content/upload/2023-11-03/1698983054622.png differ diff --git a/content/upload/2023-11-03/1698983054651.webmanifest b/content/upload/2023-11-03/1698983054651.webmanifest new file mode 100644 index 0000000..45dc8a2 --- /dev/null +++ b/content/upload/2023-11-03/1698983054651.webmanifest @@ -0,0 +1 @@ +{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file diff --git a/content/upload/2023-11-03/1698993024969.txt b/content/upload/2023-11-03/1698993024969.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698993024969.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698993024971.png b/content/upload/2023-11-03/1698993024971.png new file mode 100644 index 0000000..ca661d1 Binary files /dev/null and b/content/upload/2023-11-03/1698993024971.png differ diff --git a/content/upload/2023-11-03/1698993024973.webmanifest b/content/upload/2023-11-03/1698993024973.webmanifest new file mode 100644 index 0000000..45dc8a2 --- /dev/null +++ b/content/upload/2023-11-03/1698993024973.webmanifest @@ -0,0 +1 @@ +{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file diff --git a/content/upload/2023-11-03/1698993024975.png b/content/upload/2023-11-03/1698993024975.png new file mode 100644 index 0000000..8a94bde Binary files /dev/null and b/content/upload/2023-11-03/1698993024975.png differ diff --git a/content/upload/2023-11-03/1698993024978.png b/content/upload/2023-11-03/1698993024978.png new file mode 100644 index 0000000..f6feb27 Binary files /dev/null and b/content/upload/2023-11-03/1698993024978.png differ diff --git a/content/upload/2023-11-03/1698996056135.txt b/content/upload/2023-11-03/1698996056135.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698996056135.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698996056138.png b/content/upload/2023-11-03/1698996056138.png new file mode 100644 index 0000000..f6feb27 Binary files /dev/null and b/content/upload/2023-11-03/1698996056138.png differ diff --git a/content/upload/2023-11-03/1698996056140.webmanifest b/content/upload/2023-11-03/1698996056140.webmanifest new file mode 100644 index 0000000..45dc8a2 --- /dev/null +++ b/content/upload/2023-11-03/1698996056140.webmanifest @@ -0,0 +1 @@ +{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file diff --git a/content/upload/2023-11-03/1698996120451.txt b/content/upload/2023-11-03/1698996120451.txt new file mode 100644 index 0000000..e694967 --- /dev/null +++ b/content/upload/2023-11-03/1698996120451.txt @@ -0,0 +1,6 @@ +This favicon was generated using the following font: + +- Font Title: Leckerli One +- Font Author: Copyright (c) 2011 Gesine Todt (www.gesine-todt.de hallo@gesine-todt.de), with Reserved Font Names "Leckerli" +- Font Source: http://fonts.gstatic.com/s/leckerlione/v20/V8mCoQH8VCsNttEnxnGQ-1itLZxcBtItFw.ttf +- Font License: SIL Open Font License, 1.1 (http://scripts.sil.org/OFL)) diff --git a/content/upload/2023-11-03/1698996120453.png b/content/upload/2023-11-03/1698996120453.png new file mode 100644 index 0000000..f6feb27 Binary files /dev/null and b/content/upload/2023-11-03/1698996120453.png differ diff --git a/content/upload/2023-11-03/1698996120454.webmanifest b/content/upload/2023-11-03/1698996120454.webmanifest new file mode 100644 index 0000000..45dc8a2 --- /dev/null +++ b/content/upload/2023-11-03/1698996120454.webmanifest @@ -0,0 +1 @@ +{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} \ No newline at end of file diff --git a/content/upload/2023-11-03/1698996242717.png b/content/upload/2023-11-03/1698996242717.png new file mode 100644 index 0000000..f6feb27 Binary files /dev/null and b/content/upload/2023-11-03/1698996242717.png differ diff --git a/src/storage/file/entities/file.entity.ts b/src/storage/file/entities/file.entity.ts index 232dd43..1e8d2b2 100644 --- a/src/storage/file/entities/file.entity.ts +++ b/src/storage/file/entities/file.entity.ts @@ -1,6 +1,7 @@ import { BaseEntity } from '@/database'; import { FileCategory } from '@/storage/fileCategory'; import { ApiHideProperty } from '@nestjs/swagger'; +import { Exclude } from 'class-transformer'; import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm'; @Entity({ orderBy: { id: 'DESC' } }) @@ -54,6 +55,13 @@ export class File extends BaseEntity { @Column({ comment: '文件后缀' }) extension: string; + /** + * 文件类型 + * @example 1 + */ + @Column({ comment: '类型(1: 文本,2: 图片,3: 音频,4: 视频,5: 其他)', nullable: true }) + type: number; + /** * 分类 */ @@ -66,6 +74,8 @@ export class File extends BaseEntity { * 分类ID * @example 0 */ + @Exclude() + @ApiHideProperty() @Column({ comment: '分类ID', nullable: true }) categoryId: number; } diff --git a/src/storage/file/file.service.ts b/src/storage/file/file.service.ts index b31a942..7dd355f 100644 --- a/src/storage/file/file.service.ts +++ b/src/storage/file/file.service.ts @@ -7,6 +7,9 @@ import { UpdateFileDto } from './dto/update-file.dto'; import { File } from './entities/file.entity'; import { FindFileDto } from './dto/find-file.dto'; import { FileCategoryService } from '../fileCategory'; +import { createReadStream } from 'fs'; +import { createHash } from 'crypto'; +import { getTypeByMimetype } from './util'; @Injectable() export class FileService extends BaseService { @@ -23,13 +26,17 @@ export class FileService extends BaseService { * @returns */ async create(uploadFile: Express.Multer.File) { - const { originalname: name, mimetype, size, path: hash } = uploadFile; - const relativePath = relative(this.config.uploadDir, uploadFile.path).split(sep).join('/'); - const path = `${this.config.uploadPrefix}/${relativePath}`; + const { originalname: name, mimetype, size } = uploadFile; + const { uploadDir, uploadPrefix } = this.config; + const relativePath = relative(uploadDir, uploadFile.path).split(sep).join('/'); + const path = `${uploadPrefix}/${relativePath}`; const extension = extname(uploadFile.originalname); const description = ''; + const hash = await this.hashByFilePath(uploadFile.path); + const type = getTypeByMimetype(mimetype) const file = this.repository.create({ name, + type, mimetype, size, hash, @@ -41,7 +48,28 @@ export class FileService extends BaseService { return file.id; } - findMany(findFileDto: FindFileDto) { + /** + * 从文件路径读取流,进行MD5哈希 + * @param path 文件路径 + * @returns + */ + hashByFilePath(path: string): Promise { + const hash = createHash('md5'); + const stream = createReadStream(path); + return new Promise((res, rej) => { + stream.on('data', (chunk) => { + hash.update(chunk); + }); + stream.on('end', () => { + res(hash.digest('hex')); + }); + stream.on('error', () => { + rej('获取文件哈希值失败'); + }); + }); + } + + async findMany(findFileDto: FindFileDto) { const { page, size, name, categoryId } = findFileDto; const { skip, take } = this.formatPagination(page, size, true); const where: FindOptionsWhere = {}; @@ -51,7 +79,20 @@ export class FileService extends BaseService { if (categoryId) { where.categoryId = categoryId; } - return this.repository.findAndCount({ skip, take, where }); + return this.repository.findAndCount({ + skip, + take, + where, + relations: { + category: true, + }, + select: { + category: { + id: true, + name: true, + }, + }, + }); } findOne(id: number) { diff --git a/src/storage/file/util.ts b/src/storage/file/util.ts new file mode 100644 index 0000000..6d7e235 --- /dev/null +++ b/src/storage/file/util.ts @@ -0,0 +1,30 @@ +/** + * 文件类型 + */ +enum FileType { + /** + * 文本 + */ + TEXT = 1, + /** + * 图片 + */ + IMAGE = 2, + /** + * 音频 + */ + AUDIO = 3, + /** + * 视频 + */ + VIDEO = 4, + /** + * 其他 + */ + OTHER = 5, +} + +export function getTypeByMimetype(mimetype: string) { + const [type] = mimetype.split('/'); + return FileType[type.toLowerCase()] ?? FileType.OTHER; +} diff --git a/src/system/role/dto/create-role.dto.ts b/src/system/role/dto/create-role.dto.ts index 253d7c2..e7689a1 100644 --- a/src/system/role/dto/create-role.dto.ts +++ b/src/system/role/dto/create-role.dto.ts @@ -29,5 +29,5 @@ export class CreateRoleDto { */ @IsOptional() @IsInt({ each: true }) - menuIds: number[]; + menuIds?: number[]; } diff --git a/src/system/role/entities/role.entity.ts b/src/system/role/entities/role.entity.ts index ceca027..41034dd 100644 --- a/src/system/role/entities/role.entity.ts +++ b/src/system/role/entities/role.entity.ts @@ -43,6 +43,7 @@ export class Role extends BaseEntity { /** * 菜单ID数组 + * @example [1] */ @RelationId('menus') menuIds: number[];