@kevisual/cli 0.0.83 → 0.0.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12746,7 +12746,7 @@ var require_main4 = __commonJS((exports) => {
12746
12746
  } });
12747
12747
  });
12748
12748
 
12749
- // ../node_modules/.pnpm/@aws-sdk+middleware-flexible-checksums@3.970.0/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/getCrc32ChecksumAlgorithmFunction.js
12749
+ // ../node_modules/.pnpm/@aws-sdk+middleware-flexible-checksums@3.971.0/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/getCrc32ChecksumAlgorithmFunction.js
12750
12750
  var require_getCrc32ChecksumAlgorithmFunction = __commonJS((exports) => {
12751
12751
  Object.defineProperty(exports, "__esModule", { value: true });
12752
12752
  exports.getCrc32ChecksumAlgorithmFunction = undefined;
@@ -12776,7 +12776,7 @@ var require_getCrc32ChecksumAlgorithmFunction = __commonJS((exports) => {
12776
12776
  exports.getCrc32ChecksumAlgorithmFunction = getCrc32ChecksumAlgorithmFunction;
12777
12777
  });
12778
12778
 
12779
- // ../node_modules/.pnpm/@aws-sdk+middleware-flexible-checksums@3.970.0/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js
12779
+ // ../node_modules/.pnpm/@aws-sdk+middleware-flexible-checksums@3.971.0/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js
12780
12780
  var require_dist_cjs29 = __commonJS((exports) => {
12781
12781
  var core = require_dist_cjs24();
12782
12782
  var protocolHttp = require_dist_cjs2();
@@ -16703,7 +16703,7 @@ var require_dist_cjs50 = __commonJS((exports) => {
16703
16703
  exports.signatureV4CrtContainer = signatureV4CrtContainer;
16704
16704
  });
16705
16705
 
16706
- // ../node_modules/.pnpm/@aws-sdk+client-s3@3.970.0/node_modules/@aws-sdk/client-s3/dist-cjs/endpoint/ruleset.js
16706
+ // ../node_modules/.pnpm/@aws-sdk+client-s3@3.971.0/node_modules/@aws-sdk/client-s3/dist-cjs/endpoint/ruleset.js
16707
16707
  var require_ruleset = __commonJS((exports) => {
16708
16708
  Object.defineProperty(exports, "__esModule", { value: true });
16709
16709
  exports.ruleSet = undefined;
@@ -16902,7 +16902,7 @@ var require_ruleset = __commonJS((exports) => {
16902
16902
  exports.ruleSet = _data;
16903
16903
  });
16904
16904
 
16905
- // ../node_modules/.pnpm/@aws-sdk+client-s3@3.970.0/node_modules/@aws-sdk/client-s3/dist-cjs/endpoint/endpointResolver.js
16905
+ // ../node_modules/.pnpm/@aws-sdk+client-s3@3.971.0/node_modules/@aws-sdk/client-s3/dist-cjs/endpoint/endpointResolver.js
16906
16906
  var require_endpointResolver = __commonJS((exports) => {
16907
16907
  Object.defineProperty(exports, "__esModule", { value: true });
16908
16908
  exports.defaultEndpointResolver = undefined;
@@ -16938,7 +16938,7 @@ var require_endpointResolver = __commonJS((exports) => {
16938
16938
  util_endpoints_2.customEndpointFunctions.aws = util_endpoints_1.awsEndpointFunctions;
16939
16939
  });
16940
16940
 
16941
- // ../node_modules/.pnpm/@aws-sdk+client-s3@3.970.0/node_modules/@aws-sdk/client-s3/dist-cjs/auth/httpAuthSchemeProvider.js
16941
+ // ../node_modules/.pnpm/@aws-sdk+client-s3@3.971.0/node_modules/@aws-sdk/client-s3/dist-cjs/auth/httpAuthSchemeProvider.js
16942
16942
  var require_httpAuthSchemeProvider = __commonJS((exports) => {
16943
16943
  Object.defineProperty(exports, "__esModule", { value: true });
16944
16944
  exports.resolveHttpAuthSchemeConfig = exports.defaultS3HttpAuthSchemeProvider = exports.defaultS3HttpAuthSchemeParametersProvider = undefined;
@@ -17064,12 +17064,12 @@ var require_httpAuthSchemeProvider = __commonJS((exports) => {
17064
17064
  exports.resolveHttpAuthSchemeConfig = resolveHttpAuthSchemeConfig;
17065
17065
  });
17066
17066
 
17067
- // ../node_modules/.pnpm/@aws-sdk+client-s3@3.970.0/node_modules/@aws-sdk/client-s3/package.json
17067
+ // ../node_modules/.pnpm/@aws-sdk+client-s3@3.971.0/node_modules/@aws-sdk/client-s3/package.json
17068
17068
  var require_package2 = __commonJS((exports, module) => {
17069
17069
  module.exports = {
17070
17070
  name: "@aws-sdk/client-s3",
17071
17071
  description: "AWS SDK for JavaScript S3 Client for Node.js, Browser and React Native",
17072
- version: "3.970.0",
17072
+ version: "3.971.0",
17073
17073
  scripts: {
17074
17074
  build: "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
17075
17075
  "build:cjs": "node ../../scripts/compilation/inline client-s3",
@@ -17099,23 +17099,23 @@ var require_package2 = __commonJS((exports, module) => {
17099
17099
  "@aws-crypto/sha256-browser": "5.2.0",
17100
17100
  "@aws-crypto/sha256-js": "5.2.0",
17101
17101
  "@aws-sdk/core": "3.970.0",
17102
- "@aws-sdk/credential-provider-node": "3.970.0",
17102
+ "@aws-sdk/credential-provider-node": "3.971.0",
17103
17103
  "@aws-sdk/middleware-bucket-endpoint": "3.969.0",
17104
17104
  "@aws-sdk/middleware-expect-continue": "3.969.0",
17105
- "@aws-sdk/middleware-flexible-checksums": "3.970.0",
17105
+ "@aws-sdk/middleware-flexible-checksums": "3.971.0",
17106
17106
  "@aws-sdk/middleware-host-header": "3.969.0",
17107
17107
  "@aws-sdk/middleware-location-constraint": "3.969.0",
17108
17108
  "@aws-sdk/middleware-logger": "3.969.0",
17109
17109
  "@aws-sdk/middleware-recursion-detection": "3.969.0",
17110
17110
  "@aws-sdk/middleware-sdk-s3": "3.970.0",
17111
- "@aws-sdk/middleware-ssec": "3.969.0",
17111
+ "@aws-sdk/middleware-ssec": "3.971.0",
17112
17112
  "@aws-sdk/middleware-user-agent": "3.970.0",
17113
17113
  "@aws-sdk/region-config-resolver": "3.969.0",
17114
17114
  "@aws-sdk/signature-v4-multi-region": "3.970.0",
17115
17115
  "@aws-sdk/types": "3.969.0",
17116
17116
  "@aws-sdk/util-endpoints": "3.970.0",
17117
17117
  "@aws-sdk/util-user-agent-browser": "3.969.0",
17118
- "@aws-sdk/util-user-agent-node": "3.970.0",
17118
+ "@aws-sdk/util-user-agent-node": "3.971.0",
17119
17119
  "@smithy/config-resolver": "^4.4.6",
17120
17120
  "@smithy/core": "^3.20.6",
17121
17121
  "@smithy/eventstream-serde-browser": "^4.2.8",
@@ -17152,7 +17152,7 @@ var require_package2 = __commonJS((exports, module) => {
17152
17152
  tslib: "^2.6.2"
17153
17153
  },
17154
17154
  devDependencies: {
17155
- "@aws-sdk/signature-v4-crt": "3.970.0",
17155
+ "@aws-sdk/signature-v4-crt": "3.971.0",
17156
17156
  "@tsconfig/node20": "20.1.8",
17157
17157
  "@types/node": "^20.14.8",
17158
17158
  concurrently: "7.0.0",
@@ -18053,7 +18053,7 @@ var require_httpAuthSchemes = __commonJS((exports) => {
18053
18053
  exports.validateSigningProperties = validateSigningProperties;
18054
18054
  });
18055
18055
 
18056
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/auth/httpAuthSchemeProvider.js
18056
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/auth/httpAuthSchemeProvider.js
18057
18057
  var require_httpAuthSchemeProvider2 = __commonJS((exports) => {
18058
18058
  Object.defineProperty(exports, "__esModule", { value: true });
18059
18059
  exports.resolveHttpAuthSchemeConfig = exports.defaultSSOOIDCHttpAuthSchemeProvider = exports.defaultSSOOIDCHttpAuthSchemeParametersProvider = undefined;
@@ -18111,11 +18111,11 @@ var require_httpAuthSchemeProvider2 = __commonJS((exports) => {
18111
18111
  exports.resolveHttpAuthSchemeConfig = resolveHttpAuthSchemeConfig;
18112
18112
  });
18113
18113
 
18114
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/package.json
18114
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/package.json
18115
18115
  var require_package3 = __commonJS((exports, module) => {
18116
18116
  module.exports = {
18117
18117
  name: "@aws-sdk/nested-clients",
18118
- version: "3.970.0",
18118
+ version: "3.971.0",
18119
18119
  description: "Nested clients for AWS SDK packages.",
18120
18120
  main: "./dist-cjs/index.js",
18121
18121
  module: "./dist-es/index.js",
@@ -18153,7 +18153,7 @@ var require_package3 = __commonJS((exports, module) => {
18153
18153
  "@aws-sdk/types": "3.969.0",
18154
18154
  "@aws-sdk/util-endpoints": "3.970.0",
18155
18155
  "@aws-sdk/util-user-agent-browser": "3.969.0",
18156
- "@aws-sdk/util-user-agent-node": "3.970.0",
18156
+ "@aws-sdk/util-user-agent-node": "3.971.0",
18157
18157
  "@smithy/config-resolver": "^4.4.6",
18158
18158
  "@smithy/core": "^3.20.6",
18159
18159
  "@smithy/fetch-http-handler": "^5.3.9",
@@ -18242,7 +18242,7 @@ var require_package3 = __commonJS((exports, module) => {
18242
18242
  };
18243
18243
  });
18244
18244
 
18245
- // ../node_modules/.pnpm/@aws-sdk+util-user-agent-node@3.970.0/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
18245
+ // ../node_modules/.pnpm/@aws-sdk+util-user-agent-node@3.971.0/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
18246
18246
  var require_dist_cjs54 = __commonJS((exports) => {
18247
18247
  var os = __require("os");
18248
18248
  var process2 = __require("process");
@@ -20245,7 +20245,7 @@ var require_protocols2 = __commonJS((exports) => {
20245
20245
  exports.parseXmlErrorBody = parseXmlErrorBody;
20246
20246
  });
20247
20247
 
20248
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/endpoint/ruleset.js
20248
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/endpoint/ruleset.js
20249
20249
  var require_ruleset2 = __commonJS((exports) => {
20250
20250
  Object.defineProperty(exports, "__esModule", { value: true });
20251
20251
  exports.ruleSet = undefined;
@@ -20277,7 +20277,7 @@ var require_ruleset2 = __commonJS((exports) => {
20277
20277
  exports.ruleSet = _data;
20278
20278
  });
20279
20279
 
20280
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/endpoint/endpointResolver.js
20280
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/endpoint/endpointResolver.js
20281
20281
  var require_endpointResolver2 = __commonJS((exports) => {
20282
20282
  Object.defineProperty(exports, "__esModule", { value: true });
20283
20283
  exports.defaultEndpointResolver = undefined;
@@ -20298,7 +20298,7 @@ var require_endpointResolver2 = __commonJS((exports) => {
20298
20298
  util_endpoints_2.customEndpointFunctions.aws = util_endpoints_1.awsEndpointFunctions;
20299
20299
  });
20300
20300
 
20301
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/runtimeConfig.shared.js
20301
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/runtimeConfig.shared.js
20302
20302
  var require_runtimeConfig_shared = __commonJS((exports) => {
20303
20303
  Object.defineProperty(exports, "__esModule", { value: true });
20304
20304
  exports.getRuntimeConfig = undefined;
@@ -20348,7 +20348,7 @@ var require_runtimeConfig_shared = __commonJS((exports) => {
20348
20348
  exports.getRuntimeConfig = getRuntimeConfig;
20349
20349
  });
20350
20350
 
20351
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/runtimeConfig.js
20351
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/runtimeConfig.js
20352
20352
  var require_runtimeConfig = __commonJS((exports) => {
20353
20353
  Object.defineProperty(exports, "__esModule", { value: true });
20354
20354
  exports.getRuntimeConfig = undefined;
@@ -20486,7 +20486,7 @@ var require_dist_cjs58 = __commonJS((exports) => {
20486
20486
  });
20487
20487
  });
20488
20488
 
20489
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js
20489
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js
20490
20490
  var require_sso_oidc = __commonJS((exports) => {
20491
20491
  var middlewareHostHeader = require_dist_cjs30();
20492
20492
  var middlewareLogger = require_dist_cjs31();
@@ -20988,7 +20988,7 @@ var require_sso_oidc = __commonJS((exports) => {
20988
20988
  exports.UnsupportedGrantTypeException$ = UnsupportedGrantTypeException$;
20989
20989
  });
20990
20990
 
20991
- // ../node_modules/.pnpm/@aws-sdk+token-providers@3.970.0/node_modules/@aws-sdk/token-providers/dist-cjs/index.js
20991
+ // ../node_modules/.pnpm/@aws-sdk+token-providers@3.971.0/node_modules/@aws-sdk/token-providers/dist-cjs/index.js
20992
20992
  var require_dist_cjs59 = __commonJS((exports) => {
20993
20993
  var client = require_client();
20994
20994
  var httpAuthSchemes = require_httpAuthSchemes();
@@ -21131,7 +21131,7 @@ var require_dist_cjs59 = __commonJS((exports) => {
21131
21131
  exports.nodeProvider = nodeProvider;
21132
21132
  });
21133
21133
 
21134
- // ../node_modules/.pnpm/@aws-sdk+client-sso@3.970.0/node_modules/@aws-sdk/client-sso/dist-cjs/auth/httpAuthSchemeProvider.js
21134
+ // ../node_modules/.pnpm/@aws-sdk+client-sso@3.971.0/node_modules/@aws-sdk/client-sso/dist-cjs/auth/httpAuthSchemeProvider.js
21135
21135
  var require_httpAuthSchemeProvider3 = __commonJS((exports) => {
21136
21136
  Object.defineProperty(exports, "__esModule", { value: true });
21137
21137
  exports.resolveHttpAuthSchemeConfig = exports.defaultSSOHttpAuthSchemeProvider = exports.defaultSSOHttpAuthSchemeParametersProvider = undefined;
@@ -21209,12 +21209,12 @@ var require_httpAuthSchemeProvider3 = __commonJS((exports) => {
21209
21209
  exports.resolveHttpAuthSchemeConfig = resolveHttpAuthSchemeConfig;
21210
21210
  });
21211
21211
 
21212
- // ../node_modules/.pnpm/@aws-sdk+client-sso@3.970.0/node_modules/@aws-sdk/client-sso/package.json
21212
+ // ../node_modules/.pnpm/@aws-sdk+client-sso@3.971.0/node_modules/@aws-sdk/client-sso/package.json
21213
21213
  var require_package4 = __commonJS((exports, module) => {
21214
21214
  module.exports = {
21215
21215
  name: "@aws-sdk/client-sso",
21216
21216
  description: "AWS SDK for JavaScript Sso Client for Node.js, Browser and React Native",
21217
- version: "3.970.0",
21217
+ version: "3.971.0",
21218
21218
  scripts: {
21219
21219
  build: "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
21220
21220
  "build:cjs": "node ../../scripts/compilation/inline client-sso",
@@ -21243,7 +21243,7 @@ var require_package4 = __commonJS((exports, module) => {
21243
21243
  "@aws-sdk/types": "3.969.0",
21244
21244
  "@aws-sdk/util-endpoints": "3.970.0",
21245
21245
  "@aws-sdk/util-user-agent-browser": "3.969.0",
21246
- "@aws-sdk/util-user-agent-node": "3.970.0",
21246
+ "@aws-sdk/util-user-agent-node": "3.971.0",
21247
21247
  "@smithy/config-resolver": "^4.4.6",
21248
21248
  "@smithy/core": "^3.20.6",
21249
21249
  "@smithy/fetch-http-handler": "^5.3.9",
@@ -21312,7 +21312,7 @@ var require_package4 = __commonJS((exports, module) => {
21312
21312
  };
21313
21313
  });
21314
21314
 
21315
- // ../node_modules/.pnpm/@aws-sdk+client-sso@3.970.0/node_modules/@aws-sdk/client-sso/dist-cjs/endpoint/ruleset.js
21315
+ // ../node_modules/.pnpm/@aws-sdk+client-sso@3.971.0/node_modules/@aws-sdk/client-sso/dist-cjs/endpoint/ruleset.js
21316
21316
  var require_ruleset3 = __commonJS((exports) => {
21317
21317
  Object.defineProperty(exports, "__esModule", { value: true });
21318
21318
  exports.ruleSet = undefined;
@@ -21344,7 +21344,7 @@ var require_ruleset3 = __commonJS((exports) => {
21344
21344
  exports.ruleSet = _data;
21345
21345
  });
21346
21346
 
21347
- // ../node_modules/.pnpm/@aws-sdk+client-sso@3.970.0/node_modules/@aws-sdk/client-sso/dist-cjs/endpoint/endpointResolver.js
21347
+ // ../node_modules/.pnpm/@aws-sdk+client-sso@3.971.0/node_modules/@aws-sdk/client-sso/dist-cjs/endpoint/endpointResolver.js
21348
21348
  var require_endpointResolver3 = __commonJS((exports) => {
21349
21349
  Object.defineProperty(exports, "__esModule", { value: true });
21350
21350
  exports.defaultEndpointResolver = undefined;
@@ -21365,7 +21365,7 @@ var require_endpointResolver3 = __commonJS((exports) => {
21365
21365
  util_endpoints_2.customEndpointFunctions.aws = util_endpoints_1.awsEndpointFunctions;
21366
21366
  });
21367
21367
 
21368
- // ../node_modules/.pnpm/@aws-sdk+client-sso@3.970.0/node_modules/@aws-sdk/client-sso/dist-cjs/runtimeConfig.shared.js
21368
+ // ../node_modules/.pnpm/@aws-sdk+client-sso@3.971.0/node_modules/@aws-sdk/client-sso/dist-cjs/runtimeConfig.shared.js
21369
21369
  var require_runtimeConfig_shared2 = __commonJS((exports) => {
21370
21370
  Object.defineProperty(exports, "__esModule", { value: true });
21371
21371
  exports.getRuntimeConfig = undefined;
@@ -21415,7 +21415,7 @@ var require_runtimeConfig_shared2 = __commonJS((exports) => {
21415
21415
  exports.getRuntimeConfig = getRuntimeConfig;
21416
21416
  });
21417
21417
 
21418
- // ../node_modules/.pnpm/@aws-sdk+client-sso@3.970.0/node_modules/@aws-sdk/client-sso/dist-cjs/runtimeConfig.js
21418
+ // ../node_modules/.pnpm/@aws-sdk+client-sso@3.971.0/node_modules/@aws-sdk/client-sso/dist-cjs/runtimeConfig.js
21419
21419
  var require_runtimeConfig2 = __commonJS((exports) => {
21420
21420
  Object.defineProperty(exports, "__esModule", { value: true });
21421
21421
  exports.getRuntimeConfig = undefined;
@@ -21468,7 +21468,7 @@ var require_runtimeConfig2 = __commonJS((exports) => {
21468
21468
  exports.getRuntimeConfig = getRuntimeConfig;
21469
21469
  });
21470
21470
 
21471
- // ../node_modules/.pnpm/@aws-sdk+client-sso@3.970.0/node_modules/@aws-sdk/client-sso/dist-cjs/index.js
21471
+ // ../node_modules/.pnpm/@aws-sdk+client-sso@3.971.0/node_modules/@aws-sdk/client-sso/dist-cjs/index.js
21472
21472
  var require_dist_cjs60 = __commonJS((exports) => {
21473
21473
  var middlewareHostHeader = require_dist_cjs30();
21474
21474
  var middlewareLogger = require_dist_cjs31();
@@ -21935,7 +21935,7 @@ var require_dist_cjs60 = __commonJS((exports) => {
21935
21935
  exports.paginateListAccounts = paginateListAccounts;
21936
21936
  });
21937
21937
 
21938
- // ../node_modules/.pnpm/@aws-sdk+credential-provider-sso@3.970.0/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/loadSso-CVy8iqsZ.js
21938
+ // ../node_modules/.pnpm/@aws-sdk+credential-provider-sso@3.971.0/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/loadSso-CVy8iqsZ.js
21939
21939
  var require_loadSso_CVy8iqsZ = __commonJS((exports) => {
21940
21940
  var clientSso = require_dist_cjs60();
21941
21941
  Object.defineProperty(exports, "GetRoleCredentialsCommand", {
@@ -21952,7 +21952,7 @@ var require_loadSso_CVy8iqsZ = __commonJS((exports) => {
21952
21952
  });
21953
21953
  });
21954
21954
 
21955
- // ../node_modules/.pnpm/@aws-sdk+credential-provider-sso@3.970.0/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/index.js
21955
+ // ../node_modules/.pnpm/@aws-sdk+credential-provider-sso@3.971.0/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/index.js
21956
21956
  var require_dist_cjs61 = __commonJS((exports) => {
21957
21957
  var propertyProvider = require_dist_cjs18();
21958
21958
  var sharedIniFileLoader = require_dist_cjs44();
@@ -22129,7 +22129,7 @@ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.ht
22129
22129
  exports.validateSsoProfile = validateSsoProfile;
22130
22130
  });
22131
22131
 
22132
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/auth/httpAuthSchemeProvider.js
22132
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/auth/httpAuthSchemeProvider.js
22133
22133
  var require_httpAuthSchemeProvider4 = __commonJS((exports) => {
22134
22134
  Object.defineProperty(exports, "__esModule", { value: true });
22135
22135
  exports.resolveHttpAuthSchemeConfig = exports.defaultSigninHttpAuthSchemeProvider = exports.defaultSigninHttpAuthSchemeParametersProvider = undefined;
@@ -22187,7 +22187,7 @@ var require_httpAuthSchemeProvider4 = __commonJS((exports) => {
22187
22187
  exports.resolveHttpAuthSchemeConfig = resolveHttpAuthSchemeConfig;
22188
22188
  });
22189
22189
 
22190
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/endpoint/ruleset.js
22190
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/endpoint/ruleset.js
22191
22191
  var require_ruleset4 = __commonJS((exports) => {
22192
22192
  Object.defineProperty(exports, "__esModule", { value: true });
22193
22193
  exports.ruleSet = undefined;
@@ -22219,7 +22219,7 @@ var require_ruleset4 = __commonJS((exports) => {
22219
22219
  exports.ruleSet = _data;
22220
22220
  });
22221
22221
 
22222
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/endpoint/endpointResolver.js
22222
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/endpoint/endpointResolver.js
22223
22223
  var require_endpointResolver4 = __commonJS((exports) => {
22224
22224
  Object.defineProperty(exports, "__esModule", { value: true });
22225
22225
  exports.defaultEndpointResolver = undefined;
@@ -22240,7 +22240,7 @@ var require_endpointResolver4 = __commonJS((exports) => {
22240
22240
  util_endpoints_2.customEndpointFunctions.aws = util_endpoints_1.awsEndpointFunctions;
22241
22241
  });
22242
22242
 
22243
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/runtimeConfig.shared.js
22243
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/runtimeConfig.shared.js
22244
22244
  var require_runtimeConfig_shared3 = __commonJS((exports) => {
22245
22245
  Object.defineProperty(exports, "__esModule", { value: true });
22246
22246
  exports.getRuntimeConfig = undefined;
@@ -22290,7 +22290,7 @@ var require_runtimeConfig_shared3 = __commonJS((exports) => {
22290
22290
  exports.getRuntimeConfig = getRuntimeConfig;
22291
22291
  });
22292
22292
 
22293
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/runtimeConfig.js
22293
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/runtimeConfig.js
22294
22294
  var require_runtimeConfig3 = __commonJS((exports) => {
22295
22295
  Object.defineProperty(exports, "__esModule", { value: true });
22296
22296
  exports.getRuntimeConfig = undefined;
@@ -22343,7 +22343,7 @@ var require_runtimeConfig3 = __commonJS((exports) => {
22343
22343
  exports.getRuntimeConfig = getRuntimeConfig;
22344
22344
  });
22345
22345
 
22346
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js
22346
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js
22347
22347
  var require_signin = __commonJS((exports) => {
22348
22348
  var middlewareHostHeader = require_dist_cjs30();
22349
22349
  var middlewareLogger = require_dist_cjs31();
@@ -22687,7 +22687,7 @@ var require_signin = __commonJS((exports) => {
22687
22687
  exports.ValidationException$ = ValidationException$;
22688
22688
  });
22689
22689
 
22690
- // ../node_modules/.pnpm/@aws-sdk+credential-provider-login@3.970.0/node_modules/@aws-sdk/credential-provider-login/dist-cjs/index.js
22690
+ // ../node_modules/.pnpm/@aws-sdk+credential-provider-login@3.971.0/node_modules/@aws-sdk/credential-provider-login/dist-cjs/index.js
22691
22691
  var require_dist_cjs62 = __commonJS((exports) => {
22692
22692
  var client = require_client();
22693
22693
  var propertyProvider = require_dist_cjs18();
@@ -22963,7 +22963,7 @@ var require_dist_cjs62 = __commonJS((exports) => {
22963
22963
  exports.fromLoginCredentials = fromLoginCredentials;
22964
22964
  });
22965
22965
 
22966
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/auth/httpAuthSchemeProvider.js
22966
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/auth/httpAuthSchemeProvider.js
22967
22967
  var require_httpAuthSchemeProvider5 = __commonJS((exports) => {
22968
22968
  Object.defineProperty(exports, "__esModule", { value: true });
22969
22969
  exports.resolveHttpAuthSchemeConfig = exports.resolveStsAuthConfig = exports.defaultSTSHttpAuthSchemeProvider = exports.defaultSTSHttpAuthSchemeParametersProvider = undefined;
@@ -23027,7 +23027,7 @@ var require_httpAuthSchemeProvider5 = __commonJS((exports) => {
23027
23027
  exports.resolveHttpAuthSchemeConfig = resolveHttpAuthSchemeConfig;
23028
23028
  });
23029
23029
 
23030
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/endpoint/EndpointParameters.js
23030
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/endpoint/EndpointParameters.js
23031
23031
  var require_EndpointParameters = __commonJS((exports) => {
23032
23032
  Object.defineProperty(exports, "__esModule", { value: true });
23033
23033
  exports.commonParams = exports.resolveClientEndpointParameters = undefined;
@@ -23049,7 +23049,7 @@ var require_EndpointParameters = __commonJS((exports) => {
23049
23049
  };
23050
23050
  });
23051
23051
 
23052
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/endpoint/ruleset.js
23052
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/endpoint/ruleset.js
23053
23053
  var require_ruleset5 = __commonJS((exports) => {
23054
23054
  Object.defineProperty(exports, "__esModule", { value: true });
23055
23055
  exports.ruleSet = undefined;
@@ -23093,7 +23093,7 @@ var require_ruleset5 = __commonJS((exports) => {
23093
23093
  exports.ruleSet = _data;
23094
23094
  });
23095
23095
 
23096
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/endpoint/endpointResolver.js
23096
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/endpoint/endpointResolver.js
23097
23097
  var require_endpointResolver5 = __commonJS((exports) => {
23098
23098
  Object.defineProperty(exports, "__esModule", { value: true });
23099
23099
  exports.defaultEndpointResolver = undefined;
@@ -23114,7 +23114,7 @@ var require_endpointResolver5 = __commonJS((exports) => {
23114
23114
  util_endpoints_2.customEndpointFunctions.aws = util_endpoints_1.awsEndpointFunctions;
23115
23115
  });
23116
23116
 
23117
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/runtimeConfig.shared.js
23117
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/runtimeConfig.shared.js
23118
23118
  var require_runtimeConfig_shared4 = __commonJS((exports) => {
23119
23119
  Object.defineProperty(exports, "__esModule", { value: true });
23120
23120
  exports.getRuntimeConfig = undefined;
@@ -23165,7 +23165,7 @@ var require_runtimeConfig_shared4 = __commonJS((exports) => {
23165
23165
  exports.getRuntimeConfig = getRuntimeConfig;
23166
23166
  });
23167
23167
 
23168
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/runtimeConfig.js
23168
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/runtimeConfig.js
23169
23169
  var require_runtimeConfig4 = __commonJS((exports) => {
23170
23170
  Object.defineProperty(exports, "__esModule", { value: true });
23171
23171
  exports.getRuntimeConfig = undefined;
@@ -23231,7 +23231,7 @@ var require_runtimeConfig4 = __commonJS((exports) => {
23231
23231
  exports.getRuntimeConfig = getRuntimeConfig;
23232
23232
  });
23233
23233
 
23234
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/auth/httpAuthExtensionConfiguration.js
23234
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/auth/httpAuthExtensionConfiguration.js
23235
23235
  var require_httpAuthExtensionConfiguration = __commonJS((exports) => {
23236
23236
  Object.defineProperty(exports, "__esModule", { value: true });
23237
23237
  exports.resolveHttpAuthRuntimeConfig = exports.getHttpAuthExtensionConfiguration = undefined;
@@ -23276,7 +23276,7 @@ var require_httpAuthExtensionConfiguration = __commonJS((exports) => {
23276
23276
  exports.resolveHttpAuthRuntimeConfig = resolveHttpAuthRuntimeConfig;
23277
23277
  });
23278
23278
 
23279
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/runtimeExtensions.js
23279
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/runtimeExtensions.js
23280
23280
  var require_runtimeExtensions = __commonJS((exports) => {
23281
23281
  Object.defineProperty(exports, "__esModule", { value: true });
23282
23282
  exports.resolveRuntimeExtensions = undefined;
@@ -23292,7 +23292,7 @@ var require_runtimeExtensions = __commonJS((exports) => {
23292
23292
  exports.resolveRuntimeExtensions = resolveRuntimeExtensions;
23293
23293
  });
23294
23294
 
23295
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/STSClient.js
23295
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/STSClient.js
23296
23296
  var require_STSClient = __commonJS((exports) => {
23297
23297
  Object.defineProperty(exports, "__esModule", { value: true });
23298
23298
  exports.STSClient = exports.__Client = undefined;
@@ -23352,7 +23352,7 @@ var require_STSClient = __commonJS((exports) => {
23352
23352
  exports.STSClient = STSClient;
23353
23353
  });
23354
23354
 
23355
- // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.970.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js
23355
+ // ../node_modules/.pnpm/@aws-sdk+nested-clients@3.971.0/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js
23356
23356
  var require_sts = __commonJS((exports) => {
23357
23357
  var STSClient = require_STSClient();
23358
23358
  var smithyClient = require_dist_cjs22();
@@ -23903,7 +23903,7 @@ var require_dist_cjs63 = __commonJS((exports) => {
23903
23903
  exports.fromProcess = fromProcess;
23904
23904
  });
23905
23905
 
23906
- // ../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.970.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/fromWebToken.js
23906
+ // ../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.971.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/fromWebToken.js
23907
23907
  var require_fromWebToken = __commonJS((exports) => {
23908
23908
  var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
23909
23909
  if (k2 === undefined)
@@ -23979,7 +23979,7 @@ var require_fromWebToken = __commonJS((exports) => {
23979
23979
  exports.fromWebToken = fromWebToken;
23980
23980
  });
23981
23981
 
23982
- // ../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.970.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/fromTokenFile.js
23982
+ // ../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.971.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/fromTokenFile.js
23983
23983
  var require_fromTokenFile = __commonJS((exports) => {
23984
23984
  Object.defineProperty(exports, "__esModule", { value: true });
23985
23985
  exports.fromTokenFile = undefined;
@@ -24015,7 +24015,7 @@ var require_fromTokenFile = __commonJS((exports) => {
24015
24015
  exports.fromTokenFile = fromTokenFile;
24016
24016
  });
24017
24017
 
24018
- // ../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.970.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/index.js
24018
+ // ../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.971.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/index.js
24019
24019
  var require_dist_cjs64 = __commonJS((exports) => {
24020
24020
  var fromTokenFile = require_fromTokenFile();
24021
24021
  var fromWebToken = require_fromWebToken();
@@ -24039,7 +24039,7 @@ var require_dist_cjs64 = __commonJS((exports) => {
24039
24039
  });
24040
24040
  });
24041
24041
 
24042
- // ../node_modules/.pnpm/@aws-sdk+credential-provider-ini@3.970.0/node_modules/@aws-sdk/credential-provider-ini/dist-cjs/index.js
24042
+ // ../node_modules/.pnpm/@aws-sdk+credential-provider-ini@3.971.0/node_modules/@aws-sdk/credential-provider-ini/dist-cjs/index.js
24043
24043
  var require_dist_cjs65 = __commonJS((exports) => {
24044
24044
  var sharedIniFileLoader = require_dist_cjs44();
24045
24045
  var propertyProvider = require_dist_cjs18();
@@ -24227,7 +24227,7 @@ var require_dist_cjs65 = __commonJS((exports) => {
24227
24227
  exports.fromIni = fromIni;
24228
24228
  });
24229
24229
 
24230
- // ../node_modules/.pnpm/@aws-sdk+credential-provider-node@3.970.0/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js
24230
+ // ../node_modules/.pnpm/@aws-sdk+credential-provider-node@3.971.0/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js
24231
24231
  var require_dist_cjs66 = __commonJS((exports) => {
24232
24232
  var credentialProviderEnv = require_dist_cjs51();
24233
24233
  var propertyProvider = require_dist_cjs18();
@@ -25327,7 +25327,7 @@ var require_dist_cjs71 = __commonJS((exports) => {
25327
25327
  exports.readableStreamHasher = readableStreamHasher;
25328
25328
  });
25329
25329
 
25330
- // ../node_modules/.pnpm/@aws-sdk+client-s3@3.970.0/node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
25330
+ // ../node_modules/.pnpm/@aws-sdk+client-s3@3.971.0/node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
25331
25331
  var require_runtimeConfig_shared5 = __commonJS((exports) => {
25332
25332
  Object.defineProperty(exports, "__esModule", { value: true });
25333
25333
  exports.getRuntimeConfig = undefined;
@@ -25384,7 +25384,7 @@ var require_runtimeConfig_shared5 = __commonJS((exports) => {
25384
25384
  exports.getRuntimeConfig = getRuntimeConfig;
25385
25385
  });
25386
25386
 
25387
- // ../node_modules/.pnpm/@aws-sdk+client-s3@3.970.0/node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
25387
+ // ../node_modules/.pnpm/@aws-sdk+client-s3@3.971.0/node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
25388
25388
  var require_runtimeConfig5 = __commonJS((exports) => {
25389
25389
  Object.defineProperty(exports, "__esModule", { value: true });
25390
25390
  exports.getRuntimeConfig = undefined;
@@ -25453,7 +25453,7 @@ var require_runtimeConfig5 = __commonJS((exports) => {
25453
25453
  exports.getRuntimeConfig = getRuntimeConfig;
25454
25454
  });
25455
25455
 
25456
- // ../node_modules/.pnpm/@aws-sdk+middleware-ssec@3.969.0/node_modules/@aws-sdk/middleware-ssec/dist-cjs/index.js
25456
+ // ../node_modules/.pnpm/@aws-sdk+middleware-ssec@3.971.0/node_modules/@aws-sdk/middleware-ssec/dist-cjs/index.js
25457
25457
  var require_dist_cjs72 = __commonJS((exports) => {
25458
25458
  function ssecMiddleware(options) {
25459
25459
  return (next) => async (args) => {
@@ -25721,7 +25721,7 @@ var require_dist_cjs74 = __commonJS((exports) => {
25721
25721
  exports.waiterServiceDefaults = waiterServiceDefaults;
25722
25722
  });
25723
25723
 
25724
- // ../node_modules/.pnpm/@aws-sdk+client-s3@3.970.0/node_modules/@aws-sdk/client-s3/dist-cjs/index.js
25724
+ // ../node_modules/.pnpm/@aws-sdk+client-s3@3.971.0/node_modules/@aws-sdk/client-s3/dist-cjs/index.js
25725
25725
  var require_dist_cjs75 = __commonJS((exports) => {
25726
25726
  var middlewareExpectContinue = require_dist_cjs3();
25727
25727
  var middlewareFlexibleChecksums = require_dist_cjs29();
@@ -71161,7 +71161,7 @@ var require_extension = __commonJS((exports, module) => {
71161
71161
 
71162
71162
  // ../node_modules/.pnpm/@kevisual+ws@8.0.0/node_modules/@kevisual/ws/lib/websocket.js
71163
71163
  var require_websocket = __commonJS((exports, module) => {
71164
- var EventEmitter5 = __require("events");
71164
+ var EventEmitter4 = __require("events");
71165
71165
  var https2 = __require("https");
71166
71166
  var http3 = __require("http");
71167
71167
  var net = __require("net");
@@ -71194,7 +71194,7 @@ var require_websocket = __commonJS((exports, module) => {
71194
71194
  var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
71195
71195
  var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
71196
71196
 
71197
- class WebSocket2 extends EventEmitter5 {
71197
+ class WebSocket2 extends EventEmitter4 {
71198
71198
  constructor(address, protocols, options) {
71199
71199
  super();
71200
71200
  this._binaryType = BINARY_TYPES[0];
@@ -72068,7 +72068,7 @@ var require_subprotocol = __commonJS((exports, module) => {
72068
72068
 
72069
72069
  // ../node_modules/.pnpm/@kevisual+ws@8.0.0/node_modules/@kevisual/ws/lib/websocket-server.js
72070
72070
  var require_websocket_server = __commonJS((exports, module) => {
72071
- var EventEmitter5 = __require("events");
72071
+ var EventEmitter4 = __require("events");
72072
72072
  var http3 = __require("http");
72073
72073
  var { Duplex } = __require("stream");
72074
72074
  var { createHash } = __require("crypto");
@@ -72082,7 +72082,7 @@ var require_websocket_server = __commonJS((exports, module) => {
72082
72082
  var CLOSING = 1;
72083
72083
  var CLOSED = 2;
72084
72084
 
72085
- class WebSocketServer2 extends EventEmitter5 {
72085
+ class WebSocketServer2 extends EventEmitter4 {
72086
72086
  constructor(options, callback) {
72087
72087
  super();
72088
72088
  options = {
@@ -100810,1453 +100810,827 @@ app.route({
100810
100810
  ctx.forward(res);
100811
100811
  }).addTo(app);
100812
100812
 
100813
- // src/routes/hot-api/key-sender/lib.ts
100814
- import { keyboard, Key } from "@nut-tree-fork/nut-js";
100815
- var keyMap = {
100816
- ctrl: Key.LeftControl,
100817
- leftctrl: Key.LeftControl,
100818
- rightctrl: Key.RightControl,
100819
- alt: Key.LeftAlt,
100820
- leftalt: Key.LeftAlt,
100821
- rightalt: Key.RightAlt,
100822
- shift: Key.LeftShift,
100823
- leftshift: Key.LeftShift,
100824
- rightshift: Key.RightShift,
100825
- meta: Key.LeftSuper,
100826
- cmd: Key.LeftCmd,
100827
- win: Key.LeftWin,
100828
- ctrlorcommand: process.platform === "darwin" ? Key.LeftCmd : Key.LeftControl
100829
- };
100830
- var parseHotkey = (hotkey) => {
100831
- return hotkey.toLowerCase().split("+").map((key) => {
100832
- const trimmed = key.trim().toLowerCase();
100833
- if (keyMap[trimmed]) {
100834
- return keyMap[trimmed];
100835
- }
100836
- if (trimmed.length === 1 && /[a-z]/.test(trimmed)) {
100837
- const upperKey = trimmed.toUpperCase();
100838
- return Key[upperKey];
100839
- }
100840
- return Key[trimmed];
100841
- }).filter((key) => key !== undefined);
100842
- };
100843
- var pressHotkey = async (opts) => {
100844
- const { hotkey, durationMs = 100 } = opts;
100845
- const keys = parseHotkey(hotkey);
100846
- console.log("准备模拟按下快捷键:", hotkey);
100847
- await keyboard.pressKey(...keys);
100848
- await new Promise((resolve) => setTimeout(resolve, durationMs));
100849
- await keyboard.releaseKey(...keys);
100850
- return true;
100851
- };
100852
- var pressHotkeys = async (opts) => {
100853
- let { hotkey } = opts;
100854
- hotkey = hotkey.replace(/\s+/g, "");
100855
- const hotkeyList = hotkey.split(",").map((hk) => hk.trim());
100856
- if (hotkeyList.length === 0) {
100857
- return await pressHotkey({ ...opts, hotkey });
100858
- }
100859
- for (const hk of hotkeyList) {
100860
- await pressHotkey({ ...opts, hotkey: hk });
100861
- await new Promise((resolve) => setTimeout(resolve, 200));
100862
- }
100863
- return true;
100813
+ // src/routes/index.ts
100814
+ import os4 from "node:os";
100815
+
100816
+ // ../node_modules/.pnpm/lru-cache@11.2.4/node_modules/lru-cache/dist/esm/index.js
100817
+ var defaultPerf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
100818
+ var warned = new Set;
100819
+ var PROCESS = typeof process === "object" && !!process ? process : {};
100820
+ var emitWarning = (msg, type, code, fn) => {
100821
+ typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
100864
100822
  };
100823
+ var AC = globalThis.AbortController;
100824
+ var AS = globalThis.AbortSignal;
100825
+ if (typeof AC === "undefined") {
100826
+ AS = class AbortSignal {
100827
+ onabort;
100828
+ _onabort = [];
100829
+ reason;
100830
+ aborted = false;
100831
+ addEventListener(_2, fn) {
100832
+ this._onabort.push(fn);
100833
+ }
100834
+ };
100835
+ AC = class AbortController2 {
100836
+ constructor() {
100837
+ warnACPolyfill();
100838
+ }
100839
+ signal = new AS;
100840
+ abort(reason) {
100841
+ if (this.signal.aborted)
100842
+ return;
100843
+ this.signal.reason = reason;
100844
+ this.signal.aborted = true;
100845
+ for (const fn of this.signal._onabort) {
100846
+ fn(reason);
100847
+ }
100848
+ this.signal.onabort?.(reason);
100849
+ }
100850
+ };
100851
+ let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1";
100852
+ const warnACPolyfill = () => {
100853
+ if (!printACPolyfillWarning)
100854
+ return;
100855
+ printACPolyfillWarning = false;
100856
+ emitWarning("AbortController is not defined. If using lru-cache in " + "node 14, load an AbortController polyfill from the " + "`node-abort-controller` package. A minimal polyfill is " + "provided for use by LRUCache.fetch(), but it should not be " + "relied upon in other contexts (eg, passing it to other APIs that " + "use AbortController/AbortSignal might have undesirable effects). " + "You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", warnACPolyfill);
100857
+ };
100858
+ }
100859
+ var shouldWarn = (code) => !warned.has(code);
100860
+ var TYPE = Symbol("type");
100861
+ var isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
100862
+ var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
100865
100863
 
100866
- class Hotkeys {
100867
- pressHotkey = pressHotkey;
100868
- pressHotkeys = pressHotkeys;
100864
+ class ZeroArray extends Array {
100865
+ constructor(size) {
100866
+ super(size);
100867
+ this.fill(0);
100868
+ }
100869
100869
  }
100870
100870
 
100871
- // ../node_modules/.pnpm/@kevisual+context@0.0.4/node_modules/@kevisual/context/dist/app.js
100872
- var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
100873
- function getDefaultExportFromCjs4(x) {
100874
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
100871
+ class Stack3 {
100872
+ heap;
100873
+ length;
100874
+ static #constructing = false;
100875
+ static create(max) {
100876
+ const HeapCls = getUintArray(max);
100877
+ if (!HeapCls)
100878
+ return [];
100879
+ Stack3.#constructing = true;
100880
+ const s = new Stack3(max, HeapCls);
100881
+ Stack3.#constructing = false;
100882
+ return s;
100883
+ }
100884
+ constructor(max, HeapCls) {
100885
+ if (!Stack3.#constructing) {
100886
+ throw new TypeError("instantiate Stack using Stack.create(n)");
100887
+ }
100888
+ this.heap = new HeapCls(max);
100889
+ this.length = 0;
100890
+ }
100891
+ push(n) {
100892
+ this.heap[this.length++] = n;
100893
+ }
100894
+ pop() {
100895
+ return this.heap[--this.length];
100896
+ }
100875
100897
  }
100876
- var eventemitter33 = { exports: {} };
100877
- var hasRequiredEventemitter33;
100878
- function requireEventemitter33() {
100879
- if (hasRequiredEventemitter33)
100880
- return eventemitter33.exports;
100881
- hasRequiredEventemitter33 = 1;
100882
- (function(module) {
100883
- var has = Object.prototype.hasOwnProperty, prefix = "~";
100884
- function Events() {}
100885
- if (Object.create) {
100886
- Events.prototype = Object.create(null);
100887
- if (!new Events().__proto__)
100888
- prefix = false;
100898
+
100899
+ class LRUCache {
100900
+ #max;
100901
+ #maxSize;
100902
+ #dispose;
100903
+ #onInsert;
100904
+ #disposeAfter;
100905
+ #fetchMethod;
100906
+ #memoMethod;
100907
+ #perf;
100908
+ get perf() {
100909
+ return this.#perf;
100910
+ }
100911
+ ttl;
100912
+ ttlResolution;
100913
+ ttlAutopurge;
100914
+ updateAgeOnGet;
100915
+ updateAgeOnHas;
100916
+ allowStale;
100917
+ noDisposeOnSet;
100918
+ noUpdateTTL;
100919
+ maxEntrySize;
100920
+ sizeCalculation;
100921
+ noDeleteOnFetchRejection;
100922
+ noDeleteOnStaleGet;
100923
+ allowStaleOnFetchAbort;
100924
+ allowStaleOnFetchRejection;
100925
+ ignoreFetchAbort;
100926
+ #size;
100927
+ #calculatedSize;
100928
+ #keyMap;
100929
+ #keyList;
100930
+ #valList;
100931
+ #next;
100932
+ #prev;
100933
+ #head;
100934
+ #tail;
100935
+ #free;
100936
+ #disposed;
100937
+ #sizes;
100938
+ #starts;
100939
+ #ttls;
100940
+ #autopurgeTimers;
100941
+ #hasDispose;
100942
+ #hasFetchMethod;
100943
+ #hasDisposeAfter;
100944
+ #hasOnInsert;
100945
+ static unsafeExposeInternals(c) {
100946
+ return {
100947
+ starts: c.#starts,
100948
+ ttls: c.#ttls,
100949
+ autopurgeTimers: c.#autopurgeTimers,
100950
+ sizes: c.#sizes,
100951
+ keyMap: c.#keyMap,
100952
+ keyList: c.#keyList,
100953
+ valList: c.#valList,
100954
+ next: c.#next,
100955
+ prev: c.#prev,
100956
+ get head() {
100957
+ return c.#head;
100958
+ },
100959
+ get tail() {
100960
+ return c.#tail;
100961
+ },
100962
+ free: c.#free,
100963
+ isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
100964
+ backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
100965
+ moveToTail: (index) => c.#moveToTail(index),
100966
+ indexes: (options) => c.#indexes(options),
100967
+ rindexes: (options) => c.#rindexes(options),
100968
+ isStale: (index) => c.#isStale(index)
100969
+ };
100970
+ }
100971
+ get max() {
100972
+ return this.#max;
100973
+ }
100974
+ get maxSize() {
100975
+ return this.#maxSize;
100976
+ }
100977
+ get calculatedSize() {
100978
+ return this.#calculatedSize;
100979
+ }
100980
+ get size() {
100981
+ return this.#size;
100982
+ }
100983
+ get fetchMethod() {
100984
+ return this.#fetchMethod;
100985
+ }
100986
+ get memoMethod() {
100987
+ return this.#memoMethod;
100988
+ }
100989
+ get dispose() {
100990
+ return this.#dispose;
100991
+ }
100992
+ get onInsert() {
100993
+ return this.#onInsert;
100994
+ }
100995
+ get disposeAfter() {
100996
+ return this.#disposeAfter;
100997
+ }
100998
+ constructor(options) {
100999
+ const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf } = options;
101000
+ if (perf !== undefined) {
101001
+ if (typeof perf?.now !== "function") {
101002
+ throw new TypeError("perf option must have a now() method if specified");
101003
+ }
100889
101004
  }
100890
- function EE(fn, context, once) {
100891
- this.fn = fn;
100892
- this.context = context;
100893
- this.once = once || false;
101005
+ this.#perf = perf ?? defaultPerf;
101006
+ if (max !== 0 && !isPosInt(max)) {
101007
+ throw new TypeError("max option must be a nonnegative integer");
100894
101008
  }
100895
- function addListener(emitter, event, fn, context, once) {
100896
- if (typeof fn !== "function") {
100897
- throw new TypeError("The listener must be a function");
101009
+ const UintArray = max ? getUintArray(max) : Array;
101010
+ if (!UintArray) {
101011
+ throw new Error("invalid max value: " + max);
101012
+ }
101013
+ this.#max = max;
101014
+ this.#maxSize = maxSize;
101015
+ this.maxEntrySize = maxEntrySize || this.#maxSize;
101016
+ this.sizeCalculation = sizeCalculation;
101017
+ if (this.sizeCalculation) {
101018
+ if (!this.#maxSize && !this.maxEntrySize) {
101019
+ throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
101020
+ }
101021
+ if (typeof this.sizeCalculation !== "function") {
101022
+ throw new TypeError("sizeCalculation set to non-function");
100898
101023
  }
100899
- var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
100900
- if (!emitter._events[evt])
100901
- emitter._events[evt] = listener, emitter._eventsCount++;
100902
- else if (!emitter._events[evt].fn)
100903
- emitter._events[evt].push(listener);
100904
- else
100905
- emitter._events[evt] = [emitter._events[evt], listener];
100906
- return emitter;
100907
101024
  }
100908
- function clearEvent(emitter, evt) {
100909
- if (--emitter._eventsCount === 0)
100910
- emitter._events = new Events;
100911
- else
100912
- delete emitter._events[evt];
101025
+ if (memoMethod !== undefined && typeof memoMethod !== "function") {
101026
+ throw new TypeError("memoMethod must be a function if defined");
100913
101027
  }
100914
- function EventEmitter4() {
100915
- this._events = new Events;
100916
- this._eventsCount = 0;
101028
+ this.#memoMethod = memoMethod;
101029
+ if (fetchMethod !== undefined && typeof fetchMethod !== "function") {
101030
+ throw new TypeError("fetchMethod must be a function if specified");
100917
101031
  }
100918
- EventEmitter4.prototype.eventNames = function eventNames() {
100919
- var names = [], events, name;
100920
- if (this._eventsCount === 0)
100921
- return names;
100922
- for (name in events = this._events) {
100923
- if (has.call(events, name))
100924
- names.push(prefix ? name.slice(1) : name);
101032
+ this.#fetchMethod = fetchMethod;
101033
+ this.#hasFetchMethod = !!fetchMethod;
101034
+ this.#keyMap = new Map;
101035
+ this.#keyList = new Array(max).fill(undefined);
101036
+ this.#valList = new Array(max).fill(undefined);
101037
+ this.#next = new UintArray(max);
101038
+ this.#prev = new UintArray(max);
101039
+ this.#head = 0;
101040
+ this.#tail = 0;
101041
+ this.#free = Stack3.create(max);
101042
+ this.#size = 0;
101043
+ this.#calculatedSize = 0;
101044
+ if (typeof dispose === "function") {
101045
+ this.#dispose = dispose;
101046
+ }
101047
+ if (typeof onInsert === "function") {
101048
+ this.#onInsert = onInsert;
101049
+ }
101050
+ if (typeof disposeAfter === "function") {
101051
+ this.#disposeAfter = disposeAfter;
101052
+ this.#disposed = [];
101053
+ } else {
101054
+ this.#disposeAfter = undefined;
101055
+ this.#disposed = undefined;
101056
+ }
101057
+ this.#hasDispose = !!this.#dispose;
101058
+ this.#hasOnInsert = !!this.#onInsert;
101059
+ this.#hasDisposeAfter = !!this.#disposeAfter;
101060
+ this.noDisposeOnSet = !!noDisposeOnSet;
101061
+ this.noUpdateTTL = !!noUpdateTTL;
101062
+ this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
101063
+ this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
101064
+ this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
101065
+ this.ignoreFetchAbort = !!ignoreFetchAbort;
101066
+ if (this.maxEntrySize !== 0) {
101067
+ if (this.#maxSize !== 0) {
101068
+ if (!isPosInt(this.#maxSize)) {
101069
+ throw new TypeError("maxSize must be a positive integer if specified");
101070
+ }
100925
101071
  }
100926
- if (Object.getOwnPropertySymbols) {
100927
- return names.concat(Object.getOwnPropertySymbols(events));
101072
+ if (!isPosInt(this.maxEntrySize)) {
101073
+ throw new TypeError("maxEntrySize must be a positive integer if specified");
100928
101074
  }
100929
- return names;
100930
- };
100931
- EventEmitter4.prototype.listeners = function listeners(event) {
100932
- var evt = prefix ? prefix + event : event, handlers = this._events[evt];
100933
- if (!handlers)
100934
- return [];
100935
- if (handlers.fn)
100936
- return [handlers.fn];
100937
- for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) {
100938
- ee[i] = handlers[i].fn;
101075
+ this.#initializeSizeTracking();
101076
+ }
101077
+ this.allowStale = !!allowStale;
101078
+ this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
101079
+ this.updateAgeOnGet = !!updateAgeOnGet;
101080
+ this.updateAgeOnHas = !!updateAgeOnHas;
101081
+ this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
101082
+ this.ttlAutopurge = !!ttlAutopurge;
101083
+ this.ttl = ttl || 0;
101084
+ if (this.ttl) {
101085
+ if (!isPosInt(this.ttl)) {
101086
+ throw new TypeError("ttl must be a positive integer if specified");
100939
101087
  }
100940
- return ee;
100941
- };
100942
- EventEmitter4.prototype.listenerCount = function listenerCount(event) {
100943
- var evt = prefix ? prefix + event : event, listeners = this._events[evt];
100944
- if (!listeners)
100945
- return 0;
100946
- if (listeners.fn)
100947
- return 1;
100948
- return listeners.length;
100949
- };
100950
- EventEmitter4.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
100951
- var evt = prefix ? prefix + event : event;
100952
- if (!this._events[evt])
100953
- return false;
100954
- var listeners = this._events[evt], len = arguments.length, args, i;
100955
- if (listeners.fn) {
100956
- if (listeners.once)
100957
- this.removeListener(event, listeners.fn, undefined, true);
100958
- switch (len) {
100959
- case 1:
100960
- return listeners.fn.call(listeners.context), true;
100961
- case 2:
100962
- return listeners.fn.call(listeners.context, a1), true;
100963
- case 3:
100964
- return listeners.fn.call(listeners.context, a1, a2), true;
100965
- case 4:
100966
- return listeners.fn.call(listeners.context, a1, a2, a3), true;
100967
- case 5:
100968
- return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
100969
- case 6:
100970
- return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
100971
- }
100972
- for (i = 1, args = new Array(len - 1);i < len; i++) {
100973
- args[i - 1] = arguments[i];
100974
- }
100975
- listeners.fn.apply(listeners.context, args);
100976
- } else {
100977
- var length = listeners.length, j;
100978
- for (i = 0;i < length; i++) {
100979
- if (listeners[i].once)
100980
- this.removeListener(event, listeners[i].fn, undefined, true);
100981
- switch (len) {
100982
- case 1:
100983
- listeners[i].fn.call(listeners[i].context);
100984
- break;
100985
- case 2:
100986
- listeners[i].fn.call(listeners[i].context, a1);
100987
- break;
100988
- case 3:
100989
- listeners[i].fn.call(listeners[i].context, a1, a2);
100990
- break;
100991
- case 4:
100992
- listeners[i].fn.call(listeners[i].context, a1, a2, a3);
100993
- break;
100994
- default:
100995
- if (!args)
100996
- for (j = 1, args = new Array(len - 1);j < len; j++) {
100997
- args[j - 1] = arguments[j];
100998
- }
100999
- listeners[i].fn.apply(listeners[i].context, args);
101088
+ this.#initializeTTLTracking();
101089
+ }
101090
+ if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
101091
+ throw new TypeError("At least one of max, maxSize, or ttl is required");
101092
+ }
101093
+ if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
101094
+ const code = "LRU_CACHE_UNBOUNDED";
101095
+ if (shouldWarn(code)) {
101096
+ warned.add(code);
101097
+ const msg = "TTL caching without ttlAutopurge, max, or maxSize can " + "result in unbounded memory consumption.";
101098
+ emitWarning(msg, "UnboundedCacheWarning", code, LRUCache);
101099
+ }
101100
+ }
101101
+ }
101102
+ getRemainingTTL(key) {
101103
+ return this.#keyMap.has(key) ? Infinity : 0;
101104
+ }
101105
+ #initializeTTLTracking() {
101106
+ const ttls = new ZeroArray(this.#max);
101107
+ const starts = new ZeroArray(this.#max);
101108
+ this.#ttls = ttls;
101109
+ this.#starts = starts;
101110
+ const purgeTimers = this.ttlAutopurge ? new Array(this.#max) : undefined;
101111
+ this.#autopurgeTimers = purgeTimers;
101112
+ this.#setItemTTL = (index, ttl, start4 = this.#perf.now()) => {
101113
+ starts[index] = ttl !== 0 ? start4 : 0;
101114
+ ttls[index] = ttl;
101115
+ if (purgeTimers?.[index]) {
101116
+ clearTimeout(purgeTimers[index]);
101117
+ purgeTimers[index] = undefined;
101118
+ }
101119
+ if (ttl !== 0 && purgeTimers) {
101120
+ const t = setTimeout(() => {
101121
+ if (this.#isStale(index)) {
101122
+ this.#delete(this.#keyList[index], "expire");
101000
101123
  }
101124
+ }, ttl + 1);
101125
+ if (t.unref) {
101126
+ t.unref();
101001
101127
  }
101128
+ purgeTimers[index] = t;
101002
101129
  }
101003
- return true;
101004
- };
101005
- EventEmitter4.prototype.on = function on(event, fn, context) {
101006
- return addListener(this, event, fn, context, false);
101007
101130
  };
101008
- EventEmitter4.prototype.once = function once(event, fn, context) {
101009
- return addListener(this, event, fn, context, true);
101131
+ this.#updateItemAge = (index) => {
101132
+ starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
101010
101133
  };
101011
- EventEmitter4.prototype.removeListener = function removeListener(event, fn, context, once) {
101012
- var evt = prefix ? prefix + event : event;
101013
- if (!this._events[evt])
101014
- return this;
101015
- if (!fn) {
101016
- clearEvent(this, evt);
101017
- return this;
101134
+ this.#statusTTL = (status, index) => {
101135
+ if (ttls[index]) {
101136
+ const ttl = ttls[index];
101137
+ const start4 = starts[index];
101138
+ if (!ttl || !start4)
101139
+ return;
101140
+ status.ttl = ttl;
101141
+ status.start = start4;
101142
+ status.now = cachedNow || getNow();
101143
+ const age = status.now - start4;
101144
+ status.remainingTTL = ttl - age;
101018
101145
  }
101019
- var listeners = this._events[evt];
101020
- if (listeners.fn) {
101021
- if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
101022
- clearEvent(this, evt);
101023
- }
101024
- } else {
101025
- for (var i = 0, events = [], length = listeners.length;i < length; i++) {
101026
- if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
101027
- events.push(listeners[i]);
101028
- }
101146
+ };
101147
+ let cachedNow = 0;
101148
+ const getNow = () => {
101149
+ const n = this.#perf.now();
101150
+ if (this.ttlResolution > 0) {
101151
+ cachedNow = n;
101152
+ const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
101153
+ if (t.unref) {
101154
+ t.unref();
101029
101155
  }
101030
- if (events.length)
101031
- this._events[evt] = events.length === 1 ? events[0] : events;
101032
- else
101033
- clearEvent(this, evt);
101034
101156
  }
101035
- return this;
101157
+ return n;
101036
101158
  };
101037
- EventEmitter4.prototype.removeAllListeners = function removeAllListeners(event) {
101038
- var evt;
101039
- if (event) {
101040
- evt = prefix ? prefix + event : event;
101041
- if (this._events[evt])
101042
- clearEvent(this, evt);
101043
- } else {
101044
- this._events = new Events;
101045
- this._eventsCount = 0;
101159
+ this.getRemainingTTL = (key) => {
101160
+ const index = this.#keyMap.get(key);
101161
+ if (index === undefined) {
101162
+ return 0;
101046
101163
  }
101047
- return this;
101164
+ const ttl = ttls[index];
101165
+ const start4 = starts[index];
101166
+ if (!ttl || !start4) {
101167
+ return Infinity;
101168
+ }
101169
+ const age = (cachedNow || getNow()) - start4;
101170
+ return ttl - age;
101048
101171
  };
101049
- EventEmitter4.prototype.off = EventEmitter4.prototype.removeListener;
101050
- EventEmitter4.prototype.addListener = EventEmitter4.prototype.on;
101051
- EventEmitter4.prefixed = prefix;
101052
- EventEmitter4.EventEmitter = EventEmitter4;
101053
- {
101054
- module.exports = EventEmitter4;
101055
- }
101056
- })(eventemitter33);
101057
- return eventemitter33.exports;
101058
- }
101059
- var eventemitter3Exports3 = requireEventemitter33();
101060
- var EventEmitter4 = /* @__PURE__ */ getDefaultExportFromCjs4(eventemitter3Exports3);
101061
- var reRunFn2 = (promiseOpts) => {
101062
- const timeout = promiseOpts.timeout || 5 * 60 * 1000;
101063
- const interval = promiseOpts.interval || 1000;
101064
- const checkSuccess = promiseOpts?.checkSuccess || (() => true);
101065
- const signal = promiseOpts.signal;
101066
- return new Promise(async (resolve, reject) => {
101067
- let intervalId;
101068
- let timeoutId = setTimeout(() => {
101069
- clearTimeout(intervalId);
101070
- resolve({
101071
- code: 500,
101072
- message: "timeout"
101073
- });
101074
- }, timeout);
101075
- const fn = promiseOpts.fn || (() => true);
101076
- const runFn = async () => {
101077
- if (signal?.aborted) {
101078
- clearInterval(intervalId);
101079
- clearTimeout(timeoutId);
101080
- return resolve({
101081
- code: 499,
101082
- message: "operation cancelled"
101083
- });
101084
- }
101085
- const res = await fn();
101086
- if (!!checkSuccess(res)) {
101087
- clearInterval(intervalId);
101088
- clearTimeout(timeoutId);
101089
- resolve({
101090
- code: 200,
101091
- data: res
101092
- });
101093
- } else {
101094
- setTimeout(() => {
101095
- runFn();
101096
- }, interval);
101097
- }
101172
+ this.#isStale = (index) => {
101173
+ const s = starts[index];
101174
+ const t = ttls[index];
101175
+ return !!t && !!s && (cachedNow || getNow()) - s > t;
101098
101176
  };
101099
- if (signal) {
101100
- signal.addEventListener("abort", () => {
101101
- clearInterval(intervalId);
101102
- clearTimeout(timeoutId);
101103
- resolve({
101104
- code: 499,
101105
- message: "operation cancelled"
101106
- });
101107
- });
101108
- }
101109
- runFn();
101110
- });
101111
- };
101112
-
101113
- class BaseLoad2 {
101114
- modules = new Map;
101115
- event;
101116
- loading;
101117
- static reRunFn = reRunFn2;
101118
- timeout = 5 * 60 * 1000;
101119
- constructor() {
101120
- this.event = new EventEmitter4;
101121
- this.loading = false;
101122
101177
  }
101123
- listenKey(key, listenOpts) {
101124
- const timeout = listenOpts?.timeout ?? this.timeout;
101125
- return new Promise((resolve) => {
101126
- const timeoutId = setTimeout(() => {
101127
- this.event.removeListener(key, onEvent);
101128
- resolve({
101129
- code: 500,
101130
- message: "timeout"
101131
- });
101132
- }, timeout);
101133
- const onEvent = (error2) => {
101134
- clearTimeout(timeoutId);
101135
- if (error2) {
101136
- return resolve({
101137
- code: 500,
101138
- message: error2
101139
- });
101178
+ #updateItemAge = () => {};
101179
+ #statusTTL = () => {};
101180
+ #setItemTTL = () => {};
101181
+ #isStale = () => false;
101182
+ #initializeSizeTracking() {
101183
+ const sizes = new ZeroArray(this.#max);
101184
+ this.#calculatedSize = 0;
101185
+ this.#sizes = sizes;
101186
+ this.#removeItemSize = (index) => {
101187
+ this.#calculatedSize -= sizes[index];
101188
+ sizes[index] = 0;
101189
+ };
101190
+ this.#requireSize = (k, v, size, sizeCalculation) => {
101191
+ if (this.#isBackgroundFetch(v)) {
101192
+ return 0;
101193
+ }
101194
+ if (!isPosInt(size)) {
101195
+ if (sizeCalculation) {
101196
+ if (typeof sizeCalculation !== "function") {
101197
+ throw new TypeError("sizeCalculation must be a function");
101198
+ }
101199
+ size = sizeCalculation(v, k);
101200
+ if (!isPosInt(size)) {
101201
+ throw new TypeError("sizeCalculation return invalid (expect positive integer)");
101202
+ }
101203
+ } else {
101204
+ throw new TypeError("invalid size value (must be positive integer). " + "When maxSize or maxEntrySize is used, sizeCalculation " + "or size must be set.");
101140
101205
  }
101141
- const data = this.modules.get(key);
101142
- if (data?.loadSuccessClear) {
101143
- this.remove(key);
101206
+ }
101207
+ return size;
101208
+ };
101209
+ this.#addItemSize = (index, size, status) => {
101210
+ sizes[index] = size;
101211
+ if (this.#maxSize) {
101212
+ const maxSize = this.#maxSize - sizes[index];
101213
+ while (this.#calculatedSize > maxSize) {
101214
+ this.#evict(true);
101144
101215
  }
101145
- resolve({
101146
- code: 200,
101147
- data: data?.modules
101148
- });
101149
- };
101150
- this.event.once(key, onEvent);
101151
- });
101152
- }
101153
- async hasLoaded(key, hasLoadOpts) {
101154
- if (!key) {
101155
- return {
101156
- code: 404,
101157
- message: "key is required"
101158
- };
101159
- }
101160
- const has = this.modules.has(key);
101161
- if (!has) {
101162
- const isExist = hasLoadOpts?.isExist ?? true;
101163
- const timeout = hasLoadOpts?.timeout ?? this.timeout;
101164
- if (isExist) {
101165
- return await this.listenKey(key, { timeout });
101166
101216
  }
101167
- return {
101168
- code: 404
101169
- };
101170
- }
101171
- const data = this.modules.get(key);
101172
- if (data?.status === "loaded") {
101173
- return {
101174
- code: 200,
101175
- data: data.modules
101176
- };
101177
- }
101178
- if (data?.status === "loading") {
101179
- return await this.listenKey(key, { timeout: hasLoadOpts?.timeout ?? this.timeout });
101180
- }
101181
- if (data?.status === "error") {
101182
- return {
101183
- code: 500,
101184
- message: "load error"
101185
- };
101186
- }
101187
- if (data?.status === "cancel") {
101188
- return {
101189
- code: 499,
101190
- message: "operation cancelled"
101191
- };
101192
- }
101193
- return {
101194
- code: 404
101217
+ this.#calculatedSize += sizes[index];
101218
+ if (status) {
101219
+ status.entrySize = size;
101220
+ status.totalCalculatedSize = this.#calculatedSize;
101221
+ }
101195
101222
  };
101196
101223
  }
101197
- async loadFn(loadContent, opts) {
101198
- const key = opts.key;
101199
- if (!key) {
101200
- return {
101201
- code: 404,
101202
- message: "key is required"
101203
- };
101224
+ #removeItemSize = (_i) => {};
101225
+ #addItemSize = (_i, _s, _st) => {};
101226
+ #requireSize = (_k, _v, size, sizeCalculation) => {
101227
+ if (size || sizeCalculation) {
101228
+ throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
101204
101229
  }
101205
- const newModule = {
101206
- key: opts.key,
101207
- status: "loading",
101208
- loading: true,
101209
- loadSuccessClear: opts.loadSuccessClear ?? true
101210
- };
101211
- let errorMessage = "";
101212
- try {
101213
- const isReRun = opts.isReRun ?? false;
101214
- let res;
101215
- if (!isReRun) {
101216
- this.modules.set(key, newModule);
101217
- res = await loadContent();
101218
- } else {
101219
- newModule.controller = new AbortController;
101220
- const signal = newModule.controller.signal;
101221
- this.modules.set(key, newModule);
101222
- const data = await reRunFn2({
101223
- timeout: opts.timeout,
101224
- interval: opts.interval,
101225
- checkSuccess: opts.checkSuccess,
101226
- fn: loadContent,
101227
- signal
101228
- });
101229
- newModule.controller = null;
101230
- if (data.code === 499) {
101231
- newModule.status = "cancel";
101232
- return {
101233
- code: 499,
101234
- message: "operation cancelled"
101235
- };
101230
+ return 0;
101231
+ };
101232
+ *#indexes({ allowStale = this.allowStale } = {}) {
101233
+ if (this.#size) {
101234
+ for (let i = this.#tail;; ) {
101235
+ if (!this.#isValidIndex(i)) {
101236
+ break;
101236
101237
  }
101237
- if (data.code !== 200) {
101238
- throw new Error(data.message);
101238
+ if (allowStale || !this.#isStale(i)) {
101239
+ yield i;
101240
+ }
101241
+ if (i === this.#head) {
101242
+ break;
101243
+ } else {
101244
+ i = this.#prev[i];
101239
101245
  }
101240
- res = data.data;
101241
- }
101242
- newModule.modules = res;
101243
- newModule.status = "loaded";
101244
- return {
101245
- code: 200,
101246
- data: res
101247
- };
101248
- } catch (error2) {
101249
- errorMessage = error2.message;
101250
- newModule.status = "error";
101251
- return {
101252
- code: 500,
101253
- message: error2
101254
- };
101255
- } finally {
101256
- newModule.loading = false;
101257
- this.modules.set(opts.key, newModule);
101258
- if (!errorMessage) {
101259
- this.event.emit(opts.key);
101260
- } else {
101261
- this.event.emit(opts.key, errorMessage);
101262
101246
  }
101263
101247
  }
101264
101248
  }
101265
- async load(loadContent, opts) {
101266
- this.loading = true;
101267
- const key = opts.key;
101268
- if (!key) {
101269
- return {
101270
- code: 404,
101271
- message: "key is required"
101272
- };
101249
+ *#rindexes({ allowStale = this.allowStale } = {}) {
101250
+ if (this.#size) {
101251
+ for (let i = this.#head;; ) {
101252
+ if (!this.#isValidIndex(i)) {
101253
+ break;
101254
+ }
101255
+ if (allowStale || !this.#isStale(i)) {
101256
+ yield i;
101257
+ }
101258
+ if (i === this.#tail) {
101259
+ break;
101260
+ } else {
101261
+ i = this.#next[i];
101262
+ }
101263
+ }
101273
101264
  }
101274
- if (opts?.force) {
101275
- this.remove(key);
101265
+ }
101266
+ #isValidIndex(index) {
101267
+ return index !== undefined && this.#keyMap.get(this.#keyList[index]) === index;
101268
+ }
101269
+ *entries() {
101270
+ for (const i of this.#indexes()) {
101271
+ if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101272
+ yield [this.#keyList[i], this.#valList[i]];
101273
+ }
101276
101274
  }
101277
- const has = this.modules.has(key);
101278
- if (has) {
101279
- return await this.hasLoaded(key);
101275
+ }
101276
+ *rentries() {
101277
+ for (const i of this.#rindexes()) {
101278
+ if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101279
+ yield [this.#keyList[i], this.#valList[i]];
101280
+ }
101280
101281
  }
101281
- if (typeof loadContent === "function") {
101282
- return this.loadFn(loadContent, opts);
101282
+ }
101283
+ *keys() {
101284
+ for (const i of this.#indexes()) {
101285
+ const k = this.#keyList[i];
101286
+ if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101287
+ yield k;
101288
+ }
101283
101289
  }
101284
- console.error("loadContent is not a function and not has loaded");
101285
101290
  }
101286
- remove(key) {
101287
- const has = this.modules.has(key);
101288
- if (has) {
101289
- this.checkRemoveController(key);
101290
- this.modules.delete(key);
101291
+ *rkeys() {
101292
+ for (const i of this.#rindexes()) {
101293
+ const k = this.#keyList[i];
101294
+ if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101295
+ yield k;
101296
+ }
101291
101297
  }
101292
101298
  }
101293
- emitLoaded(key) {
101294
- this.checkRemoveController(key);
101295
- this.event.emit(key);
101299
+ *values() {
101300
+ for (const i of this.#indexes()) {
101301
+ const v = this.#valList[i];
101302
+ if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101303
+ yield this.#valList[i];
101304
+ }
101305
+ }
101296
101306
  }
101297
- setModule(key, data, loadData) {
101298
- const newModule = {
101299
- key,
101300
- status: "loaded",
101301
- loading: false,
101302
- modules: data || {},
101303
- ...loadData
101304
- };
101305
- this.modules.set(key, newModule);
101306
- this.emitLoaded(key);
101307
- return newModule;
101307
+ *rvalues() {
101308
+ for (const i of this.#rindexes()) {
101309
+ const v = this.#valList[i];
101310
+ if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101311
+ yield this.#valList[i];
101312
+ }
101313
+ }
101308
101314
  }
101309
- cancel(key) {
101310
- this.checkRemoveController(key);
101315
+ [Symbol.iterator]() {
101316
+ return this.entries();
101311
101317
  }
101312
- checkRemoveController(key) {
101313
- const data = this.modules.get(key);
101314
- if (data?.controller) {
101315
- data.controller?.abort?.();
101316
- delete data.controller;
101317
- this.modules.set(key, data);
101318
+ [Symbol.toStringTag] = "LRUCache";
101319
+ find(fn, getOptions = {}) {
101320
+ for (const i of this.#indexes()) {
101321
+ const v = this.#valList[i];
101322
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101323
+ if (value === undefined)
101324
+ continue;
101325
+ if (fn(value, this.#keyList[i], this)) {
101326
+ return this.get(this.#keyList[i], getOptions);
101327
+ }
101318
101328
  }
101319
101329
  }
101320
- }
101321
- var gt2 = globalThis || window || self;
101322
- var useEnv2 = (initEnv, initKey = "config", isOverwrite) => {
101323
- const env3 = gt2[initKey];
101324
- const _env = env3 || initEnv;
101325
- if (!env3) {
101326
- if (_env) {
101327
- gt2[initKey] = _env;
101328
- } else {
101329
- gt2[initKey] = {};
101330
+ forEach(fn, thisp = this) {
101331
+ for (const i of this.#indexes()) {
101332
+ const v = this.#valList[i];
101333
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101334
+ if (value === undefined)
101335
+ continue;
101336
+ fn.call(thisp, value, this.#keyList[i], this);
101330
101337
  }
101331
- } else if (isOverwrite) {
101332
- gt2[initKey] = { ...env3, ...initEnv };
101333
101338
  }
101334
- return gt2[initKey];
101335
- };
101336
- var useEnvKey2 = (key, init, initKey = "config") => {
101337
- const _env = useEnv2({}, initKey);
101338
- if (key && typeof _env[key] !== "undefined") {
101339
- return _env[key];
101340
- }
101341
- if (key && init) {
101342
- if (typeof init !== "function") {
101343
- _env[key] = init;
101339
+ rforEach(fn, thisp = this) {
101340
+ for (const i of this.#rindexes()) {
101341
+ const v = this.#valList[i];
101342
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101343
+ if (value === undefined)
101344
+ continue;
101345
+ fn.call(thisp, value, this.#keyList[i], this);
101344
101346
  }
101345
- if (typeof init === "function") {
101346
- const result = init();
101347
- if (result instanceof Promise) {
101348
- return result.then((res) => {
101349
- _env[key] = res;
101350
- return res;
101351
- });
101347
+ }
101348
+ purgeStale() {
101349
+ let deleted = false;
101350
+ for (const i of this.#rindexes({ allowStale: true })) {
101351
+ if (this.#isStale(i)) {
101352
+ this.#delete(this.#keyList[i], "expire");
101353
+ deleted = true;
101352
101354
  }
101353
- _env[key] = result;
101354
101355
  }
101355
- return _env[key];
101356
+ return deleted;
101356
101357
  }
101357
- if (key) {
101358
- const baseLoad = new BaseLoad2;
101359
- const voidFn = async () => {
101360
- return _env[key];
101361
- };
101362
- const checkFn = async () => {
101363
- const loadRes = await baseLoad.load(voidFn, {
101364
- key,
101365
- isReRun: true,
101366
- checkSuccess: () => _env[key],
101367
- timeout: 5 * 60 * 1000,
101368
- interval: 1000
101369
- });
101370
- if (loadRes.code !== 200) {
101371
- console.error("load key error");
101372
- return null;
101358
+ info(key) {
101359
+ const i = this.#keyMap.get(key);
101360
+ if (i === undefined)
101361
+ return;
101362
+ const v = this.#valList[i];
101363
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101364
+ if (value === undefined)
101365
+ return;
101366
+ const entry2 = { value };
101367
+ if (this.#ttls && this.#starts) {
101368
+ const ttl = this.#ttls[i];
101369
+ const start4 = this.#starts[i];
101370
+ if (ttl && start4) {
101371
+ const remain = ttl - (this.#perf.now() - start4);
101372
+ entry2.ttl = remain;
101373
+ entry2.start = Date.now();
101373
101374
  }
101374
- return _env[key];
101375
- };
101376
- return checkFn();
101377
- }
101378
- console.error("key is empty ");
101379
- return null;
101380
- };
101381
- var useEnvKeyNew2 = (key, initKey = "config", opts) => {
101382
- const _env = useEnv2({}, initKey);
101383
- if (key) {
101384
- delete _env[key];
101385
- }
101386
- if (opts?.getNew && opts.init) {
101387
- return useEnvKey2(key, opts.init, initKey);
101388
- } else if (opts?.getNew) {
101389
- return useEnvKey2(key, null, initKey);
101375
+ }
101376
+ if (this.#sizes) {
101377
+ entry2.size = this.#sizes[i];
101378
+ }
101379
+ return entry2;
101390
101380
  }
101391
- };
101392
- var useContextKey2 = (key, init, isNew) => {
101393
- if (isNew) {
101394
- return useEnvKeyNew2(key, "context", { getNew: true, init });
101381
+ dump() {
101382
+ const arr = [];
101383
+ for (const i of this.#indexes({ allowStale: true })) {
101384
+ const key = this.#keyList[i];
101385
+ const v = this.#valList[i];
101386
+ const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101387
+ if (value === undefined || key === undefined)
101388
+ continue;
101389
+ const entry2 = { value };
101390
+ if (this.#ttls && this.#starts) {
101391
+ entry2.ttl = this.#ttls[i];
101392
+ const age = this.#perf.now() - this.#starts[i];
101393
+ entry2.start = Math.floor(Date.now() - age);
101394
+ }
101395
+ if (this.#sizes) {
101396
+ entry2.size = this.#sizes[i];
101397
+ }
101398
+ arr.unshift([key, entry2]);
101399
+ }
101400
+ return arr;
101395
101401
  }
101396
- return useEnvKey2(key, init, "context");
101397
- };
101398
- var use2 = useContextKey2;
101399
- var useConfigKey2 = (key, init, isNew) => {
101400
- if (isNew) {
101401
- return useEnvKeyNew2(key, "config", { getNew: true, init });
101402
+ load(arr) {
101403
+ this.clear();
101404
+ for (const [key, entry2] of arr) {
101405
+ if (entry2.start) {
101406
+ const age = Date.now() - entry2.start;
101407
+ entry2.start = this.#perf.now() - age;
101408
+ }
101409
+ this.set(key, entry2.value, entry2);
101410
+ }
101402
101411
  }
101403
- return useEnvKey2(key, init, "config");
101404
- };
101405
- class InitEnv2 {
101406
- static isInit = false;
101407
- static init(opts) {
101408
- if (InitEnv2.isInit) {
101409
- return;
101412
+ set(k, v, setOptions = {}) {
101413
+ if (v === undefined) {
101414
+ this.delete(k);
101415
+ return this;
101410
101416
  }
101411
- const { load: load2 = true, page = false } = opts || {};
101412
- InitEnv2.isInit = true;
101413
- gt2.useConfigKey = useConfigKey2;
101414
- gt2.useContextKey = useContextKey2;
101415
- gt2.use = use2;
101416
- gt2.webEnv = { useConfigKey: useConfigKey2, useContextKey: useContextKey2, use: use2 };
101417
- load2 && (gt2.Load = BaseLoad2);
101418
- }
101419
- }
101420
- InitEnv2.init();
101421
-
101422
- // src/routes/hot-api/key-sender/index.ts
101423
- app.route({
101424
- path: "key-sender"
101425
- }).define(async (ctx) => {
101426
- let keys = ctx.query.keys;
101427
- if (keys.includes(" ")) {
101428
- keys = keys.replace(/\s+/g, "+");
101429
- }
101430
- const hotKeys = useContextKey2("hotkeys", () => new Hotkeys);
101431
- if (typeof keys === "string") {
101432
- await hotKeys.pressHotkey({
101433
- hotkey: keys
101434
- });
101435
- }
101436
- ctx.body = "ok";
101437
- }).addTo(app);
101438
-
101439
- // src/routes/index.ts
101440
- import os4 from "node:os";
101441
-
101442
- // ../node_modules/.pnpm/lru-cache@11.2.4/node_modules/lru-cache/dist/esm/index.js
101443
- var defaultPerf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
101444
- var warned = new Set;
101445
- var PROCESS = typeof process === "object" && !!process ? process : {};
101446
- var emitWarning = (msg, type, code, fn) => {
101447
- typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
101448
- };
101449
- var AC = globalThis.AbortController;
101450
- var AS = globalThis.AbortSignal;
101451
- if (typeof AC === "undefined") {
101452
- AS = class AbortSignal {
101453
- onabort;
101454
- _onabort = [];
101455
- reason;
101456
- aborted = false;
101457
- addEventListener(_2, fn) {
101458
- this._onabort.push(fn);
101417
+ const { ttl = this.ttl, start: start4, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
101418
+ let { noUpdateTTL = this.noUpdateTTL } = setOptions;
101419
+ const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
101420
+ if (this.maxEntrySize && size > this.maxEntrySize) {
101421
+ if (status) {
101422
+ status.set = "miss";
101423
+ status.maxEntrySizeExceeded = true;
101424
+ }
101425
+ this.#delete(k, "set");
101426
+ return this;
101459
101427
  }
101460
- };
101461
- AC = class AbortController2 {
101462
- constructor() {
101463
- warnACPolyfill();
101428
+ let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
101429
+ if (index === undefined) {
101430
+ index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
101431
+ this.#keyList[index] = k;
101432
+ this.#valList[index] = v;
101433
+ this.#keyMap.set(k, index);
101434
+ this.#next[this.#tail] = index;
101435
+ this.#prev[index] = this.#tail;
101436
+ this.#tail = index;
101437
+ this.#size++;
101438
+ this.#addItemSize(index, size, status);
101439
+ if (status)
101440
+ status.set = "add";
101441
+ noUpdateTTL = false;
101442
+ if (this.#hasOnInsert) {
101443
+ this.#onInsert?.(v, k, "add");
101444
+ }
101445
+ } else {
101446
+ this.#moveToTail(index);
101447
+ const oldVal = this.#valList[index];
101448
+ if (v !== oldVal) {
101449
+ if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
101450
+ oldVal.__abortController.abort(new Error("replaced"));
101451
+ const { __staleWhileFetching: s } = oldVal;
101452
+ if (s !== undefined && !noDisposeOnSet) {
101453
+ if (this.#hasDispose) {
101454
+ this.#dispose?.(s, k, "set");
101455
+ }
101456
+ if (this.#hasDisposeAfter) {
101457
+ this.#disposed?.push([s, k, "set"]);
101458
+ }
101459
+ }
101460
+ } else if (!noDisposeOnSet) {
101461
+ if (this.#hasDispose) {
101462
+ this.#dispose?.(oldVal, k, "set");
101463
+ }
101464
+ if (this.#hasDisposeAfter) {
101465
+ this.#disposed?.push([oldVal, k, "set"]);
101466
+ }
101467
+ }
101468
+ this.#removeItemSize(index);
101469
+ this.#addItemSize(index, size, status);
101470
+ this.#valList[index] = v;
101471
+ if (status) {
101472
+ status.set = "replace";
101473
+ const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
101474
+ if (oldValue !== undefined)
101475
+ status.oldValue = oldValue;
101476
+ }
101477
+ } else if (status) {
101478
+ status.set = "update";
101479
+ }
101480
+ if (this.#hasOnInsert) {
101481
+ this.onInsert?.(v, k, v === oldVal ? "update" : "replace");
101482
+ }
101464
101483
  }
101465
- signal = new AS;
101466
- abort(reason) {
101467
- if (this.signal.aborted)
101468
- return;
101469
- this.signal.reason = reason;
101470
- this.signal.aborted = true;
101471
- for (const fn of this.signal._onabort) {
101472
- fn(reason);
101484
+ if (ttl !== 0 && !this.#ttls) {
101485
+ this.#initializeTTLTracking();
101486
+ }
101487
+ if (this.#ttls) {
101488
+ if (!noUpdateTTL) {
101489
+ this.#setItemTTL(index, ttl, start4);
101473
101490
  }
101474
- this.signal.onabort?.(reason);
101491
+ if (status)
101492
+ this.#statusTTL(status, index);
101475
101493
  }
101476
- };
101477
- let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1";
101478
- const warnACPolyfill = () => {
101479
- if (!printACPolyfillWarning)
101480
- return;
101481
- printACPolyfillWarning = false;
101482
- emitWarning("AbortController is not defined. If using lru-cache in " + "node 14, load an AbortController polyfill from the " + "`node-abort-controller` package. A minimal polyfill is " + "provided for use by LRUCache.fetch(), but it should not be " + "relied upon in other contexts (eg, passing it to other APIs that " + "use AbortController/AbortSignal might have undesirable effects). " + "You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", warnACPolyfill);
101483
- };
101484
- }
101485
- var shouldWarn = (code) => !warned.has(code);
101486
- var TYPE = Symbol("type");
101487
- var isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
101488
- var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
101489
-
101490
- class ZeroArray extends Array {
101491
- constructor(size) {
101492
- super(size);
101493
- this.fill(0);
101494
- }
101495
- }
101496
-
101497
- class Stack3 {
101498
- heap;
101499
- length;
101500
- static #constructing = false;
101501
- static create(max) {
101502
- const HeapCls = getUintArray(max);
101503
- if (!HeapCls)
101504
- return [];
101505
- Stack3.#constructing = true;
101506
- const s = new Stack3(max, HeapCls);
101507
- Stack3.#constructing = false;
101508
- return s;
101509
- }
101510
- constructor(max, HeapCls) {
101511
- if (!Stack3.#constructing) {
101512
- throw new TypeError("instantiate Stack using Stack.create(n)");
101494
+ if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
101495
+ const dt = this.#disposed;
101496
+ let task;
101497
+ while (task = dt?.shift()) {
101498
+ this.#disposeAfter?.(...task);
101499
+ }
101513
101500
  }
101514
- this.heap = new HeapCls(max);
101515
- this.length = 0;
101516
- }
101517
- push(n) {
101518
- this.heap[this.length++] = n;
101501
+ return this;
101519
101502
  }
101520
101503
  pop() {
101521
- return this.heap[--this.length];
101522
- }
101523
- }
101524
-
101525
- class LRUCache {
101526
- #max;
101527
- #maxSize;
101528
- #dispose;
101529
- #onInsert;
101530
- #disposeAfter;
101531
- #fetchMethod;
101532
- #memoMethod;
101533
- #perf;
101534
- get perf() {
101535
- return this.#perf;
101536
- }
101537
- ttl;
101538
- ttlResolution;
101539
- ttlAutopurge;
101540
- updateAgeOnGet;
101541
- updateAgeOnHas;
101542
- allowStale;
101543
- noDisposeOnSet;
101544
- noUpdateTTL;
101545
- maxEntrySize;
101546
- sizeCalculation;
101547
- noDeleteOnFetchRejection;
101548
- noDeleteOnStaleGet;
101549
- allowStaleOnFetchAbort;
101550
- allowStaleOnFetchRejection;
101551
- ignoreFetchAbort;
101552
- #size;
101553
- #calculatedSize;
101554
- #keyMap;
101555
- #keyList;
101556
- #valList;
101557
- #next;
101558
- #prev;
101559
- #head;
101560
- #tail;
101561
- #free;
101562
- #disposed;
101563
- #sizes;
101564
- #starts;
101565
- #ttls;
101566
- #autopurgeTimers;
101567
- #hasDispose;
101568
- #hasFetchMethod;
101569
- #hasDisposeAfter;
101570
- #hasOnInsert;
101571
- static unsafeExposeInternals(c) {
101572
- return {
101573
- starts: c.#starts,
101574
- ttls: c.#ttls,
101575
- autopurgeTimers: c.#autopurgeTimers,
101576
- sizes: c.#sizes,
101577
- keyMap: c.#keyMap,
101578
- keyList: c.#keyList,
101579
- valList: c.#valList,
101580
- next: c.#next,
101581
- prev: c.#prev,
101582
- get head() {
101583
- return c.#head;
101584
- },
101585
- get tail() {
101586
- return c.#tail;
101587
- },
101588
- free: c.#free,
101589
- isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
101590
- backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
101591
- moveToTail: (index) => c.#moveToTail(index),
101592
- indexes: (options) => c.#indexes(options),
101593
- rindexes: (options) => c.#rindexes(options),
101594
- isStale: (index) => c.#isStale(index)
101595
- };
101596
- }
101597
- get max() {
101598
- return this.#max;
101599
- }
101600
- get maxSize() {
101601
- return this.#maxSize;
101602
- }
101603
- get calculatedSize() {
101604
- return this.#calculatedSize;
101605
- }
101606
- get size() {
101607
- return this.#size;
101608
- }
101609
- get fetchMethod() {
101610
- return this.#fetchMethod;
101611
- }
101612
- get memoMethod() {
101613
- return this.#memoMethod;
101614
- }
101615
- get dispose() {
101616
- return this.#dispose;
101617
- }
101618
- get onInsert() {
101619
- return this.#onInsert;
101620
- }
101621
- get disposeAfter() {
101622
- return this.#disposeAfter;
101623
- }
101624
- constructor(options) {
101625
- const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf } = options;
101626
- if (perf !== undefined) {
101627
- if (typeof perf?.now !== "function") {
101628
- throw new TypeError("perf option must have a now() method if specified");
101504
+ try {
101505
+ while (this.#size) {
101506
+ const val = this.#valList[this.#head];
101507
+ this.#evict(true);
101508
+ if (this.#isBackgroundFetch(val)) {
101509
+ if (val.__staleWhileFetching) {
101510
+ return val.__staleWhileFetching;
101511
+ }
101512
+ } else if (val !== undefined) {
101513
+ return val;
101514
+ }
101515
+ }
101516
+ } finally {
101517
+ if (this.#hasDisposeAfter && this.#disposed) {
101518
+ const dt = this.#disposed;
101519
+ let task;
101520
+ while (task = dt?.shift()) {
101521
+ this.#disposeAfter?.(...task);
101522
+ }
101629
101523
  }
101630
101524
  }
101631
- this.#perf = perf ?? defaultPerf;
101632
- if (max !== 0 && !isPosInt(max)) {
101633
- throw new TypeError("max option must be a nonnegative integer");
101634
- }
101635
- const UintArray = max ? getUintArray(max) : Array;
101636
- if (!UintArray) {
101637
- throw new Error("invalid max value: " + max);
101638
- }
101639
- this.#max = max;
101640
- this.#maxSize = maxSize;
101641
- this.maxEntrySize = maxEntrySize || this.#maxSize;
101642
- this.sizeCalculation = sizeCalculation;
101643
- if (this.sizeCalculation) {
101644
- if (!this.#maxSize && !this.maxEntrySize) {
101645
- throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
101525
+ }
101526
+ #evict(free) {
101527
+ const head = this.#head;
101528
+ const k = this.#keyList[head];
101529
+ const v = this.#valList[head];
101530
+ if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
101531
+ v.__abortController.abort(new Error("evicted"));
101532
+ } else if (this.#hasDispose || this.#hasDisposeAfter) {
101533
+ if (this.#hasDispose) {
101534
+ this.#dispose?.(v, k, "evict");
101646
101535
  }
101647
- if (typeof this.sizeCalculation !== "function") {
101648
- throw new TypeError("sizeCalculation set to non-function");
101536
+ if (this.#hasDisposeAfter) {
101537
+ this.#disposed?.push([v, k, "evict"]);
101649
101538
  }
101650
101539
  }
101651
- if (memoMethod !== undefined && typeof memoMethod !== "function") {
101652
- throw new TypeError("memoMethod must be a function if defined");
101653
- }
101654
- this.#memoMethod = memoMethod;
101655
- if (fetchMethod !== undefined && typeof fetchMethod !== "function") {
101656
- throw new TypeError("fetchMethod must be a function if specified");
101657
- }
101658
- this.#fetchMethod = fetchMethod;
101659
- this.#hasFetchMethod = !!fetchMethod;
101660
- this.#keyMap = new Map;
101661
- this.#keyList = new Array(max).fill(undefined);
101662
- this.#valList = new Array(max).fill(undefined);
101663
- this.#next = new UintArray(max);
101664
- this.#prev = new UintArray(max);
101665
- this.#head = 0;
101666
- this.#tail = 0;
101667
- this.#free = Stack3.create(max);
101668
- this.#size = 0;
101669
- this.#calculatedSize = 0;
101670
- if (typeof dispose === "function") {
101671
- this.#dispose = dispose;
101540
+ this.#removeItemSize(head);
101541
+ if (this.#autopurgeTimers?.[head]) {
101542
+ clearTimeout(this.#autopurgeTimers[head]);
101543
+ this.#autopurgeTimers[head] = undefined;
101672
101544
  }
101673
- if (typeof onInsert === "function") {
101674
- this.#onInsert = onInsert;
101545
+ if (free) {
101546
+ this.#keyList[head] = undefined;
101547
+ this.#valList[head] = undefined;
101548
+ this.#free.push(head);
101675
101549
  }
101676
- if (typeof disposeAfter === "function") {
101677
- this.#disposeAfter = disposeAfter;
101678
- this.#disposed = [];
101550
+ if (this.#size === 1) {
101551
+ this.#head = this.#tail = 0;
101552
+ this.#free.length = 0;
101679
101553
  } else {
101680
- this.#disposeAfter = undefined;
101681
- this.#disposed = undefined;
101554
+ this.#head = this.#next[head];
101682
101555
  }
101683
- this.#hasDispose = !!this.#dispose;
101684
- this.#hasOnInsert = !!this.#onInsert;
101685
- this.#hasDisposeAfter = !!this.#disposeAfter;
101686
- this.noDisposeOnSet = !!noDisposeOnSet;
101687
- this.noUpdateTTL = !!noUpdateTTL;
101688
- this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
101689
- this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
101690
- this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
101691
- this.ignoreFetchAbort = !!ignoreFetchAbort;
101692
- if (this.maxEntrySize !== 0) {
101693
- if (this.#maxSize !== 0) {
101694
- if (!isPosInt(this.#maxSize)) {
101695
- throw new TypeError("maxSize must be a positive integer if specified");
101696
- }
101556
+ this.#keyMap.delete(k);
101557
+ this.#size--;
101558
+ return head;
101559
+ }
101560
+ has(k, hasOptions = {}) {
101561
+ const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
101562
+ const index = this.#keyMap.get(k);
101563
+ if (index !== undefined) {
101564
+ const v = this.#valList[index];
101565
+ if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === undefined) {
101566
+ return false;
101697
101567
  }
101698
- if (!isPosInt(this.maxEntrySize)) {
101699
- throw new TypeError("maxEntrySize must be a positive integer if specified");
101568
+ if (!this.#isStale(index)) {
101569
+ if (updateAgeOnHas) {
101570
+ this.#updateItemAge(index);
101571
+ }
101572
+ if (status) {
101573
+ status.has = "hit";
101574
+ this.#statusTTL(status, index);
101575
+ }
101576
+ return true;
101577
+ } else if (status) {
101578
+ status.has = "stale";
101579
+ this.#statusTTL(status, index);
101700
101580
  }
101701
- this.#initializeSizeTracking();
101581
+ } else if (status) {
101582
+ status.has = "miss";
101702
101583
  }
101703
- this.allowStale = !!allowStale;
101704
- this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
101705
- this.updateAgeOnGet = !!updateAgeOnGet;
101706
- this.updateAgeOnHas = !!updateAgeOnHas;
101707
- this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
101708
- this.ttlAutopurge = !!ttlAutopurge;
101709
- this.ttl = ttl || 0;
101710
- if (this.ttl) {
101711
- if (!isPosInt(this.ttl)) {
101712
- throw new TypeError("ttl must be a positive integer if specified");
101713
- }
101714
- this.#initializeTTLTracking();
101584
+ return false;
101585
+ }
101586
+ peek(k, peekOptions = {}) {
101587
+ const { allowStale = this.allowStale } = peekOptions;
101588
+ const index = this.#keyMap.get(k);
101589
+ if (index === undefined || !allowStale && this.#isStale(index)) {
101590
+ return;
101715
101591
  }
101716
- if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
101717
- throw new TypeError("At least one of max, maxSize, or ttl is required");
101592
+ const v = this.#valList[index];
101593
+ return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101594
+ }
101595
+ #backgroundFetch(k, index, options, context) {
101596
+ const v = index === undefined ? undefined : this.#valList[index];
101597
+ if (this.#isBackgroundFetch(v)) {
101598
+ return v;
101718
101599
  }
101719
- if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
101720
- const code = "LRU_CACHE_UNBOUNDED";
101721
- if (shouldWarn(code)) {
101722
- warned.add(code);
101723
- const msg = "TTL caching without ttlAutopurge, max, or maxSize can " + "result in unbounded memory consumption.";
101724
- emitWarning(msg, "UnboundedCacheWarning", code, LRUCache);
101600
+ const ac = new AC;
101601
+ const { signal } = options;
101602
+ signal?.addEventListener("abort", () => ac.abort(signal.reason), {
101603
+ signal: ac.signal
101604
+ });
101605
+ const fetchOpts = {
101606
+ signal: ac.signal,
101607
+ options,
101608
+ context
101609
+ };
101610
+ const cb = (v2, updateCache = false) => {
101611
+ const { aborted } = ac.signal;
101612
+ const ignoreAbort = options.ignoreFetchAbort && v2 !== undefined;
101613
+ if (options.status) {
101614
+ if (aborted && !updateCache) {
101615
+ options.status.fetchAborted = true;
101616
+ options.status.fetchError = ac.signal.reason;
101617
+ if (ignoreAbort)
101618
+ options.status.fetchAbortIgnored = true;
101619
+ } else {
101620
+ options.status.fetchResolved = true;
101621
+ }
101725
101622
  }
101726
- }
101727
- }
101728
- getRemainingTTL(key) {
101729
- return this.#keyMap.has(key) ? Infinity : 0;
101730
- }
101731
- #initializeTTLTracking() {
101732
- const ttls = new ZeroArray(this.#max);
101733
- const starts = new ZeroArray(this.#max);
101734
- this.#ttls = ttls;
101735
- this.#starts = starts;
101736
- const purgeTimers = this.ttlAutopurge ? new Array(this.#max) : undefined;
101737
- this.#autopurgeTimers = purgeTimers;
101738
- this.#setItemTTL = (index, ttl, start4 = this.#perf.now()) => {
101739
- starts[index] = ttl !== 0 ? start4 : 0;
101740
- ttls[index] = ttl;
101741
- if (purgeTimers?.[index]) {
101742
- clearTimeout(purgeTimers[index]);
101743
- purgeTimers[index] = undefined;
101623
+ if (aborted && !ignoreAbort && !updateCache) {
101624
+ return fetchFail(ac.signal.reason);
101744
101625
  }
101745
- if (ttl !== 0 && purgeTimers) {
101746
- const t = setTimeout(() => {
101747
- if (this.#isStale(index)) {
101748
- this.#delete(this.#keyList[index], "expire");
101749
- }
101750
- }, ttl + 1);
101751
- if (t.unref) {
101752
- t.unref();
101753
- }
101754
- purgeTimers[index] = t;
101755
- }
101756
- };
101757
- this.#updateItemAge = (index) => {
101758
- starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
101759
- };
101760
- this.#statusTTL = (status, index) => {
101761
- if (ttls[index]) {
101762
- const ttl = ttls[index];
101763
- const start4 = starts[index];
101764
- if (!ttl || !start4)
101765
- return;
101766
- status.ttl = ttl;
101767
- status.start = start4;
101768
- status.now = cachedNow || getNow();
101769
- const age = status.now - start4;
101770
- status.remainingTTL = ttl - age;
101771
- }
101772
- };
101773
- let cachedNow = 0;
101774
- const getNow = () => {
101775
- const n = this.#perf.now();
101776
- if (this.ttlResolution > 0) {
101777
- cachedNow = n;
101778
- const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
101779
- if (t.unref) {
101780
- t.unref();
101781
- }
101782
- }
101783
- return n;
101784
- };
101785
- this.getRemainingTTL = (key) => {
101786
- const index = this.#keyMap.get(key);
101787
- if (index === undefined) {
101788
- return 0;
101789
- }
101790
- const ttl = ttls[index];
101791
- const start4 = starts[index];
101792
- if (!ttl || !start4) {
101793
- return Infinity;
101794
- }
101795
- const age = (cachedNow || getNow()) - start4;
101796
- return ttl - age;
101797
- };
101798
- this.#isStale = (index) => {
101799
- const s = starts[index];
101800
- const t = ttls[index];
101801
- return !!t && !!s && (cachedNow || getNow()) - s > t;
101802
- };
101803
- }
101804
- #updateItemAge = () => {};
101805
- #statusTTL = () => {};
101806
- #setItemTTL = () => {};
101807
- #isStale = () => false;
101808
- #initializeSizeTracking() {
101809
- const sizes = new ZeroArray(this.#max);
101810
- this.#calculatedSize = 0;
101811
- this.#sizes = sizes;
101812
- this.#removeItemSize = (index) => {
101813
- this.#calculatedSize -= sizes[index];
101814
- sizes[index] = 0;
101815
- };
101816
- this.#requireSize = (k, v, size, sizeCalculation) => {
101817
- if (this.#isBackgroundFetch(v)) {
101818
- return 0;
101819
- }
101820
- if (!isPosInt(size)) {
101821
- if (sizeCalculation) {
101822
- if (typeof sizeCalculation !== "function") {
101823
- throw new TypeError("sizeCalculation must be a function");
101824
- }
101825
- size = sizeCalculation(v, k);
101826
- if (!isPosInt(size)) {
101827
- throw new TypeError("sizeCalculation return invalid (expect positive integer)");
101828
- }
101829
- } else {
101830
- throw new TypeError("invalid size value (must be positive integer). " + "When maxSize or maxEntrySize is used, sizeCalculation " + "or size must be set.");
101831
- }
101832
- }
101833
- return size;
101834
- };
101835
- this.#addItemSize = (index, size, status) => {
101836
- sizes[index] = size;
101837
- if (this.#maxSize) {
101838
- const maxSize = this.#maxSize - sizes[index];
101839
- while (this.#calculatedSize > maxSize) {
101840
- this.#evict(true);
101841
- }
101842
- }
101843
- this.#calculatedSize += sizes[index];
101844
- if (status) {
101845
- status.entrySize = size;
101846
- status.totalCalculatedSize = this.#calculatedSize;
101847
- }
101848
- };
101849
- }
101850
- #removeItemSize = (_i) => {};
101851
- #addItemSize = (_i, _s, _st) => {};
101852
- #requireSize = (_k, _v, size, sizeCalculation) => {
101853
- if (size || sizeCalculation) {
101854
- throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
101855
- }
101856
- return 0;
101857
- };
101858
- *#indexes({ allowStale = this.allowStale } = {}) {
101859
- if (this.#size) {
101860
- for (let i = this.#tail;; ) {
101861
- if (!this.#isValidIndex(i)) {
101862
- break;
101863
- }
101864
- if (allowStale || !this.#isStale(i)) {
101865
- yield i;
101866
- }
101867
- if (i === this.#head) {
101868
- break;
101869
- } else {
101870
- i = this.#prev[i];
101871
- }
101872
- }
101873
- }
101874
- }
101875
- *#rindexes({ allowStale = this.allowStale } = {}) {
101876
- if (this.#size) {
101877
- for (let i = this.#head;; ) {
101878
- if (!this.#isValidIndex(i)) {
101879
- break;
101880
- }
101881
- if (allowStale || !this.#isStale(i)) {
101882
- yield i;
101883
- }
101884
- if (i === this.#tail) {
101885
- break;
101886
- } else {
101887
- i = this.#next[i];
101888
- }
101889
- }
101890
- }
101891
- }
101892
- #isValidIndex(index) {
101893
- return index !== undefined && this.#keyMap.get(this.#keyList[index]) === index;
101894
- }
101895
- *entries() {
101896
- for (const i of this.#indexes()) {
101897
- if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101898
- yield [this.#keyList[i], this.#valList[i]];
101899
- }
101900
- }
101901
- }
101902
- *rentries() {
101903
- for (const i of this.#rindexes()) {
101904
- if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101905
- yield [this.#keyList[i], this.#valList[i]];
101906
- }
101907
- }
101908
- }
101909
- *keys() {
101910
- for (const i of this.#indexes()) {
101911
- const k = this.#keyList[i];
101912
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101913
- yield k;
101914
- }
101915
- }
101916
- }
101917
- *rkeys() {
101918
- for (const i of this.#rindexes()) {
101919
- const k = this.#keyList[i];
101920
- if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101921
- yield k;
101922
- }
101923
- }
101924
- }
101925
- *values() {
101926
- for (const i of this.#indexes()) {
101927
- const v = this.#valList[i];
101928
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101929
- yield this.#valList[i];
101930
- }
101931
- }
101932
- }
101933
- *rvalues() {
101934
- for (const i of this.#rindexes()) {
101935
- const v = this.#valList[i];
101936
- if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
101937
- yield this.#valList[i];
101938
- }
101939
- }
101940
- }
101941
- [Symbol.iterator]() {
101942
- return this.entries();
101943
- }
101944
- [Symbol.toStringTag] = "LRUCache";
101945
- find(fn, getOptions = {}) {
101946
- for (const i of this.#indexes()) {
101947
- const v = this.#valList[i];
101948
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101949
- if (value === undefined)
101950
- continue;
101951
- if (fn(value, this.#keyList[i], this)) {
101952
- return this.get(this.#keyList[i], getOptions);
101953
- }
101954
- }
101955
- }
101956
- forEach(fn, thisp = this) {
101957
- for (const i of this.#indexes()) {
101958
- const v = this.#valList[i];
101959
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101960
- if (value === undefined)
101961
- continue;
101962
- fn.call(thisp, value, this.#keyList[i], this);
101963
- }
101964
- }
101965
- rforEach(fn, thisp = this) {
101966
- for (const i of this.#rindexes()) {
101967
- const v = this.#valList[i];
101968
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101969
- if (value === undefined)
101970
- continue;
101971
- fn.call(thisp, value, this.#keyList[i], this);
101972
- }
101973
- }
101974
- purgeStale() {
101975
- let deleted = false;
101976
- for (const i of this.#rindexes({ allowStale: true })) {
101977
- if (this.#isStale(i)) {
101978
- this.#delete(this.#keyList[i], "expire");
101979
- deleted = true;
101980
- }
101981
- }
101982
- return deleted;
101983
- }
101984
- info(key) {
101985
- const i = this.#keyMap.get(key);
101986
- if (i === undefined)
101987
- return;
101988
- const v = this.#valList[i];
101989
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
101990
- if (value === undefined)
101991
- return;
101992
- const entry2 = { value };
101993
- if (this.#ttls && this.#starts) {
101994
- const ttl = this.#ttls[i];
101995
- const start4 = this.#starts[i];
101996
- if (ttl && start4) {
101997
- const remain = ttl - (this.#perf.now() - start4);
101998
- entry2.ttl = remain;
101999
- entry2.start = Date.now();
102000
- }
102001
- }
102002
- if (this.#sizes) {
102003
- entry2.size = this.#sizes[i];
102004
- }
102005
- return entry2;
102006
- }
102007
- dump() {
102008
- const arr = [];
102009
- for (const i of this.#indexes({ allowStale: true })) {
102010
- const key = this.#keyList[i];
102011
- const v = this.#valList[i];
102012
- const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
102013
- if (value === undefined || key === undefined)
102014
- continue;
102015
- const entry2 = { value };
102016
- if (this.#ttls && this.#starts) {
102017
- entry2.ttl = this.#ttls[i];
102018
- const age = this.#perf.now() - this.#starts[i];
102019
- entry2.start = Math.floor(Date.now() - age);
102020
- }
102021
- if (this.#sizes) {
102022
- entry2.size = this.#sizes[i];
102023
- }
102024
- arr.unshift([key, entry2]);
102025
- }
102026
- return arr;
102027
- }
102028
- load(arr) {
102029
- this.clear();
102030
- for (const [key, entry2] of arr) {
102031
- if (entry2.start) {
102032
- const age = Date.now() - entry2.start;
102033
- entry2.start = this.#perf.now() - age;
102034
- }
102035
- this.set(key, entry2.value, entry2);
102036
- }
102037
- }
102038
- set(k, v, setOptions = {}) {
102039
- if (v === undefined) {
102040
- this.delete(k);
102041
- return this;
102042
- }
102043
- const { ttl = this.ttl, start: start4, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
102044
- let { noUpdateTTL = this.noUpdateTTL } = setOptions;
102045
- const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
102046
- if (this.maxEntrySize && size > this.maxEntrySize) {
102047
- if (status) {
102048
- status.set = "miss";
102049
- status.maxEntrySizeExceeded = true;
102050
- }
102051
- this.#delete(k, "set");
102052
- return this;
102053
- }
102054
- let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
102055
- if (index === undefined) {
102056
- index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
102057
- this.#keyList[index] = k;
102058
- this.#valList[index] = v;
102059
- this.#keyMap.set(k, index);
102060
- this.#next[this.#tail] = index;
102061
- this.#prev[index] = this.#tail;
102062
- this.#tail = index;
102063
- this.#size++;
102064
- this.#addItemSize(index, size, status);
102065
- if (status)
102066
- status.set = "add";
102067
- noUpdateTTL = false;
102068
- if (this.#hasOnInsert) {
102069
- this.#onInsert?.(v, k, "add");
102070
- }
102071
- } else {
102072
- this.#moveToTail(index);
102073
- const oldVal = this.#valList[index];
102074
- if (v !== oldVal) {
102075
- if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
102076
- oldVal.__abortController.abort(new Error("replaced"));
102077
- const { __staleWhileFetching: s } = oldVal;
102078
- if (s !== undefined && !noDisposeOnSet) {
102079
- if (this.#hasDispose) {
102080
- this.#dispose?.(s, k, "set");
102081
- }
102082
- if (this.#hasDisposeAfter) {
102083
- this.#disposed?.push([s, k, "set"]);
102084
- }
102085
- }
102086
- } else if (!noDisposeOnSet) {
102087
- if (this.#hasDispose) {
102088
- this.#dispose?.(oldVal, k, "set");
102089
- }
102090
- if (this.#hasDisposeAfter) {
102091
- this.#disposed?.push([oldVal, k, "set"]);
102092
- }
102093
- }
102094
- this.#removeItemSize(index);
102095
- this.#addItemSize(index, size, status);
102096
- this.#valList[index] = v;
102097
- if (status) {
102098
- status.set = "replace";
102099
- const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
102100
- if (oldValue !== undefined)
102101
- status.oldValue = oldValue;
102102
- }
102103
- } else if (status) {
102104
- status.set = "update";
102105
- }
102106
- if (this.#hasOnInsert) {
102107
- this.onInsert?.(v, k, v === oldVal ? "update" : "replace");
102108
- }
102109
- }
102110
- if (ttl !== 0 && !this.#ttls) {
102111
- this.#initializeTTLTracking();
102112
- }
102113
- if (this.#ttls) {
102114
- if (!noUpdateTTL) {
102115
- this.#setItemTTL(index, ttl, start4);
102116
- }
102117
- if (status)
102118
- this.#statusTTL(status, index);
102119
- }
102120
- if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
102121
- const dt = this.#disposed;
102122
- let task;
102123
- while (task = dt?.shift()) {
102124
- this.#disposeAfter?.(...task);
102125
- }
102126
- }
102127
- return this;
102128
- }
102129
- pop() {
102130
- try {
102131
- while (this.#size) {
102132
- const val = this.#valList[this.#head];
102133
- this.#evict(true);
102134
- if (this.#isBackgroundFetch(val)) {
102135
- if (val.__staleWhileFetching) {
102136
- return val.__staleWhileFetching;
102137
- }
102138
- } else if (val !== undefined) {
102139
- return val;
102140
- }
102141
- }
102142
- } finally {
102143
- if (this.#hasDisposeAfter && this.#disposed) {
102144
- const dt = this.#disposed;
102145
- let task;
102146
- while (task = dt?.shift()) {
102147
- this.#disposeAfter?.(...task);
102148
- }
102149
- }
102150
- }
102151
- }
102152
- #evict(free) {
102153
- const head = this.#head;
102154
- const k = this.#keyList[head];
102155
- const v = this.#valList[head];
102156
- if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
102157
- v.__abortController.abort(new Error("evicted"));
102158
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
102159
- if (this.#hasDispose) {
102160
- this.#dispose?.(v, k, "evict");
102161
- }
102162
- if (this.#hasDisposeAfter) {
102163
- this.#disposed?.push([v, k, "evict"]);
102164
- }
102165
- }
102166
- this.#removeItemSize(head);
102167
- if (this.#autopurgeTimers?.[head]) {
102168
- clearTimeout(this.#autopurgeTimers[head]);
102169
- this.#autopurgeTimers[head] = undefined;
102170
- }
102171
- if (free) {
102172
- this.#keyList[head] = undefined;
102173
- this.#valList[head] = undefined;
102174
- this.#free.push(head);
102175
- }
102176
- if (this.#size === 1) {
102177
- this.#head = this.#tail = 0;
102178
- this.#free.length = 0;
102179
- } else {
102180
- this.#head = this.#next[head];
102181
- }
102182
- this.#keyMap.delete(k);
102183
- this.#size--;
102184
- return head;
102185
- }
102186
- has(k, hasOptions = {}) {
102187
- const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
102188
- const index = this.#keyMap.get(k);
102189
- if (index !== undefined) {
102190
- const v = this.#valList[index];
102191
- if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === undefined) {
102192
- return false;
102193
- }
102194
- if (!this.#isStale(index)) {
102195
- if (updateAgeOnHas) {
102196
- this.#updateItemAge(index);
102197
- }
102198
- if (status) {
102199
- status.has = "hit";
102200
- this.#statusTTL(status, index);
102201
- }
102202
- return true;
102203
- } else if (status) {
102204
- status.has = "stale";
102205
- this.#statusTTL(status, index);
102206
- }
102207
- } else if (status) {
102208
- status.has = "miss";
102209
- }
102210
- return false;
102211
- }
102212
- peek(k, peekOptions = {}) {
102213
- const { allowStale = this.allowStale } = peekOptions;
102214
- const index = this.#keyMap.get(k);
102215
- if (index === undefined || !allowStale && this.#isStale(index)) {
102216
- return;
102217
- }
102218
- const v = this.#valList[index];
102219
- return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
102220
- }
102221
- #backgroundFetch(k, index, options, context) {
102222
- const v = index === undefined ? undefined : this.#valList[index];
102223
- if (this.#isBackgroundFetch(v)) {
102224
- return v;
102225
- }
102226
- const ac = new AC;
102227
- const { signal } = options;
102228
- signal?.addEventListener("abort", () => ac.abort(signal.reason), {
102229
- signal: ac.signal
102230
- });
102231
- const fetchOpts = {
102232
- signal: ac.signal,
102233
- options,
102234
- context
102235
- };
102236
- const cb = (v2, updateCache = false) => {
102237
- const { aborted } = ac.signal;
102238
- const ignoreAbort = options.ignoreFetchAbort && v2 !== undefined;
102239
- if (options.status) {
102240
- if (aborted && !updateCache) {
102241
- options.status.fetchAborted = true;
102242
- options.status.fetchError = ac.signal.reason;
102243
- if (ignoreAbort)
102244
- options.status.fetchAbortIgnored = true;
102245
- } else {
102246
- options.status.fetchResolved = true;
102247
- }
102248
- }
102249
- if (aborted && !ignoreAbort && !updateCache) {
102250
- return fetchFail(ac.signal.reason);
102251
- }
102252
- const bf2 = p;
102253
- const vl = this.#valList[index];
102254
- if (vl === p || ignoreAbort && updateCache && vl === undefined) {
102255
- if (v2 === undefined) {
102256
- if (bf2.__staleWhileFetching !== undefined) {
102257
- this.#valList[index] = bf2.__staleWhileFetching;
102258
- } else {
102259
- this.#delete(k, "fetch");
101626
+ const bf2 = p;
101627
+ const vl = this.#valList[index];
101628
+ if (vl === p || ignoreAbort && updateCache && vl === undefined) {
101629
+ if (v2 === undefined) {
101630
+ if (bf2.__staleWhileFetching !== undefined) {
101631
+ this.#valList[index] = bf2.__staleWhileFetching;
101632
+ } else {
101633
+ this.#delete(k, "fetch");
102260
101634
  }
102261
101635
  } else {
102262
101636
  if (options.status)
@@ -102463,671 +101837,1222 @@ class LRUCache {
102463
101837
  }
102464
101838
  return allowStale ? value.__staleWhileFetching : undefined;
102465
101839
  }
102466
- } else {
102467
- if (status)
102468
- status.get = "hit";
102469
- if (fetching) {
102470
- return value.__staleWhileFetching;
101840
+ } else {
101841
+ if (status)
101842
+ status.get = "hit";
101843
+ if (fetching) {
101844
+ return value.__staleWhileFetching;
101845
+ }
101846
+ this.#moveToTail(index);
101847
+ if (updateAgeOnGet) {
101848
+ this.#updateItemAge(index);
101849
+ }
101850
+ return value;
101851
+ }
101852
+ } else if (status) {
101853
+ status.get = "miss";
101854
+ }
101855
+ }
101856
+ #connect(p, n) {
101857
+ this.#prev[n] = p;
101858
+ this.#next[p] = n;
101859
+ }
101860
+ #moveToTail(index) {
101861
+ if (index !== this.#tail) {
101862
+ if (index === this.#head) {
101863
+ this.#head = this.#next[index];
101864
+ } else {
101865
+ this.#connect(this.#prev[index], this.#next[index]);
101866
+ }
101867
+ this.#connect(this.#tail, index);
101868
+ this.#tail = index;
101869
+ }
101870
+ }
101871
+ delete(k) {
101872
+ return this.#delete(k, "delete");
101873
+ }
101874
+ #delete(k, reason) {
101875
+ let deleted = false;
101876
+ if (this.#size !== 0) {
101877
+ const index = this.#keyMap.get(k);
101878
+ if (index !== undefined) {
101879
+ if (this.#autopurgeTimers?.[index]) {
101880
+ clearTimeout(this.#autopurgeTimers?.[index]);
101881
+ this.#autopurgeTimers[index] = undefined;
101882
+ }
101883
+ deleted = true;
101884
+ if (this.#size === 1) {
101885
+ this.#clear(reason);
101886
+ } else {
101887
+ this.#removeItemSize(index);
101888
+ const v = this.#valList[index];
101889
+ if (this.#isBackgroundFetch(v)) {
101890
+ v.__abortController.abort(new Error("deleted"));
101891
+ } else if (this.#hasDispose || this.#hasDisposeAfter) {
101892
+ if (this.#hasDispose) {
101893
+ this.#dispose?.(v, k, reason);
101894
+ }
101895
+ if (this.#hasDisposeAfter) {
101896
+ this.#disposed?.push([v, k, reason]);
101897
+ }
101898
+ }
101899
+ this.#keyMap.delete(k);
101900
+ this.#keyList[index] = undefined;
101901
+ this.#valList[index] = undefined;
101902
+ if (index === this.#tail) {
101903
+ this.#tail = this.#prev[index];
101904
+ } else if (index === this.#head) {
101905
+ this.#head = this.#next[index];
101906
+ } else {
101907
+ const pi = this.#prev[index];
101908
+ this.#next[pi] = this.#next[index];
101909
+ const ni = this.#next[index];
101910
+ this.#prev[ni] = this.#prev[index];
101911
+ }
101912
+ this.#size--;
101913
+ this.#free.push(index);
101914
+ }
101915
+ }
101916
+ }
101917
+ if (this.#hasDisposeAfter && this.#disposed?.length) {
101918
+ const dt = this.#disposed;
101919
+ let task;
101920
+ while (task = dt?.shift()) {
101921
+ this.#disposeAfter?.(...task);
101922
+ }
101923
+ }
101924
+ return deleted;
101925
+ }
101926
+ clear() {
101927
+ return this.#clear("delete");
101928
+ }
101929
+ #clear(reason) {
101930
+ for (const index of this.#rindexes({ allowStale: true })) {
101931
+ const v = this.#valList[index];
101932
+ if (this.#isBackgroundFetch(v)) {
101933
+ v.__abortController.abort(new Error("deleted"));
101934
+ } else {
101935
+ const k = this.#keyList[index];
101936
+ if (this.#hasDispose) {
101937
+ this.#dispose?.(v, k, reason);
101938
+ }
101939
+ if (this.#hasDisposeAfter) {
101940
+ this.#disposed?.push([v, k, reason]);
101941
+ }
101942
+ }
101943
+ }
101944
+ this.#keyMap.clear();
101945
+ this.#valList.fill(undefined);
101946
+ this.#keyList.fill(undefined);
101947
+ if (this.#ttls && this.#starts) {
101948
+ this.#ttls.fill(0);
101949
+ this.#starts.fill(0);
101950
+ for (const t of this.#autopurgeTimers ?? []) {
101951
+ if (t !== undefined)
101952
+ clearTimeout(t);
101953
+ }
101954
+ this.#autopurgeTimers?.fill(undefined);
101955
+ }
101956
+ if (this.#sizes) {
101957
+ this.#sizes.fill(0);
101958
+ }
101959
+ this.#head = 0;
101960
+ this.#tail = 0;
101961
+ this.#free.length = 0;
101962
+ this.#calculatedSize = 0;
101963
+ this.#size = 0;
101964
+ if (this.#hasDisposeAfter && this.#disposed) {
101965
+ const dt = this.#disposed;
101966
+ let task;
101967
+ while (task = dt?.shift()) {
101968
+ this.#disposeAfter?.(...task);
101969
+ }
101970
+ }
101971
+ }
101972
+ }
101973
+
101974
+ // src/module/cache/auth.ts
101975
+ var authCache = new LRUCache({
101976
+ max: 1e4,
101977
+ ttl: 1000 * 60 * 60 * 24 * 7
101978
+ });
101979
+
101980
+ // src/routes/index.ts
101981
+ var getTokenUser = async (token) => {
101982
+ const query3 = assistantConfig2.query;
101983
+ const res = await query3.post({
101984
+ path: "user",
101985
+ key: "me",
101986
+ token
101987
+ });
101988
+ return res;
101989
+ };
101990
+ var getTokenUserCache = async (token) => {
101991
+ const tokenUser = await authCache.get(token);
101992
+ if (tokenUser) {
101993
+ return {
101994
+ code: 200,
101995
+ data: tokenUser
101996
+ };
101997
+ }
101998
+ const res = await getTokenUser(token);
101999
+ if (res.code === 200) {
102000
+ authCache.set(token, res.data);
102001
+ }
102002
+ return res;
102003
+ };
102004
+ var checkAuth = async (ctx, isAdmin = false) => {
102005
+ const config2 = assistantConfig2.getConfig();
102006
+ const { auth = {} } = config2;
102007
+ const token = ctx.query.token;
102008
+ console.log("checkAuth", ctx.query, { token });
102009
+ if (!token) {
102010
+ return {
102011
+ code: 401,
102012
+ message: "未登录"
102013
+ };
102014
+ }
102015
+ let tokenUser = await authCache.get(token);
102016
+ if (!tokenUser) {
102017
+ const tokenUserRes = await getTokenUser(token);
102018
+ if (tokenUserRes.code !== 200) {
102019
+ return {
102020
+ code: tokenUserRes.code,
102021
+ message: "验证失败" + tokenUserRes.message
102022
+ };
102023
+ } else {
102024
+ tokenUser = tokenUserRes.data;
102025
+ }
102026
+ authCache.set(token, tokenUser);
102027
+ }
102028
+ if (ctx.state) {
102029
+ ctx.state = {
102030
+ ...ctx.state,
102031
+ token,
102032
+ tokenUser
102033
+ };
102034
+ }
102035
+ const { username } = tokenUser;
102036
+ if (!auth.username) {
102037
+ auth.username = username;
102038
+ assistantConfig2.setConfig({ auth });
102039
+ }
102040
+ if (isAdmin && auth.username) {
102041
+ const admins = config2.auth?.admin || [];
102042
+ let isCheckAdmin = false;
102043
+ const admin = auth.username;
102044
+ if (admin === username) {
102045
+ isCheckAdmin = true;
102046
+ }
102047
+ if (!isCheckAdmin && admins.length > 0 && admins.includes(username)) {
102048
+ isCheckAdmin = true;
102049
+ }
102050
+ if (!isCheckAdmin) {
102051
+ return {
102052
+ code: 403,
102053
+ message: "非管理员用户"
102054
+ };
102055
+ }
102056
+ }
102057
+ return {
102058
+ code: 200,
102059
+ data: { tokenUser, token }
102060
+ };
102061
+ };
102062
+ app.route({
102063
+ path: "auth",
102064
+ id: "auth",
102065
+ description: "获取当前登录用户信息, 第一个登录的用户为管理员用户"
102066
+ }).define(async (ctx) => {
102067
+ const authResult = await checkAuth(ctx);
102068
+ if (authResult.code !== 200) {
102069
+ ctx.throw(authResult.code, authResult.message);
102070
+ }
102071
+ }).addTo(app);
102072
+ app.route({
102073
+ path: "admin-auth",
102074
+ id: "admin-auth",
102075
+ description: "管理员鉴权, 获取用户信息,并验证是否为管理员。"
102076
+ }).define(async (ctx) => {
102077
+ console.log("query", ctx.query);
102078
+ const authResult = await checkAuth(ctx, true);
102079
+ if (authResult.code !== 200) {
102080
+ ctx.throw(authResult.code, authResult.message);
102081
+ }
102082
+ }).addTo(app);
102083
+ app.route({
102084
+ path: "client",
102085
+ key: "version",
102086
+ description: "获取客户端版本号"
102087
+ }).define(async (ctx) => {
102088
+ ctx.body = "v1.0.0";
102089
+ }).addTo(app);
102090
+ app.route({
102091
+ path: "client",
102092
+ key: "time",
102093
+ description: "获取当前时间"
102094
+ }).define(async (ctx) => {
102095
+ ctx.body = {
102096
+ time: new Date().getTime(),
102097
+ date: new Date().toLocaleDateString()
102098
+ };
102099
+ }).addTo(app);
102100
+ app.route({
102101
+ path: "client",
102102
+ key: "system",
102103
+ description: "获取系统信息"
102104
+ }).define(async (ctx) => {
102105
+ const { platform, arch, release } = os4;
102106
+ ctx.body = {
102107
+ platform: platform(),
102108
+ arch: arch(),
102109
+ release: release()
102110
+ };
102111
+ }).addTo(app);
102112
+
102113
+ // ../node_modules/.pnpm/@kevisual+ws@8.0.0/node_modules/@kevisual/ws/wrapper.mjs
102114
+ var import_stream2 = __toESM(require_stream5(), 1);
102115
+ var import_receiver = __toESM(require_receiver(), 1);
102116
+ var import_sender = __toESM(require_sender(), 1);
102117
+ var import_websocket = __toESM(require_websocket(), 1);
102118
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
102119
+ var wrapper_default = import_websocket.default;
102120
+
102121
+ // src/module/assistant/html/login.ts
102122
+ var renderNoAuthAndLogin = (text) => {
102123
+ return `<!DOCTYPE html>
102124
+ <html lang="en">
102125
+ <head>
102126
+ <meta charset="UTF-8">
102127
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
102128
+ <title>Login Required</title>
102129
+ <style>
102130
+ body {
102131
+ font-family: Arial, sans-serif;
102132
+ background-color: #f4f4f4;
102133
+ display: flex;
102134
+ justify-content: center;
102135
+ align-items: center;
102136
+ height: 100vh;
102137
+ margin: 0;
102138
+ }
102139
+ .container {
102140
+ background: white;
102141
+ padding: 20px;
102142
+ border-radius: 5px;
102143
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
102144
+ text-align: center;
102145
+ }
102146
+ h1 {
102147
+ color: #333;
102148
+ }
102149
+ p {
102150
+ color: #666;
102151
+ }
102152
+ a {
102153
+ display: inline-block;
102154
+ margin-top: 15px;
102155
+ padding: 10px 15px;
102156
+ background-color: #007BFF;
102157
+ color: white;
102158
+ text-decoration: none;
102159
+ border-radius: 5px;
102160
+ }
102161
+ a:hover {
102162
+ background-color: #0056b3;
102163
+ }
102164
+ </style>
102165
+ </head>
102166
+ <body>
102167
+ <div class="container">
102168
+ <p>${text}</p>
102169
+ <a href="/root/home">转到首页</a>
102170
+ </div>
102171
+ </body>
102172
+ </html>`;
102173
+ };
102174
+
102175
+ // src/services/proxy/proxy-page-index.ts
102176
+ var localProxy = new LocalProxy({});
102177
+ localProxy.initFromAssistantConfig(assistantConfig2);
102178
+ var isOpenPath = (pathname) => {
102179
+ const openPaths = ["/root/home", "/root/cli"];
102180
+ for (const openPath of openPaths) {
102181
+ if (pathname.startsWith(openPath)) {
102182
+ return true;
102183
+ }
102184
+ }
102185
+ return false;
102186
+ };
102187
+ var authFilter = async (req, res) => {
102188
+ const _assistantConfig = assistantConfig2.getCacheAssistantConfig();
102189
+ const auth = _assistantConfig?.auth || {};
102190
+ const share = auth.share || "protected";
102191
+ const noAdmin = !auth.username;
102192
+ if (noAdmin)
102193
+ return false;
102194
+ const admin = auth.username;
102195
+ const admins = auth.admin || [];
102196
+ if (admin) {
102197
+ admins.push(admin);
102198
+ }
102199
+ const url3 = new URL(req.url, "http://localhost");
102200
+ const pathname = decodeURIComponent(url3.pathname);
102201
+ if (pathname === "/" || pathname === "/favicon.ico") {
102202
+ return false;
102203
+ }
102204
+ if (pathname.startsWith("/root/home") || pathname === "/root/cli") {
102205
+ return false;
102206
+ }
102207
+ const openApiPaths = ["/api", "/v1", "/client", "/serve"];
102208
+ for (const openPath of openApiPaths) {
102209
+ if (pathname.startsWith(openPath)) {
102210
+ return false;
102211
+ }
102212
+ }
102213
+ if (share === "public") {
102214
+ return false;
102215
+ }
102216
+ const { token } = await getToken(req);
102217
+ if (!token) {
102218
+ res.writeHead(302, { Location: `/root/home/` });
102219
+ res.end();
102220
+ return false;
102221
+ }
102222
+ const tokenUser = await getTokenUserCache(token);
102223
+ if (share === "protected" && tokenUser?.code === 200) {
102224
+ return false;
102225
+ }
102226
+ if (share === "private") {
102227
+ if (tokenUser?.code === 200) {
102228
+ const username = tokenUser?.data?.username;
102229
+ if (admins.includes(username)) {
102230
+ return false;
102231
+ }
102232
+ }
102233
+ }
102234
+ return true;
102235
+ };
102236
+ var proxyRoute = async (req, res) => {
102237
+ const _assistantConfig = assistantConfig2.getCacheAssistantConfig();
102238
+ const home = _assistantConfig?.home || "/root/home";
102239
+ const auth = _assistantConfig?.auth || {};
102240
+ let noAdmin = !auth.username;
102241
+ const toSetting = () => {
102242
+ res.writeHead(302, { Location: `/root/cli/setting/` });
102243
+ res.end();
102244
+ return true;
102245
+ };
102246
+ const url3 = new URL(req.url, "http://localhost");
102247
+ const pathname = decodeURIComponent(url3.pathname);
102248
+ if (pathname === "/") {
102249
+ if (noAdmin) {
102250
+ return toSetting();
102251
+ }
102252
+ res.writeHead(302, { Location: `${home}/` });
102253
+ return res.end();
102254
+ }
102255
+ if (pathname.startsWith("/favicon.ico")) {
102256
+ res.statusCode = 404;
102257
+ res.end("Not Found Favicon");
102258
+ return;
102259
+ }
102260
+ if (pathname.startsWith("/client/upload")) {
102261
+ simpleRouter.parse(req, res);
102262
+ return;
102263
+ }
102264
+ if (pathname.startsWith("/client")) {
102265
+ logger.debug("handle by router", { url: req.url });
102266
+ return;
102267
+ }
102268
+ const apiProxy = _assistantConfig?.api?.proxy || [];
102269
+ const defaultApiProxy = createApiProxy(_assistantConfig?.app?.url || "https://kevisual.cn");
102270
+ const allProxy = [...apiProxy, ...defaultApiProxy];
102271
+ const apiBackendProxy = allProxy.find((item) => pathname.startsWith(item.path));
102272
+ if (apiBackendProxy) {
102273
+ log.debug("apiBackendProxy", { apiBackendProxy, url: req.url });
102274
+ return proxy(req, res, {
102275
+ path: apiBackendProxy.path,
102276
+ target: apiBackendProxy.target,
102277
+ ...apiBackendProxy
102278
+ });
102279
+ }
102280
+ logger.debug("proxyRoute handle by router", { url: req.url }, noAdmin);
102281
+ const urls = pathname.split("/");
102282
+ const [_2, _user, _app] = urls;
102283
+ if (!_app) {
102284
+ res.statusCode = 404;
102285
+ res.end("Not Found Proxy");
102286
+ return;
102287
+ }
102288
+ const isOpen = isOpenPath(pathname);
102289
+ log.debug("proxyRoute", { _user, _app, pathname, noAdmin, isOpen });
102290
+ if (noAdmin && !isOpen) {
102291
+ return toSetting();
102292
+ }
102293
+ if (_app && urls.length === 3) {
102294
+ res.writeHead(302, { Location: `${req.url}/` });
102295
+ return res.end();
102296
+ }
102297
+ const proxyApiList = _assistantConfig?.proxy || [];
102298
+ const proxyApi = proxyApiList.find((item) => pathname.startsWith(item.path));
102299
+ if (proxyApi && proxyApi.type === "file") {
102300
+ log.debug("proxyApi", { proxyApi, pathname });
102301
+ const _indexPath = proxyApi.indexPath || `${_user}/${_app}/index.html`;
102302
+ const _rootPath = proxyApi.rootPath;
102303
+ if (!_rootPath) {
102304
+ log.error("Not Found rootPath", { proxyApi, pathname });
102305
+ return res.end(`Not Found [${proxyApi.path}] rootPath`);
102306
+ }
102307
+ return fileProxy(req, res, {
102308
+ path: proxyApi.path,
102309
+ rootPath: proxyApi.rootPath,
102310
+ ...proxyApi,
102311
+ indexPath: _indexPath
102312
+ });
102313
+ } else if (proxyApi && proxyApi.type === "http") {
102314
+ log.debug("proxyApi http", { proxyApi, pathname });
102315
+ return httpProxy(req, res, {
102316
+ path: proxyApi.path,
102317
+ target: proxyApi.target,
102318
+ type: "http"
102319
+ });
102320
+ }
102321
+ const filter2 = await authFilter(req, res);
102322
+ if (filter2) {
102323
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
102324
+ return res.end(renderNoAuthAndLogin("Not Authorized Proxy"));
102325
+ }
102326
+ const localProxyProxyList = localProxy.getLocalProxyList();
102327
+ const localProxyProxy = localProxyProxyList.find((item) => pathname.startsWith(item.path));
102328
+ if (localProxyProxy) {
102329
+ log.log("localProxyProxy", { localProxyProxy, url: req.url });
102330
+ return fileProxy(req, res, {
102331
+ path: localProxyProxy.path,
102332
+ rootPath: localProxy.pagesDir,
102333
+ indexPath: localProxyProxy.indexPath
102334
+ });
102335
+ }
102336
+ const creatCenterProxy = createApiProxy(_assistantConfig?.app?.url || "https://kevisual.cn", ["/root", "/" + _user]);
102337
+ const centerProxy = creatCenterProxy.find((item) => pathname.startsWith(item.path));
102338
+ if (centerProxy) {
102339
+ return httpProxy(req, res, {
102340
+ path: centerProxy.path,
102341
+ target: centerProxy.target,
102342
+ type: "http"
102343
+ });
102344
+ }
102345
+ log.debug("handle by router 404", req.url);
102346
+ res.statusCode = 404;
102347
+ res.end("Not Found Proxy");
102348
+ };
102349
+ var proxyWs = () => {
102350
+ const apiProxy = assistantConfig2.getCacheAssistantConfig()?.api?.proxy || [];
102351
+ const registry2 = assistantConfig2.getRegistry();
102352
+ const proxy4 = assistantConfig2.getCacheAssistantConfig()?.proxy || [];
102353
+ const proxyApi = [...apiProxy, ...proxy4].filter((item) => item.ws);
102354
+ const demoProxy = [
102355
+ {
102356
+ path: "/api/ws/demo",
102357
+ target: "https://kevisual.xiongxiao.me",
102358
+ pathname: "/api/router",
102359
+ ws: true
102360
+ }
102361
+ ];
102362
+ const pathRouter = proxyApi.find((item) => item.path === "/api/router");
102363
+ if (!pathRouter) {
102364
+ proxyApi.push({
102365
+ path: "/api/router",
102366
+ target: registry2 || "https://kevisual.cn",
102367
+ pathname: "/api/router",
102368
+ ws: true
102369
+ });
102370
+ }
102371
+ return proxyApi.map(createProxyInfo);
102372
+ };
102373
+ var createProxyInfo = (proxyApiItem) => {
102374
+ const func = async (req, res) => {
102375
+ const { ws, emitter, id, data } = req;
102376
+ if (!id) {
102377
+ ws.send(JSON.stringify({ type: "error", message: "not found id" }));
102378
+ ws.close();
102379
+ return;
102380
+ }
102381
+ let _proxySocket = ws.data.proxySocket;
102382
+ if (!_proxySocket) {
102383
+ const _u = new URL(proxyApiItem.path, `${proxyApiItem.target}`);
102384
+ if (proxyApiItem.pathname) {
102385
+ _u.pathname = proxyApiItem.pathname;
102386
+ }
102387
+ const isHttps = _u.protocol === "https:";
102388
+ const wsProtocol = isHttps ? "wss" : "ws";
102389
+ const wsUrl = `${wsProtocol}://${_u.host}${_u.pathname}`;
102390
+ console.log("WebSocket proxy URL", { wsUrl });
102391
+ const proxySocket = new wrapper_default(wsUrl);
102392
+ proxySocket.on("open", () => {
102393
+ proxySocket.on("message", (message) => {
102394
+ ws.send(message);
102395
+ });
102396
+ });
102397
+ proxySocket.on("error", (err) => {
102398
+ console.error(`WebSocket proxy error: ${err.message}`);
102399
+ });
102400
+ proxySocket.on("close", () => {
102401
+ console.log("WebSocket proxy closed");
102402
+ });
102403
+ emitter.once("close--" + id, () => {
102404
+ console.log("WebSocket client closed");
102405
+ proxySocket?.close?.();
102406
+ });
102407
+ ws.data.proxySocket = proxySocket;
102408
+ return;
102409
+ }
102410
+ console.log("ws.data", data);
102411
+ _proxySocket.send(JSON.stringify(data));
102412
+ };
102413
+ return {
102414
+ path: proxyApiItem.path,
102415
+ io: true,
102416
+ func
102417
+ };
102418
+ };
102419
+
102420
+ // src/routes-simple/upload.ts
102421
+ var import_busboy = __toESM(require_lib4(), 1);
102422
+ import path14 from "path";
102423
+ import fs14 from "fs";
102424
+
102425
+ // ../node_modules/.pnpm/@kevisual+router@0.0.55/node_modules/@kevisual/router/src/server/cookie.ts
102426
+ var NullObject2 = /* @__PURE__ */ (() => {
102427
+ const C = function() {};
102428
+ C.prototype = Object.create(null);
102429
+ return C;
102430
+ })();
102431
+ function parseCookie2(str, options) {
102432
+ const obj = new NullObject2;
102433
+ const len = str.length;
102434
+ if (len < 2)
102435
+ return obj;
102436
+ const dec = options?.decode || decode2;
102437
+ let index = 0;
102438
+ do {
102439
+ const eqIdx = eqIndex2(str, index, len);
102440
+ if (eqIdx === -1)
102441
+ break;
102442
+ const endIdx = endIndex2(str, index, len);
102443
+ if (eqIdx > endIdx) {
102444
+ index = str.lastIndexOf(";", eqIdx - 1) + 1;
102445
+ continue;
102446
+ }
102447
+ const key = valueSlice2(str, index, eqIdx);
102448
+ if (obj[key] === undefined) {
102449
+ obj[key] = dec(valueSlice2(str, eqIdx + 1, endIdx));
102450
+ }
102451
+ index = endIdx + 1;
102452
+ } while (index < len);
102453
+ return obj;
102454
+ }
102455
+ function endIndex2(str, min, len) {
102456
+ const index = str.indexOf(";", min);
102457
+ return index === -1 ? len : index;
102458
+ }
102459
+ function eqIndex2(str, min, max) {
102460
+ const index = str.indexOf("=", min);
102461
+ return index < max ? index : -1;
102462
+ }
102463
+ function valueSlice2(str, min, max) {
102464
+ let start4 = min;
102465
+ let end = max;
102466
+ do {
102467
+ const code = str.charCodeAt(start4);
102468
+ if (code !== 32 && code !== 9)
102469
+ break;
102470
+ } while (++start4 < end);
102471
+ while (end > start4) {
102472
+ const code = str.charCodeAt(end - 1);
102473
+ if (code !== 32 && code !== 9)
102474
+ break;
102475
+ end--;
102476
+ }
102477
+ return str.slice(start4, end);
102478
+ }
102479
+ function decode2(str) {
102480
+ if (str.indexOf("%") === -1)
102481
+ return str;
102482
+ try {
102483
+ return decodeURIComponent(str);
102484
+ } catch (e) {
102485
+ return str;
102486
+ }
102487
+ }
102488
+
102489
+ // src/module/get-header-token.ts
102490
+ var getTokenFromRequest = (req) => {
102491
+ let token = req.headers?.["authorization"] || req.headers?.["Authorization"] || "";
102492
+ const url3 = new URL(req.url || "", "http://localhost");
102493
+ if (!token) {
102494
+ token = url3.searchParams.get("token") || "";
102495
+ }
102496
+ if (!token) {
102497
+ const parsedCookies = parseCookie2(req.headers.cookie || "");
102498
+ token = parsedCookies.token || "";
102499
+ }
102500
+ if (token) {
102501
+ token = token.replace("Bearer ", "");
102502
+ }
102503
+ return token;
102504
+ };
102505
+
102506
+ // ../node_modules/.pnpm/@kevisual+context@0.0.4/node_modules/@kevisual/context/dist/app.js
102507
+ var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
102508
+ function getDefaultExportFromCjs4(x) {
102509
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
102510
+ }
102511
+ var eventemitter33 = { exports: {} };
102512
+ var hasRequiredEventemitter33;
102513
+ function requireEventemitter33() {
102514
+ if (hasRequiredEventemitter33)
102515
+ return eventemitter33.exports;
102516
+ hasRequiredEventemitter33 = 1;
102517
+ (function(module) {
102518
+ var has = Object.prototype.hasOwnProperty, prefix = "~";
102519
+ function Events() {}
102520
+ if (Object.create) {
102521
+ Events.prototype = Object.create(null);
102522
+ if (!new Events().__proto__)
102523
+ prefix = false;
102524
+ }
102525
+ function EE(fn, context, once) {
102526
+ this.fn = fn;
102527
+ this.context = context;
102528
+ this.once = once || false;
102529
+ }
102530
+ function addListener(emitter, event, fn, context, once) {
102531
+ if (typeof fn !== "function") {
102532
+ throw new TypeError("The listener must be a function");
102533
+ }
102534
+ var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
102535
+ if (!emitter._events[evt])
102536
+ emitter._events[evt] = listener, emitter._eventsCount++;
102537
+ else if (!emitter._events[evt].fn)
102538
+ emitter._events[evt].push(listener);
102539
+ else
102540
+ emitter._events[evt] = [emitter._events[evt], listener];
102541
+ return emitter;
102542
+ }
102543
+ function clearEvent(emitter, evt) {
102544
+ if (--emitter._eventsCount === 0)
102545
+ emitter._events = new Events;
102546
+ else
102547
+ delete emitter._events[evt];
102548
+ }
102549
+ function EventEmitter4() {
102550
+ this._events = new Events;
102551
+ this._eventsCount = 0;
102552
+ }
102553
+ EventEmitter4.prototype.eventNames = function eventNames() {
102554
+ var names = [], events, name;
102555
+ if (this._eventsCount === 0)
102556
+ return names;
102557
+ for (name in events = this._events) {
102558
+ if (has.call(events, name))
102559
+ names.push(prefix ? name.slice(1) : name);
102560
+ }
102561
+ if (Object.getOwnPropertySymbols) {
102562
+ return names.concat(Object.getOwnPropertySymbols(events));
102563
+ }
102564
+ return names;
102565
+ };
102566
+ EventEmitter4.prototype.listeners = function listeners(event) {
102567
+ var evt = prefix ? prefix + event : event, handlers = this._events[evt];
102568
+ if (!handlers)
102569
+ return [];
102570
+ if (handlers.fn)
102571
+ return [handlers.fn];
102572
+ for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) {
102573
+ ee[i] = handlers[i].fn;
102574
+ }
102575
+ return ee;
102576
+ };
102577
+ EventEmitter4.prototype.listenerCount = function listenerCount(event) {
102578
+ var evt = prefix ? prefix + event : event, listeners = this._events[evt];
102579
+ if (!listeners)
102580
+ return 0;
102581
+ if (listeners.fn)
102582
+ return 1;
102583
+ return listeners.length;
102584
+ };
102585
+ EventEmitter4.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
102586
+ var evt = prefix ? prefix + event : event;
102587
+ if (!this._events[evt])
102588
+ return false;
102589
+ var listeners = this._events[evt], len = arguments.length, args, i;
102590
+ if (listeners.fn) {
102591
+ if (listeners.once)
102592
+ this.removeListener(event, listeners.fn, undefined, true);
102593
+ switch (len) {
102594
+ case 1:
102595
+ return listeners.fn.call(listeners.context), true;
102596
+ case 2:
102597
+ return listeners.fn.call(listeners.context, a1), true;
102598
+ case 3:
102599
+ return listeners.fn.call(listeners.context, a1, a2), true;
102600
+ case 4:
102601
+ return listeners.fn.call(listeners.context, a1, a2, a3), true;
102602
+ case 5:
102603
+ return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
102604
+ case 6:
102605
+ return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
102606
+ }
102607
+ for (i = 1, args = new Array(len - 1);i < len; i++) {
102608
+ args[i - 1] = arguments[i];
102471
102609
  }
102472
- this.#moveToTail(index);
102473
- if (updateAgeOnGet) {
102474
- this.#updateItemAge(index);
102610
+ listeners.fn.apply(listeners.context, args);
102611
+ } else {
102612
+ var length = listeners.length, j;
102613
+ for (i = 0;i < length; i++) {
102614
+ if (listeners[i].once)
102615
+ this.removeListener(event, listeners[i].fn, undefined, true);
102616
+ switch (len) {
102617
+ case 1:
102618
+ listeners[i].fn.call(listeners[i].context);
102619
+ break;
102620
+ case 2:
102621
+ listeners[i].fn.call(listeners[i].context, a1);
102622
+ break;
102623
+ case 3:
102624
+ listeners[i].fn.call(listeners[i].context, a1, a2);
102625
+ break;
102626
+ case 4:
102627
+ listeners[i].fn.call(listeners[i].context, a1, a2, a3);
102628
+ break;
102629
+ default:
102630
+ if (!args)
102631
+ for (j = 1, args = new Array(len - 1);j < len; j++) {
102632
+ args[j - 1] = arguments[j];
102633
+ }
102634
+ listeners[i].fn.apply(listeners[i].context, args);
102635
+ }
102475
102636
  }
102476
- return value;
102477
102637
  }
102478
- } else if (status) {
102479
- status.get = "miss";
102480
- }
102481
- }
102482
- #connect(p, n) {
102483
- this.#prev[n] = p;
102484
- this.#next[p] = n;
102485
- }
102486
- #moveToTail(index) {
102487
- if (index !== this.#tail) {
102488
- if (index === this.#head) {
102489
- this.#head = this.#next[index];
102490
- } else {
102491
- this.#connect(this.#prev[index], this.#next[index]);
102638
+ return true;
102639
+ };
102640
+ EventEmitter4.prototype.on = function on(event, fn, context) {
102641
+ return addListener(this, event, fn, context, false);
102642
+ };
102643
+ EventEmitter4.prototype.once = function once(event, fn, context) {
102644
+ return addListener(this, event, fn, context, true);
102645
+ };
102646
+ EventEmitter4.prototype.removeListener = function removeListener(event, fn, context, once) {
102647
+ var evt = prefix ? prefix + event : event;
102648
+ if (!this._events[evt])
102649
+ return this;
102650
+ if (!fn) {
102651
+ clearEvent(this, evt);
102652
+ return this;
102492
102653
  }
102493
- this.#connect(this.#tail, index);
102494
- this.#tail = index;
102495
- }
102496
- }
102497
- delete(k) {
102498
- return this.#delete(k, "delete");
102499
- }
102500
- #delete(k, reason) {
102501
- let deleted = false;
102502
- if (this.#size !== 0) {
102503
- const index = this.#keyMap.get(k);
102504
- if (index !== undefined) {
102505
- if (this.#autopurgeTimers?.[index]) {
102506
- clearTimeout(this.#autopurgeTimers?.[index]);
102507
- this.#autopurgeTimers[index] = undefined;
102654
+ var listeners = this._events[evt];
102655
+ if (listeners.fn) {
102656
+ if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
102657
+ clearEvent(this, evt);
102508
102658
  }
102509
- deleted = true;
102510
- if (this.#size === 1) {
102511
- this.#clear(reason);
102512
- } else {
102513
- this.#removeItemSize(index);
102514
- const v = this.#valList[index];
102515
- if (this.#isBackgroundFetch(v)) {
102516
- v.__abortController.abort(new Error("deleted"));
102517
- } else if (this.#hasDispose || this.#hasDisposeAfter) {
102518
- if (this.#hasDispose) {
102519
- this.#dispose?.(v, k, reason);
102520
- }
102521
- if (this.#hasDisposeAfter) {
102522
- this.#disposed?.push([v, k, reason]);
102523
- }
102524
- }
102525
- this.#keyMap.delete(k);
102526
- this.#keyList[index] = undefined;
102527
- this.#valList[index] = undefined;
102528
- if (index === this.#tail) {
102529
- this.#tail = this.#prev[index];
102530
- } else if (index === this.#head) {
102531
- this.#head = this.#next[index];
102532
- } else {
102533
- const pi = this.#prev[index];
102534
- this.#next[pi] = this.#next[index];
102535
- const ni = this.#next[index];
102536
- this.#prev[ni] = this.#prev[index];
102659
+ } else {
102660
+ for (var i = 0, events = [], length = listeners.length;i < length; i++) {
102661
+ if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
102662
+ events.push(listeners[i]);
102537
102663
  }
102538
- this.#size--;
102539
- this.#free.push(index);
102540
102664
  }
102665
+ if (events.length)
102666
+ this._events[evt] = events.length === 1 ? events[0] : events;
102667
+ else
102668
+ clearEvent(this, evt);
102541
102669
  }
102542
- }
102543
- if (this.#hasDisposeAfter && this.#disposed?.length) {
102544
- const dt = this.#disposed;
102545
- let task;
102546
- while (task = dt?.shift()) {
102547
- this.#disposeAfter?.(...task);
102548
- }
102549
- }
102550
- return deleted;
102551
- }
102552
- clear() {
102553
- return this.#clear("delete");
102554
- }
102555
- #clear(reason) {
102556
- for (const index of this.#rindexes({ allowStale: true })) {
102557
- const v = this.#valList[index];
102558
- if (this.#isBackgroundFetch(v)) {
102559
- v.__abortController.abort(new Error("deleted"));
102670
+ return this;
102671
+ };
102672
+ EventEmitter4.prototype.removeAllListeners = function removeAllListeners(event) {
102673
+ var evt;
102674
+ if (event) {
102675
+ evt = prefix ? prefix + event : event;
102676
+ if (this._events[evt])
102677
+ clearEvent(this, evt);
102560
102678
  } else {
102561
- const k = this.#keyList[index];
102562
- if (this.#hasDispose) {
102563
- this.#dispose?.(v, k, reason);
102564
- }
102565
- if (this.#hasDisposeAfter) {
102566
- this.#disposed?.push([v, k, reason]);
102567
- }
102679
+ this._events = new Events;
102680
+ this._eventsCount = 0;
102568
102681
  }
102682
+ return this;
102683
+ };
102684
+ EventEmitter4.prototype.off = EventEmitter4.prototype.removeListener;
102685
+ EventEmitter4.prototype.addListener = EventEmitter4.prototype.on;
102686
+ EventEmitter4.prefixed = prefix;
102687
+ EventEmitter4.EventEmitter = EventEmitter4;
102688
+ {
102689
+ module.exports = EventEmitter4;
102569
102690
  }
102570
- this.#keyMap.clear();
102571
- this.#valList.fill(undefined);
102572
- this.#keyList.fill(undefined);
102573
- if (this.#ttls && this.#starts) {
102574
- this.#ttls.fill(0);
102575
- this.#starts.fill(0);
102576
- for (const t of this.#autopurgeTimers ?? []) {
102577
- if (t !== undefined)
102578
- clearTimeout(t);
102691
+ })(eventemitter33);
102692
+ return eventemitter33.exports;
102693
+ }
102694
+ var eventemitter3Exports3 = requireEventemitter33();
102695
+ var EventEmitter4 = /* @__PURE__ */ getDefaultExportFromCjs4(eventemitter3Exports3);
102696
+ var reRunFn2 = (promiseOpts) => {
102697
+ const timeout = promiseOpts.timeout || 5 * 60 * 1000;
102698
+ const interval = promiseOpts.interval || 1000;
102699
+ const checkSuccess = promiseOpts?.checkSuccess || (() => true);
102700
+ const signal = promiseOpts.signal;
102701
+ return new Promise(async (resolve, reject) => {
102702
+ let intervalId;
102703
+ let timeoutId = setTimeout(() => {
102704
+ clearTimeout(intervalId);
102705
+ resolve({
102706
+ code: 500,
102707
+ message: "timeout"
102708
+ });
102709
+ }, timeout);
102710
+ const fn = promiseOpts.fn || (() => true);
102711
+ const runFn = async () => {
102712
+ if (signal?.aborted) {
102713
+ clearInterval(intervalId);
102714
+ clearTimeout(timeoutId);
102715
+ return resolve({
102716
+ code: 499,
102717
+ message: "operation cancelled"
102718
+ });
102579
102719
  }
102580
- this.#autopurgeTimers?.fill(undefined);
102581
- }
102582
- if (this.#sizes) {
102583
- this.#sizes.fill(0);
102584
- }
102585
- this.#head = 0;
102586
- this.#tail = 0;
102587
- this.#free.length = 0;
102588
- this.#calculatedSize = 0;
102589
- this.#size = 0;
102590
- if (this.#hasDisposeAfter && this.#disposed) {
102591
- const dt = this.#disposed;
102592
- let task;
102593
- while (task = dt?.shift()) {
102594
- this.#disposeAfter?.(...task);
102720
+ const res = await fn();
102721
+ if (!!checkSuccess(res)) {
102722
+ clearInterval(intervalId);
102723
+ clearTimeout(timeoutId);
102724
+ resolve({
102725
+ code: 200,
102726
+ data: res
102727
+ });
102728
+ } else {
102729
+ setTimeout(() => {
102730
+ runFn();
102731
+ }, interval);
102595
102732
  }
102733
+ };
102734
+ if (signal) {
102735
+ signal.addEventListener("abort", () => {
102736
+ clearInterval(intervalId);
102737
+ clearTimeout(timeoutId);
102738
+ resolve({
102739
+ code: 499,
102740
+ message: "operation cancelled"
102741
+ });
102742
+ });
102596
102743
  }
102597
- }
102598
- }
102599
-
102600
- // src/module/cache/auth.ts
102601
- var authCache = new LRUCache({
102602
- max: 1e4,
102603
- ttl: 1000 * 60 * 60 * 24 * 7
102604
- });
102605
-
102606
- // src/routes/index.ts
102607
- var getTokenUser = async (token) => {
102608
- const query3 = assistantConfig2.query;
102609
- const res = await query3.post({
102610
- path: "user",
102611
- key: "me",
102612
- token
102744
+ runFn();
102613
102745
  });
102614
- return res;
102615
102746
  };
102616
- var getTokenUserCache = async (token) => {
102617
- const tokenUser = await authCache.get(token);
102618
- if (tokenUser) {
102619
- return {
102620
- code: 200,
102621
- data: tokenUser
102622
- };
102623
- }
102624
- const res = await getTokenUser(token);
102625
- if (res.code === 200) {
102626
- authCache.set(token, res.data);
102747
+
102748
+ class BaseLoad2 {
102749
+ modules = new Map;
102750
+ event;
102751
+ loading;
102752
+ static reRunFn = reRunFn2;
102753
+ timeout = 5 * 60 * 1000;
102754
+ constructor() {
102755
+ this.event = new EventEmitter4;
102756
+ this.loading = false;
102627
102757
  }
102628
- return res;
102629
- };
102630
- var checkAuth = async (ctx, isAdmin = false) => {
102631
- const config2 = assistantConfig2.getConfig();
102632
- const { auth = {} } = config2;
102633
- const token = ctx.query.token;
102634
- console.log("checkAuth", ctx.query, { token });
102635
- if (!token) {
102636
- return {
102637
- code: 401,
102638
- message: "未登录"
102639
- };
102758
+ listenKey(key, listenOpts) {
102759
+ const timeout = listenOpts?.timeout ?? this.timeout;
102760
+ return new Promise((resolve) => {
102761
+ const timeoutId = setTimeout(() => {
102762
+ this.event.removeListener(key, onEvent);
102763
+ resolve({
102764
+ code: 500,
102765
+ message: "timeout"
102766
+ });
102767
+ }, timeout);
102768
+ const onEvent = (error2) => {
102769
+ clearTimeout(timeoutId);
102770
+ if (error2) {
102771
+ return resolve({
102772
+ code: 500,
102773
+ message: error2
102774
+ });
102775
+ }
102776
+ const data = this.modules.get(key);
102777
+ if (data?.loadSuccessClear) {
102778
+ this.remove(key);
102779
+ }
102780
+ resolve({
102781
+ code: 200,
102782
+ data: data?.modules
102783
+ });
102784
+ };
102785
+ this.event.once(key, onEvent);
102786
+ });
102640
102787
  }
102641
- let tokenUser = await authCache.get(token);
102642
- if (!tokenUser) {
102643
- const tokenUserRes = await getTokenUser(token);
102644
- if (tokenUserRes.code !== 200) {
102788
+ async hasLoaded(key, hasLoadOpts) {
102789
+ if (!key) {
102645
102790
  return {
102646
- code: tokenUserRes.code,
102647
- message: "验证失败" + tokenUserRes.message
102791
+ code: 404,
102792
+ message: "key is required"
102648
102793
  };
102649
- } else {
102650
- tokenUser = tokenUserRes.data;
102651
- }
102652
- authCache.set(token, tokenUser);
102653
- }
102654
- if (ctx.state) {
102655
- ctx.state = {
102656
- ...ctx.state,
102657
- token,
102658
- tokenUser
102659
- };
102660
- }
102661
- const { username } = tokenUser;
102662
- if (!auth.username) {
102663
- auth.username = username;
102664
- assistantConfig2.setConfig({ auth });
102665
- }
102666
- if (isAdmin && auth.username) {
102667
- const admins = config2.auth?.admin || [];
102668
- let isCheckAdmin = false;
102669
- const admin = auth.username;
102670
- if (admin === username) {
102671
- isCheckAdmin = true;
102672
- }
102673
- if (!isCheckAdmin && admins.length > 0 && admins.includes(username)) {
102674
- isCheckAdmin = true;
102675
102794
  }
102676
- if (!isCheckAdmin) {
102795
+ const has = this.modules.has(key);
102796
+ if (!has) {
102797
+ const isExist = hasLoadOpts?.isExist ?? true;
102798
+ const timeout = hasLoadOpts?.timeout ?? this.timeout;
102799
+ if (isExist) {
102800
+ return await this.listenKey(key, { timeout });
102801
+ }
102677
102802
  return {
102678
- code: 403,
102679
- message: "非管理员用户"
102803
+ code: 404
102680
102804
  };
102681
102805
  }
102682
- }
102683
- return {
102684
- code: 200,
102685
- data: { tokenUser, token }
102686
- };
102687
- };
102688
- app.route({
102689
- path: "auth",
102690
- id: "auth",
102691
- description: "获取当前登录用户信息, 第一个登录的用户为管理员用户"
102692
- }).define(async (ctx) => {
102693
- const authResult = await checkAuth(ctx);
102694
- if (authResult.code !== 200) {
102695
- ctx.throw(authResult.code, authResult.message);
102696
- }
102697
- }).addTo(app);
102698
- app.route({
102699
- path: "admin-auth",
102700
- id: "admin-auth",
102701
- description: "管理员鉴权, 获取用户信息,并验证是否为管理员。"
102702
- }).define(async (ctx) => {
102703
- console.log("query", ctx.query);
102704
- const authResult = await checkAuth(ctx, true);
102705
- if (authResult.code !== 200) {
102706
- ctx.throw(authResult.code, authResult.message);
102707
- }
102708
- }).addTo(app);
102709
- app.route({
102710
- path: "client",
102711
- key: "version",
102712
- description: "获取客户端版本号"
102713
- }).define(async (ctx) => {
102714
- ctx.body = "v1.0.0";
102715
- }).addTo(app);
102716
- app.route({
102717
- path: "client",
102718
- key: "time",
102719
- description: "获取当前时间"
102720
- }).define(async (ctx) => {
102721
- ctx.body = {
102722
- time: new Date().getTime(),
102723
- date: new Date().toLocaleDateString()
102724
- };
102725
- }).addTo(app);
102726
- app.route({
102727
- path: "client",
102728
- key: "system",
102729
- description: "获取系统信息"
102730
- }).define(async (ctx) => {
102731
- const { platform, arch, release } = os4;
102732
- ctx.body = {
102733
- platform: platform(),
102734
- arch: arch(),
102735
- release: release()
102736
- };
102737
- }).addTo(app);
102738
-
102739
- // ../node_modules/.pnpm/@kevisual+ws@8.0.0/node_modules/@kevisual/ws/wrapper.mjs
102740
- var import_stream2 = __toESM(require_stream5(), 1);
102741
- var import_receiver = __toESM(require_receiver(), 1);
102742
- var import_sender = __toESM(require_sender(), 1);
102743
- var import_websocket = __toESM(require_websocket(), 1);
102744
- var import_websocket_server = __toESM(require_websocket_server(), 1);
102745
- var wrapper_default = import_websocket.default;
102746
-
102747
- // src/module/assistant/html/login.ts
102748
- var renderNoAuthAndLogin = (text) => {
102749
- return `<!DOCTYPE html>
102750
- <html lang="en">
102751
- <head>
102752
- <meta charset="UTF-8">
102753
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
102754
- <title>Login Required</title>
102755
- <style>
102756
- body {
102757
- font-family: Arial, sans-serif;
102758
- background-color: #f4f4f4;
102759
- display: flex;
102760
- justify-content: center;
102761
- align-items: center;
102762
- height: 100vh;
102763
- margin: 0;
102764
- }
102765
- .container {
102766
- background: white;
102767
- padding: 20px;
102768
- border-radius: 5px;
102769
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
102770
- text-align: center;
102771
- }
102772
- h1 {
102773
- color: #333;
102774
- }
102775
- p {
102776
- color: #666;
102777
- }
102778
- a {
102779
- display: inline-block;
102780
- margin-top: 15px;
102781
- padding: 10px 15px;
102782
- background-color: #007BFF;
102783
- color: white;
102784
- text-decoration: none;
102785
- border-radius: 5px;
102786
- }
102787
- a:hover {
102788
- background-color: #0056b3;
102789
- }
102790
- </style>
102791
- </head>
102792
- <body>
102793
- <div class="container">
102794
- <p>${text}</p>
102795
- <a href="/root/home">转到首页</a>
102796
- </div>
102797
- </body>
102798
- </html>`;
102799
- };
102800
-
102801
- // src/services/proxy/proxy-page-index.ts
102802
- var localProxy = new LocalProxy({});
102803
- localProxy.initFromAssistantConfig(assistantConfig2);
102804
- var isOpenPath = (pathname) => {
102805
- const openPaths = ["/root/home", "/root/cli"];
102806
- for (const openPath of openPaths) {
102807
- if (pathname.startsWith(openPath)) {
102808
- return true;
102806
+ const data = this.modules.get(key);
102807
+ if (data?.status === "loaded") {
102808
+ return {
102809
+ code: 200,
102810
+ data: data.modules
102811
+ };
102809
102812
  }
102810
- }
102811
- return false;
102812
- };
102813
- var authFilter = async (req, res) => {
102814
- const _assistantConfig = assistantConfig2.getCacheAssistantConfig();
102815
- const auth = _assistantConfig?.auth || {};
102816
- const share = auth.share || "protected";
102817
- const noAdmin = !auth.username;
102818
- if (noAdmin)
102819
- return false;
102820
- const admin = auth.username;
102821
- const admins = auth.admin || [];
102822
- if (admin) {
102823
- admins.push(admin);
102824
- }
102825
- const url3 = new URL(req.url, "http://localhost");
102826
- const pathname = decodeURIComponent(url3.pathname);
102827
- if (pathname === "/" || pathname === "/favicon.ico") {
102828
- return false;
102829
- }
102830
- if (pathname.startsWith("/root/home") || pathname === "/root/cli") {
102831
- return false;
102832
- }
102833
- const openApiPaths = ["/api", "/v1", "/client", "/serve"];
102834
- for (const openPath of openApiPaths) {
102835
- if (pathname.startsWith(openPath)) {
102836
- return false;
102813
+ if (data?.status === "loading") {
102814
+ return await this.listenKey(key, { timeout: hasLoadOpts?.timeout ?? this.timeout });
102837
102815
  }
102816
+ if (data?.status === "error") {
102817
+ return {
102818
+ code: 500,
102819
+ message: "load error"
102820
+ };
102821
+ }
102822
+ if (data?.status === "cancel") {
102823
+ return {
102824
+ code: 499,
102825
+ message: "operation cancelled"
102826
+ };
102827
+ }
102828
+ return {
102829
+ code: 404
102830
+ };
102838
102831
  }
102839
- if (share === "public") {
102840
- return false;
102841
- }
102842
- const { token } = await getToken(req);
102843
- if (!token) {
102844
- res.writeHead(302, { Location: `/root/home/` });
102845
- res.end();
102846
- return false;
102847
- }
102848
- const tokenUser = await getTokenUserCache(token);
102849
- if (share === "protected" && tokenUser?.code === 200) {
102850
- return false;
102851
- }
102852
- if (share === "private") {
102853
- if (tokenUser?.code === 200) {
102854
- const username = tokenUser?.data?.username;
102855
- if (admins.includes(username)) {
102856
- return false;
102832
+ async loadFn(loadContent, opts) {
102833
+ const key = opts.key;
102834
+ if (!key) {
102835
+ return {
102836
+ code: 404,
102837
+ message: "key is required"
102838
+ };
102839
+ }
102840
+ const newModule = {
102841
+ key: opts.key,
102842
+ status: "loading",
102843
+ loading: true,
102844
+ loadSuccessClear: opts.loadSuccessClear ?? true
102845
+ };
102846
+ let errorMessage = "";
102847
+ try {
102848
+ const isReRun = opts.isReRun ?? false;
102849
+ let res;
102850
+ if (!isReRun) {
102851
+ this.modules.set(key, newModule);
102852
+ res = await loadContent();
102853
+ } else {
102854
+ newModule.controller = new AbortController;
102855
+ const signal = newModule.controller.signal;
102856
+ this.modules.set(key, newModule);
102857
+ const data = await reRunFn2({
102858
+ timeout: opts.timeout,
102859
+ interval: opts.interval,
102860
+ checkSuccess: opts.checkSuccess,
102861
+ fn: loadContent,
102862
+ signal
102863
+ });
102864
+ newModule.controller = null;
102865
+ if (data.code === 499) {
102866
+ newModule.status = "cancel";
102867
+ return {
102868
+ code: 499,
102869
+ message: "operation cancelled"
102870
+ };
102871
+ }
102872
+ if (data.code !== 200) {
102873
+ throw new Error(data.message);
102874
+ }
102875
+ res = data.data;
102876
+ }
102877
+ newModule.modules = res;
102878
+ newModule.status = "loaded";
102879
+ return {
102880
+ code: 200,
102881
+ data: res
102882
+ };
102883
+ } catch (error2) {
102884
+ errorMessage = error2.message;
102885
+ newModule.status = "error";
102886
+ return {
102887
+ code: 500,
102888
+ message: error2
102889
+ };
102890
+ } finally {
102891
+ newModule.loading = false;
102892
+ this.modules.set(opts.key, newModule);
102893
+ if (!errorMessage) {
102894
+ this.event.emit(opts.key);
102895
+ } else {
102896
+ this.event.emit(opts.key, errorMessage);
102857
102897
  }
102858
102898
  }
102859
102899
  }
102860
- return true;
102861
- };
102862
- var proxyRoute = async (req, res) => {
102863
- const _assistantConfig = assistantConfig2.getCacheAssistantConfig();
102864
- const home = _assistantConfig?.home || "/root/home";
102865
- const auth = _assistantConfig?.auth || {};
102866
- let noAdmin = !auth.username;
102867
- const toSetting = () => {
102868
- res.writeHead(302, { Location: `/root/cli/setting/` });
102869
- res.end();
102870
- return true;
102871
- };
102872
- const url3 = new URL(req.url, "http://localhost");
102873
- const pathname = decodeURIComponent(url3.pathname);
102874
- if (pathname === "/") {
102875
- if (noAdmin) {
102876
- return toSetting();
102900
+ async load(loadContent, opts) {
102901
+ this.loading = true;
102902
+ const key = opts.key;
102903
+ if (!key) {
102904
+ return {
102905
+ code: 404,
102906
+ message: "key is required"
102907
+ };
102877
102908
  }
102878
- res.writeHead(302, { Location: `${home}/` });
102879
- return res.end();
102909
+ if (opts?.force) {
102910
+ this.remove(key);
102911
+ }
102912
+ const has = this.modules.has(key);
102913
+ if (has) {
102914
+ return await this.hasLoaded(key);
102915
+ }
102916
+ if (typeof loadContent === "function") {
102917
+ return this.loadFn(loadContent, opts);
102918
+ }
102919
+ console.error("loadContent is not a function and not has loaded");
102880
102920
  }
102881
- if (pathname.startsWith("/favicon.ico")) {
102882
- res.statusCode = 404;
102883
- res.end("Not Found Favicon");
102884
- return;
102921
+ remove(key) {
102922
+ const has = this.modules.has(key);
102923
+ if (has) {
102924
+ this.checkRemoveController(key);
102925
+ this.modules.delete(key);
102926
+ }
102885
102927
  }
102886
- if (pathname.startsWith("/client/upload")) {
102887
- simpleRouter.parse(req, res);
102888
- return;
102928
+ emitLoaded(key) {
102929
+ this.checkRemoveController(key);
102930
+ this.event.emit(key);
102889
102931
  }
102890
- if (pathname.startsWith("/client")) {
102891
- logger.debug("handle by router", { url: req.url });
102892
- return;
102932
+ setModule(key, data, loadData) {
102933
+ const newModule = {
102934
+ key,
102935
+ status: "loaded",
102936
+ loading: false,
102937
+ modules: data || {},
102938
+ ...loadData
102939
+ };
102940
+ this.modules.set(key, newModule);
102941
+ this.emitLoaded(key);
102942
+ return newModule;
102893
102943
  }
102894
- const apiProxy = _assistantConfig?.api?.proxy || [];
102895
- const defaultApiProxy = createApiProxy(_assistantConfig?.app?.url || "https://kevisual.cn");
102896
- const allProxy = [...apiProxy, ...defaultApiProxy];
102897
- const apiBackendProxy = allProxy.find((item) => pathname.startsWith(item.path));
102898
- if (apiBackendProxy) {
102899
- log.debug("apiBackendProxy", { apiBackendProxy, url: req.url });
102900
- return proxy(req, res, {
102901
- path: apiBackendProxy.path,
102902
- target: apiBackendProxy.target,
102903
- ...apiBackendProxy
102904
- });
102944
+ cancel(key) {
102945
+ this.checkRemoveController(key);
102905
102946
  }
102906
- logger.debug("proxyRoute handle by router", { url: req.url }, noAdmin);
102907
- const urls = pathname.split("/");
102908
- const [_2, _user, _app] = urls;
102909
- if (!_app) {
102910
- res.statusCode = 404;
102911
- res.end("Not Found Proxy");
102912
- return;
102947
+ checkRemoveController(key) {
102948
+ const data = this.modules.get(key);
102949
+ if (data?.controller) {
102950
+ data.controller?.abort?.();
102951
+ delete data.controller;
102952
+ this.modules.set(key, data);
102953
+ }
102913
102954
  }
102914
- const isOpen = isOpenPath(pathname);
102915
- log.debug("proxyRoute", { _user, _app, pathname, noAdmin, isOpen });
102916
- if (noAdmin && !isOpen) {
102917
- return toSetting();
102955
+ }
102956
+ var gt2 = globalThis || window || self;
102957
+ var useEnv2 = (initEnv, initKey = "config", isOverwrite) => {
102958
+ const env3 = gt2[initKey];
102959
+ const _env = env3 || initEnv;
102960
+ if (!env3) {
102961
+ if (_env) {
102962
+ gt2[initKey] = _env;
102963
+ } else {
102964
+ gt2[initKey] = {};
102965
+ }
102966
+ } else if (isOverwrite) {
102967
+ gt2[initKey] = { ...env3, ...initEnv };
102918
102968
  }
102919
- if (_app && urls.length === 3) {
102920
- res.writeHead(302, { Location: `${req.url}/` });
102921
- return res.end();
102969
+ return gt2[initKey];
102970
+ };
102971
+ var useEnvKey2 = (key, init, initKey = "config") => {
102972
+ const _env = useEnv2({}, initKey);
102973
+ if (key && typeof _env[key] !== "undefined") {
102974
+ return _env[key];
102922
102975
  }
102923
- const proxyApiList = _assistantConfig?.proxy || [];
102924
- const proxyApi = proxyApiList.find((item) => pathname.startsWith(item.path));
102925
- if (proxyApi && proxyApi.type === "file") {
102926
- log.debug("proxyApi", { proxyApi, pathname });
102927
- const _indexPath = proxyApi.indexPath || `${_user}/${_app}/index.html`;
102928
- const _rootPath = proxyApi.rootPath;
102929
- if (!_rootPath) {
102930
- log.error("Not Found rootPath", { proxyApi, pathname });
102931
- return res.end(`Not Found [${proxyApi.path}] rootPath`);
102976
+ if (key && init) {
102977
+ if (typeof init !== "function") {
102978
+ _env[key] = init;
102932
102979
  }
102933
- return fileProxy(req, res, {
102934
- path: proxyApi.path,
102935
- rootPath: proxyApi.rootPath,
102936
- ...proxyApi,
102937
- indexPath: _indexPath
102938
- });
102939
- } else if (proxyApi && proxyApi.type === "http") {
102940
- log.debug("proxyApi http", { proxyApi, pathname });
102941
- return httpProxy(req, res, {
102942
- path: proxyApi.path,
102943
- target: proxyApi.target,
102944
- type: "http"
102945
- });
102980
+ if (typeof init === "function") {
102981
+ const result = init();
102982
+ if (result instanceof Promise) {
102983
+ return result.then((res) => {
102984
+ _env[key] = res;
102985
+ return res;
102986
+ });
102987
+ }
102988
+ _env[key] = result;
102989
+ }
102990
+ return _env[key];
102946
102991
  }
102947
- const filter2 = await authFilter(req, res);
102948
- if (filter2) {
102949
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
102950
- return res.end(renderNoAuthAndLogin("Not Authorized Proxy"));
102992
+ if (key) {
102993
+ const baseLoad = new BaseLoad2;
102994
+ const voidFn = async () => {
102995
+ return _env[key];
102996
+ };
102997
+ const checkFn = async () => {
102998
+ const loadRes = await baseLoad.load(voidFn, {
102999
+ key,
103000
+ isReRun: true,
103001
+ checkSuccess: () => _env[key],
103002
+ timeout: 5 * 60 * 1000,
103003
+ interval: 1000
103004
+ });
103005
+ if (loadRes.code !== 200) {
103006
+ console.error("load key error");
103007
+ return null;
103008
+ }
103009
+ return _env[key];
103010
+ };
103011
+ return checkFn();
102951
103012
  }
102952
- const localProxyProxyList = localProxy.getLocalProxyList();
102953
- const localProxyProxy = localProxyProxyList.find((item) => pathname.startsWith(item.path));
102954
- if (localProxyProxy) {
102955
- log.log("localProxyProxy", { localProxyProxy, url: req.url });
102956
- return fileProxy(req, res, {
102957
- path: localProxyProxy.path,
102958
- rootPath: localProxy.pagesDir,
102959
- indexPath: localProxyProxy.indexPath
102960
- });
103013
+ console.error("key is empty ");
103014
+ return null;
103015
+ };
103016
+ var useEnvKeyNew2 = (key, initKey = "config", opts) => {
103017
+ const _env = useEnv2({}, initKey);
103018
+ if (key) {
103019
+ delete _env[key];
102961
103020
  }
102962
- const creatCenterProxy = createApiProxy(_assistantConfig?.app?.url || "https://kevisual.cn", ["/root", "/" + _user]);
102963
- const centerProxy = creatCenterProxy.find((item) => pathname.startsWith(item.path));
102964
- if (centerProxy) {
102965
- return httpProxy(req, res, {
102966
- path: centerProxy.path,
102967
- target: centerProxy.target,
102968
- type: "http"
102969
- });
103021
+ if (opts?.getNew && opts.init) {
103022
+ return useEnvKey2(key, opts.init, initKey);
103023
+ } else if (opts?.getNew) {
103024
+ return useEnvKey2(key, null, initKey);
102970
103025
  }
102971
- log.debug("handle by router 404", req.url);
102972
- res.statusCode = 404;
102973
- res.end("Not Found Proxy");
102974
103026
  };
102975
- var proxyWs = () => {
102976
- const apiProxy = assistantConfig2.getCacheAssistantConfig()?.api?.proxy || [];
102977
- const registry2 = assistantConfig2.getRegistry();
102978
- const proxy4 = assistantConfig2.getCacheAssistantConfig()?.proxy || [];
102979
- const proxyApi = [...apiProxy, ...proxy4].filter((item) => item.ws);
102980
- const demoProxy = [
102981
- {
102982
- path: "/api/ws/demo",
102983
- target: "https://kevisual.xiongxiao.me",
102984
- pathname: "/api/router",
102985
- ws: true
102986
- }
102987
- ];
102988
- const pathRouter = proxyApi.find((item) => item.path === "/api/router");
102989
- if (!pathRouter) {
102990
- proxyApi.push({
102991
- path: "/api/router",
102992
- target: registry2 || "https://kevisual.cn",
102993
- pathname: "/api/router",
102994
- ws: true
102995
- });
103027
+ var useContextKey2 = (key, init, isNew) => {
103028
+ if (isNew) {
103029
+ return useEnvKeyNew2(key, "context", { getNew: true, init });
102996
103030
  }
102997
- return proxyApi.map(createProxyInfo);
103031
+ return useEnvKey2(key, init, "context");
102998
103032
  };
102999
- var createProxyInfo = (proxyApiItem) => {
103000
- const func = async (req, res) => {
103001
- const { ws, emitter, id, data } = req;
103002
- if (!id) {
103003
- ws.send(JSON.stringify({ type: "error", message: "not found id" }));
103004
- ws.close();
103005
- return;
103006
- }
103007
- let _proxySocket = ws.data.proxySocket;
103008
- if (!_proxySocket) {
103009
- const _u = new URL(proxyApiItem.path, `${proxyApiItem.target}`);
103010
- if (proxyApiItem.pathname) {
103011
- _u.pathname = proxyApiItem.pathname;
103012
- }
103013
- const isHttps = _u.protocol === "https:";
103014
- const wsProtocol = isHttps ? "wss" : "ws";
103015
- const wsUrl = `${wsProtocol}://${_u.host}${_u.pathname}`;
103016
- console.log("WebSocket proxy URL", { wsUrl });
103017
- const proxySocket = new wrapper_default(wsUrl);
103018
- proxySocket.on("open", () => {
103019
- proxySocket.on("message", (message) => {
103020
- ws.send(message);
103021
- });
103022
- });
103023
- proxySocket.on("error", (err) => {
103024
- console.error(`WebSocket proxy error: ${err.message}`);
103025
- });
103026
- proxySocket.on("close", () => {
103027
- console.log("WebSocket proxy closed");
103028
- });
103029
- emitter.once("close--" + id, () => {
103030
- console.log("WebSocket client closed");
103031
- proxySocket?.close?.();
103032
- });
103033
- ws.data.proxySocket = proxySocket;
103034
- return;
103035
- }
103036
- console.log("ws.data", data);
103037
- _proxySocket.send(JSON.stringify(data));
103038
- };
103039
- return {
103040
- path: proxyApiItem.path,
103041
- io: true,
103042
- func
103043
- };
103033
+ var use2 = useContextKey2;
103034
+ var useConfigKey2 = (key, init, isNew) => {
103035
+ if (isNew) {
103036
+ return useEnvKeyNew2(key, "config", { getNew: true, init });
103037
+ }
103038
+ return useEnvKey2(key, init, "config");
103044
103039
  };
103045
-
103046
- // src/routes-simple/upload.ts
103047
- var import_busboy = __toESM(require_lib4(), 1);
103048
- import path14 from "path";
103049
- import fs14 from "fs";
103050
-
103051
- // ../node_modules/.pnpm/@kevisual+router@0.0.55/node_modules/@kevisual/router/src/server/cookie.ts
103052
- var NullObject2 = /* @__PURE__ */ (() => {
103053
- const C = function() {};
103054
- C.prototype = Object.create(null);
103055
- return C;
103056
- })();
103057
- function parseCookie2(str, options) {
103058
- const obj = new NullObject2;
103059
- const len = str.length;
103060
- if (len < 2)
103061
- return obj;
103062
- const dec = options?.decode || decode2;
103063
- let index = 0;
103064
- do {
103065
- const eqIdx = eqIndex2(str, index, len);
103066
- if (eqIdx === -1)
103067
- break;
103068
- const endIdx = endIndex2(str, index, len);
103069
- if (eqIdx > endIdx) {
103070
- index = str.lastIndexOf(";", eqIdx - 1) + 1;
103071
- continue;
103072
- }
103073
- const key = valueSlice2(str, index, eqIdx);
103074
- if (obj[key] === undefined) {
103075
- obj[key] = dec(valueSlice2(str, eqIdx + 1, endIdx));
103040
+ class InitEnv2 {
103041
+ static isInit = false;
103042
+ static init(opts) {
103043
+ if (InitEnv2.isInit) {
103044
+ return;
103076
103045
  }
103077
- index = endIdx + 1;
103078
- } while (index < len);
103079
- return obj;
103080
- }
103081
- function endIndex2(str, min, len) {
103082
- const index = str.indexOf(";", min);
103083
- return index === -1 ? len : index;
103084
- }
103085
- function eqIndex2(str, min, max) {
103086
- const index = str.indexOf("=", min);
103087
- return index < max ? index : -1;
103088
- }
103089
- function valueSlice2(str, min, max) {
103090
- let start4 = min;
103091
- let end = max;
103092
- do {
103093
- const code = str.charCodeAt(start4);
103094
- if (code !== 32 && code !== 9)
103095
- break;
103096
- } while (++start4 < end);
103097
- while (end > start4) {
103098
- const code = str.charCodeAt(end - 1);
103099
- if (code !== 32 && code !== 9)
103100
- break;
103101
- end--;
103102
- }
103103
- return str.slice(start4, end);
103104
- }
103105
- function decode2(str) {
103106
- if (str.indexOf("%") === -1)
103107
- return str;
103108
- try {
103109
- return decodeURIComponent(str);
103110
- } catch (e) {
103111
- return str;
103046
+ const { load: load2 = true, page = false } = opts || {};
103047
+ InitEnv2.isInit = true;
103048
+ gt2.useConfigKey = useConfigKey2;
103049
+ gt2.useContextKey = useContextKey2;
103050
+ gt2.use = use2;
103051
+ gt2.webEnv = { useConfigKey: useConfigKey2, useContextKey: useContextKey2, use: use2 };
103052
+ load2 && (gt2.Load = BaseLoad2);
103112
103053
  }
103113
103054
  }
103114
-
103115
- // src/module/get-header-token.ts
103116
- var getTokenFromRequest = (req) => {
103117
- let token = req.headers?.["authorization"] || req.headers?.["Authorization"] || "";
103118
- const url3 = new URL(req.url || "", "http://localhost");
103119
- if (!token) {
103120
- token = url3.searchParams.get("token") || "";
103121
- }
103122
- if (!token) {
103123
- const parsedCookies = parseCookie2(req.headers.cookie || "");
103124
- token = parsedCookies.token || "";
103125
- }
103126
- if (token) {
103127
- token = token.replace("Bearer ", "");
103128
- }
103129
- return token;
103130
- };
103055
+ InitEnv2.init();
103131
103056
 
103132
103057
  // src/routes-simple/router.ts
103133
103058
  var cacheFilePath = useFileStore("cache-file", { needExists: true });
@@ -105633,7 +105558,7 @@ program.description("启动服务").option("-d, --daemon", "是否以守护进
105633
105558
  } else if (options.start) {
105634
105559
  console.log("启动服务", source_default.green(assistantConfig2.configDir));
105635
105560
  const config2 = assistantConfig2.getCacheAssistantConfig();
105636
- const listenPort = options.port || config2?.server?.port;
105561
+ const listenPort = parseInt(options.port || config2?.server?.port);
105637
105562
  const listenPath = config2?.server?.path || "::";
105638
105563
  const server = await runServer(listenPort, listenPath);
105639
105564
  } else {