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


TypeScript firebase-functions.pubsub类代码示例

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


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

示例1: require

'use strict';

import * as functions from 'firebase-functions';
const loggingClient = require('@google-cloud/logging');

import { runInDebugContext } from 'vm';

// create the Stackdriver Logging client
const logging = new loggingClient({
  projectId: process.env.GCLOUD_PROJECT,
});

// start cloud function

exports.deviceLog =
  functions.pubsub.topic('device-logs').onPublish((message) => {
    const log = logging.log('device-logs');
    const metadata = {
      // Set the Cloud IoT Device you are writing a log for
      // you extract the required device info from the PubSub attributes
      resource: {
        type: 'cloudiot_device',
        labels: {
          project_id: message.attributes.projectId,
          device_num_id: message.attributes.deviceNumId,
          device_registry_id: message.attributes.deviceRegistryId,
          location: message.attributes.location,
        }
      },
      labels: {
        // note device_id is not part of the monitored resource, but you can
开发者ID:ajbisht,项目名称:community,代码行数:31,代码来源:index.ts

示例2: pub

    const okUrl =
      thread_ts ||
      (text && text.includes('fireship.io')) ||
      subtype === 'message_deleted';

    // If OK, publish data
    if (okType && okUrl) {
      await pub(body);
      res.sendStatus(200);
    }
  }
);

// @Question Bot https://fireship.io/foo hello
// Creates and updates slack threads to that mention the bot
export const recordMessage = functions.pubsub
  .topic(PS_TOPIC)
  .onPublish(async (message, context) => {
    console.log(message.json);
    const { event, command } = message.json;

    if (event) {
      console.log(event);
      return await handleBotEvent(event);
    }

    if (command) {
      return handleSlackCommand(message.json);
    }
  });

/// HELPERS ///
开发者ID:janjachacz,项目名称:fireship.io,代码行数:32,代码来源:slack.ts

示例3: next

});

// Create an error handler.
app.use((err, req, res, next) => {
  if (res.headersSent) {
    return next(err);
  }
  if (res.statusCode === 200) {
    res.statusMessage = err.message || err;
    res.status(400);
  }
  res.json({ error: err.message || err });
});

export const api = functions.https.onRequest(app);
export const grades = functions.pubsub.topic('grades').onPublish(event => {
  const { chicagoId, record } = event.data.json;
  const basis = [record['term'], record['course'], record['section']].join();
  const key = crypto
    .pbkdf2Sync(basis, chicagoId, 2000000, 20, 'sha512')
    .toString('base64')
    .replace(/=/g, '')
    .replace(/\+/g, '-')
    .replace(/\//g, '_');
  return admin
    .firestore()
    .collection('institutions')
    .doc('uchicago')
    .collection('grades')
    .doc(key)
    .set({
开发者ID:kevmo314,项目名称:canigraduate.uchicago.edu,代码行数:31,代码来源:index.ts

示例4: imageDeleteHandler

    await imageDeleteHandler(name, admin.database())
    return
  }

  if (resourceState === 'exists' && metageneration > 1) {
    // This is a metadata change event.
    return
  }

  console.log('New image created. Name:', name)
  await imageCreateHandler(name, metadata, admin.database())
})

/**
 * This function will be triggered hourly and remove old images from
 * Firebase storage.
 */
export const imagesPurger = functions.pubsub.topic('hourly-tick').onPublish(async event => {
  const files = await listOldImages(admin.database())
  console.log('Going to remove following files:', files)
  await storageCleaner(files, storage())
})

/**
 * This function will be triggered hourly and remove old logs from Firebase realtime database
 */
export const logsPurger = functions.pubsub.topic('hourly-tick').onPublish(async event => {
  const logs = await listOldLogs(admin.database())
  await logsCleaner(logs)
})
开发者ID:jsse-2017-ph23,项目名称:firebase-functions,代码行数:30,代码来源:index.ts


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