Skip to content

Commit 6fac871

Browse files
committed
refactor: allow UPPER_CASE for consts
1 parent 2c3d2f8 commit 6fac871

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ module.exports = {
2121
format: ['camelCase', 'PascalCase'],
2222
leadingUnderscore: 'allow',
2323
},
24+
{
25+
selector: 'variable',
26+
modifiers: ['const'],
27+
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
28+
},
2429
{
2530
selector: 'typeLike',
2631
format: ['PascalCase'],

src/core/const.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable @typescript-eslint/naming-convention */
2-
31
// supported platforms
42
// TODO: refactor to enums and put name mapping into util method
53
export const IOS = 1;
@@ -15,7 +13,7 @@ export const REACT_NATIVE_NAME = 'React-Native';
1513
export const CORDOVA = 2;
1614
export const CORDOVA_NAME = 'Cordova';
1715

18-
// suupported env
16+
// supported env
1917
export const PRODUCTION = 'Production';
2018
export const STAGING = 'Staging';
2119

src/core/services/account-manager.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { redisClient } from '../utils/connections';
1111
import { passwordVerifySync, randToken, md5, passwordHashSync } from '../utils/security';
1212
import { emailManager } from './email-manager';
1313

14-
const loginLimitPre = 'LOGIN_LIMIT_PRE_';
15-
const registerCode = 'REGISTER_CODE_';
16-
const expired = 1200;
17-
const expiredSpeed = 10;
14+
const LOGIN_LIMIT_PRE = 'LOGIN_LIMIT_PRE_';
15+
const REGISTER_CODE = 'REGISTER_CODE_';
16+
const EXPIRED = 1200;
17+
const EXPIRED_SPEED = 10;
1818

1919
class AccountManager {
2020
collaboratorCan(uid: number, appName: string, logger: Logger) {
@@ -119,7 +119,7 @@ class AccountManager {
119119
})
120120
.then((users) => {
121121
if (tryLoginTimes > 0) {
122-
const loginKey = `${loginLimitPre}${users.id}`;
122+
const loginKey = `${LOGIN_LIMIT_PRE}${users.id}`;
123123
return redisClient.get(loginKey).then((loginErrorTimes) => {
124124
if (Number(loginErrorTimes) > tryLoginTimes) {
125125
throw new AppError(`您输入密码错误次数超过限制,帐户已经锁定`);
@@ -132,7 +132,7 @@ class AccountManager {
132132
.then((users) => {
133133
if (!passwordVerifySync(password, users.password)) {
134134
if (tryLoginTimes > 0) {
135-
const loginKey = `${loginLimitPre}${users.id}`;
135+
const loginKey = `${LOGIN_LIMIT_PRE}${users.id}`;
136136
redisClient.exists(loginKey).then((isExists) => {
137137
if (!isExists) {
138138
const expires = moment().endOf('day').unix() - moment().unix();
@@ -163,7 +163,7 @@ class AccountManager {
163163
// 将token临时存储到redis
164164
const token = randToken(40);
165165
return redisClient
166-
.setEx(`${registerCode}${md5(email)}`, expired, token)
166+
.setEx(`${REGISTER_CODE}${md5(email)}`, EXPIRED, token)
167167
.then(() => {
168168
return token;
169169
});
@@ -182,15 +182,15 @@ class AccountManager {
182182
}
183183
})
184184
.then(() => {
185-
const registerKey = `${registerCode}${md5(email)}`;
185+
const registerKey = `${REGISTER_CODE}${md5(email)}`;
186186
return redisClient.get(registerKey).then((storageToken) => {
187187
if (_.isEmpty(storageToken)) {
188188
throw new AppError(`验证码已经失效,请您重新获取`);
189189
}
190190
if (!_.eq(token, storageToken)) {
191191
redisClient.ttl(registerKey).then((ttl) => {
192192
if (ttl > 0) {
193-
redisClient.expire(registerKey, ttl - expiredSpeed);
193+
redisClient.expire(registerKey, ttl - EXPIRED_SPEED);
194194
}
195195
});
196196
throw new AppError(`您输入的验证码不正确,请重新输入`);

src/core/services/client-manager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { DEPLOYMENT_FAILED, DEPLOYMENT_SUCCEEDED } from '../const';
1414
import { parseVersion, getBlobDownloadUrl } from '../utils/common';
1515
import { redisClient } from '../utils/connections';
1616

17-
const updateCheck = 'UPDATE_CHECK';
18-
const chosenMan = 'CHOSEN_MAN';
19-
const expired = 600;
17+
const UPDATE_CHECK = 'UPDATE_CHECK';
18+
const CHOSEN_MAN = 'CHOSEN_MAN';
19+
const EXPIRED = 600;
2020

2121
interface UpdateCheckInfo {
2222
packageId: number;
@@ -38,7 +38,7 @@ interface UpdateCheckInfo {
3838

3939
class ClientManager {
4040
private getUpdateCheckCacheKey(deploymentKey, appVersion, label, packageHash) {
41-
return [updateCheck, deploymentKey, appVersion, label, packageHash].join(':');
41+
return [UPDATE_CHECK, deploymentKey, appVersion, label, packageHash].join(':');
4242
}
4343

4444
clearUpdateCheckCache(deploymentKey, appVersion, label, packageHash, logger: Logger) {
@@ -108,7 +108,7 @@ class ClientManager {
108108
try {
109109
logger.debug('updateCheckFromCache read from db');
110110
const strRs = JSON.stringify(rs);
111-
redisClient.setEx(redisCacheKey, expired, strRs);
111+
redisClient.setEx(redisCacheKey, EXPIRED, strRs);
112112
} catch (e) {
113113
// do nothing
114114
}
@@ -118,7 +118,7 @@ class ClientManager {
118118
}
119119

120120
private getChosenManCacheKey(packageId, rollout, clientUniqueId) {
121-
return [chosenMan, packageId, rollout, clientUniqueId].join(':');
121+
return [CHOSEN_MAN, packageId, rollout, clientUniqueId].join(':');
122122
}
123123

124124
private random(rollout) {

src/core/services/datacenter-manager.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { config } from '../config';
77
import { createEmptyFolder, copy } from '../utils/common';
88
import { calcAllFileSha256, packageHashSync } from '../utils/security';
99

10-
const manifestFilename = 'manifest.json';
11-
const contentsName = 'contents';
10+
const MANIFEST_FILENAME = 'manifest.json';
11+
const CONTENTS_NAME = 'contents';
1212

1313
class DataCenterManager {
1414
getDataDir() {
@@ -18,17 +18,17 @@ class DataCenterManager {
1818
hasPackageStoreSync(packageHash: string) {
1919
const dataDir = this.getDataDir();
2020
const packageHashPath = path.join(dataDir, packageHash);
21-
const manifestFile = path.join(packageHashPath, manifestFilename);
22-
const contentPath = path.join(packageHashPath, contentsName);
21+
const manifestFile = path.join(packageHashPath, MANIFEST_FILENAME);
22+
const contentPath = path.join(packageHashPath, CONTENTS_NAME);
2323
return fs.existsSync(manifestFile) && fs.existsSync(contentPath);
2424
}
2525

2626
getPackageInfo(packageHash: string) {
2727
if (this.hasPackageStoreSync(packageHash)) {
2828
const dataDir = this.getDataDir();
2929
const packageHashPath = path.join(dataDir, packageHash);
30-
const manifestFile = path.join(packageHashPath, manifestFilename);
31-
const contentPath = path.join(packageHashPath, contentsName);
30+
const manifestFile = path.join(packageHashPath, MANIFEST_FILENAME);
31+
const contentPath = path.join(packageHashPath, CONTENTS_NAME);
3232
return this.buildPackageInfo(packageHash, packageHashPath, contentPath, manifestFile);
3333
}
3434
throw new AppError("can't get PackageInfo");
@@ -51,8 +51,8 @@ class DataCenterManager {
5151
validateStore(providePackageHash: string, logger: Logger) {
5252
const dataDir = this.getDataDir();
5353
const packageHashPath = path.join(dataDir, providePackageHash);
54-
const manifestFile = path.join(packageHashPath, manifestFilename);
55-
const contentPath = path.join(packageHashPath, contentsName);
54+
const manifestFile = path.join(packageHashPath, MANIFEST_FILENAME);
55+
const contentPath = path.join(packageHashPath, CONTENTS_NAME);
5656
if (!this.hasPackageStoreSync(providePackageHash)) {
5757
logger.debug(`validateStore providePackageHash not exist`);
5858
return Promise.resolve(false);
@@ -84,8 +84,8 @@ class DataCenterManager {
8484
const packageHash = packageHashSync(manifestJson);
8585
const dataDir = this.getDataDir();
8686
const packageHashPath = path.join(dataDir, packageHash);
87-
const manifestFile = path.join(packageHashPath, manifestFilename);
88-
const contentPath = path.join(packageHashPath, contentsName);
87+
const manifestFile = path.join(packageHashPath, MANIFEST_FILENAME);
88+
const contentPath = path.join(packageHashPath, CONTENTS_NAME);
8989
return this.validateStore(packageHash, logger).then((isValidate) => {
9090
if (!force && isValidate) {
9191
return this.buildPackageInfo(

src/core/utils/storage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import fsextra from 'fs-extra';
88
import { Logger } from 'kv-logger';
99
import _ from 'lodash';
1010
import qiniu from 'qiniu';
11-
1211
import { AppError } from '../app-error';
1312
import { config } from '../config';
1413

src/routes/apps.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import _ from 'lodash';
44
import validator from 'validator';
55
import { AppError } from '../core/app-error';
66
import { config } from '../core/config';
7-
87
import {
98
IOS,
109
IOS_NAME,

0 commit comments

Comments
 (0)