當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。