Skip to content

Commit

Permalink
don't require api key for v2 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
InventivetalentDev committed Jan 21, 2025
1 parent 7f80568 commit 376f855
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/routes/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
md5,
modelToVariant,
simplifyUserAgent,
sleep,
updateTraffic,
validateUrl,
variantToModel
Expand Down Expand Up @@ -80,14 +81,17 @@ export const register = (app: Application) => {
const flags = container.get<IFlagProvider>(CoreTypes.FlagProvider);
try {
const apiKey = (req as V2CompatRequest).apiKey;
if (apiKey) {
if (req.query["v2"]) {
req.v2Compat = true;
} else {
if (apiKey.grants && (apiKey.grants as any).v2_compat) {
req.v2Compat = true
} else if (apiKey && await flags.isEnabled('api.v2_compat.all_requests')) {
if (req.query["v2"]) {
req.v2Compat = true;
} else {
if (apiKey && apiKey.grants && (apiKey.grants as any).v2_compat) {
req.v2Compat = true
} else if (await flags.isEnabled('api.v2_compat.all_requests')) {
if (apiKey || !await flags.isEnabled('api.v2_compat.require_api_key')) {
req.v2Compat = true;
if (!apiKey) {
await sleep(300 + Math.random() * 500);
}
}
}
}
Expand Down

0 comments on commit 376f855

Please sign in to comment.