Skip to content

Commit f6d200b

Browse files
committed
fix samples so CI passes
1 parent 85a47dd commit f6d200b

File tree

8 files changed

+62
-48
lines changed

8 files changed

+62
-48
lines changed

2nd-gen/alerts-to-discord/functions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ id: \`${id}\`
7878
if (response.ok) {
7979
logger.info(
8080
`Posted fatal Crashlytics alert ${id} to Discord`,
81-
event.payload,
81+
event.data.payload,
8282
);
8383
} else {
8484
throw new Error(response.error);

2nd-gen/callable-functions/functions/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ const sanitizer = require("./sanitizer");
2222
// [START v2allAdd]
2323
// [START v2addFunctionTrigger]
2424
// Adds two numbers to each other.
25-
exports.addnumbers = onCall((data) => {
25+
exports.addnumbers = onCall((request) => {
2626
// [END v2addFunctionTrigger]
2727
// [START v2readAddData]
2828
// Numbers passed from the client.
29-
const firstNumber = data.firstNumber;
30-
const secondNumber = data.secondNumber;
29+
const firstNumber = request.data.firstNumber;
30+
const secondNumber = request.data.secondNumber;
3131
// [END v2readAddData]
3232

3333

@@ -89,7 +89,7 @@ exports.addmessage = onCall((data, context) => {
8989
// Saving the new message to the Realtime Database.
9090
const sanitizedMessage = sanitizer.sanitizeText(text); // Sanitize message.
9191

92-
return getDatabase.ref("/messages").push({
92+
return getDatabase().ref("/messages").push({
9393
text: sanitizedMessage,
9494
author: {uid, name, picture, email},
9595
}).then(() => {

2nd-gen/callable-functions/functions/sanitizer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ exports.sanitizeText = (text) => {
3939
/**
4040
* Returns true if the string contains swearwords.
4141
* @param {string} message
42-
* @return {string}
42+
* @return {boolean}
4343
*/
4444
function containsSwearwords(message) {
4545
return message !== badWordsFilter.clean(message);
@@ -58,7 +58,7 @@ function replaceSwearwords(message) {
5858
* Detect if the current message is shouting. i.e. there are too many Uppercase
5959
* characters or exclamation points.
6060
* @param {string} message message to be analyzed
61-
* @return {string}
61+
* @return {boolean}
6262
*/
6363
function isShouting(message) {
6464
return message.replace(/[^A-Z]/g, "").length > message.length / 2 ||

2nd-gen/custom-events/functions/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
// [START import]
1818
const {onCustomEventPublished} = require("firebase-functions/v2/eventarc");
1919
const logger = require("firebase-functions/logger");
20-
const { initializeApp } = require('firebase-admin/app');
21-
const { getStorage } = require('firebase-admin/storage');
20+
const {initializeApp} = require("firebase-admin/app");
21+
const {getStorage} = require("firebase-admin/storage");
2222
// [END import]
2323

2424
initializeApp();
@@ -33,5 +33,6 @@ exports.onimageresized = onCustomEventPublished(
3333
.bucket("my-project.appspot.com")
3434
.file(event.subject)
3535
.delete();
36-
});
36+
}
37+
);
3738
// [END imageresizedEvent]

2nd-gen/taskqueues-backup-images/functions/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const HttpsError = functions.https.HttpsError;
2828
initializeApp();
2929

3030
const BACKUP_START_DATE = new Date("1995-06-17");
31-
const BACKUP_COUNT = process.env.BACKUP_COUNT || 100;
32-
const HOURLY_BATCH_SIZE = process.env.HOURLY_BATCH_SIZE || 500;
31+
const BACKUP_COUNT = parseInt(process.env.BACKUP_COUNT) || 100;
32+
const HOURLY_BATCH_SIZE = parseInt(process.env.HOURLY_BATCH_SIZE) || 500;
3333
const BACKUP_BUCKET = process.env.BACKUP_BUCKET;
3434

3535
/**
@@ -47,7 +47,7 @@ exports.backupapod = onTaskDispatched(
4747
maxConcurrentDispatches: 6,
4848
},
4949
}, async (req) => {
50-
// [END v2TaskFunctionSetup]
50+
// [END v2TaskFunctionSetup]
5151
const date = req.data.date;
5252
if (!date) {
5353
logger.warn("Invalid payload. Must include date.");
@@ -100,10 +100,15 @@ exports.backupapod = onTaskDispatched(
100100

101101

102102
let auth;
103+
104+
// [START v2GetFunctionUri]
103105
/**
104-
* Returns URL of the given v2 google cloud function.
106+
* Get the URL of a given v2 cloud function.
107+
*
108+
* @param {string} name the function's name
109+
* @param {string} location the function's location
110+
* @return {Promise<string>} The URL of the function
105111
*/
106-
// [START v2GetFunctionUri]
107112
async function getFunctionUrl(name, location="us-central1") {
108113
if (!auth) {
109114
auth = new GoogleAuth({
@@ -133,7 +138,8 @@ exports.enqueuebackuptasks = onRequest(
133138
const enqueues = [];
134139
for (let i = 0; i <= BACKUP_COUNT; i += 1) {
135140
const iteration = Math.floor(i / HOURLY_BATCH_SIZE);
136-
const scheduleDelaySeconds = iteration * (60 * 60); // Delay each batch by N * hour
141+
// Delay each batch by N * hour
142+
const scheduleDelaySeconds = iteration * (60 * 60);
137143

138144
const backupDate = new Date(BACKUP_START_DATE);
139145
backupDate.setDate(BACKUP_START_DATE.getDate() + i);

2nd-gen/time-server/functions/index.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
'use strict';
16+
"use strict";
1717

1818
// [START v2httpImport]
19-
const { onRequest } = require('firebase-functions/v2/https');
19+
const {onRequest} = require("firebase-functions/v2/https");
2020
// [END v2httpImport]
2121

2222
// [START v2httpAdditionalImports]
23-
const logger = require('firebase-functions/logger');
23+
const logger = require("firebase-functions/logger");
2424
// Moments library to format dates.
25-
const moment = require('moment');
25+
const moment = require("moment");
2626
// [END v2httpAdditionalImports]
2727

2828
// [START v2httpAll]
2929
/**
30-
* Returns the server's date. Options `timeoutSeconds` and `region` are optional.
30+
* Returns the server's date.
31+
* Options `timeoutSeconds` and `region` are optional.
3132
*
3233
* You must provide a `format` URL query parameter or `format` value in
3334
* the request body with which we'll try to format the date.
@@ -43,33 +44,36 @@ const moment = require('moment');
4344
* https://us-central1-<project-id>.cloudfunctions.net/date
4445
*/
4546
// [START v2httpTrigger]
46-
exports.date = onRequest({ timeoutSeconds: 1200, region: ["us-west1", "us-east1"] }, (req, res) => {
47-
// [END v2httpTrigger]
47+
exports.date = onRequest(
48+
{timeoutSeconds: 1200, region: ["us-west1", "us-east1"]},
49+
(req, res) => {
50+
// [END v2httpTrigger]
4851

49-
// [START v2httpSendError]
50-
// Forbidding PUT requests.
51-
if (req.method === 'PUT') {
52-
res.status(403).send('Forbidden!');
53-
return;
54-
}
55-
// [END v2httpSendError]
56-
57-
// Reading date format from URL query parameter.
58-
// [START v2httpReadQueryParam]
59-
let format = req.query.format;
60-
// [END v2httpReadQueryParam]
52+
// [START v2httpSendError]
53+
// Forbidding PUT requests.
54+
if (req.method === "PUT") {
55+
res.status(403).send("Forbidden!");
56+
return;
57+
}
58+
// [END v2httpSendError]
6159

62-
// Reading date format from request body query parameter
63-
if (!format) {
64-
// [START v2httpReadBodyParam]
65-
format = req.body.format;
66-
// [END v2httpReadBodyParam]
67-
}
60+
// Reading date format from URL query parameter.
61+
// [START v2httpReadQueryParam]
62+
let format = req.query.format;
63+
// [END v2httpReadQueryParam]
6864

69-
// [START v2httpSendResponse]
70-
const formattedDate = moment().format(`${format}`);
71-
logger.log('Sending formatted date:', formattedDate);
72-
res.status(200).send(formattedDate);
73-
// [END v2httpSendResponse]
74-
});
65+
// Reading date format from request body query parameter
66+
if (!format) {
67+
// [START v2httpReadBodyParam]
68+
format = req.body.format;
69+
// [END v2httpReadBodyParam]
70+
}
71+
72+
// [START v2httpSendResponse]
73+
const formattedDate = moment().format(`${format}`);
74+
logger.log("Sending formatted date:", formattedDate);
75+
res.status(200).send(formattedDate);
76+
// [END v2httpSendResponse]
77+
}
78+
);
7579
// [END v2httpAll]

authenticated-json-api/functions/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ app.post('/api/messages', async (req, res) => {
8080
} catch(error) {
8181
functions.logger.log(
8282
'Error detecting sentiment or saving message',
83+
// @ts-ignore
8384
error.message
8485
);
8586
res.sendStatus(500);
@@ -112,6 +113,7 @@ app.get('/api/messages', async (req, res) => {
112113

113114
res.status(200).json(messages);
114115
} catch(error) {
116+
// @ts-ignore
115117
functions.logger.log('Error getting messages', error.message);
116118
res.sendStatus(500);
117119
}
@@ -138,6 +140,7 @@ app.get('/api/message/:messageId', async (req, res) => {
138140
functions.logger.log(
139141
'Error getting message details',
140142
messageId,
143+
// @ts-ignore
141144
error.message
142145
);
143146
return res.sendStatus(500);

image-sharp/functions/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Generate Thumbnail with Sharp Firebase Functions sample",
44
"dependencies": {
55
"@google-cloud/storage": "^4.3.1",
6-
"sharp": "0.23.4",
6+
"sharp": "0.30.4",
77
"firebase-admin": "^10.0.0",
88
"firebase-functions": "^3.16.0"
99
},

0 commit comments

Comments
 (0)