本文整理汇总了TypeScript中firebase-functions.pubsub.topic方法的典型用法代码示例。如果您正苦于以下问题:TypeScript pubsub.topic方法的具体用法?TypeScript pubsub.topic怎么用?TypeScript pubsub.topic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类firebase-functions.pubsub
的用法示例。
在下文中一共展示了pubsub.topic方法的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
示例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 ///
示例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({
示例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)
})