Tag: google cloud functions

将巨大的Firebase数据库更新为交易

我正在使用Firebase数据库为iOS应用程序和维护巨大的数据库。 对于一些事件,我使用云function来同时更新几个兄弟节点作为事务。 但是,一些节点包含巨大的子节点(可能是一百万)。 在云function方面是否扩大了大量logging?

Firebase的云端function – 移除最老的孩子

我有一个onWrite云function设置为侦听当用户更新的东西。 我想删除最大的孩子,如果有超过3,这是我在: exports.removeOld = functions.database.ref('/users/{uid}/media').onWrite(event => { const uid = event.params.uid if(event.data.numChildren() > 3) { //Remove Oldest child… } }) 每个孩子都有一个"timestamp"键。 { "users" : { "jKAWX7v9dSOsJtatyHHXPQ3MO193" : { "media" : { "-Kq2_NvqCXCg_ogVRvA" : { "date" : 1.501151203274347E9, "title" : "Something…" }, "-Kq2_V3t_kws3vlAt6B" : { "date" : 1.501151232526373E9, "title" : "Hello World.." } "-Kq2_V3t_kws3B6B" : { […]

尝试通过Firebase云端function发送通知(Android)后出现错误

我是Firebase和nodejs的新手。 我正尝试使用Firebase云端函数从一台设备向另一台设备发送通知。 这是发送通知的node.js代码: var functions = require('firebase-functions'); var admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotification = functions.database.ref('/sendNotification/{notificationId}') .onWrite(event => { var regToken="fYRweeL8cic:APA91bH6Q_gyKKrLL…"; // Grab the current value of what was written to the Realtime Database. var eventSnapshot = event.data; var payload = { data: { title: eventSnapshot.child("title").val() } }; // Set the message as high priority and […]

上传到Firebase存储时,如何使用Cloud Functions for FIrebase获取mp3文件的持续时间

我正在为一个舞蹈应用程序build立一个音乐库。 目前我有一个云端function,当一个mp3file upload到Firebase存储时自动创build一个数据库实例,我仍然需要以某种方式获取该mp3文件的持续时间,并将该信息存储在数据库中。 我是新来的JavaScript和第一次做node.js,一些来源指向使用MP3元数据,我没有经验玩任何一个。 一些帮助将不胜感激。

从Firebasefunction访问Google Site Verification API

我正在尝试使用Node.js的Firebase函数使用Google Site Verification API 。 Github的google-api-nodejs-client存储库中提供的READMEbuild议使用默认的应用程序方法,而不是手动创buildOAuth2客户端,JWT客户端或计算客户端。 我写了下面的例子,我尝试在本地(模拟function环境)上运行,并在Firebasefunction上远程运行: const google = require('googleapis'); google.auth.getApplicationDefault(function (err, authClient, projectId) { if (err) { console.log('Authentication failed because of ', err); return; } if (authClient.createScopedRequired && authClient.createScopedRequired()) { authClient = authClient.createScoped([ 'https://www.googleapis.com/auth/siteverification' ]); } const siteVerification = google.siteVerification({ version: 'v1', auth: authClient }); siteVerification.webResource.get({ id: 'test.com' }, {}, function (err, data) […]

试图访问实时数据库时,Firebase Node.jspipe理SDK超时

使用带有Firebase函数的Node.js admin SDK每当我尝试访问实时数据库时,都会收到一个超时值。 只有在本地testing函数( firebase serve –only functions,hosting仅适用firebase serve –only functions,hosting )以及使用functions.config().firebase firebase serve –only functions,hosting初始化默认应用程序时才会发生这种情况。 这是一个刚刚发生在几天前的新行为。 但是,如果我尝试使用serviceAccount.json文件初始化默认应用程序,则一切正常。 我正在使用firebase-admin版本4.2.1和firebase firebase-functions版本0.5.9 。 我写了一个简单的http triggered函数,由于超时而失败: const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); const db = admin.database(); exports.testDbConnection = functions.https.onRequest((req, res) => { return admin.database().ref().once('value') .then(function(snapshot) { res.json(snapshot); }).catch(function(error) { res.json(error); }); });

Google Cloud Function不会终止过去的最大function持续时间

在“时间限制”部分的Google Cloud Functions文档中,它表示最长持续时间应该是540秒。 之后,云端function应该终止。 “最大function持续时间 – 一个function在被强行终止之前可以运行的最长时间 – 540秒 ” 我已经对http-triggers进行了一些testing,并注意到如果在6秒内没有发回响应,函数将终止。 我还运行了另一个testing,立即发送回应,并每分钟asynchronouslogging一条消息。 目前40分钟后,它仍然在logging消息。 这里是代码片段: function recursiveCallback (n) { console.log(`MarkTest: Callback Pass ${n}`); setTimeout(function () { recursiveCallback(n + 1); }, 1000 * 60); } exports.test_func = function (req, resp, callback) { console.log('Sending Response. response'); resp.send(''); console.log('Response Sent.'); console.log('Starting Async Polling'); recursiveCallback(0); console.log('test_func End') }; 这是一个错误,还是这个故意?

如何发送通知给所有用户,除了android中的发件人使用节点js的firebase函数

我有一个firebase云function发送通知的主题。 问题是,它发送给所有用户,包括发件人,而我不希望它发送给发件人。 请不要提供订阅和取消订阅示例,因为我无法理解此解决scheme。 请帮忙? const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.pushNotification = functions.database.ref('/messages/{pushId}').onWrite( event => { console.log('Push notification event triggered'); var message1 = event.data.val(); if (!message1) { return; } var valueObject = message1.messageText; console.log('Push notification event triggered '+valueObject); const payload = { notification: { title:'Chat app', body: valueObject, }, }; const options […]

Firebase函数通知

我正尝试使用FCM服务发送简单的推送通知。 每当我的function被呼叫,我想收到一个通知,我希望我的手机振铃和振动。 我有两个问题: 当我收到通知时,我得到5个,而不是一个。 第二个问题是,如果我收到通知时手机的声音被激活,手机不会振动或振铃,但如果处于振动模式,则会在收到通知时振动。 任何想法如何解决这个问题? 谢谢! 'use strict' const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); exports.sendNotification = functions.database.ref('/Alerts/{email_encoded}/{alert_id}').onWrite(event => { const email_encoded = event.params.email_encoded; const alert_id = event.params.alert_id; const deviceToken = admin.database().ref(`/Users/${email_encoded}/device_token`).once('value'); deviceToken.then(result => { const token_id = result.val(); const payload = { notification: { title: "Alert", body: "alert triggered", icon: "default", […]

通过云端function检索Firebase存储图像链接

如何通过云端function检索Firebase中存储的图片的下载链接? 我已经尝试了各种各样的变化,包括下一个: exports.getImgs = functions.https.onRequest((req, res) => { var storage = require('@google-cloud/storage')(); var storageRef = storage.ref; console.log(storageRef); storageRef.child('users/user1/avatar.jpg').getDownloadURL().then(function(url) { }); });