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


TypeScript FileBox.fromBase64方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: contactQrcode

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

    if (contactId !== this.selfId()) {
      throw new Error('can not set avatar for others')
    }
    if (!this.padchatManager) {
      throw new Error('no padchat manager')
    }

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

    const contactPayload = await this.contactPayload(contactId)
    const contactName    = contactPayload.alias || contactPayload.name || contactPayload.id
    const fileBox        = FileBox.fromBase64(base64, `${contactName}.jpg`)

    const qrcode = await fileBoxToQrcode(fileBox)

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

示例6: messageFile

 /**
  *
  * Message
  *
  */
 public async messageFile(id: string): Promise<FileBox> {
   return FileBox.fromBase64(
     'cRH9qeL3XyVnaXJkppBuH20tf5JlcG9uFX1lL2IvdHRRRS9kMMQxOPLKNYIzQQ==',
     'mock-file' + id + '.txt',
   )
 }
开发者ID:miggame,项目名称:wechaty,代码行数:11,代码来源:puppet-mock.ts


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