@@ -18,7 +18,7 @@ import { SeriesService } from '@services/SeriesService/index.js'
18
18
import { SearchService } from '@services/SearchService/index.js'
19
19
import { ExternalIntegrationService } from '@services/ExternalIntegrationService/index.js'
20
20
import { PostService } from '@services/PostService/index.js'
21
- import { RedisService } from '@lib/redis/RedisService.js'
21
+ import { CreateFeedArgs , RedisService , SpamCheckArgs } from '@lib/redis/RedisService.js'
22
22
import { GraphcdnService } from '@lib/graphcdn/GraphcdnService.js'
23
23
import { ImageService } from '@services/ImageService/index.js'
24
24
import { UserService } from '@services/UserService/index.js'
@@ -121,15 +121,15 @@ export class PostApiService implements Service {
121
121
}
122
122
123
123
if ( ! post . is_private && data . is_private ) {
124
- setImmediate ( async ( ) => {
124
+ setTimeout ( async ( ) => {
125
125
if ( ! signedUserId ) return
126
126
const isIntegrated = await this . externalInterationService . checkIntegrated ( signedUserId )
127
127
if ( ! isIntegrated ) return
128
128
this . externalInterationService . notifyWebhook ( {
129
129
type : 'deleted' ,
130
130
post_id : post . id ,
131
131
} )
132
- } )
132
+ } , 0 )
133
133
}
134
134
135
135
return { ...post , url_slug : data . url_slug }
@@ -168,12 +168,10 @@ export class PostApiService implements Service {
168
168
const isPublish = ! data . is_temp && ! data . is_private
169
169
170
170
const country = geoip . lookup ( ip ) ?. country ?? ''
171
- const isSpam = this . isIncludeSpamKeyword ( { input, user, country } )
172
171
const isLimit = await this . isPostLimitReached ( signedUserId )
173
172
const isBlock = await this . dynamicConfigService . isBlockedUser ( user . username )
174
173
175
174
const checks = [
176
- { type : 'spam' , value : isSpam } ,
177
175
{ type : 'limit' , value : isLimit } ,
178
176
{ type : 'block' , value : isBlock } ,
179
177
]
@@ -249,7 +247,7 @@ export class PostApiService implements Service {
249
247
await this . handleTags ( tags , post . id )
250
248
251
249
if ( isPublish ) {
252
- setImmediate ( async ( ) => {
250
+ setTimeout ( async ( ) => {
253
251
if ( ! post ) return
254
252
if ( ! signedUserId ) return
255
253
@@ -269,20 +267,34 @@ export class PostApiService implements Service {
269
267
user : true ,
270
268
} ,
271
269
} )
270
+
272
271
if ( ! targetPost ) return
273
272
274
273
const serializedPost = this . postService . serialize ( targetPost )
275
274
this . externalInterationService . notifyWebhook ( {
276
275
type : type === 'write' ? 'created' : 'updated' ,
277
276
post : serializedPost ,
278
277
} )
279
- } )
280
-
281
- const queueData = {
282
- fk_following_id : signedUserId ,
283
- fk_post_id : post . id ,
284
- }
285
- this . redis . createFeedQueue ( queueData )
278
+ } , 0 )
279
+
280
+ // create feed
281
+ setTimeout ( ( ) => {
282
+ const queueData : CreateFeedArgs = {
283
+ fk_following_id : signedUserId ,
284
+ fk_post_id : post . id ,
285
+ }
286
+ this . redis . createFeedQueue ( queueData )
287
+ } , 0 )
288
+
289
+ // check spam
290
+ setTimeout ( ( ) => {
291
+ const queueData : SpamCheckArgs = {
292
+ post_id : post . id ,
293
+ user_id : signedUserId ,
294
+ ip,
295
+ }
296
+ this . redis . addToSpamCheckQueue ( queueData )
297
+ } , 0 )
286
298
}
287
299
288
300
setTimeout ( async ( ) => {
@@ -322,16 +334,17 @@ export class PostApiService implements Service {
322
334
323
335
const generate = customAlphabet ( 'abcdefghijklmnopqrstuvwxyz1234567890' , 8 )
324
336
const isEditArgs = this . isEditArgs ( input )
337
+ const isWriteArgs = ! isEditArgs
325
338
326
339
if ( isEditArgs && urlSlugDuplicate && urlSlugDuplicate . id !== input . id ) {
327
340
const randomString = generate ( 8 )
328
- processedUrlSlug = processedUrlSlug . slice ( 0 , 245 )
341
+ processedUrlSlug = processedUrlSlug . slice ( 0 , 240 )
329
342
processedUrlSlug += `-${ randomString } `
330
343
}
331
344
332
- if ( ! isEditArgs && urlSlugDuplicate ) {
345
+ if ( isWriteArgs && urlSlugDuplicate ) {
333
346
const randomString = generate ( 8 )
334
- processedUrlSlug = processedUrlSlug . slice ( 0 , 245 )
347
+ processedUrlSlug = processedUrlSlug . slice ( 0 , 240 )
335
348
processedUrlSlug += `-${ randomString } `
336
349
}
337
350
0 commit comments