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


TypeScript cuid.default方法代碼示例

本文整理匯總了TypeScript中cuid.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript cuid.default方法的具體用法?TypeScript cuid.default怎麽用?TypeScript cuid.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cuid的用法示例。


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

示例1: async

export default async (event, context, callback): Promise<void> => {
  const url = createPresignedURL()
  const channelId = cuid()

  callback(null, {
    statusCode: 200,
    body: JSON.stringify({ url, channelId }),
  })
}
開發者ID:13768324554,項目名稱:chromeless,代碼行數:9,代碼來源:session.ts

示例2: returnScreenshot

  // Returns the S3 url or local file path
  async returnScreenshot(): Promise<string> {
    const data = await screenshot(this.client)

    // check if S3 configured
    if (process.env['CHROMELESS_S3_BUCKET_NAME'] && process.env['CHROMELESS_S3_BUCKET_URL']) {
      const s3Path = `${cuid()}.png`
      const s3 = new AWS.S3()
      await s3.putObject({
        Bucket: process.env['CHROMELESS_S3_BUCKET_NAME'],
        Key: s3Path,
        ContentType: 'image/png',
        ACL: 'public-read',
        Body: new Buffer(data, 'base64'),
      }).promise()

      return `https://${process.env['CHROMELESS_S3_BUCKET_URL']}/${s3Path}`
    }

    // write to `/tmp` instead
    else {
      const filePath = `/tmp/${cuid()}.png`
      fs.writeFileSync(filePath, Buffer.from(data, 'base64'))

      return filePath
    }
  }
開發者ID:KhaledNobani,項目名稱:chromeless,代碼行數:27,代碼來源:local-runtime.ts

示例3: returnPdf

  // Returns the S3 url or local file path
  async returnPdf(options?: PdfOptions): Promise<string> {
    const data = await pdf(this.client, options)

    // check if S3 configured
    if (
      process.env['CHROMELESS_S3_BUCKET_NAME'] &&
      process.env['CHROMELESS_S3_BUCKET_URL']
    ) {
      const s3Path = `${cuid()}.pdf`
      const s3 = new AWS.S3()
      await s3
        .putObject({
          Bucket: process.env['CHROMELESS_S3_BUCKET_NAME'],
          Key: s3Path,
          ContentType: 'application/pdf',
          ACL: 'public-read',
          Body: new Buffer(data, 'base64'),
        })
        .promise()

      return `https://${process.env['CHROMELESS_S3_BUCKET_URL']}/${s3Path}`
    } else {
      // write to `${os.tmpdir()}` instead
      const filePath = path.join(os.tmpdir(), `${cuid()}.pdf`)
      fs.writeFileSync(filePath, Buffer.from(data, 'base64'))

      return filePath
    }
  }
開發者ID:xw616525957,項目名稱:chromeless,代碼行數:30,代碼來源:local-runtime.ts

示例4: writeToFile

export function writeToFile(
  data: string,
  extension: string,
  filePathOverride: string,
): string {
  const filePath =
    filePathOverride || path.join(os.tmpdir(), `${cuid()}.${extension}`)
  fs.writeFileSync(filePath, Buffer.from(data, 'base64'))
  return filePath
}
開發者ID:13768324554,項目名稱:chromeless,代碼行數:10,代碼來源:util.ts

示例5: Error

export async function uploadToS3(data: string, contentType: string): Promise<string> {
  const s3ContentType = s3ContentTypes[contentType]
  if (!s3ContentType) {
    throw new Error(`Unknown S3 Content type ${contentType}`)
  }
  const s3Path = `${getS3ObjectKeyPrefix()}${cuid()}.${s3ContentType.extension}`
  const s3 = new AWS.S3()
  await s3
        .putObject({
          Bucket: getS3BucketName(),
          Key: s3Path,
          ContentType: contentType,
          ACL: 'public-read',
          Body: Buffer.from(data, 'base64'),
        })
        .promise()

  return `https://${getS3BucketUrl()}/${s3Path}`
}
開發者ID:nylen,項目名稱:chromeless,代碼行數:19,代碼來源:util.ts

示例6:

const getPingUrl = (region: string) => `${getDynamoUrl(region)}/ping?x=${cuid()}`
開發者ID:sadeeqaji,項目名稱:graphcool-cli,代碼行數:1,代碼來源:ping.ts


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