Skip to content

Commit eba2482

Browse files
committed
Merge branch 'development'
2 parents 5f0cc6b + 14b594b commit eba2482

File tree

15 files changed

+158
-64
lines changed

15 files changed

+158
-64
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
.env.*
88
!**/**/.env.example
99

10-
.vscode
10+
.vscode

infrastructure/Pulumi.production.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
config:
22
aws:region: ap-northeast-2
33
velog:DOCKER_ENV: production
4-
velog:target: server
4+
velog:target: server,web

infrastructure/Pulumi.stage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
config:
22
aws:region: ap-northeast-2
33
velog:DOCKER_ENV: stage
4-
velog:target: server
4+
velog:target: web

packages/velog-cron/src/services/StatsService/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class StatsService implements Service {
3939
`[Daily]\n기간: ${format(
4040
start,
4141
'yyyy-MM-dd',
42-
)}}\n${usersCount}명의 사용자가 가입했습니다.\n${postCount}개의 공개 포스트가 작성되었습니다.`,
42+
)}\n${usersCount}명의 사용자가 가입했습니다.\n${postCount}개의 공개 포스트가 작성되었습니다.`,
4343
)
4444
}
4545
public async weekly() {

packages/velog-server/src/common/plugins/global/authPlugin.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,35 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
1919
const authorization = request.headers['authorization']
2020

2121
try {
22-
if (!accessToken && authorization) {
22+
if (!accessToken && !!authorization && typeof authorization === 'string') {
2323
accessToken = authorization.split('Bearer ')[1]
2424
}
2525

2626
if (!accessToken && !refreshToken) return
2727

28-
if (accessToken && refreshToken) {
28+
if (accessToken) {
2929
const accessTokenData = await jwt.decodeToken<AccessTokenData>(accessToken)
3030

3131
const diff = accessTokenData.exp * 1000 - new Date().getTime()
3232
// refresh token when life < 30mins
3333
if (diff < Time.ONE_MINUTE_IN_MS * 30 && refreshToken) {
3434
await userService.restoreToken({ request, reply })
3535
}
36+
37+
request.user = { id: accessTokenData.user_id }
38+
return
3639
}
3740

3841
if (!accessToken && refreshToken) {
3942
const tokens = await userService.restoreToken({ request, reply })
4043
accessToken = tokens.accessToken
41-
}
4244

43-
if (!accessToken) return
45+
const accessTokenData = await jwt.decodeToken<AccessTokenData>(accessToken)
46+
request.user = { id: accessTokenData.user_id }
47+
return
48+
}
4449

45-
const accessTokenData = await jwt.decodeToken<AccessTokenData>(accessToken)
46-
request.user = { id: accessTokenData.user_id }
50+
request.user = null
4751
} catch (e) {
4852
console.log('accessToken', accessToken)
4953
console.log('authPlugin error', e)
@@ -55,10 +59,9 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
5559

5660
const accessTokenData = await jwt.decodeToken<AccessTokenData>(accessToken)
5761
request.user = { id: accessTokenData.user_id }
58-
} else {
59-
throw new Error()
6062
}
6163
} catch (error) {
64+
console.log('refresh token error', error)
6265
const cookie = container.resolve(CookieService)
6366
cookie.clearCookie(reply, 'access_token')
6467
cookie.clearCookie(reply, 'refresh_token')

packages/velog-server/src/lib/discord/DiscordService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export class DiscordService {
3030
'canceling statement',
3131
'Not allow origin',
3232
'Unknown query',
33+
'ECONNRESET',
34+
'https://oauth2.googleapis.com',
35+
'/api/posts/v1/score',
3336
]
3437
const isFrequentWordIncluded = frequentWord.some((word) => message.includes(word))
3538

packages/velog-server/src/services/PostLikeService/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ export class PostLikeService implements Service {
120120
await this.postService.updatePostScore(postId)
121121
}
122122

123-
setTimeout(() => {
123+
setTimeout(async () => {
124124
try {
125-
this.searchService.searchSync.update(post.id)
125+
await this.searchService.searchSync.update(post.id)
126126
} catch (error) {
127127
console.log('likePost searchSync update error', error)
128128
}
@@ -190,9 +190,9 @@ export class PostLikeService implements Service {
190190
})
191191

192192
await this.postService.updatePostScore(postId)
193-
setTimeout(() => {
193+
setTimeout(async () => {
194194
try {
195-
this.searchService.searchSync.update(post.id)
195+
await this.searchService.searchSync.update(post.id)
196196
} catch (error) {
197197
console.log('unlikePost searchSync update error', error)
198198
}

packages/velog-server/src/services/PostService/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class PostService implements Service {
291291
id: true,
292292
},
293293
orderBy: {
294-
[timeframe === 'year' ? 'likes' : 'score']: 'desc',
294+
score: 'desc',
295295
},
296296
take: limit,
297297
skip: offset,
@@ -403,15 +403,17 @@ export class PostService implements Service {
403403
}
404404
}
405405
public async updatePostScore(postId: string) {
406-
await axios.patch(
407-
`${ENV.cronHost}/api/posts/v1/score/${postId}`,
408-
{},
409-
{
410-
headers: {
411-
'Cron-Api-Key': ENV.cronApiKey,
406+
try {
407+
await axios.patch(
408+
`${ENV.cronHost}/api/posts/v1/score/${postId}`,
409+
{},
410+
{
411+
headers: {
412+
'Cron-Api-Key': ENV.cronApiKey,
413+
},
412414
},
413-
},
414-
)
415+
)
416+
} catch (_) {}
415417
}
416418
public shortDescription(post: Post): string {
417419
if (post.short_description) return post.short_description

packages/velog-server/src/services/TagService/index.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,25 @@ export class TagService implements Service {
164164
if (tag) return tag
165165

166166
const filtered = this.utils.escapeForUrl(name).toLowerCase()
167-
const freshTag = await this.db.tag.create({
168-
data: {
169-
name,
170-
name_filtered: filtered,
171-
},
172-
})
173-
174-
return freshTag
167+
try {
168+
const freshTag = await this.db.tag.create({
169+
data: {
170+
name,
171+
name_filtered: filtered,
172+
},
173+
})
174+
return freshTag
175+
} catch (error) {
176+
console.log('create tag error', error)
177+
console.log('name', name)
178+
console.log('name_filtered', filtered)
179+
const tag = await this.db.tag.findFirst({
180+
where: {
181+
name: name,
182+
},
183+
})
184+
return tag!
185+
}
175186
}
176187
}
177188

packages/velog-server/src/services/UserService/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class UserService implements Service {
123123
public async updateLastAccessedAt(userId?: string): Promise<void> {
124124
if (!userId) return
125125
try {
126-
await this.db.userProfile.update({
126+
await this.db.userProfile.updateMany({
127127
where: {
128128
fk_user_id: userId,
129129
},

packages/velog-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"html-react-parser": "^5.0.6",
4444
"inquirer": "^9.2.7",
4545
"nanoid": "^4.0.2",
46-
"next": "^14.1.0",
46+
"next": "14.1.0",
4747
"postcss-flexbugs-fixes": "^5.0.2",
4848
"postcss-preset-env": "^8.5.0",
4949
"prismjs": "^1.29.0",

packages/velog-web/src/features/velog/components/VelogFollowings/VelogFollowings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function VelogFollowings({ username }: Props) {
1616

1717
useInfiniteScroll(ref, fetchMore)
1818

19-
if (isLoading || isFetching) return <VelogFollowListSkeleton />
19+
if (isLoading) return <VelogFollowListSkeleton />
2020
if (followings.length === 0) return <VelogFollowingsEmpty />
2121
return (
2222
<>

packages/velog-web/src/graphql/helpers/generated.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ export type CreateNotificationInput = {
104104
type: NotificationType
105105
}
106106

107+
export type EditPostInput = {
108+
body: Scalars['String']['input']
109+
id: Scalars['ID']['input']
110+
is_markdown: Scalars['Boolean']['input']
111+
is_private: Scalars['Boolean']['input']
112+
is_temp: Scalars['Boolean']['input']
113+
meta: Scalars['JSON']['input']
114+
series_id?: InputMaybe<Scalars['ID']['input']>
115+
tags: Array<Scalars['String']['input']>
116+
thumbnail?: InputMaybe<Scalars['String']['input']>
117+
title: Scalars['String']['input']
118+
token?: InputMaybe<Scalars['String']['input']>
119+
url_slug: Scalars['String']['input']
120+
}
121+
107122
export type FeedPostsInput = {
108123
limit?: InputMaybe<Scalars['PositiveInt']['input']>
109124
offset?: InputMaybe<Scalars['Int']['input']>
@@ -187,16 +202,17 @@ export type Mutation = {
187202
acceptIntegration: Scalars['String']['output']
188203
confirmChangeEmail: Maybe<Scalars['Void']['output']>
189204
createNotification: Notification
205+
editPost: Post
190206
follow: Maybe<Scalars['Boolean']['output']>
191207
initiateChangeEmail: Maybe<Scalars['Void']['output']>
192-
likePost: Maybe<Post>
208+
likePost: Post
193209
logout: Maybe<Scalars['Void']['output']>
194210
readAllNotifications: Maybe<Scalars['Void']['output']>
195211
readNotification: Maybe<Scalars['Void']['output']>
196212
removeAllNotifications: Maybe<Scalars['Void']['output']>
197213
sendMail: Maybe<SendMailResponse>
198214
unfollow: Maybe<Scalars['Boolean']['output']>
199-
unlikePost: Maybe<Post>
215+
unlikePost: Post
200216
unregister: Maybe<Scalars['Void']['output']>
201217
updateAbout: Maybe<UserProfile>
202218
updateEmailRules: Maybe<UserMeta>
@@ -205,6 +221,7 @@ export type Mutation = {
205221
updateSocialInfo: Maybe<UserProfile>
206222
updateThumbnail: Maybe<UserProfile>
207223
updateVelogTitle: Maybe<VelogConfig>
224+
writePost: Post
208225
}
209226

210227
export type MutationConfirmChangeEmailArgs = {
@@ -215,6 +232,10 @@ export type MutationCreateNotificationArgs = {
215232
input: CreateNotificationInput
216233
}
217234

235+
export type MutationEditPostArgs = {
236+
input: EditPostInput
237+
}
238+
218239
export type MutationFollowArgs = {
219240
input: FollowInput
220241
}
@@ -271,6 +292,10 @@ export type MutationUpdateVelogTitleArgs = {
271292
input: UpdateVelogTitleInput
272293
}
273294

295+
export type MutationWritePostArgs = {
296+
input: WritePostInput
297+
}
298+
274299
export type Notification = {
275300
action: Scalars['JSON']['output']
276301
action_id: Maybe<Scalars['ID']['output']>
@@ -611,6 +636,7 @@ export type User = {
611636
id: Scalars['ID']['output']
612637
is_certified: Scalars['Boolean']['output']
613638
is_followed: Scalars['Boolean']['output']
639+
is_trusted: Scalars['Boolean']['output']
614640
profile: UserProfile
615641
series_list: Array<Series>
616642
updated_at: Scalars['DateTimeISO']['output']
@@ -656,6 +682,20 @@ export type VelogConfig = {
656682
title: Maybe<Scalars['String']['output']>
657683
}
658684

685+
export type WritePostInput = {
686+
body: Scalars['String']['input']
687+
is_markdown: Scalars['Boolean']['input']
688+
is_private: Scalars['Boolean']['input']
689+
is_temp: Scalars['Boolean']['input']
690+
meta: Scalars['JSON']['input']
691+
series_id?: InputMaybe<Scalars['ID']['input']>
692+
tags: Array<Scalars['String']['input']>
693+
thumbnail?: InputMaybe<Scalars['String']['input']>
694+
title: Scalars['String']['input']
695+
token?: InputMaybe<Scalars['String']['input']>
696+
url_slug: Scalars['String']['input']
697+
}
698+
659699
export type AdsQueryVariables = Exact<{
660700
input: AdsInput
661701
}>

packages/velog-web/src/prefetch/getCurrentUser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default async function getCurrentUser() {
66
try {
77
const headers = {}
88
const token = getAccessToken()
9+
910
if (token) {
1011
Object.assign(headers, { authorization: `Bearer ${token.value}` })
1112
}

0 commit comments

Comments
 (0)