Skip to content

Commit 2f678fb

Browse files
author
Nicolas Garnier
committed
Changing all existing samples for v1.0.0 launch
Change-Id: I96ead147c6469cd6b48211e5590d0af576d2c520
1 parent 200716b commit 2f678fb

File tree

95 files changed

+642
-703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+642
-703
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
lerna-debug.log
66
*~
77
service-account-credentials.json
8+
**/package-lock.json

assistant-say-number/functions/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Firebase Functions",
44
"dependencies": {
55
"actions-on-google": "^1.0.7",
6-
"firebase-admin": "^4.0.5",
7-
"firebase-functions": "^0.5.1"
6+
"firebase-admin": "~5.9.0",
7+
"firebase-functions": "^1.0.0"
88
},
99
"devDependencies": {
1010
"eslint": "^4.13.1",
@@ -17,5 +17,6 @@
1717
"start": "npm run shell",
1818
"deploy": "firebase deploy --only functions",
1919
"logs": "firebase functions:log"
20-
}
20+
},
21+
"private": true
2122
}

authenticated-json-api/functions/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818

1919
const functions = require('firebase-functions');
2020
const admin = require('firebase-admin');
21-
const Language = require('@google-cloud/language');
21+
admin.initializeApp();
22+
const language = require('@google-cloud/language');
23+
const client = new language.LanguageServiceClient();
2224
const express = require('express');
23-
2425
const app = express();
25-
const language = new Language({projectId: process.env.GCLOUD_PROJECT});
2626

27-
admin.initializeApp(functions.config().firebase);
2827

2928
// Express middleware that validates Firebase ID Tokens passed in the Authorization HTTP header.
3029
// The Firebase ID token needs to be passed as a Bearer token in the Authorization HTTP header like this:
@@ -52,8 +51,8 @@ app.use(authenticate);
5251
app.post('/messages', (req, res) => {
5352
const message = req.body.message;
5453

55-
language.detectSentiment(message).then((results) => {
56-
const category = categorizeScore(results[0].score);
54+
client.analyzeSentiment({document: message}).then((results) => {
55+
const category = categorizeScore(results[0].documentSentiment.score);
5756
const data = {message: message, sentiment: results, category: category};
5857
return admin.database().ref(`/users/${req.user.uid}/messages`).push(data);
5958
}).then((snapshot) => {

authenticated-json-api/functions/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "functions",
33
"description": "Cloud Functions for Firebase",
44
"dependencies": {
5-
"@google-cloud/language": "^0.10.3",
5+
"@google-cloud/language": "^1.1.0",
66
"express": "^4.15.2",
7-
"firebase-admin": "~4.1.2",
8-
"firebase-functions": "^0.5"
7+
"firebase-admin": "~5.9.0",
8+
"firebase-functions": "^1.0.0"
99
},
1010
"private": true,
1111
"devDependencies": {

authorized-https-endpoint/functions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
const functions = require('firebase-functions');
1919
const admin = require('firebase-admin');
20-
admin.initializeApp(functions.config().firebase);
20+
admin.initializeApp();
2121
const express = require('express');
2222
const cookieParser = require('cookie-parser')();
2323
const cors = require('cors')({origin: true});

authorized-https-endpoint/functions/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"cookie-parser": "^1.4.3",
66
"cors": "^2.8.1",
77
"express": "^4.14.1",
8-
"firebase-admin": "^5.6.0",
9-
"firebase-functions": "^0.8.0"
8+
"firebase-admin": "~5.9.0",
9+
"firebase-functions": "^1.0.0"
1010
},
1111
"devDependencies": {
1212
"eslint": "^4.13.1",
@@ -19,5 +19,6 @@
1919
"start": "npm run shell",
2020
"deploy": "firebase deploy --only functions",
2121
"logs": "firebase functions:log"
22-
}
22+
},
23+
"private": true
2324
}

bigquery-import/functions/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Import data to BigQuery Firebase Functions sample",
44
"dependencies": {
55
"@google-cloud/bigquery": "^0.6.0",
6-
"firebase-admin": "^4.1.1",
7-
"firebase-functions": "^0.5.1"
6+
"firebase-admin": "~5.9.0",
7+
"firebase-functions": "^1.0.0"
88
},
99
"devDependencies": {
1010
"eslint": "^4.13.1",
@@ -17,5 +17,6 @@
1717
"start": "npm run shell",
1818
"deploy": "firebase deploy --only functions",
1919
"logs": "firebase functions:log"
20-
}
20+
},
21+
"private": true
2122
}

child-count/functions/index.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,39 @@
1717

1818
const functions = require('firebase-functions');
1919
const admin = require('firebase-admin');
20-
admin.initializeApp(functions.config().firebase);
20+
admin.initializeApp();
2121

2222
// Keeps track of the length of the 'likes' child list in a separate property.
23-
exports.countlikechange = functions.database.ref('/posts/{postid}/likes/{likeid}').onWrite((event) => {
24-
const collectionRef = event.data.ref.parent;
25-
const countRef = collectionRef.parent.child('likes_count');
23+
exports.countlikechange = functions.database.ref('/posts/{postid}/likes/{likeid}').onWrite(
24+
(change) => {
25+
const collectionRef = change.after.ref.parent;
26+
const countRef = collectionRef.parent.child('likes_count');
2627

27-
let increment;
28-
if (event.data.exists() && !event.data.previous.exists()) {
29-
increment = 1;
30-
} else if (!event.data.exists() && event.data.previous.exists()) {
31-
increment = -1;
32-
} else {
33-
return null;
34-
}
28+
let increment;
29+
if (change.after.exists() && !change.after.previous.exists()) {
30+
increment = 1;
31+
} else if (!change.after.exists() && change.after.previous.exists()) {
32+
increment = -1;
33+
} else {
34+
return null;
35+
}
3536

36-
// Return the promise from countRef.transaction() so our function
37-
// waits for this async event to complete before it exits.
38-
return countRef.transaction((current) => {
39-
return (current || 0) + increment;
40-
}).then(() => {
41-
return console.log('Counter updated.');
42-
});
43-
});
37+
// Return the promise from countRef.transaction() so our function
38+
// waits for this async event to complete before it exits.
39+
return countRef.transaction((current) => {
40+
return (current || 0) + increment;
41+
}).then(() => {
42+
return console.log('Counter updated.');
43+
});
44+
});
4445

4546
// If the number of likes gets deleted, recount the number of likes
46-
exports.recountlikes = functions.database.ref('/posts/{postid}/likes_count').onWrite((event) => {
47-
if (!event.data.exists()) {
48-
const counterRef = event.data.ref;
49-
const collectionRef = counterRef.parent.child('likes');
47+
exports.recountlikes = functions.database.ref('/posts/{postid}/likes_count').onDelete((snap) => {
48+
const counterRef = snap.ref;
49+
const collectionRef = counterRef.parent.child('likes');
5050

51-
// Return the promise from counterRef.set() so our function
52-
// waits for this async event to complete before it exits.
53-
return collectionRef.once('value')
51+
// Return the promise from counterRef.set() so our function
52+
// waits for this async event to complete before it exits.
53+
return collectionRef.once('value')
5454
.then((messagesData) => counterRef.set(messagesData.numChildren()));
55-
}
56-
return null;
5755
});

child-count/functions/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "child-count-functions",
33
"description": "Count Child nodes Firebase Functions sample",
44
"dependencies": {
5-
"firebase-admin": "^4.1.1",
6-
"firebase-functions": "^0.5.1"
5+
"firebase-admin": "~5.9.0",
6+
"firebase-functions": "^1.0.0"
77
},
88
"devDependencies": {
99
"eslint": "^4.13.1",
@@ -16,5 +16,6 @@
1616
"start": "npm run shell",
1717
"deploy": "firebase deploy --only functions",
1818
"logs": "firebase functions:log"
19-
}
19+
},
20+
"private": true
2021
}

convert-images/functions/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ const JPEG_EXTENSION = '.jpg';
3030
* When an image is uploaded in the Storage bucket it is converted to JPEG automatically using
3131
* ImageMagick.
3232
*/
33-
exports.imageToJPG = functions.storage.object().onChange((event) => {
34-
const object = event.data;
33+
exports.imageToJPG = functions.storage.object().onFinalize((object) => {
3534
const filePath = object.name;
3635
const baseFileName = path.basename(filePath, path.extname(filePath));
3736
const fileDir = path.dirname(filePath);

0 commit comments

Comments
 (0)