@@ -31,7 +31,6 @@ export async function GET(input: APIEvent) {
3131 const auth = await Database . use ( ( tx ) =>
3232 tx
3333 . select ( {
34- lite : BillingTable . lite ,
3534 userID : KeyTable . userID ,
3635 workspaceID : KeyTable . workspaceID ,
3736 } )
@@ -115,24 +114,31 @@ export async function GET(input: APIEvent) {
115114
116115 return new Response (
117116 JSON . stringify ( {
118- useBalance : auth . lite ?. useBalance ?? false ,
119- rollingUsage : Subscription . analyzeRollingUsage ( {
120- limit : limits . rollingLimit ,
121- window : limits . rollingWindow ,
122- usage : row . rollingUsage ?? 0 ,
123- timeUpdated : row . timeRollingUpdated ?? new Date ( ) ,
124- } ) ,
125- weeklyUsage : Subscription . analyzeWeeklyUsage ( {
126- limit : limits . weeklyLimit ,
127- usage : row . weeklyUsage ?? 0 ,
128- timeUpdated : row . timeWeeklyUpdated ?? new Date ( ) ,
129- } ) ,
130- monthlyUsage : Subscription . analyzeMonthlyUsage ( {
131- limit : limits . monthlyLimit ,
132- usage : row . monthlyUsage ?? 0 ,
133- timeUpdated : row . timeMonthlyUpdated ?? new Date ( ) ,
134- timeSubscribed : row . timeCreated ,
135- } ) ,
117+ usage : {
118+ rolling : formatUsage (
119+ Subscription . analyzeRollingUsage ( {
120+ limit : limits . rollingLimit ,
121+ window : limits . rollingWindow ,
122+ usage : row . rollingUsage ?? 0 ,
123+ timeUpdated : row . timeRollingUpdated ?? new Date ( ) ,
124+ } ) ,
125+ ) ,
126+ weekly : formatUsage (
127+ Subscription . analyzeWeeklyUsage ( {
128+ limit : limits . weeklyLimit ,
129+ usage : row . weeklyUsage ?? 0 ,
130+ timeUpdated : row . timeWeeklyUpdated ?? new Date ( ) ,
131+ } ) ,
132+ ) ,
133+ monthly : formatUsage (
134+ Subscription . analyzeMonthlyUsage ( {
135+ limit : limits . monthlyLimit ,
136+ usage : row . monthlyUsage ?? 0 ,
137+ timeUpdated : row . timeMonthlyUpdated ?? new Date ( ) ,
138+ timeSubscribed : row . timeCreated ,
139+ } ) ,
140+ ) ,
141+ } ,
136142 } ) ,
137143 {
138144 status : 200 ,
@@ -142,3 +148,11 @@ export async function GET(input: APIEvent) {
142148 } ,
143149 )
144150}
151+
152+ function formatUsage ( usage : { status : "ok" | "rate-limited" ; resetInSec : number ; usagePercent : number } ) {
153+ return {
154+ status : usage . status ,
155+ percent : usage . usagePercent ,
156+ resetsAt : new Date ( Date . now ( ) + usage . resetInSec * 1000 ) . toISOString ( ) ,
157+ }
158+ }
0 commit comments