Skip to content

Commit 19dff99

Browse files
committed
πŸ› fix: coderabbit μ½”λ“œ 리뷰 반영
1 parent d4e6d35 commit 19dff99

File tree

12 files changed

+45
-40
lines changed

12 files changed

+45
-40
lines changed

β€Žserver/src/file/controller/file.controller.tsβ€Ž

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class FileController {
4141
validators: [
4242
new MaxFileSizeValidator({
4343
maxSize: FILE_SIZE_LIMITS.IMAGE,
44-
message: 'file size limit',
44+
message: `File size must not exceed ${FILE_SIZE_LIMITS.IMAGE / (1024 * 1024)}MB`,
4545
}),
4646
new FileTypeValidator({
4747
fileType: /image\/(png|jpg|jpeg|webp|gif)/,
@@ -54,11 +54,9 @@ export class FileController {
5454
@Query() query: UploadFileQueryRequestDto,
5555
@CurrentUser() user: Payload,
5656
) {
57-
file.path = await this.fileService.handleUpload(file, query.uploadType);
58-
5957
return ApiResponse.responseWithData(
6058
'파일 μ—…λ‘œλ“œμ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€.',
61-
await this.fileService.create(file, user.id),
59+
await this.fileService.handleUpload(file, query.uploadType, user.id),
6260
);
6361
}
6462

β€Žserver/src/file/service/file.service.tsβ€Ž

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export class FileService {
1818
private readonly logger: WinstonLoggerService,
1919
) {}
2020

21-
async handleUpload(file: Express.Multer.File, uploadType: FileUploadType) {
21+
async handleUpload(
22+
file: Express.Multer.File,
23+
uploadType: FileUploadType,
24+
userId: number,
25+
) {
2226
const today = this.getDateString();
2327
const targetDir = path.join(this.basePath, uploadType, today);
2428

@@ -30,7 +34,17 @@ export class FileService {
3034

3135
await fs.writeFile(filePath, file.buffer);
3236

33-
return filePath;
37+
const { originalname, mimetype, size } = file;
38+
const savedFile = await this.fileRepository.save({
39+
originalName: originalname,
40+
mimetype,
41+
size,
42+
path: filePath,
43+
user: { id: userId },
44+
});
45+
const accessUrl = this.generateAccessUrl(filePath);
46+
47+
return UploadFileResponseDto.toResponseDto(savedFile, accessUrl);
3448
}
3549

3650
private async ensureDirectory(dir: string) {
@@ -42,23 +56,6 @@ export class FileService {
4256
return now.toISOString().split('T')[0];
4357
}
4458

45-
async create(
46-
file: Express.Multer.File,
47-
userId: number,
48-
): Promise<UploadFileResponseDto> {
49-
const { originalname, mimetype, size, path } = file;
50-
const savedFile = await this.fileRepository.save({
51-
originalName: originalname,
52-
mimetype,
53-
size,
54-
path,
55-
user: { id: userId },
56-
});
57-
const accessUrl = this.generateAccessUrl(path);
58-
59-
return UploadFileResponseDto.toResponseDto(savedFile, accessUrl);
60-
}
61-
6259
private generateAccessUrl(filePath: string): string {
6360
return filePath.replace(this.basePath, '/objects');
6461
}

β€Žserver/src/user/provider/github.provider.tsβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class GithubOAuthProvider implements OAuthProvider {
6565
scope,
6666
};
6767
} catch (error) {
68-
this.logger.error(`Oauth 둜그인 쀑 μ—λŸ¬ λ°œμƒ, ${error}`);
68+
this.logger.error(`Failed to fetch token info from GitHub: ${error}`);
6969
throw new BadGatewayException(
7070
'ν˜„μž¬ μ™ΈλΆ€ μ„œλΉ„μŠ€μ™€μ˜ 연결에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.',
7171
);
@@ -93,6 +93,7 @@ export class GithubOAuthProvider implements OAuthProvider {
9393
picture: avatar_url,
9494
} as UserInfo;
9595
} catch (error) {
96+
this.logger.error(`Failed to fetch user info from GitHub: ${error}`);
9697
throw new BadGatewayException(
9798
'ν˜„μž¬ μ™ΈλΆ€ μ„œλΉ„μŠ€μ™€μ˜ 연결에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.',
9899
);

β€Žserver/src/user/provider/google.provider.tsβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import {
88
UserInfo,
99
} from '../constant/oauth.constant';
1010
import axios from 'axios';
11+
import { WinstonLoggerService } from '../../common/logger/logger.service';
1112

1213
@Injectable()
1314
export class GoogleOAuthProvider implements OAuthProvider {
15+
constructor(private readonly logger: WinstonLoggerService) {}
16+
1417
getAuthUrl() {
1518
const googleOAuthUrl = OAUTH_URL_PATH.GOOGLE.AUTH_URL;
1619

@@ -66,6 +69,7 @@ export class GoogleOAuthProvider implements OAuthProvider {
6669
expires_in,
6770
};
6871
} catch (error) {
72+
this.logger.error(`Failed to fetch token info from Google: ${error}`);
6973
throw new BadGatewayException(
7074
'ν˜„μž¬ μ™ΈλΆ€ μ„œλΉ„μŠ€μ™€μ˜ 연결에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.',
7175
);
@@ -93,6 +97,7 @@ export class GoogleOAuthProvider implements OAuthProvider {
9397
picture,
9498
} as UserInfo;
9599
} catch (error) {
100+
this.logger.error(`Failed to fetch user info from Google: ${error}`);
96101
throw new BadGatewayException(
97102
'ν˜„μž¬ μ™ΈλΆ€ μ„œλΉ„μŠ€μ™€μ˜ 연결에 μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.',
98103
);

β€Žserver/test/feed/e2e/up-view-count.e2e-spec.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe(`POST ${URL}/{feedId} E2E Test`, () => {
131131
});
132132
const savedFeedReadRedis = await redisService.sismember(
133133
redisKeyMake(feed.id.toString()),
134-
testIp,
134+
testNewIp,
135135
);
136136

137137
// DB, Redis then

β€Žserver/test/file/e2e/delete.e2e-spec.tsβ€Ž

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ describe(`DELETE ${URL}/{fileId} E2E Test`, () => {
5656
expect(data).toBeUndefined();
5757
});
5858

59-
it('[200] DBμ—μ„œ νŒŒμΌμ„ μ‚­μ œν–ˆμ§€λ§Œ FS 라이브러리λ₯Ό ν†΅ν•΄μ„œ μ‹€νŒ¨ν–ˆμ„ κ²½μš°μ— μ„œλΉ„μŠ€μ—μ„œ 파일 μ‚­μ œλ₯Ό μ„±κ³΅ν•œλ‹€.', async () => {
59+
it('[200] DBμ—μ„œ νŒŒμΌμ„ μ‚­μ œν–ˆμ§€λ§Œ FS 라이브러리의 μ‚­μ œ 문제일 κ²½μš°μ— μ„œλΉ„μŠ€μ—μ„œ 파일 μ‚­μ œλ₯Ό μ„±κ³΅ν•œλ‹€.', async () => {
6060
// given
6161
file = await fileRepository.save(FileFixture.createFileFixture({ user }));
6262
const fs = await import('fs/promises');
63-
jest.spyOn(fs, 'access').mockResolvedValue(undefined);
63+
jest
64+
.spyOn(fs, 'unlink')
65+
.mockRejectedValue(new Error('EACCES: permission denied'));
6466

6567
const accessToken = createAccessToken(user);
6668

@@ -82,12 +84,14 @@ describe(`DELETE ${URL}/{fileId} E2E Test`, () => {
8284
// DB, Redis then
8385
expect(savedFile).toBeNull();
8486
});
85-
86-
it('[200] DBμ—μ„œ νŒŒμΌμ„ μ‚­μ œν–ˆμ§€λ§Œ FS λΌμ΄λΈŒλŸ¬λ¦¬μ—μ„œ κΆŒν•œ 문제일 경우 μ„œλΉ„μŠ€μ—μ„œ 파일 μ‚­μ œλ₯Ό μ„±κ³΅ν•œλ‹€.', async () => {
87+
it('[200] DBμ—μ„œ νŒŒμΌμ„ μ‚­μ œν–ˆμ§€λ§Œ FS 라이브러리의 μ ‘κ·Ό 문제일 경우 μ„œλΉ„μŠ€μ—μ„œ 파일 μ‚­μ œλ₯Ό μ„±κ³΅ν•œλ‹€.', async () => {
8788
// given
8889
file = await fileRepository.save(FileFixture.createFileFixture({ user }));
8990
const fs = await import('fs/promises');
90-
jest.spyOn(fs, 'unlink').mockResolvedValue(undefined);
91+
jest
92+
.spyOn(fs, 'access')
93+
.mockRejectedValue(new Error('EACCES: permission denied'));
94+
9195
const accessToken = createAccessToken(user);
9296

9397
// Http when

β€Žserver/test/file/e2e/upload.e2e-spec.tsβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,13 @@ describe(`POST ${URL} E2E Test`, () => {
104104

105105
// DB, Redis when
106106
const savedFile = await fileRepository.findOneBy({
107-
originalName: 'test.png',
108-
mimetype: 'image/png',
107+
originalName: 'test.txt',
108+
mimetype: 'text/plain',
109109
});
110110

111111
// DB, Redis then
112112
expect(savedFile).toBeNull();
113113
});
114-
115114
it('[400] 파일 크기가 μΌμΉ˜ν•˜μ§€ μ•Šμ„ 경우 파일 μ—…λ‘œλ“œλ₯Ό μ‹€νŒ¨ν•œλ‹€. ', async () => {
116115
// given
117116
const requestDto = new UploadFileQueryRequestDto({

β€Žserver/test/oauth/e2e/callback.e2e-spec.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe(`GET ${URL} E2E Test`, () => {
5858
// DB, Redis when
5959
const savedProvider = await providerRepository.findOneBy({
6060
providerUserId: '1',
61-
providerType: 'github',
61+
providerType: OAuthType.Github,
6262
});
6363

6464
// DB, Redis then
@@ -104,7 +104,7 @@ describe(`GET ${URL} E2E Test`, () => {
104104
// DB, Redis when
105105
const savedProvider = await providerRepository.findOneBy({
106106
providerUserId: '1',
107-
providerType: 'google',
107+
providerType: OAuthType.Google,
108108
});
109109

110110
// DB, Redis then

β€Žserver/test/rss/e2e/history/reject.e2e-spec.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ describe(`GET ${URL} E2E Test`, () => {
2121
agent = supertest(app.getHttpServer());
2222
const rssRejectRepository = app.get(RssRejectRepository);
2323
const redisService = app.get(RedisService);
24-
const rssAccepts = Array.from({ length: 2 }).map((_, i) =>
24+
const rssRejects = Array.from({ length: 2 }).map((_, i) =>
2525
RssRejectFixture.createRssRejectFixture({}, i),
2626
);
2727
[rssRejectList] = await Promise.all([
28-
rssRejectRepository.save(rssAccepts),
28+
rssRejectRepository.save(rssRejects),
2929
redisService.set(redisKeyMake(sessionKey), 'test1234'),
3030
]);
3131
rssRejectList.reverse();

β€Žserver/test/user/e2e/certificate.e2e-spec.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe(`POST ${URL} E2E Test`, () => {
7070

7171
// DB, Redis then
7272
expect(savedRegisterCode).toBeNull();
73-
expect(savedUser).not.toBeUndefined();
73+
expect(savedUser).not.toBeNull();
7474
expect(
7575
await bcrypt.compare(
7676
UserFixture.GENERAL_USER.password,

0 commit comments

Comments
Β (0)