Tag: firebase database

当每个函数结束时需要执行函数

我有节点js / firebase中的这个代码: ref.child("recipts").once("value", function(usersSnap) { usersSnap.forEach(function(reciptsSnap) { reciptsSnap.forEach(function(reciptSnap) { reciptSnap.ref.child("last_recipt").once("value", function(b) { b.forEach(function(c) { //Here I fill some "product" object }); }); reciptSnap.forEach(function(b) { //Here I fill some "product" object }); }); }); }); 当“reciptSnap”forEachs完成时,我需要执行一个函数。 我怎样才能做到这一点,我尝试使用variablesi ++和i–但只适用于每个迭代。 我调用的函数是用forEachs循环中的填充数据操纵我创build的产品对象。

Google云端存储的Firebase云端functionAPI错误

随着Firebase云端function的推出,我们正在考虑将当前的一些node.js服务器端代码移到云端function。 我遇到的一个问题是将文件从GCS存储区下载到磁盘上的临时文件,然后通过电子邮件将其作为附件(使用mailgun-js)发送。 导致我悲伤的那段代码是: return mkdirp(tempLocalDir).then(() => { const bucket = gcs.bucket(gcsBucket); const tempFilePath = tempLocalDir + gcsFile; return bucket.file(gcsFile).download({ destination: tempFilePath }).then(() => { console.log('File downloaded locally to', tempFilePath); var messageSubject = "Test"; var messageBody = "Test with attach"; var mailgunData = { from: , to: agentEmail, subject: messageSubject, html: messageBody, attachment: tempFilePath, }; mailgunAgent.messages().send(mailgunData, […]

在每次执行中发送多个推送通知的Firebase函数中返回*的内容?

我正在使用单个的Firebasefunction向我的Android用户发送多个推送通知。 每个通知的详细信息都将写入我的Firebase数据库中的date和时间。 我使用cron通过http请求来触发此Firebasefunction。 我的问题是,Firebase函数应该如何返回以完成所有Firebase节点(代表通知)的循环并完成发送所有通知? 这是我现在所拥有的。 它在发送第一个通知之后退出。 我想要的是完成查看所有Firebase子节点并为每个节点发送通知。 我不明白Promise的想法足以找出在多个推送通知的情况下返回什么。 这也没有帮助,我几乎完全忘记了如何写javascript。 exports.sendHourlyNotifications = functions.https.onRequest((req, res) => { const dateStr = req.query.date; const hourStr = req.query.hour; console.log('sendHourlyNotifications', 'date: ' + dateStr + " hour: " + hourStr); const parentRef = admin.database().ref(); const notifRef = parentRef.child('all-notifications'); const hourRef = notifRef.child(dateStr).child(hourStr); return hourRef.once('value').then(snapshot => { const updates = {}; snapshot.forEach(function(childSnapshot) […]

Firebase的Cloud Functions中将对象从一个节点复制到另一个节点

我正在使用Firebase的云端函数,而且我似乎是一个非常基本的操作。 如果有人添加post,他会写入/posts/ 。 我想要使​​用与初始文章中使用的相同的密钥将该post的一部分保存在不同的节点(称为public-posts或private-postspost)下。 我的代码看起来像这样 const functions = require('firebase-functions'); exports.copyPost = functions.database .ref('/posts/{pushId}') .onWrite(event => { const post = event.data.val(); const smallPost = (({ name, descr }) => ({ name, descr }))(post); if (post.isPublic) { return functions.database.ref('/public-posts/' + event.params.pushId) .set(smallPost); } else { return functions.database.ref('/private-posts/' + event.params.pushId) .set(smallPost); } }) 我得到的错误信息是: functions.database.ref(…).set不是一个函数 。 我究竟做错了什么?

如何检查服务器上的客户端进行身份validation?

情况: 目前,我通过URL传递UID到服务器。 然后我使用UID检查数据库中是否存在该UID: 码: router.get("/profile/:uid", function(req, res, next){ var uid = req.params.uid; var userRef = admin.database().ref("users/"+uid); userRef.once('value', function(snapshot){ if (snapshot != null) { 问题: 这意味着任何人都可以访问任何人的个人资料通过构build一个url并将其粘贴到search栏中,并包括该用户的UID。 题: 如何检查用户是否在服务器上进行了身份validation,而没有出现这种安全漏洞?

如何通过Firebase Admin与代理连接到Firebase?

目前,我正在使用Firebase Admin SDK在NodeJS服务器端应用程序中连接Firebase数据库。 但我没有find通过代理设置连接Firebase的选项,或者它可以检测到我的系统HTTP_PROXY环境variables。 当我通过node index.js运行节点脚本,并得到一些像这样的超时消息(我知道在我的工作networking中,我无法直接连接到Firebase)。 Error: Credential implementation provided to initializeApp() via the "credential " property failed to fetch a valid Google OAuth2 access token with the following error: "connect ETIMEDOUT 216.58.200.237:443". at ….erver\node_modules\firebase-adm in\lib\firebase-app.js:74:23 at process._tickCallback (internal/process/next_tick.js:103:7) 我也使用浏览器通过代理访问Firebase控制台,它的工作原理。 但是如何在NodeJS服务器端脚本中解决这个问题呢?

有没有办法缩短string唯一ID的数组,同时仍然确保独特性?

我有一个来自Firebase数据库的string唯一ID数组,其中一个如下所示: QXgZI3JB72Zf1qzeawIdxHSsPa62 我想把这些ID打印给用户,但是首先我想首先把ID缩短到最less7个字符左右,但是如果两个缩短的ID最终变成相等的话,那么这个ID就会超过这个长度。 这样,如果有人想要引用一个特定的ID,他们可以使用缩短的版本,而不会意外地指多个东西。 有什么办法可以做到这一点? 为了更好地了解我在说什么,请参阅git命令git rev-parse ( docs ),该文件具有–short标志,它将一个提交散列切割成至less7个字符长(但将允许它如果不再是独一无二的,则可以更长一些): 而不是输出对象名称的完整SHA-1值,尝试将它们缩写为更短的唯一名称。

节点工作人员崩溃与“火警警告”

我有一个在节点上运行的firebase-worker( https://github.com/firebase/firebase-queue )。 我有一个工作需要做的特定任务的大量积压,但通常任务失败,然后工作人员停止以下错误消息: Oct 13 20:34:57 Worker app/low_priority_worker.1: FIREBASE WARNING: transaction at /low_priority_queue/tasks/-KTupoITHgT10u5uasQq failed: disconnect Oct 13 20:34:57 Worker app/low_priority_worker.1: FIREBASE WARNING: transaction at /user_dashboard/-JmteP57yEdeDFzAyv-p/1476403200000/views/-KTuI5464YGfBx9KEmNs failed: disconnect 工作人员正在执行的任务是在Firebasepath上增加一个值: # Increment comment amount on listing incrementDashboardListingTypeAmountPromise = BaseHelper.firebaseDatabase.ref("user_dashboard").child(@data.seller_id).child("#{Date.create().setUTC(true).beginningOfDay().format("{x}")}").child(@data.type).child(@data.listing_id).transaction (currentValue) -> (currentValue || 0) + 1 # Promise callback Promise.all([incrementDashboardListingTypeAmountPromise].compact()).then (results) => # Execute callback callback() […]

对高度请求的队列进行Firebase优化

基于firebase的游戏,其中每个用户在同一个waitingList上推送一个请求,以便一个nodeJS服务器为每两个等待的玩家分别准备一个循环游戏。 我在nodeJS上使用Firebase JS v3: var ref = firebase.database().ref(); //this is where we populate rounds var gamesRef = ref.child('games'); //users path var usersRef = ref.child('users'); //waiting queue var waitingRef = ref.child('waitingList'); //listen for each new queued user waitingRef.on('child_added', function(snap){ waitingRef.transaction(function(waitingList){ if(waitingList !== null){ var keys = Object.keys(waitingList); //take two players if(keys.length >= 2){ //prepare a new […]

如何使用Cloud Functions for Firebase向特定用户发送推送通知

我使用Firebase作为我的Android应用程序的后端,并且对于使用Firebase的云端函数非常新,我想知道如何在发生事件时发送特定用户的推送通知。 例如,如果在数据库的adminName节点上发生写入时,如何在下面的代码中使用uId向用户发送推送通知: exports.sendNotification = functions.database.ref('/users/{uId}/groups/{adminName}') .onWrite(event => { // Grab the current value of what was written to the Realtime Database. var eventSnapshot = event.data; var str1 = "Author is "; var str = str1.concat(eventSnapshot.child("author").val()); console.log(str); var topic = "android"; var payload = { data: { title: eventSnapshot.child("title").val(), author: eventSnapshot.child("author").val() } }; // Send a […]