gpt4 book ai didi

javascript - Firebase Cloud 在从之前的工作函数复制的代码中出现意外的 token ?

转载 作者:行者123 更新时间:2023-11-28 04:08:25 26 4
gpt4 key购买 nike

我想以此作为序言,说我已经向其他一些开发人员展示了这个,他们不知道出了什么问题。

我有一些 Firebase 云功能,并且所有其他功能都有效。但是,当我尝试添加另一个函数并使用与其他函数相同的代码简单地访问相同的数据库时,我得到了一个“意外的 token ”。错误。这是我的代码:

exports.activateLatestDormantGame = functions.https.onRequest((request, response) => {
var database = admin.database().ref();
var gamesDatabase = database.child('games');
var gameNum;

var gamesDatabaseQuery = gamesDatabase.orderByKey().limitToFirst(1);
gamesDatabaseQuery.once('child_added').then((latestGame) => {
gameNum = parseInt(latestGame.getKey());
gamesDatabaseQuery.off('child_added');
}).then(() => {
gamesDatabase.child(gameNum.toString()).child('isActive').set('true');
response.end();
});
});

exports.tallyVotes = functions.https.onRequest((request, response) => {
var database = admin.database().ref();

var gamesDatabaseQuery = database.child('games').orderByKey().limitToFirst(1);

gamesDatabaseQuery.once('child_added').then((latestGame) => {
return parseInt(latestGame.getKey());
}).then((latestGameKey) => {
var gameDatabaseRef = database.child('games').child(latestGameKey.toString());
var numTeams = gameDatabaseRef.child('teams').child('numTeams').val();
var votes = [];
for (team in numTeams) {
var tallyString = gameDatabaseRef.child('answers').child(team.toString()).val();
var tallyArray = tallyString.split(',');
var highestVote = 0;
for (vote in tallyArray) {
if (parseInt(vote) > highestVote) {
highestVote = parseInt(vote);
}
}
votes.push(highestVote);
}

var questionsAskedString = gamesDatabaseRef.child('questionsAsked').val();
var questionsAskedArray = questionsAskedString.split(',');
var latestQuestion = questionsAskedArray[questionsAskedArray.length - 1];

return [latestQuestion, votes, latestGameKey];
}).then(returnArray) => {
var answer = database.child('questionDatabase').child(returnArray[0]).child('answerIndex').val();
var correctTeams = [];
for (var i = 0; i < returnArray[1].length; i++) {
if (returnArray[1][i] == answer) {
correctTeams.push(i);
}
}
database.child('games').child(returnArray[2]).child('correctTeams').set(correctTeams.join(','));
response.end();
});
});

这是错误:

Error: Error occurred while parsing your function triggers.

/private/var/folders/zm/qyfsj2ms2yd0w2t748s_v16m0000gn/T/fbfn_8186jLVALtYUfzf1/index.js:48
gamesDatabaseQuery.once('child_added').then((latestGame) => {
^

SyntaxError: Unexpected token .
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:588:28)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11

我添加了 activateLatestGame 函数来表明我正在重用代码,但它不起作用。我什至不知道这里的问题是什么,非常感谢任何帮助。

干杯!

最佳答案

此行中缺少 (:

}).then(returnArray) => {

应该是:

}).then((returnArray) => {

关于javascript - Firebase Cloud 在从之前的工作函数复制的代码中出现意外的 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46499023/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com