@@ -10,7 +10,6 @@ import {
1010 md5 ,
1111 modelToVariant ,
1212 simplifyUserAgent ,
13- sleep ,
1413 updateTraffic ,
1514 validateUrl ,
1615 variantToModel
@@ -37,8 +36,6 @@ import { v2GenerateAndWait } from "../models/v2/generate";
3736import { V2SkinResponse } from "../typings/v2/V2SkinResponse" ;
3837import { mineSkinV2InitialMiddleware } from "../middleware/combined" ;
3938import { rateLimitMiddlewareWithDelay } from "../middleware/rateLimit" ;
40- import { IFlagProvider , TYPES as CoreTypes } from "@mineskin/core" ;
41- import { container } from "../inversify.config" ;
4239import { Log } from "../Log" ;
4340import { validateModel , validateName , validateVariant , validateVisibility } from "../util/validate" ;
4441import { rewriteV2Options } from "../util/compat" ;
@@ -77,59 +74,59 @@ export const register = (app: Application) => {
7774
7875 // v2 compatibility layers
7976 const v2CompatMiddleware = async ( req : V2CompatRequest & MineSkinV2Request , res : Response , next : NextFunction ) => {
80- req . v2Compat = false ;
81- const flags = container . get < IFlagProvider > ( CoreTypes . FlagProvider ) ;
82- try {
83- const apiKey = ( req as V2CompatRequest ) . apiKey ;
84- if ( req . query [ "v2" ] ) {
85- req . v2Compat = true ;
86- } else {
87- if ( apiKey && apiKey . grants && ( apiKey . grants as any ) . v2_compat ) {
88- req . v2Compat = true
89- } else if ( await flags . isEnabled ( 'api.v2_compat.all_requests' ) ) {
90- if ( apiKey || ! await flags . isEnabled ( 'api.v2_compat.require_api_key' ) ) {
91- req . v2Compat = true ;
92- if ( ! apiKey ) {
93- await sleep ( 300 + Math . random ( ) * 500 ) ;
94- }
95- }
96- }
97- }
98- } catch ( e ) {
99- Sentry . captureException ( e ) ;
100- Log . l . error ( e ) ;
101- }
77+ req . v2Compat = true ;
78+ // const flags = container.get<IFlagProvider>(CoreTypes.FlagProvider);
79+ // try {
80+ // const apiKey = (req as V2CompatRequest).apiKey;
81+ // if (req.query["v2"]) {
82+ // req.v2Compat = true;
83+ // } else {
84+ // if (apiKey && apiKey.grants && (apiKey.grants as any).v2_compat) {
85+ // req.v2Compat = true
86+ // } else if (await flags.isEnabled('api.v2_compat.all_requests')) {
87+ // if (apiKey || !await flags.isEnabled('api.v2_compat.require_api_key')) {
88+ // req.v2Compat = true;
89+ // if (!apiKey) {
90+ // await sleep(300 + Math.random() * 500);
91+ // }
92+ // }
93+ // }
94+ // }
95+ // } catch (e) {
96+ // Sentry.captureException(e);
97+ // Log.l.error(e);
98+ // }
10299
103- if ( req . v2Compat ) {
104- if ( ! req . warnings ) {
105- req . warnings = [ ] ;
106- }
107- try {
108- const [ enabled , chance ] = await Promise . all ( [
109- flags . isEnabled ( 'api.v2_compat.chance' ) ,
110- flags . getValue ( 'api.v2_compat.chance' )
111- ] ) ;
112- if ( ! enabled ) {
113- req . v2Compat = false ;
114- req . warnings . push ( {
115- code : "compat_disabled" ,
116- message : "v2 compatibility is currently disabled"
117- } ) ;
118- } else if ( chance ) {
119- const random = Math . random ( ) ;
120- if ( random > Number ( chance ) ) {
121- req . v2Compat = false ;
122- req . warnings . push ( {
123- code : "compat_disabled" ,
124- message : "v2 compatibility is currently disabled"
125- } ) ;
126- }
127- }
128- } catch ( e ) {
129- Sentry . captureException ( e ) ;
130- Log . l . error ( e ) ;
131- }
132- }
100+ // if (req.v2Compat) {
101+ // if (!req.warnings) {
102+ // req.warnings = [];
103+ // }
104+ // try {
105+ // const [enabled, chance] = await Promise.all([
106+ // flags.isEnabled('api.v2_compat.chance'),
107+ // flags.getValue('api.v2_compat.chance')
108+ // ]);
109+ // if (!enabled) {
110+ // req.v2Compat = false;
111+ // req.warnings.push({
112+ // code: "compat_disabled",
113+ // message: "v2 compatibility is currently disabled"
114+ // });
115+ // } else if (chance) {
116+ // const random = Math.random();
117+ // if (random > Number(chance)) {
118+ // req.v2Compat = false;
119+ // req.warnings.push({
120+ // code: "compat_disabled",
121+ // message: "v2 compatibility is currently disabled"
122+ // });
123+ // }
124+ // }
125+ // } catch (e) {
126+ // Sentry.captureException(e);
127+ // Log.l.error(e);
128+ // }
129+ // }
133130
134131 if ( req . v2Compat ) {
135132 Log . l . info ( `${ req . breadcrumbC } Redirecting to v2 compatibility layer` ) ;
0 commit comments