Parcourir la source

refactor 使用 Buffer.from 替换 new Buffer

tumobi il y a 7 ans
Parent
commit
4143f00f52
3 fichiers modifiés avec 6 ajouts et 6 suppressions
  1. 2 2
      src/api/controller/comment.js
  2. 1 1
      src/api/controller/goods.js
  3. 3 3
      src/api/service/weixin.js

+ 2 - 2
src/api/controller/comment.js

@@ -15,7 +15,7 @@ module.exports = class extends Base {
     const typeId = this.post('typeId');
     const valueId = this.post('valueId');
     const content = this.post('content');
-    const buffer = new Buffer(content);
+    const buffer = Buffer.from(content);
     const insertId = await this.model('comment').add({
       type_id: typeId,
       value_id: valueId,
@@ -79,7 +79,7 @@ module.exports = class extends Base {
     const commentList = [];
     for (const commentItem of comments.data) {
       const comment = {};
-      comment.content = new Buffer(commentItem.content, 'base64').toString();
+      comment.content = Buffer.from(commentItem.content, 'base64').toString();
       comment.type_id = commentItem.type_id;
       comment.value_id = commentItem.value_id;
       comment.id = commentItem.id;

+ 1 - 1
src/api/controller/goods.js

@@ -41,7 +41,7 @@ module.exports = class extends Base {
     if (!think.isEmpty(hotComment)) {
       const commentUser = await this.model('user').field(['nickname', 'username', 'avatar']).where({id: hotComment.user_id}).find();
       commentInfo = {
-        content: new Buffer(hotComment.content, 'base64').toString(),
+        content: Buffer.from(hotComment.content, 'base64').toString(),
         add_time: think.datetime(new Date(hotComment.add_time * 1000)),
         nickname: commentUser.nickname,
         avatar: commentUser.avatar,

+ 3 - 3
src/api/service/weixin.js

@@ -11,9 +11,9 @@ module.exports = class extends think.Service {
    */
   async decryptUserInfoData(sessionKey, encryptedData, iv) {
     // base64 decode
-    const _sessionKey = new Buffer(sessionKey, 'base64');
-    encryptedData = new Buffer(encryptedData, 'base64');
-    iv = new Buffer(iv, 'base64');
+    const _sessionKey = Buffer.from(sessionKey, 'base64');
+    encryptedData = Buffer.from(encryptedData, 'base64');
+    iv = Buffer.from(iv, 'base64');
     let decoded = '';
     try {
       // 解密