File tree Expand file tree Collapse file tree 3 files changed +11
-12
lines changed Expand file tree Collapse file tree 3 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ interface CacheService {
4
4
connect : ( ) => void ;
5
5
remove : ( ...keys : string [ ] ) => Promise < number > ;
6
6
disconnect : ( ) => void ;
7
- readBlackList : ( ) => Promise < string [ ] > ;
7
+ readBlockList : ( ) => Promise < string [ ] > ;
8
8
}
9
9
10
10
class Cache implements CacheService {
@@ -34,13 +34,13 @@ class Cache implements CacheService {
34
34
return Promise . resolve ( ) ;
35
35
}
36
36
37
- public async readBlackList ( ) : Promise < string [ ] > {
37
+ public async readBlockList ( ) : Promise < string [ ] > {
38
38
if ( ! this . client ) {
39
39
this . connect ( ) ;
40
40
}
41
41
42
42
try {
43
- const keyname = this . setName . blackList ;
43
+ const keyname = this . setName . blockList ;
44
44
const list = await this . client ?. smembers ( keyname ) ;
45
45
return list ?? [ ] ;
46
46
} catch ( error ) {
@@ -67,7 +67,7 @@ class Cache implements CacheService {
67
67
68
68
private get setName ( ) : Record < SetName , string > {
69
69
return {
70
- blackList : 'set:blackList ' ,
70
+ blockList : 'set:blockList ' ,
71
71
} ;
72
72
}
73
73
}
@@ -87,4 +87,4 @@ type GenerateCacheKey = {
87
87
88
88
type QueueName = 'feed' ;
89
89
90
- type SetName = 'blackList ' ;
90
+ type SetName = 'blockList ' ;
Original file line number Diff line number Diff line change @@ -822,7 +822,7 @@ export const resolvers: IResolvers<any, ApolloContext> = {
822
822
console . log ( e ) ;
823
823
}
824
824
}
825
- const isBlockList = await checkBlockList ( ctx . user_id ) ;
825
+ const isBlockList = await checkBlockList ( ctx . user_id , user ?. username ) ;
826
826
if ( isBlockList ) {
827
827
post . is_private = true ;
828
828
}
@@ -1116,7 +1116,7 @@ export const resolvers: IResolvers<any, ApolloContext> = {
1116
1116
}
1117
1117
post . url_slug = processedUrlSlug ;
1118
1118
1119
- const isBlockList = await checkBlockList ( ctx . user_id ) ;
1119
+ const isBlockList = await checkBlockList ( ctx . user_id , user ?. username ) ;
1120
1120
if ( isBlockList ) {
1121
1121
post . is_private = true ;
1122
1122
}
Original file line number Diff line number Diff line change 1
1
import cache from '../cache' ;
2
2
3
- export async function checkBlockList ( userId : string ) {
3
+ export async function checkBlockList ( userId : string , username : string = '' ) {
4
4
const blockListFromEnv = ( process . env . BLOCK_LIST ?? '' ) . split ( ',' ) ;
5
- const blockListFromCache = await cache . readBlackList ( ) ;
6
- const blockList = [ ...blockListFromEnv , ...blockListFromCache ] ;
7
-
8
- return blockList . includes ( userId ) ;
5
+ const blockListFromCache = await cache . readBlockList ( ) ;
6
+ const isBlocked = blockListFromEnv . includes ( userId ) || blockListFromCache . includes ( username ) ;
7
+ return isBlocked ;
9
8
}
You can’t perform that action at this time.
0 commit comments