[英]update firebase upon cloud storage thumbnail completion
I have the following index.js that's triggered when a thumbnail is generated in cloud storage.我有以下在云存储中生成缩略图时触发的 index.js。 It seems to work fine.
它似乎工作正常。
I'd like to replace the console.log
line with code that adds a field like {"thumbnail_done":true}
to the firebase document docid
found in the script.我想用将
{"thumbnail_done":true}
之类的字段添加到脚本中找到的 firebase 文档docid
的代码替换console.log
行。 I'm not clear on how to do that.我不清楚该怎么做。
exports.thumbComplete = (event, context) => {
const fname = event.name;
let suffix = "_200x200.jpeg"
if (fname.endsWith(suffix)) {
let docid = fname.substring(0, fname.length - suffix.length);
console.log(`thumbnail processing complete: ${docid}`);
}
};
Thanks!谢谢!
Got it working with the following:得到它与以下工作:
// The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access Firestore.
const admin = require('firebase-admin');
admin.initializeApp();
exports.generateThumbnail = functions.storage.object().onFinalize(async (object) => {
const fname = object.name;
let suffix = "_200x200.jpeg"
if (fname.endsWith(suffix)) {
let docid = fname.substring(0, fname.length - suffix.length);
await admin.firestore().doc(`photo/${docid}`).update({ 'uploaded': true });
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.