Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';

export class DeleteFileEntity {
@ApiProperty({ type: String, example: 'path/to/file.jpg' })
path: string;
}
15 changes: 11 additions & 4 deletions apps/server/rest/src/modules/files/entities/detail-file.entity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';

export class DetailFileEntity {
@ApiProperty({ type: String, example: 'images' })
path: string;
/** 재귀적으로 탐색한 파일 수 */

@ApiProperty({ type: Number, example: 42 })
fileCount: number;
Comment on lines +7 to 8
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

기존에 존재하던 JSDoc 설명이 삭제되었습니다. Swagger UI에서도 해당 설명이 노출될 수 있도록 @ApiPropertydescription 속성을 사용하는 것이 좋습니다.

Suggested change
@ApiProperty({ type: Number, example: 42 })
fileCount: number;
@ApiProperty({ type: Number, example: 42, description: '재귀적으로 탐색한 파일 수' })
fileCount: number;

/** 재귀적으로 탐색한 하위 디렉토리 수 (루트 제외) */

@ApiProperty({ type: Number, example: 5 })
directoryCount: number;
Comment on lines +10 to 11
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

기존에 존재하던 JSDoc 설명이 삭제되었습니다. Swagger UI에서도 해당 설명이 노출될 수 있도록 @ApiPropertydescription 속성을 사용하는 것이 좋습니다.

Suggested change
@ApiProperty({ type: Number, example: 5 })
directoryCount: number;
@ApiProperty({ type: Number, example: 5, description: '재귀적으로 탐색한 하위 디렉토리 수 (루트 제외)' })
directoryCount: number;

/** 자식이 없는 leaf 노드 수 (파일 + 빈 디렉토리) */

@ApiProperty({ type: Number, example: 44 })
leafCount: number;
Comment on lines +13 to 14
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

기존에 존재하던 JSDoc 설명이 삭제되었습니다. Swagger UI에서도 해당 설명이 노출될 수 있도록 @ApiPropertydescription 속성을 사용하는 것이 좋습니다.

Suggested change
@ApiProperty({ type: Number, example: 44 })
leafCount: number;
@ApiProperty({ type: Number, example: 44, description: '자식이 없는 leaf 노드 수 (파일 + 빈 디렉토리)' })
leafCount: number;

/** 모든 파일 크기의 합계 (byte) */

@ApiProperty({ type: Number, example: 10485760 })
totalSize: number;
Comment on lines +16 to 17
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

기존에 존재하던 JSDoc 설명이 삭제되었습니다. Swagger UI에서도 해당 설명이 노출될 수 있도록 @ApiPropertydescription 속성을 사용하는 것이 좋습니다.

Suggested change
@ApiProperty({ type: Number, example: 10485760 })
totalSize: number;
@ApiProperty({ type: Number, example: 10485760, description: '모든 파일 크기의 합계 (byte)' })
totalSize: number;

}
35 changes: 33 additions & 2 deletions apps/server/rest/src/modules/files/entities/read-file.entity.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,51 @@
import { ApiProperty } from '@nestjs/swagger';

export class ReadFileEntity {
@ApiProperty({ type: String, example: 'example.jpg' })
name: string;

@ApiProperty({ type: String, example: 'test' })
parentPath: string;

@ApiProperty({ type: String, example: 'test/example.jpg' })
path: string;

@ApiProperty({ type: Boolean, example: true })
isFile: boolean;

@ApiProperty({ type: Boolean, example: false })
isDirectory: boolean;

@ApiProperty({ type: Boolean, example: false })
isBlockDevice: boolean;

@ApiProperty({ type: Boolean, example: false })
isCharacterDevice: boolean;

@ApiProperty({ type: Boolean, example: false })
isSymbolicLink: boolean;

@ApiProperty({ type: Boolean, example: false })
isFIFO: boolean;

@ApiProperty({ type: Boolean, example: false })
isSocket: boolean;

@ApiProperty({ type: Number, example: 1741684171704 })
birthtimeMs: number;

@ApiProperty({ type: Number, example: 1741684171704 })
ctimeMs: number;

@ApiProperty({ type: Number, example: 1741684171704 })
mtimeMs: number;
/** byte */

@ApiProperty({ type: Number, nullable: true, example: 123 })
size: number | null;
Comment on lines +43 to 44
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

기존에 존재하던 JSDoc 설명이 삭제되었습니다. Swagger UI에서도 해당 설명이 노출될 수 있도록 @ApiPropertydescription 속성을 사용하는 것이 좋습니다.

Suggested change
@ApiProperty({ type: Number, nullable: true, example: 123 })
size: number | null;
@ApiProperty({ type: Number, nullable: true, example: 123, description: 'byte' })
size: number | null;


@ApiProperty({ type: Number, example: 33188 })
mode: number;
/** 디렉토리인 경우 직속 자식 수, 파일인 경우 null */

@ApiProperty({ type: Number, nullable: true, example: 3 })
childCount: number | null;
Comment on lines +49 to 50
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

기존에 존재하던 JSDoc 설명이 삭제되었습니다. Swagger UI에서도 해당 설명이 노출될 수 있도록 @ApiPropertydescription 속성을 사용하는 것이 좋습니다.

Suggested change
@ApiProperty({ type: Number, nullable: true, example: 3 })
childCount: number | null;
@ApiProperty({ type: Number, nullable: true, example: 3, description: '디렉토리인 경우 직속 자식 수, 파일인 경우 null' })
childCount: number | null;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';

export class UpdateFileEntity {
@ApiProperty({ type: String, example: 'path/new' })
path: string;

@ApiProperty({ type: String, example: 'new-example.jpg' })
filename: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';

export class UploadFileEntity {
@ApiProperty({ type: String, example: './test/uploads/path/to/example.jpg' })
filePath: string;

@ApiProperty({ type: String, example: 'https://static.zerovoyage.com/path/to/example.jpg' })
publicUrl: string;
}
76 changes: 24 additions & 52 deletions apps/server/rest/src/modules/files/files.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ import {
UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiOkResponse, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
import {
ApiBearerAuth,
ApiBody,
ApiConsumes,
ApiExtraModels,
ApiOkResponse,
ApiOperation,
ApiQuery,
ApiTags,
getSchemaPath,
} from '@nestjs/swagger';

import { AdminGuard } from '@server-rest/auth/guards/admin.guard';
import { JwtAuthGuard } from '@server-rest/auth/guards/jwt-auth.guard';
Expand All @@ -42,6 +52,7 @@ import {
@LogMetadata({ module: 'files', importance: 'high' })
@UseGuards(JwtAuthGuard, AdminGuard)
@ApiBearerAuth()
@ApiExtraModels(ReadFileEntity, DetailFileEntity, UploadFileEntity, UpdateFileEntity, DeleteFileEntity)
export class FilesController {
constructor(
@Inject(FilesService) private readonly filesService: FilesService,
Expand Down Expand Up @@ -77,16 +88,11 @@ export class FilesController {
description: 'File uploaded successfully',
schema: {
type: 'object',
required: ['status', 'message', 'data'],
properties: {
status: { type: 'number', example: HttpStatus.CREATED },
message: { type: 'string', example: 'success' },
data: {
type: 'object',
properties: {
filePath: { type: 'string', example: './test/uploads/path/to/example.jpg' },
publicUrl: { type: 'string', example: 'http://localhost:3000/test/uploads/path/to/example.jpg' },
},
},
data: { $ref: getSchemaPath(UploadFileEntity) },
},
},
})
Expand Down Expand Up @@ -136,11 +142,13 @@ export class FilesController {
description: 'Directory created successfully',
schema: {
type: 'object',
required: ['status', 'message', 'data'],
properties: {
status: { type: 'number', example: HttpStatus.CREATED },
message: { type: 'string', example: 'success' },
data: {
type: 'object',
required: ['path'],
properties: {
path: { type: 'string', example: 'path-to' },
},
Expand Down Expand Up @@ -198,19 +206,11 @@ export class FilesController {
description: 'Folder detail retrieved successfully',
schema: {
type: 'object',
required: ['status', 'message', 'data'],
properties: {
status: { type: 'number', example: HttpStatus.OK },
message: { type: 'string', example: 'success' },
data: {
type: 'object',
properties: {
path: { type: 'string', example: 'images' },
fileCount: { type: 'number', example: 42 },
directoryCount: { type: 'number', example: 5 },
leafCount: { type: 'number', example: 44 },
totalSize: { type: 'number', example: 10485760 },
},
},
data: { $ref: getSchemaPath(DetailFileEntity) },
},
},
})
Expand Down Expand Up @@ -244,32 +244,13 @@ export class FilesController {
description: 'File list retrieved successfully',
schema: {
type: 'object',
required: ['status', 'message', 'data'],
properties: {
status: { type: 'number', example: HttpStatus.OK },
message: { type: 'string', example: 'success' },
data: {
type: 'array',
items: {
type: 'object',
properties: {
name: { type: 'string', example: 'example.jpg' },
parentPath: { type: 'string', example: 'test' },
path: { type: 'string', example: 'test/example.jpg' },
isFile: { type: 'boolean', example: true },
isDirectory: { type: 'boolean', example: false },
isBlockDevice: { type: 'boolean', example: false },
isCharacterDevice: { type: 'boolean', example: false },
isSymbolicLink: { type: 'boolean', example: false },
isFIFO: { type: 'boolean', example: false },
isSocket: { type: 'boolean', example: false },
birthtimeMs: { type: 'number', example: 1741684171704.64 },
ctimeMs: { type: 'number', example: 1741684171704.64 },
mtimeMs: { type: 'number', example: 1741684171704.64 },
size: { type: 'number', example: 123 },
mode: { type: 'number', example: 33188 },
childCount: { type: 'number', nullable: true, example: 3 },
},
},
items: { $ref: getSchemaPath(ReadFileEntity) },
},
},
},
Expand Down Expand Up @@ -314,16 +295,11 @@ export class FilesController {
description: 'File renamed successfully',
schema: {
type: 'object',
required: ['status', 'message', 'data'],
properties: {
status: { type: 'number', example: HttpStatus.OK },
message: { type: 'string', example: 'success' },
data: {
type: 'object',
properties: {
path: { type: 'string', example: './test/uploads/path/new' },
filename: { type: 'string', example: 'new-example.jpg' },
},
},
data: { $ref: getSchemaPath(UpdateFileEntity) },
},
},
})
Expand Down Expand Up @@ -399,15 +375,11 @@ export class FilesController {
description: 'File deleted successfully',
schema: {
type: 'object',
required: ['status', 'message', 'data'],
properties: {
status: { type: 'number', example: HttpStatus.OK },
message: { type: 'string', example: 'success' },
data: {
type: 'object',
properties: {
path: { type: 'string', example: './test/uploads/test' },
},
},
data: { $ref: getSchemaPath(DeleteFileEntity) },
},
},
})
Expand Down
Loading