使用 Firebase 进行服务器端计算

IT技术 javascript firebase
2021-02-08 12:35:07

给定的起始日期/时间和持续时间,我怎样才能使服务器侧计算,其确定是否有物体"finished""in progress""upcoming"

--Show
  --duration: "144"
  --startDate: "2015-11-10"
  --startTime: "14:00"
  --status: "?"

客户端 javascript 来确定节目是否已经开始:

// if negative, then show hasn't started yet
var time = (-(startdate.getTime() - currentdate.getTime()) / 1000 / 60); 

客户端 javascript 以确定节目是否已完成运行:

// if negative, then show has finished
var timeLeft = channelDuration - timerStartTime;
2个回答

无法在 Firebase 上运行您自己的服务器端代码。看:

但是您可以存储服务器端时间戳,这似乎是您想要做的:

ref.child('Show/startTimestamp').set(Firebase.ServerValue.TIMESTAMP);

然后,您可以获得尚未开始的节目:

var shows = ref.child('Shows');
ref.orderByChild('startTimeStamp').startAt(Date.now()).on(...
嘿弗兰克,将来有机会添加这些功能吗?
2021-04-14 12:35:07

对于路过的人,我认为现在 Firebase 允许您通过Cloud Function. 对于这种情况,您可以创建一个函数,该函数status在将数据添加到您的数据库时通过其他参数来确定状态。

请结帐

https://firebase.google.com/docs/functions/