Skip to content

Commit

Permalink
Fix eslint (#158)
Browse files Browse the repository at this point in the history
* fix eslint issues

* 0.3.8

* modify: fix the bug about the sort of attribute in CDNUploadDataRequest and PackCdnData

* modify: recorrect some mistakes
  • Loading branch information
su-chang authored and windmemory committed Jul 11, 2019
1 parent e9f60cb commit 2a6b510
Show file tree
Hide file tree
Showing 48 changed files with 445 additions and 429 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/gateway/proto-ts/*

src/gateway/proto/*
2 changes: 1 addition & 1 deletion bin/store-dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,4 @@ export function dumpRoomMembers () {
}

main()
.catch(console.error)
.catch(console.error)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet-padpro",
"version": "0.3.7",
"version": "0.3.8",
"description": "Padpro Puppet for Wechaty",
"directories": {
"example": "examples"
Expand All @@ -17,7 +17,7 @@
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
"lint:md": "markdownlint README.md",
"lint:ts": "tsc --noEmit",
"lint:es": "eslint 'bin/**/*.ts' 'src/**/*.ts' 'tests/**/*.spec.ts' --ignore-pattern tests/fixtures/",
"lint:es": "eslint 'src/**/*.ts' 'tests/**/*.spec.ts' --ignore-pattern tests/fixtures/",
"test": "npm run lint && npm run test:unit && npm run test:int",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:unit": "blue-tape -r ts-node/register \"src/**/*.spec.ts\"",
Expand Down
2 changes: 1 addition & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const SPECIALUSERS = ['newsapp', 'fmessage', 'filehelper', 'weibo', 'qqma
'readerapp', 'blogapp', 'facebookapp', 'masssendapp', 'meishiapp', 'feedsapp', 'voip',
'blogappweixin', 'weixin', 'brandsessionholder', 'weixinreminder', 'wxid_novlwrv3lqwv11',
'gh_22b87fa7cb3c', 'officialaccounts', 'notification_messages', 'wxid_novlwrv3lqwv11',
'gh_22b87fa7cb3c', 'wxitil', 'userexperience_alarm', 'notification_messages'
'gh_22b87fa7cb3c', 'wxitil', 'userexperience_alarm', 'notification_messages',
]

export const CLIENT_OS_TYPE = 'iPad iPhone OS9.3.3'
Expand Down
72 changes: 36 additions & 36 deletions src/converter/message-converter.spec.ts

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/converter/room-converter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
log
} from '../config'
import { log } from '../config'

import {
GrpcRoomRawPayload,
PadproRoomPayload
PadproRoomPayload,
} from '../schemas'

const PRE = 'RoomConverter'
Expand Down
2 changes: 2 additions & 0 deletions src/gateway/dedupe-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const PRE = 'DedupeApi'
* Only api calls in the DEDUPE_API list will be affected.
*/
export class DedupeApi {

private pool: {
[key: string]: ApiCall
}
Expand Down Expand Up @@ -138,4 +139,5 @@ export class DedupeApi {
private getKey (apiName: string, params?: ApiParams) {
return `${apiName}-${params ? JSON.stringify(params) : ''}`
}

}
5 changes: 3 additions & 2 deletions src/gateway/grpc-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class GrpcGateway extends EventEmitter {
const payload = Buffer.from(response.getPayload_asU8())
const commandUrl = response.getCommandurl()
this.cleanUpErrorCounter()
resolve({ payload, commandUrl })
resolve({ commandUrl, payload })
}
}
)
Expand Down Expand Up @@ -274,11 +274,12 @@ export class GrpcGateway extends EventEmitter {
* Retry rpc call
*/
try {
await new Promise(r => setTimeout(r, 1000))
await new Promise(resolve => setTimeout(resolve, 1000))
const result = await callback()
return result
} catch (e) {
return this.processError(e, callback, --retryLeft)
}
}

}
8 changes: 4 additions & 4 deletions src/gateway/proto-ts/PadchatGrpc_grpc_pb.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// package: GrpcPadchat
// file: PadchatGrpc.proto

/* tslint:disable */
/* eslint:disable */

import * as grpc from "grpc";
import * as PadchatGrpc_pb from "./PadchatGrpc_pb";
import * as grpc from 'grpc';
import * as PadchatGrpc_pb from './PadchatGrpc_pb';

interface IPadchatGrpcService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
packLong: IPadchatGrpcService_IPackLong;
Expand Down Expand Up @@ -71,4 +71,4 @@ export class PadchatGrpcClient extends grpc.Client implements IPadchatGrpcClient
public parse(request: PadchatGrpc_pb.ParseRequest, callback: (error: Error | null, response: PadchatGrpc_pb.ParsedResponse) => void): grpc.ClientUnaryCall;
public parse(request: PadchatGrpc_pb.ParseRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: PadchatGrpc_pb.ParsedResponse) => void): grpc.ClientUnaryCall;
public parse(request: PadchatGrpc_pb.ParseRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: Error | null, response: PadchatGrpc_pb.ParsedResponse) => void): grpc.ClientUnaryCall;
}
}
4 changes: 2 additions & 2 deletions src/gateway/proto-ts/PadchatGrpc_pb.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// package: GrpcPadchat
// file: PadchatGrpc.proto

/* tslint:disable */
/* eslint:disable */

import * as jspb from "google-protobuf";

Expand Down Expand Up @@ -163,4 +163,4 @@ export namespace ParsedResponse {
export type AsObject = {
payload: string,
}
}
}
24 changes: 12 additions & 12 deletions src/gateway/wechat-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ export class WechatGateway extends EventEmitter {

longSocket.once('error', (e) => {
log.error(PRE, `initLongSocket() Promise() longSocket.on(error) ${e}`)
return reject('ERROR')
return reject(new Error('ERROR'))
})
longSocket.once('close', () => {
log.silly(PRE, 'initLongSocket() Promise() longSocket.on(close)')
return reject('CLOSE')
return reject(new Error('CLOSE'))
})
longSocket.once('timeout', () => {
log.silly(PRE, `initLongSocket() Promise() longSocket.on(timeout)`)
return reject('TIMEOUT')
return reject(new Error('TIMEOUT'))
})
})

Expand Down Expand Up @@ -259,7 +259,7 @@ export class WechatGateway extends EventEmitter {
if (!this.apiCounter[apiName]) {
this.apiCounter[apiName] = 0
}
this.apiCounter[apiName] ++
this.apiCounter[apiName]++
log.silly(PRE, `_callApi(${apiName}, ${JSON.stringify(params)}) the ${this.apiCounter[apiName]} times, booted ${(new Date().getTime() - this.bootTime) / 1000} seconds since boot.`)
const option = ApiOptions[apiName]
if (!option) {
Expand Down Expand Up @@ -336,7 +336,7 @@ export class WechatGateway extends EventEmitter {
let dataLen = 0

if (response.statusCode !== 200) {
reject(`sendShort failed, status code: ${response.statusCode}, status message: ${response.statusMessage}`)
reject(new Error(`sendShort failed, status code: ${response.statusCode}, status message: ${response.statusMessage}`))
}
response.on('data', (chunk: any) => {
rawData.push(chunk)
Expand All @@ -355,7 +355,7 @@ export class WechatGateway extends EventEmitter {
this.emit('reset')
} else if (judgeFlag !== 191) {
log.warn(`sendShort receive unknown package: [${judgeFlag}] ${buffer.toString('hex')} ${buffer.toString()}]`)
reject('UNKNOWN_PACKAGE')
reject(new Error('UNKNOWN_PACKAGE'))
}
}
resolve(buffer)
Expand All @@ -367,7 +367,7 @@ export class WechatGateway extends EventEmitter {
})
req.on('timeout', () => {
req.abort()
reject(`TIMEOUT`)
reject(new Error(`TIMEOUT`))
})
req.write(res.payload)
req.end()
Expand All @@ -389,7 +389,7 @@ export class WechatGateway extends EventEmitter {
this.emit('reset')
} else if (judgeFlag !== 191) {
log.warn(`sendLong receive unknown package: [${judgeFlag}] ${buffer.toString('hex')}]`)
reject('UNKNOWN_PACKAGE')
reject(new Error('UNKNOWN_PACKAGE'))
}
}
delete this.backs[reqSeq]
Expand Down Expand Up @@ -452,10 +452,9 @@ export class WechatGateway extends EventEmitter {
} else {
this.emit('newMessage', bys)
}
} else if (bys.length >= 16 && bys[16] !== 191 &&
!(bys[3] === 58 && bys[5] === 16 && bys[7] === 1 && bys.length === 58) &&
!(bys[3] === 47 && bys[5] === 16 && bys[7] === 1 && bys.length === 47)) {
return
} else if (bys.length >= 16 && bys[16] !== 191
&& !(bys[3] === 58 && bys[5] === 16 && bys[7] === 1 && bys.length === 58)
&& !(bys[3] === 47 && bys[5] === 16 && bys[7] === 1 && bys.length === 47)) {
} else {
const seq = this.bufferToInt(bys, 12) // 12 - 16 sequence number
this.backs[seq] && this.backs[seq](bys)
Expand All @@ -465,4 +464,5 @@ export class WechatGateway extends EventEmitter {
private bufferToInt (buffer: Buffer, offset = 0): number {
return buffer.readUIntBE(offset, 4)
}

}
20 changes: 10 additions & 10 deletions src/manager/cache-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class CacheManager {
public async setRoom (
roomId: string,
payload: PadproRoomPayload
): Promise<void> {
): Promise<void> {
if (!this.cacheRoomRawPayload) {
throw new Error(`${PRE} setRoom() has no cache.`)
}
Expand Down Expand Up @@ -302,12 +302,12 @@ export class CacheManager {
log.silly(PRE, `parseJSON(${payload})`)
return JSON.parse(payload, (_, v) => {
if (
v !== null &&
typeof v === 'object' &&
'type' in v &&
v.type === 'Buffer' &&
'data' in v &&
Array.isArray(v.data)
v !== null
&& typeof v === 'object'
&& 'type' in v
&& v.type === 'Buffer'
&& 'data' in v
&& Array.isArray(v.data)
) {
return Buffer.from(v.data)
}
Expand All @@ -321,7 +321,7 @@ export class CacheManager {
): Promise<void> {
log.verbose(PRE, 'initCache(%s, %s)', token, userId)

if ( this.cacheContactRawPayload
if (this.cacheContactRawPayload
|| this.cacheRoomMemberRawPayload
|| this.cacheRoomRawPayload
|| this.cacheRoomInvitationRawPayload
Expand Down Expand Up @@ -380,7 +380,7 @@ export class CacheManager {
private async releaseCache () {
log.verbose(PRE, 'releaseCache()')

if ( this.cacheContactRawPayload
if (this.cacheContactRawPayload
&& this.cacheRoomMemberRawPayload
&& this.cacheRoomRawPayload
&& this.cacheRoomInvitationRawPayload
Expand All @@ -393,7 +393,7 @@ export class CacheManager {
this.cacheRoomMemberRawPayload.close(),
this.cacheRoomRawPayload.close(),
this.cacheRoomInvitationRawPayload.close(),
this.cacheFile.close()
this.cacheFile.close(),
])

this.cacheContactRawPayload = undefined
Expand Down
21 changes: 12 additions & 9 deletions src/manager/cdn-manager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint promise/param-names: 0 */
/* eslint sort-keys: 0 */
import http, { ClientRequest, IncomingMessage, RequestOptions } from 'http'
import md5 from 'md5'
import publicIp from 'public-ip'
Expand Down Expand Up @@ -74,10 +76,10 @@ export class CDNManager {
const result: GrpcGetCdnDnsPayload = await this.wechatGateway.callApi('GrpcGetCdnDns', { ip })
this.cdnInfo = {
authKey: Buffer.from(result.dnsCdn.aesKey, 'base64'),
clientVersion: result.clientVersion,
serverIP: result.dnsCdn.ip,
uin: parseInt(result.dnsCdn.uin, 10),
version: parseInt(result.dnsCdn.ver, 10),
clientVersion: result.clientVersion,
}
}

Expand All @@ -94,7 +96,7 @@ export class CDNManager {
new Promise((_, reject) => {
const timeoutTimer = setTimeout(() => {
clearTimeout(timeoutTimer)
reject(`${PRE} sendFile() failed, Can not get CDN info: timeout.`)
reject(new Error(`${PRE} sendFile() failed, Can not get CDN info: timeout.`))
}, 20000)
}),
])
Expand Down Expand Up @@ -147,9 +149,9 @@ export class CDNManager {
if (response.fileid) {
fileid = response.fileid
await this.cacheManager.setFileCache(fileid, {
fileId: fileid,
aesKey,
timestamp: new Date().getTime()
fileId: fileid,
timestamp: new Date().getTime(),
})
}
curIndex = endIndex
Expand Down Expand Up @@ -202,7 +204,7 @@ export class CDNManager {
new Promise((_, reject) => {
const timeoutTimer = setTimeout(() => {
clearTimeout(timeoutTimer)
reject(`${PRE} sendFile() failed, Can not get CDN info: timeout.`)
reject(new Error(`${PRE} sendFile() failed, Can not get CDN info: timeout.`))
}, 20000)
}),
])
Expand All @@ -215,7 +217,7 @@ export class CDNManager {

result = Buffer.concat([
result,
data
data,
])
dataLen = response.totalsize || dataLen
curIndex += data.length
Expand Down Expand Up @@ -393,7 +395,7 @@ export class CDNManager {
} catch (e) {
tryCount++
log.verbose(PRE, `_sendCdnRequest() the ${tryCount} try failed for reason: \n${e}`)
await new Promise(r => setTimeout(r, 1000 * tryCount * tryCount))
await new Promise(resolve => setTimeout(resolve, 1000 * tryCount * tryCount))
}
}
throw new Error(`${PRE} sendCdnRequest failed. Retried ${tryCount} times.`)
Expand Down Expand Up @@ -426,7 +428,7 @@ export class CDNManager {
let dataLen = 0

if (response.statusCode !== 200) {
reject(`sendCdnRequest failed, status code: ${response.statusCode}, status message: ${response.statusMessage}`)
reject(new Error(`sendCdnRequest failed, status code: ${response.statusCode}, status message: ${response.statusMessage}`))
}
response.on('data', (chunk: any) => {
rawData.push(chunk)
Expand All @@ -448,10 +450,11 @@ export class CDNManager {
})
req.on('timeout', () => {
req.abort()
reject(`TIMEOUT`)
reject(new Error(`TIMEOUT`))
})
req.write(data)
req.end()
})
}

}
Loading

0 comments on commit 2a6b510

Please sign in to comment.