Tag: google cloud functions

Firebasefunction可以在使用NodeJS从数据库中删除对象时从存储中删除文件

我是NodeJS的新手,我正在尝试为Firebase的云端函数编写下一个方法。 我正在努力实现的是: 当用户从Firebase DB中移除Photo对象时,该function应该被触发; 该代码应该从对应于Photo obj的存储中移除文件对象。 这些是我的Firebase数据库结构: 照片/ {userUID} / {} photoUID { "dateCreated": "2017-07-27T16:40:31.000000Z", "isProfilePhoto": true, "isSafe": true, "uid": "{photoUID}", "userUID": "{userUID}" } Firebase存储格式: 照片/ {userUID} / {} photoUID .PNG 和我正在使用的NodeJS代码: const functions = require('firebase-functions') const googleCloudStorage = require('@google-cloud/storage')({keyFilename: 'firebase_admin_sdk.json' }) const admin = require('firebase-admin') const vision = require('@google-cloud/vision')(); admin.initializeApp(functions.config().firebase) exports.sanitizePhoto = functions.database.ref('photos/{userUID}/{photoUID}') .onDelete(event […]

如何在Firebase的Cloud Functions中实现json对象?

我想通过将原始收据发送到App Store服务器进行validation,并使用Firebase云function获取validation回执,来validation应用购买收据中的苹果。 var jsonObject = { 'receipt-data': receiptData, password: functions.config().apple.iappassword }; var jsonData = JSON.stringify(jsonObject); var firebaseRef = '/' + fbRefHelper.getUserPaymentInfo(currentUser); let url = "https://sandbox.itunes.apple.com/verifyReceipt";//or production request.post({ headers: { 'content-type': 'application/x-www-form-urlencoded' }, url: url, body: jsonData }, function (error, response, body) { if (error) { } else { var jsonResponse = JSON.parse(body); if (jsonResponse.status === […]

存储上的Firebasefunction是否存在通配符?

我已成功使用Firebasefunction对我上传到Firebase存储的文件执行操作。 我目前想要做的是通过使用通配符访问我正在推送数据的文件夹,其实现方式与实时数据库+ Firestore相同。 但是,每当我尝试访问这些参数,他们只返回null 。 这不可能吗? 这是我的代码的一个例子: exports.generateThumbnail = functions.storage.object('user-photos/{userId}/{publicOrPrivate}').onChange(event => { const privateOrPublic = event.params.publicOrPrivate; const isPrivate = (event.params.publicOrPrivate == "private"); const userId = event.params.userId; console.log("user id and publicOrPrivate are", userId, privateOrPublic); //"user id and publicOrPrivate are undefined undefined" } 谢谢!

通过云端function访问Gmail API

我正在尝试构build一个响应Gmail邮件发送邮件的电子邮件parsing器。 我目前能够接收和parsingpubsub消息并提取historyId,但我无法validation我的请求到gmail api。 这是我到现在为止: //function defined outside the scope of the main function //used to create auth client function getAuthClient(event, callback) { var GoogleAuth = require('google-auth-library'); var authFactory = new GoogleAuth(); authFactory.getApplicationDefault(function (err, authClient) { if (err) { console.log('Unable to get application default credentials.'); callback(err); return; } // Create the oAuth scopes you need if […]

如何设置Heroku的时区

我写了一个Node.js服务器在Heroku(Global)上运行。 一切工作正常在我的本地主机,但作为Heroku的时区是UTC我的function现在运行不正确。 有人可以帮我设定一个默认的时区吗? 这是我的代码: router.get('/year/:yyear/:mmonth/:ddate/:hhours/:mminute/:sseconds/:fireTitle/:fireBody', function(req, res) { var year1 = req.params.yyear; var month1 = (req.params.mmonth)-1; var date1 = req.params.ddate; var hours1 = req.params.hhours; var minute1 = (req.params.mminute); var seconds1 = req.params.sseconds; var datetime = new Date((new Date)*1 – 1000*3600*5.5 ); var responseObject= "Your Function has been set for : "+year1+month1+date1+hours1+minute1+seconds1 +" date "+ datetime; […]

如何评分 – 限制Google云端Pub / Sub Queue

我使用Google的Pub / Sub队列来处理服务之间的消息。 一些用户连接到速率限制API。 例如,我将街道地址推送到发布/订阅主题上。 我有一个Cloudfunction,通过推送订阅该主题,并呼叫外部限速地理编码服务。 理想情况下,我的街道地址可以毫不拖延地推到话题上,话题会保留这些消息 – 以限速的方式呼叫用户。 反正有configuration这样的延迟,或消息分发速率限制? 增加Ack窗口并没有什么帮助:我已经构build了这个系统来防止长时间运行的function。

Google Firebase错误(函数返回undefined,期望Promise或value)

我正在开发使用Firebase的服务器。 我在Youtube上复制了Google Developer's Video。 它运行良好,但在日志中有一个错误: 函数返回undefined,预期为Promise或value 它说函数返回undefined ,但是我让function返回一个promise `set“ 我该如何解决这个问题? function sanitize(s) { var sanitizedText = s; console.log('sanitize params: ', sanitizedText); sanitizedText = sanitizedText.replace(/\bstupid\b/ig, "wonderful"); return sanitizedText; } exports.sanitizePost = functions.database .ref('/posts/{pushId}') .onWrite(event => { const post = event.data.val(); if (post.sanitized) return; console.log('Sanitizing new post', event.params.pushId); console.log(post); post.sanitized = true; post.title = sanitize(post.title); post.body = […]

从我之前部署的Firebase控制台获取代码

我已经在nodejs中创build了firebase函数,并将代码部署在firebase上。 该function是在创build新用户时发送电子邮件。 我现在已经丢失了代码。 我们可以从Firebase中获取代码吗?

如何使用云端函数删除文件?

当我在Firebase数据库中删除post时,我希望云function可以相应地删除post在Firebase存储中的缩略图。 我的问题是,当我试图删除缩略图我不认为我正确定位图像文件。 这是我所尝试的: const functions = require('firebase-functions') const admin = require('firebase-admin') const gcs = require('@google-cloud/storage')() exports.deletePost = functions.database.ref('Posts/{pushId}').onWrite(event => { const original = event.data.val() const previous = event.data.previous.val() const pushId = event.params.pushId if (original === null) return const filePath = 'Posts/' + pushId + 'thumbnail.jpg' const bucket = gcs.bucket('postsapp-12312') const file = bucket.file(filePath) const pr […]

如何使用私有NPM包与云function?

我正在尝试将应用切换到Firebase,并将后端传输到Firebase云端function。 此应用程序正在使用私有包( @org/name )作为依赖项。 我试过不同的解决scheme,但似乎没有工作: 传递一个NPM_TOKEN env:不可能,因为Firebase限制为小写configuration npm install模块npm install在函数目录中 使用YARN和NPM授权令牌在函数目录中创build一个.npmrc文件 它始终拒绝部署: Deploy Error: Build failed: Module @org/name not found in npm registry Firebase是否支持私人套餐?