当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript file-box.FileBox类代码示例

本文整理汇总了TypeScript中file-box.FileBox的典型用法代码示例。如果您正苦于以下问题:TypeScript FileBox类的具体用法?TypeScript FileBox怎么用?TypeScript FileBox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileBox类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: contactAvatar

  public async contactAvatar(contactId: string, file?: FileBox): Promise<void | FileBox> {
    log.verbose('PuppetPadchat', 'contactAvatar(%s%s)',
                                  contactId,
                                  file ? (', ' + file.name) : '',
                )

    /**
     * 1. set avatar for user self
     */
    if (file) {
      if (contactId !== this.selfId()) {
        throw new Error('can not set avatar for others')
      }
      if (!this.padchatManager) {
        throw new Error('no padchat manager')
      }
      await this.padchatManager.WXSetHeadImage(await file.toBase64())
      return
    }

    /**
     * 2. get avatar
     */
    const payload = await this.contactPayload(contactId)

    if (!payload.avatar) {
      throw new Error('no avatar')
    }

    const fileBox = FileBox.fromUrl(
      payload.avatar,
      `wechaty-contact-avatar-${payload.name}.jpg`,
    )
    return fileBox
  }
开发者ID:miggame,项目名称:wechaty,代码行数:35,代码来源:puppet-padchat.ts

示例2: messageFile

  /**
   *
   * Message
   *
   */
  public async messageFile(messageId: string): Promise<FileBox> {
    log.warn('PuppetPadchat', 'messageFile(%s)', messageId)

    if (!this.padchatManager) {
      throw new Error('no padchat manager')
    }

    const rawPayload = await this.messageRawPayload(messageId)
    const payload    = await this.messagePayload(messageId)

    const rawText        = JSON.stringify(rawPayload)
    const attachmentName = payload.filename || payload.id

    let result

    switch (payload.type) {
      case MessageType.Audio:
        result = await this.padchatManager.WXGetMsgVoice(rawText)
        console.log(result)
        return FileBox.fromBase64(result.voice, `${attachmentName}.slk`)

      case MessageType.Emoticon:
        result = await this.padchatManager.WXGetMsgEmoticon(rawText)
        console.log(result)
        return FileBox.fromBase64(result.image, `${attachmentName}.gif`)

      case MessageType.Image:
        result = await this.padchatManager.WXGetMsgImage(rawText)
        console.log(result)
        return FileBox.fromBase64(result.image, `${attachmentName}.jpg`)

      case MessageType.Video:
        result = await this.padchatManager.WXGetMsgVideo(rawText)
        console.log(result)
        return FileBox.fromBase64(result.video, `${attachmentName}.mp4`)

      case MessageType.Attachment:
      default:
        log.warn('PuppetPadchat', 'messageFile(%s) unsupport type: %s(%s) because it is not fully implemented yet, PR is welcome.',
                                  messageId,
                                  PadchatMessageType[rawPayload.sub_type],
                                  rawPayload.sub_type,
                )
        const base64 = 'Tm90IFN1cHBvcnRlZCBBdHRhY2htZW50IEZpbGUgVHlwZSBpbiBNZXNzYWdlLgpTZWU6IGh0dHBzOi8vZ2l0aHViLmNvbS9DaGF0aWUvd2VjaGF0eS9pc3N1ZXMvMTI0OQo='
        const filename = 'wechaty-puppet-padchat-message-attachment-' + messageId + '.txt'

        const file = FileBox.fromBase64(
          base64,
          filename,
        )

        return file
    }
  }
开发者ID:miggame,项目名称:wechaty,代码行数:59,代码来源:puppet-padchat.ts

示例3: messageSendFile

  public async messageSendFile(
    receiver : Receiver,
    file     : FileBox,
  ): Promise<void> {
    log.verbose('PuppetWechat4u', 'messageSend(%s, %s)', receiver, file)

    // room first
    const id = receiver.roomId || receiver.contactId

    if (!id) {
      throw new Error('no id')
    }

    /**
     * 通过表情MD5发送表情
     */
    // wechat4u.sendMsg({
    //   emoticonMd5: '00c801cdf69127550d93ca52c3f853ff'
    // }, ToUserName)
    //   .catch(err => {
    //     bot.emit('error', err)
    //   })

    /**
     * 以下通过上传文件发送图片,视频,附件等
     * 通用方法为入下
     * file为多种类型
     * filename必填,主要为了判断文件类型
     */
    await this.wechat4u.sendMsg({
      file     : await file.toStream(),
      filename : file.name,
    }, id)
  }
开发者ID:miggame,项目名称:wechaty,代码行数:34,代码来源:puppet-wechat4u.ts

示例4: emitLoginQrcode

  protected async emitLoginQrcode(): Promise<void> {
    log.verbose('PuppetPadchatManager', `emitLoginQrCode()`)

    if (this.loginScanQrcode) {
      throw new Error('qrcode exist')
    }

    const result = await this.WXGetQRCode()
    if (!result || !result.qr_code) {
      log.verbose('PuppetPadchatManager', `emitLoginQrCode() result not found. Call WXInitialize() and try again ...`)

      await this.WXInitialize()

      // wait 1 second and try again
      await new Promise(r => setTimeout(r, 1000))
      return await this.emitLoginQrcode()
    }

    const fileBox = FileBox.fromBase64(result.qr_code, 'qrcode.jpg')
    const qrcodeDecoded = await fileBoxToQrcode(fileBox)

    this.loginScanQrcode = qrcodeDecoded
    this.loginScanStatus = WXCheckQRCodeStatus.WaitScan

    this.emit(
      'scan',
      this.loginScanQrcode,
      this.loginScanStatus,
    )
  }
开发者ID:miggame,项目名称:wechaty,代码行数:30,代码来源:padchat-manager.ts

示例5: roomAvatar

  public async roomAvatar(roomId: string): Promise<FileBox> {
    log.verbose('PuppetMock', 'roomAvatar(%s)', roomId)

    const payload = await this.roomPayload(roomId)

    if (payload.avatar) {
      return FileBox.fromUrl(payload.avatar)
    }
    log.warn('PuppetMock', 'roomAvatar() avatar not found, use the chatie default.')
    return qrCodeForChatie()
  }
开发者ID:miggame,项目名称:wechaty,代码行数:11,代码来源:puppet-mock.ts

示例6: messageSendFile

  public async messageSendFile(
    receiver : Receiver,
    file     : FileBox,
  ): Promise<void> {
    log.verbose('PuppetPadchat', 'messageSend("%s", %s)', JSON.stringify(receiver), file)

    // Send to the Room if there's a roomId
    const id = receiver.roomId || receiver.contactId

    if (!id) {
      throw new Error('no id!')
    }

    if (!this.padchatManager) {
      throw new Error('no padchat manager')
    }

    const type = file.mimeType || path.extname(file.name)
    switch (type) {
      case '.slk':
        // 发送语音消息(微信silk格式语音)
        await this.padchatManager.WXSendVoice(
          id,
          await file.toBase64(),
          60,
        )
        break

      default:
        await this.padchatManager.WXSendImage(
          id,
          await file.toBase64(),
        )
        break
    }
  }
开发者ID:miggame,项目名称:wechaty,代码行数:36,代码来源:puppet-padchat.ts

示例7: contactAvatar

  public async contactAvatar(contactId: string, file?: FileBox): Promise<void | FileBox> {
    log.verbose('PuppetMock', 'contactAvatar(%s)', contactId)

    /**
     * 1. set
     */
    if (file) {
      return
    }

    /**
     * 2. get
     */
    const WECHATY_ICON_PNG = path.resolve('../../docs/images/wechaty-icon.png')
    return FileBox.fromFile(WECHATY_ICON_PNG)
  }
开发者ID:miggame,项目名称:wechaty,代码行数:16,代码来源:puppet-mock.ts

示例8: test

test('imageBase64ToQrCode()', async t => {
  const QRCODE_IMAGE_BASE64 = [
    'iVBORw0KGgoAAAANSUhEUgAAAMgAAADIAQMAAACXljzdAAAABlBMVEX///8AAABVwtN+AAAA',
    'CXBIWXMAAA7EAAAOxAGVKw4bAAAA7klEQVRYw+2WsQ3EIAxFjShSMgKjZLRktIzCCJQpIv7Z',
    'hCiXO/qzT/wCWXo0X3wbEw0NWVaEKM187KHW2QLZ+AhpXovfQ+J6skEWHELqBa5NEeCwR7iS',
    'V7BDzuzAiZ9eqn5IWjfWXHf7VCO5tPAM6U9AjSRideyHFn4FiuvDqV5CM9rZXuF2pZmIAjZy',
    'x4S0MDdBxEmu3TrliPf7iglPvuLlRydfU3P70UweCSK+ZYK0mUg1O4AVcv0/8itGkC7SdiTH',
    '0+Mz19oJZ4NkhhSPbIhQkQGI8u1HJzmzs7p7pzNAru2pJb6z8ykkQ0P/pheK6vjurjf7+wAA',
    'AABJRU5ErkJggg==',
  ].join('')
  const EXPECTED_QRCODE_TEXT = 'hello, world!'

  const file = FileBox.fromBase64(QRCODE_IMAGE_BASE64, 'hello.png')
  const text = await fileBoxToQrcode(file)
  t.equal(text, EXPECTED_QRCODE_TEXT, 'should decode qrcode image base64')
})
开发者ID:miggame,项目名称:wechaty,代码行数:16,代码来源:file-box-to-qrcode.spec.ts

示例9: roomQrcode

  public async roomQrcode(roomId: string): Promise<string> {
    log.verbose('PuppetPadchat', 'roomQrcode(%s)', roomId)

    const memberIdList = await this.roomMemberList(roomId)
    if (!memberIdList.includes(this.selfId())) {
      throw new Error('userSelf not in this room: ' + roomId)
    }

    const base64 = await this.padchatManager!.WXGetUserQRCode(roomId, 0)

    const roomPayload = await this.roomPayload(roomId)
    const roomName    = roomPayload.topic || roomPayload.id
    const fileBox     = FileBox.fromBase64(base64, `${roomName}-qrcode.jpg`)

    const qrcode = await fileBoxToQrcode(fileBox)

    return qrcode
  }
开发者ID:miggame,项目名称:wechaty,代码行数:18,代码来源:puppet-padchat.ts

示例10: contactAvatar

  public async contactAvatar(contactId: string, file?: FileBox): Promise<void | FileBox> {
    log.verbose('PuppetWechat4u', 'contactAvatar(%s)', contactId)

    if (file) {
      throw new Error('not supported')
    }

    const rawPayload = await this.contactRawPayload(contactId)

    const res = await this.wechat4u.getHeadImg(rawPayload.HeadImgUrl)
    /**
     * 如何获取联系人头像
     */
    return FileBox.fromStream(
      res.data,
      `${contactId}.jpg`, // FIXME
    )
  }
开发者ID:miggame,项目名称:wechaty,代码行数:18,代码来源:puppet-wechat4u.ts


注:本文中的file-box.FileBox类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。