@@ -7,19 +7,19 @@ import { ratelimit } from "./lib/upstash"
7
7
import { isDev } from "./utils/env" ;
8
8
import { digestMessage } from "./utils/fp" ;
9
9
10
- const redis = Redis . fromEnv ( ) ;
10
+ // const redis = Redis.fromEnv();
11
11
12
12
export async function middleware ( req : NextRequest , context : NextFetchEvent ) {
13
13
const { sentences, targetLang, srcLang, apiKey } = await req . json ( ) ;
14
14
let rkey = `${ targetLang } _${ srcLang } _${ sentences } }` ;
15
15
rkey = "tranres_" + await digestMessage ( rkey ) ;
16
- const cached = await redis . get < string [ ] > ( rkey ) ;
16
+ // const cached = await redis.get<string[]>(rkey);
17
17
18
- if ( ! isDev && cached ) {
19
- //if (cached) {
20
- console . log ( "Using cached response " + rkey ) ;
21
- return NextResponse . json ( cached ) ;
22
- }
18
+ // if (!isDev && cached) {
19
+ // // if (cached) {
20
+ // console.log("Using cached response " + rkey);
21
+ // return NextResponse.json(cached);
22
+ // }
23
23
24
24
// licenseKeys
25
25
if ( apiKey ) {
@@ -33,10 +33,11 @@ export async function middleware(req: NextRequest, context: NextFetchEvent) {
33
33
}
34
34
}
35
35
// TODO: unique to a user (userid, email etc) instead of IP
36
- const identifier = req . ip ?? "127.0.0.7" ;
37
- const { success, remaining } = await ratelimit . limit ( "trans-" + identifier ) ;
38
- console . log ( `======== ip ${ identifier } , remaining: ${ remaining } ========` ) ;
39
- if ( ! apiKey && ! success ) {
36
+ // const identifier = req.ip ?? "127.0.0.7";
37
+ // const { success, remaining } = await ratelimit.limit("trans-" + identifier);
38
+ // console.log(`======== ip ${identifier}, remaining: ${remaining} ========`);
39
+ // if (!apiKey && !success) {
40
+ if ( ! apiKey ) {
40
41
return NextResponse . redirect ( new URL ( "/shop" , req . url ) ) ;
41
42
}
42
43
}
0 commit comments