@@ -66,49 +66,50 @@ export class PostController implements Controller {
66
66
return posts . length
67
67
}
68
68
async spamFilterTestRunner ( ) {
69
+ if ( ENV . appEnv !== 'development' ) return
70
+
69
71
const utils = container . resolve ( UtilsService )
70
72
const postService = container . resolve ( PostService )
71
73
try {
72
- if ( ENV . appEnv !== 'development' ) return
73
-
74
74
const filePath = path . resolve ( utils . resolveDir ( './src/routes/posts/v1/spam_post.json' ) )
75
75
76
76
const fileExits = fs . existsSync ( filePath )
77
- if ( ! fileExits ) return
77
+ if ( ! fileExits ) {
78
+ throw new NotFoundError ( 'Not found spam_post.json' )
79
+ }
78
80
79
81
const readFileResult = fs . readFileSync ( filePath , { encoding : 'utf-8' } )
80
82
const data = JSON . parse ( readFileResult )
81
83
const key = Object . keys ( data ) [ 0 ]
82
84
const posts : PostData [ ] = data [ key ]
83
- . filter ( ( v : any ) => ! ! v . title )
84
- . map ( ( v : any , index : number ) => ( { id : index , ...v } ) )
85
+ . filter ( ( post : any ) => post . title )
86
+ . map ( ( post : any , index : number ) => ( { id : index , ...post } ) )
85
87
86
- const postLength = 5000
88
+ const maxPostLength = 5000
87
89
const set = new Set ( )
88
-
89
90
const bannedUesrnames : string [ ] = [ ]
90
91
91
- for ( const post of posts . slice ( 0 , postLength ) ) {
92
+ for ( const post of posts . slice ( 0 , maxPostLength ) ) {
92
93
const { id, title, body, username } = post
93
94
if ( bannedUesrnames . includes ( username ) ) {
94
95
set . add ( id )
95
96
}
96
97
97
- const isSpam = await postService . checkIsSpam ( title , body , username , '' , 'US' )
98
- if ( isSpam ) {
98
+ const isForeignSpam = await postService . checkIsSpam ( title , body , username , '' , 'US' )
99
+ if ( isForeignSpam ) {
99
100
set . add ( id )
100
101
continue
101
102
}
102
103
103
- const isSpam2 = await postService . checkIsSpam ( title , body , username , '' , 'KR' )
104
- if ( isSpam2 ) {
104
+ const isInternalSpam = await postService . checkIsSpam ( title , body , username , '' , 'KR' )
105
+ if ( isInternalSpam ) {
105
106
set . add ( id )
106
107
}
107
108
}
108
109
109
110
const isSpamCount = set . size
110
111
console . log ( 'isSpamCount: ' , isSpamCount )
111
- console . log ( 'ratio: ' , isSpamCount / postLength )
112
+ console . log ( 'ratio: ' , isSpamCount / maxPostLength )
112
113
113
114
const allowIds : number [ ] = [ ]
114
115
for ( const id of allowIds ) {
0 commit comments