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