Commit 7403e900 authored by axet's avatar axet 🍄

fix firebase functions

parent b179009d
Pipeline #34147348 passed with stage
in 28 seconds
......@@ -24,30 +24,24 @@ exports.deleteOldUsers = functions.database.ref('users/{userId}').onCreate((snap
});
exports.topics = functions.https.onRequest((req, res) => {
let message;
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET, PUT');
res.set('Access-Control-Allow-Headers', 'Content-Type');
switch (req.get('content-type')) {
case 'application/json':
message = req.body;
break;
case 'application/octet-stream':
message = JSON.parse(req.body.toString()) ; // Convert buffer to a string
break;
case 'text/plain':
message = JSON.parse(req.body);
break;
case 'application/x-www-form-urlencoded':
message = JSON.parse(req.body);
break;
if (req.method === 'OPTIONS') {
return res.status(204).send('');
}
let message = req.body;
if (message) {
let to = message.to.replace(/^(\/topics\/)/,'');
res = admin.messaging().sendToTopic(to, message);
if (!message) {
return res.status(500).send("no message");
}
res.send(`OK`);
return admin.messaging().send(message).then((response) => {
return res.status(200).send(response);
})
.catch((error) => {
return res.status(500).send(error);
});
});
......@@ -5,8 +5,5 @@
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.0.5"
},
"engines": {
"node": "8"
},
"private": true
}
......@@ -99,10 +99,9 @@ global.deleteall = function deleteall(thread) {
function command(cmd) {
var url = "https://us-central1-android-sms-gate.cloudfunctions.net/topics";
var ref = "/topics/" + CRYPTO.address(current.key);
var ref = CRYPTO.address(current.key).toString();
var json = {
"to" : ref,
"priority" : "high",
"topic" : ref,
"data": {
"text": CRYPTO.encrypt(current.key, new Buffer(JSON.stringify(cmd))).toString('base64')
}
......
......@@ -8,7 +8,7 @@ which minify || npm install minifier
which browserify || npm install browserify
npm install
[ ! -e node_modules ] && npm install
browserify index.js -o smsgate.js
......
......@@ -144,10 +144,9 @@ global.deleteall = function deleteall(thread) {
function command(cmd) {
var url = "https://us-central1-android-sms-gate.cloudfunctions.net/topics";
var ref = "/topics/" + CRYPTO.address(current.key);
var ref = CRYPTO.address(current.key).toString();
var json = {
"to" : ref,
"priority" : "high",
"topic" : ref,
"data": {
"text": CRYPTO.encrypt(current.key, new Buffer(JSON.stringify(cmd))).toString('base64')
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment