firebase - Firebase Cloud Functions 等待变量
问题描述
我想将 img_thumb_url 写入 firebase 数据库。在 func1A 中,我在下面编写的代码我希望当那些全局变量 room 和 msg_key 不为空时它可以突破 while 循环,但我发现它始终未定义,尽管当 func2B 成功触发时这些变量用字符串值定义。
...
while(1){
if(room!=null && msg_key!=null){
console.log('room is ', room, '. msg_key is ', msg_key);
console.log('break from the loop');
break;
}
}
admin.initializeApp();
return admin.database().ref('/msgs/' + room + '/chat/' + msg_key + '/attachment/photo/thumbnail/url2').set(img_thumb_url);
})
但是 ' '/msgs/' + room + '/chat/' + msg_key + '/attachment/photo/thumbnail/url2 ' 上面的路径取决于从其他函数 func2B 检索到的变量 room 和 msg_key ,
exports.func2B = functions.database.ref('/msgs/{roomName}/chat/{pushid}')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const msg = snapshot.val();
if (msg.attachPhotoUrl == null) {
console.log('No photo attachment found');
return null;
}
if (msg_key != null) {
console.log('msg_key no longer null');
return null;
}
console.log('writing url2 for thumbnail in firebase database...');
msg_key = msg.key;
room = msg.roomName;
console.log('room is ',room);
console.log('msg_key is ',msg_key);
console.log('img_thumb_url: ',img_thumb_url);
return ....
});
我不确定这是否是正确的方法,但我不认为它这么简单。请帮助我如何解决。如何将 func2B 中的赋值变量 room 和 msg_key 获取到 func1A?
解决方案
推荐阅读
- mysql - 如何获取列中元素的 id 和数量,即使它们在 SQL 中为 0
- microsoft-graph-api - 更新 OneNote 页面上的数据错误,“此流不支持超时”
- richfaces - 比较值数据表 JSF 1.2
- amazon-web-services - AWS S3 cli 不适用于端点 URL
- pandas - Boto3 s3 选择 CSV 到 Pandas Dataframe-- 麻烦定界
- google-cloud-platform - GCP 服务 ssh 并在 GCE 中的 10 个虚拟机上运行脚本,而无需使用堡垒 VM
- amazon-web-services - 如何正确格式化此 YAML 代码段?
- vb.net - 在 AppStream 上为 WinForm 应用程序引用“主文件夹”的最佳方式
- mysql - 未通过 Visual Studio 数据源向导导入的外键约束
- python - 如何更改列表和总和的输出?