@@ -8,6 +8,7 @@ import { getReputation } from "../utils/reputation";
8
8
import { Category , SegmentUUID } from "../types/segments.model" ;
9
9
import { config } from "../config" ;
10
10
import { canSubmit } from "../utils/permissions" ;
11
+ import { oneOf } from "../utils/promise" ;
11
12
const maxRewardTime = config . maxRewardTimePerSegmentInSeconds ;
12
13
13
14
async function dbGetSubmittedSegmentSummary ( userID : HashedUserID ) : Promise < { minutesSaved : number , segmentCount : number } > {
@@ -115,6 +116,13 @@ async function getPermissions(userID: HashedUserID): Promise<Record<string, bool
115
116
return result ;
116
117
}
117
118
119
+ async function getFreeChaptersAccess ( userID : HashedUserID ) : Promise < boolean > {
120
+ return await oneOf ( [ isUserVIP ( userID ) ,
121
+ ( async ( ) => ( await getReputation ( userID ) ) > 0 ) ( ) ,
122
+ ( async ( ) => ! ! ( await db . prepare ( "get" , `SELECT "timeSubmitted" FROM "sponsorTimes" WHERE "timeSubmitted" < 1590969600000 AND "userID" = ? LIMIT 1` , [ userID ] , { useReplica : true } ) ) ) ( )
123
+ ] ) ;
124
+ }
125
+
118
126
type cases = Record < string , any >
119
127
120
128
const executeIfFunction = ( f : any ) =>
@@ -139,7 +147,8 @@ const dbGetValue = (userID: HashedUserID, property: string): Promise<string|Segm
139
147
reputation : ( ) => getReputation ( userID ) ,
140
148
vip : ( ) => isUserVIP ( userID ) ,
141
149
lastSegmentID : ( ) => dbGetLastSegmentForUser ( userID ) ,
142
- permissions : ( ) => getPermissions ( userID )
150
+ permissions : ( ) => getPermissions ( userID ) ,
151
+ freeChaptersAccess : ( ) => getFreeChaptersAccess ( userID )
143
152
} ) ( "" ) ( property ) ;
144
153
} ;
145
154
@@ -149,7 +158,7 @@ async function getUserInfo(req: Request, res: Response): Promise<Response> {
149
158
const defaultProperties : string [ ] = [ "userID" , "userName" , "minutesSaved" , "segmentCount" , "ignoredSegmentCount" ,
150
159
"viewCount" , "ignoredViewCount" , "warnings" , "warningReason" , "reputation" ,
151
160
"vip" , "lastSegmentID" ] ;
152
- const allProperties : string [ ] = [ ...defaultProperties , "banned" , "permissions" ] ;
161
+ const allProperties : string [ ] = [ ...defaultProperties , "banned" , "permissions" , "freeChaptersAccess" ] ;
153
162
let paramValues : string [ ] = req . query . values
154
163
? JSON . parse ( req . query . values as string )
155
164
: req . query . value
0 commit comments