Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

youzanyun-open-sdk

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

youzanyun-open-sdk - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

41

lib/token/manager.js

@@ -7,5 +7,4 @@ const delay = require('delay');

const CloudTypeTool = 'Tool';
const TokenLockKey = 'yzy_token_lock';
const TokenKdtsKey = 'yzy_token_kdts';
module.exports = class TokenManager {

@@ -16,2 +15,3 @@ constructor({

httpClient,
env,
tokenHost

@@ -24,2 +24,5 @@ }) {

this.httpClient = httpClient;
this.tokenLockKey = `yzy_${env}_token_lock`;
this.tokenKdtsKey = `yzy_${env}_token_kdts`;
this.tokenService = new Token({

@@ -36,3 +39,3 @@ clientId, clientSecret, tokenHost,

this.cloudType = CloudTypeSelf;
this.tokenCacheKeyPrefix = `yzy_token_${CloudTypeSelf}_`;
this.tokenCacheKeyPrefix = `yzy_${env}_token_${CloudTypeSelf}_`;
}

@@ -48,3 +51,3 @@

this.cloudType = CloudTypeTool;
this.tokenCacheKeyPrefix = `yzy_token_${CloudTypeTool}_`;
this.tokenCacheKeyPrefix = `yzy_${env}_token_${CloudTypeTool}_`;
}

@@ -62,5 +65,5 @@

await ioredisClient.set(cacheKey, JSON.stringify(token));
let kdtsString = await ioredisClient.get(TokenKdtsKey) || '';
let kdtsString = await ioredisClient.get(this.tokenKdtsKey) || '';
if (kdtsString.indexOf(kdtId + '') == -1) {
await ioredisClient.set(TokenKdtsKey, kdtsString + ',' + kdtId)
await ioredisClient.set(this.tokenKdtsKey, kdtsString + ',' + kdtId)
}

@@ -78,3 +81,3 @@ return token;

while (tryCount < totalCount) { // 随机等待加锁时间
let lockReturn = await ioredisClient.setnx(TokenLockKey, '' + Date.now());
let lockReturn = await ioredisClient.setnx(this.tokenLockKey, '' + Date.now());
if (lockReturn == 1) {

@@ -87,7 +90,7 @@ return true;

// 超时检测
let lockValue = await ioredisClient.get(TokenLockKey);
let lockValue = await ioredisClient.get(this.tokenLockKey);
let diff = Date.now() - lockValue;
if (!Number.isInteger(diff) || diff > 1000 * 60 * 2) { // 2分钟超时
await ioredisClient.del(TokenLockKey);
let lockReturn = await ioredisClient.setnx(TokenLockKey, '' + Date.now());
await ioredisClient.del(this.tokenLockKey);
let lockReturn = await ioredisClient.setnx(this.tokenLockKey, '' + Date.now());
if (lockReturn == 1) {

@@ -102,3 +105,3 @@ return true;

async releaseTokenOperate() {
await this.ioredisClient.del(TokenLockKey);
await this.ioredisClient.del(this.tokenLockKey);
return true;

@@ -112,3 +115,3 @@ }

let ioredisClient = this.ioredisClient;
let kdtsString = await ioredisClient.get(TokenKdtsKey) || '';
let kdtsString = await ioredisClient.get(this.tokenKdtsKey) || '';
let kdts = kdtsString.split(',');

@@ -136,10 +139,14 @@ for (let kdtId of kdts) {

async getAllToken() {
async getTokenState() {
let ioredisClient = this.ioredisClient;
let kdtsString = await ioredisClient.get(TokenKdtsKey) || '';
let lockValue = await ioredisClient.get(TokenLockKey);
let kdtsString = await ioredisClient.get(this.tokenKdtsKey) || '';
let lockValue = await ioredisClient.get(this.tokenLockKey);
let result = {
kdtsKey: this.tokenKdtsKey,
kdts: kdtsString,
lockKey: this.tokenLockKey,
lockValue,
tokenList: []
tokenCacheKeyPrefix: this.tokenCacheKeyPrefix,
localCache: this.tokenCache,
redisToolTokenList: []
};

@@ -159,3 +166,3 @@

}
result.tokenList.push(token);
result.redisToolTokenList.push(token);
}

@@ -162,0 +169,0 @@ return result;

{
"name": "youzanyun-open-sdk",
"version": "1.2.0",
"version": "1.2.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc