當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript qrcode.toDataURL函數代碼示例

本文整理匯總了TypeScript中qrcode.toDataURL函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript toDataURL函數的具體用法?TypeScript toDataURL怎麽用?TypeScript toDataURL使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了toDataURL函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
	// Get 'password' parameter
	const [password, passwordErr] = $.str.get(params.password);
	if (passwordErr) return rej('invalid password param');

	// Compare password
	const same = await bcrypt.compare(password, user.password);

	if (!same) {
		return rej('incorrect password');
	}

	// Generate user's secret key
	const secret = speakeasy.generateSecret({
		length: 32
	});

	await User.update(user._id, {
		$set: {
			twoFactorTempSecret: secret.base32
		}
	});

	// Get the data URL of the authenticator URL
	QRCode.toDataURL(speakeasy.otpauthURL({
		secret: secret.base32,
		encoding: 'base32',
		label: user.username,
		issuer: config.host
	}), (err, data_url) => {
		res({
			qr: data_url,
			secret: secret.base32,
			label: user.username,
			issuer: config.host
		});
	});
});
開發者ID:ha-dai,項目名稱:Misskey,代碼行數:38,代碼來源:register.ts

示例2: convertObjectToQRCodeDataURL

export async function convertObjectToQRCodeDataURL(object: any): Promise<string> {
  const string = JSON.stringify(object);

  return await QRCode.toDataURL(string);
}
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:5,代碼來源:string-encoding.ts

示例3: function

/// <reference path="qrcode.d.ts" />

import * as QRCode from 'qrcode';

QRCode.toDataURL('i am a pony!', function (err, url) {
    console.log(url);
});

var qrcodedraw = new QRCodeLib.QRCodeDraw();

qrcodedraw.draw(document.getElementById('test') as HTMLCanvasElement, "this text will be in the code!", function (error, canvas) {
    if (error) {
        return console.log('Error =( ', error);
    }
    console.log('success!');
});
開發者ID:CNManning,項目名稱:DefinitelyTyped,代碼行數:16,代碼來源:qrcode-tests.ts

示例4:

import * as QRCode from 'qrcode';

const canvas = document.getElementById('canvas') as HTMLCanvasElement;

QRCode.toCanvas(canvas, 'sample text', (error) => {
    if (error) console.error(error);
    console.log('success!');
});

QRCode.toDataURL('I am a pony!', (err, url) => {
    console.log(url);
});

QRCode.toDataURL('some text', { errorCorrectionLevel: 'H' }, (err, url) => {
    console.log(url);
});

QRCode.toDataURL('some text', { version: 2 }, (err, url) => {
    console.log(url);
});

QRCode.toDataURL([
    { data: 'ABCDEFG', mode: 'alphanumeric' },
    { data: '0123456', mode: 'numeric' }
], (err, url) => {
    console.log(url);
});

QRCode.toCanvas('text', { errorCorrectionLevel: 'H' }, (err, canvas) => {
    if (err) throw err;
});
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:qrcode-tests.ts

示例5: async

const buildRenderParams = async (user?: User, cards?: any[], data?: any) => ({
  site: {
    title: siteTitle,
    admin: adminEmail,
    source: sourceCodeUrl,
    reg: openRegister,
  },
  user: user
    ? {
        ...user,
        ss: {
          ...shadowsocks,
          port: user.connPort,
          encryption: user.connEnc,
          password: user.connPassword,
          uri: new Buffer(
            `${user.connEnc}:${user.connPassword}@${shadowsocks.host}:${
              user.connPort
            }`
          ).toString("base64"),
          qrcode: await makeQrCode(
            "ss://" +
              Buffer.from(
                `${user.connEnc}:${user.connPassword}@${shadowsocks.host}:${
                  user.connPort
                }`
              ).toString("base64")
          ),
        },
        vmess: {
          ...vmess,
          webSocket: {
            ...vmess.webSocket,
            headersJson: JSON.stringify(vmess.webSocket.headers),
          },
          tcpHeaderJson: JSON.stringify(vmess.tcp.header),
          remark: siteTitle,
          id: user.vmessUid,
          aid: user.vmessAlterId,
          link: {
            android: Buffer.from(
              JSON.stringify({
                add: proxyHost,
                aid: user.vmessAlterId,
                host: `${vmess.webSocket.path};${proxyHost}`,
                id: user.vmessUid,
                net: vmess.network,
                port: vmess.port,
                ps: siteTitle,
                tls: vmess.tls.status === "off" ? "" : "tls",
                type:
                  vmess.network === "tcp"
                    ? vmess.tcp.header.type
                    : vmess.network === "kcp"
                    ? vmess.kcp.header.type
                    : "none",
              })
            ).toString("base64"),
            win: Buffer.from(
              JSON.stringify({
                add: proxyHost,
                aid: user.vmessAlterId,
                host: `${vmess.webSocket.path};${proxyHost}`,
                id: user.vmessUid,
                net: vmess.network,
                port: vmess.port,
                ps: siteTitle,
                tls: vmess.tls.status === "off" ? "" : "tls",
                type:
                  vmess.network === "tcp"
                    ? vmess.tcp.header.type
                    : vmess.network === "kcp"
                    ? vmess.kcp.header.type
                    : "none",
              })
            ).toString("base64"),
            shadowrocket: `${Buffer.from(
              `chacha20-poly1305:${user.vmessUid}@${proxyHost}:${vmess.port}`
            ).toString("base64")}?obfsParam=${vmess.webSocket.host}&path=${
              vmess.network === "ws"
                ? vmess.webSocket.path
                : vmess.tcp.header.type
            }&obfs=${
              vmess.network === "ws"
                ? "websocket"
                : vmess.network === "tcp"
                ? vmess.tcp.header.type
                : "none"
            }&tls=${vmess.tls.status === "off" ? 0 : 1}`,
          },
          qrcode: {
            kitsunebi: await makeQrCode(
              "vmess://" +
                Buffer.from(
                  `chacha20-poly1305:${user.vmessUid}@${proxyHost}:${
                    vmess.port
                  }`
                ).toString("base64") +
                `?network=${vmess.network}` +
                (vmess.network === "ws"
//.........這裏部分代碼省略.........
開發者ID:coderfox,項目名稱:Another-SS-Panel,代碼行數:101,代碼來源:index.ts

示例6: async

const getGuide = async (user: IUser, siteName?: string): Promise<IGuide> => {
  const ssUri =
    "ss://" +
    Buffer.from(
      `${user.ss.encryption}:${user.ss.password}@${user.ss.host}:${
        user.ss.port
      }`
    ).toString("base64");
  const ssQr = await makeQrCode(ssUri);
  return {
    vmess: [
      {
        os: "Android",
        descriptions: [
          {
            title: "下载应用",
            content: "下载客户端并安装(app-universal-release.apk)。",
            links: [
              {
                name: "GitHub",
                href: "https://github.com/2dust/v2rayNG/releases",
              },
            ],
          },
          {
            title: "添加配置",
            content:
              "点击下面的按钮,按照系统提示用应用 v2rayNG 打开,并按照应用提示确认添加。",
            links: [
              {
                name: "配置",
                href:
                  "vmess://" +
                  Buffer.from(
                    JSON.stringify({
                      add: user.vmess.host,
                      aid: user.vmess.aid,
                      host: `${user.vmess.webSocket.path};${
                        user.vmess.webSocket.host
                      }`,
                      id: user.vmess.id,
                      net: user.vmess.network,
                      port: user.vmess.port,
                      ps: siteName,
                      tls: user.vmess.tls.status === "off" ? "" : "tls",
                      type:
                        user.vmess.network === "tcp"
                          ? user.vmess.tcp.header.type
                          : user.vmess.network === "kcp"
                          ? user.vmess.kcp.header.type
                          : "none",
                    })
                  ).toString("base64"),
              },
            ],
          },
          {
            title: "改善配置(可选)",
            content:
              "点击新增的配置文件右侧编辑图标,在弹出的面板内,修改「security」为「chacha20-poly1305」,点击右上角对号保存。",
          },
          {
            title: "设置路由",
            content:
              "点击右上角菜单,选择「Settings」;打开「Bypass Mainland」,(可选)打开「Enable Mux」;返回首页。",
          },
          {
            title: "启动代理",
            content:
              "点击下方纸飞机,待提示「Start Server Success」后即可开始使用网络。个别系统可能会询问权限,请一律允许。",
          },
        ],
      },
      {
        os: "iOS(Kitsunebi)",
        descriptions: [
          {
            title: "下载应用",
            content:
              "在 App Store 购买应用 Kitsunebi(¥12),或申请免费的测试版(需要挂代理访问)。",
            links: [
              {
                name: "App Store",
                href: "https://itunes.apple.com/cn/app/kitsunebi/id1275446921",
              },
              {
                name: "TestFlight",
                href:
                  "https://docs.google.com/forms/d/e/1FAIpQLSekOGRE7cXk3vBTVjlHiv6RJRXfeItZvjQCDRxyigKYq6ChmA/viewform",
              },
            ],
          },
          {
            title: "添加配置",
            content:
              "打开应用,点击左上角📷图标扫描下方二维码;移动设备可以长按保存二维码后,点击左上角📷图标,再点击右上角文件夹图标,从相册中选择二维码图片。",
            qrcode: await makeQrCode(
              "vmess://" +
                Buffer.from(
                  `chacha20-poly1305:${user.vmess.id}@${user.vmess.host}:${
//.........這裏部分代碼省略.........
開發者ID:coderfox,項目名稱:Another-SS-Panel,代碼行數:101,代碼來源:guide.ts


注:本文中的qrcode.toDataURL函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。