提问人:JRR 提问时间:11/16/2023 更新时间:11/16/2023 访问量:17
如何发布 Firebase 远程配置模板?[关闭]
How I publish template for Firebase remote config? [closed]
问:
当我尝试使用 Node Js 发布新模板时,我总是遇到问题。如果我通过Firebase控制台(相同的文件)添加,那就没问题了。
我的JSON格式:
{
"conditions": [
{
"name": "For English Android Users",
"expression": "device.os == 'android' && device.language in ['en']",
"tagColor": "GREEN"
}
],
"parameters": {
"publish": {
"defaultValue": {
"value": "Testing publish"
},
"conditionalValues": {
"For English Android Users": {
"value": "Testing publish"
}
}
}
},
"version": {
"versionNumber": "6",
"updateTime": "2023-11-16T15:53:30.574106Z",
"updateUser": {
"email": "[email protected]"
},
"updateOrigin": "ADMIN_SDK_NODE",
"updateType": "INCREMENTAL_UPDATE"
}
}
添加 etag 序列号或远程直接版本节点 json 有任何更改吗?我对这个文件应该是什么样子感到非常困惑。
我的控制器在输入路径时调用 POST 请求时调用函数:
function validateTemplate( template ) {
return new Promise( function( resolve, reject ) {
config
.validateTemplate( template )
.then( function() {
resolve( true );
})
.catch( function( err ) {
console.error( "Template is invalid and cannot be published" );
console.error( err );
resolve( false );
});
});
}
function publishTemplate( req, res, next ) {
var template;
try {
upload.single( "publish" )( req, res, function( err ) {
if ( err ) {
return next( new Error( "Error uploading file" ));
}
if ( !req.file ) {
throw new Error( "No file uploaded" );
}
var fileContent = fs.readFileSync( req.file.path, "UTF8" );
template = config.createTemplateFromJSON( fileContent );
validateTemplate( template )
.then( function( isValid ) {
if ( !isValid ) {
throw new Error( "Template is invalid" );
}
return config.publishTemplate( template );
})
.then( function( publication ) {
res.status( 200 ).send( "Template has been published" );
})
.catch( function( err ) {
console.error( "Failed to publish template: ", err );
next( err );
});
});
}
catch ( err ) {
return next( new Error( err ));
}
}
答: 暂无答案
评论